QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#74333 | #4812. Counting Sequence | Reanap | WA | 1792ms | 28456kb | C++14 | 2.5kb | 2023-01-31 18:45:04 | 2023-01-31 18:45:06 |
Judging History
answer
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <iostream>
#include <algorithm>
#define pii pair <int , int>
#define pll pair <LL , LL>
#define mp make_pair
#define fs first
#define sc second
using namespace std;
typedef long long LL;
//const int Mxdt=100000;
//static char buf[Mxdt],*p1=buf,*p2=buf;
//#define getchar() p1==p2&&(p2=(p1=buf)+fread(buf,1,Mxdt,stdin),p1==p2)?EOF:*p1++;
template <typename T>
void read(T &x) {
T f=1;x=0;char s=getchar();
while(s<'0'||s>'9') {if(s=='-') f=-1;s=getchar();}
while(s>='0'&&s<='9') {x=(x<<3)+(x<<1)+(s^'0');s=getchar();}
x *= f;
}
template <typename T>
void write(T x , char s='\n') {
if(!x) {putchar('0');putchar(s);return;}
if(x<0) {putchar('-');x=-x;}
T t = 0 , tmp[25] = {};
while(x) tmp[t ++] = x % 10 , x /= 10;
while(t -- > 0) putchar(tmp[t] + '0');
putchar(s);
}
const int MAXN = 3e5 + 5;
const int B = 800;
const int mod = 998244353;
inline int Add(int x , int y) {x += y;return x >= mod?x - mod:x;}
inline int Sub(int x , int y) {x -= y;return x < 0?x + mod:x;}
inline int Mul(int x , int y) {return 1ll * x * y % mod;}
inline int qpow(int a , int b) {
int res = 1;
while(b) {
if(b & 1) res = Mul(res , a);
a = Mul(a , a);
b >>= 1;
}
return res;
}
int f[(B << 2) + 5][(B << 1) + 5] , n , c;
inline int Get(int x) {
return ((x / (B << 1)) & 1) * (B << 1) + (x % (B << 1));
}
int g[2][B * (B - 1) + 5];
int main() {
read(n),read(c);
for (int i = 1; i <= B; ++i) f[Get(i)][i] = 1;
for (int i = 0; i < n; ++i) for (int j = 1; j <= B * 2; ++j) if(i + j - 1 <= n) {
int cur = Get(i);
if(j > 1 && i + j - 1 <= n) f[Get(i + j - 1)][j - 1] = Add(f[Get(i + j - 1)][j - 1] , Mul(c , f[cur][j]));
if(j < B * 2 && i + j + 1 <= n) f[Get(i + j + 1)][j + 1] = Add(f[Get(i + j + 1)][j + 1] , f[cur][j]);
f[cur][j] = 0;
}
int ans = 0;
for (int j = 1; j <= B * 2; ++j) ans = Add(ans , f[Get(n)][j]);
// write(ans);
int Z = B * (B - 1) / 2;
g[1][Z] = 1;
if(n > B) ans = Add(ans , 1);
int lim = B * (B - 1);
for (int i = 2; i <= B; ++i) {
for (int j = 0; j <= lim; ++j) {
g[i & 1][j] = 0;
if(j >= i) g[i & 1][j] = Add(g[i & 1][j] , Mul(g[(i - 1) & 1][j - (i - 1)] , c));
if(j + i <= lim) g[i & 1][j] = Add(g[i & 1][j] , g[(i - 1) & 1][j + (i - 1)]);
}
for (int j = B + 1; j <= n; ++j) if(n - j * i + Z <= lim && n - j * i + Z >= 0) ans = Add(ans , g[i & 1][n - j * i + Z]);
}
write(ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1395ms
memory: 14340kb
input:
5 3
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 0
Accepted
time: 1402ms
memory: 14156kb
input:
1 0
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 1476ms
memory: 21124kb
input:
2022 39
output:
273239559
result:
ok 1 number(s): "273239559"
Test #4:
score: 0
Accepted
time: 1437ms
memory: 14020kb
input:
1 998244352
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 1490ms
memory: 15040kb
input:
1 12345678
output:
1
result:
ok 1 number(s): "1"
Test #6:
score: 0
Accepted
time: 1409ms
memory: 14344kb
input:
20 998998
output:
643731701
result:
ok 1 number(s): "643731701"
Test #7:
score: 0
Accepted
time: 1398ms
memory: 14132kb
input:
23 123
output:
947753998
result:
ok 1 number(s): "947753998"
Test #8:
score: 0
Accepted
time: 1446ms
memory: 14328kb
input:
50 5555
output:
745339864
result:
ok 1 number(s): "745339864"
Test #9:
score: 0
Accepted
time: 1417ms
memory: 14080kb
input:
60 6666
output:
690992218
result:
ok 1 number(s): "690992218"
Test #10:
score: 0
Accepted
time: 1399ms
memory: 13580kb
input:
100 50
output:
169678588
result:
ok 1 number(s): "169678588"
Test #11:
score: 0
Accepted
time: 1434ms
memory: 14604kb
input:
500 88888
output:
216149701
result:
ok 1 number(s): "216149701"
Test #12:
score: 0
Accepted
time: 1405ms
memory: 14708kb
input:
1000 213456
output:
270989457
result:
ok 1 number(s): "270989457"
Test #13:
score: 0
Accepted
time: 1470ms
memory: 20812kb
input:
2000 119988
output:
756425375
result:
ok 1 number(s): "756425375"
Test #14:
score: 0
Accepted
time: 1586ms
memory: 27088kb
input:
3000 998244352
output:
71841227
result:
ok 1 number(s): "71841227"
Test #15:
score: 0
Accepted
time: 1447ms
memory: 27144kb
input:
3000 555555555
output:
79880116
result:
ok 1 number(s): "79880116"
Test #16:
score: 0
Accepted
time: 1484ms
memory: 28332kb
input:
4321 1234
output:
949603993
result:
ok 1 number(s): "949603993"
Test #17:
score: 0
Accepted
time: 1480ms
memory: 28336kb
input:
5000 0
output:
5
result:
ok 1 number(s): "5"
Test #18:
score: 0
Accepted
time: 1487ms
memory: 28388kb
input:
5000 88888777
output:
833064960
result:
ok 1 number(s): "833064960"
Test #19:
score: 0
Accepted
time: 1482ms
memory: 28456kb
input:
5000 35557777
output:
696388498
result:
ok 1 number(s): "696388498"
Test #20:
score: 0
Accepted
time: 1600ms
memory: 28456kb
input:
10000 123456
output:
434296902
result:
ok 1 number(s): "434296902"
Test #21:
score: -100
Wrong Answer
time: 1792ms
memory: 28388kb
input:
20000 555555
output:
682438420
result:
wrong answer 1st numbers differ - expected: '34806915', found: '682438420'