QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#74335 | #4812. Counting Sequence | Reanap | WA | 2168ms | 8764kb | C++14 | 2.5kb | 2023-01-31 19:24:41 | 2023-01-31 19:24:41 |
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 << 2));
}
int g[2][B * (B + 1) + 5];
int main() {
read(n),read(c);
for (int i = 1; i < n; ++i) {
int cur = Get(i);
if(i <= B) f[cur][i] = Add(f[cur][i] , 1);
for (int j = 1; j <= B * 2; ++j) if(i + j - 1 <= n) {
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]);
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] , g[(i - 1) & 1][j - (i - 1)]);
if(j + i <= lim) g[i & 1][j] = Add(g[i & 1][j] , Mul(g[(i - 1) & 1][j + (i - 1)] , c));
}
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: 0
Wrong Answer
time: 2168ms
memory: 8764kb
input:
5 3
output:
7
result:
wrong answer 1st numbers differ - expected: '8', found: '7'