QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#232350 | #7559. Bocchi the Rock | CharlieVinnie | TL | 0ms | 0kb | C++17 | 2.6kb | 2023-10-30 11:26:50 | 2023-10-30 11:26:51 |
answer
#include "bits/stdc++.h"
#ifdef DEBUG
#include "PrettyDebug.hpp"
#else
#define debug(...) [](auto...){}(__VA_ARGS__)
#define debuga(...) [](auto...){}(__VA_ARGS__)
#endif
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Rev(i,a,b) for(int i=a;i>=b;i--)
#define Fin(file) freopen(file,"r",stdin)
#define Fout(file) freopen(file,"w",stdout)
#define assume(expr) ((!!(expr))||(exit((fprintf(stderr,"Assumption Failed: %s on Line %d\n",#expr,__LINE__),-1)),false))
#define range basic_string_view
using namespace std; typedef long long ll;
constexpr int N=5e4+5,mod=998244353;
int n,f[2][2][2][N]; string s; // f[o][arc][col][cnt] R=0,B=1 Y=0,P=1 0 point, 1 edge
inline void ck(int& x,int y) { x+=y-mod; x+=x>>31&mod; }
inline bool I0(char c,int o) { return c!="BR"[o]; }
inline bool I1(char c,int o) { return c!="PY"[o]; }
signed main(){
atexit([](){cerr<<"Time = "<<clock()<<" ms"<<endl;}); ios::sync_with_stdio(0); cin.tie(0);
// cin>>n>>s; s=' '+s;
n=5e4; s=string(n*2+1,'?');
For(u,0,1) if(I1(s[1],u)) f[0][u][0][0]=1;
int o=0;
For(i,1,n-1){
if(i%1000==0) debug(i,clock());
#pragma GCC unroll(2)
For(u,0,1)
#pragma GCC unroll(2)
For(v,0,1) memset(f[o^1][u][v],0,i<<2);
char c0=s[i*2],c1=s[i*2+1];
#pragma GCC unroll(2)
For(u,0,1)
#pragma GCC unroll(2)
For(v,0,1)
For(j,0,i-1) if(f[o][u][v][j]){
int x=f[o][u][v][j];
if(j==0){
if(I1(c1,u)){
ck(f[o^1][u][0][0],x);
if(c0=='?') ck(f[o^1][u][0][0],x);
}
if(I1(c1,u^1)){
if(I0(c0,0)) ck(f[o^1][u^1][0][1],x);
if(I0(c0,1)) ck(f[o^1][u^1][1][1],x);
}
}
else{
if(I1(c1,u)){
ck(f[o^1][u][v][j],x);
if(c0=='?') ck(f[o^1][u][v][j],x);
}
if(I1(c1,u^1)){
if(I0(c0,v )) ck(f[o^1][u^1][v^1][j-1],x);
if(I0(c0,v^1)) ck(f[o^1][u^1][v^1][j+1],x);
}
}
}
o^=1;
}
int ans=0; For(u,0,1) For(v,0,1){
if(I0(s[n*2],0)) ck(ans,f[o][u][v][0]);
if(I0(s[n*2],1)) ck(ans,f[o][u][v][0]);
if(I0(s[n*2],v)) ck(ans,f[o][u][v][1]);
}
cout<<ans<<'\n';
return 0;
}
// START TYPING IF YOU DON'T KNOW WHAT TO DO
// STOP TYPING IF YOU DON'T KNOW WHAT YOU'RE DOING
// CONTINUE, NON-STOPPING, FOR CHARLIEVINNIE
// Started Coding On: October 30 Mon, 10 : 41 : 58
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
2 ????