제출 #638584

#제출 시각아이디문제언어결과실행 시간메모리
638584morasha3Alternating Heights (CCO22_day1problem1)C++17
25 / 25
838 ms4516 KiB
#include <bits/stdc++.h> using namespace std; typedef double ld; #define endl '\n' bool dfs(vector<vector<int>>& v) { int n = v.size(); vector<int> deg(n); for (int a = 0; a < n; a++) for (int b : v[a]) deg[b]++; vector<int> q; q.reserve(n); for (int i = 0; i < n; i++) if (deg[i] == 0) q.push_back(i); for (int rep = 0; rep < q.size(); rep++) { int c = q[rep]; for (auto nxt : v[c]) { deg[nxt]--; if (deg[nxt] == 0) q.push_back(nxt); } } return n>q.size(); } int32_t main() { //freopen("jumping.in","r",stdin); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,k,q; cin>>n>>k>>q; int arr[n]; for(int i=0; i<n; i++) {cin>>arr[i]; arr[i]--;} int m[n]; for(int rep:{0,1}) { for(int i=rep,r=i; i<n; i+=2) { while(r<n) { vector<vector<int>>adj(k); for(int j=i; j<r; j++) { if (j % 2 == i % 2) adj[arr[j]].push_back(arr[j + 1]); else adj[arr[j + 1]].push_back(arr[j]); } if(dfs(adj)) break; r++; } m[i]=r; } } while(q--) { int a,b; cin>>a>>b; a--,b--; if(m[a]>b) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'bool dfs(std::vector<std::vector<int> >&)':
Main.cpp:18:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for (int rep = 0; rep < q.size(); rep++)
      |                       ~~~~^~~~~~~~~~
Main.cpp:28:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     return n>q.size();
      |            ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...