Submission #112074

#TimeUsernameProblemLanguageResultExecution timeMemory
112074AMO5Memory 2 (JOI16_memory2)C++98
100 / 100
3 ms1408 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include "Memory2_lib.h" using namespace std; using namespace __gnu_pbds; #define fi first #define se second #define mp make_pair #define pb push_back #define fbo find_by_order #define ook order_of_key #define all(x) (x).begin(), (x).end() typedef long long ll; typedef pair <int, int> pii; typedef pair <ll, ll> pll; typedef pair <ll, int> pli; typedef vector<int> vi; typedef vector<ll> vll; typedef long double ld; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; typedef set<int>::iterator sit; typedef map<int,int>::iterator mit; typedef vector<int>::iterator vit; long long INF=numeric_limits<long long>::max(); int vis[1011],p[1011]; int adj[505][505]; vector<int> pos[55]; /* int Flip(int a, int b) { cout << a << " " << b << endl; int c; cin >> c; return c; } void Answer(int a, int b, int c) { cout << a << " " << b << " " << c << endl; p[a] = c; p[b] = c; return; } */ void query(int a, int b, int c) { //cout << "q " << a << " " << b << " " << c << endl; if(adj[a][b]==adj[b][c]&&adj[a][b]==adj[a][c]) { } else if(adj[a][b] == adj[a][c]&&!vis[a]) { int val = adj[a][b]; pos[val].pb(a); vis[a] = 1; } else if(adj[a][b] == adj[b][c]&&!vis[b]) { int val = adj[a][b]; pos[val].pb(b); vis[b] = 1; } else if(adj[a][c] == adj[b][c]&&!vis[c]) { int val = adj[a][c]; pos[val].pb(c); vis[c] = 1; } return; } void Solve(int T, int N){ int n = N; N*=2; memset(vis,0,sizeof(vis)); memset(adj,-1,sizeof(adj)); for(int i = 0; i < N; i++) { if(vis[i])continue; for(int j = i+1; j < N; j++) { if(vis[j]||vis[i])continue; if(adj[i][j]==-1)adj[i][j] = Flip(i,j); for(int k = j+1; k < N; k++) { if(vis[k]||vis[j]||vis[i])continue; if(adj[i][k]==-1)adj[i][k] = Flip(i,k); if(adj[j][k]==-1)adj[j][k] = Flip(j,k); query(i,j,k); } } } /* for(int i = 0; i < n; i++) { cout << i << " --- "; for(int j = 0; j < pos[i].size(); j++){ cout << pos[i][j] << " " ; } cout << endl; } */ //visit smallest int ptr = -1; for(int i = 0; i < n; i++) { if(pos[i].empty()) { ptr = i; break; } } for(int i = 0; i < N; i++) { if(!vis[i])pos[ptr].pb(i); } for(int i = 0; i < n; i++) { Answer(pos[i][0],pos[i][1],i); } return; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...