QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#74332 | #4812. Counting Sequence | Reanap | WA | 1331ms | 27212kb | C++14 | 2.5kb | 2023-01-31 18:38:04 | 2023-01-31 18:38:05 |
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] = 0;
if(n > B) ans = Add(ans , 1);
int lim = B * (B - 1);
for (int i = 2; i <= B; ++i) {
for (int j = 1; 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] , c));
if(j + i <= lim) g[i & 1][j] = Add(g[i & 1][j] , g[(i - 1) & 1][j + i]);
}
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: 1278ms
memory: 14276kb
input:
5 3
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 0
Accepted
time: 1270ms
memory: 13908kb
input:
1 0
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 1298ms
memory: 21152kb
input:
2022 39
output:
273239559
result:
ok 1 number(s): "273239559"
Test #4:
score: 0
Accepted
time: 1274ms
memory: 13964kb
input:
1 998244352
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 1331ms
memory: 14344kb
input:
1 12345678
output:
1
result:
ok 1 number(s): "1"
Test #6:
score: 0
Accepted
time: 1296ms
memory: 13324kb
input:
20 998998
output:
643731701
result:
ok 1 number(s): "643731701"
Test #7:
score: 0
Accepted
time: 1275ms
memory: 13696kb
input:
23 123
output:
947753998
result:
ok 1 number(s): "947753998"
Test #8:
score: 0
Accepted
time: 1322ms
memory: 14588kb
input:
50 5555
output:
745339864
result:
ok 1 number(s): "745339864"
Test #9:
score: 0
Accepted
time: 1310ms
memory: 13600kb
input:
60 6666
output:
690992218
result:
ok 1 number(s): "690992218"
Test #10:
score: 0
Accepted
time: 1304ms
memory: 13644kb
input:
100 50
output:
169678588
result:
ok 1 number(s): "169678588"
Test #11:
score: 0
Accepted
time: 1318ms
memory: 15292kb
input:
500 88888
output:
216149701
result:
ok 1 number(s): "216149701"
Test #12:
score: 0
Accepted
time: 1273ms
memory: 15060kb
input:
1000 213456
output:
270989457
result:
ok 1 number(s): "270989457"
Test #13:
score: 0
Accepted
time: 1294ms
memory: 20744kb
input:
2000 119988
output:
756425375
result:
ok 1 number(s): "756425375"
Test #14:
score: -100
Wrong Answer
time: 1322ms
memory: 27212kb
input:
3000 998244352
output:
71841225
result:
wrong answer 1st numbers differ - expected: '71841227', found: '71841225'