답안 #973914

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
973914 2024-05-02T12:52:13 Z SeenSiravit Alternating Heights (CCO22_day1problem1) C++14
0 / 25
189 ms 3392 KB
#include<bits/stdc++.h>

using namespace std;

const int mxN = 3e3 + 5;

int n,k,q;
int a[mxN];
int ans[mxN];

vector<int> g[mxN];
int vis[mxN];
bool valid;

void dfs(int u){
    vis[u] = 1;

    for(auto v : g[u]){
        if(vis[v] == 2) continue;
        else if(vis[v] == 1){
            valid = false;
            return ;
        }else{
            dfs(v);

            if(!valid) return ;
        }
    }

    vis[u] = 2;
}

int main(){

    scanf("%d %d %d",&n,&k,&q);

    for(int i=1;i<=n;i++) scanf("%d",a+i);
    for(int i=1;i<=n;i++) ans[i] = n + 1;

    for(int l=1;l<=n;l++){
        int lb=l+1 , ub=n;

        while(lb<=ub){
            // clear edge and reset vis value
            for(int i=1;i<=k;i++) g[i].clear() , vis[i] = 0;

            int mid = (lb + ub) / 2;

            // add edge
            int t = 1;
            for(int i=l;i<mid;i++){
                if(t == 1) g[a[i]].push_back(a[i+1]);
                else g[a[i+1]].push_back(a[i]);

                t ^= 1;
            }

            valid = true;

            for(int i=l;i<=mid;i++){
                if(vis[a[i]] == 0){
                    dfs(a[i]);
                    if(!valid) break;
                }
            }

            if(!valid){
                ans[l] = min(ans[l] , mid);
                // printf("l=%d , mid=%d\n" , l , mid);
                ub = mid - 1;
            }else lb = mid + 1;
        }
    }

    for(int i=1;i<=n;i++) printf("%d " , ans[i]);
    printf("\n");

    while(q--){
        int l,r;
        scanf("%d %d" , &l , &r);

        cout<< (ans[l]<=r ? "NO" : "YES") << "\n";
    }

    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:35:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |     scanf("%d %d %d",&n,&k,&q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
Main.cpp:37:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     for(int i=1;i<=n;i++) scanf("%d",a+i);
      |                           ~~~~~^~~~~~~~~~
Main.cpp:80:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |         scanf("%d %d" , &l , &r);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 189 ms 3392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 184 ms 3380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 189 ms 3392 KB Output isn't correct
2 Halted 0 ms 0 KB -