# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
413828 | ivan24 | 버섯 세기 (IOI20_mushrooms) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "mushrooms.h"
#include <bits/stdc++.h>
using namespace std;
using ll = int;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
#define F first
#define S second
int main() {
check_input(1 == scanf("%d", &n), "Could not read n.");
check_input(min_n <= n, "n must not be less than %d, but it is %d.", min_n, n);
check_input(n <= max_n, "n must not be greater than %d, but it is %d.", max_n, n);
species.resize(n);
for (int i = 0; i < n; i++) {
check_input(1 == scanf("%d", &species[i]), "Could not read species element [%d].", i);
check_input(species[i]==species_A || species[i] == species_B,
"Species elements must be %d or %d, but species element [%d] is %d.", species_A, species_B, i, species[i]);
}
check_input(species[0] == species_A, "Species element [%d] must be %d.", 0, species_A);
// Postponed closing standard input in order to allow interactive usage of the grader.
qc = 0;
qs = 0;
int answer = count_mushrooms(n);
printf("%d\n%d\n", answer, qc);
fclose(stdout);
fclose(stdin);
return 0;
}
class Solver{
private:
ll n;
vvi known;
void typeZeroQuery (ll x){
ll res = use_machine(vi{0,x});
known[res].push_back(x);
}
void typeOneQuery(ll x1, ll x2){
ll curType = 0;
if (2 > known[0].size()) curType = 1;
vi v = {known[curType][0],x1,known[curType][1],x2};
ll res = use_machine(v);
if (res & 2){
known[1-curType].push_back(x1);
}else{
known[curType].push_back(x1);
}
if (res & 1){
known[1-curType].push_back(x2);
}else{
known[curType].push_back(x2);
}
}
public:
Solver(ll n): n(n){
}
ll solve(){
known.assign(2,vi());
known[0].push_back(0);
for (ll i = 1; 3 > i; i++){
typeZeroQuery(i);
}
for (ll i = 3; n > i+1; i+=2){
typeOneQuery(i,i+1);
}
if (n%2 == 0) typeZeroQuery(n-1);
return known[0].size();
}
};
int count_mushrooms(int n) {
Solver mySolver(n);
return mySolver.solve();
}