# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1040067 | Dan4Life | 버섯 세기 (IOI20_mushrooms) | C++17 | 5 ms | 884 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "mushrooms.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) begin(a),end(a)
using ll = long long;
map<vector<int>,int> M;
int useM(vector<int> v){
if(M.count(v)) return M[v];
return M[v]=use_machine(v);
}
const int B = 100;
vector<int> V[2];
int count_mushrooms(int n) {
int ans = 1, i=1, P;
if(n<=200){
for(int i = 1; i < n; i++)
ans+=!useM({0,i});
return ans;
}
V[0].clear(), V[1].clear(); V[0].pb(0);
V[useM({0,i})].pb(i), i++;
V[useM({0,i})].pb(i), i++;
P = sz(V[1])>sz(V[0]);
int x = useM({V[P][0],i,V[P][1],i+1});
V[x%2?!P:P].pb(i+1); V[x>=2?!P:P].pb(i); i+=2;
while(i<n and sz(V[0])+sz(V[1])<2*B-1){
vector<int> v; v.clear();
P = sz(V[1])>sz(V[0]);
v.pb(V[P][0]), v.pb(i+1);
v.pb(V[P][1]), v.pb(i+2);
v.pb(V[P][2]), v.pb(i);
int x = useM(v), c1=P, c2=P, c3=P, c4=P, c5=P;
if(x%2) c3^=1, x--;
if(x!=2){
if(x==4) c1^=1, c2^=1;
V[c1].pb(i+1); V[c2].pb(i+2); V[c3].pb(i); i+=3;
}
else{
if(sz(V[!P])>=2){
v.clear(); v.pb(V[!P][0]), v.pb(i+1), v.pb(V[!P][1]); v.pb(V[P][0]);
v.pb(i+2); v.pb(V[P][1]); v.pb(i+3); v.pb(V[P][2]); v.pb(i+4);
x = useM(v)-1; c1 = !P;
if(x%2) c5^=1, x--;
if(x==2) c4^=1;
else if(x==4) c1^=1, c2^=1;
else if(x==6) c1^=1, c2^=1, c4^=1;
V[c1].pb(i+1); V[c2].pb(i+2); V[c3].pb(i); V[c4].pb(i+3); V[c5].pb(i+4); i+=5;
}
else{
if(useM({0,i+1})) c1=1,c2=0;
else c1=0, c2=1;
V[c1].pb(i+1); V[c2].pb(i+2); V[c3].pb(i); i+=3;
}
}
}
ans=sz(V[0]);
while(i<n){
P = sz(V[1])>sz(V[0]);
vector<int> v; v.clear();
for(int j = 0; j < sz(V[P]) and i<n; j++)
v.pb(V[P][j]), v.pb(i), i++;
int x = useM(v);
if(!P) ans+=sz(v)/2;
if(x%2) ans+=P?1:-1, V[P^1].pb(v.back());
else V[P].pb(v.back());
ans+=x/2*(P?1:-1);
if(i==n) break;
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |