제출 #1339818

#제출 시각아이디문제언어결과실행 시간메모리
1339818SmuggingSpunToxic Gene 2 (NOI24_toxic)C++20
72 / 100
5 ms348 KiB
#include "toxic.h"
#include<bits/stdc++.h>
using namespace std;
const int LIM = 1e3;
void determine_type(int n){
  vector<char>ans(n, 'T');
  int low = 0, high = n - 2, pdif = -1, toxic;
  vector<int>query_value;
  while(low <= high){
    int mid = (low + high) >> 1;
    vector<int>p(mid + 1);
    iota(p.begin(), p.end(), 0);
    if(mid == 1){
      p.push_back(1);
    }
    vector<int>x = query_machine(p);
    if(x.back() == p.size()){
      low = mid + 1;
    }
    else{
      swap(query_value, x);
      high = (pdif = mid) - 1;
    }
  }
  if(pdif == -1){
    vector<int>p(n);
    iota(p.begin(), p.end(), 0);
    query_value = query_machine(p);
    if(query_value.size() == 1){
      ans[n - 1] = 'R';
    }
    else{
      fill(ans.begin(), ans.end(), 'R');
      ans[n - 1] = 'T';
    }
    answer_type(ans);
    return;
  }
  if(pdif > 1){
    toxic = query_value.size() == 1 ? 0 : pdif;
  }
  else{
    toxic = query_value.size() == 1 ? 1 : 0;
  }
  vector<int>p(n);
  iota(p.begin(), p.end(), 0);
  p.erase(p.begin() + toxic);
  while(!p.empty()){
    vector<int>ask = {toxic}, sample;
    for(int i = 2; !p.empty() && ask.size() + i < LIM; i += 2, ask.push_back(toxic)){
      int x = p.back();
      p.pop_back();
      sample.push_back(x);
      for(int j = 0; j < i; j++){
        ask.push_back(x);
      }
    }
    vector<int>delta = query_machine(ask);
    for(int i = int(delta.size()) - 1; i > 0; i--){
      delta[i] = delta[i - 1] - delta[i];
    }
    delta[0] = int(ask.size()) - delta[0];
    delta.push_back(0);
    for(int i = 0; i + 1 < delta.size(); i++){
      if(delta[i] != delta[i + 1]){
        ans[sample[i]] = 'R';
      }
    }
  }
  answer_type(ans);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...