当前位置:网站首页>[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;
}
边栏推荐
- Is Huishang futures a regular futures platform? Is it safe to open an account in Huishang futures?
- 线上开通ETF基金账户安全吗?有哪些步骤?
- js如何将带有分割符的字符串转化成一个n维数组
- Enter wechat applet
- golang中的select详解
- Code example of libcurl download file
- ISO 27001 Information Security Management System Certification
- Euler function: find the number of numbers less than or equal to N and coprime with n
- Countdownlatch blocking wait for multithreading concurrency
- Work and leisure suggestions of old programmers
猜你喜欢
How to retrieve the password for opening Excel files
Domestic spot silver should be understood
Fix the black screen caused by iPhone system failure
Flex layout
Explain in detail the process of realizing Chinese text classification by CNN
Gameframework eating guide
Android development interview was badly hit in 3 years, and now the recruitment technical requirements are so high?
Happy new year | 202112 monthly summary
Rotation order and universal lock of unity panel
This is the latest opportunity of the London bank trend
随机推荐
transform. Forward and vector3 Differences in the use of forward
Happy new year | 202112 monthly summary
Samba basic usage
Technical secrets of ByteDance data platform: implementation and optimization of complex query based on Clickhouse
How to use JMeter function and mockjs function in metersphere interface test
线上开通ETF基金账户安全吗?有哪些步骤?
Growing up in the competition -- (Guangyou's most handsome cub) Pikachu walking
Alibaba cloud Li Feifei: China's cloud database has taken the lead in many mainstream technological innovations abroad
. Net cloud native architect training camp (permission system code implements actionaccess) -- learning notes
Is it safe to open a securities account? Is there any danger
On the language internationalization of Yongzhong Office
Talk about the favorite tools used by project managers
The new server is packaged with the source code of H5 mall with an operation level value of several thousand
t10_ Adapting to Market Participantsand Conditions
Countdownlatch blocking wait for multithreading concurrency
Can hero sports go public against the wind?
Replace UUID, nanoid is faster and safer!
Small exercise -- subnet division and summary
[C supplement] [string] display the schedule of a month by date
Explain in detail the process of realizing Chinese text classification by CNN