Submission #941295

# Submission time Handle Problem Language Result Execution time Memory
941295 2024-03-08T13:12:20 Z nguyentunglam Toxic Gene (NOI23_toxic) C++17
38.4941 / 100
10 ms 668 KB
#include<bits/stdc++.h>
#include "toxic.h"
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
using namespace std;

const int N = 300 + 10, T = 8;
int order[N], ans[N];

char type[3] = {'R', 'S', 'T'};

mt19937 rng(1);

#ifdef ngu
int cnt_query;
char a[N], b[N];
int query_sample(vector<int> species) {
  cnt_query++;
  bool toxic = 0;
  for(int &j : species) toxic |= a[j] == 'T';
  int ret = 0;
  for(int &j : species) {
    if (a[j] == 'S') ret++;
    else if (a[j] == 'R' && !toxic) ret++;
  }
  return ret;
}

void answer_type(int x, char c) {
  b[x] = c;
}
#endif // ngu

void Search (vector<int> candidate) {
  if (candidate.size() == 1) {
    ans[candidate.back()] = 2;
    return;
  }
  vector<int> left, right;
  int mid = (int) candidate.size() / 2;
  for(int i = 0; i < mid; i++) left.push_back(candidate[i]);
  for(int i = mid; i < candidate.size(); i++) right.push_back(candidate[i]);
  if (!left.empty() && query_sample(left) == 0) Search(left);
  if (!right.empty() && query_sample(right) == 0) Search(right);
}

void determine_type (int n) {
  for(int i = 1; i <= n; i++) order[i] = i, ans[i] = 0;
  shuffle(order + 1, order + n + 1, rng);
  vector<vector<int> > double_check;
  for(int i = 1; i <= n; i += T) {
    vector<int> ask;
    int border = min(i + T - 1, n);
    for(int j = i; j <= border; j++) {
      int cnt = 1 << j - i;
      while (cnt--) ask.push_back(order[j]);
    }
    int result = query_sample(ask);
    int full = 1 << (border - i + 1); full--;
//    cout << result << " " << i << " " << full << endl;
//    for(int &j : ask) cout << j << " "; cout << "#\n";
    if (result == full) {
      vector<int> tmp;
      for(int j = i; j <= border; j++) tmp.push_back(order[j]);
      double_check.push_back(tmp);
    }
    else {
      vector<int> candidate;
      for(int j = i; j <= border; j++) {
        int delta = j - i;
        if (result >> delta & 1) ans[order[j]] = 1;
        else candidate.push_back(order[j]);
      }
      Search(candidate);
    }
  }

//  for(int i = 1; i <= n; i++) cout << ans[i] << " "; cout << endl;

  int toxic = 0;
  for(int i = 1; i <= n; i++) if (ans[i] == 2) toxic = i;
  for(auto &arr : double_check) {
    int cur = 1;
    vector<int> ask = {toxic};
    for(int j = 0; j < arr.size(); j++) {
      int cnt = 1 << j;
      while (cnt--) ask.push_back(arr[j]);
    }
    int result = query_sample(ask);
    for(int j = 0; j < arr.size(); j++) {
      if (result >> j & 1) ans[arr[j]] = 1;
    }
  }

  for(int i = 1; i <= n; i++) {
    answer_type(i, type[ans[i]]);
  }
}

#ifdef ngu
int main() {

  freopen ("task.inp", "r", stdin);
  freopen ("task.out", "w", stdout);

  int t; cin >> t;

  while (t--) {
    cnt_query = 0;
    int n; cin >> n;

    for(int i = 1; i <= n; i++) cin >> a[i];

    determine_type(n);

//    for(int i = 1; i <= n; i++) assert(a[i] == b[i]);

    for(int i = 1; i <= n; i++) cout << b[i] << " "; cout << endl;
    assert(cnt_query <= 600);

    cerr << cnt_query << endl;
  }
}
#endif // ngu

Compilation message

toxic.cpp: In function 'void Search(std::vector<int>)':
toxic.cpp:44:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |   for(int i = mid; i < candidate.size(); i++) right.push_back(candidate[i]);
      |                    ~~^~~~~~~~~~~~~~~~~~
toxic.cpp: In function 'void determine_type(int)':
toxic.cpp:57:24: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   57 |       int cnt = 1 << j - i;
      |                      ~~^~~
toxic.cpp:87:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |     for(int j = 0; j < arr.size(); j++) {
      |                    ~~^~~~~~~~~~~~
toxic.cpp:92:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |     for(int j = 0; j < arr.size(); j++) {
      |                    ~~^~~~~~~~~~~~
toxic.cpp:85:9: warning: unused variable 'cur' [-Wunused-variable]
   85 |     int cur = 1;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Partially correct 7 ms 516 KB Partially correct
3 Partially correct 9 ms 668 KB Partially correct
4 Partially correct 7 ms 344 KB Partially correct
5 Partially correct 7 ms 348 KB Partially correct
6 Partially correct 7 ms 348 KB Partially correct
7 Partially correct 7 ms 348 KB Partially correct
8 Partially correct 7 ms 348 KB Partially correct
9 Partially correct 7 ms 348 KB Partially correct
10 Partially correct 7 ms 348 KB Partially correct
11 Partially correct 6 ms 348 KB Partially correct
12 Partially correct 7 ms 348 KB Partially correct
13 Partially correct 7 ms 348 KB Partially correct
14 Partially correct 7 ms 348 KB Partially correct
15 Partially correct 7 ms 348 KB Partially correct
16 Partially correct 7 ms 344 KB Partially correct
17 Partially correct 7 ms 348 KB Partially correct
18 Partially correct 7 ms 348 KB Partially correct
19 Partially correct 7 ms 512 KB Partially correct
20 Partially correct 7 ms 348 KB Partially correct
21 Partially correct 6 ms 348 KB Partially correct
22 Correct 6 ms 348 KB Output is correct
23 Correct 6 ms 348 KB Output is correct
24 Partially correct 7 ms 348 KB Partially correct
25 Partially correct 7 ms 348 KB Partially correct
26 Partially correct 7 ms 348 KB Partially correct
27 Partially correct 7 ms 508 KB Partially correct
28 Partially correct 7 ms 344 KB Partially correct
29 Partially correct 10 ms 348 KB Partially correct
30 Partially correct 7 ms 348 KB Partially correct
31 Partially correct 9 ms 348 KB Partially correct
32 Partially correct 7 ms 348 KB Partially correct
33 Partially correct 7 ms 508 KB Partially correct
34 Partially correct 7 ms 344 KB Partially correct
35 Partially correct 7 ms 348 KB Partially correct
36 Partially correct 1 ms 348 KB Partially correct