Submission #225921

#TimeUsernameProblemLanguageResultExecution timeMemory
225921erd1Park (JOI17_park)C++14
67 / 100
181 ms760 KiB
#include "park.h" #include<bits/stdc++.h> #define all(x) (x).begin(), (x).end() #define pb push_back using namespace std; template<typename Iter> ostream& outIt(ostream& out, Iter b, Iter e){ for(Iter i = b; i != e; i++) out << (i == b?"":" ") << *i; return out; } template<typename T> ostream& operator<<(ostream& out, vector<T>& v){ return outIt(out << '[', all(v)) << ']'; } static int Place[1400]; int ran(int t = INT_MAX){ static int x = 10292837; return ((x*0xdefaced+1)&INT_MAX)%t; } bool ask(int l, int r){ //cout << l << " " << r << endl; //for(int i = 0; i < 6; i++)cout << Place[i] << " "; cout << endl; return Ask(min(l, r), max(l, r), Place); } void answer(int l, int r){ Answer(min(l, r), max(l, r)); } void Sort(int l, int r, vector<int>& v){ //cout << l << " " <<r << " " << v<< endl; if(v.size() == 0) return answer(l, r); if(v.size() == 1) return answer(l, v[0]), answer(v[0], r); int pivot = v[ran(v.size())]; for(auto i: v)Place[i] = 1; Place[l] = Place[r] = 1; vector<int> R, L; for(auto i: v) if(i != pivot) Place[i] = 0, (ask(l, pivot)?R:L).pb(i), Place[i] = 1; for(auto i: v)Place[i] = 0; Place[l] = Place[r] = 0; Sort(l, pivot, L); Sort(pivot, r, R); auto st = copy(all(L), v.begin()); *st = pivot; copy(all(R), next(st)); } int FindLink(int N, int x, vector<int> v){ int l = 0, r = v.size(); //cout << "FindLink" << v << endl; for(int i = 0; i < N; i++)Place[i] = 1; while(r-l > 1){ for(int i = (l+r>>1); i < v.size();i++)Place[v[i]] = 0; (ask(v[0], x)?r:l) = l+r>>1; for(int i = 0; i < v.size();i++)Place[v[i]] = 1; } for(int i = 0; i < N; i++)Place[i] = 0; return v[l]; } vector<int> Findchain(int x, int y, vector<int>& pool){ //cout << "Findchain" << endl; Place[x] = Place[y] = 1; vector<int> ans; if(ask(x, y))return Place[x] = Place[y], ans; int l = -1, r = pool.size(); while(true){ while(r-l > 1){ for(auto i: pool)Place[i] = false; for(int i = 0; i < (l+r>>1); i++)Place[pool[i]] = 1; (ask(x, y)?r:l) = (l+r>>1); } if(r == 0)break; ans.pb(pool[r-1]); Place[pool[r-1]] = 1; pool.erase(pool.begin()+r-1); l = -1; } for(auto i: pool)Place[i] = false; for(auto i: ans)Place[i] = false; reverse(all(ans)); return ans; } vector<int> v, ord, pool; vector<bool> used; void Detect(int T, int N) { if(T == 2){ v.resize(N-2); iota(all(v), 1); Sort(0, N-1, v); } if(T == 3 || T == 4){ v.resize(N-1); iota(all(v), 1); pool.resize(N-1); iota(all(pool), 1); used.resize(N); ord.pb(0); random_shuffle(all(v), ran); //cout << v << endl; for(auto i: v){ if(used[i])continue; int x = FindLink(N, i, ord); pool.erase(find(all(pool), i)); auto vs = Findchain(x, i, pool); //cout << x << " " << i << vs << endl; for(auto j: vs)used[j] = true; Sort(x, i, vs); copy(all(vs), inserter(ord, ord.end())); ord.pb(i); //cout << ord << endl; vs.resize(0); } } }

Compilation message (stderr)

park.cpp: In function 'int FindLink(int, int, std::vector<int>)':
park.cpp:59:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         for(int i = (l+r>>1); i < v.size();i++)Place[v[i]] = 0;
                      ~^~
park.cpp:59:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = (l+r>>1); i < v.size();i++)Place[v[i]] = 0;
                               ~~^~~~~~~~~~
park.cpp:60:31: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         (ask(v[0], x)?r:l) = l+r>>1;
                              ~^~
park.cpp:61:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0; i < v.size();i++)Place[v[i]] = 1;
                        ~~^~~~~~~~~~
park.cpp: In function 'std::vector<int> Findchain(int, int, std::vector<int>&)':
park.cpp:75:34: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
             for(int i = 0; i < (l+r>>1); i++)Place[pool[i]] = 1;
                                 ~^~
park.cpp:76:33: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
             (ask(x, y)?r:l) = (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...