跳到正文

题解

[Yandex Cup 2024 Qual F] Zeroth Rome 题解

FFTotoro约 9 分钟
原文
文章信息与版本

文章信息

发布
2024年10月24日
收录
2025年12月12日
更新
2026年11月8日
篇幅
约 9 分钟
获赞
2

版本

  1. v1当前

前言

English version of this editorial is provided after the sample code.

题意简述

本题为交互题,你需要猜 tt 个 [0,2024][0,2024] 间的非负整数 x1,x2,…,xtx_1,x_2,\ldots,x_t,可以询问最多 1515 次,每次询问形如“给定一个大小为 N(1≤N≤2025)N(1\le N\le 2025) 的集合 SS 满足 SS 的每个元素都是 [0,2024][0,2024] 间的非负整数,交互库回答每个 xix_i 是否在该集合内”。

注意,你的询问需要一次性全部给出,之后交互库再进行回答。但是,对于每个 xix_i,交互库会在最多一个询问上给出错误的回复,而你需要准确地找出每个 xix_i。

题目解法

如果交互库不会给出错误的回复,那么解决问题是简单的:考虑二进制拆位,对于每一位,询问值域中所有该位为 11 的数构成的集合,如果目标数存在于该集合内,代表目标数的该位为 11,否则为 00。可以在 ⌈log⁡2V⌉\lceil\log_2V\rceil 次询问内完成。

如果交互库会在最多一个询问上给出错误的回复呢?考虑给 [0,2024][0,2024] 间每个整数一个独特的“编号”:设整数 ii 的编号为 aia_i,如果 ∀i≠j,popcount(ai⊕aj)≥3\forall i\ne j,\mathrm{popcount}(a_i\oplus a_j)\ge 3(其中 popcount\mathrm{popcount} 表示一个整数二进制下 11 的个数,⊕\oplus 表示按位异或),那么使用上面的询问方法询问这些编号,一定会得出正确的答案。具体确定答案的方法为,假设询问中得到了一个数 xx,那么只要找到唯一一个 aia_i 满足 popcount(ai⊕x)≤1\mathrm{popcount}(a_i\oplus x)\le 1 的 aia_i,ii 即为答案——可以证明这种编号构造方法能唯一确定答案。

现在的问题即为构造一组这样的 aia_i。我们发现可以从 00 开始给每个数分配编号,将所有不合法的编号插入一个 std::set,之后找之中没出现过的最小非负整数,将其作为编号分配给下一个整数。用上面的方法进行暴力枚举,发现存在一组构造使得 ai≤32330a_i\le 32330,可以在 1515 次询问内找到答案。

参考代码

C++
#include<bits/stdc++.h>
using namespace std;
const int N=2024;
int main(){
  ios::sync_with_stdio(false);
  vector<int> a; set<int> s;
  for(int i=0,x=0;i<=N;i++){
    a.emplace_back(x),s.emplace(x);
    for(int j=0;j<15;j++)
      for(int k=0;k<15;k++)
        s.emplace(x^(1<<j)^(j==k?0:(1<<k)));
    while(s.find(x)!=s.end())x++;
  }
  cerr<<a.back()<<endl;
  for(int i=0;i<=N;i++)
    for(int j=i+1;j<=N;j++)
      assert(__builtin_popcount(a[i]^a[j])>=3);
  int t; cin>>t;
  vector<vector<int> > v(15);
  cout<<"15\n";
  for(int i=0;i<15;i++){
    for(int j=0;j<=N;j++)
      if(a[j]>>i&1)
        v[i].emplace_back(j);
    for(int j:v[i])cout<<j<<' ';
    cout<<endl;
  }
  while(t--){
    int c=0,r=-1;
    for(int i=0;i<15;i++){
      int x; cin>>x;
      if(x)c|=1<<i;
    }
    for(int i=0;i<=N;i++)
      if(__builtin_popcount(a[i]^c)<=1)r=i;
    cout<<r<<endl;
  }
  return 0;
}

English Version

Translated by ChatGPT

Problem

This is an interactive problem, where you need to guess tt non-negative integers x1,x2,…,xtx_1, x_2, \ldots, x_t within the range [0,2024][0, 2024]. You can ask at most 1515 queries, and each query takes the form: “Given a set SS of size N(1≤N≤2025) N(1\le N\le 2025), where every element of SS is a non-negative integer within [0,2024][0, 2024], does the interactor return whether each xix_i is in this set or not?”

Note that you must provide all the queries at once, after which the interactor will respond. However, for each xix_i, the system will give incorrect feedback for at most one query, and your goal is to accurately identify each xix_i.

Solution

If the interactor never gave incorrect feedback, the solution would be straightforward: Consider the binary representation of each number. For each bit position, query a set consisting of all numbers in the range whose value in that bit position is 11. If the target number belongs to that set, then the corresponding bit is 11; otherwise, it is 00. This could be done in ⌈log⁡2V⌉\lceil \log_2 V \rceil queries.

However, with the interactor potentially giving an incorrect response for up to one query, we need to take a different approach. We assign a unique “code” to each integer in the range [0,2024][0, 2024]. Let the code for integer ii be aia_i, and ensure that for all i≠ji \neq j, we have popcount(ai⊕aj)≥3\mathrm{popcount}(a_i \oplus a_j) \geq 3, where popcount\mathrm{popcount} denotes the number of 11s in the binary representation of an integer, and ⊕\oplus represents the bitwise XOR operation. By querying these codes in the method described earlier, we can guarantee a correct result.

To determine the answer, suppose we obtain a result xx from the queries. We need to find the unique aia_i such that popcount(ai⊕x)≤1\mathrm{popcount}(a_i \oplus x) \leq 1, which will give us the correct ii. This method ensures that we can uniquely identify the correct answer.

The problem now becomes constructing such a set of aia_i. We can assign codes starting from 00, and for each code, insert invalid codes into a std::set. Then, for each subsequent number, assign the smallest non-negative integer that has not yet been used as a code. Using brute force exploration, we find that there exists a set of codes such that ai≤32330a_i \leq 32330, which allows us to find the answer within 1515 queries.

原文
存档评论1 条抓取于