답안 #1040067

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1040067 2024-07-31T15:29:23 Z Dan4Life 버섯 세기 (IOI20_mushrooms) C++17
100 / 100
5 ms 884 KB
#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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 4 ms 688 KB Output is correct
8 Correct 2 ms 476 KB Output is correct
9 Correct 5 ms 600 KB Output is correct
10 Correct 3 ms 600 KB Output is correct
11 Correct 3 ms 600 KB Output is correct
12 Correct 3 ms 532 KB Output is correct
13 Correct 3 ms 600 KB Output is correct
14 Correct 2 ms 520 KB Output is correct
15 Correct 3 ms 600 KB Output is correct
16 Correct 3 ms 540 KB Output is correct
17 Correct 2 ms 344 KB Output is correct
18 Correct 3 ms 856 KB Output is correct
19 Correct 3 ms 532 KB Output is correct
20 Correct 3 ms 600 KB Output is correct
21 Correct 3 ms 600 KB Output is correct
22 Correct 3 ms 600 KB Output is correct
23 Correct 5 ms 628 KB Output is correct
24 Correct 2 ms 344 KB Output is correct
25 Correct 3 ms 508 KB Output is correct
26 Correct 3 ms 600 KB Output is correct
27 Correct 3 ms 600 KB Output is correct
28 Correct 3 ms 648 KB Output is correct
29 Correct 3 ms 536 KB Output is correct
30 Correct 3 ms 600 KB Output is correct
31 Correct 3 ms 796 KB Output is correct
32 Correct 4 ms 600 KB Output is correct
33 Correct 3 ms 524 KB Output is correct
34 Correct 3 ms 600 KB Output is correct
35 Correct 3 ms 600 KB Output is correct
36 Correct 3 ms 632 KB Output is correct
37 Correct 3 ms 600 KB Output is correct
38 Correct 3 ms 600 KB Output is correct
39 Correct 3 ms 604 KB Output is correct
40 Correct 4 ms 600 KB Output is correct
41 Correct 3 ms 600 KB Output is correct
42 Correct 3 ms 476 KB Output is correct
43 Correct 3 ms 884 KB Output is correct
44 Correct 3 ms 600 KB Output is correct
45 Correct 3 ms 596 KB Output is correct
46 Correct 3 ms 600 KB Output is correct
47 Correct 3 ms 556 KB Output is correct
48 Correct 3 ms 600 KB Output is correct
49 Correct 3 ms 600 KB Output is correct
50 Correct 4 ms 600 KB Output is correct
51 Correct 3 ms 776 KB Output is correct
52 Correct 3 ms 600 KB Output is correct
53 Correct 3 ms 460 KB Output is correct
54 Correct 3 ms 600 KB Output is correct
55 Correct 5 ms 600 KB Output is correct
56 Correct 3 ms 600 KB Output is correct
57 Correct 5 ms 856 KB Output is correct
58 Correct 3 ms 552 KB Output is correct
59 Correct 3 ms 600 KB Output is correct
60 Correct 4 ms 600 KB Output is correct
61 Correct 4 ms 620 KB Output is correct
62 Correct 0 ms 344 KB Output is correct
63 Correct 0 ms 344 KB Output is correct
64 Correct 1 ms 344 KB Output is correct
65 Correct 0 ms 344 KB Output is correct
66 Correct 0 ms 344 KB Output is correct
67 Correct 1 ms 344 KB Output is correct
68 Correct 0 ms 344 KB Output is correct
69 Correct 0 ms 344 KB Output is correct
70 Correct 1 ms 344 KB Output is correct
71 Correct 0 ms 344 KB Output is correct
72 Correct 0 ms 344 KB Output is correct
73 Correct 0 ms 344 KB Output is correct
74 Correct 0 ms 344 KB Output is correct
75 Correct 0 ms 344 KB Output is correct
76 Correct 0 ms 344 KB Output is correct
77 Correct 0 ms 344 KB Output is correct
78 Correct 0 ms 344 KB Output is correct
79 Correct 0 ms 344 KB Output is correct
80 Correct 1 ms 344 KB Output is correct
81 Correct 0 ms 344 KB Output is correct
82 Correct 0 ms 344 KB Output is correct
83 Correct 0 ms 344 KB Output is correct
84 Correct 0 ms 344 KB Output is correct
85 Correct 0 ms 344 KB Output is correct
86 Correct 0 ms 344 KB Output is correct
87 Correct 0 ms 344 KB Output is correct
88 Correct 0 ms 344 KB Output is correct
89 Correct 0 ms 344 KB Output is correct
90 Correct 0 ms 344 KB Output is correct
91 Correct 0 ms 344 KB Output is correct