답안 #547512

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
547512 2022-04-10T21:33:26 Z seungho9422 사육제 (CEOI14_carnival) C++17
100 / 100
8 ms 316 KB
#include <bits/stdc++.h>
using namespace std;
 
const int N = 160;
 
int ans[N];
 
int main() {
  int n, a, b, pos, mid, res, prv, now;
  vector <int> v;
  cin.tie(0)->sync_with_stdio(0);
  cin >> n;
  for(int i = 1; i <= n; i++) {
    cout << i << ' ';
    for(int j = 1; j <= i; j++) {
      cout << j << ' ';
    }
    cout << endl;

    cin >> now;
    if(now != prv) {
      v.push_back(i);
      ans[i] = now;
      prv = now;
      continue;
    }

    a = 0, b = v.size() - 1;
    while(a <= b) {
      mid = (a+b) / 2;

      cout << mid + 2 << ' ';
      for(int i = 0; i <= mid; i++) {
        cout << v[i] << ' ';
      }
      cout << i << endl;

      cin >> res;
      if(res < mid + 2) {
        b = mid - 1;
        pos = mid;
      }
      else {
        a = mid + 1;
      }
    }
    ans[i] = ans[v[pos]];
  }

  for(int i = 0; i <= n; i++) {
      cout << ans[i] << ' ';
  }
  cout << endl;
  return 0;
}

Compilation message

carnival.cpp: In function 'int main()':
carnival.cpp:21:5: warning: 'prv' may be used uninitialized in this function [-Wmaybe-uninitialized]
   21 |     if(now != prv) {
      |     ^~
carnival.cpp:47:23: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   47 |     ans[i] = ans[v[pos]];
      |                       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 208 KB Output is correct
2 Correct 7 ms 208 KB Output is correct
3 Correct 4 ms 208 KB Output is correct
4 Correct 3 ms 208 KB Output is correct
5 Correct 5 ms 208 KB Output is correct
6 Correct 4 ms 208 KB Output is correct
7 Correct 6 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 208 KB Output is correct
2 Correct 8 ms 208 KB Output is correct
3 Correct 4 ms 208 KB Output is correct
4 Correct 3 ms 208 KB Output is correct
5 Correct 6 ms 208 KB Output is correct
6 Correct 5 ms 208 KB Output is correct
7 Correct 6 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 208 KB Output is correct
2 Correct 5 ms 208 KB Output is correct
3 Correct 7 ms 208 KB Output is correct
4 Correct 3 ms 208 KB Output is correct
5 Correct 6 ms 208 KB Output is correct
6 Correct 6 ms 208 KB Output is correct
7 Correct 7 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 208 KB Output is correct
2 Correct 6 ms 208 KB Output is correct
3 Correct 5 ms 208 KB Output is correct
4 Correct 3 ms 316 KB Output is correct
5 Correct 8 ms 208 KB Output is correct
6 Correct 5 ms 208 KB Output is correct
7 Correct 4 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 208 KB Output is correct
2 Correct 7 ms 208 KB Output is correct
3 Correct 5 ms 208 KB Output is correct
4 Correct 5 ms 208 KB Output is correct
5 Correct 5 ms 208 KB Output is correct
6 Correct 5 ms 208 KB Output is correct
7 Correct 3 ms 208 KB Output is correct