# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
727549 | jnjwnwnw | Carnival (CEOI14_carnival) | Java | 443 ms | 13988 KiB |
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.util.*;
import java.io.*;
public class carnival {
public static void main(String[] args) throws IOException{
new carnival();
}
public carnival() throws IOException{
AIO s = new AIO();
int n = s.nextInt();
int numThatFormOwnSet = 1;
String asking = " 1 ";
boolean[] formOwnSet = new boolean[n];
formOwnSet[0] = true;
int prev = 1;
for(int i = 2; i <= n; i++){
s.println(i + asking + i);
int cur = s.nextInt();
formOwnSet[i-1] = (cur != prev);
numThatFormOwnSet += (cur!=prev) ? 1 : 0;
prev = cur;
asking = asking + i + " ";
}
ArrayList<Integer>[] sets = new ArrayList[numThatFormOwnSet];
int curSet = 0;
for(int i = 0; i < n; i++){
if (formOwnSet[i]){
sets[curSet] = new ArrayList<Integer>();
sets[curSet].add(i+1);
curSet++;
}
}
curSet = 0;
for(int i = 0; i <n; i++){
if (formOwnSet[i]){
curSet++;
} else{
for(int j = 0; j <= curSet; j++){
int setID = sets[j].get(0);
s.println("2 " + (i+1) + " " + setID);
if (s.nextInt() == 1){
sets[j].add(i+1);
break;
}
}
}
}
int[] result = new int[n+1];
for(int i = 0; i < numThatFormOwnSet; i++){
for(int j: sets[i]){
result[j] = i+1;
}
}
for(int i: result){
s.print(i + " ");
}
s.println();
}
}
/**
* fastish io specific to this problem, this is more for ease of typing and readability later on
*/
class AIO {
private StringTokenizer st;
private BufferedReader br;
public AIO(){
br = new BufferedReader(new InputStreamReader(System.in));
st = new StringTokenizer("");
}
public int nextInt() throws IOException{
if (!st.hasMoreTokens()){
st = new StringTokenizer(br.readLine());
}
return Integer.parseInt(st.nextToken());
}
public void println(int a){
System.out.println(a);
}
public void print(int a){
System.out.print(a);
}
public void println(String s){
System.out.println(s);
}
public void print(String s){
System.out.print(s);
}
public void println(){
System.out.println();
}
}
Compilation message (stderr)
# | 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... |