Submission #592891

#TimeUsernameProblemLanguageResultExecution timeMemory
592891farhan132자동 인형 (IOI18_doll)C++17
49 / 100
301 ms70200 KiB
#include "doll.h" #include <bits/stdc++.h> using namespace std; typedef int ll; typedef pair<ll , ll> ii; #define ff first #define ss second #define pb push_back const ll N = 1e6 + 5; vector < ll > v[N]; vector < ll > g[N]; ll S = 0; ll col[N]; vector < ll > child; vector < ll > X,Y; void setX(ll i, ll x){ X[abs(i) - 1] = x; return; } void setY(ll i, ll y){ Y[abs(i) - 1] = y; return; } ll tot = 0; ll breakdown(ll sz){ if(sz == 2){ S--; X.pb(0); Y.pb(0); tot += 2; return S; } ll node = S - 1; S--; X.pb(0); Y.pb(0); ll n1 = breakdown(sz/2); ll n2 = breakdown(sz/2); g[-node].pb(-n1); g[-node].pb(-n2); setX(node, n1); setY(node, n2); return node; } void go(ll node, ll sz){ if(sz == 2){ child.pb(node); col[-node] ^= 1; return; } if(col[-node]) go(-g[-node][1], sz/2); else go(-g[-node][0], sz/2); col[-node] ^= 1; return; } void create_circuit(int M, std::vector<int> A) { memset(col, 0, sizeof(col)); ll n = A.size(); A.pb(0); for(ll i = 0; i < n; i++){ v[A[i]].pb(A[i + 1]); } ll m = M; vector < ll > C(m + 1); C[0] = A[0]; vector < ll > all; for(ll i = 1; i <= m; i++){ if(v[i].size() == 0){ C[i] = 0; continue; } if(v[i].size() == 1){ C[i] = v[i][0]; continue; } C[i] = -1; } for(ll i = 0; i < n; i++){ if(C[A[i]] == -1){ all.pb(A[i + 1]); } } if(all.size()){ ll two = 1; ll d = 1; while(two * 2 < all.size()) two *= 2, d++; two *= 2; child.clear(); tot = 0; ll root = breakdown(two); while(tot--) go(root, two); ll rem = child.size(); ll cur = 0; for(ll j = 0; j < child.size(); j++){ if(rem > all.size()){ if(col[-child[j]]) setY(child[j], root); else setX(child[j], root); }else{ if(col[-child[j]]) setY(child[j], all[cur]); else setX(child[j], all[cur]); cur++; } col[-child[j]] ^= 1; rem--; } } #ifdef LOCAL for(ll i = 0; i <= m; i++){ cout << C[i] << ' '; } cout << '\n'; for(ll i = 0; i < X.size(); i++){ cout << -(i + 1) << ' ' << X[i] << ' ' << Y[i] << '\n'; } #endif answer(C, X, Y); }

Compilation message (stderr)

doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:89:19: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |     while(two * 2 < all.size()) two *= 2, d++;
      |           ~~~~~~~~^~~~~~~~~~~~
doll.cpp:96:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |     for(ll j = 0; j < child.size(); j++){
      |                   ~~^~~~~~~~~~~~~~
doll.cpp:97:14: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |       if(rem > all.size()){
      |          ~~~~^~~~~~~~~~~~
#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...