제출 #718230

#제출 시각아이디문제언어결과실행 시간메모리
718230baojiaopisuCounting Mushrooms (IOI20_mushrooms)C++14
74.34 / 100
9 ms556 KiB
#include "mushrooms.h" #include <vector> #include <iostream> #include <algorithm> #include <array> #include <random> #include <chrono> using namespace std; #define pb push_back mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int count_mushrooms(int n) { vector<int> a, b; vector<int> not_solved; for(int i = 1; i < n; i++) not_solved.pb(i); a.pb(0); shuffle(not_solved.begin(), not_solved.end(), rng); int res = 1; while(not_solved.size()) { if(a.size() >= b.size()) { vector<int> r; while(not_solved.size() && r.size() < a.size()) { r.pb(not_solved.back()); not_solved.pop_back(); } vector<int> ask; for(int i = 0; i < (int)a.size(); i++) { if(i < r.size()) ask.pb(r[i]); ask.pb(a[i]); } int x = use_machine(ask); res += r.size() - ((x + 1) / 2); for(int i = 1; i <= 5; i++) { if(r.empty() || a.size() >= 150) break; if(a.size() == 1 || r.size() == 1) { int u = r.back(); r.pop_back(); if(use_machine({a[0], u})) { b.pb(u); } else a.pb(u); } else { int u = r.back(); r.pop_back(); int v = r.back(); r.pop_back(); int d = use_machine({a[0], u, a[1], v}); if(d & 1) b.pb(v); else a.pb(v); if(d & 2) b.pb(u); else a.pb(u); } } } else { vector<int> r; while(not_solved.size() && r.size() < b.size()) { r.pb(not_solved.back()); not_solved.pop_back(); } vector<int> ask; for(int i = 0; i < (int)b.size(); i++) { if(i < r.size()) ask.pb(r[i]); ask.pb(b[i]); } int x = use_machine(ask); res += (x + 1) / 2; for(int i = 1; i <= 5; i++) { if(r.empty() || b.size() >= 150) break; if(b.size() == 1 || r.size() == 1) { int u = r.back(); r.pop_back(); if(use_machine({b[0], u})) { a.pb(u); } else b.pb(u); } else { int u = r.back(); r.pop_back(); int v = r.back(); r.pop_back(); int d = use_machine({b[0], u, b[1], v}); if(d & 1) a.pb(v); else b.pb(v); if(d & 2) a.pb(u); else b.pb(u); } } } } return res; }

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

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:31:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     if(i < r.size()) ask.pb(r[i]);
      |        ~~^~~~~~~~~~
mushrooms.cpp:64:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |     if(i < r.size()) ask.pb(r[i]);
      |        ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...