QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#453515 | #8049. Equal Sums | ucup-team3282 | ML | 0ms | 3732kb | C++14 | 1.6kb | 2024-06-23 22:54:32 | 2024-06-23 22:54:33 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=510;
const int mod=998244353;
const int maxv=300;
int n,m;
int la[maxn],ra[maxn],lb[maxn],rb[maxn];
int f[maxn][maxn][maxv*2+10],s[maxn][maxn][maxv*2+10];
int pls(int x,int y){
return x+y<mod?x+y:x+y-mod;
}
int main(){
ios::sync_with_stdio(0);
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>la[i]>>ra[i];
for(int j=1;j<=m;j++)
cin>>lb[j]>>rb[j];
for(int k=-maxv;k<=maxv;k++){
if(la[1]<=k&&k<=ra[1])
f[1][0][k+maxv+1]=1;
s[1][0][k+maxv+1]=pls(s[1][0][k-1+maxv+1],f[1][0][k+maxv+1]);
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
// cout<<"---------------------"<<i<<' '<<j<<"---------------------"<<endl;
for(int k=-maxv;k<=maxv;k++){
if(k<=ra[i] && k-max(k,la[i])>=-maxv){
// cout<<'\t'<<max(k-ra[i],-maxv)<<"~"<<k-max(k,la[i])<<" -> "<<k<<endl;
f[i][j][k+maxv+1]=pls(pls(mod-s[i-1][j][max(k-ra[i],-maxv)-1 +maxv+1],
s[i-1][j][k-max(k,la[i])+maxv+1]),f[i][j][k+maxv+1]);
}
if(-k+1<=rb[j] && k+max(-k+1,lb[j])<=maxv){
// cout<<'\t'<<k+max(-k+1,lb[j])<<"~"<<min(k+rb[j],maxv)<<" -> "<<k<<endl;
f[i][j][k+maxv+1]=pls(pls(mod-s[i][j-1][k+max(-k+1,lb[j])-1 +maxv+1],
s[i][j-1][min(k+rb[j],maxv) +maxv+1]),f[i][j][k+maxv+1]);
}
// cout<<"f "<<i<<' '<<j<<' '<<k<<' '<<f[i][j][k+maxv+1]<<endl;
s[i][j][k+maxv+1]=pls(s[i][j][k-1+maxv+1],f[i][j][k+maxv+1]);
}
}
}
for(int i=1;i<=n;i++,cout<<endl)
for(int j=1;j<=m;j++)
cout<<f[i][j][maxv+1]<<' ';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3732kb
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
Memory Limit Exceeded
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:
253 28920 1823471 64684950 369289507 321579783 911819072 179865406 455257174 416949810 901983192 17383860 14 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 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...