当前位置:   article > 正文

【CF1478C】Nezzar and Symmetric Array

cf1478c

code

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstring>

using namespace std;
typedef long long ll;

int n;
void solve(){
    cin >> n;
    vector<ll> v;
    for (int i = 0; i < 2 *n; ++i) {
        ll x;
        cin >> x;
        v.push_back(x);
    }
    sort(v.rbegin(), v.rend());
    v.erase(unique(v.begin(), v.end()), v.end());
    if (v.size() != n){
        cout << "NO\n";
        return;
    }
    int div = n << 1;
    vector<ll> a;
    a.push_back(0);

    for (int i = 0; i < n; ++i) {
        ll sum = v[i];
        if (i >= 1) a[i] += a[i - 1];
        sum -= 2*a[i];
        if (sum > 0 && sum % div == 0){
            a.push_back(sum / div);
            div -= 2;
        }else{
            cout << "NO\n";
            return;
        }
    }
    cout << "YES\n";
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(), cout.tie();
    int cases;
    cin >> cases;
    while (cases--){
        solve();
    }
    return 0;
}

  • 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
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/75473
推荐阅读
相关标签
  

闽ICP备14008679号