QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#453531 | #8049. Equal Sums | ucup-team3282 | WA | 1ms | 3720kb | C++14 | 1.6kb | 2024-06-23 23:08:06 | 2024-06-23 23:08:07 |
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=500;
int n,m;
int la[maxn],ra[maxn],lb[maxn],rb[maxn];
int f[2][maxn][maxv*2+10],s[2][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++){
f[i&1][j][k]=s[i&1][j][k]=0;
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&1][j][k+maxv+1]=pls(pls(mod-s[i&1^1][j][max(k-ra[i],-maxv)-1 +maxv+1],
s[i&1^1][j][k-max(k,la[i])+maxv+1]),f[i&1][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&1][j][k+maxv+1]=pls(pls(mod-s[i&1][j-1][k+max(-k+1,lb[j])-1 +maxv+1],
s[i&1][j-1][min(k+rb[j],maxv) +maxv+1]),f[i&1][j][k+maxv+1]);
}
// cout<<"f "<<i<<' '<<j<<' '<<k<<' '<<f[i&1][j][k+maxv+1]<<endl;
s[i&1][j][k+maxv+1]=pls(s[i&1][j][k-1+maxv+1],f[i&1][j][k+maxv+1]);
}
cout<<f[i&1][j][maxv+1]<<' ';
}
cout<<endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3720kb
input:
2 3 1 2 2 3 1 4 2 2 1 3
output:
2 0 998244351 0 7 9
result:
wrong answer 3rd numbers differ - expected: '0', found: '998244351'