QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#604886 | #4932. Moon and Sun | NMK# | WA | 1ms | 7808kb | C++17 | 1.4kb | 2024-10-02 14:24:14 | 2024-10-02 14:24:16 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 235813,a[1000005];
ll fact[1000005],factInv[1000005];
int n;
ll mpow(ll x,ll M) {
if(!M) return 1;
ll tmp = mpow(x,M/2);
if(M % 2) return tmp*tmp%mod*x%mod;
return tmp*tmp%mod;
}
ll Com(ll x,ll r) {
return fact[x]*factInv[r]%mod*factInv[x-r]%mod;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie();
cin >> n;
fact[0] = 1;
for(int i = 1;i <= n;i++) fact[i] = fact[i-1]*i%mod;
for(int i = 0;i <= n;i++) factInv[i] = mpow(fact[i],mod-2);
for(int i = 1;i <= n;i++) {
cin >> a[i];
}
int op = n%2;
ll val = 0;
for(int i = 1;i <= n;i++) {
val = (val+a[i]*Com(n-1,i-1)*(op ? 1 : -1)%mod);
val %= mod;
op ^= 1;
}
op = n%2;
int ans = 0;
for(int i = 1;i <= n;i++) {
ll t = Com(n-1,i-1)*(op ? 1 : -1);
ll val2 = val-t*a[i]%mod;
val2 %= mod;
val2 += mod;
val2 %= mod;
ll v = mpow((-t+mod)%mod,mod-2)*val2%mod; // v = x
//cout << val2-mod << ' ' << t << '\n';
//cout << v << ' ' << v*mpow((-t+mod)%mod,mod-2)%mod-mod << ' ';
//cout << (val2+v*t)%mod << "\n\n";
if(v > abs(v-mod)) v -= mod;
if(-100000 <= v&&v <= 100000) ans++;
op ^= 1;
}
cout << ans;
}
// ax = b (a = Com(n-1,i-1), b = val2)
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7752kb
input:
5 4 1 0 7 2
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 0ms
memory: 7808kb
input:
4 10 20 30 -40
output:
4
result:
ok single line: '4'
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 7736kb
input:
2 100 100
output:
2
result:
wrong answer 1st lines differ - expected: '0', found: '2'