QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#336066 | #8049. Equal Sums | xuqin | WA | 899ms | 8984kb | C++14 | 2.4kb | 2024-02-24 12:48:38 | 2024-02-24 12:48:39 |
Judging History
answer
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<utility>
#include<ctime>
#include<vector>
#include<queue>
#include<iostream>
#include<set>
#include<random>
#include<string>
#include<cmath>
#include<chrono>
#include<map>
#define eb emplace_back
using namespace std;
const int maxn=5e2+10, maxm=1.2e4+10, inf=2e9+12, P=998244353;
typedef long long LL;
typedef unsigned long long ULL;
const LL INF=4e18;
typedef pair<int, int> pii;
typedef pair<LL, int> pli;
typedef pair<int, LL> pil;
inline int read() {
int x=0, f=1; char c=getchar();
for(; c<'0'||c>'9'; c=getchar()) if(c=='-') f=0;
for(; c>='0'&&c<='9'; c=getchar()) x=x*10+c-'0';
return f?x:-x;
}
inline int add(int x, int y) {x+=y; return x>=P?x-P:x;}
inline int del(int x, int y) {x-=y; return x<0?x+P:x;}
inline int ksm(int x, int y) {
int s=1; for(; y; y>>=1, x=1LL*x*x%P) if(y&1) s=1LL*s*x%P; return s;
}
mt19937 rnd((unsigned)chrono::steady_clock::now().time_since_epoch().count());
int gcd(int x, int y) {return y?gcd(y, x%y):x;}
int lx[maxn], rx[maxn], ly[maxn], ry[maxn];
int f[2][maxn][maxn<<1], ans[maxn][maxn];
int main() {
int n=read(), m=read();
int V=0;
for(int i=1; i<=n; ++i) lx[i]=read(), rx[i]=read(), V=max(V, rx[i]);
for(int i=1; i<=m; ++i) ly[i]=read(), ry[i]=read(), V=max(V, ry[i]);
int M=maxn, cur=0;
f[0][0][M]=1;
for(int _=0; _<n+m; ++_, cur^=1) {
for(int i=0; i<=n; ++i) for(int s=M-V; s<=M+V; ++s) f[cur^1][i][s]=0;
for(int i=0; i<=_&&i<=n; ++i) //i _-i
for(int s=M-V; s<=M+V; ++s) {
int val=f[cur][i][s]; if(val==0) continue;
if(s<M&&i<n) {
f[cur^1][i+1][s+lx[i+1]]=add(f[cur^1][i+1][s+lx[i+1]], val);
f[cur^1][i+1][s+rx[i+1]+1]=del(f[cur^1][i+1][s+rx[i+1]+1], val);
}
if(s>=M&&_-i<m) {
f[cur^1][i][s-ry[_-i+1]]=add(f[cur^1][i][s-ry[_-i+1]], val);
f[cur^1][i][s-ly[_-i+1]+1]=del(f[cur^1][i][s-ly[_-i+1]+1], val);
}
}
for(int i=0; i<=_+1&&i<=n; ++i)
for(int s=M-V; s<=M+V; ++s) f[cur^1][i][s]=add(f[cur^1][i][s], f[cur^1][i][s-1]);
for(int i=1; i<=_+1&&i<=n; ++i) ans[i][_+1-i]=f[cur^1][i][M];
}
for(int i=1; i<=n; ++i, puts(""))
for(int j=1; j<=m; ++j) printf("%d ", ans[i][j]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5848kb
input:
2 3 1 2 2 3 1 4 2 2 1 3
output:
2 0 0 3 4 4
result:
ok 6 numbers
Test #2:
score: -100
Wrong Answer
time: 899ms
memory: 8984kb
input:
500 500 19 458 1 480 7 485 50 461 12 476 15 461 48 466 40 453 46 467 9 458 27 478 26 472 46 459 29 490 6 500 17 487 48 484 28 472 28 459 25 480 4 491 29 481 36 460 2 491 44 499 22 473 20 458 4 483 27 471 2 496 11 461 43 450 2 478 37 466 15 459 42 482 7 451 19 455 2 453 47 475 48 450 1 474 46 471 9 4...
output:
411 79401 9145270 673005095 180581065 984223118 586589234 293043270 404363796 865361724 665487988 118838806 926189944 226338288 521479857 808644951 786041288 340769021 177100 21 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer 501st numbers differ - expected: '97494', found: '0'