QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#90851#5530. No Zero-Sum SubsegmentSorting#WA 70ms65844kbC++1.7kb2023-03-25 20:01:032023-03-25 20:01:04

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-25 20:01:04]
  • 评测
  • 测评结果:WA
  • 用时:70ms
  • 内存:65844kb
  • [2023-03-25 20:01:03]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
const ll mod=998244353;
ll a,b,c,d;
typedef array<ll,3> arin;
const int iu=4e6;
ll f[iu+1];
ll inf[iu+1];
ll pw(ll x,ll y){
	if(y==0) return 1;
	if(y%2) return x*pw(x,y-1)%mod;
	ll res=pw(x,y/2);
	return res*res%mod;
}
ll e(ll a,ll b,ll c){
	if(a<0 || b<0 || c<0) return 0;
	return f[a+b+c]*inf[a]%mod*inf[b]%mod*inf[c]%mod;
}
ll h(ll a,ll b,ll c){//ways to arrange such that start and end is 2
	c-=2*b;
	//cout << "tmp " << a << ' ' << b << ' ' << c << endl;
	if(a<0 || b<0 || c<0) return 0;
	ll ans=(e(a,b,c)-e(a-1,b,c)*2+e(a-2,b,c)+2*mod+(a==1 && b==0 && c==0))%mod;
	//cout << ans << endl;
	return ans;
}
ll g(ll a,ll b,ll c){
	ll calc=(h(a,b,c)+h(a,b-1,c-1)*2+h(a,b-2,c-2))%mod;
	//cout << "G " << a << ' ' << b << ' ' << c << ' ' << calc << endl;
	return calc;
}
arin cal(ll a,ll b,ll c){
	arin res;
	res[0]=h(a,b,c);
	res[1]=h(a,b,c+1)*2%mod;
	res[1]=(res[1]+2*mod-2*res[0])%mod;
	res[2]=h(a,b,c+2);
	res[2]=(res[2]+2*mod-res[1]-res[0])%mod;
	return res;
}
void solve(){
	cin >> a >> b >> c >> d;
	if(b+c==0){
		cout << (a==0 || d==0) << '\n';
		return;
	}
	if(b+c==1){
		cout << (1+(a!=0 || d!=0)) << '\n';
		return;
	}
	if((d-a)*2+(c-b)<0){
		swap(a,d);
		swap(b,c);
	}
	swap(a,d);
	if(a<d){
		cout << "0\n";
		return;
	}
	auto v=cal(c,b,a-d);
	//cout << v[0] << ' ' << v[1] << ' ' << v[2] << endl;
	ll ans=(v[0]*(d==0)+v[1]+v[2]*(d+1))%mod;
	cout << ans << '\n';
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	f[0]=1;
	for(int i=1; i<=iu ;i++){
		f[i]=f[i-1]*i%mod;
	}
	inf[iu]=pw(f[iu],mod-2);
	for(int i=iu; i>=1 ;i--){
		inf[i-1]=inf[i]*i%mod;
	}
	int t;cin >> t;while(t--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 27ms
memory: 65844kb

input:

5
69 0 0 0
1 1 1 1
0 0 3 3
6 1 0 6
10000 10000 1000000 1000000

output:

1
0
20
2
480402900

result:

ok 5 number(s): "1 0 20 2 480402900"

Test #2:

score: -100
Wrong Answer
time: 70ms
memory: 65804kb

input:

83520
13 1 6 8
13 9 3 14
1 16 13 0
8 12 7 16
10 5 9 15
16 16 15 1
5 11 0 4
12 4 11 15
16 7 1 10
2 6 3 3
15 14 12 0
0 8 12 12
3 0 6 7
16 2 16 15
16 16 16 13
8 13 2 14
7 9 7 0
9 8 4 6
13 16 4 11
11 1 12 4
7 9 4 16
12 13 0 4
5 0 9 1
11 11 0 3
1 11 14 3
3 3 7 3
8 5 4 4
6 7 12 14
2 11 5 6
15 4 9 14
15 11...

output:

0
0
0
0
0
0
52
0
26784
0
0
0
392
0
0
0
0
0
0
0
0
478686
0
136136
0
0
0
0
0
0
0
1680
0
821
0
24024
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8994258
0
0
0
0
0
293930
0
0
156637
166
0
0
0
0
0
0
0
0
0
54
0
0
1248
126
0
0
0
344
0
9867
10880
544
0
0
0
0
0
216580
0
0
4620
0
0
0
0
0
57915
0
0
0
10
0
72442440
0
1085473...

result:

wrong answer 952nd numbers differ - expected: '17', found: '2'