# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
879624 | 2023-11-27T18:43:21 Z | andrei_boaca | Mechanical Doll (IOI18_doll) | C++17 | 1 ms | 5724 KB |
#include "doll.h" #include <bits/stdc++.h> //#include "grader.cpp" using namespace std; typedef long long ll; typedef pair<int,int> pii; int n; const int INF=1e9; vector<int> vecini[100005]; vector<int> C,X,Y; vector<int> v; int lft[5000005],rgt[5000005]; int s; int state[5000005]; int added=0; int build(int lg) { if(lg==1) return INF; added+=lg%2; lg+=lg%2; int a=build(lg/2); int b=build(lg/2); s++; lft[s]=a; rgt[s]=b; return -s; } int plsmake() { if(v.size()==1) return v[0]; ll lg=v.size(); added=0; int c=build(lg); vector<pii> ord; for(int i=1;i<=lg+added;i++) { int nod=c; while(true) { nod=abs(nod); if(state[nod]==0) { if(lft[nod]==INF) { ord.push_back({nod,0}); state[nod]^=1; break; } state[nod]=1; nod=lft[nod]; continue; } else { if(rgt[nod]==INF) { ord.push_back({nod,1}); state[nod]^=1; break; } state[nod]=0; nod=rgt[nod]; continue; } } } for(int i=0;i<ord.size();i++) { int who=ord[i].first; int dir=ord[i].second; if(i+1<v.size()) { if(dir==0) lft[who]=v[i]; else rgt[who]=v[i]; continue; } if(i+1==ord.size()) { if(dir==0) lft[who]=v.back(); else rgt[who]=v.back(); continue; } if(dir==0) lft[who]=c; else rgt[who]=c; } return c; } void create_circuit(int M, std::vector<int> A) { C.resize(M+1); n=A.size(); /*if(M==1) { C[0]=1; if(n==1) { answer(C,X,Y); return; } s=1; C[1]=-s; for(int i=1;i<A.size();i++) { lft[s]=1; if(i+1==A.size()) rgt[s]=0; else { rgt[s]=-(s+1); s++; } } for(int i=1;i<=s;i++) { X.push_back(lft[i]); Y.push_back(rgt[i]); } answer(C,X,Y); return; }*/ for(int i=0;i<A.size();i++) { int x=A[i]; int nxt=0; if(i+1<A.size()) nxt=A[i+1]; vecini[x].push_back(nxt); } C[0]=A[0]; for(int i=1;i<=M;i++) { if(vecini[i].empty()) { C[i]=0; continue; } else { v=vecini[i]; C[i]=plsmake(); } } for(int i=1;i<=s;i++) { X.push_back(lft[i]); Y.push_back(rgt[i]); } for(int i=0;i<C.size();i++) cout<<C[i]<<' '; cout<<'\n'; for(int i=1;i<=s;i++) cout<<-i<<' '<<X[i-1]<<' '<<Y[i-1]<<'\n'; answer(C,X,Y); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 3676 KB | DO NOT PRINT ANYTHING TO STANDARD OUTPUT |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 3676 KB | DO NOT PRINT ANYTHING TO STANDARD OUTPUT |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 3676 KB | DO NOT PRINT ANYTHING TO STANDARD OUTPUT |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 5724 KB | DO NOT PRINT ANYTHING TO STANDARD OUTPUT |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 5724 KB | DO NOT PRINT ANYTHING TO STANDARD OUTPUT |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 5724 KB | DO NOT PRINT ANYTHING TO STANDARD OUTPUT |
2 | Halted | 0 ms | 0 KB | - |