제출 #697544

#제출 시각아이디문제언어결과실행 시간메모리
697544garam1732버섯 세기 (IOI20_mushrooms)C++14
0 / 100
2 ms208 KiB
#include "mushrooms.h" #include <bits/stdc++.h> using namespace std; vector<int> a, b; int cnt = 106; int count_mushrooms(int n) { a.push_back(0); if(n < 2*cnt+5) { for(int i = 1; i < n; i++) use_machine({0, i}) ? b.push_back(i) : a.push_back(i); return a.size(); } use_machine({0, 1}) ? b.push_back(1) : a.push_back(1); use_machine({0, 2}) ? b.push_back(2) : a.push_back(2); if(a.size() > 1) { int x = use_machine({a[0], 3, a[1], 4}); (x&1) ? b.push_back(4) : a.push_back(4); (x&2) ? b.push_back(3) : a.push_back(3); } else { int x = use_machine({b[0], 3, b[1], 4}); (x&1) ? a.push_back(4) : b.push_back(4); (x&2) ? a.push_back(3) : b.push_back(3); } int idx = 5; bool flag = false; if(a.size() < 3) flag = true; if(flag) swap(a, b); if(a.size() > 2) { while(idx <= 2*cnt) { int x = use_machine({a[0], idx, a[1], idx+1, a[2], idx+2}); (x&1) ? b.push_back(idx+2) : a.push_back(idx+2); if(x/2 == 0) { a.push_back(idx); a.push_back(idx+1); idx += 3; } else if(x/2 == 2) { b.push_back(idx); b.push_back(idx+1); idx += 3; } else if(b.size() > 1) { int x = use_machine({b[0], idx, b[1], a[0], idx+1, a[1], idx+3, a[2], idx+4}); (x&1) ? b.push_back(idx+4) : a.push_back(idx+4); (x&2) ? b.push_back(idx+3) : a.push_back(idx+3); (x&4) ? b.push_back(idx+1) : a.push_back(idx+1); (x&4) ? a.push_back(idx) : b.push_back(idx); idx += 5; } else { int x = use_machine({a[0], idx, a[1], idx+3}); (x&1) ? b.push_back(idx+3) : a.push_back(idx+3); (x&2) ? b.push_back(idx) : a.push_back(idx); (x&2) ? a.push_back(idx+1) : b.push_back(idx+1); idx += 4; } } } if(flag) swap(a, b); if(a.size() + b.size() == n) return a.size(); std::vector<int> m; int res = a.size(); idx = 2*cnt+1; while(idx < n) { if(a.size() > b.size()) { int z; m.clear(); for(int i = 0; i < a.size(); i++) { if(idx < n) { if(i == 0) z = idx; m.push_back(idx++); } m.push_back(a[i]); } int x = use_machine(m); res += (int)m.size() - (int)a.size() - (x+1)/2; (x&1) ? b.push_back(z) : a.push_back(z); } else { int z; m.clear(); for(int i = 0; i < b.size(); i++) { if(idx < n) { if(i == 0) z = idx; m.push_back(idx++); } m.push_back(b[i]); } int x = use_machine(m); res += (x+1)/2; (x&1) ? a.push_back(z) : b.push_back(z); } } return res; }

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

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:69:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   69 |  if(a.size() + b.size() == n) return a.size();
      |     ~~~~~~~~~~~~~~~~~~~~^~~~
mushrooms.cpp:78:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |             for(int i = 0; i < a.size(); i++) {
      |                            ~~^~~~~~~~~~
mushrooms.cpp:93:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |             for(int i = 0; i < b.size(); i++) {
      |                            ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...