답안 #760099

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
760099 2023-06-17T07:36:03 Z raysh07 버섯 세기 (IOI20_mushrooms) C++17
100 / 100
8 ms 328 KB
#include "mushrooms.h"
#include <bits/stdc++.h>
using namespace std;

// const int N = 101;
// int ac[N];

// int use_machine(vector <int> a){
//     int ans = 0;
    
//     for (int i = 1; i < a.size(); i++){
//         ans += ac[a[i]] != ac[a[i - 1]];
//     }
    
//     return ans;
// }
 
int count_mushrooms(int n) {
    vector <int> a, b;
    a.push_back(0);
    int p = 1;
    int ans = 0;
    const int C = 100;
    int moves = 0;
    
    while (p < n){
        if (p != (n - 1) && p != (n - 2) && max(a.size(), b.size()) <= C && max(a.size(), b.size()) >= 3){
            if (a.size() >= 3){
                int c = use_machine({p, a[0], p + 1, a[1], p + 2, a[2]});
                if (c & 1) b.push_back(p), c--;
                else a.push_back(p);
                
                if (c == 0) {
                    a.push_back(p + 1);
                    a.push_back(p + 2);
                    p += 3;
                } else if (c == 4){
                    b.push_back(p + 1);
                    b.push_back(p + 2);
                    p += 3;
                } else {
                    assert(c == 2);
                    if (b.size() >= 2 && p + 4 < n){
                        c = use_machine({b[0], p + 1, b[1], a[0], p + 2, a[1], p + 3, a[2], p + 4});
                        c--;
                        if (c >= 4) {
                            a.push_back(p + 1);
                            b.push_back(p + 2);
                            c -= 4;
                        } else {
                            a.push_back(p + 2);
                            b.push_back(p + 1);
                        }
                        
                        if (c & 1) b.push_back(p + 4), c--;
                        else a.push_back(p + 4);
                        
                        if (c == 2) b.push_back(p + 3);
                        else a.push_back(p + 3);
                        
                        p += 5;
                    } else {
                        c = use_machine({p + 1, a[0], p + 2, a[1]});
                        if (c & 1) b.push_back(p + 1);
                        else a.push_back(p + 1);
                        
                        if (c >= 2) b.push_back(p + 2);
                        else a.push_back(p + 2);
                        p += 3;
                    }
                }
            } 
            else {
                int c = use_machine({p, b[0], p + 1, b[1], p + 2, b[2]});
                if (c & 1) a.push_back(p), c--;
                else b.push_back(p);
                
                if (c == 0){
                    b.push_back(p + 1);
                    b.push_back(p + 2);
                    p += 3;
                } else if (c == 4){
                    a.push_back(p + 1);
                    a.push_back(p + 2);
                    p += 3;
                } else {
                    if (a.size() >= 2 && p + 4 < n){
                        c = use_machine({a[0], p + 1, a[1], b[0], p + 2, b[1], p + 3, b[2], p + 4});
                        c--;
                        
                        if (c >= 4) {
                            b.push_back(p + 1);
                            a.push_back(p + 2);
                            c -= 4;
                        } else {
                            a.push_back(p + 1);
                            b.push_back(p + 2);
                        }
                        
                        if (c & 1) a.push_back(p + 4), c--;
                        else b.push_back(p + 4);
                        
                        if (c == 2) a.push_back(p + 3);
                        else b.push_back(p + 3);
                        
                        p += 5;
                    } else {
                        c = use_machine({p + 1, b[0], p + 2, b[1]});
                        if (c & 1) a.push_back(p + 1), c--;
                        else b.push_back(p + 1);
                        
                        if (c == 2) a.push_back(p + 2);
                        else b.push_back(p + 2);
                        
                        p += 3;
                    }
                }
            }
            continue;
        }
        if (p != (n - 1) && max(a.size(), b.size()) <= C && max(a.size(), b.size()) >= 2){
            if (a.size() >= 2) {
                int c = use_machine({a[0], p, a[1], p + 1});
                moves++;
                if (c & 1) b.push_back(p + 1);
                else a.push_back(p + 1);
                if (c >= 2) b.push_back(p);
                else a.push_back(p);
            } else {
                int c = use_machine({b[0], p, b[1], p + 1});
                moves++;
                if (c & 1) a.push_back(p + 1);
                else b.push_back(p + 1);
                if (c >= 2) a.push_back(p);
                else b.push_back(p);
            }
            
            p += 2;
            continue;
        }
        // cout << "PRINTING " << p << " ";
        // for (auto x : a) cout << x << " ";
        // cout << "\n";
        if (a.size() > b.size()){
            int g = a.size();
            g = min(g, n - p);
            
            vector <int> m;
            for (int i = 0; i < g; i++){
                m.push_back(p + i);
                m.push_back(a[i]);
            }
            
            int c = use_machine(m);
            if (c & 1) b.push_back(p), c--;
            else a.push_back(p);
            moves++;
            
          //  cout << g << " " << c/2 << "\n";
            ans += g - 1 - (c/2);
            p += g;
        } else {
            int g = b.size();
            g = min(g, n - p);
            
            vector <int> m;
            for (int i = 0; i < g; i++){
                m.push_back(p + i);
                m.push_back(b[i]);
            }
            
            int c = use_machine(m);
            if (c & 1) a.push_back(p), c--;
            else b.push_back(p);
            moves++;
            
            ans += c/2;
            p += g;
        }
    }
    
    return ans + a.size();
}

