This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "routers.h"
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> find_routers(int l, int n, int q){
vector<int>ans(n);
vector<int>before(n, -1);
ans[0]=0;
if (l%2!=0) l--;
vector<pair<int,int>>memoria(n, make_pair(0, 1e9));
for (int i=1; i<n; i++){
int right=min(l-2*(n-i-1), 2*memoria[i].second-ans[i-1]-2);
int left=max(ans[i-1]+2, 2*memoria[i-1].first-ans[i-1]);
int m;
bool tipo=false;
while (left!=right){
m=(right-left)/2+left;
if (m%2!=0) m++;
if (left+2==right){
int m3=(left-ans[i-1])/2+ans[i-1];
if (m3%2==0) m3+=2;
else m3++;
if (m3)
if (use_detector(m3)==i) right-=2;
else left+=2;
}
else if (tipo==false){
if (use_detector(m)==i+1){
memoria[i+1].second=min(memoria[i+1].second, m);
right=m-2;
}else{
memoria[i].first=max(memoria[i].first, m);
tipo=true;
}
}else{
int m2=(right-m)/2+m;
if (m2%2!=0) m2++;
if (use_detector(m2)==i+1){
memoria[i+1].second=min(memoria[i+1].second, m2);
right=m-2;
tipo=false;
}else{
memoria[i].first=max(memoria[i].first, m2);
left=m;
}
}
}ans[i]=left;
}return ans;
}
Compilation message (stderr)
routers.cpp: In function 'std::vector<int> find_routers(int, int, int)':
routers.cpp:25:20: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
25 | if (m3)
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |