Submission #620600

# Submission time Handle Problem Language Result Execution time Memory
620600 2022-08-03T07:32:22 Z Theo830 Alternating Heights (CCO22_day1problem1) C++17
6 / 25
1000 ms 11412 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];
    f(i,0,n){
        ll l = i+1,r = n-1;
        ans[i] = i;
        while(l <= r){
            ll mid = (l+r)/2;
            vll ex;
            f(j,i,mid+1){
                ex.pb(arr[j]-1);
            }
            if(check(ex)){
                l = mid + 1;
                ans[i] = max(ans[i],mid);
            }
            else{
                r = mid - 1;
            }
        }
    }
    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 Execution timed out 1076 ms 4204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 199 ms 10128 KB Output is correct
2 Correct 178 ms 10188 KB Output is correct
3 Correct 179 ms 10200 KB Output is correct
4 Correct 144 ms 8056 KB Output is correct
5 Correct 146 ms 8780 KB Output is correct
6 Correct 192 ms 10476 KB Output is correct
7 Correct 201 ms 10320 KB Output is correct
8 Correct 197 ms 10648 KB Output is correct
9 Correct 175 ms 11008 KB Output is correct
10 Correct 180 ms 11060 KB Output is correct
11 Correct 179 ms 11412 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1085 ms 596 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1076 ms 4204 KB Time limit exceeded
2 Halted 0 ms 0 KB -