Submission #698955

#TimeUsernameProblemLanguageResultExecution timeMemory
698955safaricolaAlternating Heights (CCO22_day1problem1)C++17
0 / 25
1 ms596 KiB
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 1; i <= n; i++) #define pb push_back int n,a[3010],st=2,k,q,top[3010],cur,mini[3010],x,y; bool rmv[3010][3010],vis[3010]; vector<int> adjl[3010]; bool ord(int a){ if(vis[a] && top[a]==-1) return true; if(vis[a]) return false; vis[a] = true; for (int it: adjl[a]){ if(rmv[a][it])continue; if(ord(it)){ return true; } } cur++; top[a]=cur; return false; } bool remov(){ bool flag=true; while(flag){ flag=false; cur=0; memset(top, -1, sizeof(top)); memset(vis, 0, sizeof(vis)); for(int i=1; i<=n; i++) if(!vis[i]) if(ord(i)){ flag=true; i=n+1; break; } if(flag){ //remove edge; if(st%2==1){ rmv[a[st]][a[st-1]]=1; }else{ rmv[a[st-1]][a[st]]=1; } st++; } } } int main(){ cin>>n>>k>>q; mini[1]=1; rep(i,n){ cin>>a[i]; if(i==1)continue; if(i%2==1){ adjl[a[i]].pb(a[i-1]); remov(); //cout<<st<<' '<<i<<endl; mini[i]=st-1; }else{ adjl[a[i-1]].pb(a[i]); remov(); //cout<<st<<' '<<i<<endl; mini[i]=st-1; } } while(q--){ cin>>x>>y; if(x<mini[y])cout<<"NO"<<endl; else cout<<"YES"<<endl; } } /* 6 3 3 1 1 2 3 1 2 1 2 2 5 2 6 */

Compilation message (stderr)

Main.cpp: In function 'bool remov()':
Main.cpp:46:1: warning: no return statement in function returning non-void [-Wreturn-type]
   46 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...