Submission #883591

# Submission time Handle Problem Language Result Execution time Memory
883591 2023-12-05T13:23:55 Z kongum Finding Routers (IOI20_routers) C++17
0 / 100
2000 ms 604 KB
#include <bits/stdc++.h>
#include "routers.h"

#define fi first
#define se second
#define all(a) (a).begin(), (a).end()

using namespace std;
using pii = pair<int, int>;
using ti3 = tuple<int, int, int>;

const int MAX = 100010;
int arr[MAX], fir[MAX], cnt[MAX], res[MAX];


int lowerBound(int lo, int hi, int tar) { // tar + 1반환
    while (lo + 1 < hi) {
        int mid = (lo + hi) / 2;
        int chk = use_detector(mid);
        if (chk < tar) lo = mid;
        else hi = mid;
        
    }
    return hi;
}

void divide(int lo, int hi) {
    int mid = (lo + hi) / 2;
    int tar = use_detector(mid);
    int lft = lowerBound(lo, hi, tar);
    int rgt = lowerBound(lo, hi, tar + 1) - 1;
    arr[lft] = tar;
    arr[rgt] = tar;

    if (lo + 1 < lft) divide(lo, lft - 1);
    if (mid < hi) divide(mid, hi);
}

std::vector<int> find_routers(int l, int n, int q) {
    for (int i = 0; i < MAX; i++) arr[i] = -1;
    divide(-1, l + 1);

    for (int i = 1; i < l; i++) arr[i] = max(arr[i], arr[i - 1]);
    for (int i = 0; i < l + 1; i++) {
        if (arr[i] >= 0) cnt[arr[i]]++;
        if (i >= 1 && arr[i] > arr[i - 1]) fir[arr[i]] = i;
    }
    fir[0] = 0;
    res[0] = 0;

    for (int i = 1; i < n; i++) {
        res[i] = res[i - 1] + (cnt[i - 1] - 1) * 2;
        cnt[i] -= cnt[i - 1] - 2;
    }
    vector<int> v;
    for (int i = 0; i < n; i++) v.push_back(res[i]);

    return v;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 2024 ms 600 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2054 ms 604 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2035 ms 600 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2039 ms 600 KB Time limit exceeded
2 Halted 0 ms 0 KB -