Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- https://codeforces.com/contest/1851/problem/D
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long
- int main()
- {
- ll i,j,k,t,n,a[200005];
- cin>>t;
- while(t--)
- {
- cin>>n;set<ll> b;
- ll s=(1+n)*n/2;
- ll x,l=0;
- for(i=1;i<n;i++)
- {
- cin>>x;
- if(x-l<=n)
- b.insert(x-l);
- l=x;
- }
- if(b.size()==n-2+(x!=s))
- cout<<"YES"<<endl;
- else
- cout<<"NO"<<endl;
- }
- return 0;
- }
- #include <bits/stdc++.h>
- using namespace std;
- using ll = long long;
- int main()
- {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- int tests;
- cin >> tests;
- while (tests--) {
- ll n;
- cin >> n;
- --n;
- vector<ll> a(n);
- for (ll &i: a) {
- cin >> i;
- }
- vector<ll> numbers(1, a[0]);
- for (int i{1}; i < n; ++i) {
- numbers.push_back(a[i] - a[i - 1]);
- }
- ++n;
- vector<bool> occurred(1 + n, false);
- vector<ll> unexpected_numbers;
- for (auto i: numbers) {
- if (1 <= i && i <= n) {
- if (occurred[i]) {
- unexpected_numbers.push_back(i);
- } else {
- occurred[i] = true;
- }
- } else {
- unexpected_numbers.push_back(i);
- }
- }
- vector<ll> missing_numbers;
- for (int i{1}; i <= n; ++i) {
- if (!occurred[i]) {
- missing_numbers.push_back(i);
- }
- }
- if (missing_numbers.size() == 1u) {
- ll sum = n * (n + 1) / 2;
- if (a.back() < sum && missing_numbers[0] == sum - a.back()) {
- cout << "YES\n";
- } else {
- cout << "NO\n";
- }
- continue;
- }
- if (
- unexpected_numbers.size() == 1u
- && missing_numbers.size() == 2u
- && unexpected_numbers[0] == missing_numbers[0] + missing_numbers[1]
- ) {
- cout << "YES\n";
- } else {
- cout << "NO\n";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement