Submission #972827

#TimeUsernameProblemLanguageResultExecution timeMemory
972827kwongwengMechanical Doll (IOI18_doll)C++17
53 / 100
125 ms22328 KiB
#include "doll.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> ii; typedef vector<ii> vii; typedef long double ld; typedef vector<vector<ll>> vll; #define FOR(i, a, b) for(int i = a; i < b; i++) #define ROF(i, a, b) for(int i = a; i >= b; i--) #define pb push_back #define ms memset #define fi first #define se second const int mxN = 1e6+1; int cur = 1; vi X(mxN),Y(mxN),C; void build(int i, vi nxt){ if (nxt.size()==2){ X[i-1] = nxt[0]; Y[i-1] = nxt[1]; return; } int len = nxt.size(); if (len % 2 == 0){ X[i-1] = -cur; cur++; vi Nxt; for (int j = 0; j < len; j+=2) Nxt.pb(nxt[j]); build(cur-1,Nxt); Nxt.clear(); for (int j = 1; j < len; j+=2) Nxt.pb(nxt[j]); Y[i-1] = -cur; cur++; build(cur-1,Nxt); }else{ X[i-1] = -cur; cur++; vi Nxt; for (int j = 0; j < len-1; j+=2) Nxt.pb(nxt[j]); Nxt.pb(-i); build(cur-1,Nxt); Nxt.clear(); for (int j = 1; j < len; j+=2) Nxt.pb(nxt[j]); Y[i-1] = -cur; cur++; Nxt.pb(nxt[len-1]); build(cur-1,Nxt); } } void create_circuit(int M, vi A) { int N = A.size(); C.resize(M+1); C[0] = A[0]; vi nxt[M+1]; FOR(i,0,N-1){ nxt[A[i]].pb(A[i+1]); } nxt[A[N-1]].pb(0); FOR(i,1,M+1){ if (nxt[i].empty()) continue; if (nxt[i].size()==1){ C[i] = nxt[i][0]; continue; } C[i] = -cur; cur++; build(cur-1,nxt[i]); } vi x(cur-1), y(cur-1); FOR(i,0,cur-1){ x[i]=X[i]; y[i]=Y[i]; } answer(C, x, y); }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...