제출 #758185

#제출 시각아이디문제언어결과실행 시간메모리
758185Sam_a17카멜레온의 사랑 (JOI20_chameleon)C++17
100 / 100
58 ms412 KiB
#define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> // #include "chameleon.h" // #include <atcoder/all> #include <cstdio> using namespace std; #ifndef ONLINE_JUDGE #define dbg(x) cerr << #x <<" "; print(x); cerr << endl; #else #define dbg(x) #endif #define sz(x) (int((x).size())) #define len(x) (int)x.length() #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define clr(x) (x).clear() #define uniq(x) x.resize(unique(all(x)) - x.begin()); #define blt(x) __builtin_popcount(x) #define pb push_back #define popf pop_front #define popb pop_back #define ld long double #define ll long long void print(long long t) {cerr << t;} void print(int t) {cerr << t;} void print(string t) {cerr << t;} void print(char t) {cerr << t;} void print(double t) {cerr << t;} void print(unsigned long long t) {cerr << t;} void print(long double t) {cerr << t;} #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; #define nl '\n' // Indexed Set template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template <class T, class V> void print(pair <T, V> p); template <class T> void print(vector <T> v); template <class T> void print(set <T> v); template <class T, class V> void print(map <T, V> v); template <class T> void print(multiset <T> v); template <class T> void print(T v[],T n) {cerr << "["; for(int i = 0; i < n; i++) {cerr << v[i] << " ";} cerr << "]";} template <class T, class V> void print(pair <T, V> p) {cerr << "{"; print(p.first); cerr << ","; print(p.second); cerr << "}";} template <class T> void print(vector <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";} template <class T> void print(Tree <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";} template <class T> void print(deque <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";} template <class T> void print(set <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";} template <class T> void print(multiset <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";} template <class T, class V> void print(map <T, V> v) {cerr << "[ "; for (auto i : v) {print(i); cerr << " ";} cerr << "]";} // for random generations mt19937 myrand(chrono::steady_clock::now().time_since_epoch().count()); // mt19937 myrand(131); // for grid problems int dx[8] = {-1,0,1,0,1,-1,1,-1}; int dy[8] = {0,1,0,-1,1,1,-1,-1}; long long ka() { long long x = 0; bool z = false; while (1) { char y = getchar(); if (y == '-') z = true; else if ('0' <= y && y <= '9') x = x * 10 + y - '0'; else { if (z) x *= -1; return x; } } } // lowest / (1 << 17) >= 1e5 / (1 << 18) >= 2e5 / (1 << 21) >= 1e6 void fastIO() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } // file in/out void setIO(string str = "") { fastIO(); if (str != "") { freopen((str + ".in").c_str(), "r", stdin); freopen((str + ".out").c_str(), "w", stdout); } else if(str == "input") { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } } const int maxN = 1005; bool vis[maxN]; vector<int> bro[maxN], adj[maxN]; int n, p[maxN], iran[maxN]; int Query(const std::vector<int> &p); void Answer(int a, int b); vector<int> first, second; bool vis2[maxN]; vector<int> g[5]; void Solve(int N) { n = N; g[0].push_back(1); for(int i = 2; i <= 2 * n; i++) { bool added = false; for(int j = 0; j <= 3; j++) { g[j].push_back(i); if(Query(g[j]) != sz(g[j])) { g[j].pop_back(); int lst = -1; while(true) { if(lst != -1) { vector<int> vi{i}; for(int k = lst + 1; k <= sz(g[j]) - 1; k++) { vi.push_back(g[j][k]); } if(Query(vi) == sz(vi)) { break; } } int ina = lst + 1, inb = sz(g[j]) - 1, ans = -1; while(ina <= inb) { int mid = (ina + inb) / 2; vector<int> toask{i}; for(int k = lst + 1; k <= mid; k++) { toask.push_back(g[j][k]); } if(Query(toask) != sz(toask)) { ans = mid; inb = mid - 1; } else { ina = mid + 1; } } bro[g[j][ans]].push_back(i); bro[i].push_back(g[j][ans]); lst = ans; } } else { if(added) { g[j].pop_back(); } added = true; } } } vector<bool> done(2 * n + 1); for(int i = 1; i <= 2 * n; i++) { if(done[i]) continue; vector<int> which = bro[i]; if(sz(which) == 3) { bro[i] = which; queue<int> q; q.push(i); while(!q.empty()) { auto u = q.front(); q.pop(); if(iran[u] == 0) { for(int j = 0; j < (1 << 3); j++) { if(blt(j) != 2) continue; vector<int> ask{u}; int to = -1; for(int k = 0; k < 3; k++) { if(j & (1 << k)) { ask.push_back(which[k]); } else { to = which[k]; } } if(Query(ask) == 1) { p[u] = to; iran[to] = u; done[u] = true; q.push(to); break; } } } else { set<int> st; for(auto j: bro[u]) { st.insert(j); } st.erase(iran[u]); vector<int> ask{u, iran[u]}; int ls = *st.rbegin(); for(auto j: st) { ask.push_back(j); if(Query(ask) == 1) { p[u] = ls; iran[ls] = u; if(!done[u]) { done[u] = true; q.push(ls); } break; } ask.pop_back(); ls = j; } } } } else { if(!vis[i]) { vis[i] = vis[which[0]] = true; Answer(i, which[0]); } } } for(int i = 1; i <= 2 * n; i++) { if(vis[i]) continue; if(bro[i].empty()) continue; int harazat = -1; for(auto j: bro[i]) { if(j == p[i]) continue; if(j == iran[i]) continue; assert(harazat == -1); harazat = j; } assert(harazat != -1); vis[i] = vis[harazat] = true; Answer(i, harazat); } }

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

chameleon.cpp: In function 'void setIO(std::string)':
chameleon.cpp:94:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |     freopen((str + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
chameleon.cpp:95:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   95 |     freopen((str + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
chameleon.cpp:97:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   97 |     freopen("input.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
chameleon.cpp:98:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   98 |     freopen("output.txt", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...