QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#135487 | #5744. Palindromic Differences | tselmegkh# | WA | 1ms | 3536kb | C++20 | 2.5kb | 2023-08-05 16:11:52 | 2023-08-05 16:11:55 |
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];
int 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] = 1;
for(int i = 1; i <= n; i++){
fac[i] = mul(fac[i - 1], i);
}
sort(all(a));
ll ans = 0;
if(n % 2 == 0){
cout << calc(a, t) << '\n';
} else {
for(int i = 0; i < n; i++){
tot += a[i]; int x = (n + 1) / 2;
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: 3520kb
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: 0
Accepted
time: 1ms
memory: 3536kb
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 4 4 8 8 8 2 8 2 2 4 8 2 2 4 2 8 2 2 8 2 8 2 8 8 2 2 2 2 2 2 2 2 2 2 4 2 8 2 2 8 2 8 2 4 8 8 4 8 2 2 2 4 8 4 8 2 2 8 2 2 2 2 4 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:
ok 100 numbers
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 3480kb
input:
100 6 620 -1224 -1224 -577 620 -27 6 2368 2266 788 -950 -848 630 6 -742 373 -1293 373 -1293 -178 9 313 863 -874 602 -1135 602 -874 -136 -585 7 -639 -331 73 -639 477 785 785 6 56 2521 -432 1768 -697 2256 8 -821 61 -183 -237 -679 329 398 -78 6 -2045 -2047 -437 987 -623 985 8 340 -934 988 -354 -313 408...
output:
24 48 24 192 24 48 0 48 384 48 3840 48 24 24 48 384 1920 384 384 192 48 48 24 128 16 1920 1920 1280 1920 128 24 0 24 192 960 24 192 1280 192 128 3840 48 128 48 1280 384 24 48 24 0 3840 0 384 0 24 3840 384 384 0 128 48 0 192 128 0 24 192 24 3840 128 0 192 24 192 128 192 1920 48 1280 192 1920 128 1920...
result:
wrong answer 24th numbers differ - expected: '64', found: '128'