Submission #44996307
Source Code Expand
#include<bits/stdc++.h>
#define LL long long
#define DB double
#define MOD 998244353
#define ls(x) x << 1
#define rs(x) x << 1 | 1
#define lowbit(x) x & (-x)
#define PII pair<int, int>
#define MP make_pair
#define VI vector<int>
#define VII vector<int>::iterator
#define all(x) x.begin(), x.end()
#define EB emplace_back
#define SI set<int>
#define SII set<int>::iterator
#define QI queue<int>
using namespace std;
template<typename T> void chkmn(T &a, const T &b) { (a > b) && (a = b); }
template<typename T> void chkmx(T &a, const T &b) { (a < b) && (a = b); }
int inc(const int &a, const int &b) { return a + b >= MOD ? a + b - MOD : a + b; }
int dec(const int &a, const int &b) { return a - b < 0 ? a - b + MOD : a - b; }
int mul(const int &a, const int &b) { return 1LL * a * b % MOD; }
int sqr(const int &a) { return 1LL * a * a % MOD; }
void Inc(int &a, const int &b) { ((a += b) >= MOD) && (a -= MOD); }
void Dec(int &a, const int &b) { ((a -= b) < 0) && (a += MOD); }
void Mul(int &a, const int &b) { a = 1LL * a * b % MOD; }
void Sqr(int &a) { a = 1LL * a * a % MOD; }
int qwqmi(int x, int k = MOD - 2)
{
int res = 1;
while(k)
{
if(k & 1) Mul(res, x);
Sqr(x), k >>= 1;
}
return res;
}
const int N = 1e6 + 5;
const int F = 23;
char ch[N];
int n, cnt;
int w[N][F];
int f[N][F], ans;
int main()
{
scanf("%s", ch + 1);
n = strlen(ch + 1);
for(int i = 1; i <= n; ++i)
{
if(ch[i] != 'B') w[i][0] = 1;
cnt += (ch[i] == '?');
}
for(int j = 1; j < F; ++j)
for(int i = 1; i + (1 << j) - 1 <= n; ++i)
w[i][j] = min(w[i][j - 1], w[i + (1 << (j - 1))][j - 1]);
f[n + 1][0] = 1;
for(int i = n; i >= 1; --i)
{
if(ch[i] != 'B')
{
for(int j = 0; j < F; ++j)
f[i][j] = f[i + 1][j];
}
if(ch[i] != 'S')
{
Inc(f[i][1], f[i + 1][0]);
for(int j = 2; j < F; ++j)
if(w[i + 1][j - 2])
Inc(f[i][j], f[i + (1 << (j - 2)) + 1][j - 1]);
}
}
for(int j = 0; j < F; ++j)
Inc(ans, f[1][j]);
ans = dec(qwqmi(2, cnt), ans);
printf("%d\n", ans);
return 0;
}
Submission Info
| Submission Time |
|
| Task |
C - Block Game |
| User |
Schucking_Sattin |
| Language |
C++ (GCC 9.2.1) |
| Score |
1000 |
| Code Size |
2075 Byte |
| Status |
AC |
| Exec Time |
300 ms |
| Memory |
184468 KiB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:46:7: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
46 | scanf("%s", ch + 1);
| ~~~~~^~~~~~~~~~~~~~
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
1000 / 1000 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
example0.txt, example1.txt |
| All |
000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, example0.txt, example1.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 000.txt |
AC |
292 ms |
184308 KiB |
| 001.txt |
AC |
296 ms |
184464 KiB |
| 002.txt |
AC |
238 ms |
184252 KiB |
| 003.txt |
AC |
300 ms |
184396 KiB |
| 004.txt |
AC |
286 ms |
184440 KiB |
| 005.txt |
AC |
287 ms |
184252 KiB |
| 006.txt |
AC |
283 ms |
184304 KiB |
| 007.txt |
AC |
287 ms |
184312 KiB |
| 008.txt |
AC |
285 ms |
184348 KiB |
| 009.txt |
AC |
266 ms |
184308 KiB |
| 010.txt |
AC |
117 ms |
86272 KiB |
| 011.txt |
AC |
9 ms |
8584 KiB |
| 012.txt |
AC |
138 ms |
102928 KiB |
| 013.txt |
AC |
261 ms |
176384 KiB |
| 014.txt |
AC |
243 ms |
164372 KiB |
| 015.txt |
AC |
285 ms |
184264 KiB |
| 016.txt |
AC |
275 ms |
184312 KiB |
| 017.txt |
AC |
274 ms |
184348 KiB |
| 018.txt |
AC |
274 ms |
184468 KiB |
| 019.txt |
AC |
272 ms |
184256 KiB |
| example0.txt |
AC |
2 ms |
3696 KiB |
| example1.txt |
AC |
2 ms |
3808 KiB |