답안 #1058972

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1058972 2024-08-14T15:28:45 Z RecursiveCo 버섯 세기 (IOI20_mushrooms) C++17
80.1418 / 100
5 ms 600 KB
// CF template, version 3.0

#include <bits/stdc++.h>
#include "mushrooms.h"

using namespace std;

#define improvePerformance ios_base::sync_with_stdio(false); cin.tie(0)
#define getTest int t; cin >> t
#define eachTest for (int _var=0;_var<t;_var++)
#define get(name) int (name); cin >> (name)
#define out(o) cout << (o)
#define getList(cnt, name) vector<int> (name); for (int _=0;_<(cnt);_++) { get(a); (name).push_back(a); }
#define sortl(name) sort((name).begin(), (name).end())
#define rev(name) reverse((name).begin(), (name).end())
#define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
#define decision(b) if (b){out("YES");}else{out("NO");}

//#define int long long int

template <typename T, typename I>
struct segtree {
    int n;
    vector<T> tree;
    vector<I> initial;
    T id;

    segtree(int i_n, vector<I> i_initial, T i_id): n(i_n), initial(i_initial), id(i_id) {
        tree.resize(4 * n);
    }

    T conquer(T left, T right) {
        // write your conquer function
    }

    T value(I inp) {
        // write your value function
    }

    void build(int v, int l, int r) {
        if (l == r) tree[v] = value(initial[l]);
        else {
            int middle = (l + r) / 2;
            build(2 * v, l, middle);
            build(2 * v + 1, middle + 1, r);
            tree[v] = conquer(tree[2 * v], tree[2 * v + 1]);
        }
    }

    void upd(int v, int l, int r, int i, I x) {
        if (l == r) tree[v] = value(x);
        else {
            int middle = (l + r) / 2;
            if (middle >= i) upd(2 * v, l, middle, i, x);
            else upd(2 * v + 1, middle + 1, r, i, x);
            tree[v] = conquer(tree[2 * v], tree[2 * v + 1]);
        }
    }

    T query(int v, int l, int r, int ql, int qr) {
        if (ql <= l && r <= qr) return tree[v];
        else if (r < ql || qr < l) return id;
        int middle = (l + r) / 2;
        T left = query(2 * v, l, middle, ql, qr);
        T right = query(2 * v + 1, middle + 1, r, ql, qr);
        return conquer(left, right);
    }
};

// vector<int>

int count_mushrooms(int n) {
    int a = 1;
    int b = 0;
    vector<int> A;
    vector<int> B;
    A.push_back(0);
    if (n == 2) {
        vector<int> X;
        X.push_back(0);
        X.push_back(1);
        int pairs = use_machine(X);
        if (pairs == 0) a++;
        return a;
    }
    vector<int> X;
    X.push_back(0);
    X.push_back(1);
    int pairs = use_machine(X);
    if (pairs == 0) a++, A.push_back(1);
    else b++, B.push_back(1);
    X.pop_back();
    X.push_back(2);
    pairs = use_machine(X);
    if (pairs == 0) a++, A.push_back(2);
    else b++, B.push_back(2);
    n -= 2;
    forto(min((n - 1) / 2, 140), i) {
        vector<int> X;
        bool flag = false;
        if (A.size() < 2) {
            flag = true;
            swap(A, B);
            swap(a, b);
        }
        X.push_back(A[0]);
        X.push_back(2 * i + 3);
        X.push_back(A[1]);
        X.push_back(2 * i + 4);
        int pairs = use_machine(X);
        switch (pairs) {
            case 0:
                a += 2;
                A.push_back(2 * i + 3);
                A.push_back(2 * i + 4);
                break;
            case 1:
                a++;
                A.push_back(2 * i + 3);
                b++;
                B.push_back(2 * i + 4);
                break;
            case 2:
                a++;
                A.push_back(2 * i + 4);
                b++;
                B.push_back(2 * i + 3);
                break;
            case 3:
                b += 2;
                B.push_back(2 * i + 3);
                B.push_back(2 * i + 4);
                break;
        }
        if (flag) {
            swap(A, B);
            swap(a, b);
        }
    }
    if (n > 281) {
        n -= 281;
        int ind = 283;
        while (n) {
            int num = min(n, 141);
            vector<int> X;
            if (A.size() >= 142) {
                forto(num, i) X.push_back(A[i]), X.push_back(ind + i);
                X.push_back(A[num]);
                int pairs = use_machine(X);
                a += num - pairs / 2;
            } else {
                forto(num, i) X.push_back(B[i]), X.push_back(ind + i);
                X.push_back(B[num]);
                int pairs = use_machine(X);
                a += pairs / 2;
            }
            n -= num;
            ind += num;
        }
    } else if (n % 2 == 0) {
        vector<int> X;
        X.push_back(0);
        X.push_back(n + 1);
        int pairs = use_machine(X);
        if (pairs == 0) a++;
    }
    return a;
}

