제출 #448590

#제출 시각아이디문제언어결과실행 시간메모리
448590JooDdae카멜레온의 사랑 (JOI20_chameleon)C++17
44 / 100
178 ms660 KiB
#include "chameleon.h" #include <bits/stdc++.h> using namespace std; int nxt[1010]; bool chk[1010]; vector<int> v[1010]; void addEdge(int a, int b){ v[a].push_back(b), v[b].push_back(a); } int find_next(const int u, const vector<int> &q){ if(q.empty() || v[u].size() == 3) return 0; int L = 0, R = q.size()-1; while(L <= R){ int M = (L+R)/2; vector<int> Q(1, u); for(int i=0;i<=M;i++) Q.push_back(q[i]); if(Query(Q) == Q.size()) L = M+1; else R = M-1; } if(L == q.size()) return 0; addEdge(u, q[R+1]); return q[R+1]; } void Solve(int N) { set<int> s1, s2; for(int i=1;i<=2*N;i++){ vector<int> q1(s1.begin(), s1.end()), q2(s2.begin(), s2.end()); int k = 0; while(k = find_next(i, q1)){ while(!q1.empty() && *q1.begin() <= k) q1.erase(q1.begin()); } while(k = find_next(i, q2)){ while(!q2.empty() && *q2.begin() <= k) q2.erase(q2.begin()); } vector<int> chk2(2*N+1), g, b; queue<pair<int, int>> q; chk2[i] = 1; q.push({i, 0}); while(!q.empty()){ auto [u, c] = q.front(); q.pop(); if(s1.count(u)) s1.erase(u); if(s2.count(u)) s2.erase(u); (c ? b : g).push_back(u); for(auto x : v[u]) if(!chk2[x]) chk2[x] = 1, q.push({x, !c}); } for(auto x : g) s1.insert(x); for(auto x : b) s2.insert(x); } // for(int i=1;i<=2*N;i++) if(!chk[i]){ // set<int> s = s1.count(i) ? s2 : s1; // vector<int> q(s.begin(), s.end()); // if(!v[i].empty()){ // while(!q.empty() && *q.begin() <= v[i].back()) q.erase(q.begin()); // } // int k = 0; // while(k = find_next(i, q)){ // while(!q.empty() && *q.begin() <= v[i].back()) q.erase(q.begin()); // } // if(v[i].size() == 1){ // chk[i] = chk[v[i][0]] = 1, Answer(i, v[i][0]); // } // } // for(int i=1;i<=2*N;i++){ // printf("[%d] :",i); // for(int x : v[i]) printf(" %d",x); // puts(""); // } // ---------------------------------------- don't touch line ----------------------------------------- for(int i=1;i<=2*N;i++) if(!chk[i]) {if(v[i].size() == 1){ chk[i] = chk[v[i][0]] = 1, Answer(i, v[i][0]); continue; } int &A = v[i][0], &B = v[i][1], &C = v[i][2]; if(Query({i, B, C}) == 1) swap(A, C); else if(Query({i, A, C}) == 1) swap(B, C); nxt[i] = C, v[i].pop_back(); } for(int i=1;i<=2*N;i++) if(!chk[i]){ int x = (chk[v[i][1]] || nxt[v[i][1]] == i ? v[i][0] : v[i][1]); chk[i] = chk[x] = 1, Answer(i, x); } }

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

chameleon.cpp: In function 'int find_next(int, const std::vector<int>&)':
chameleon.cpp:23:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |         if(Query(Q) == Q.size()) L = M+1;
      |            ~~~~~~~~~^~~~~~~~~~~
chameleon.cpp:27:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     if(L == q.size()) return 0;
      |        ~~^~~~~~~~~~~
chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:40:17: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   40 |         while(k = find_next(i, q1)){
      |               ~~^~~~~~~~~~~~~~~~~~
chameleon.cpp:43:17: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   43 |         while(k = find_next(i, q2)){
      |               ~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...