Submission #723207

# Submission time Handle Problem Language Result Execution time Memory
723207 2023-04-13T10:49:04 Z nguyentunglam Koala Game (APIO17_koala) C++17
Compilation error
0 ms 0 KB
#include "koala.h"
#include<bits/stdc++.h>
using namespace std;
const int N = 110;
int b[N], r[N], mark[N], ans[N], c[N], order[N];
int n, w;
int minValue(int n, int w) {
    for(int i = 0; i < n; i++) b[i] = 0;
    b[0] = 1;
    playRound(b, r);
    for(int i = 0; i < n; i++) if (!r[i]) return i;
    return 0;
}

int maxValue(int n, int w) {
    for(int i = 0; i < n; i++) mark[i] = 1;
    while (1) {
        int cnt = 0;
        for(int i = 0; i < n; i++) cnt += mark[i];
        if (cnt == 1) break;
        int val = w / cnt;
        for(int i = 0; i < n; i++) {
            if (mark[i]) b[i] = val;
            else b[i] = 0;
        }
        playRound(b, r);
        for(int i = 0; i < n; i++) mark[i] &= (r[i] > 0);
    }
    for(int i = 0; i < n; i++) if (mark[i]) return i;
    return 0;
}

int greaterValue(int n, int w) {
    int L = 1, R = min(w / 2, 9);
    while (L <= R) {
        int mid = L + R >> 1;
        for(int i = 2; i < n; i++) b[i] = 0;
        b[0] = b[1] = mid;
        playRound(b, r);
        int tmp = 0;
        for(int i = 0; i < 2; i++) if (r[i] > b[i]) tmp++;

        if (tmp == 2) L = mid + 1;
        else {
            if (tmp == 1) {
                if (r[0] > b[0]) return 0;
                return 1;
            }
            R = mid - 1;
        }
    }
    return 0;
}

void solve(vector<int> lst, int L, int R) {
    if (lst.size() == 1) {
        ans[lst[0]] = L;
        return;
    }
    int l = 1, r = min(10, w / (int)lst.size());
    while (l <= r) {
        int mid = l + r >> 1;
        for(int i = 0; i < n; i++) b[i] = 0;
        for(int &j : lst) b[j] = mid;
        playRound(b, c);
        int tmp = 0;
        for(int &j : lst) tmp += (c[j] > b[j]);

        if (tmp == lst.size()) l = mid + 1;
        else {
            if (tmp > 0) {
                vector<int> v1, v2;
                for(int &j : lst) {
                    if (c[j] > b[j]) v1.push_back(j);
                    else v2.push_back(j);
                }
                solve(v2, L, L + v2.size() - 1);
                solve(v1, L + v2.size(), R);
                return;
            }
            else r = mid - 1;
        }
    }
}

bool cmp(const int &x, const int &y) {
    for(int i = 0; i < n; i++) b[i] = 0;
    b[x] = w / 2; b[y] = w / 2;
    playRound(b, c);
    return c[x] <= b[x];
}

void MergeSort(vector<int> &v) {
    if (v.size() == 1) return;
    vector<int> L, R;
    for (int i = 0; i < (int) v.size() / 2; ++i) L.push_back(v[i]);
    for (int i = (int) v.size() / 2; i < (int) v.size(); ++i) R.push_back(v[i]);

    MergeSort(L); MergeSort(R);
    v.clear();
    int i = 0; j = 0;
    while (i < (int) L.size() || j < (int) R.size()) {
        if (L.size() && R.size()) {
            if (cmp(L[i], R[j])) v.push_back(L[i++]);
            else v.push_back(R[j++]);
        }
        else if (L.size()) v.push_back(L[i++]);
        else v.push_back(R[j++]);
    }
}

void allValues(int _n, int W, int *P) {
    n = _n;
    w = W;
    if (W == 2 * n) {
        vector<int> v(n);
        iota(v.begin(), v.end(), 0);
        MergeSort(v);
        for(int i = 0; i < n; i++) P[v[i]] = i + 1;
    } else {
        vector<int> init;
        for(int i = 0; i < n; i++) init.push_back(i);
        solve(init, 1, n);
        for(int i = 0; i < n; i++) P[i] = ans[i];
    }
}

Compilation message

koala.cpp: In function 'int greaterValue(int, int)':
koala.cpp:36:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   36 |         int mid = L + R >> 1;
      |                   ~~^~~
koala.cpp: In function 'void solve(std::vector<int>, int, int)':
koala.cpp:62:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   62 |         int mid = l + r >> 1;
      |                   ~~^~~
koala.cpp:69:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |         if (tmp == lst.size()) l = mid + 1;
      |             ~~~~^~~~~~~~~~~~~
koala.cpp: In function 'void MergeSort(std::vector<int>&)':
koala.cpp:101:16: error: 'j' was not declared in this scope
  101 |     int i = 0; j = 0;
      |                ^