QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#478178 | #8049. Equal Sums | cppcppcpp3 | TL | 0ms | 3648kb | C++14 | 1.3kb | 2024-07-14 18:14:18 | 2024-07-14 18:14:18 |
Judging History
answer
#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
const int N=505;
const int p=998244353;
static char buf[1000000],*p1=buf,*p2=buf;
#define getchar() p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++
inline int wrd(){int x=0,f=1;char c=getchar();while(c<'0' || c>'9'){if(c=='-') f=-1;c=getchar();}while(c>='0' && c<='9') {x=(x<<3)+(x<<1)+c-48;c=getchar();}return x*f;}
inline void write(int x){static char buf[20];static int len=-1;if(x<0)putchar('-'),x=-x;do buf[++len]=x%10,x/=10;while(x);while(len>=0)putchar(buf[len--]+48);}
void ad(int &a,int b){(a+=b)>=p&&(a-=p);}
int n,m,f[N][N][N<<1];
pii a[N],b[N];
signed main(){
n=wrd(),m=wrd();
for(int i=1;i<=n;++i) a[i]={wrd(),wrd()};
for(int i=1;i<=m;++i) b[i]={wrd(),wrd()};
f[0][0][500]=1;
for(int i=0;i<=n;++i){
for(int j=0;j<=m;++j){
for(int k=-500;k<=500;++k){
if(!f[i][j][k+500]) continue;
if(k>0){
if(j<m) for(int t=b[j+1].fi;t<=b[j+1].se;++t){
ad(f[i][j+1][k-t+500],f[i][j][k+500]);
}
}else{
if(i<n) for(int t=a[i+1].fi;t<=a[i+1].se;++t){
ad(f[i+1][j][k+t+500],f[i][j][k+500]);
}
}
}
}
}
for(int i=1;i<=n;++i){
for(int j=1;j<=m;++j) write(f[i][j][500]),putchar(' ');
puts("");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3648kb
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...