# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
346119 | Ikkyu9541 | 버섯 세기 (IOI20_mushrooms) | C++17 | 12 ms | 492 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "mushrooms.h"
#include <vector>
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
int count_mushrooms(int n) {
bool b[100005];
int ans = 1;
b[0] = 0;
vector<int> a;
a.push_back(0);
a.push_back(0);
vector<int> m[2];
m[0].push_back(0);
int i;
if(n < 200){
for (i = 1; i < n; i++){
a[0] = i-1; a[1] = i;
int u = use_machine(a);
if(u){
b[i] = !b[i-1];
}
else{
b[i] = b[i-1];
}
if(b[i] == 0) ans++;
}
return ans;
}
for (i = 1; i*i < n; i++){
a[0] = i-1; a[1] = i;
int u = use_machine(a);
if(u){
b[i] = !b[i-1];
}
else{
b[i] = b[i-1];
}
if(b[i] == 0) ans++;
m[b[i]].push_back(i);
}
a.clear();
int mm;
if(m[0].size() > m[1].size()) mm = 0;
else mm = 1;
/*
printf("(");
for(int j=0; j<m[0].size(); j++){
printf("%d, ", m[0][j]);
}
printf(")");
printf("(");
for(int j=0; j<m[1].size(); j++){
printf("%d, ", m[1][j]);
}
printf(")");*/
int mms = m[mm].size();
int l = 0;
a.push_back(m[mm][l%m[mm].size()]); l++;
while(i<n){
a.push_back(i);
a.push_back(m[mm][l%m[mm].size()]); l++;
if(i==n-1 || a.size() >= (mms*2)-1){
/*
printf("[");
for(int j=0; j<a.size(); j++){
printf("%d, ", a[j]);
}*/
int ta;
if(mm == 1)
ta = use_machine(a)/2;
else
ta = (a.size()/2) - (use_machine(a)/2);
ans += ta;
// printf(":%d]", ta);
a.clear();
l = 0;
a.push_back(m[mm][l%m[mm].size()]); l++;
}
i++;
}
return ans;
}
/*
0 0 1 1 0 1 0 1 0 0 0 0 1 1 1 0 1 0 1 1 1 0 0 0 1 1 0 1 0 1 0 1 0 1 1
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
0 0 1 0 1 0 1 0 0 0 1 0 1 0 1 1 1 1 0 0 1 0 1 0 1 0 1 0 1 1 1 0 1 0 1 1 0 1 0 1 0 1 0 1 0 1 1 0 1 0
*/
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |