제출 #330681

#제출 시각아이디문제언어결과실행 시간메모리
330681AlexLuchianovXoractive (IZhO19_xoractive)C++14
100 / 100
4 ms384 KiB
#include "interactive.h"
#include <vector>
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>

using namespace std;

std::vector<int> dif(std::vector<int> a, std::vector<int> b) {
  std::vector<int> v;
  int ptr = 0;
  for(int i = 0; i < a.size(); i++) {
    while(ptr < b.size() && b[ptr] < a[i])
      ptr++;
    if(ptr < b.size() && b[ptr] == a[i]) 
      ptr++;
    else
      v.push_back(a[i]);
  }
  return v;
}

std::vector<int> intersect(std::vector<int> a, std::vector<int> b) {
  std::vector<int> v;
  int ptr = 0;
  for(int i = 0; i < a.size(); i++) {
    while(ptr < b.size() && b[ptr] < a[i])
      ptr++;
    if(ptr < b.size() && b[ptr] == a[i]) {
      v.push_back(a[i]);
      ptr++;
    }
  }
  return v;
}

int const lgmax = 7;

vector<int> guess(int n) {
  int key = ask(n);
  std::vector<std::vector<int>> st(1 + lgmax);
  for(int i = 0; i < lgmax; i++) {
    std::vector<int> quer;
    for(int j = 1; j < n; j++)
      if(j & (1 << i))
        quer.push_back(j);
    if(0 < quer.size()) { 
      std::vector<int> without, with;
      without = get_pairwise_xor(quer);
      quer.push_back(n);
      with = get_pairwise_xor(quer);
      without.insert(without.begin(), 0);
      st[i] = dif(with, without);
    }
  }
  
  std::vector<int> ans;
  for(int i = 1;i < n; i++) {
    std::vector<int> sol;
    for(int j = 0; j < lgmax; j++) {
      if(sol.size() == 0 && (i & (1 << j)))
        sol = st[j];
    }
    
    for(int j = 0; j < lgmax; j++)
      if(0 < (i & (1 << j)))
        sol = intersect(sol, st[j]);
      else
        sol = dif(sol, st[j]);
    ans.push_back(sol[0] ^ key);
  }
  ans.push_back(key);
  return ans;
}

컴파일 시 표준 에러 (stderr) 메시지

Xoractive.cpp: In function 'std::vector<int> dif(std::vector<int>, std::vector<int>)':
Xoractive.cpp:13:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |   for(int i = 0; i < a.size(); i++) {
      |                  ~~^~~~~~~~~~
Xoractive.cpp:14:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |     while(ptr < b.size() && b[ptr] < a[i])
      |           ~~~~^~~~~~~~~~
Xoractive.cpp:16:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     if(ptr < b.size() && b[ptr] == a[i])
      |        ~~~~^~~~~~~~~~
Xoractive.cpp: In function 'std::vector<int> intersect(std::vector<int>, std::vector<int>)':
Xoractive.cpp:27:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |   for(int i = 0; i < a.size(); i++) {
      |                  ~~^~~~~~~~~~
Xoractive.cpp:28:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     while(ptr < b.size() && b[ptr] < a[i])
      |           ~~~~^~~~~~~~~~
Xoractive.cpp:30:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     if(ptr < b.size() && b[ptr] == a[i]) {
      |        ~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...