Submission #353056

# Submission time Handle Problem Language Result Execution time Memory
353056 2021-01-21T05:23:32 Z talant117408 Counting Mushrooms (IOI20_mushrooms) C++17
80.7143 / 100
15 ms 544 KB
#include "mushrooms.h"
#ifndef EVAL
#include "stub.cpp"
#endif
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

#define precision(n) fixed << setprecision(n)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define eps (double)1e-9
#define PI 2*acos(0.0)
#define endl "\n"
#define sz(v) int((v).size())
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define OK cout << "OK" << endl;

inline bool isvowel(char ch){
    ch = tolower(ch);
    return (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u');
}

inline bool isprime(int n){
    if(n < 2 || (n%2 == 0 && n != 2)) return false;
    for(int i = 3; i*i <= n; i++)
        if(n%i == 0) return false;
    return true;
}

class Union{
    private:
        vector <int> saizu, link;
    public:
        Union(int n){
            saizu.assign(n, 1); link.resize(n);
            iota(all(link), 0);
        }
        int find(int n){
            if(link[n] == n) return n;
            return link[n] = find(link[n]);
        }
        int same(int a, int b){
            return find(a) == find(b);
        }
        void unite(int a, int b){
            if(same(a, b)) return;

            a = find(a); b = find(b);
            if(saizu[a] < saizu[b]) swap(a, b);

            saizu[a] += saizu[b];
            link[b] = a;
        }
        int getsize(int a){
            return saizu[find(a)];
        }
};

const int mod = 1e9+7;

ll mode(ll a){
    a %= mod;
    if(a < 0) a += mod;
    return a;
}

ll subt(ll a, ll b){
    return mode(mode(a)-mode(b));
}

ll add(ll a, ll b){
    return mode(mode(a)+mode(b));
}

ll mult(ll a, ll b){
    return mode(mode(a)*mode(b));
}

ll binpow(ll a, ll b){
    ll res = 1;
    while(b){
        if(b&1) res = mult(res, a);
        a = mult(a, a);
        b >>= 1;
    }
    return res;
}

int ans = 1;
vector <int> a, b;

int count_mushrooms(int n) {
	a.pb(0);
    int j = 1;
    
    while(j < n){
        if(sz(a) >= sz(b)){
            vector <int> tmp;
            int cnt = -1;
            for(int i = j; i < min(j+sz(a), n); i++){
                tmp.pb(a[i-j]); tmp.pb(i);
                cnt++;
            }
            j = min(j+sz(a), n);
            auto res = use_machine(tmp);
            if(res&1){
                b.pb(tmp.back());
                res--;
            }
            else{
                a.pb(tmp.back());
                ans++;
            }
            ans += cnt-res/2;
        }
        else{
            vector <int> tmp;
            int cnt = -1;
            for(int i = j; i < min(j+sz(b), n); i++){
                tmp.pb(b[i-j]); tmp.pb(i);
                cnt++;
            }
            j = min(j+sz(b), n);
            auto res = use_machine(tmp);
            if(res&1){
                a.pb(tmp.back());
                ans++;
                res--;
            }
            else{
                b.pb(tmp.back());
            }
            ans += res/2;
        }
    }
    
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 7 ms 364 KB Output is correct
8 Correct 7 ms 364 KB Output is correct
9 Correct 7 ms 364 KB Output is correct
10 Partially correct 7 ms 364 KB Output is partially correct
11 Partially correct 9 ms 364 KB Output is partially correct
12 Partially correct 8 ms 364 KB Output is partially correct
13 Correct 8 ms 364 KB Output is correct
14 Correct 5 ms 500 KB Output is correct
15 Partially correct 9 ms 364 KB Output is partially correct
16 Partially correct 9 ms 364 KB Output is partially correct
17 Correct 6 ms 384 KB Output is correct
18 Correct 9 ms 492 KB Output is correct
19 Partially correct 8 ms 364 KB Output is partially correct
20 Partially correct 7 ms 364 KB Output is partially correct
21 Partially correct 8 ms 364 KB Output is partially correct
22 Partially correct 8 ms 364 KB Output is partially correct
23 Correct 7 ms 364 KB Output is correct
24 Correct 5 ms 364 KB Output is correct
25 Partially correct 12 ms 364 KB Output is partially correct
26 Partially correct 9 ms 364 KB Output is partially correct
27 Partially correct 8 ms 364 KB Output is partially correct
28 Partially correct 7 ms 532 KB Output is partially correct
29 Partially correct 10 ms 364 KB Output is partially correct
30 Partially correct 8 ms 364 KB Output is partially correct
31 Partially correct 11 ms 420 KB Output is partially correct
32 Partially correct 6 ms 448 KB Output is partially correct
33 Partially correct 9 ms 420 KB Output is partially correct
34 Partially correct 8 ms 364 KB Output is partially correct
35 Partially correct 11 ms 544 KB Output is partially correct
36 Partially correct 11 ms 392 KB Output is partially correct
37 Partially correct 8 ms 364 KB Output is partially correct
38 Partially correct 9 ms 396 KB Output is partially correct
39 Partially correct 13 ms 364 KB Output is partially correct
40 Partially correct 9 ms 364 KB Output is partially correct
41 Partially correct 15 ms 492 KB Output is partially correct
42 Partially correct 8 ms 396 KB Output is partially correct
43 Partially correct 11 ms 364 KB Output is partially correct
44 Partially correct 13 ms 364 KB Output is partially correct
45 Partially correct 11 ms 364 KB Output is partially correct
46 Partially correct 7 ms 364 KB Output is partially correct
47 Partially correct 9 ms 364 KB Output is partially correct
48 Partially correct 8 ms 364 KB Output is partially correct
49 Partially correct 10 ms 364 KB Output is partially correct
50 Partially correct 10 ms 364 KB Output is partially correct
51 Partially correct 8 ms 364 KB Output is partially correct
52 Partially correct 8 ms 364 KB Output is partially correct
53 Partially correct 9 ms 364 KB Output is partially correct
54 Partially correct 11 ms 364 KB Output is partially correct
55 Partially correct 8 ms 364 KB Output is partially correct
56 Partially correct 10 ms 364 KB Output is partially correct
57 Partially correct 9 ms 364 KB Output is partially correct
58 Partially correct 10 ms 492 KB Output is partially correct
59 Partially correct 9 ms 364 KB Output is partially correct
60 Partially correct 13 ms 364 KB Output is partially correct
61 Partially correct 13 ms 364 KB Output is partially correct
62 Correct 1 ms 364 KB Output is correct
63 Correct 1 ms 364 KB Output is correct
64 Correct 1 ms 364 KB Output is correct
65 Correct 1 ms 364 KB Output is correct
66 Correct 1 ms 512 KB Output is correct
67 Correct 1 ms 364 KB Output is correct
68 Correct 1 ms 364 KB Output is correct
69 Correct 1 ms 364 KB Output is correct
70 Correct 0 ms 364 KB Output is correct
71 Correct 1 ms 364 KB Output is correct
72 Correct 1 ms 364 KB Output is correct
73 Correct 1 ms 364 KB Output is correct
74 Correct 0 ms 364 KB Output is correct
75 Correct 1 ms 364 KB Output is correct
76 Correct 1 ms 364 KB Output is correct
77 Correct 1 ms 364 KB Output is correct
78 Correct 1 ms 364 KB Output is correct
79 Correct 1 ms 364 KB Output is correct
80 Correct 1 ms 364 KB Output is correct
81 Correct 1 ms 364 KB Output is correct
82 Correct 1 ms 364 KB Output is correct
83 Correct 1 ms 364 KB Output is correct
84 Correct 0 ms 364 KB Output is correct
85 Correct 1 ms 364 KB Output is correct
86 Correct 1 ms 364 KB Output is correct
87 Correct 1 ms 364 KB Output is correct
88 Correct 1 ms 364 KB Output is correct
89 Correct 1 ms 384 KB Output is correct
90 Correct 0 ms 364 KB Output is correct
91 Correct 1 ms 364 KB Output is correct