QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#764256 | #8049. Equal Sums | byron10000 | ML | 1ms | 3796kb | C++14 | 1.5kb | 2024-11-20 08:19:44 | 2024-11-20 08:19:53 |
Judging History
answer
#if defined(_USE_PCH_)
#include "pch.hpp"
#else
#include <bits/stdc++.h>
#endif
#define RNG(V_, A_, B_, ...) for(int V_=(A_), V_##_END=(B_) __VA_OPT__(,) __VA_ARGS__; V_<=V_##_END; V_++)
#define IRNG(V_, A_, B_, ...) for(int V_=(A_), V_##_END=(B_) __VA_OPT__(,) __VA_ARGS__; V_>=V_##_END; V_--)
#ifdef _WIN32
#define long int64_t
#endif
#define fi first
#define se second
#define _UN using namespace
using namespace std;
typedef pair<int,int> pii;
typedef __int128 i128;
const int MAXN=510; const long MOD=998244353;
int n,m;
struct{ int l,r; } A[MAXN],B[MAXN];
long F[MAXN][MAXN][MAXN*2];
void addto(long& x,long y){ x=(x+y+MOD)%MOD; }
int main(){
#if defined(_LOCAL_)
freopen("in","r",stdin);
// freopen("out","w",stdout);
// freopen("/dev/null","w",stderr);
#else
#endif
ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
cin>>n>>m;
RNG(i,1,n) cin>>A[i].l>>A[i].r;
RNG(i,1,m) cin>>B[i].l>>B[i].r;
const auto M=501;
F[0][0][M]=1,F[0][0][M+1]=-1;
RNG(i,0,n){
RNG(j,0,m){
RNG(a,-M+1,M){
addto(F[i][j][M+a],F[i][j][M+a-1]);
if(!F[i][j][M+a]) continue;
if(i<n&&a<=0) addto(F[i+1][j][M+a+A[i+1].l],F[i][j][M+a]),addto(F[i+1][j][M+a+A[i+1].r+1],-F[i][j][M+a]);
if(j<m&&a>0) addto(F[i][j+1][M+a-B[j+1].r],F[i][j][M+a]),addto(F[i][j+1][M+a-B[j+1].l+1],-F[i][j][M+a]);
}
}
}
RNG(i,1,n){
RNG(j,1,m) cout<<F[i][j][M]<<" ";
cout<<"\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3796kb
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
Memory 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...
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 ...