Submission #620619

# Submission time Handle Problem Language Result Execution time Memory
620619 2022-08-03T07:37:47 Z Theo830 Alternating Heights (CCO22_day1problem1) C++17
0 / 25
456 ms 12024 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9+7;
const ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ii,ll>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
ll n;
vector<vll>in;
ll out[3005] = {0};
bool check(vll arr){
    f(i,0,n){
        out[i] = 0;
    }
    in.assign(n,vll());
    ll posoi = 0;
    queue<ll>q;
    f(i,0,(ll)arr.size()-1){
        if(i % 2 == 0){
            out[arr[i]]++;
            in[arr[i+1]].pb(arr[i]);
        }
        else{
            out[arr[i+1]]++;
            in[arr[i]].pb(arr[i+1]);
        }
    }
    f(i,0,n){
        if(out[i] == 0){
            q.push(i);
        }
    }
    while(!q.empty()){
        ll f = q.front();
        q.pop();
        posoi++;
        for(auto x:in[f]){
            out[x]--;
            if(out[x] == 0){
                q.push(x);
            }
        }
    }
    return posoi == n;
}
int main(void){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll k,q;
    cin>>n>>k>>q;
    ll arr[n];
    f(i,0,n){
        cin>>arr[i];
    }
    ll ans[n];
    ll pos[2] = {0,1};
    f(i,0,n){
        ans[i] = max(i,pos[i % 2] - 1);
        while(pos[i % 2] < n){
            vll ex;
            f(j,i,pos[i % 2] + 1){
                ex.pb(arr[j]);
            }
            if(check(ex)){
                pos[i % 2]++;
            }
            else{
                ans[i] = pos[i % 2]-1;
                break;
            }
        }
    }
    while(q--){
        ll x,y;
        cin>>x>>y;
        if(ans[x-1] >= y-1){
            cout<<"YES\n";
        }
        else{
            cout<<"NO\n";
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 438 ms 9856 KB Output is correct
2 Incorrect 456 ms 12024 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 153 ms 3972 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Runtime error 246 ms 964 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 438 ms 9856 KB Output is correct
2 Incorrect 456 ms 12024 KB Output isn't correct
3 Halted 0 ms 0 KB -