답안 #827378

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
827378 2023-08-16T12:00:56 Z ttamx 버섯 세기 (IOI20_mushrooms) C++14
100 / 100
8 ms 456 KB
#include "mushrooms.h"
#include<bits/stdc++.h>

using namespace std;

const int CUT=38;

int count_mushrooms(int n) {
	if(n==2)return 2-use_machine({0,1});
	vector<int> c(n);
	c[0]=0;
	vector<int> pos[2];
	for(int i=1;i<=2;i++)c[i]=use_machine({0,i});
	for(int i=0;i<=2;i++)pos[c[i]].emplace_back(i);
	int id=pos[1].size()>pos[0].size();
	int front=3;
	auto find2=[&](int idx){
		int tmp=use_machine({idx,pos[id][0],idx+1,pos[id][1]});
		c[idx]=tmp&1^id;
		c[idx+1]=tmp>>1^id;
	};
	if(front+1<n){
		find2(front);
		for(int j=0;j<2;j++)pos[c[front+j]].emplace_back(front+j);
		front+=2;
	}
	for(int i=0;i<CUT&&front+4<n;i++,front+=5){
		id=pos[1].size()>pos[0].size();
		int tmp=use_machine({front,pos[id][0],front+1,pos[id][1],front+2,pos[id][2]});
		c[front]=tmp&1^id;
		if((tmp>>1)!=1){
			c[front+1]=c[front+2]=tmp>>2^id;
			find2(front+3);
		}else{
			if(pos[id^1].size()>1){
				tmp=use_machine({front+3,pos[id][0],front+4,pos[id][1],front+1,pos[id][2],pos[id^1][0],front+2,pos[id^1][1]})-1;
				c[front+3]=tmp&1^id;
				c[front+4]=tmp>>1&1^id;
				c[front+1]=tmp>>2^id;
				c[front+2]=c[front+1]^1;
			}else{
				find2(front+1);
				find2(front+3);
			}
		}
		for(int j=0;j<5;j++)pos[c[front+j]].emplace_back(front+j);
	}
	int last=n;
	int sum=0;
	for(int i=front;i<last;i++){
		id=pos[1].size()>pos[0].size();
		vector<int> res;
		int cnt=0;
		for(int j=0;j<pos[id].size();j++){
			if(j==0){
				res.emplace_back(i);
			}else{
				res.emplace_back(--last);
				cnt++;
			}
			res.emplace_back(pos[id][j]);
			if(last==i+1)break;
		}
		int tmp=use_machine(res);
		c[i]=tmp&1^id;
		pos[c[i]].emplace_back(i);
		if(id){
			sum+=tmp>>1;
		}else{
			sum+=cnt-(tmp>>1);
		}
	}
	for(int i=0;i<last;i++)sum+=c[i]==0;
	return sum;
}

Compilation message

mushrooms.cpp: In lambda function:
mushrooms.cpp:19:13: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   19 |   c[idx]=tmp&1^id;
      |          ~~~^~
mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:30:15: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   30 |   c[front]=tmp&1^id;
      |            ~~~^~
mushrooms.cpp:37:19: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   37 |     c[front+3]=tmp&1^id;
      |                ~~~^~
mushrooms.cpp:38:22: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   38 |     c[front+4]=tmp>>1&1^id;
      |                ~~~~~~^~
