QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#135517#5744. Palindromic Differencestselmegkh#WA 6ms3608kbC++202.5kb2023-08-05 16:52:242023-08-05 16:52:28

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-05 16:52:28]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:3608kb
  • [2023-08-05 16:52:24]
  • 提交

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;

    map<ll, int> c;
    for(int i = 0; i < n; i++){
        c[a[i]]++;
    }
    int dif = 0;
    for(int i = 0; i < n; i++){
        ll l = a[i], r = t - a[i];
        if(c[l] == 0)continue;
        if(c.find(r) == c.end()){
            return 0;
        }
        if(c[r] == 0)return 0;
        if(l != r){
            dif++;
            c[l]--; c[r]--;
        } else {
            c[l] -= 2;
        }
        cnt[{min(l, r), max(l, r)}]++;
    }
    ll ans = mul(fac[n / 2], binpow(2, dif, mod));

    for(auto x : cnt){
        ans = mul(ans, inverse(fac[x.ss]));
    }
    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){
        if(tot % (n / 2)){
            cout << "0\n";
            return;
        }
        cout << calc(a, t) << '\n';
    } else {
        if(tot % n){
            cout << "0\n";
            return;
        }
        cout << calc(a, tot / n * 2) << '\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;
}

詳細信息

Test #1:

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

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: 3528kb

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: 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
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: 6ms
memory: 3608kb

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: -100
Wrong Answer
time: 1ms
memory: 3488kb

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:

54313572
261650713
13452621
206053914
12
0
42170347
747018042
293378235
178048367
662937047
473322600
731737267
985503292
147033245
796944196
742110695
748501180
811378871
4480
830984329
100415968
96175861
160337120
237559679
0
632567605
54430517
0
960
0
964079992
332058238
513936011
894268227
92571...

result:

wrong answer 1st numbers differ - expected: '797334197', found: '54313572'