Submission #414927

#TimeUsernameProblemLanguageResultExecution timeMemory
414927Pro_ktmrLibrary (JOI18_library)C++17
100 / 100
234 ms476 KiB
#include"bits/stdc++.h" #include"library.h" #include<unordered_set> #include<unordered_map> #include<random> using namespace std; typedef long long ll; const ll MOD = (ll)(1e9+7); #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++) int dx[4]={ 1,0,-1,0 }; int dy[4]={ 0,1,0,-1 }; namespace A{ int N; vector<pair<int,int>> e; int siz(int l, int r){ int ret = r-l; rep(i, e.size()){ if(l <= e[i].first && e[i].first < r && l <= e[i].second && e[i].second < r) ret--; } return ret; } int Search1(int l, int r, int x){ if(l+1 == r) return l; vector<int> tmp(N, 0); int m = (l+r)/2; for(int i=l; i<m; i++) tmp[i] = 1; tmp[x] = 1; int ret = Query(tmp); if(siz(l, m) == ret) return Search1(l, m, x); else return Search1(m, r, x); } pair<int, int> Search2(int l, int r, int x){ vector<int> tmp(N, 0); int m = (l+r)/2; for(int i=l; i<m; i++) tmp[i] = 1; tmp[x] = 1; int ret = Query(tmp); if(siz(l, m)-1 == ret) return Search2(l, m, x); else if(siz(l, m)+1 == ret) return Search2(m, r, x); else return mp(Search1(l, m, x), Search1(m, r, x)); } vector<int> ls[1000]; void dfs(int n, int b, vector<int>& ans){ ans.pb(n+1); rep(i, ls[n].size()){ if(ls[n][i] == b) continue; dfs(ls[n][i], n, ans); } } } void Solve(int _N){ using namespace A; N = _N; if(N == 1){ Answer({ 1 }); return; } int memo[1000]; rep(i, N){ vector<int> tmp(N, 0); rep(j, i+1) tmp[j] = 1; memo[i] = Query(tmp); if(i > 0 && memo[i-1]+1 != memo[i]){ pair<int, int> ret = mp(-1,-1); if(memo[i-1] == memo[i]) ret.first = Search1(0, i, i); else ret = Search2(0, i, i); e.pb({ ret.first, i }); if(ret.second != -1) e.pb({ ret.second, i }); } } rep(i, e.size()){ ls[e[i].first].pb(e[i].second); ls[e[i].second].pb(e[i].first); } rep(i, N){ if(ls[i].size() == 1){ vector<int> ans; dfs(i, -1, ans); Answer(ans); return; } } }

Compilation message (stderr)

library.cpp: In function 'int A::siz(int, int)':
library.cpp:12:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   12 | #define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
      |                           ^
library.cpp:22:3: note: in expansion of macro 'rep'
   22 |   rep(i, e.size()){
      |   ^~~
library.cpp: In function 'void A::dfs(int, int, std::vector<int>&)':
library.cpp:12:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   12 | #define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
      |                           ^
library.cpp:55:3: note: in expansion of macro 'rep'
   55 |   rep(i, ls[n].size()){
      |   ^~~
library.cpp: In function 'void Solve(int)':
library.cpp:12:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   12 | #define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
      |                           ^
library.cpp:70:2: note: in expansion of macro 'rep'
   70 |  rep(i, N){
      |  ^~~
library.cpp:12:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   12 | #define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
      |                           ^
library.cpp:72:3: note: in expansion of macro 'rep'
   72 |   rep(j, i+1) tmp[j] = 1;
      |   ^~~
library.cpp:12:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   12 | #define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
      |                           ^
library.cpp:83:2: note: in expansion of macro 'rep'
   83 |  rep(i, e.size()){
      |  ^~~
library.cpp:12:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   12 | #define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
      |                           ^
library.cpp:87:2: note: in expansion of macro 'rep'
   87 |  rep(i, N){
      |  ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...