This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
import java.io.*;
import java.util.HashMap;
import java.util.TreeSet;
import java.util.TreeMap;
public class carnival {
static BufferedReader br;
static TreeMap<Integer, TreeSet<Integer>> costumeToPos;
static int i;
public static void main(String[] args) throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
costumeToPos = new TreeMap<>();
costumeToPos.put(1,new TreeSet<>());
costumeToPos.get(1).add(1);
for (i=2; i <= N; i++) {
System.out.print(i+" ");
for (int j = 1; j <= i; j++) {
System.out.print(j+" ");
}
System.out.println();
System.out.flush();
int feedback = Integer.parseInt(br.readLine());
if (feedback == costumeToPos.size()+1) {
costumeToPos.put(costumeToPos.lastKey()+1,new TreeSet<>());
costumeToPos.get(costumeToPos.lastKey()).add(i);
continue;
}
int a = 1, b = costumeToPos.lastKey()-1;
int ans = 0;
while (a <= b) {
int mid = (a+b+1)/2;
if (works(mid)) {
a = mid+1;
ans = mid;
}
else b = mid-1;
}
costumeToPos.get(ans+1).add(i);
}
int [] ans = new int [N+1];
for (int num : costumeToPos.keySet()) {
for (int n : costumeToPos.get(num)) {
ans[n] = num;
}
}
System.out.print(0+" ");
for (int i = 1; i <= N; i++) {
System.out.print(ans[i]+" ");
}
System.out.println();
System.out.flush();
}
static boolean works (int upTo) throws IOException {
System.out.print((upTo+1)+" ");
for (int num : costumeToPos.keySet()) {
if (num == upTo+1) break;
System.out.print(costumeToPos.get(num).first()+" ");
}
System.out.print(i+" ");
System.out.println();
System.out.flush();
int feedback = Integer.parseInt(br.readLine());
if (feedback == upTo+1) return true;
else return false;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |