답안 #70399

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
70399 2018-08-22T19:32:06 Z chpipis 커다란 상품 (IOI17_prize) C++11
0 / 100
15 ms 5880 KB
#include "prize.h"
#include <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;

const int MAXN = 2e5 + 5;
const int SIZE = 300;

int cnt[MAXN], num_q;
vi memo[MAXN];

vi query(int x) {
    if (memo[x].size() > 0)
        return memo[x];
    num_q++;
    vi ret = ask(x);
    return memo[x] = ret;
}

int find_best(int n) {
    memset(cnt, 0, sizeof cnt);
    fill(memo, memo + n + 1, vi());
    num_q = 0;
    /*
    int mx = -1;
    for (int i = 0, j; i < n; i = j + 1) {
        if (i == n - 1) return i;
        j = i;
        vi cur = query(i);
        if (cur[0] + cur[1] == 0) return i;
        if (cur[0] + cur[1] < mx) continue;
        mx = max(mx, cur[0] + cur[1]);
        int lo = i + 1, hi = n - 1;
        while (lo <= hi) {
            int mid = (lo + hi) >> 1;
            vi now = query(mid);
            if (now[0] + now[1] == 0) return mid;
            if (now == cur) {
                lo = mid + 1;
                j = mid;
            } else {
                hi = mid - 1;
            }
        }
    }
    */
    for (int i = 0; i < n; i++) {
        if (i == n - 1) return i;
        vi cur = query(i);
        int type = cur[0] + cur[1];
        if (type == 0) return i;
        cnt[type]++;
        if (query(i + 1) != cur)
            continue;
        int b;
        for (b = i / SIZE; (b + 1) * SIZE < n; b++) {
            if (query((b + 1) * SIZE) != cur)
                break;
        }
        int lo = max(i + 1, b * SIZE), hi = min(n - 1, (b + 1) * SIZE - 1);
        if (i == (b + 1) * SIZE - 1) {
            lo = (b + 1) * SIZE;
            hi = min(n - 1, (b + 2) * SIZE - 1);
        }
        while (lo < hi) {
            int mid = (lo + hi) >> 1;
            vi now = query(mid);
            if (now == cur || now[0] == cnt[type] + cur[0]) {
                lo = mid + 1;
            } else {
                hi = mid;
            }
        }
        i = hi - 1;
    }
}



Compilation message

prize.cpp: In function 'int find_best(int)':
prize.cpp:78:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 15 ms 5880 KB answer is not correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 5880 KB answer is not correct
2 Halted 0 ms 0 KB -