답안 #250925

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
250925 2020-07-19T13:00:26 Z receed 코알라 (APIO17_koala) C++14
100 / 100
96 ms 512 KB
#include "koala.h"
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cassert>
#include <string>
#include <set>
#include <map>
#include <random>
#include <bitset>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using ul = unsigned long long;
using ld = long double;

int cache[2][205];
int num[2][205];
char taken[105][205];

const int N = 100;
int W = 200;
int b[N], r[N], tk[N], val[N];

void solve() {
    int i, j;
    for (i=0;i<205;++i) {
        cache[1][i] = 0;
        num[1][i] = 0;
    }

    for (i=0;i<N;++i) {
        int v = b[i]+1;
        int ii = i&1;
        int o = ii^1;
        for (j=0;j<=W;++j) {
            cache[ii][j] = cache[o][j];
            num[ii][j] = num[o][j];
            taken[i][j] = 0;
        }
        for (j=W;j>=v;--j) {
            int h = cache[o][j-v] + val[i];
            int hn = num[o][j-v] + 1;
            if (h > cache[ii][j] || (h == cache[ii][j] && hn > num[ii][j])) {
                cache[ii][j] = h;
                num[ii][j] = hn;
                taken[i][j] = 1;
            } else {
                taken[i][j] = 0;
            }
        }
    }
    int cur = W;
    for (i=N-1;i>=0;--i) {
        int cr = taken[i][cur] ? (b[i] + 1) : 0;
        cur -= cr;
        if (cr)
            tk[i] = 1;
        else
            tk[i] = 0;
    }
}

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

int maxValue(int n, int w) {
    vector<int> a(n), na;
    rep(i, n)
        a[i] = i;
    while (a.size() > 1) {
        int cw = w / a.size();
        rep(i, n)
            b[i] = 0;
        for (int i : a)
            b[i] = cw;
        playRound(b, r);
        na.clear();
        for (int i : a)
            if (r[i] > cw)
                na.push_back(i);
        a = na;
    }
    assert(!a.empty());
    return a[0];
}

int greaterValue(int n, int w) {
    int l = 0, rr = 6, m;
    vector<int> a {1, 2, 3, 4, 5, 6, 8};
    while (1) {
        m = (l + rr) / 2;
        b[0] = b[1] = a[m];
        playRound(b, r);
        if (r[0] > a[m] && r[1] > a[m]) {
            assert(l != rr);
            l = m + 1;
        }
        else if (r[0] <= a[m] && r[1] <= a[m]) {
            assert(l != rr);
            rr = m - 1;
        }
        else
            return r[0] < r[1];
    }
    return -1;
}

void go(int l, int cr, vector<int> lp) {
    // cout << l << ' '<< cr << endl;
    if (cr - l <= 1)
        return;
    rep(i, N)
        b[i] = 0;
    for (int i : lp)
        b[i] = W / lp.size();
    while (1) {
        assert(b[lp[0]] > 0);
        solve();
        if (tk[lp[0]] != tk[lp.back()]) {
            playRound(b, r);
            vector<int> l1, l2;
            int c1 = l;
            for (int i : lp) {
                if (r[i] > b[i])
                    l2.push_back(i);
                else
                    l1.push_back(i);
            }
            assert(!l1.empty() && !l2.empty());
            for (int i : l1)
                val[i] = c1++;
            for (int i : l2)
                val[i] = c1++;
            go(l + l1.size(), cr, l2);
            go(l, l + l1.size(), l1);
            return;
        }
        for (int i : lp)
            b[i]--;
    }
}

