제출 #833736

#제출 시각아이디문제언어결과실행 시간메모리
833736finn__버섯 세기 (IOI20_mushrooms)C++17
0 / 100
2 ms336 KiB
#include <bits/stdc++.h> #include "mushrooms.h" using namespace std; constexpr size_t M = 141; int count_mushrooms(int n) { // Binary search for another A. bool second_is_b = use_machine({0, 1}); int a = 1, b = second_is_b ? n : 1, c = 0, lower_limit = 0; while (a < b) { int mid = (a + b) / 2; vector<int> v(mid - lower_limit + 1); iota(v.begin(), v.end(), lower_limit); int x = use_machine(v) + c; if (x >= 2) b = mid; else a = mid + 1, lower_limit = mid, c = x; } if (a == n) return 1; int last_known = a, num_a = 2; // Search for at least M A or B. vector<int> a_indices = {0, a}, b_indices; for (int i = last_known + 1; i + 1 < n; i += 2) { int x = use_machine({0, i, a, i + 1}); last_known = i + 1; if (x & 1) b_indices.push_back(i + 1); else a_indices.push_back(i + 1), ++num_a; if (x & 2) b_indices.push_back(i); else a_indices.push_back(i), ++num_a; if (a_indices.size() >= M || b_indices.size() >= M) break; } if (last_known == n - 2) { num_a += !use_machine({0, n - 1}); ++last_known; } if (last_known == n - 1) return num_a; { vector<int> r = a_indices.size() == M ? a_indices : b_indices; bool flag = a_indices.size() != M; for (int i = last_known + 1; i < n; i += M) { vector<int> v; for (int j = 0; j < M && i + j < n; ++j) { v.push_back(r[j]); v.push_back(i + j); } int x = use_machine(v); num_a += flag ? (x + 1) / 2 : v.size() / 2 - (x + 1) / 2; } } return num_a; }

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

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:65:31: warning: comparison of integer expressions of different signedness: 'int' and 'const size_t' {aka 'const long unsigned int'} [-Wsign-compare]
   65 |             for (int j = 0; j < M && i + j < n; ++j)
      |                             ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...