QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#765744#8049. Equal Sumswsc2008WA 2857ms13908kbC++142.4kb2024-11-20 15:09:342024-11-20 15:09:39

Judging History

你现在查看的是最新测评结果

  • [2024-11-20 15:09:39]
  • 评测
  • 测评结果:WA
  • 用时:2857ms
  • 内存:13908kb
  • [2024-11-20 15:09:34]
  • 提交

answer

#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define pii pair<ll,ll>
#define rep(i,a,b) for(ll i=(a);i<=(b);++i)
#define per(i,a,b) for(ll i=(a);i>=(b);--i)
using namespace std;
bool Mbe;
ll read(){
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
void write(ll x){
    if(x<0)putchar('-'),x=-x;
    if(x>9)write(x/10);
    putchar(x%10+'0');
}
const ll N=509,Mod=998244353;
ll n,m,L[N],R[N],U[N],V[N],dp[2][N][N*2],dt[N*2],cur,ans[N][N];
bool Med;
int main(){
    cerr<<fabs(&Med-&Mbe)/1048576.0<<"MB\n";
    n=read(),m=read();
    rep(i,1,n)L[i]=read(),R[i]=read();
    rep(i,1,m)U[i]=read(),V[i]=read();
    dp[0][0][0+500]=1;
    //k 表示 A-B
    //k<=0 时转移 A,否则转移 B
    rep(i,0,n){
        memset(dp[cur^1],0,sizeof(dp[cur^1]));
        rep(j,0,m){
            rep(k,1,1000)dt[k]=(dt[k-1]+dt[k])%Mod;
            rep(k,-500,500)dp[cur][j][k+500]=(dp[cur][j][k+500]+dt[k+500])%Mod;
            memset(dt,0,sizeof(dt));
            if(i&&j)ans[i][j]=dp[cur][j][0+500];
            if(j==m)break;
            rep(k,1,500){
                if(!dp[cur][j][k+500])continue;
                // cout<<i<<" "<<j<<" "<<k<<" "<<dp[cur][j][k+500]<<endl;
                ll l=k-V[j+1],r=k-U[j+1];
                l=max(l,-500ll);
                if(l>r)continue;
                dt[l+500]=(dt[l+500]+dp[cur][j][k+500])%Mod;
                dt[r+500+1]=(dt[r+500+1]-dp[cur][j][k+500]+Mod)%Mod;
            }
        }
        if(i<n){
            rep(j,0,m){
                memset(dt,0,sizeof(dt));
                rep(k,-500,0){
                    if(!dp[cur][j][k+500])continue;
                    ll l=k+L[i+1],r=k+R[i+1];
                    r=min(r,500ll);
                    if(l>r)continue;
                    dt[l+500]=(dt[l+500]+dp[cur][j][k+500])%Mod;
                    dt[r+500+1]=(dt[r+500+1]-dp[cur][j][k+500]+Mod)%Mod;
                }
                rep(k,1,1000)dt[k]=(dt[k-1]+dt[k])%Mod;
                rep(k,-500,500)dp[cur^1][j][k+500]=(dp[cur^1][j][k+500]+dt[k+500])%Mod;
            }
            cur^=1;
        }
    }
    rep(i,1,n){
        rep(j,1,m)write(ans[i][j]),putchar(' ');
        putchar('\n');
    }
    cerr<<"\n"<<clock()*1.0/CLOCKS_PER_SEC*1000<<"ms\n";
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 12468kb

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
Wrong Answer
time: 2857ms
memory: 13908kb

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:

411 79401 9145270 673005095 180581065 984223118 586589234 293043270 404363796 865361724 665487988 118838806 926189944 226338288 521479857 808644951 786041288 340769021 177100 21 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 ...

result:

wrong answer 13501st numbers differ - expected: '0', found: '934630338'