Submission #545452

# Submission time Handle Problem Language Result Execution time Memory
545452 2022-04-04T14:36:26 Z maomao90 Koala Game (APIO17_koala) C++17
66 / 100
72 ms 440 KB
// Hallelujah, praise the one who set me free
// Hallelujah, death has lost its grip on me
// You have broken every chain, There's salvation in your name
// Jesus Christ, my living hope
#include <bits/stdc++.h> 
#include "koala.h"
using namespace std;

template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
typedef long double ld;
#define MP make_pair
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define MT make_tuple
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

#ifndef DEBUG
#define cerr if (0) cerr
#endif

#define INF 1000000005
#define LINF 1000000000000000005ll
#define MAXN 200005

int minValue(int n, int w) {
    int b[n], r[n];
    REP (i, 0, n) {
        b[i] = 0;
    }
    b[0] = 1;
    playRound(b, r);
    REP (i, 0, n) {
        if (r[i] == 0) {
            return i;
        }
    }
    assert(0);
}

int maxValue(int n, int w) {
    int b[n], r[n];
    REP (i, 0, n) {
        b[i] = 1;
    }
    playRound(b, r);
    vi big;
    REP (i, 0, n) {
        if (r[i] > 1) {
            big.pb(i);
        }
    }
    while (big.size() > 1) {
        int x = w / big.size();
        REP (i, 0, n) {
            b[i] = 0;
        }
        for (int i : big) {
            b[i] = x;
        }
        playRound(b, r);
        big.clear();
        REP (i, 0, n) {
            if (r[i] > 1) {
                big.pb(i);
            }
        }
    }
    assert(big.size() == 1);
    return big[0];
}

int greaterValue(int n, int w) {
    int lo = 1, hi = min(w / 2, 8), mid;
    while (lo <= hi) {
        mid = lo + hi >> 1;
        int b[n], r[n];
        REP (i, 0, n) {
            b[i] = 0;
        }
        b[0] = b[1] = mid;
        playRound(b, r);
        bool is0 = r[0] > mid, is1 = r[1] > mid;
        if (is0 != is1) {
            if (is0) {
                return 0;
            } else {
                return 1;
            }
        }
        if (is0) {
            lo = mid + 1;
        } else {
            hi = mid - 1;
        }
    }
    assert(0);
    return 0;
}

template <class T>
void stable_sort(int *arr, int l, int r, T &&f) {
    int n = r - l;
    if (n <= 1) return;
    int m = l + r >> 1;
    stable_sort(arr, l, m, f);
    stable_sort(arr, m, r, f);
    int res[n];
    int a = 0, b = 0;
    while (a + b < n) {
        if (a == m) {
            res[a + b] = arr[m + b++];
        } else if (b == n - m) {
            res[a + b] = arr[l + a++];
        } else if (f(arr[l + a], arr[m + b])) {
            res[a + b] = arr[l + a++];
        } else {
            res[a + b] = arr[m + b++];
        }
    }
    REP (i, 0, n) {
        arr[l + i] = res[i];
    }
}

void allValues(int n, int w, int *p) {
    if (w == 2 * n) {
        int id[n];
        iota(id, id + n, 0);
        stable_sort(id, id + n, [&] (int l, int r) {
                int b[n], c[n];
                REP (i, 0, n) {
                    b[i] = 0;
                }
                b[l] = b[r] = n;
                playRound(b, c);
                return c[l] <= n;
                });
        REP (i, 0, n) {
            p[id[i]] = i + 1;
        }
    } else {
        int id[n];
        iota(id, id + n, 0);
        stable_sort(id, id + n, [&] (int s, int e) {
                int lo = 1, hi = min(w / 2, 8), mid;
                while (lo <= hi) {
                    mid = lo + hi >> 1;
                    int b[n], r[n];
                    REP (i, 0, n) {
                        b[i] = 0;
                    }
                    b[s] = b[e] = mid;
                    playRound(b, r);
                    bool is0 = r[s] > mid, is1 = r[e] > mid;
                    if (is0 != is1) {
                        if (is0) {
                            return 0;
                        } else {
                            return 1;
                        }
                    }
                    if (is0) {
                        lo = mid + 1;
                    } else {
                        hi = mid - 1;
                    }
                }
                assert(0);
                return 0;
        });
        REP (i, 0, n) {
            p[id[i]] = i + 1;
        }
    }
}

Compilation message

koala.cpp: In function 'int greaterValue(int, int)':
koala.cpp:88:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   88 |         mid = lo + hi >> 1;
      |               ~~~^~~~
koala.cpp: In lambda function:
koala.cpp:160:30: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  160 |                     mid = lo + hi >> 1;
      |                           ~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 208 KB Output is correct
2 Correct 3 ms 208 KB Output is correct
3 Correct 4 ms 208 KB Output is correct
4 Correct 4 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 312 KB Output is correct
2 Correct 12 ms 208 KB Output is correct
3 Correct 12 ms 320 KB Output is correct
4 Correct 12 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 62 ms 332 KB Output is partially correct
2 Partially correct 72 ms 328 KB Output is partially correct
3 Partially correct 59 ms 324 KB Output is partially correct
4 Partially correct 65 ms 328 KB Output is partially correct
5 Partially correct 58 ms 316 KB Output is partially correct
6 Partially correct 61 ms 316 KB Output is partially correct
7 Partially correct 63 ms 328 KB Output is partially correct
8 Partially correct 64 ms 440 KB Output is partially correct
9 Partially correct 59 ms 328 KB Output is partially correct
10 Partially correct 61 ms 320 KB Output is partially correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 208 KB Output is correct
2 Correct 34 ms 208 KB Output is correct
3 Correct 32 ms 296 KB Output is correct
4 Correct 33 ms 304 KB Output is correct
5 Correct 31 ms 312 KB Output is correct
6 Correct 31 ms 208 KB Output is correct
7 Correct 35 ms 292 KB Output is correct
8 Correct 41 ms 292 KB Output is correct
9 Correct 32 ms 216 KB Output is correct
10 Correct 30 ms 208 KB Output is correct
11 Correct 33 ms 208 KB Output is correct
12 Correct 13 ms 208 KB Output is correct
13 Correct 32 ms 208 KB Output is correct
14 Correct 34 ms 208 KB Output is correct
15 Correct 30 ms 312 KB Output is correct
16 Correct 31 ms 208 KB Output is correct
17 Correct 30 ms 208 KB Output is correct
18 Correct 31 ms 208 KB Output is correct
19 Correct 31 ms 208 KB Output is correct
20 Correct 31 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 23 ms 304 KB Output is partially correct
2 Partially correct 37 ms 288 KB Output is partially correct
3 Partially correct 31 ms 208 KB Output is partially correct
4 Partially correct 30 ms 208 KB Output is partially correct
5 Partially correct 34 ms 208 KB Output is partially correct
6 Partially correct 32 ms 208 KB Output is partially correct
7 Partially correct 32 ms 208 KB Output is partially correct
8 Partially correct 32 ms 296 KB Output is partially correct
9 Partially correct 33 ms 208 KB Output is partially correct
10 Partially correct 31 ms 208 KB Output is partially correct
11 Partially correct 31 ms 208 KB Output is partially correct
12 Partially correct 13 ms 208 KB Output is partially correct
13 Partially correct 29 ms 208 KB Output is partially correct
14 Partially correct 30 ms 312 KB Output is partially correct
15 Partially correct 30 ms 316 KB Output is partially correct
16 Partially correct 34 ms 208 KB Output is partially correct
17 Partially correct 34 ms 292 KB Output is partially correct
18 Partially correct 35 ms 308 KB Output is partially correct
19 Partially correct 31 ms 208 KB Output is partially correct
20 Partially correct 30 ms 208 KB Output is partially correct
21 Partially correct 29 ms 208 KB Output is partially correct
22 Partially correct 33 ms 292 KB Output is partially correct
23 Partially correct 30 ms 208 KB Output is partially correct
24 Partially correct 32 ms 296 KB Output is partially correct
25 Partially correct 37 ms 296 KB Output is partially correct
26 Partially correct 33 ms 208 KB Output is partially correct
27 Partially correct 32 ms 304 KB Output is partially correct
28 Partially correct 31 ms 208 KB Output is partially correct
29 Partially correct 30 ms 312 KB Output is partially correct
30 Partially correct 30 ms 308 KB Output is partially correct
31 Partially correct 32 ms 296 KB Output is partially correct
32 Partially correct 32 ms 208 KB Output is partially correct
33 Partially correct 34 ms 208 KB Output is partially correct
34 Partially correct 27 ms 208 KB Output is partially correct
35 Partially correct 34 ms 208 KB Output is partially correct
36 Partially correct 36 ms 208 KB Output is partially correct
37 Partially correct 30 ms 208 KB Output is partially correct
38 Partially correct 29 ms 208 KB Output is partially correct
39 Partially correct 29 ms 296 KB Output is partially correct
40 Partially correct 29 ms 208 KB Output is partially correct