답안 #1118407

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1118407 2024-11-25T12:52:06 Z adaawf 커다란 상품 (IOI17_prize) C++17
0 / 100
40 ms 716 KB
#include <iostream>
#include <vector>
#include <assert.h>
using namespace std;
int a[20005], cc = 0;
vector<int> ask(int i);
int find_best(int n) {
    vector<pair<int, pair<int, int>>> v;
    vector<int> t;
    int mi = 0;
    for (int i = 1; i <= 480; i++) {
        t = ask(i);
        if (t[0] + t[1] == 0) return i;
        mi = max(mi, t[0] + t[1]);
    }
    int c = 0;
    for (int i = 1; i <= 20000; i += 10) {
        c = 0;
        while (1) {
            if (i > n) break;
            t = ask(i);
            if (t[0] + t[1] == 0) return i;
            if (t[0] + t[1] == mi) {
                break;
            }
            c++;
            i++;
        }
        if (i <= n) v.push_back({i, {t[1], c}});
    }
    //cout << cc << '\n';
    v.push_back({n + 1, {0, c}});
    for (int i = 0; i < v.size() - 1; i++) {
        int h = v[i].second.first - v[i + 1].second.first;
        h -= v[i + 1].second.second;
        if (h >= 2) {
            for (int j = v[i].first + 1; j < v[i].first + 10; j++) {
                t = ask(i);
                if (t[0] + t[1] == 0) return j;
            }
        }
        else if (h == 1) {
            int l = v[i].first + 1, r = v[i].first + 9, res;
            while (l <= r) {
                int mid = (l + r) / 2;
                t = ask(mid);
                if (t[0] + t[1] == 0) return mid;
                if (t[0] + t[1] != mi) break;
                if (t[1] == v[i].second.first) {
                    res = mid;
                    l = mid + 1;
                }
                else r = mid - 1;
            }
        }
    }
    assert(0);
    return -1;
}

Compilation message

prize.cpp: In function 'int find_best(int)':
prize.cpp:33:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     for (int i = 0; i < v.size() - 1; i++) {
      |                     ~~^~~~~~~~~~~~~~
prize.cpp:43:57: warning: variable 'res' set but not used [-Wunused-but-set-variable]
   43 |             int l = v[i].first + 1, r = v[i].first + 9, res;
      |                                                         ^~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 37 ms 716 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 40 ms 708 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -