QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#179077#5744. Palindromic DifferencestselmegkhWA 0ms3652kbC++202.4kb2023-09-14 17:36:502023-09-14 17:36:52

Judging History

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

  • [2023-09-14 17:36:52]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3652kb
  • [2023-09-14 17:36:50]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <assert.h>
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;

ll binpow(ll a, ll b){
    if(b == 0) return 1 % mod;
    ll ans = binpow(a, b / 2);
    ans = (ans * ans) % mod;
    if(b % 2 == 1) ans = (ans * a) % mod; 
    return ans % mod;
}
ll inverse(ll x){
    return binpow(x, mod - 2);
}


void solve(){
    ll n;
    cin >> n;

    vector<long long> a(n);
    map<long long, long long> m;
    vector<ll> v;

    ll ttl = 0;

    for(ll i = 0; i < n; i++){
        cin >> a[i];
        m[a[i]]++;
        ttl +=  a[i];
    }
    ll number;

    if(n % 2 == 1) number = n;
    else number = (n + 1) / 2;

    if(ttl % number != 0){
        cout << 0 << '\n';
        return;
    } 
    
    ll sum = ttl / number;
    if(n % 2 == 1) sum = sum * 2;

    if(n % 2 == 1){
        if(m.find(sum / 2) == m.end()){
            cout << 0 << '\n';
            return;
        }
        m[sum / 2]--;
    }    
    ll pow_2 = 0;
    for(auto& x : m){
        if(x.ss == 0) continue;
        if(sum % 2 == 0 && x.first == sum / 2){
            if(x.second % 2 == 1){
                cout << 0 << '\n';
                return;
            }
            v.pb(x.ss / 2);
            continue;
        }
        if(m.find(sum - x.ff) == m.end() || m[sum - x.ff] != x.ss){
            cout << 0 << '\n';
            return;
        }
        m[sum - x.ff] = 0;
        v.pb(x.ss);
        pow_2 += x.ss;
    }
    ll ans = 1;
    vector<ll> fac(n, 0);
    fac[1] = 1;
    for(ll i = 2; i < n; i++){
        fac[i] = (fac[i - 1] * i) % mod;
    }
    ans = fac[n / 2];
    ll data = 0;
    for(auto& x : v){
        data += x;
        ans = ans * inverse(fac[x]);
    }
    assert(data == n / 2);
    ans = (ans * binpow(2, pow_2)) % mod;
    cout << ans << '\n';
    return;
}

int main(){
    int t = 1;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

详细

Test #1:

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

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: 0ms
memory: 3652kb

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: 0ms
memory: 3544kb

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
179465728
1920
555717867
24
0
24
192
160
24
192
179465728
192
555717867
3840
48
64
48
640
384
24
48
24
0
3840
0
384
0
24
3840
384
384
0
555717867
48
0
192
64
0
24
192
24
3840
64
0
192
24
192
64
192
1920
48
6...

result:

wrong answer 28th numbers differ - expected: '960', found: '179465728'