제출 #1203545

#제출 시각아이디문제언어결과실행 시간메모리
1203545raphaeltroenFinding Routers (IOI20_routers)C++20
39 / 100
1 ms840 KiB
#include <bits/stdc++.h>
using namespace std;
map<int, int> first;
vector<int> found;
#include "routers.h"

/*int use_detector(int x);*/

int findfromprevplace(int i, int x, int l){
    int start = x+1, end;
    if(first.empty())end = l;
    else end = (*first.begin()).second-1;
    int lasti = x, curr, middle;
    while(start<=end){
        middle = (start+end)/2;

        if(found[middle] == -1) {
            curr = use_detector(middle);
            found[middle] = curr;
        }else {curr = found[middle];}
        first[curr] = min(first[curr], middle);

        if(curr != i){
            end = middle -1;
        }else{
            lasti = max(lasti, middle);
            start = middle +1;
        }
    }
    if(first.find(i+1) != first.end()) first.erase(i+1);
    if(first.find(i)!=first.end()) first.erase(i);
    return 2*lasti-x;
}

std::vector<int> find_routers(int l, int n, int q){
    vector<int> ans;
    ans.push_back(0);
    int currfound = 0;
    int i = 0;
    found.resize(l+1, -1);
    while(ans.size()<n){
        currfound = findfromprevplace(i, currfound, l);
        ans.push_back(currfound);
        i++;
    }
    return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...