void allValues(int n, int w, int *p) {
    W = w;
    rep(i, n)
        val[i] = i + 1;
    vector<int> lp(n);
    rep(i, n)
        lp[i] = i;
    go(1, n + 1, lp);
    rep(i, n)
        p[i] = val[i];
    if (w == 2*n) {
        // TODO: Implement Subtask 4 solution here.
        // You may leave this block unmodified if you are not attempting this
        // subtask.
    } else {
        // TODO: Implement Subtask 5 solution here.
        // You may leave this block unmodified if you are not attempting this
        // subtask.
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 384 KB Output is correct
2 Correct 18 ms 384 KB Output is correct
3 Correct 17 ms 384 KB Output is correct
4 Correct 17 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 86 ms 384 KB Output is correct
2 Correct 96 ms 384 KB Output is correct
3 Correct 85 ms 384 KB Output is correct
4 Correct 85 ms 384 KB Output is correct
5 Correct 84 ms 400 KB Output is correct
6 Correct 88 ms 512 KB Output is correct
7 Correct 84 ms 384 KB Output is correct
8 Correct 86 ms 384 KB Output is correct
9 Correct 92 ms 512 KB Output is correct
10 Correct 83 ms 508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 504 KB Output is correct
2 Correct 16 ms 384 KB Output is correct
3 Correct 17 ms 384 KB Output is correct
4 Correct 17 ms 384 KB Output is correct
5 Correct 16 ms 384 KB Output is correct
6 Correct 16 ms 384 KB Output is correct
7 Correct 16 ms 384 KB Output is correct
8 Correct 17 ms 384 KB Output is correct
9 Correct 16 ms 384 KB Output is correct
10 Correct 16 ms 512 KB Output is correct
11 Correct 16 ms 384 KB Output is correct
12 Correct 16 ms 384 KB Output is correct
13 Correct 16 ms 384 KB Output is correct
14 Correct 17 ms 384 KB Output is correct
15 Correct 16 ms 384 KB Output is correct
16 Correct 17 ms 384 KB Output is correct
17 Correct 16 ms 384 KB Output is correct
18 Correct 16 ms 384 KB Output is correct
19 Correct 16 ms 384 KB Output is correct
20 Correct 19 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 384 KB Output is correct
2 Correct 57 ms 384 KB Output is correct
3 Correct 56 ms 384 KB Output is correct
4 Correct 56 ms 384 KB Output is correct
5 Correct 56 ms 384 KB Output is correct
6 Correct 55 ms 384 KB Output is correct
7 Correct 56 ms 384 KB Output is correct
8 Correct 56 ms 504 KB Output is correct
9 Correct 56 ms 384 KB Output is correct
10 Correct 56 ms 384 KB Output is correct
11 Correct 58 ms 384 KB Output is correct
12 Correct 55 ms 384 KB Output is correct
13 Correct 55 ms 384 KB Output is correct
14 Correct 56 ms 384 KB Output is correct
15 Correct 55 ms 384 KB Output is correct
16 Correct 56 ms 384 KB Output is correct
17 Correct 57 ms 384 KB Output is correct
18 Correct 55 ms 384 KB Output is correct
19 Correct 56 ms 384 KB Output is correct
20 Correct 55 ms 384 KB Output is correct
21 Correct 55 ms 504 KB Output is correct
22 Correct 56 ms 384 KB Output is correct
23 Correct 57 ms 384 KB Output is correct
24 Correct 56 ms 384 KB Output is correct
25 Correct 55 ms 384 KB Output is correct
26 Correct 56 ms 504 KB Output is correct
27 Correct 56 ms 504 KB Output is correct
28 Correct 56 ms 384 KB Output is correct
29 Correct 56 ms 412 KB Output is correct
30 Correct 59 ms 384 KB Output is correct
31 Correct 56 ms 384 KB Output is correct
32 Correct 55 ms 384 KB Output is correct
33 Correct 56 ms 412 KB Output is correct
34 Correct 55 ms 384 KB Output is correct
35 Correct 57 ms 384 KB Output is correct
36 Correct 57 ms 504 KB Output is correct
37 Correct 56 ms 384 KB Output is correct
38 Correct 55 ms 384 KB Output is correct
39 Correct 56 ms 384 KB Output is correct
40 Correct 54 ms 384 KB Output is correct