QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#405135 | #8049. Equal Sums | Alish | TL | 1ms | 3684kb | C++17 | 1.4kb | 2024-05-05 11:53:28 | 2024-05-05 11:53:30 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define F first
#define S second
#define pb push_back
#define endl '\n'
#define Mp make_pair
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " = " << x << endl;
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("tests.in" , "r" , stdin) ;
ll mod = 998244353 ;
const int N = 507, M=502;
int dp[N][N][2*N];
int a[N], b[N];
int l1[N], r1[N], l2[N], r2[N];
int n, m;
int main()
{
fast_io
cin>>n>>m;
for (int i=1; i<=n; i++) cin>>l1[i]>>r1[i];
for (int i=1; i<=m; i++) cin>>l2[i]>>r2[i];
dp[0][0][M]=1;
for(int i=0; i<=n; i++) {
for(int j=0; j<=m; j++) {
if(i || j) for(int k=1; k<2*M; k++) dp[i][j][k]=(dp[i][j][k]+dp[i][j][k-1])%mod;
if(i && j) cout<<dp[i][j][M]<<" ";
for (int k=0; k<M; k++){
dp[i+1][j][k+l1[i+1]]=(dp[i+1][j][k+l1[i+1]]+dp[i][j][k])%mod;
dp[i+1][j][k+r1[i+1]+1]=(dp[i+1][j][k+r1[i+1]+1]-dp[i][j][k]+mod)%mod;
dp[i][j+1][M-r2[j+1]+k]=(dp[i][j+1][M-r2[j+1]+k]+dp[i][j][M+k])%mod;
dp[i][j+1][M-l2[j+1]+1+k]=(dp[i][j+1][M-l2[j+1]+1+k]-dp[i][j][M+k]+mod )%mod;
}
}
if(i) cout<<endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3684kb
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...
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 ...