제출 #592963

#제출 시각아이디문제언어결과실행 시간메모리
592963farhan132자동 인형 (IOI18_doll)C++17
100 / 100
298 ms68740 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 _n; 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); g[-node].pb(-n1); setY(node, n1); // cout << node << ' ' << n1 << '\n'; if(tot >= _n){ setX(node, -1); return node; } ll n2 = breakdown(sz/2); g[-node].pb(-n2); setX(node, n2); //cout << node << ' ' << n2 << '\n'; return node; } void go(ll node, ll sz){ if(g[-node].size() == 0){ child.pb(node); col[-node] ^= 1; return; } if(!col[-node]){ col[-node] ^= 1; if(g[-node].size() == 2) go(-g[-node][1], sz/2); else go(-1, 0); }else{ col[-node] ^= 1; go(-g[-node][0], sz/2); } 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; ll mx = 0; for(ll i = 1; i <= m; i++){ mx = max(mx, (ll)v[i].size()); 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()){ _n = 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); memset(col, 0, sizeof(col)); while(tot--) go(root, two); ll rem = child.size(); memset(col, 0, sizeof(col)); 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]); //cout << cur << ' ' << all[cur] << '\n'; 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); }

컴파일 시 표준 에러 (stderr) 메시지

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