当前位置:网站首页>[acnoi2022] color ball
[acnoi2022] color ball
2022-07-01 18:17:00 【OneInDark】
subject
Background ( The cruelest and truest reality , Often say it in the most playful way )
“ Who doesn't like being O U Y E \sf OUYE OUYE It's hanging , raise your hand , It's still too late to quit .”
If life could start over , I'll go back to where I never set foot O I \rm OI OI The time of . The sky is high and the emperor is far away , I am my own king . I control my body , Only take your own will as the standard .
Until that day , I'm sitting in that classroom , I can't see the interior of its original prison car . I heard that sentence again , Maybe this time , I will give different answers . Maybe I won't put my hands between my legs , Don't bear the coming three years j o k e r \rm joker joker time , No use F i r e W i n g B i r d \sf FireWingBird FireWingBird Put on a smiling face to please it .
I slowly raised my hand , Trembling , Like a person dying , The last whine of stretching neck ……
“ Bang, !”
Clap your hands heavily on the table .
“ Be hanged if you are hanged ! Do you think I'll quit ?”
……
in endure Examination try . I and O U Y E \sf OUYE OUYE Duel .
“ Everyone has his own efforts , This effort is indelible ! Gossip ⋅ \large\cdot ⋅ Sixty four violent search !”
“ You use ‘ Strive ’ To make a perfunctory excuse , It's impossible to defeat me ! Your fate is doomed to lose to me !” O U Y E \sf OUYE OUYE Said , Rush to me ,“ Rolling escape ⋅ \large\cdot ⋅ E I \sf EI EI The soul of !” I instantly lost consciousness .
He let me know , Fate is unchangeable .
……
The fourth provincial war broke out .
I stand D D ( X Y X ) \sf DD(XYX) DD(XYX) In front of , Two sharp wooden thorns ran straight through my chest . My heart is empty . I finally understand , So many people , Actively rush to death , That feeling of freedom …… On my forehead , The seal of those with bad habits is gradually disappearing ……
“ Why? …… You only sacrifice for me now ?” D D ( X Y X ) \sf DD(XYX) DD(XYX) Full of puzzles .
“ because …… You said I was …… genius .”
“ Didn't you say that you would never let your companions live ?” The sound comes from the gold medal pile H a n d I n D e v i l \sf HandInDevil HandInDevil bring a person to the presence of sb. .“ I want you to say it again !”
“ Look at the living companions around you ! As long as you keep pretending to be weak , There will be more companions alive ! Touch the corpse of your partner who is not yet cold , Enjoy it ! In the end , The rest will only be the ones you are most familiar with 、 Is also the most afraid —— Huddle for warmth !”
“ Come on , Come to me .” H a n d I n D e v i l \sf HandInDevil HandInDevil Put out your hand .
Title Description
Black and white balls are lined up . You can execute several times “ eliminate ” operation , Every time “ eliminate ” The process is :
- Take out a length of n ( 2 ∤ n ) n\;(2\nmid n) n(2∤n) The prefix of , Remember it as S S S .
- take S S S Take out the last three balls . according to Some kind of rule , They will change into a ball . Put the ball back S S S Tail of .
- Repeat the previous step , until ∣ S ∣ = 1 |S|=1 ∣S∣=1 . Put this ball back in front of the original ball sequence ( Pay attention to the original S S S It has been taken out ).
“ eliminate ” There is only one ball left , If the ball is white , Then this row of balls is “ good Chromatic ”( Be careful “ good ” It's shangsheng ).
Now give me some balls , Some balls have unknown colors , ask , If you assign a color to all balls with unknown colors , How many cases are “ Lecherous ”. The answer is right 998244353 998244353 998244353 modulus . Some kind of rule Will be given every time .
Data range and tips
The number of balls ⩽ 1 0 6 \leqslant 10^6 ⩽106 .
Ideas
Always wanted to DFA \textit{DFA} DFA, Then I feel numb . As a result, look at the solution , It seems very simple , I'm embarrassed .
need Linear scanning In order to count . Transform directly according to the meaning of the topic : The ball that has been swept so far , Save up . Add two balls each time , To operate , Empty the balls in the stack , Become a ball ; Otherwise, join yourself .
It doesn't matter how the stack looks , Because the result is just a ball , Only need to use * a , b * \langle a,b\rangle *a,b* You can store , When the newly added ball is white or black , What color ball will change after one operation . Such a function has only 2 2 2^2 22 individual , The problem of judgment , You can use it 2 2 2 2^{2^2} 222 Shape pressure indicates whether each function can be summed up .
The same goes for counting . It can be extended to m m m Two colors , The complexity is O ( m 2 2 m m n ) \mathcal O(m^22^{m^m}n) O(m22mmn) .
Code
#include <cstdio> // JZM yydJUNK!!!
#include <iostream> // XJX yyds!!!
#include <algorithm> // XYX yydLONELY!!!
#include <cstring> // (the STRONG long for LONELINESS)
#include <cctype> // ZXY yydSISTER!!!
using namespace std;
# define rep(i,a,b) for(int i=(a); i<=(b); ++i)
# define drep(i,a,b) for(int i=(a); i>=(b); --i)
typedef long long llong;
inline int readint(){
int a = 0, c = getchar(), f = 1;
for(; !isdigit(c); c=getchar())
if(c == '-') f = -f;
for(; isdigit(c); c=getchar())
a = (a<<3)+(a<<1)+(c^48);
return a*f;
}
const int MAXN = 100005, MOD = 998244353;
inline void modAddUp(int &x, const int &y){
if((x += y) >= MOD) x -= MOD;
}
int trans[2][2][1<<4], dp[2][1<<4];
char mov[15], str[MAXN];
int main(){
for(int T=readint(); T; --T){
scanf("%s",mov);
rep(a,0,1) rep(b,0,1) rep(c,0,1) rep(d,0,1){
// when function is <c,d>, push_back(a,b)
{
// if operate @a a here
int ass = a ? d : c; // become <ass,b>
const int zero = mov[ass^(b<<1)]^48;
const int one = mov[ass^(b<<1)^4]^48;
trans[a][b][1<<(c^(d<<1))] = 1<<(zero^(one<<1));
}
{
// if not to operate @a a here
const int zero = (mov[a|(b<<1)]^48) ? d : c;
const int one = (mov[a|(b<<1)|4]^48) ? d : c;
trans[a][b][1<<(c^(d<<1))] |= 1<<(zero^(one<<1));
}
}
rep(a,0,1) rep(b,0,1) rep(S,1,(1<<4)-1)
trans[a][b][S] = trans[a][b][S&(S-1)]|trans[a][b][S&-S];
scanf("%s",str); int n = int(strlen(str))-1;
memset(dp[0],0,(1<<4)<<2), dp[0][1<<2] = 1;
for(int i=0,nxt=1; i!=n; i+=2,nxt^=1){
memset(dp[nxt],0,(1<<4)<<2);
rep(a,0,1) if((str[i]^48) != (a^1))
rep(b,0,1) if((str[i+1]^48) != (b^1))
rep(S,1,(1<<4)-1) modAddUp(
dp[nxt][trans[a][b][S]],dp[nxt^1][S]);
}
int ans = 0;
rep(c,0,1) if((str[n]^48) != (c^1))
rep(S,1,(1<<4)-1){
bool ok = false;
rep(a,0,1) rep(b,0,1) if(S>>(a^(b<<1))&1)
if((c ? b : a) == 1) ok = true;
if(ok) modAddUp(ans,dp[(n>>1)&1][S]);
}
printf("%d\n",ans);
}
return 0;
}
边栏推荐
- Mujoco's biped robot Darwin model
- Redis -- data type and operation
- Smart factory digital management system software platform
- 【Try to Hack】vulnhub DC4
- Intelligent operation and maintenance practice: banking business process and single transaction tracking
- Kernel stray cat stray dog pet adoption platform H5 source code
- Talk about the favorite tools used by project managers
- Oracle TRUNC function processing date format
- People help ant help task platform repair source code
- Debiasing word embeddings | talking about word embedding and deviation removal # yyds dry goods inventory #
猜你喜欢

Definition of rotation axis in mujoco

Source code of new campus errand / campus task platform on mutual station
![[PHP foundation] realize the connection between PHP and SQL database](/img/eb/c8953eddfe3b19b0adb5529957d275.jpg)
[PHP foundation] realize the connection between PHP and SQL database

ACM mm 2022 video understanding challenge video classification track champion autox team technology sharing

Common design parameters of solid rocket motor

How to write good code - Defensive Programming Guide

Enter wechat applet

Kernel stray cat stray dog pet adoption platform H5 source code

What impact will multinational encryption regulation bring to the market in 2022

Good looking UI mall source code has been scanned, no back door, no encryption
随机推荐
Slider verification code identification gadget display
Is the fund of futures account safe? How to open an account?
Apache iceberg source code analysis: schema evolution
Heavy disclosure! Hundreds of important information systems have been invaded, and the host has become a key attack target
DRF --- response rewrite
Talk about the favorite tools used by project managers
MES production equipment manufacturing execution system software
Android development interview was badly hit in 3 years, and now the recruitment technical requirements are so high?
New patent applications and transfers
Htt [ripro network disk link detection plug-in] currently supports four common network disks
SQL injection vulnerability (MySQL and MSSQL features)
How to use JMeter function and mockjs function in metersphere interface test
Intel's open source deep learning tool library openvino will increase cooperation with local software and hardware parties and continue to open
Pytorch crossentropyloss learning
D @ safety and dip1000
Is it reasonable and safe to open a securities account for 10000 shares free of charge? How to say
Highly reliable program storage and startup control system based on anti fuse FPGA and QSPI flash
ACL 2022 | decomposed meta learning small sample named entity recognition
Smart factory digital management system software platform
Function, condition, regular expression