제출 #718448

#제출 시각아이디문제언어결과실행 시간메모리
718448baojiaopisuCounting Mushrooms (IOI20_mushrooms)C++14
25 / 100
25 ms464 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()) {
			if(a.size() >= 150) {
				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);
				if(x & 1) {
					b.pb(r[0]);
					swap(r[0], r[r.size() - 1]);
					r.pop_back();
				} else {
					a.pb(r[0]);
					swap(r[0], r[r.size() - 1]);
					r.pop_back();
				}
			} else {
				for(int i = 1; i <= 5; i++) {
					if(not_solved.empty() || a.size() >= 150) break;
					if(a.size() == 1 || not_solved.size() == 1) {
						int u = not_solved.back();
						not_solved.pop_back();
						if(use_machine({a[0], u})) {
							b.pb(u);
						} else {
							++res;
						}
					} else {
						int u = not_solved.back();
						not_solved.pop_back();
						int v = not_solved.back();
						not_solved.pop_back();
						int d = use_machine({a[0], u, a[1], v});
						if(d & 1) b.pb(v); else a.pb(v), res++;
						if(d & 2) b.pb(u); else a.pb(u), res++;
					}
				}
			}
		} else {
			if(b.size() >= 150) {
				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);
				if(x & 1) {
					a.pb(r[0]);
					swap(r[0], r[r.size() - 1]);
					r.pop_back();
				} else {
					b.pb(r[0]);
					swap(r[0], r[r.size() - 1]);
					r.pop_back();
				}
				res += (x + 1) / 2;
			} else {
				for(int i = 1; i <= 5; i++) {
					if(not_solved.empty() || b.size() >= 150) break;
					if(b.size() == 1 || not_solved.size() == 1) {
						int u = not_solved.back();
						not_solved.pop_back();
						if(use_machine({b[0], u})) {
							a.pb(u);
							++res;
						} else b.pb(u);
					} else {
						int u = not_solved.back();
						not_solved.pop_back();
						int v = not_solved.back();
						not_solved.pop_back();
						int d = use_machine({b[0], u, b[1], v});
						if(d & 1) a.pb(v), res++; else b.pb(v);
						if(d & 2) a.pb(u), res++; else b.pb(u);
					}
				}
			}
		}
	}

	return res;
}

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

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