mushrooms.cpp:54:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |   for(int j=0;j<pos[id].size();j++){
      |               ~^~~~~~~~~~~~~~~
mushrooms.cpp:65:11: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   65 |   c[i]=tmp&1^id;
      |        ~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 5 ms 336 KB Output is correct
8 Correct 6 ms 336 KB Output is correct
9 Correct 4 ms 392 KB Output is correct
10 Correct 5 ms 392 KB Output is correct
11 Correct 5 ms 336 KB Output is correct
12 Correct 7 ms 336 KB Output is correct
13 Correct 5 ms 392 KB Output is correct
14 Correct 5 ms 336 KB Output is correct
15 Correct 8 ms 396 KB Output is correct
16 Correct 5 ms 336 KB Output is correct
17 Correct 3 ms 352 KB Output is correct
18 Correct 5 ms 336 KB Output is correct
19 Correct 5 ms 336 KB Output is correct
20 Correct 6 ms 336 KB Output is correct
21 Correct 6 ms 336 KB Output is correct
22 Correct 5 ms 336 KB Output is correct
23 Correct 4 ms 336 KB Output is correct
24 Correct 3 ms 336 KB Output is correct
25 Correct 4 ms 336 KB Output is correct
26 Correct 5 ms 336 KB Output is correct
27 Correct 7 ms 336 KB Output is correct
28 Correct 6 ms 388 KB Output is correct
29 Correct 5 ms 336 KB Output is correct
30 Correct 6 ms 336 KB Output is correct
31 Correct 5 ms 392 KB Output is correct
32 Correct 5 ms 336 KB Output is correct
33 Correct 6 ms 336 KB Output is correct
34 Correct 5 ms 336 KB Output is correct
35 Correct 6 ms 336 KB Output is correct
36 Correct 5 ms 392 KB Output is correct
37 Correct 5 ms 336 KB Output is correct
38 Correct 5 ms 336 KB Output is correct
39 Correct 5 ms 456 KB Output is correct
40 Correct 5 ms 400 KB Output is correct
41 Correct 5 ms 336 KB Output is correct
42 Correct 5 ms 384 KB Output is correct
43 Correct 5 ms 336 KB Output is correct
44 Correct 5 ms 336 KB Output is correct
45 Correct 5 ms 336 KB Output is correct
46 Correct 5 ms 336 KB Output is correct
47 Correct 6 ms 336 KB Output is correct
48 Correct 6 ms 336 KB Output is correct
49 Correct 6 ms 336 KB Output is correct
50 Correct 5 ms 388 KB Output is correct
51 Correct 5 ms 396 KB Output is correct
52 Correct 5 ms 336 KB Output is correct
53 Correct 5 ms 388 KB Output is correct
54 Correct 6 ms 400 KB Output is correct
55 Correct 6 ms 384 KB Output is correct
56 Correct 6 ms 336 KB Output is correct
57 Correct 5 ms 396 KB Output is correct
58 Correct 6 ms 396 KB Output is correct
59 Correct 6 ms 336 KB Output is correct
60 Correct 5 ms 336 KB Output is correct
61 Correct 5 ms 336 KB Output is correct
62 Correct 0 ms 208 KB Output is correct
63 Correct 0 ms 208 KB Output is correct
64 Correct 0 ms 208 KB Output is correct
65 Correct 0 ms 208 KB Output is correct
66 Correct 0 ms 208 KB Output is correct
67 Correct 0 ms 208 KB Output is correct
68 Correct 0 ms 208 KB Output is correct
69 Correct 1 ms 208 KB Output is correct
70 Correct 0 ms 208 KB Output is correct
71 Correct 0 ms 208 KB Output is correct
72 Correct 0 ms 208 KB Output is correct
73 Correct 0 ms 208 KB Output is correct
74 Correct 0 ms 208 KB Output is correct
75 Correct 0 ms 208 KB Output is correct
76 Correct 1 ms 208 KB Output is correct
77 Correct 0 ms 208 KB Output is correct
78 Correct 0 ms 208 KB Output is correct
79 Correct 0 ms 208 KB Output is correct
80 Correct 0 ms 208 KB Output is correct
81 Correct 0 ms 208 KB Output is correct
82 Correct 0 ms 208 KB Output is correct
83 Correct 0 ms 208 KB Output is correct
84 Correct 0 ms 208 KB Output is correct
85 Correct 0 ms 208 KB Output is correct
86 Correct 0 ms 208 KB Output is correct
87 Correct 0 ms 208 KB Output is correct
88 Correct 0 ms 208 KB Output is correct
89 Correct 0 ms 208 KB Output is correct
90 Correct 0 ms 208 KB Output is correct
91 Correct 0 ms 208 KB Output is correct