QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#513626 | #5530. No Zero-Sum Subsegment | jaker | WA | 26ms | 27316kb | C++20 | 4.0kb | 2024-08-10 18:47:08 | 2024-08-10 18:47:08 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = j;i <= k;++i)
#define repp(i,j,k) for(int i = j;i >= k;--i)
#define ld long double
const int p = 998244353;
int A,B,C,D,a,b,c,d;
bool fl = true;
int ksm(int a,int b) {
int res = 1;
while(b) {
if(b&1) res = 1ll*res*a%p;
b >>= 1;
a = 1ll*a*a%p;
}
return res;
}
void pre(int tp1,int tp2) {
fl = true;
a = A; b = B; c = C; d = D;
if( tp1 == 1 && tp2 == 1 ) {
if( D < 2 || A <= D || C == 0 || B == 0 ) { fl = false; return;}
else { b = B-1; c = C-1; d = 0; a = A - D - 1; }
}
else if( tp1 == 1 && tp2 == 2 ) {
if( D < 2 || A <= D+1 || C < 2 ) { fl = false; return; }
else { b = B; c = C - 2; d = 0; a = A - D - 2; }
}
else if( tp1 == 1 && tp2 == 3 ) {
if( D == 0 || C < 2 || A <= D+1 ) { fl = false; return; }
else { b = B; c = C - 2; d = 0; a = A - D - 2; }
}
else if( tp1 == 1 && tp2 == 4 ) {
if( D == 0 || C == 0 || A <= D ) { fl = false; return; }
else { b = B; c = C - 1; d = 0; a = A - D - 1; }
}
else if( tp1 == 2 && tp2 == 1 ) {
if( D < 2 || B < 2 || A < D ) { fl = false; return; }
else { b = B - 2; c = C; d = 0; a = A - D; }
}
else if( tp1 == 2 && tp2 == 2 ) {
if( D < 2 || C == 0 || B == 0 || A <= D ) { fl = false; return; }
else { b = B - 1; c = C - 1; d = 0; a = A - D - 1; }
}
else if( tp1 == 2 && tp2 == 3 ) {
if( D == 0 || C == 0 || B == 0 || A <= D ){ fl = false; return; }
else { b = B - 1; c = C - 1; d = 0; a = A - D - 1; }
}
else if( tp1 == 2 && tp2 == 4 ) {
if( D == 0 || B == 0 || A < D ){ fl = false; return; }
else { b = B - 1; c = C; d = 0; a = A - D; }
}
else if( tp1 == 3 && tp2 == 1 ) {
if( D == 0 || B == 0 || A < D ) { fl = false; return; }
else { b = B - 1; c = C; d = 0; a = A - D; }
}
else if( tp1 == 3 && tp2 == 2 ) {
if( D == 0 || C == 0 || A <= D ) { fl = false; return; }
else { b = B; c = C - 1; d = 0; a = A - D - 1; }
}
else if( tp1 == 3 && tp2 == 3 ) {
if( A == 0 || C == 0 || D != 0 ) { fl = false; return; }
else { b = B; c = C - 1; d = 0; a = A - 1; }
}
else if( tp1 == 3 && tp2 == 4 ) {
if( D != 0 ) { fl = false; return; }
else { b = B; c = C; d = 0; a = A; }
}
else if( tp1 == 4 && tp2 == 1 ) {
if( D == 0 || B == 0 || C == 0 || A <= D ) { fl = false; return; }
else { b = B - 1; c = C - 1; d = 0; a = A - D - 1; }
}
else if( tp1 == 4 && tp2 == 2 ) {
if( D == 0 || C <= 1 || A <= D+1 ) { fl = false; return; }
else { b = B; c = C - 2; d = 0; a = A - D - 2; }
}
else if( tp1 == 4 && tp2 == 3 ) {
if( D != 1 || A == 0 || C <= 1 ) { fl = false; return; }
else { b = B; c = C - 2; d = 0; a = A - 1; }
}
else if( tp1 == 4 && tp2 == 4 ) {
if( D != 0 || C == 0 || A == 0 ) { fl = false; return; }
else { b = B; c = C - 1; d = 0; a = A - 1; }
}
}
int fac[3001000],inv[3001000];
int ans = 0;
void calc(int tp1,int tp2) {
pre(tp1,tp2);
if( !fl ) return;
a -= 2*c;
if( a < 0 || b < 0 || c < 0 ) return;
ans = ( ans + 1ll*fac[a+b+c]*inv[a]%p*inv[b]%p*inv[c]%p )%p;
printf("#%d %d %d\n",tp1,tp2,ans);
}
int main(){
fac[0] = 1; rep(i,1,3000000) fac[i] = 1ll*fac[i-1]*i%p;
inv[3000000] = ksm(fac[3000000],p-2); repp(i,3000000-1,0) inv[i] = 1ll*inv[i+1]*(i+1)%p;
int T; scanf("%d",&T);
while(T--) {
scanf("%d%d%d%d",&D,&C,&B,&A);
int S = 2*A+B-2*C-2*D;
if( S < 0 ) {
S = -S;
swap(A,D); swap(B,C);
}
ans = 0;
calc(1,1);calc(1,2);calc(1,3); calc(1,4);
calc(2,1);calc(2,2);calc(2,3); calc(2,4);
calc(3,1);calc(3,2);calc(3,3); calc(3,4);
calc(4,1);calc(4,2);calc(4,3); calc(4,4);
printf("%d\n",ans);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 26ms
memory: 27316kb
input:
5 69 0 0 0 1 1 1 1 0 0 3 3 6 1 0 6 10000 10000 1000000 1000000
output:
#3 4 1 1 0 #3 4 20 20 #2 4 1 #3 1 2 2 #1 1 465896533 #1 2 864720913 #1 3 265300940 #1 4 409145480 #2 1 857111128 #2 2 324763308 #2 3 790659841 #2 4 356813909 #3 1 921212330 #3 2 66812517 #4 1 532709050 #4 2 931533430 931533430
result:
wrong output format Expected integer, but "#3" found