QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#478114 | #8049. Equal Sums | XiaoZi_qwq | TL | 1ms | 5920kb | C++14 | 1.4kb | 2024-07-14 17:15:10 | 2024-07-14 17:15:11 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
inline int max(int a,int b){return a>b?a:b;}
inline int read(){
register int x=0,f=1;
char c=getchar();
while(c<'0' || '9'<c) f=(c=='-')?-1:1,c=getchar();
while('0'<=c && c<='9') x=(x<<3)+(x<<1)+c-'0',c=getchar();
return x*f;
}
const int N=510,mod=998244353;
int n,m,xl[N],xr[N],yl[N],yr[N],f[N][N][2*N],dx[N][2],dy[N][2];
bool able[N][N];
int main()
{
//freopen("test1.in","r",stdin);
n=read(),m=read();
for(int i=1;i<=n;i++) xl[i]=read(),xr[i]=read(),dx[i][1]=dx[i-1][1]+xr[i],dx[i][0]=dx[i-1][0]+xl[i];
for(int i=1;i<=m;i++) yl[i]=read(),yr[i]=read(),dy[i][1]=dy[i-1][1]+yr[i],dy[i][0]=dy[i-1][0]+yl[i];
for(int i=xl[1];i<=xr[1];i++)
for(int j=yl[1];j<=yr[1];j++)
f[1][1][i-j+500]++;
able[1][1]=true;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++){
if(!able[i][j]) continue;
for(int k=0;k<=1000;k++){
if(f[i][j][k]==0) continue;
if(k<=500){
for(int l=xl[i+1];l<=xr[i+1];l++)
f[i+1][j][k+l]=(f[i+1][j][k+l]+f[i][j][k])%mod;
able[i+1][j]=true;
}
else{
for(int l=yl[j+1];l<=yr[j+1];l++)
f[i][j+1][k-l]=(f[i][j+1][k-l]+f[i][j][k])%mod;
able[i][j+1]=true;
}
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++)
printf("%d ",f[i][j][500]);
putchar('\n');
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5920kb
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
Time 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...