当前位置:网站首页>[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;
}
边栏推荐
- Yuancosmos game farmersworld farmers world - core content of the second conference in China!
- 聊聊项目经理最爱使用的工具
- Petrv2: a unified framework for 3D perception of multi camera images
- LeetCode 148. Sort linked list
- SCP -i private key usage
- Cassette helicopter and alternating electric field magnetic manometer DPC
- Single element of an ordered array
- This is the latest opportunity of the London bank trend
- To improve the efficiency of office collaboration, trackup may be the best choice
- People help ant help task platform repair source code
猜你喜欢

Penetration practice vulnhub range Nemesis

Cloud picture says | distributed transaction management DTM: the little helper behind "buy buy buy"

Samba basic usage

Petrv2: a unified framework for 3D perception of multi camera images

How to use JMeter function and mockjs function in metersphere interface test

Rotation order and universal lock of unity panel

The method of real-time tracking the current price of London Silver

Apache iceberg source code analysis: schema evolution

Intelligent operation and maintenance practice: banking business process and single transaction tracking

Replace UUID, nanoid is faster and safer!
随机推荐
Thinkphp6 - CMS multi wechat management system source code
When the fixed frequency artifact falls in love with multithreading | ros2 fixed frequency topic release demo
Draw drawing process of UI drawing process
Can hero sports go public against the wind?
Apache iceberg source code analysis: schema evolution
Nielseniq found that 60% of the re launched products had poor returns
An example of data analysis of an old swatch and an old hard disk disassembly and assembly combined with the sensor of an electromagnetic press
(6) VIM editor MV cat redirection standard input and output more pipe symbols head tail
[C supplement] [string] display the schedule of a month by date
L'ouverture d'un compte d'actions en ligne est - elle sécurisée? Fiable?
手机开户股票开户安全吗?那么开户需要带些什么?
Is the fund of futures account safe? How to open an account?
js如何将带有分割符的字符串转化成一个n维数组
Leetcode 1380. Lucky numbers in the matrix (save the minimum number of each row and the maximum number of each column)
目前炒期货在哪里开户最正规安全?怎么期货开户?
Check log4j problems using stain analysis
Data warehouse (3) star model and dimension modeling of data warehouse modeling
Basic usage of shell script
Highly reliable program storage and startup control system based on anti fuse FPGA and QSPI flash
Gameframework eating guide