QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#461049#8486. CasinoLynkcat#WA 11ms19404kbC++141.4kb2024-07-02 15:31:572024-07-02 15:31:57

Judging History

This is the latest submission verdict.

  • [2024-07-02 15:31:57]
  • Judged
  • Verdict: WA
  • Time: 11ms
  • Memory: 19404kb
  • [2024-07-02 15:31:57]
  • Submitted

answer

#include<bits/stdc++.h>
#define poly vector<int>
#define IOS ios::sync_with_stdio(false)
#define ll long long
#define mp make_pair
#define mt make_tuple
#define pa pair < int,int >
#define fi first
#define se second
#define inf 1e18
#define mod 998244353
#define sz(x) ((int)((x).size()))
#define int ll
// #define N 
using namespace std;
const int N=1000005;
int fac[N],inv[N];
inline int quickPower(int x,int y)
{
    int res=1;
    while (y)
    {
        if (y&1)res=res*x%mod;
        x=x*x%mod;
        y>>=1;
    }
    return res;
}
inline int C(int x,int y)
{
    if (x<y||y<0) return 0;
    return fac[x]*inv[y]%mod*inv[x-y]%mod;
}
void BellaKira()
{
    fac[0]=1;
    for (int i=1;i<N;i++) fac[i]=fac[i-1]*i%mod;
    inv[N-1]=quickPower(fac[N-1],mod-2);
    for (int i=N-1;i>=1;i--) inv[i-1]=inv[i]*i%mod;
    int n;
    cin>>n;
    poly cnt(3,0);
    int ans=0;
    for (int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        cnt[x%3]++;
    }
    // cout<<cnt[1]<<" "<<cnt[2]<<" "<<cnt[0]<<endl;
    if (cnt[1]==cnt[2]+1||cnt[1]==cnt[2]+2)
    {
        ans=(ans+fac[cnt[1]]*fac[cnt[2]]%mod*C(n-1,cnt[0])%mod)%mod;
    }
    if (cnt[2]==cnt[1]+1||cnt[2]==cnt[1]+2)
    {
        ans=(ans+fac[cnt[1]]*fac[cnt[2]]%mod*C(n-1,cnt[0])%mod)%mod;
    }
    cout<<ans<<'\n';

}
signed main()
{
	IOS;
	cin.tie(0);
	int T=1;
	while (T--)
	{
		BellaKira();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 19164kb

input:

3
100 21 892

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 11ms
memory: 19404kb

input:

4
11 19 30 32

output:

6

result:

ok 1 number(s): "6"

Test #3:

score: 0
Accepted
time: 7ms
memory: 19168kb

input:

3
4 298 28

output:

0

result:

ok 1 number(s): "0"

Test #4:

score: -100
Wrong Answer
time: 7ms
memory: 19216kb

input:

5
24 27 38 46 94

output:

12

result:

wrong answer 1st numbers differ - expected: '24', found: '12'