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 <bits/stdc++.h>
#ifndef DEBUG
#include "grader.h"
#endif
using namespace std;
vector<int> v, q;
void setinterval(int n, int l, int r, int val){
int i;
for( i = 0; i < n; i++ ){
if(i >= l && i <= r)
q[i] = val;
else
q[i] = n + 1; // nu va modifica rezultatul query-ului
}
}
#ifdef DEBUG
vector<int> p;
int permut[] = {9, 8, 10, 5, 3, 2, 1, 4, 7, 6};
int query(int n){
int i, cnt = 0;
for( i = 0; i < n; i++ ){
printf("%d ", q[i]);
cnt += (q[i] == p[i]);
}
printf("\n");
return cnt;
}
#endif
void solve(int n){
//printf("%d ", n);
int i, val, st, dr, mij;
q.reserve(n);
v.reserve(n);
for( val = 1; val <= n; val++ ){
// cautam binar pentru fiecare valoare pozitia sa
setinterval(n, 0, n - 1, val);
st = 0;
dr = n;
//printf("%d %d", st, dr);
while( dr - st > 1 ){
mij = (st + dr) / 2;
setinterval(n, st, mij - 1, val);
if(query(q))
dr = mij;
else
st = mij;
}
v[st] = val;
}
query(v);
return;
}
#ifdef DEBUG
int main(){
int i, n;
n = 10;
p.reserve(n);
for( i = 0; i < n; i++ ){
p[i] = permut[i];
//printf("%d ", p[i]);
}
solve(n);
return 0;
}
#endif // DEBUG
Compilation message (stderr)
mouse.cpp: In function 'void solve(int)':
mouse.cpp:33:7: warning: unused variable 'i' [-Wunused-variable]
33 | int i, val, st, dr, mij;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |