답안 #886226

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
886226 2023-12-11T15:25:45 Z vjudge1 Toxic Gene (NOI23_toxic) C++17
45.7412 / 100
10 ms 516 KB
#include "toxic.h"
#include <bits/stdc++.h>

using namespace std;

template<typename A, typename B>
string to_string(pair<A, B>);
string to_string(string S) {
  return '"' + S + '"';
}
string to_string(const char* c) {
  return to_string(string(c));
}
string to_string(bool b) {
  return (b ? "true" : "false");
}
template<size_t T>
string to_string(bitset<T> bs) {
  return bs.to_string();
}
string to_string(vector<bool> v) {
  string res = "{";
  for (int i = 0; i < int(v.size()); ++i) {
    if (int(res.size()) > 1) {
      res += ", ";
    }
    res += to_string(v[i]);
  }
  return res + "}";
}
template<typename T>
string to_string(T v) {
  string res = "{";
  for (auto e : v) {
    if (int(res.size()) > 1) {
      res += ", ";
    }
    res += to_string(e);
  }
  return res + "}";
}
template<typename A, typename B>
string to_string(pair<A, B> p) {
  return '(' + to_string(p.first) + ", " + to_string(p.second) + ')';
}
void debug_out() {
  cerr << endl;
}
template<typename H, typename... T>
void debug_out(H head, T... tail) {
  cerr << "  " << to_string(head);
  debug_out(tail...);
}

#ifdef DEBUG 
  #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) 
#else 
  #define debug(...) void(37)
#endif

mt19937 rng(chrono::steady_clock().now().time_since_epoch().count());
int Rand(int l, int r) {
  return uniform_int_distribution<int>(l, r)(rng);
}

constexpr int B = 8;
void determine_type(int N){
  vector<int> shuf(N);
  iota(shuf.begin(), shuf.end(), 1);
  shuffle(shuf.begin(), shuf.end(), rng);
	debug(shuf);
  vector<bool> t(N);
  auto Q = [&](vector<int> ask) {
    vector<int> r;
    for (auto x : ask) {
      r.push_back(shuf[x]);
    }
    return query_sample(r);
  };
  auto Get = [&](int l, int r) {
    vector<int> ask(r - l + 1);
    iota(ask.begin(), ask.end(), l);
    return (Q(ask) != (r - l + 1));
  };
  auto Answer = [&](int x, char T) {
    answer_type(shuf[x], T);
  };
    
  for (int i = 0, r; i < N; i = r) {
    r = min(N, i + B);
    int low = i;
    while (low < r && Get(low, r - 1)) {
      int high = r - 1;
      while (low < high) {
        int mid = (low + high) >> 1;
        if (Get(low, mid)) {
          high = mid;
        } else {
          low = mid + 1;
        }
      }
      debug(low);
      t[low] = true;
      low += 1;
    }
  } 
  //debug(t);
  int toxic = int(max_element(t.begin(), t.end()) - t.begin());
  vector<int> non;
  for (int i = 0; i < N; ++i) {
    if (!t[i]) {
      non.push_back(i);
    }
  }
  int s = int(non.size());
  int jump = 8;
  vector<bool> strong(N);
  for (int i = 0, r; i < s; i = r) {
    r = min(s, i + jump);
    vector<int> ask = {toxic};
    for (int j = i, sz = 1; j < r; ++j, sz *= 2) {
      for (int k = 0; k < sz; ++k) {
        ask.push_back(non[j]);
      }
    }
    debug(ask);
    int res = Q(ask);
    debug(ask, res);
    for (int j = i, b = 0; j < r; ++j, ++b) {
      if ((res >> b) % 2) {
        strong[non[j]] = true;
      }
    }
  }
  for (int i = 0; i < N; ++i) {
    if (strong[i]) {
      Answer(i, 'S');
    } else if (t[i]) {
      Answer(i, 'T');
    } else {
      Answer(i, 'R');
    }
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Partially correct 7 ms 344 KB Partially correct
3 Partially correct 7 ms 344 KB Partially correct
4 Partially correct 9 ms 348 KB Partially correct
5 Partially correct 9 ms 348 KB Partially correct
6 Partially correct 7 ms 344 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 344 KB Partially correct
10 Partially correct 7 ms 344 KB Partially correct
11 Partially correct 7 ms 348 KB Partially correct
12 Partially correct 7 ms 512 KB Partially correct
13 Partially correct 7 ms 348 KB Partially correct
14 Partially correct 7 ms 348 KB Partially correct
15 Partially correct 10 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 512 KB Partially correct
19 Partially correct 7 ms 508 KB Partially correct
20 Partially correct 8 ms 512 KB Partially correct
21 Partially correct 8 ms 512 KB Partially correct
22 Partially correct 7 ms 344 KB Partially correct
23 Partially correct 6 ms 348 KB Partially correct
24 Partially correct 7 ms 508 KB Partially correct
25 Partially correct 7 ms 516 KB Partially correct
26 Partially correct 8 ms 348 KB Partially correct
27 Partially correct 7 ms 348 KB Partially correct
28 Partially correct 7 ms 348 KB Partially correct
29 Partially correct 8 ms 344 KB Partially correct
30 Partially correct 7 ms 348 KB Partially correct
31 Partially correct 8 ms 512 KB Partially correct
32 Partially correct 8 ms 344 KB Partially correct
33 Partially correct 8 ms 348 KB Partially correct
34 Partially correct 7 ms 348 KB Partially correct
35 Partially correct 7 ms 348 KB Partially correct
36 Partially correct 1 ms 348 KB Partially correct