제출 #129338

#제출 시각아이디문제언어결과실행 시간메모리
129338Just_Solve_The_Problem자동 인형 (IOI18_doll)C++11
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> #include "doll.h" //#include "grader.cpp" using namespace std; const int maxn = (int)1e6 + 7; const int inf = (int)1e6 + 6; int sz; void solve5(int M, vector<int> A) { int N = A.size(); vector<int> C(M + 1); vector<int> X, Y; C[0] = A[0]; int tmp = N - 1; while (tmp > 0) { sz++; tmp >>= 1; } if (sz) C[1] = -1; else C[1] = 0; X.resize(sz); Y.resize(sz); tmp = N - 1; for (int i = 1; i <= sz; i++) { if ((tmp >> (sz - i)) & 1) { X[i - 1] = A[0]; } else { X[i - 1] = -1; } Y[i - 1] = ((i == sz) ? 0 : -(i + 1)); } answer(C, X, Y); } vector <int> X, Y, a; int ind = -1, siz; int lim, NN; int make(int l, int r) { if (r + NN < lim) return -1; if (l == r) { int cur = 0; for (int i = 0; i < siz; i++) { if ((l >> i) & 1) cur |= (1 << siz - i - 1); } return cur; } int mid = (l + r) >> 1; int a, b; int cur = ind--; a = make(l, mid); b = make(mid + 1, r); X[-cur - 1] = a; Y[-cur - 1] = b; return cur--; } void solve1234(int M, vector<int> _A) { a = _A; a.push_back(0); NN = a.size(); lim = 1; while (lim < a.size()) { lim *= 2; siz++; } X.resize(lim); Y.resize(lim); vector <int> C(M + 1); if (NN == 1) { answer(C, X, Y); return ; } int qwe = make(0, lim - 1); fill(C.begin(), C.end(), qwe); while (X.back() == 0 && Y.back() == 0) { X.pop_back(); Y.pop_back(); } map<int, int> mp; for (int i = 0; i < X.size(); i++) { if (X[i] >= 0) mp[X[i]] = 0; if (Y[i] >= 0) mp[Y[i]] = 0; } int cnt = 0; for (auto &to : mp) { to.second = cnt++; } for (int i = 0; i < X.size(); i++) { if (X[i] >= 0) { X[i] = A[mp[X[i]]]; } if (Y[i] >= 0) { Y[i] = A[mp[Y[i]]]; } } //for (int i = 0; i < C.size(); i++) { //cout << C[i] << ' '; //} //cout << endl; //for (int i = 0; i < X.size(); i++) { //cout << X[i] << ' ' << Y[i] << endl; //} answer(C, X, Y); } void create_circuit(int M, vector<int> A) { if (M == 1) { solve5(M, A); } else { solve1234(M, A); } } /* 3 20 1 1 1 1 2 2 2 2 1 1 1 1 2 2 2 2 3 3 3 3 4 2 1 2 3 5 1 2 1 2 2 */

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

doll.cpp: In function 'int make(int, int)':
doll.cpp:47:46: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   47 |       if ((l >> i) & 1) cur |= (1 << siz - i - 1);
      |                                      ~~~~~~~~^~~
doll.cpp: In function 'void solve1234(int, std::vector<int>)':
doll.cpp:66:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |  while (lim < a.size()) {
      |         ~~~~^~~~~~~~~~
doll.cpp:84:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |   for (int i = 0; i < X.size(); i++) {
      |                   ~~^~~~~~~~~~
doll.cpp:92:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |   for (int i = 0; i < X.size(); i++) {
      |                   ~~^~~~~~~~~~
doll.cpp:94:14: error: 'A' was not declared in this scope
   94 |       X[i] = A[mp[X[i]]];
      |              ^
doll.cpp:97:14: error: 'A' was not declared in this scope
   97 |       Y[i] = A[mp[Y[i]]];
      |              ^