Submission #448142

#TimeUsernameProblemLanguageResultExecution timeMemory
448142jhnah917Chameleon's Love (JOI20_chameleon)C++14
100 / 100
94 ms1528 KiB
#include "chameleon.h" #include <bits/stdc++.h> using namespace std; namespace { int N, Match[1010], Color[1010]; bool Love[1010][1010]; vector<int> G[1010], Nodes[2]; void Init(){ memset(Match, -1, sizeof Match); memset(Color, -1, sizeof Color); memset(Love, 0, sizeof Love); for(int i=0; i<1010; i++) G[i].clear(); } void DFS(int v, int color){ Color[v] = color; Nodes[color].push_back(v); for(auto i : G[v]) if(Color[i] == -1) DFS(i, color^1); } bool HasEdge(vector<int> vec, int now){ vec.push_back(now); return Query(vec) < vec.size(); } int Search(const vector<int> &vec, int v){ int l = 0, r = vec.size() - 1; while(l < r){ int m = l + r >> 1; vector<int> now; for(int i=0; i<=m; i++) now.push_back(vec[i]); if(HasEdge(now, v)) r = m; else l = m + 1; } return r; } int Like(int v){ int a = G[v][0], b = G[v][1], c = G[v][2]; if(Query({ v, b, c }) == 1) return a; if(Query({ v, a, c }) == 1) return b; return c; } } // namespace void Solve(int n){ N = n + n; Init(); for(int i=1; i<=N; i++){ memset(Color, -1, sizeof Color); Nodes[0].clear(); Nodes[1].clear(); for(int j=1; j<i; j++) if(Color[j] == -1) DFS(j, 0); for(int c=0; c<2; c++){ while(HasEdge(Nodes[c], i)){ auto j = Search(Nodes[c], i); G[i].push_back(Nodes[c][j]); G[Nodes[c][j]].push_back(i); Nodes[c].erase(Nodes[c].begin() + j); } } } for(int i=1; i<=N; i++){ if(G[i].size() == 1){ Match[i] = G[i][0]; Match[G[i][0]] = i; continue; } int j = Like(i); Love[i][j] = Love[j][i] = true; } for(int i=1; i<=N; i++){ if(Match[i] != -1) continue; for(auto j : G[i]) if(!Love[i][j]) Match[i] = j; } for(int i=1; i<=N; i++) if(i < Match[i]) Answer(i, Match[i]); }

Compilation message (stderr)

chameleon.cpp: In function 'bool {anonymous}::HasEdge(std::vector<int>, int)':
chameleon.cpp:24:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |         return Query(vec) < vec.size();
      |                ~~~~~~~~~~~^~~~~~~~~~~~
chameleon.cpp: In function 'int {anonymous}::Search(const std::vector<int>&, int)':
chameleon.cpp:30:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   30 |             int m = l + r >> 1;
      |                     ~~^~~
#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...