QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#319059#4932. Moon and Sunowen0806WA 2ms12076kbC++201.9kb2024-02-01 18:08:512024-02-01 18:08:51

Judging History

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

  • [2024-02-01 18:08:51]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:12076kb
  • [2024-02-01 18:08:51]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define PB push_back
#define pii pair<int, int>
#define ll long long
using namespace std;
const int N = 2e5 + 5;
const int INF = 1e18;
const int MOD = 235813;
int a[N], arr[N];
ll fac[1000020], inv[1000020];
int qpow(int x, int y){
    int ret = 1;
    while(y){
        if(y & 1) ret = ret * x % MOD;
        x = x * x % MOD;
        y >>= 1;
    }
    return ret;
}
ll getInv(ll a){ return qpow(a,MOD-2); } //逆元
void init(int n){    // O(N)
    fac[0] = 1;
    for(ll i = 1; i <= n; i++)
        fac[i] = fac[i-1] * i % MOD;
    inv[n] = getInv(fac[n]);
    for(ll i = n-1; i >= 0; i--)
        inv[i] = inv[i+1] * (i+1) % MOD;
}

ll C(int n,int m){    //O(1)
    if(m > n)    return 0;
    return fac[n] * inv[m] % MOD * inv[n-m] % MOD;
}
void solve(){
    init(1e5+5);
    int n;
    cin >> n;
    for(int i=1; i<=n; i++) cin >> a[i];

    int sun = 0;
    for(int i=1; i<=n; i++){
        if(i%2) sun = (sun + a[i]*C(n-1, i-1)%MOD) % MOD;
        else sun = (sun - a[i]*C(n-1, i-1)%MOD + MOD) % MOD;
    }
    // cout << sun << endl;

    int ans = 0;
    for(int i=1; i<=n; i++){
        int tmp, mul = C(n-1, i-1);
        if(i%2) tmp = (sun - a[i]*C(n-1, i-1)%MOD + MOD) % MOD;
        else tmp = (sun + a[i]*C(n-1, i-1)%MOD) % MOD;

        int k = tmp * getInv(mul) % MOD;
        int kk = k - MOD;
        if(i%2 && (k == -a[i] || kk == -a[i])) continue;
        if(i%2==0 && (k == a[i] || kk == a[i])) continue;
        // cout << k << " " << kk << endl;
        if(-1e5 <= k && k <= 1e5) ans++;
        if(-1e5 <= kk && kk <= 1e5) ans++;
        // cout << mul * k << " ";
        // if(MOD <= mul * k && mul * k <= MOD) ans++;

    }
    cout << ans << endl;
}
signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int T = 1;
    // cin >> T;
    while(T--){
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 8452kb

input:

5
4 1 0 7 2

output:

3

result:

ok single line: '3'

Test #2:

score: 0
Accepted
time: 2ms
memory: 10448kb

input:

4
10 20 30 -40

output:

4

result:

ok single line: '4'

Test #3:

score: 0
Accepted
time: 0ms
memory: 12076kb

input:

2
100 100

output:

0

result:

ok single line: '0'

Test #4:

score: 0
Accepted
time: 2ms
memory: 8460kb

input:

16
19 43 69 21 72 9 70 -15 25 29 -23 -13 -41 79 -89 93

output:

14

result:

ok single line: '14'

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 10544kb

input:

392
23531 -70064 22423 -55534 23391 -22700 88756 80526 36369 -10007 -28096 22617 -12591 80476 39531 -80144 -87955 93969 33358 30633 34132 -65817 -57922 -28367 -74214 50143 -36912 21570 -27256 -34989 14043 -92315 -12277 26859 97682 91797 -79591 30563 -58224 27016 -67737 99067 30626 16374 -49340 -1712...

output:

323

result:

wrong answer 1st lines differ - expected: '334', found: '323'