// int main(){
//     int n; cin >> n;
//     for (int i = 0; i < n; i++) cin >> ac[i];
    
//     cout << count_mushrooms(n) << "\n";
//     return 0;
// }
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 2 ms 208 KB Output is correct
7 Correct 4 ms 208 KB Output is correct
8 Correct 4 ms 208 KB Output is correct
9 Correct 4 ms 208 KB Output is correct
10 Correct 6 ms 208 KB Output is correct
11 Correct 5 ms 208 KB Output is correct
12 Correct 6 ms 208 KB Output is correct
13 Correct 5 ms 208 KB Output is correct
14 Correct 3 ms 208 KB Output is correct
15 Correct 5 ms 208 KB Output is correct
16 Correct 5 ms 208 KB Output is correct
17 Correct 3 ms 208 KB Output is correct
18 Correct 6 ms 308 KB Output is correct
19 Correct 5 ms 208 KB Output is correct
20 Correct 5 ms 208 KB Output is correct
21 Correct 5 ms 320 KB Output is correct
22 Correct 5 ms 208 KB Output is correct
23 Correct 6 ms 208 KB Output is correct
24 Correct 3 ms 208 KB Output is correct
25 Correct 5 ms 208 KB Output is correct
26 Correct 7 ms 312 KB Output is correct
27 Correct 5 ms 208 KB Output is correct
28 Correct 7 ms 316 KB Output is correct
29 Correct 5 ms 320 KB Output is correct
30 Correct 8 ms 308 KB Output is correct
31 Correct 5 ms 316 KB Output is correct
32 Correct 5 ms 208 KB Output is correct
33 Correct 4 ms 320 KB Output is correct
34 Correct 5 ms 208 KB Output is correct
35 Correct 5 ms 208 KB Output is correct
36 Correct 5 ms 208 KB Output is correct
37 Correct 5 ms 328 KB Output is correct
38 Correct 5 ms 320 KB Output is correct
39 Correct 5 ms 208 KB Output is correct
40 Correct 5 ms 208 KB Output is correct
41 Correct 5 ms 208 KB Output is correct
42 Correct 5 ms 308 KB Output is correct
43 Correct 4 ms 208 KB Output is correct
44 Correct 5 ms 324 KB Output is correct
45 Correct 5 ms 208 KB Output is correct
46 Correct 5 ms 208 KB Output is correct
47 Correct 5 ms 308 KB Output is correct
48 Correct 5 ms 208 KB Output is correct
49 Correct 4 ms 208 KB Output is correct
50 Correct 7 ms 208 KB Output is correct
51 Correct 5 ms 208 KB Output is correct
52 Correct 5 ms 208 KB Output is correct
53 Correct 5 ms 208 KB Output is correct
54 Correct 5 ms 208 KB Output is correct
55 Correct 5 ms 208 KB Output is correct
56 Correct 6 ms 208 KB Output is correct
57 Correct 5 ms 208 KB Output is correct
58 Correct 5 ms 316 KB Output is correct
59 Correct 5 ms 208 KB Output is correct
60 Correct 4 ms 208 KB Output is correct
61 Correct 5 ms 320 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 0 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 1 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 0 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 1 ms 208 KB Output is correct
88 Correct 1 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