Submission #52174

# Submission time Handle Problem Language Result Execution time Memory
52174 2018-06-24T13:31:04 Z imeimi2000 Koala Game (APIO17_koala) C++17
100 / 100
152 ms 940 KB
#include "koala.h"
#include <vector>
#include <set>

using namespace std;

int n, w;
int qb[100];
int qr[100];
int minValue(int N, int W) {
    n = N;
    w = W;
    qb[0] = 1;
    for (int i = 1; i < n; ++i) {
        qb[i] = 0;
    }
    playRound(qb, qr);
    for (int i = 0; i < n; ++i) {
        if (qb[i] < qr[i]) continue;
        return i;
    }
}

int cand[100];
int maxValue(int N, int W) {
    n = N;
    w = W;
    for (int i = 0; i < n; ++i) cand[i] = 1;
    int cnt = n;
    
    while (cnt > 1) {
        for (int i = 0; i < n; ++i) {
            if (cand[i]) qb[i] = w / cnt;
            else qb[i] = 0;
        }
        playRound(qb, qr);
        for (int i = 0; i < n; ++i) {
            if (cand[i] && qr[i] <= qb[i]) --cnt, cand[i] = 0;
        }
    }
    for (int i = 0; i < n; ++i) {
        if (cand[i]) return i;
    }
}

int greaterValue(int N, int W) {
    n = N;
    w = W;
    for (int i = 0; i < n; ++i) {
        qb[i] = 0;
    }
    const int arr[5] = { 1, 2, 3, 5, 8 };
    int s = 0, e = 4;
    while (s <= e) {
        int m = (s + e) / 2;
        qb[0] = qb[1] = arr[m];
        playRound(qb, qr);
        int a = (qb[0] < qr[0]);
        int b = (qb[1] < qr[1]);
        if (a != b) return b;
        if (a) s = m + 1;
        else e = m - 1;
    }
}

int sortArray[100];
bool cmp(int x, int y) {
    for (int i = 0; i < n; ++i) {
        qb[i] = 0;
    }
    qb[x] = qb[y] = n;
    playRound(qb, qr);
    if (qb[x] < qr[x]) return 0;
    return 1;
}

void mergeSort(int s, int e) {
    if (e <= s) return;
    int m = (s + e) / 2;
    mergeSort(s, m);
    mergeSort(m + 1, e);
    int tp[100];
    int i = s, j = m + 1, k = s;
    while (i <= m || j <= e) {
        if (i > m) tp[k++] = sortArray[j++];
        else if (j > e) tp[k++] = sortArray[i++];
        else if (cmp(sortArray[i], sortArray[j])) tp[k++] = sortArray[i++];
        else tp[k++] = sortArray[j++];
    }
    for (i = s; i <= e; ++i) {
        sortArray[i] = tp[i];
    }
}

int saveFinds[101];
int findNineMax(const set<int> &mp) {
    for (int i = 0; i < n; ++i) {
        qb[i] = 0;
    }
    for (int i : mp) qb[i] = 11;
    for (int i = mp.size(); i < 9; ++i) qb[saveFinds[i]] = 11;
    playRound(qb, qr);
    for (int i : mp) {
        if (qb[i] < qr[i]) return i;
    }
}

void findNumbers(int s, int e, int qs = 0) {
    const int qn[3] = { 2, 4, 3 };
    if (e - s < 9) {
        set<int> mp;
        for (int i = s; i <= e; ++i) mp.insert(saveFinds[i]);
        for (int i = e; i > s; --i) {
            mp.erase(saveFinds[i] = findNineMax(mp));
        }
        saveFinds[s] = *mp.begin();
        return;
    }
    for (int i = 0; i < n; ++i) {
        qb[i] = 0;
    }
    for (int i = s; i <= e; ++i) {
        qb[saveFinds[i]] = qn[qs];
    }
    playRound(qb, qr);
    vector<int> tp1, tp2;
    for (int i = s; i <= e; ++i) {
        if (qb[saveFinds[i]] < qr[saveFinds[i]]) tp2.push_back(saveFinds[i]);
        else tp1.push_back(saveFinds[i]);
    }
    int i = s;
    for (int j : tp1) saveFinds[i++] = j;
    for (int j : tp2) saveFinds[i++] = j;
    i = s + tp1.size();
    findNumbers(s, i - 1, qs + 1);
    findNumbers(i, e, qs + 1);
}

