#P93. Interactive Problem Test 2: And-Sum Conversion

Interactive Problem Test 2: And-Sum Conversion

Person in charge

Problem Description

There are nn non-negative integers a1,a2,,ana_1,a_2,\ldots,a_n, where each aia_i takes a value between 00 and 1515, inclusive.

Before interaction begins, you can obtain the value of nn.

You have 44 interaction opportunities. In each interaction, you can specify a non-negative integer xx (must be between 00 and 1515 inclusive), and you will receive the count of elements in a1,a2,,ana_1,a_2,\ldots,a_n that satisfy ai AND x=aia_i \text{ AND } x = a_i.

Using these 44 interactions, determine the value of a1+a2++ana_1 + a_2 + \ldots + a_n.

Interaction Protocol

This is an interactive problem.

The problem provides an additional header file "conversion.h" for interaction:

Function Description Constraints Call Limit
int start(); Returns the value of nn None Unlimited
int interact(int x); Returns the count of aia_i satisfying ai AND x=aia_i \text{ AND } x = a_i 0x150 \le x \le 15 must be satisfied 44
void stop(int s); Submit your answer ss (the sum) Must terminate interaction after calling 11

Use the following template:

#include <bits/stdc++.h>
#include "conversion.h"
using namespace std;
int main()
{
  int n = start(); // Get n
  int s = 0; // Answer
  // Perform interactions here using interact()
  stop(s); // Submit answer
  return 0;
}

Sample

For this sample, n=4n=4, {a4}={0,1,2,3}\{a_4\}=\{0,1,2,3\}, with correct answer 0+1+2+3=60+1+2+3=6.

The following interaction sequence would get AC:

Function Call Return Value Explanation
start(); 44 n=4n=4
interact(0); 11 Only a1a_1 satisfies
interact(1); 22 a1,a2a_1,a_2 satisfy
interact(2); 2 2 a1,a3a_1,a_3 satisfy
interact(3); 44 All aia_i satisfy
stop(6); // Correct answer 66 submitted

Constraints

1n106,0ai15.1 \le n \le 10^6,0 \le a_i \le 15.