답안 #504103

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
504103 2022-01-09T20:07:13 Z 600Mihnea Archery (IOI09_archery) C++17
39 / 100
2000 ms 22192 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_smart(int x) {
  if (my_rank == 0) {
    return 0;
  }
  return get_brute(x);
}

int get(int x) {
  if (thesol[x] != INF) {
    return thesol[x];
  }
  thesol[x] = get_smart(x);
  return thesol[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 5 ms 11212 KB Output is correct
2 Correct 5 ms 11288 KB Output is correct
3 Correct 9 ms 11300 KB Output is correct
4 Execution timed out 2084 ms 11348 KB Time limit exceeded
5 Correct 6 ms 11212 KB Output is correct
6 Correct 15 ms 11308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 11212 KB Output is correct
2 Correct 23 ms 11212 KB Output is correct
3 Correct 1320 ms 11352 KB Output is correct
4 Execution timed out 2085 ms 12040 KB Time limit exceeded
5 Execution timed out 2097 ms 20596 KB Time limit exceeded
6 Correct 20 ms 11212 KB Output is correct
7 Correct 153 ms 11340 KB Output is correct
8 Execution timed out 2091 ms 12108 KB Time limit exceeded
9 Execution timed out 2096 ms 12364 KB Time limit exceeded
10 Correct 384 ms 11340 KB Output is correct
11 Execution timed out 2099 ms 12364 KB Time limit exceeded
12 Execution timed out 2060 ms 11344 KB Time limit exceeded
13 Execution timed out 2098 ms 17996 KB Time limit exceeded
14 Execution timed out 2082 ms 11468 KB Time limit exceeded
15 Execution timed out 2098 ms 13004 KB Time limit exceeded
16 Correct 19 ms 11212 KB Output is correct
17 Correct 1091 ms 11364 KB Output is correct
18 Execution timed out 2093 ms 11340 KB Time limit exceeded
19 Execution timed out 2088 ms 11468 KB Time limit exceeded
20 Execution timed out 2095 ms 11536 KB Time limit exceeded
21 Execution timed out 2098 ms 12364 KB Time limit exceeded
22 Execution timed out 2098 ms 12876 KB Time limit exceeded
23 Execution timed out 2099 ms 21064 KB Time limit exceeded
24 Correct 17 ms 11212 KB Output is correct
25 Correct 388 ms 11340 KB Output is correct
26 Execution timed out 2098 ms 11468 KB Time limit exceeded
27 Execution timed out 2099 ms 12364 KB Time limit exceeded
28 Execution timed out 2085 ms 18116 KB Time limit exceeded
29 Correct 821 ms 11360 KB Output is correct
30 Execution timed out 2091 ms 11468 KB Time limit exceeded
31 Execution timed out 2094 ms 12364 KB Time limit exceeded
32 Execution timed out 2081 ms 20740 KB Time limit exceeded
33 Correct 18 ms 11212 KB Output is correct
34 Correct 16 ms 11212 KB Output is correct
35 Correct 1770 ms 11392 KB Output is correct
36 Execution timed out 2096 ms 11340 KB Time limit exceeded
37 Execution timed out 2076 ms 12108 KB Time limit exceeded
38 Execution timed out 2094 ms 12620 KB Time limit exceeded
39 Correct 16 ms 11212 KB Output is correct
40 Correct 419 ms 11344 KB Output is correct
41 Correct 1524 ms 11388 KB Output is correct
42 Execution timed out 2096 ms 11340 KB Time limit exceeded
43 Execution timed out 2097 ms 11468 KB Time limit exceeded
44 Execution timed out 2097 ms 11724 KB Time limit exceeded
45 Execution timed out 2099 ms 12356 KB Time limit exceeded
46 Execution timed out 2097 ms 12484 KB Time limit exceeded
47 Execution timed out 2098 ms 22192 KB Time limit exceeded