#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 = 1; 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 + 1);
v.reserve(n + 1);
for( val = 1; val <= n; val++ ){
// cautam binar pentru fiecare valoare pozitia sa
setinterval(n, 1, n, val);
st = 1;
dr = n + 1;
//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
mouse.cpp: In function 'void solve(int)':
mouse.cpp:33:7: warning: unused variable 'i' [-Wunused-variable]
33 | int i, val, st, dr, mij;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |