QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#179102 | #5744. Palindromic Differences | tselmegkh | AC ✓ | 446ms | 40328kb | C++20 | 2.3kb | 2023-09-14 18:02:25 | 2023-09-14 18:02:25 |
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 long long N = 2e5 + 5, mod = 1e9 + 9;
#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;
long long binpow(long long a, long long b, long long m) {
a %= m;
long long res = 1;
while (b > 0) {
if (b & 1)
res = res * a % m;
a = a * a % m;
b >>= 1;
}
return res;
}
ll inverse(ll a){
return binpow(a, mod - 2, mod);
}
void solve(){
int n;
cin >> n;
map<ll, ll> m;
ll ttl = 0;
for(int i = 0; i < n; i++){
ll input;
cin >> input;
ttl += input;
m[input]++;
}
if((n % 2 == 1 && ttl % n != 0) || (n % 2 == 0 && ttl % (n / 2) != 0)){
cout << 0 << '\n';
return;
}
ll sum = ttl * 2 / n;
if(n % 2 == 1 && sum % 2 == 1){
cout << 0 << '\n';
return;
}
if(n % 2 == 1 && m.find(sum / 2) == m.end()){
cout << 0 << '\n';
return;
}
if(n % 2 == 1) m[sum / 2]--;
vector<ll> v;
ll pow_2 = 0;
for(auto& x : m){
if(x.ff > sum / 2) continue;
if(sum % 2 == 0 && x.ff == sum / 2 && x.ss % 2 == 1){
cout << 0 << '\n';
return;
}
if(sum % 2 == 0 && x.ff == sum / 2){
v.pb(x.ss / 2);
continue;
}
if(m.find(sum - x.ff) == m.end() || m[sum - x.ff] != x.ss){
cout << 0 << '\n';
return;
}
v.pb(x.ss);
pow_2 += x.ss;
}
vector<ll> fac(n);
fac[0] = 1;
fac[1] = 1;
for(ll i = 2; i < n; i++){
fac[i] = (fac[i - 1] * i) % mod;
}
ll ans = fac[n / 2];
for(auto& x : v){
ans = (ans * inverse(fac[x])) % mod;
}
ans = (ans * binpow(2, pow_2, mod)) % mod;
cout << ans << '\n';
return;
}
int main(){
int t = 1;
cin >> t;
while(t--){
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3424kb
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: 3504kb
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: 0
Accepted
time: 1ms
memory: 3440kb
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 64 8 1920 1920 960 1920 96 24 0 24 192 160 24 192 960 192 96 3840 48 64 48 640 384 24 48 24 0 3840 0 384 0 24 3840 384 384 0 96 48 0 192 64 0 24 192 24 3840 64 0 192 24 192 64 192 1920 48 640 192 1920 64 1920 192 384 64 0 ...
result:
ok 100 numbers
Test #4:
score: 0
Accepted
time: 11ms
memory: 3468kb
input:
100 120 -114455311 -174718615 -37866982 -532413059 -97795839 -156986074 -433955847 -223791205 36013704 -128839659 -418460507 108469214 -141533155 -61323330 -374765855 -446611365 -363293792 -223791205 -360642838 130620126 -37866982 -174718615 -434523524 -374765855 -446611365 -199440556 141236146 3464...
output:
301557016 693667370 679308776 382295205 413760016 590145961 904245786 403834612 677442056 80470289 858160459 914072231 25248974 231559052 153817535 907768656 563481227 601280785 971106226 751059249 763721259 928947455 677434313 26701054 769219518 677880763 125068890 427310717 667323432 0 0 70980410 ...
result:
ok 100 numbers
Test #5:
score: 0
Accepted
time: 0ms
memory: 3456kb
input:
100 349 4 -3 8 -5 6 3 3 12 10 -1 -2 0 0 -3 0 6 -1 3 6 9 12 10 3 3 11 6 -3 4 10 13 12 11 12 10 4 3 2 11 4 10 12 -2 -1 -2 4 -2 5 -4 6 10 3 -2 7 -2 13 5 3 12 5 4 5 9 -4 4 9 11 7 3 -3 12 -2 3 4 -1 9 9 6 9 5 3 3 10 7 4 1 1 -4 1 5 3 7 10 12 5 3 5 -5 12 11 1 3 4 4 -3 5 4 -3 -2 4 10 -1 9 4 10 4 -5 10 10 1 -...
output:
797334197 261650713 13452621 292658387 12 0 530220802 412900254 602693947 178048367 662937047 473322600 847468670 985503292 147033245 796944196 742110695 748501180 476456386 4480 15366259 100415968 96175861 160337120 884872249 0 632567605 54430517 0 5760 0 133556422 720513380 994746414 894268227 925...
result:
ok 100 numbers
Test #6:
score: 0
Accepted
time: 6ms
memory: 3508kb
input:
27 1000 -184054583 18950513 454533642 -173057958 339301016 -198317448 326966377 -140222777 -140222777 -184054583 384145165 -65361155 278937133 185812676 185812676 112074970 278937133 470945604 112074970 -65361155 -41413370 59125766 474850417 438110423 179925892 117961754 18950513 348345925 -14022277...
output:
110520192 735843216 513694224 740469570 2 174086022 587180293 1 513795966 447284518 176864924 425116607 63246314 1 750674059 387828424 741519055 816108292 431980043 369481989 2 740182541 337072795 1 83085379 312638265 503004
result:
ok 27 numbers
Test #7:
score: 0
Accepted
time: 430ms
memory: 34644kb
input:
1 500000 -35150664 144585927 169760595 -50559995 -22850504 109794846 188072608 -172822995 7347429 -17441834 14310102 154155174 -147341794 -123361554 72804482 44376266 112090757 -114685139 -62821805 27933970 -19669016 -123889172 37346259 -29714463 182774165 -53550750 -165268941 154185019 145369413 16...
output:
0
result:
ok 1 number(s): "0"
Test #8:
score: 0
Accepted
time: 72ms
memory: 7032kb
input:
1 500000 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 123...
output:
1
result:
ok 1 number(s): "1"
Test #9:
score: 0
Accepted
time: 446ms
memory: 27124kb
input:
1 500000 144603534 -89837766 1987286 165330109 19992331 -84670369 163455795 50871559 -139059922 112148990 -157611311 20814793 187916411 88090633 -13853193 -96438867 408247618 80217938 227938850 305424479 61983214 79161811 237287207 114755658 -80743762 340287746 71992958 157745372 -135527322 13699245...
output:
913387832
result:
ok 1 number(s): "913387832"
Test #10:
score: 0
Accepted
time: 400ms
memory: 27100kb
input:
1 500000 157514047 -42235989 203500526 -140641448 -16040598 44538676 -135560685 50342461 93134143 86299575 -122503542 -179301211 54704492 151455680 -2251861 -157377464 207867421 10359177 253318620 187202102 229503945 119850256 6889609 -93489109 100117003 17429625 110194795 180892801 -138432544 -9887...
output:
493838496
result:
ok 1 number(s): "493838496"
Test #11:
score: 0
Accepted
time: 431ms
memory: 26992kb
input:
1 500000 -159638317 270502828 -121352656 276965059 -184090959 89699787 463088147 484402481 338891394 -62720188 413238831 4549171 -124710021 369548680 282766650 134308879 170640349 185614116 199285770 -122011909 -87909101 26171382 124964768 312752562 273062537 463577547 333562209 349263346 416911814 ...
output:
694861705
result:
ok 1 number(s): "694861705"
Test #12:
score: 0
Accepted
time: 433ms
memory: 27000kb
input:
1 500000 -32838117 67728982 190597229 -132611918 -37703073 22101212 55589916 177161510 203513054 41527205 -8597577 -141799704 95208759 37847251 172919659 -23015366 -76578404 90346391 -40387515 232150729 -27461993 84506952 -113806848 -50379151 -91259613 226323228 178687236 133893671 1613412 94990382 ...
output:
102782842
result:
ok 1 number(s): "102782842"
Test #13:
score: 0
Accepted
time: 424ms
memory: 27096kb
input:
1 499999 -181939350 177047587 376374128 137325564 344635455 300099459 81705853 433327654 461694879 209066820 88973836 -160166963 -33415554 92935001 361965247 196069646 114952451 -66937255 -107534999 -8492839 154504109 -195309823 276473930 296943757 173552748 80936110 349206678 284720129 205529310 -4...
output:
750024497
result:
ok 1 number(s): "750024497"
Test #14:
score: 0
Accepted
time: 398ms
memory: 27048kb
input:
1 500000 -81516492 185829879 -287219514 -119866058 -147557964 60055880 50967632 -62571293 -96073475 59756839 -279906569 -164589116 -95559645 -28265329 -109476273 138093804 107568092 151317749 -27284649 -56866979 -285717104 -16186734 -8668345 -244070808 -271539022 -168032439 -34109554 22128483 -18691...
output:
563104622
result:
ok 1 number(s): "563104622"
Test #15:
score: 0
Accepted
time: 412ms
memory: 27104kb
input:
1 500000 74685816 132905522 52332400 27863103 -187528176 35501460 139043359 125298232 62738407 -149197098 114721173 -207012942 149998079 53715882 -67850635 56170381 -193026714 -99557881 -188957191 -76686098 1311785 43584368 -47521046 173907631 -155226304 -70716471 70916462 45776075 -62917358 -421892...
output:
498918353
result:
ok 1 number(s): "498918353"
Test #16:
score: 0
Accepted
time: 380ms
memory: 27036kb
input:
1 500000 127114539 279807925 213109115 174334015 307757171 -20167864 -173555000 40497025 124479960 124038075 -10661245 141205240 -42927309 283417167 12112958 93395923 349215911 192578324 173694208 11295226 80657446 67600454 -141548799 148083225 -4216721 160614942 139566436 -83036500 32116584 4616762...
output:
443357339
result:
ok 1 number(s): "443357339"
Test #17:
score: 0
Accepted
time: 407ms
memory: 26956kb
input:
1 499999 -244434376 -2816835 31905801 -173133860 13823536 66859305 -184516658 89746940 133879571 -38255438 97687435 -248521850 -123193526 126995946 -196253031 -74501420 -39525816 -72831091 -284638707 -90143971 -99476794 -77094643 -133604793 90694402 154965841 -132132096 -182436965 101251630 35827693...
output:
340694461
result:
ok 1 number(s): "340694461"
Test #18:
score: 0
Accepted
time: 400ms
memory: 27028kb
input:
1 500000 312193553 344205065 237720327 263837973 387732505 120904580 -76226754 -5669382 99145847 387722373 317184839 -117643072 105488194 177202657 -77456556 267234992 56270828 10184179 101917561 157037961 180517782 375399981 297669679 -61146160 5379485 108836755 175463548 185306330 245275368 -15521...
output:
838738574
result:
ok 1 number(s): "838738574"
Test #19:
score: 0
Accepted
time: 218ms
memory: 10524kb
input:
1 500000 -147041412 186559727 -22545111 -124509578 -110578695 60986661 -82024032 34917279 -156348403 66953770 19143334 -1679117 -129795280 -69872636 90428639 -197880855 -54717805 -11021835 7937595 -30518034 190847667 -184204078 56739377 25694532 -116575628 63753461 -81880708 -23193103 196003654 -191...
output:
286270253
result:
ok 1 number(s): "286270253"
Test #20:
score: 0
Accepted
time: 160ms
memory: 7560kb
input:
1 500000 -199283313 -186774128 -99431490 -153406109 107482790 -169729685 5095946 -14329909 -100075974 -99141187 67259227 -8109927 13892779 -59721330 -135750651 -30954745 -43005026 -151288994 -288866832 139765576 67333772 -146838483 -265052428 -36696652 27429367 136889662 -102448749 -21466950 -165153...
output:
29677003
result:
ok 1 number(s): "29677003"
Test #21:
score: 0
Accepted
time: 137ms
memory: 6948kb
input:
1 500000 -222063041 32058033 -36549483 740629 -148949822 -161839714 -35766411 -34676840 -66665918 182245586 -182185407 -54467092 -231734440 107512204 -143220910 -143376815 76191361 -134548903 -236108001 30769862 62549562 -246058856 87541933 -275364332 -104250420 109628747 100183621 -54361710 -131377...
output:
824022109
result:
ok 1 number(s): "824022109"
Test #22:
score: 0
Accepted
time: 87ms
memory: 7200kb
input:
1 500000 -305 -434 636 597 -619 -527 266 -640 392 -690 666 -170 531 540 -593 323 -523 569 -300 -491 426 -130 421 -609 -505 -607 172 -673 -594 -557 -93 207 -593 687 -464 -665 -353 344 -206 -581 -437 -560 -500 442 447 -652 -401 -535 678 -337 -472 668 607 -331 -664 -539 366 -275 436 516 -496 -336 547 -...
output:
255580629
result:
ok 1 number(s): "255580629"
Test #23:
score: 0
Accepted
time: 262ms
memory: 40328kb
input:
1 500000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100...
output:
924782062
result:
ok 1 number(s): "924782062"