Compilation message

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:16:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   16 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
mushrooms.cpp:98:5: note: in expansion of macro 'forto'
   98 |     forto(min((n - 1) / 2, 140), i) {
      |     ^~~~~
mushrooms.cpp:16:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   16 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
mushrooms.cpp:147:17: note: in expansion of macro 'forto'
  147 |                 forto(num, i) X.push_back(A[i]), X.push_back(ind + i);
      |                 ^~~~~
mushrooms.cpp:16:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   16 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
mushrooms.cpp:152:17: note: in expansion of macro 'forto'
  152 |                 forto(num, i) X.push_back(B[i]), X.push_back(ind + i);
      |                 ^~~~~
# 결과 실행 시간 메모리 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 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Partially correct 3 ms 344 KB Output is partially correct
8 Partially correct 3 ms 344 KB Output is partially correct
9 Partially correct 4 ms 344 KB Output is partially correct
10 Partially correct 4 ms 344 KB Output is partially correct
11 Partially correct 3 ms 344 KB Output is partially correct
12 Partially correct 3 ms 344 KB Output is partially correct
13 Partially correct 3 ms 344 KB Output is partially correct
14 Correct 2 ms 344 KB Output is correct
15 Partially correct 3 ms 344 KB Output is partially correct
16 Partially correct 4 ms 344 KB Output is partially correct
17 Correct 2 ms 344 KB Output is correct
18 Partially correct 3 ms 344 KB Output is partially correct
19 Partially correct 3 ms 344 KB Output is partially correct
20 Partially correct 4 ms 344 KB Output is partially correct
21 Partially correct 3 ms 444 KB Output is partially correct
22 Partially correct 3 ms 344 KB Output is partially correct
23 Partially correct 3 ms 344 KB Output is partially correct
24 Correct 2 ms 344 KB Output is correct
25 Partially correct 3 ms 344 KB Output is partially correct
26 Partially correct 3 ms 344 KB Output is partially correct
27 Partially correct 3 ms 344 KB Output is partially correct
28 Partially correct 3 ms 344 KB Output is partially correct
29 Partially correct 3 ms 344 KB Output is partially correct
30 Partially correct 3 ms 600 KB Output is partially correct
31 Partially correct 3 ms 344 KB Output is partially correct
32 Partially correct 5 ms 344 KB Output is partially correct
33 Partially correct 3 ms 344 KB Output is partially correct
34 Partially correct 3 ms 344 KB Output is partially correct
35 Partially correct 3 ms 344 KB Output is partially correct
36 Partially correct 4 ms 344 KB Output is partially correct
37 Partially correct 4 ms 344 KB Output is partially correct
38 Partially correct 3 ms 344 KB Output is partially correct
39 Partially correct 4 ms 344 KB Output is partially correct
40 Partially correct 3 ms 344 KB Output is partially correct
41 Partially correct 5 ms 452 KB Output is partially correct
42 Partially correct 4 ms 344 KB Output is partially correct
43 Partially correct 4 ms 344 KB Output is partially correct
44 Partially correct 3 ms 344 KB Output is partially correct
45 Partially correct 3 ms 344 KB Output is partially correct
46 Partially correct 3 ms 344 KB Output is partially correct
47 Partially correct 3 ms 344 KB Output is partially correct
48 Partially correct 5 ms 344 KB Output is partially correct
49 Partially correct 5 ms 344 KB Output is partially correct
50 Partially correct 3 ms 344 KB Output is partially correct
51 Partially correct 3 ms 344 KB Output is partially correct
52 Partially correct 3 ms 344 KB Output is partially correct
53 Partially correct 3 ms 344 KB Output is partially correct
54 Partially correct 3 ms 344 KB Output is partially correct
55 Partially correct 3 ms 344 KB Output is partially correct
56 Partially correct 4 ms 344 KB Output is partially correct
57 Partially correct 3 ms 344 KB Output is partially correct
58 Partially correct 3 ms 344 KB Output is partially correct
59 Partially correct 3 ms 344 KB Output is partially correct
60 Partially correct 5 ms 344 KB Output is partially correct
61 Partially correct 3 ms 344 KB Output is partially correct
62 Correct 0 ms 344 KB Output is correct
63 Correct 0 ms 344 KB Output is correct
64 Correct 0 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 0 ms 344 KB Output is correct
68 Correct 0 ms 344 KB Output is correct
69 Correct 0 ms 416 KB Output is correct
70 Correct 0 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 368 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 1 ms 344 KB Output is correct
80 Correct 0 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