답안 #625197

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
625197 2022-08-09T15:07:16 Z MilosMilutinovic Nizovi (COI14_nizovi) C++14
90 / 100
194 ms 428 KB
/**
 *    author:  wxhtzdy
 *    created: 09.08.2022 16:41:55
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);  
  int na, nb;
  cin >> na >> nb;
  auto Ask = [&](int i, int j) {
    cout << "cmp " << i << " " << j << endl;
    int x;
    cin >> x;
    return x;
  };            
  vector<int> at(na);
  for (int i = 0; i < na; i++) {
    int low = 1, high = nb;
    while (low <= high) {
      int mid = low + high >> 1;
      if (Ask(i + 1, na + mid) >= 0) {
        at[i] = mid;
        low = mid + 1;                                              
      } else {
        high = mid - 1;  
      }
    }
  }
  auto Reverse = [&](int pos, int la, int lb) {
    assert(la >= 1 && lb >= 1);
    cout << "reverse " << pos << " " << pos + la + lb - 1 << endl;
    if (la > 1) {
      cout << "reverse " << pos + lb << " " << pos + la + lb - 1 << endl;
    }
    if (lb > 1) {
      cout << "reverse " << pos << " " << pos + lb - 1 << endl;
    }
  };  
  int ptr = 0;
  for (int i = 0; i < na; i++) {
    if (ptr < at[i]) {
      Reverse(i + 1 + ptr, na - i, at[i] - ptr);
      ptr = at[i];           
    }            
  }
  cout << "end" << endl;                                                                       
  return 0;
}

Compilation message

nizovi.cpp: In function 'int main()':
nizovi.cpp:24:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   24 |       int mid = low + high >> 1;
      |                 ~~~~^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 3 ms 208 KB Output is correct
3 Correct 3 ms 208 KB Output is correct
4 Correct 18 ms 208 KB Output is correct
5 Correct 22 ms 300 KB Output is correct
6 Correct 32 ms 208 KB Output is correct
7 Correct 113 ms 300 KB Output is correct
8 Correct 168 ms 300 KB Output is correct
9 Correct 75 ms 300 KB Output is correct
10 Incorrect 194 ms 428 KB Total cost of reverse commands > 3 000 000