답안 #1048212

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1048212 2024-08-08T05:23:22 Z becaido 커다란 상품 (IOI17_prize) C++17
0 / 100
1000 ms 1048576 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
using namespace std;

#ifdef WAIMAI
#include "grader.cpp"
#else
#include "prize.h"
#endif

#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() {cout << '\n';}
template<typename T, typename...U>
void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);}
#else
#define debug(...) 7122
#endif

#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second

const int SIZE = 2e5 + 5;
const int K = 450;

int mx, L[SIZE], R[SIZE];
vector<int> id;

pair<int, int> que(int i) {
    if (L[i] == -1) {
        auto v = ask(i);
        L[i] = v[0], R[i] = v[1];
    }
    return {L[i], R[i]};
}

void rec(int l, int r, int lc, int rc, int tot) {
    if (l > r || tot == 0) return;
    if (l == r) {
        id.pb(l);
        return;
    }
    int mid = (l + r) / 2;
    FOR (i, mid, r) {
        auto [lcnt, rcnt] = que(i);
        if (lcnt + rcnt != mx) {
            id.pb(i);
            continue;
        }
        lcnt -= lc, rcnt -= rc;
        rec(l, mid - 1, lc, rc + (i - mid) + rcnt, tot - (i - mid) - rcnt);
        rec(i + 1, r, lc + lcnt, rcnt, tot - lcnt);
    }
    rec(l, mid - 1, lc, rc + (r - mid + 1), tot - (r - mid + 1));
}

int find_best(int n) {
    FOR (i, 0, n - 1) L[i] = R[i] = -1;
    if (n < K) {
        FOR (i, 0, n - 1) {
            auto [l, r] = que(i);
            if (l == 0 && r == 0) return i;
        }
    }

    mx = 0;
    FOR (i, 0, K - 1) {
        auto [l, r] = que(i);
        mx = max(mx, l + r);
    }

    id.clear();
    rec(0, n - 1, 0, 0, mx);
    for (int i : id) {
        auto [l, r] = que(i);
        if (l == 0 && r == 0) return i;
    }
}

/*
in1
8
3 2 3 1 3 3 2 3
*/

Compilation message

prize.cpp: In function 'int find_best(int)':
prize.cpp:83:1: warning: control reaches end of non-void function [-Wreturn-type]
   83 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2093 ms 1048576 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2085 ms 1048576 KB Time limit exceeded
2 Halted 0 ms 0 KB -