Submission #888405

# Submission time Handle Problem Language Result Execution time Memory
888405 2023-12-17T09:53:32 Z hamidh100 Koala Game (APIO17_koala) C++17
47 / 100
47 ms 968 KB
#include "koala.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
#define PB push_back
#define MP make_pair
#define all(a) (a).begin(), (a).end()
#define endl '\n'
#define dbg(x) cerr << '[' << #x << ": " << x << "]\n"
#define dbg2(x, y) cerr << '[' << #x << ": " << x << ", " << #y << ": " << y << "]\n"
#define YES cout << "YES\n"
#define NO cout << "NO\n"

const ll INF = (ll)2e18 + 1386;
const ld EPS = 0.000000000000001;
const int MOD = 1e9 + 7;

inline int _add(int a, int b){ int res = a + b; return (res >= MOD ? res - MOD : res); }
inline int _neg(int a, int b){ int res = (abs(a - b) < MOD ? a - b : (a - b) % MOD); return (res < 0 ? res + MOD : res); }
inline int _mlt(ll a, ll b){ return (a * b % MOD); }
inline void fileIO(string i, string o){ freopen(i.c_str(), "r", stdin); freopen(o.c_str(), "w", stdout); }

const int MAXN = 103;

int n, w, a[MAXN], b[MAXN];

int minValue(int N, int W) {
    n = N, w = W;
    fill(a, a + n, 0);
    a[0] = 1;
    playRound(a, b);
    if (b[0] == 1) return 0;
    for (int i = 0; i < n; i++){
        if (b[i] == 0) return i;
    }
    return -1;
}

int maxValue(int N, int W) {
    n = N, w = W;
    VI cand, nxt;
    bitset<MAXN> incand;
    incand.reset();
    fill(a, a + n, 1);
    playRound(a, b);
    for (int i = 0; i < n; i++){
        if (b[i] > a[i]){
            cand.PB(i);
            incand[i] = 1;
        }
    }

    fill(a, a + n, 0);
    for (int i : cand) a[i] = 2;
    playRound(a, b);
    for (int i : cand){
        if (b[i] > a[i]) nxt.PB(i);
        else incand[i] = 0;
    }
    cand = nxt; nxt.clear();

    fill(a, a + n, 0);
    for (int i : cand) a[i] = 4;
    playRound(a, b);
    for (int i : cand){
        if (b[i] > a[i]) nxt.PB(i);
        else incand[i] = 0;
    }
    cand = nxt; nxt.clear();

    fill(a, a + n, 0);
    for (int i : cand) a[i] = 11;
    playRound(a, b);
    for (int i : cand){
        if (b[i] > a[i]) nxt.PB(i);
        else incand[i] = 0;
    }
    cand = nxt; nxt.clear();
    return cand[0];
}

int greaterValue(int N, int W) {
    int l = 1, r = 9;
	while (l != r) {
		int mid = l + r >> 1;
		a[0] = a[1] = mid;
		playRound(a, b);
		if (b[0] > mid && b[1] > mid) l = mid + 1;
		else if (b[0] <= mid && b[1] <= mid) r = mid - 1;
		else return (b[0] < b[1]);
	}
	a[0] = a[1] = l;
	playRound(a, b);
	return (b[0] < b[1]);
}

bool cmp(int i, int j){
    i--, j--;
    fill(a, a + n, 0);
    a[i] = a[j] = 100;
    playRound(a, b);
    return b[j] > a[j];
}

int tmp[101];

void mergesort(int l, int r, int *arr){
    if (l + 1 >= r) return;
    int mid = l + r >> 1;
    mergesort(l, mid, arr);
    mergesort(mid, r, arr);
    for (int i = l; i < r; i++) tmp[i] = arr[i];
    int p1 = l, p2 = mid, pc = l;
    while (p1 < mid && p2 < r){
        if (cmp(tmp[p1], tmp[p2])){
            arr[pc++] = tmp[p1++];
        } else {
            arr[pc++] = tmp[p2++];
        }
    }
    while (p1 < mid) arr[pc++] = tmp[p1++];
    while (p2 < r) arr[pc++] = tmp[p2++];
}

void allValues(int N, int W, int *P) {
    n = N, w = W;
    if (w == 2*n) {
        int arr[101];
        iota(arr, arr + n + 1, 0);
        mergesort(1, n + 1, arr);
        for (int i = 1; i <= n; i++) P[arr[i] - 1] = i;
    } else {
        // TODO: Implement Subtask 5 solution here.
        // You may leave this block unmodified if you are not attempting this
        // subtask.
    }
}

Compilation message

koala.cpp: In function 'int greaterValue(int, int)':
koala.cpp:92:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   92 |   int mid = l + r >> 1;
      |             ~~^~~
koala.cpp: In function 'void mergesort(int, int, int*)':
koala.cpp:116:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  116 |     int mid = l + r >> 1;
      |               ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 344 KB Output is correct
2 Correct 3 ms 344 KB Output is correct
3 Correct 3 ms 344 KB Output is correct
4 Correct 3 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 344 KB Output is correct
2 Correct 10 ms 460 KB Output is correct
3 Correct 10 ms 344 KB Output is correct
4 Correct 10 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 968 KB Output is correct
2 Correct 47 ms 464 KB Output is correct
3 Correct 40 ms 468 KB Output is correct
4 Correct 40 ms 480 KB Output is correct
5 Correct 41 ms 716 KB Output is correct
6 Correct 40 ms 480 KB Output is correct
7 Correct 43 ms 460 KB Output is correct
8 Correct 40 ms 476 KB Output is correct
9 Correct 41 ms 472 KB Output is correct
10 Correct 39 ms 472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 344 KB Output is correct
2 Correct 25 ms 456 KB Output is correct
3 Correct 26 ms 344 KB Output is correct
4 Correct 25 ms 500 KB Output is correct
5 Correct 24 ms 344 KB Output is correct
6 Correct 25 ms 456 KB Output is correct
7 Correct 24 ms 456 KB Output is correct
8 Correct 24 ms 344 KB Output is correct
9 Correct 24 ms 344 KB Output is correct
10 Correct 24 ms 452 KB Output is correct
11 Correct 26 ms 344 KB Output is correct
12 Correct 16 ms 452 KB Output is correct
13 Correct 25 ms 428 KB Output is correct
14 Correct 22 ms 448 KB Output is correct
15 Correct 22 ms 596 KB Output is correct
16 Correct 22 ms 452 KB Output is correct
17 Correct 21 ms 344 KB Output is correct
18 Correct 23 ms 344 KB Output is correct
19 Correct 22 ms 344 KB Output is correct
20 Correct 22 ms 456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -