QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#135488 | #5744. Palindromic Differences | tselmegkh# | WA | 1ms | 3576kb | C++20 | 2.6kb | 2023-08-05 16:12:44 | 2023-08-05 16:12:46 |
Judging History
answer
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iomanip>
using namespace std;
const int N = 5e5 + 5, inf = 1e9;
#define pb push_back
#define mp make_pair
#define ll long long
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define sz(x) (int)x.size()
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int mod = 1e9 + 9;
ll binpow(ll a, ll b, ll m){
a %= m;
ll res = 1;
while(b > 0){
if(b & 1)
res = res * a % m;
a = a * a % m;
b >>= 1;
}
return res;
}
ll mul(ll a, ll b){
a %= mod;
a *= b;
a %= mod;
return a;
}
ll add(ll a, ll b){
a %= mod;
a += b;
a %= mod;
return a;
}
ll inverse(ll x){
return binpow(x, mod - 2, mod);
}
ll fac[N];
ll n;
ll calc(vector<ll> &a, ll t){
map<pair<ll, ll>, int> cnt;
int dif = 0;
for(int i = 0; i < n; i++){
ll l = a[i], r = t - a[i];
int idx = lower_bound(all(a), r) - a.begin();
if(idx < n && a[idx] == r){
if(l != r){
dif++;
}
if(n % 2 == 0){
cnt[{min(l, r), max(l, r)}]++;
} else if(l != r){
cnt[{min(l, r), max(l, r)}]++;
}
} else {
return 0;
}
}
ll ans = mul(mul(fac[n / 2], inverse(n / 2 - sz(cnt) + 1)), binpow(2, dif / 2, mod));
return ans;
}
void solve(){
cin >> n;
vector<ll> a(n);
ll tot = 0;
for(int i = 0; i < n; i++){
cin >> a[i];
tot += a[i];
}
//tot / (n + 1) / 2
ll t = tot / ((n + 1) / 2);
fac[0] = 1ll;
for(int i = 1; i <= n; i++){
fac[i] = mul(fac[i - 1], i);
}
sort(all(a));
if(n % 2 == 0){
cout << calc(a, t) << '\n';
} else {
ll ans = 0;
map<ll, bool> calculated;
for(int i = 0; i < n; i++){
tot += a[i]; int x = (n + 1) / 2;
if(calculated.find(a[i]) != calculated.end())continue;
calculated[a[i]] = true;
if(tot % x == 0){
ans = add(ans, calc(a, tot / x));
}
tot -= a[i];
}
cout << ans << '\n';
}
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t = 1;
cin >> t;
while(t--){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3576kb
input:
5 3 2 3 1 4 1 1 1 1 3 1 2 4 7 0 200 0 200 50 100 150 14 -1 0 1 2 3 4 5 6 7 8 9 10 11 12
output:
2 1 0 24 645120
result:
ok 5 number(s): "2 1 0 24 645120"
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3484kb
input:
100 3 96 145 47 5 26 50 50 26 38 4 -60 -72 -60 -72 5 19 70 -32 117 -79 4 -34 -85 -11 -62 4 187 26 -85 76 2 22 -150 5 33 127 -61 -88 154 3 208 85 -38 3 -71 3 77 4 -78 90 -78 90 4 45 -41 -77 81 2 -93 85 3 -269 -100 69 5 -35 -31 -31 -33 -35 3 -91 -3 -47 4 -80 -82 42 44 2 -217 17 2 -56 74 5 -71 146 141 ...
output:
2 0 4 8 8 8 2 8 2 2 4 8 2 2 0 2 8 2 2 8 2 8 2 8 8 2 2 2 2 2 2 2 2 2 2 0 2 8 2 2 8 2 8 2 4 8 8 0 8 2 2 2 4 8 0 8 2 2 8 2 2 2 2 0 8 8 8 2 8 2 8 2 4 8 2 8 2 4 2 2 2 2 8 8 8 2 8 8 8 2 2 8 2 4 8 8 2 2 2 2
result:
wrong answer 2nd numbers differ - expected: '4', found: '0'