Submission #424396

#TimeUsernameProblemLanguageResultExecution timeMemory
424396dualityPark (JOI17_park)C++11
100 / 100
604 ms1988 KiB
#define DEBUG 0 #include <bits/stdc++.h> using namespace std; #if DEBUG // basic debugging macros int __i__,__j__; #define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl #define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl #define printVar(n) cout<<#n<<": "<<n<<endl #define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl #define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;} #define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;} // advanced debugging class // debug 1,2,'A',"test"; class _Debug { public: template<typename T> _Debug& operator,(T val) { cout << val << endl; return *this; } }; #define debug _Debug(), #else #define printLine(l) #define printLine2(l,c) #define printVar(n) #define printArr(a,l) #define print2dArr(a,r,c) #define print2dArr2(a,r,c,l) #define debug #endif // define #define MAX_VAL 999999999 #define MAX_VAL_2 999999999999999999LL #define EPS 1e-6 #define mp make_pair #define pb push_back // typedef typedef unsigned int UI; typedef long long int LLI; typedef unsigned long long int ULLI; typedef unsigned short int US; typedef pair<int,int> pii; typedef pair<LLI,LLI> plli; typedef vector<int> vi; typedef vector<LLI> vlli; typedef vector<pii> vpii; typedef vector<plli> vplli; // ---------- END OF TEMPLATE ---------- #include "park.h" vi order; int seen[1400]; int P[1400]; int ask(int A,int B,int *P) { if (A > B) swap(A,B); return Ask(A,B,P); } int answer(int A,int B) { if (A > B) swap(A,B); Answer(A,B); return 0; } int add(int u,int N) { int i; for (i = 0; i < N; i++) P[i] = 0; for (i = 0; i < order.size(); i++) P[order[i]] = 1; P[u] = 1; if (ask(0,u,P)) order.pb(u),seen[u] = 1; else { vi o; for (i = 0; i < N; i++) { if (!seen[i] && (i != u)) o.pb(i); } int l = 0,r = o.size()-1; while (l < r) { int m = (l+r) / 2; for (i = 0; i < N; i++) P[i] = 0; for (i = 0; i < order.size(); i++) P[order[i]] = 1; P[u] = 1; for (i = 0; i <= m; i++) P[o[i]] = 1; if (ask(0,u,P)) r = m; else l = m+1; } add(o[l],N); add(u,N); } return 0; } vi adjList[1400]; vi e,c; bool comp(int a,int b) { return seen[a] < seen[b]; } int visited[1400]; int doDFS(int u,int p) { if (visited[u]) return 0; int i; c.pb(u); for (i = 0; i < adjList[u].size(); i++) { int v = adjList[u][i]; if (v != p) doDFS(v,u); } return 0; } int getEdges(vi v,int u,int N) { int i; sort(v.begin(),v.end(),comp); for (i = 0; i < N; i++) P[i] = 0; for (i = 0; i < v.size(); i++) P[v[i]] = 1; P[u] = 1; if (!ask(v[0],u,P)) return 0; int l = 0,r = v.size()-1; while (l < r) { int m = (l+r) / 2; for (i = 0; i < N; i++) P[i] = 0; for (i = 0; i <= m; i++) P[v[i]] = 1; P[u] = 1; if (ask(v[0],u,P)) r = m; else l = m+1; } e.pb(v[l]),visited[v[l]] = 1; vector<vi> com; for (i = 0; i < adjList[v[l]].size(); i++) { doDFS(adjList[v[l]][i],-1); if (!c.empty()) com.pb(c); c.clear(); } for (i = 0; i < com.size(); i++) getEdges(com[i],u,N); return 0; } void Detect(int T,int N) { int i; order.pb(0),seen[0] = 1; for (i = 1; i < N; i++) { if (!seen[i]) add(i,N); } vi v; for (i = 0; i < N; i++) seen[order[i]] = i; for (i = 1; i < N; i++) { int u = order[i]; fill(visited,visited+N,0); v.pb(order[i-1]); getEdges(v,u,N); int f = 1; while (!e.empty()) { if (f) adjList[e.back()].pb(u),adjList[u].pb(e.back()),f = 0; answer(e.back(),u); e.pop_back(); } } }

Compilation message (stderr)

park.cpp: In function 'int add(int, int)':
park.cpp:74:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |     for (i = 0; i < order.size(); i++) P[order[i]] = 1;
      |                 ~~^~~~~~~~~~~~~~
park.cpp:87:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |             for (i = 0; i < order.size(); i++) P[order[i]] = 1;
      |                         ~~^~~~~~~~~~~~~~
park.cpp: In function 'int doDFS(int, int)':
park.cpp:108:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  108 |     for (i = 0; i < adjList[u].size(); i++) {
      |                 ~~^~~~~~~~~~~~~~~~~~~
park.cpp: In function 'int getEdges(vi, int, int)':
park.cpp:118:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  118 |     for (i = 0; i < v.size(); i++) P[v[i]] = 1;
      |                 ~~^~~~~~~~~~
park.cpp:133:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  133 |     for (i = 0; i < adjList[v[l]].size(); i++) {
      |                 ~~^~~~~~~~~~~~~~~~~~~~~~
park.cpp:138:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  138 |     for (i = 0; i < com.size(); i++) getEdges(com[i],u,N);
      |                 ~~^~~~~~~~~~~~
#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...