QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#477845 | #8049. Equal Sums | c20150005 | TL | 0ms | 3884kb | C++14 | 864b | 2024-07-14 11:40:06 | 2024-07-14 11:40:07 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;using ll=long long;
int rd(int x=0,char c=getchar()){int f=1;while(!isdigit(c))f=(c^'-'?1:-1),c=getchar();while(isdigit(c))x=x*10+(c^48),c=getchar();return f*x;}
const int N=505;const int mod=998244353;
int n,m,l1[N],r1[N],l2[N],r2[N];
int dp[N][N][N<<1];
int md(const int&x){return x>=mod?x-mod:x;}
int main(){
n=rd(),m=rd();
for(int i=1;i<=n;i++)l1[i]=rd(),r1[i]=rd();
for(int i=1;i<=m;i++)l2[i]=rd(),r2[i]=rd();
dp[0][0][500]=1;
for(int i=0;i<=n;i++)for(int j=0;j<=m;j++)for(int k=0;k<=1000;k++){
if(k>=500)for(int w=l2[j+1];w<=r2[j+1];w++)
dp[i][j+1][k-w]=md(dp[i][j+1][k-w]+dp[i][j][k]);
if(k<500)for(int w=l1[i+1];w<=r1[i+1];w++)
dp[i+1][j][k+w]=md(dp[i+1][j][k+w]+dp[i][j][k]);
}
for(int i=1;i<=n;puts(""),i++)for(int j=1;j<=m;j++)printf("%d ",dp[i][j][500]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3884kb
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...