답안 #504102

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
504102 2022-01-09T20:04:36 Z 600Mihnea Archery (IOI09_archery) C++17
39 / 100
2000 ms 24812 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 2 * 200000 + 7;
const int INF = (int) 1e9 + 7;
int n;
int r;
int my_rank;
int init_ord[N];
int ord[N];
int winner[N];
int loser[N];
vector<int> guys[N];
bool wannap;
int thesol[N];

int simulate_step_for_get_brute() {
  for (int i = 0; i < n; i++) {
    if (ord[2 * i] < ord[2 * i + 1]) {
      winner[i] = ord[2 * i];
      loser[i] = ord[2 * i + 1];
    } else {
      winner[i] = ord[2 * i + 1];
      loser[i] = ord[2 * i];
    }
    guys[i].clear();
  }
  guys[0].push_back(winner[0]);
  for (int i = 1; i < n; i++) {
    guys[i - 1].push_back(winner[i]);
    guys[i].push_back(loser[i]);
  }
  guys[n - 1].push_back(loser[0]);
  for (int i = 0; i < n; i++) {
    assert((int) guys[i].size() == 2);
    for (int it = 0; it < 2; it++) {
      ord[2 * i + it] = guys[i][it];
    }
  }
  return (loser[0] == my_rank);
}

void print() {
  cout << " ----> ";
  for (int i = 0; i < 2 * n; i++) {
    cout << ord[i] + 1 << " ";
  }
  cout << "\n";
}

int get_brute(int pos) {
  pos = 2 * pos;
  int sol = -1, ans = 0;
  assert(0 <= pos && pos < 2 * n);
  ord[pos] = my_rank;
  for (int i = 0; i < pos; i++) {
    ord[i] = init_ord[i];
  }
  for (int i = pos + 1; i < 2 * n; i++) {
    ord[i] = init_ord[i - 1];
  }
  if (wannap) print();
  for (int j = 1; j <= r; j++) {
    ans += simulate_step_for_get_brute();
    if (wannap) print();
  }
  for (int i = 0; i < 2 * n; i++) {
    if (ord[i] == my_rank) {
      sol = i;
    }
  }
  if (wannap) cout << "= " << sol << "\n";
  assert(sol != -1);
  return sol / 2 - ans * n;
}

int get(int x) {
  if (thesol[x] != INF) {
    return thesol[x];
  }
  return thesol[x] = get_brute(x);
}

int rep(int x) {
  x %= n;
  if (x < 0) x += n;
  return x;
}


int mn = (int) 1e9;
int best = -1;

void upd(int i) {
  int x = get(i);
  int y = rep(x);
  if (y < mn) {
    mn = y;
    best = i;
  } else {
    if (y == mn) {
      best = max(best, i);
    }
  }
}

signed main() {
  ios::sync_with_stdio(0); cin.tie(0);

  //freopen ("input", "r", stdin);

  for (int i = 0; i < N; i++) {
    thesol[i] = INF;
  }

  wannap = 0;

  cin >> n >> r;
  r = 2 * n + r % n;
  cin >> my_rank;
  my_rank--;
  for (int i = 0; i < 2 * n - 1; i++) {
    cin >> init_ord[i];
    init_ord[i]--;
  }
  upd(0);
  upd(n - 1);
  {
    int low = 0, high = n - 1;
    while (low <= high) {
      int mid = (low + high) / 2;
      upd(mid);
      if (get(mid) == get(0)) {
        low = mid + 1;
      } else {
        high = mid - 1;
      }
    }
  }
  int L = get(0), R = get(n - 1);
  for (int j = L; j <= R; j++) {
    if (j % n) {
      continue;
    }
    int low = 0, high = n - 1, the_value = INF;
    while (low <= high) {
      int mid = (low + high) / 2;
      upd(mid);
      if (get(mid) >= j) {
        high = mid - 1;
        the_value = mid;
      } else {
        low = mid + 1;
      }
    }
    low = the_value;
    high = n - 1;
    while (low <= high) {
      int mid = (low + high) / 2;
      upd(mid);
      if (get(mid) == get(the_value)) {
        low = mid + 1;
      } else {
        high = mid - 1;
      }
    }
  }
  cout << best + 1 << "\n";
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 11260 KB Output is correct
2 Correct 990 ms 11376 KB Output is correct
3 Correct 10 ms 11276 KB Output is correct
4 Execution timed out 2071 ms 11340 KB Time limit exceeded
5 Correct 5 ms 11280 KB Output is correct
6 Correct 15 ms 11276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 11268 KB Output is correct
2 Correct 24 ms 11332 KB Output is correct
3 Correct 1322 ms 11372 KB Output is correct
4 Execution timed out 2082 ms 12236 KB Time limit exceeded
5 Execution timed out 2048 ms 22792 KB Time limit exceeded
6 Correct 22 ms 11196 KB Output is correct
7 Correct 152 ms 11340 KB Output is correct
8 Execution timed out 2093 ms 12236 KB Time limit exceeded
9 Execution timed out 2094 ms 12620 KB Time limit exceeded
10 Correct 394 ms 11340 KB Output is correct
11 Execution timed out 2082 ms 12620 KB Time limit exceeded
12 Execution timed out 2091 ms 11468 KB Time limit exceeded
13 Execution timed out 2053 ms 19552 KB Time limit exceeded
14 Execution timed out 2039 ms 11596 KB Time limit exceeded
15 Execution timed out 2084 ms 13380 KB Time limit exceeded
16 Correct 18 ms 11212 KB Output is correct
17 Correct 1081 ms 11360 KB Output is correct
18 Execution timed out 2088 ms 11340 KB Time limit exceeded
19 Execution timed out 2083 ms 11424 KB Time limit exceeded
20 Execution timed out 2085 ms 11596 KB Time limit exceeded
21 Execution timed out 2084 ms 12560 KB Time limit exceeded
22 Execution timed out 2044 ms 13260 KB Time limit exceeded
23 Execution timed out 2065 ms 23440 KB Time limit exceeded
24 Correct 17 ms 11268 KB Output is correct
25 Correct 392 ms 11360 KB Output is correct
26 Execution timed out 2074 ms 11596 KB Time limit exceeded
27 Execution timed out 2095 ms 12688 KB Time limit exceeded
28 Execution timed out 2052 ms 19780 KB Time limit exceeded
29 Correct 804 ms 11376 KB Output is correct
30 Execution timed out 2096 ms 11596 KB Time limit exceeded
31 Execution timed out 2075 ms 12600 KB Time limit exceeded
32 Execution timed out 2009 ms 23044 KB Time limit exceeded
33 Correct 19 ms 11212 KB Output is correct
34 Correct 16 ms 11212 KB Output is correct
35 Correct 1775 ms 11416 KB Output is correct
36 Execution timed out 2097 ms 11416 KB Time limit exceeded
37 Execution timed out 2086 ms 12364 KB Time limit exceeded
38 Execution timed out 2085 ms 12924 KB Time limit exceeded
39 Correct 16 ms 11212 KB Output is correct
40 Correct 403 ms 11356 KB Output is correct
41 Correct 1486 ms 11408 KB Output is correct
42 Execution timed out 2076 ms 11352 KB Time limit exceeded
43 Execution timed out 2019 ms 11584 KB Time limit exceeded
44 Execution timed out 2068 ms 11844 KB Time limit exceeded
45 Execution timed out 2067 ms 12568 KB Time limit exceeded
46 Execution timed out 2074 ms 12696 KB Time limit exceeded
47 Execution timed out 2023 ms 24812 KB Time limit exceeded