void allValues(int N, int W, int *P) {
    n = N;
    w = W;
    if (W == N + N) {
        for (int i = 0; i < n; ++i) {
            sortArray[i] = i;
        }
        mergeSort(0, n - 1);
        for (int i = 0; i < n; ++i) {
            P[sortArray[i]] = i + 1;
        }
    } else {
        int arr[100];
        set<int> mp;
        for (int i = 0; i < n; ++i) mp.insert(i);
        for (int i = 0; i < n / 2; ++i) {
            for (int j = 0; j < n; ++j) {
                qb[j] = 0;
                arr[j] = 1;
            }
            for (int j = 0; j < i; ++j) {
                qb[saveFinds[j]] = 1;
                arr[saveFinds[j]] = 0;
            }
            for (int j = 0, k = 0; j < n && k <= i; ++j) {
                if (qb[j]) continue;
                qb[j] = 1;
                ++k;
            }
            playRound(qb, qr);
            for (int j = 0; j < n; ++j) {
                if (arr[j] && qr[j] <= qb[j]) {
                    saveFinds[i] = j;
                    mp.erase(j);
                    break;
                }
            }
        }
        for (int i = n / 2; i < n; ++i) {
            saveFinds[i] = *mp.begin();
            mp.erase(mp.begin());
        }
        findNumbers(n / 2, n - 1);
        for (int i = 0; i < n; ++i) {
            P[saveFinds[i]] = i + 1;
        }
    }
}

Compilation message

koala.cpp: In function 'int minValue(int, int)':
koala.cpp:22:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
koala.cpp: In function 'int maxValue(int, int)':
koala.cpp:44:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
koala.cpp: In function 'int greaterValue(int, int)':
koala.cpp:64:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
koala.cpp: In function 'int findNineMax(const std::set<int>&)':
koala.cpp:106:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Correct 10 ms 248 KB Output is correct
2 Correct 9 ms 484 KB Output is correct
3 Correct 9 ms 580 KB Output is correct
4 Correct 7 ms 580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 580 KB Output is correct
2 Correct 27 ms 580 KB Output is correct
3 Correct 19 ms 580 KB Output is correct
4 Correct 17 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 692 KB Output is correct
2 Correct 116 ms 816 KB Output is correct
3 Correct 113 ms 816 KB Output is correct
4 Correct 94 ms 816 KB Output is correct
5 Correct 141 ms 816 KB Output is correct
6 Correct 112 ms 816 KB Output is correct
7 Correct 126 ms 816 KB Output is correct
8 Correct 152 ms 940 KB Output is correct
9 Correct 149 ms 940 KB Output is correct
10 Correct 140 ms 940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 940 KB Output is correct
2 Correct 61 ms 940 KB Output is correct
3 Correct 44 ms 940 KB Output is correct
4 Correct 44 ms 940 KB Output is correct
5 Correct 40 ms 940 KB Output is correct
6 Correct 50 ms 940 KB Output is correct
7 Correct 41 ms 940 KB Output is correct
8 Correct 48 ms 940 KB Output is correct
9 Correct 50 ms 940 KB Output is correct
10 Correct 44 ms 940 KB Output is correct
11 Correct 50 ms 940 KB Output is correct
12 Correct 25 ms 940 KB Output is correct
13 Correct 39 ms 940 KB Output is correct
14 Correct 47 ms 940 KB Output is correct
15 Correct 35 ms 940 KB Output is correct
16 Correct 35 ms 940 KB Output is correct
17 Correct 55 ms 940 KB Output is correct
18 Correct 35 ms 940 KB Output is correct
19 Correct 34 ms 940 KB Output is correct
20 Correct 42 ms 940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 940 KB Output is correct
2 Correct 5 ms 940 KB Output is correct
3 Correct 7 ms 940 KB Output is correct
4 Correct 5 ms 940 KB Output is correct
5 Correct 7 ms 940 KB Output is correct
6 Correct 8 ms 940 KB Output is correct
7 Correct 6 ms 940 KB Output is correct
8 Correct 6 ms 940 KB Output is correct
9 Correct 8 ms 940 KB Output is correct
10 Correct 6 ms 940 KB Output is correct
11 Correct 9 ms 940 KB Output is correct
12 Correct 9 ms 940 KB Output is correct
13 Correct 3 ms 940 KB Output is correct
14 Correct 7 ms 940 KB Output is correct
15 Correct 9 ms 940 KB Output is correct
16 Correct 10 ms 940 KB Output is correct
17 Correct 8 ms 940 KB Output is correct
18 Correct 6 ms 940 KB Output is correct
19 Correct 6 ms 940 KB Output is correct
20 Correct 7 ms 940 KB Output is correct
21 Correct 7 ms 940 KB Output is correct
22 Correct 7 ms 940 KB Output is correct
23 Correct 7 ms 940 KB Output is correct
24 Correct 6 ms 940 KB Output is correct
25 Correct 7 ms 940 KB Output is correct
26 Correct 6 ms 940 KB Output is correct
27 Correct 7 ms 940 KB Output is correct
28 Correct 8 ms 940 KB Output is correct
29 Correct 6 ms 940 KB Output is correct
30 Correct 7 ms 940 KB Output is correct
31 Correct 8 ms 940 KB Output is correct
32 Correct 9 ms 940 KB Output is correct
33 Correct 6 ms 940 KB Output is correct
34 Correct 7 ms 940 KB Output is correct
35 Correct 6 ms 940 KB Output is correct
36 Correct 8 ms 940 KB Output is correct
37 Correct 8 ms 940 KB Output is correct
38 Correct 7 ms 940 KB Output is correct
39 Correct 8 ms 940 KB Output is correct
40 Correct 6 ms 940 KB Output is correct