답안 #1076085

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1076085 2024-08-26T11:04:00 Z raduv Mouse (info1cup19_mouse) C++17
0 / 100
0 ms 344 KB
#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

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 0 ms 344 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 344 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 344 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -