답안 #310118

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
310118 2020-10-05T20:17:22 Z peti1234 버섯 세기 (IOI20_mushrooms) C++17
100 / 100
9 ms 512 KB
#include <bits/stdc++.h>
#include "mushrooms.h"
using namespace std;
vector<int> a, b, sz, s;
int sa, sb, pos, ert, x, adb;
bool v[20002];
void pb(int x) {
    sz.push_back(x);
}
void ap(int x) {
    a.push_back(x);
}
void bp(int x) {
    b.push_back(x);
}
void cl() {
    sz.clear();
}
void add(int a) {
    if (x%2) bp(a);
    else ap(a);
}
void fadd(int a) {
    if (x%2) ap(a);
    else bp(a);
}
int kerd() {
    return use_machine(sz);
}
void ek(int a) {
    pb(0), pb(a);
    x=kerd();
    add(a),
    cl();
}
int count_mushrooms(int n) {
    ap(0), ert=sqrt(n);
    ert=110;
    if (n<220) {
        for (int i=1; i<n; i++) ek(i);
        return a.size();
    }

    for (int i=1; i<=2; i++) ek(i);
    sa=a.size();
    if (sa>1) {
        pb(a[0]), pb(3), pb(a[1]), pb(4);
        x=kerd();
        add(4), x/=2;
        add(3);
    } else {
        pb(b[0]), pb(3), pb(b[1]), pb(4);
        x=kerd();
        fadd(4), x/=2;
        fadd(3);
    }
    pos=5;
    sa=a.size(), sb=b.size();
    while(max(sa, sb)<ert) {
        cl();
        if (sa>2) {
            pb(a[0]), pb(pos), pb(a[1]), pb(pos+1), pb(a[2]), pb(pos+2);
            x=kerd();
            add(pos+2);
            if (x<2) ap(pos), ap(pos+1), pos+=3;
            else if (x>=4) bp(pos), bp(pos+1), pos+=3;
            else {
                if (sb>1) {
                    cl();
                    pb(b[0]), pb(pos), pb(b[1]), pb(a[0]), pb(pos+1), pb(a[1]), pb(pos+3), pb(a[2]), pb(pos+4);
                    x=kerd()-1;
                    add(pos+4);
                    x/=2;
                    add(pos+3);
                    x/=2;
                    add(pos+1), fadd(pos);
                    pos+=5;
                } else {
                    cl();
                    pb(a[0]), pb(pos), pb(a[1]), pb(pos+3);
                    x=kerd();
                    add(pos+3), x/=2;
                    add(pos), fadd(pos+1);
                    pos+=4;
                }
            }
        } else {
            pb(b[0]), pb(pos), pb(b[1]), pb(pos+1), pb(b[2]), pb(pos+2);
            x=kerd();
            fadd(pos+2);
            if (x<2) bp(pos), bp(pos+1), pos+=3;
            else if (x>=4) ap(pos), ap(pos+1), pos+=3;
            else {
                if (sa>1) {
                    cl();
                    pb(a[0]), pb(pos), pb(a[1]), pb(b[0]), pb(pos+1), pb(b[1]), pb(pos+3), pb(b[2]), pb(pos+4);
                    x=kerd()-1;
                    fadd(pos+4);
                    x/=2;
                    fadd(pos+3);
                    x/=2;
                    fadd(pos+1), add(pos);
                    pos+=5;
                } else {
                    cl();
                    pb(b[0]), pb(pos), pb(b[1]), pb(pos+3);
                    x=kerd();
                    fadd(pos+3), x/=2;
                    fadd(pos), add(pos+1);
                    pos+=4;
                }
            }
        }
        sa=a.size(), sb=b.size();
    }
    while(pos<n) {
        cl();
        if (sa>=sb) {
            for (int i=0; i<sa && pos+i<n; i++) {
                pb(a[i]), pb(pos+i);
            }
            x=kerd();
            int y=sz.back();
            add(y);
            pos=1+y;
            int si=sz.size();
            adb+=((si-2)/2-x/2);

        } else {
            for (int i=0; i<sb && pos+i<n; i++) {
                pb(b[i]), pb(pos+i);
            }
            x=kerd();
            int y=sz.back();
            fadd(y);
            pos=1+y;
            adb+=(x/2);
        }
        sa=a.size(), sb=b.size();
    }
    return sa+adb;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 3 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 6 ms 256 KB Output is correct
8 Correct 6 ms 256 KB Output is correct
9 Correct 7 ms 256 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
12 Correct 6 ms 384 KB Output is correct
13 Correct 6 ms 508 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 7 ms 384 KB Output is correct
16 Correct 7 ms 384 KB Output is correct
17 Correct 4 ms 256 KB Output is correct
18 Correct 8 ms 384 KB Output is correct
19 Correct 9 ms 256 KB Output is correct
20 Correct 6 ms 384 KB Output is correct
21 Correct 7 ms 384 KB Output is correct
22 Correct 9 ms 384 KB Output is correct
23 Correct 8 ms 384 KB Output is correct
24 Correct 4 ms 384 KB Output is correct
25 Correct 9 ms 256 KB Output is correct
26 Correct 7 ms 384 KB Output is correct
27 Correct 6 ms 384 KB Output is correct
28 Correct 6 ms 384 KB Output is correct
29 Correct 7 ms 384 KB Output is correct
30 Correct 8 ms 384 KB Output is correct
31 Correct 6 ms 412 KB Output is correct
32 Correct 6 ms 384 KB Output is correct
33 Correct 7 ms 384 KB Output is correct
34 Correct 9 ms 384 KB Output is correct
35 Correct 9 ms 384 KB Output is correct
36 Correct 7 ms 384 KB Output is correct
37 Correct 7 ms 256 KB Output is correct
38 Correct 7 ms 256 KB Output is correct
39 Correct 7 ms 384 KB Output is correct
40 Correct 6 ms 380 KB Output is correct
41 Correct 6 ms 508 KB Output is correct
42 Correct 7 ms 384 KB Output is correct
43 Correct 7 ms 384 KB Output is correct
44 Correct 7 ms 384 KB Output is correct
45 Correct 7 ms 384 KB Output is correct
46 Correct 9 ms 380 KB Output is correct
47 Correct 9 ms 384 KB Output is correct
48 Correct 8 ms 512 KB Output is correct
49 Correct 7 ms 384 KB Output is correct
50 Correct 7 ms 384 KB Output is correct
51 Correct 7 ms 384 KB Output is correct
52 Correct 7 ms 384 KB Output is correct
53 Correct 7 ms 256 KB Output is correct
54 Correct 8 ms 384 KB Output is correct
55 Correct 7 ms 256 KB Output is correct
56 Correct 7 ms 384 KB Output is correct
57 Correct 7 ms 384 KB Output is correct
58 Correct 9 ms 384 KB Output is correct
59 Correct 7 ms 384 KB Output is correct
60 Correct 8 ms 256 KB Output is correct
61 Correct 7 ms 384 KB Output is correct
62 Correct 0 ms 256 KB Output is correct
63 Correct 0 ms 256 KB Output is correct
64 Correct 0 ms 256 KB Output is correct
65 Correct 0 ms 256 KB Output is correct
66 Correct 1 ms 256 KB Output is correct
67 Correct 0 ms 256 KB Output is correct
68 Correct 1 ms 256 KB Output is correct
69 Correct 0 ms 256 KB Output is correct
70 Correct 1 ms 256 KB Output is correct
71 Correct 0 ms 256 KB Output is correct
72 Correct 1 ms 256 KB Output is correct
73 Correct 0 ms 256 KB Output is correct
74 Correct 0 ms 256 KB Output is correct
75 Correct 0 ms 256 KB Output is correct
76 Correct 1 ms 256 KB Output is correct
77 Correct 0 ms 256 KB Output is correct
78 Correct 0 ms 256 KB Output is correct
79 Correct 0 ms 256 KB Output is correct
80 Correct 0 ms 256 KB Output is correct
81 Correct 1 ms 256 KB Output is correct
82 Correct 0 ms 256 KB Output is correct
83 Correct 1 ms 256 KB Output is correct
84 Correct 1 ms 256 KB Output is correct
85 Correct 0 ms 256 KB Output is correct
86 Correct 0 ms 256 KB Output is correct
87 Correct 0 ms 256 KB Output is correct
88 Correct 1 ms 256 KB Output is correct
89 Correct 1 ms 256 KB Output is correct
90 Correct 1 ms 256 KB Output is correct
91 Correct 1 ms 256 KB Output is correct