답안 #944685

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
944685 2024-03-13T03:28:01 Z nguyentunglam 드문 곤충 (IOI22_insects) C++17
0 / 100
40 ms 672 KB
#include "insects.h"
#include<bits/stdc++.h>
using namespace std;

const int NN = 1e5 + 10;

bool in[NN];

int min_cardinality(int n) {
  int type = 0;
  for(int i = 0; i < n; i++) {
    move_inside(i);
    if (press_button() == 1) {
      ++type;
      in[i] = 1;
    }
    else move_outside(i);
  }

  int l = 1, r = n / type, ans = 1;
  int cur = 1;

  while (l < r) {
    int mid = (l + r) / 2 + 1;
    assert(cur <= mid);
    vector<int> last_added;
    int last = cur;
    for(int i = 0; i < n; i++) if (!in[i]) {
      in[i] = 1;
      move_inside(i);
      int nxt = press_button();
      if (nxt > mid) {
        move_outside(i);
        in[i] = 0;
      }
      else {
        cur = nxt;
        last_added.push_back(i);
      }
    }
    int total = 0;
    for(int i = 0; i < n; i++) total += in[i];
    if (cur == mid && mid * type == total) {
      l = mid;
    }
    else {
      r = mid - 1;
      for(auto &j : last_added) move_outside(j);
      cur = last;
    }
  }
  return l;
}

Compilation message

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:20:28: warning: unused variable 'ans' [-Wunused-variable]
   20 |   int l = 1, r = n / type, ans = 1;
      |                            ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 3 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 2 ms 344 KB Output is correct
9 Incorrect 3 ms 344 KB Wrong answer.
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 3 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 2 ms 344 KB Output is correct
9 Incorrect 3 ms 344 KB Wrong answer.
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 500 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 40 ms 444 KB Output is correct
8 Correct 10 ms 344 KB Output is correct
9 Correct 26 ms 592 KB Output is correct
10 Incorrect 38 ms 672 KB Wrong answer.
11 Halted 0 ms 0 KB -