답안 #620628

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
620628 2022-08-03T07:40:32 Z Theo830 Alternating Heights (CCO22_day1problem1) C++17
0 / 25
480 ms 9264 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]-1);
            }
            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";
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 480 ms 9264 KB Output is correct
2 Incorrect 472 ms 8196 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 158 ms 4784 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 324 KB Output is correct
2 Correct 389 ms 616 KB Output is correct
3 Correct 400 ms 568 KB Output is correct
4 Correct 268 ms 504 KB Output is correct
5 Incorrect 1 ms 340 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 480 ms 9264 KB Output is correct
2 Incorrect 472 ms 8196 KB Output isn't correct
3 Halted 0 ms 0 KB -