exec_outcome
stringclasses
1 value
code_uid
stringlengths
32
32
file_name
stringclasses
111 values
prob_desc_created_at
stringlengths
10
10
prob_desc_description
stringlengths
63
3.8k
prob_desc_memory_limit
stringclasses
18 values
source_code
stringlengths
117
65.5k
lang_cluster
stringclasses
1 value
prob_desc_sample_inputs
stringlengths
2
802
prob_desc_time_limit
stringclasses
27 values
prob_desc_sample_outputs
stringlengths
2
796
prob_desc_notes
stringlengths
4
3k
lang
stringclasses
5 values
prob_desc_input_from
stringclasses
3 values
tags
listlengths
0
11
src_uid
stringlengths
32
32
prob_desc_input_spec
stringlengths
28
2.37k
difficulty
int64
-1
3.5k
prob_desc_output_spec
stringlengths
17
1.47k
prob_desc_output_to
stringclasses
3 values
hidden_unit_tests
stringclasses
1 value
PASSED
58b57e1f23e68298c8d008daf5e865eb
train_002.jsonl
1590935700
This is an interactive problem.Ayush devised a new scheme to set the password of his lock. The lock has $$$k$$$ slots where each slot can hold integers from $$$1$$$ to $$$n$$$. The password $$$P$$$ is a sequence of $$$k$$$ integers each in the range $$$[1, n]$$$, $$$i$$$-th element of which goes into the $$$i$$$-th slot of the lock.To set the password of his lock, Ayush comes up with an array $$$A$$$ of $$$n$$$ integers each in the range $$$[1, n]$$$ (not necessarily distinct). He then picks $$$k$$$ non-empty mutually disjoint subsets of indices $$$S_1, S_2, ..., S_k$$$ $$$(S_i \underset{i \neq j} \cap S_j = \emptyset)$$$ and sets his password as $$$P_i = \max\limits_{j \notin S_i} A[j]$$$. In other words, the $$$i$$$-th integer in the password is equal to the maximum over all elements of $$$A$$$ whose indices do not belong to $$$S_i$$$.You are given the subsets of indices chosen by Ayush. You need to guess the password. To make a query, you can choose a non-empty subset of indices of the array and ask the maximum of all elements of the array with index in this subset. You can ask no more than 12 queries.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); int N=s.nextInt(); for(int i=0;i<N;i++){ System.out.println(help(s)); s.nextLine(); String ans=s.nextLine(); } } static boolean[] visited; static int size1; public static String help(Scanner s){ int n=s.nextInt(),k=s.nextInt(); visited=new boolean[n]; size1=n; List<Integer>[] rem=new List[k]; for(int i=0;i<k;i++){ rem[i]=new ArrayList<>(); int isize=s.nextInt(); for(int j=0;j<isize;j++){ int get=s.nextInt(); rem[i].add(get); visited[get-1]=true; size1--; } } if(k==1){ System.out.println(help(rem,0)); System.out.flush(); int ans=s.nextInt(); return "! "+ans; } int start=0,end=k-1; System.out.println(help(rem,start,end)); System.out.flush(); int max=s.nextInt(); while (start!=end){ int mid=(start+end)/2; System.out.println(help(rem,start,mid)); System.out.flush(); if(s.nextInt()==max){ end=mid; }else start=mid+1; } //System.out.println(start); System.out.println(help(rem,start)); System.out.flush(); int result=s.nextInt(); return help(k,max,start,result); } public static String help(List<Integer>[] rem,int start,int end){ StringBuilder ans=new StringBuilder("?"); int size=size1; for(int i=start;i<=end;i++) size+=rem[i].size(); ans.append(' '); ans.append(size); for(int i=start;i<=end;i++){ for(int j:rem[i]){ ans.append(' '); ans.append(j); } } for (int i=0;i<visited.length;i++){ if(!visited[i]){ ans.append(' '); ans.append(i+1); } } return ans.toString(); } public static String help(List<Integer>[] rem,int sub){ StringBuilder ans=new StringBuilder("?"); int size=size1; for(int i=0;i<rem.length;i++) { if (i == sub) continue; size+=rem[i].size(); } ans.append(' '); ans.append(size); for(int i=0;i<rem.length;i++){ if(i==sub)continue; for(int j:rem[i]){ ans.append(' '); ans.append(j); } } for (int i=0;i<visited.length;i++){ if(!visited[i]){ ans.append(' '); ans.append(i+1); } } return ans.toString(); } public static String help(int k,int max,int index,int result){ StringBuilder ans=new StringBuilder("!"); for(int i=0;i<k;i++){ if(i==index) { ans.append(' '); ans.append(result); }else { ans.append(' '); ans.append(max); } } return ans.toString(); } }
Java
["1\n4 2\n2 1 3\n2 2 4\n\n1\n\n2\n\n3\n\n4\n\nCorrect"]
2 seconds
["? 1 1\n\n? 1 2\n\n? 1 3\n\n? 1 4\n\n! 4 3"]
NoteThe array $$$A$$$ in the example is $$$[1, 2, 3, 4]$$$. The length of the password is $$$2$$$. The first element of the password is the maximum of $$$A[2]$$$, $$$A[4]$$$ (since the first subset contains indices $$$1$$$ and $$$3$$$, we take maximum over remaining indices). The second element of the password is the maximum of $$$A[1]$$$, $$$A[3]$$$ (since the second subset contains indices $$$2$$$, $$$4$$$).Do not forget to read the string "Correct" / "Incorrect" after guessing the password.
Java 11
standard input
[ "math", "binary search", "implementation", "interactive" ]
b0bce8524eb69b695edc1394ff86b913
The first line of the input contains a single integer $$$t$$$ $$$(1 \leq t \leq 10)$$$ — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ $$$(2 \leq n \leq 1000, 1 \leq k \leq n)$$$ — the size of the array and the number of subsets. $$$k$$$ lines follow. The $$$i$$$-th line contains an integer $$$c$$$ $$$(1 \leq c \lt n)$$$ — the size of subset $$$S_i$$$, followed by $$$c$$$ distinct integers in the range $$$[1, n]$$$  — indices from the subset $$$S_i$$$. It is guaranteed that the intersection of any two subsets is empty.
2,100
null
standard output
PASSED
b47c9a2d9b5398811685e6d4272b5cfb
train_002.jsonl
1590935700
This is an interactive problem.Ayush devised a new scheme to set the password of his lock. The lock has $$$k$$$ slots where each slot can hold integers from $$$1$$$ to $$$n$$$. The password $$$P$$$ is a sequence of $$$k$$$ integers each in the range $$$[1, n]$$$, $$$i$$$-th element of which goes into the $$$i$$$-th slot of the lock.To set the password of his lock, Ayush comes up with an array $$$A$$$ of $$$n$$$ integers each in the range $$$[1, n]$$$ (not necessarily distinct). He then picks $$$k$$$ non-empty mutually disjoint subsets of indices $$$S_1, S_2, ..., S_k$$$ $$$(S_i \underset{i \neq j} \cap S_j = \emptyset)$$$ and sets his password as $$$P_i = \max\limits_{j \notin S_i} A[j]$$$. In other words, the $$$i$$$-th integer in the password is equal to the maximum over all elements of $$$A$$$ whose indices do not belong to $$$S_i$$$.You are given the subsets of indices chosen by Ayush. You need to guess the password. To make a query, you can choose a non-empty subset of indices of the array and ask the maximum of all elements of the array with index in this subset. You can ask no more than 12 queries.
256 megabytes
/** * * @author tstulemeijer */ import java.io.OutputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) throws Exception { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); try(PrintWriter out = new PrintWriter(outputStream)){ TaskD solver = new TaskD(); solver.solve(in, out); } } static class TaskD { void rangeQuery (PrintWriter out, int lowerBound, int upperBound){ out.print("? " + Integer.toString(upperBound+1-lowerBound)); for(int i = lowerBound; i <= upperBound; ++i) out.print(" " + Integer.toString(i)); out.println(); out.flush(); } void solve(InputReader in, PrintWriter out) { int t = in.nextInt(); while(t-- != 0){ int n = in.nextInt(); int k = in.nextInt(); List<Set<Integer>> setIndices = new ArrayList<>(k); for(int i = 0; i != k; ++i){ setIndices.add(new HashSet<>()); int c = in.nextInt(); for(int j = 0; j != c; ++j) setIndices.get(i).add(in.nextInt()); } int lowerBound = 1; int upperBound = n; rangeQuery(out, lowerBound, upperBound); int max = in.nextInt(); while(lowerBound != upperBound){ rangeQuery(out, lowerBound, lowerBound-1 + (upperBound+1-lowerBound)/2); if(max == in.nextInt()) upperBound = lowerBound-1 + (upperBound+1-lowerBound)/2; else lowerBound = lowerBound + (upperBound+1-lowerBound)/2; } int indexOfMax = 0; Set<Integer> setMissingMax = new HashSet<>(); for(var s : setIndices){ if(s.contains(lowerBound)){ indexOfMax = setIndices.indexOf(s) + 1; setMissingMax = s; break; } } out.print("? " + Integer.toString(n-setMissingMax.size())); for(int i = 1; i <= n; ++i){ if(!setMissingMax.contains(i)) out.print(" " + Integer.toString(i)); } out.println(); out.flush(); int special = in.nextInt(); out.print("!"); for(int i = 0; i != k; ++i){ if(i+1 != indexOfMax) out.print(" " + Integer.toString(max)); else out.print(" " + Integer.toString(special)); } out.println(); out.flush(); if ("Incorrect".equals(in.next())) return; } } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public long nextLong() { return Long.parseLong(next()); } public int nextInt() { return Integer.parseInt(next()); } } }
Java
["1\n4 2\n2 1 3\n2 2 4\n\n1\n\n2\n\n3\n\n4\n\nCorrect"]
2 seconds
["? 1 1\n\n? 1 2\n\n? 1 3\n\n? 1 4\n\n! 4 3"]
NoteThe array $$$A$$$ in the example is $$$[1, 2, 3, 4]$$$. The length of the password is $$$2$$$. The first element of the password is the maximum of $$$A[2]$$$, $$$A[4]$$$ (since the first subset contains indices $$$1$$$ and $$$3$$$, we take maximum over remaining indices). The second element of the password is the maximum of $$$A[1]$$$, $$$A[3]$$$ (since the second subset contains indices $$$2$$$, $$$4$$$).Do not forget to read the string "Correct" / "Incorrect" after guessing the password.
Java 11
standard input
[ "math", "binary search", "implementation", "interactive" ]
b0bce8524eb69b695edc1394ff86b913
The first line of the input contains a single integer $$$t$$$ $$$(1 \leq t \leq 10)$$$ — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ $$$(2 \leq n \leq 1000, 1 \leq k \leq n)$$$ — the size of the array and the number of subsets. $$$k$$$ lines follow. The $$$i$$$-th line contains an integer $$$c$$$ $$$(1 \leq c \lt n)$$$ — the size of subset $$$S_i$$$, followed by $$$c$$$ distinct integers in the range $$$[1, n]$$$  — indices from the subset $$$S_i$$$. It is guaranteed that the intersection of any two subsets is empty.
2,100
null
standard output
PASSED
0fdabd2968457ac7afc38b7c30b3b0c2
train_002.jsonl
1590935700
This is an interactive problem.Ayush devised a new scheme to set the password of his lock. The lock has $$$k$$$ slots where each slot can hold integers from $$$1$$$ to $$$n$$$. The password $$$P$$$ is a sequence of $$$k$$$ integers each in the range $$$[1, n]$$$, $$$i$$$-th element of which goes into the $$$i$$$-th slot of the lock.To set the password of his lock, Ayush comes up with an array $$$A$$$ of $$$n$$$ integers each in the range $$$[1, n]$$$ (not necessarily distinct). He then picks $$$k$$$ non-empty mutually disjoint subsets of indices $$$S_1, S_2, ..., S_k$$$ $$$(S_i \underset{i \neq j} \cap S_j = \emptyset)$$$ and sets his password as $$$P_i = \max\limits_{j \notin S_i} A[j]$$$. In other words, the $$$i$$$-th integer in the password is equal to the maximum over all elements of $$$A$$$ whose indices do not belong to $$$S_i$$$.You are given the subsets of indices chosen by Ayush. You need to guess the password. To make a query, you can choose a non-empty subset of indices of the array and ask the maximum of all elements of the array with index in this subset. You can ask no more than 12 queries.
256 megabytes
import java.math.*; import java.io.*; import java.util.*; import java.awt.*; public class Main implements Runnable { @Override public void run() { try { new Solver().solve(); System.exit(0); } catch (Exception | Error e) { e.printStackTrace(); System.exit(1); } } public static void main(String[] args) throws Exception { //new Thread(null, new Main(), "Solver", 1l << 25).start(); new Solver().solve(); } } class Solver { final Helper hp; final int MAXN = 1000_006; final long MOD = (long) 1e9 + 7; final Timer timer; final TimerTask task; Solver() { hp = new Helper(MOD, MAXN); hp.initIO(System.in, System.out); timer = new Timer(); task = new TimerTask() { @Override public void run() { try { hp.flush(); System.exit(0); } catch (Exception e) { } } }; //timer.schedule(task, 4700); } void solve() throws Exception { int tc = TESTCASES ? hp.nextInt() : 1; for (int tce = 1; tce <= tc; ++tce) solve(tce); timer.cancel(); hp.flush(); } boolean TESTCASES = true; int N, K; BitSet[] idx; void solve(int tc) throws Exception { int i, j, k; map = new HashMap<>(); N = hp.nextInt(); K = hp.nextInt(); idx = new BitSet[K]; for (i = 0; i < K; ++i) { int C = hp.nextInt(); idx[i] = new BitSet(); for (j = 0; j < C; ++j) idx[i].set(hp.nextInt()); } BitSet all = new BitSet(); all.set(1, N + 1); maxEle = query(all); ans = new int[K]; solve(0, K - 1); System.out.print("! "); for (int itr : ans) System.out.print(itr + " "); System.out.println(); if (hp.next().charAt(0) != 'C') System.exit(0); } int maxEle; int[] ans; void solve(int l, int r) throws Exception { int mid = l + r >> 1; System.err.println(Arrays.toString(ans)); if (l < mid) { BitSet temp = new BitSet(); for (int i = l; i <= mid; ++i) { temp.or(idx[i]); } int max = query(temp); if (max == maxEle) { for (int i = mid + 1; i <= r; ++i) { ans[i] = maxEle; } solve(l, mid); } else { for (int i = l; i <= mid; ++i) { ans[i] = maxEle; } solve(mid + 1, r); } } else if (l == r) { BitSet bs = new BitSet(); bs.set(1, N + 1); bs.xor(idx[l]); ans[l] = query(bs); } else { BitSet bs = new BitSet(); bs.or(idx[l]); int temp = query(bs); if (temp == maxEle) { ans[r] = maxEle; solve(l, l); } else { ans[l] = maxEle; solve(r, r); } } } HashMap<String, Integer> map; int query(BitSet bs) throws Exception { String hash = bs.toString(); System.err.println(hash); if (map.containsKey(hash)) return map.get(hash); System.out.print("? " + bs.cardinality() + " "); for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) { System.out.print(i + " "); } System.out.println(); int res = hp.nextInt(); map.put(hash, res); return res; } } class Helper { final long MOD; final int MAXN; final Random rnd; public Helper(long mod, int maxn) { MOD = mod; MAXN = maxn; rnd = new Random(); } public static int[] sieve; public static ArrayList<Integer> primes; public void setSieve() { primes = new ArrayList<>(); sieve = new int[MAXN]; int i, j; for (i = 2; i < MAXN; ++i) if (sieve[i] == 0) { primes.add(i); for (j = i; j < MAXN; j += i) { sieve[j] = i; } } } public static long[] factorial; public void setFactorial() { factorial = new long[MAXN]; factorial[0] = 1; for (int i = 1; i < MAXN; ++i) factorial[i] = factorial[i - 1] * i % MOD; } public long getFactorial(int n) { if (factorial == null) setFactorial(); return factorial[n]; } public long ncr(int n, int r) { if (r > n) return 0; if (factorial == null) setFactorial(); long numerator = factorial[n]; long denominator = factorial[r] * factorial[n - r] % MOD; return numerator * pow(denominator, MOD - 2, MOD) % MOD; } public long[] getLongArray(int size) throws Exception { long[] ar = new long[size]; for (int i = 0; i < size; ++i) ar[i] = nextLong(); return ar; } public int[] getIntArray(int size) throws Exception { int[] ar = new int[size]; for (int i = 0; i < size; ++i) ar[i] = nextInt(); return ar; } public String[] getStringArray(int size) throws Exception { String[] ar = new String[size]; for (int i = 0; i < size; ++i) ar[i] = next(); return ar; } public String joinElements(long... ar) { StringBuilder sb = new StringBuilder(); for (long itr : ar) sb.append(itr).append(" "); return sb.toString().trim(); } public String joinElements(int... ar) { StringBuilder sb = new StringBuilder(); for (int itr : ar) sb.append(itr).append(" "); return sb.toString().trim(); } public String joinElements(String... ar) { StringBuilder sb = new StringBuilder(); for (String itr : ar) sb.append(itr).append(" "); return sb.toString().trim(); } public String joinElements(Object... ar) { StringBuilder sb = new StringBuilder(); for (Object itr : ar) sb.append(itr).append(" "); return sb.toString().trim(); } public long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); } public int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } public long max(long... ar) { long ret = ar[0]; for (long itr : ar) ret = Math.max(ret, itr); return ret; } public int max(int... ar) { int ret = ar[0]; for (int itr : ar) ret = Math.max(ret, itr); return ret; } public long min(long... ar) { long ret = ar[0]; for (long itr : ar) ret = Math.min(ret, itr); return ret; } public int min(int... ar) { int ret = ar[0]; for (int itr : ar) ret = Math.min(ret, itr); return ret; } public long sum(long... ar) { long sum = 0; for (long itr : ar) sum += itr; return sum; } public long sum(int... ar) { long sum = 0; for (int itr : ar) sum += itr; return sum; } public void shuffle(int[] ar) { int r; for (int i = 0; i < ar.length; ++i) { r = rnd.nextInt(ar.length); if (r != i) { ar[i] ^= ar[r]; ar[r] ^= ar[i]; ar[i] ^= ar[r]; } } } public void shuffle(long[] ar) { int r; for (int i = 0; i < ar.length; ++i) { r = rnd.nextInt(ar.length); if (r != i) { ar[i] ^= ar[r]; ar[r] ^= ar[i]; ar[i] ^= ar[r]; } } } public void reverse(int[] ar) { int r; for (int i = 0; i < ar.length; ++i) { r = ar.length - 1 - i; if (r > i) { ar[i] ^= ar[r]; ar[r] ^= ar[i]; ar[i] ^= ar[r]; } } } public void reverse(long[] ar) { int r; for (int i = 0; i < ar.length; ++i) { r = ar.length - 1 - i; if (r > i) { ar[i] ^= ar[r]; ar[r] ^= ar[i]; ar[i] ^= ar[r]; } } } public long pow(long base, long exp, long MOD) { base %= MOD; long ret = 1; while (exp > 0) { if ((exp & 1) == 1) ret = ret * base % MOD; base = base * base % MOD; exp >>= 1; } return ret; } static final int BUFSIZE = 1 << 20; static byte[] buf; static int index, total; static InputStream in; static BufferedWriter bw; public void initIO(InputStream is, OutputStream os) { try { in = is; bw = new BufferedWriter(new OutputStreamWriter(os)); buf = new byte[BUFSIZE]; } catch (Exception e) { } } public void initIO(String inputFile, String outputFile) { try { in = new FileInputStream(inputFile); bw = new BufferedWriter(new OutputStreamWriter( new FileOutputStream(outputFile))); buf = new byte[BUFSIZE]; } catch (Exception e) { } } private int scan() throws Exception { if (index >= total) { index = 0; total = in.read(buf); if (total <= 0) return -1; } return buf[index++]; } public String next() throws Exception { int c; for (c = scan(); c <= 32; c = scan()) ; StringBuilder sb = new StringBuilder(); for (; c > 32; c = scan()) sb.append((char) c); return sb.toString(); } public int nextInt() throws Exception { int c, val = 0; for (c = scan(); c <= 32; c = scan()) ; boolean neg = c == '-'; if (c == '-' || c == '+') c = scan(); for (; c >= '0' && c <= '9'; c = scan()) val = (val << 3) + (val << 1) + (c & 15); return neg ? -val : val; } public long nextLong() throws Exception { int c; long val = 0; for (c = scan(); c <= 32; c = scan()) ; boolean neg = c == '-'; if (c == '-' || c == '+') c = scan(); for (; c >= '0' && c <= '9'; c = scan()) val = (val << 3) + (val << 1) + (c & 15); return neg ? -val : val; } public void print(Object a) throws Exception { bw.write(a.toString()); } public void printsp(Object a) throws Exception { print(a); print(" "); } public void println() throws Exception { bw.write("\n"); } public void println(Object a) throws Exception { print(a); println(); } public void flush() throws Exception { bw.flush(); } }
Java
["1\n4 2\n2 1 3\n2 2 4\n\n1\n\n2\n\n3\n\n4\n\nCorrect"]
2 seconds
["? 1 1\n\n? 1 2\n\n? 1 3\n\n? 1 4\n\n! 4 3"]
NoteThe array $$$A$$$ in the example is $$$[1, 2, 3, 4]$$$. The length of the password is $$$2$$$. The first element of the password is the maximum of $$$A[2]$$$, $$$A[4]$$$ (since the first subset contains indices $$$1$$$ and $$$3$$$, we take maximum over remaining indices). The second element of the password is the maximum of $$$A[1]$$$, $$$A[3]$$$ (since the second subset contains indices $$$2$$$, $$$4$$$).Do not forget to read the string "Correct" / "Incorrect" after guessing the password.
Java 11
standard input
[ "math", "binary search", "implementation", "interactive" ]
b0bce8524eb69b695edc1394ff86b913
The first line of the input contains a single integer $$$t$$$ $$$(1 \leq t \leq 10)$$$ — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ $$$(2 \leq n \leq 1000, 1 \leq k \leq n)$$$ — the size of the array and the number of subsets. $$$k$$$ lines follow. The $$$i$$$-th line contains an integer $$$c$$$ $$$(1 \leq c \lt n)$$$ — the size of subset $$$S_i$$$, followed by $$$c$$$ distinct integers in the range $$$[1, n]$$$  — indices from the subset $$$S_i$$$. It is guaranteed that the intersection of any two subsets is empty.
2,100
null
standard output
PASSED
4c9433c07bad98d142bcab6ffe4dde61
train_002.jsonl
1590935700
This is an interactive problem.Ayush devised a new scheme to set the password of his lock. The lock has $$$k$$$ slots where each slot can hold integers from $$$1$$$ to $$$n$$$. The password $$$P$$$ is a sequence of $$$k$$$ integers each in the range $$$[1, n]$$$, $$$i$$$-th element of which goes into the $$$i$$$-th slot of the lock.To set the password of his lock, Ayush comes up with an array $$$A$$$ of $$$n$$$ integers each in the range $$$[1, n]$$$ (not necessarily distinct). He then picks $$$k$$$ non-empty mutually disjoint subsets of indices $$$S_1, S_2, ..., S_k$$$ $$$(S_i \underset{i \neq j} \cap S_j = \emptyset)$$$ and sets his password as $$$P_i = \max\limits_{j \notin S_i} A[j]$$$. In other words, the $$$i$$$-th integer in the password is equal to the maximum over all elements of $$$A$$$ whose indices do not belong to $$$S_i$$$.You are given the subsets of indices chosen by Ayush. You need to guess the password. To make a query, you can choose a non-empty subset of indices of the array and ask the maximum of all elements of the array with index in this subset. You can ask no more than 12 queries.
256 megabytes
import java.math.*; import java.io.*; import java.util.*; import java.awt.*; public class Main implements Runnable { @Override public void run() { try { new Solver().solve(); System.exit(0); } catch (Exception | Error e) { e.printStackTrace(); System.exit(1); } } public static void main(String[] args) throws Exception { //new Thread(null, new Main(), "Solver", 1l << 25).start(); new Solver().solve(); } } class Solver { final Helper hp; final int MAXN = 1000_006; final long MOD = (long) 1e9 + 7; final Timer timer; final TimerTask task; Solver() { hp = new Helper(MOD, MAXN); hp.initIO(System.in, System.out); timer = new Timer(); task = new TimerTask() { @Override public void run() { try { hp.flush(); System.exit(0); } catch (Exception e) { } } }; //timer.schedule(task, 4700); } void solve() throws Exception { int tc = TESTCASES ? hp.nextInt() : 1; for (int tce = 1; tce <= tc; ++tce) solve(tce); timer.cancel(); hp.flush(); } boolean TESTCASES = true; int N, K; BitSet[] idx; void solve(int tc) throws Exception { int i, j, k; map = new HashMap<>(); N = hp.nextInt(); K = hp.nextInt(); idx = new BitSet[K]; for (i = 0; i < K; ++i) { int C = hp.nextInt(); idx[i] = new BitSet(); for (j = 0; j < C; ++j) idx[i].set(hp.nextInt()); } BitSet all = new BitSet(); all.set(1, N + 1); maxEle = query(all); ans = new int[K]; solve(0, K - 1); System.out.print("! "); for (int itr : ans) System.out.print(itr + " "); System.out.println(); if (hp.next().charAt(0) != 'C') System.exit(0); } int maxEle; int[] ans; void solve(int l, int r) throws Exception { int mid = l + r >> 1; if (l < mid) { BitSet temp = new BitSet(); for (int i = l; i <= mid; ++i) { temp.or(idx[i]); } int max = query(temp); if (max == maxEle) { for (int i = mid + 1; i <= r; ++i) { ans[i] = maxEle; } solve(l, mid); } else { for (int i = l; i <= mid; ++i) { ans[i] = maxEle; } solve(mid + 1, r); } } else if (l == r) { BitSet bs = new BitSet(); bs.set(1, N + 1); bs.xor(idx[l]); ans[l] = query(bs); } else { BitSet bs = new BitSet(); bs.or(idx[l]); int temp = query(bs); if (temp == maxEle) { ans[r] = maxEle; solve(l, l); } else { ans[l] = maxEle; solve(r, r); } } } HashMap<String, Integer> map; int query(BitSet bs) throws Exception { String hash = bs.toString(); if (map.containsKey(hash)) return map.get(hash); System.out.print("? " + bs.cardinality() + " "); for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) { System.out.print(i + " "); } System.out.println(); int res = hp.nextInt(); map.put(hash, res); return res; } } class Helper { final long MOD; final int MAXN; final Random rnd; public Helper(long mod, int maxn) { MOD = mod; MAXN = maxn; rnd = new Random(); } public static int[] sieve; public static ArrayList<Integer> primes; public void setSieve() { primes = new ArrayList<>(); sieve = new int[MAXN]; int i, j; for (i = 2; i < MAXN; ++i) if (sieve[i] == 0) { primes.add(i); for (j = i; j < MAXN; j += i) { sieve[j] = i; } } } public static long[] factorial; public void setFactorial() { factorial = new long[MAXN]; factorial[0] = 1; for (int i = 1; i < MAXN; ++i) factorial[i] = factorial[i - 1] * i % MOD; } public long getFactorial(int n) { if (factorial == null) setFactorial(); return factorial[n]; } public long ncr(int n, int r) { if (r > n) return 0; if (factorial == null) setFactorial(); long numerator = factorial[n]; long denominator = factorial[r] * factorial[n - r] % MOD; return numerator * pow(denominator, MOD - 2, MOD) % MOD; } public long[] getLongArray(int size) throws Exception { long[] ar = new long[size]; for (int i = 0; i < size; ++i) ar[i] = nextLong(); return ar; } public int[] getIntArray(int size) throws Exception { int[] ar = new int[size]; for (int i = 0; i < size; ++i) ar[i] = nextInt(); return ar; } public String[] getStringArray(int size) throws Exception { String[] ar = new String[size]; for (int i = 0; i < size; ++i) ar[i] = next(); return ar; } public String joinElements(long... ar) { StringBuilder sb = new StringBuilder(); for (long itr : ar) sb.append(itr).append(" "); return sb.toString().trim(); } public String joinElements(int... ar) { StringBuilder sb = new StringBuilder(); for (int itr : ar) sb.append(itr).append(" "); return sb.toString().trim(); } public String joinElements(String... ar) { StringBuilder sb = new StringBuilder(); for (String itr : ar) sb.append(itr).append(" "); return sb.toString().trim(); } public String joinElements(Object... ar) { StringBuilder sb = new StringBuilder(); for (Object itr : ar) sb.append(itr).append(" "); return sb.toString().trim(); } public long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); } public int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } public long max(long... ar) { long ret = ar[0]; for (long itr : ar) ret = Math.max(ret, itr); return ret; } public int max(int... ar) { int ret = ar[0]; for (int itr : ar) ret = Math.max(ret, itr); return ret; } public long min(long... ar) { long ret = ar[0]; for (long itr : ar) ret = Math.min(ret, itr); return ret; } public int min(int... ar) { int ret = ar[0]; for (int itr : ar) ret = Math.min(ret, itr); return ret; } public long sum(long... ar) { long sum = 0; for (long itr : ar) sum += itr; return sum; } public long sum(int... ar) { long sum = 0; for (int itr : ar) sum += itr; return sum; } public void shuffle(int[] ar) { int r; for (int i = 0; i < ar.length; ++i) { r = rnd.nextInt(ar.length); if (r != i) { ar[i] ^= ar[r]; ar[r] ^= ar[i]; ar[i] ^= ar[r]; } } } public void shuffle(long[] ar) { int r; for (int i = 0; i < ar.length; ++i) { r = rnd.nextInt(ar.length); if (r != i) { ar[i] ^= ar[r]; ar[r] ^= ar[i]; ar[i] ^= ar[r]; } } } public void reverse(int[] ar) { int r; for (int i = 0; i < ar.length; ++i) { r = ar.length - 1 - i; if (r > i) { ar[i] ^= ar[r]; ar[r] ^= ar[i]; ar[i] ^= ar[r]; } } } public void reverse(long[] ar) { int r; for (int i = 0; i < ar.length; ++i) { r = ar.length - 1 - i; if (r > i) { ar[i] ^= ar[r]; ar[r] ^= ar[i]; ar[i] ^= ar[r]; } } } public long pow(long base, long exp, long MOD) { base %= MOD; long ret = 1; while (exp > 0) { if ((exp & 1) == 1) ret = ret * base % MOD; base = base * base % MOD; exp >>= 1; } return ret; } static final int BUFSIZE = 1 << 20; static byte[] buf; static int index, total; static InputStream in; static BufferedWriter bw; public void initIO(InputStream is, OutputStream os) { try { in = is; bw = new BufferedWriter(new OutputStreamWriter(os)); buf = new byte[BUFSIZE]; } catch (Exception e) { } } public void initIO(String inputFile, String outputFile) { try { in = new FileInputStream(inputFile); bw = new BufferedWriter(new OutputStreamWriter( new FileOutputStream(outputFile))); buf = new byte[BUFSIZE]; } catch (Exception e) { } } private int scan() throws Exception { if (index >= total) { index = 0; total = in.read(buf); if (total <= 0) return -1; } return buf[index++]; } public String next() throws Exception { int c; for (c = scan(); c <= 32; c = scan()) ; StringBuilder sb = new StringBuilder(); for (; c > 32; c = scan()) sb.append((char) c); return sb.toString(); } public int nextInt() throws Exception { int c, val = 0; for (c = scan(); c <= 32; c = scan()) ; boolean neg = c == '-'; if (c == '-' || c == '+') c = scan(); for (; c >= '0' && c <= '9'; c = scan()) val = (val << 3) + (val << 1) + (c & 15); return neg ? -val : val; } public long nextLong() throws Exception { int c; long val = 0; for (c = scan(); c <= 32; c = scan()) ; boolean neg = c == '-'; if (c == '-' || c == '+') c = scan(); for (; c >= '0' && c <= '9'; c = scan()) val = (val << 3) + (val << 1) + (c & 15); return neg ? -val : val; } public void print(Object a) throws Exception { bw.write(a.toString()); } public void printsp(Object a) throws Exception { print(a); print(" "); } public void println() throws Exception { bw.write("\n"); } public void println(Object a) throws Exception { print(a); println(); } public void flush() throws Exception { bw.flush(); } }
Java
["1\n4 2\n2 1 3\n2 2 4\n\n1\n\n2\n\n3\n\n4\n\nCorrect"]
2 seconds
["? 1 1\n\n? 1 2\n\n? 1 3\n\n? 1 4\n\n! 4 3"]
NoteThe array $$$A$$$ in the example is $$$[1, 2, 3, 4]$$$. The length of the password is $$$2$$$. The first element of the password is the maximum of $$$A[2]$$$, $$$A[4]$$$ (since the first subset contains indices $$$1$$$ and $$$3$$$, we take maximum over remaining indices). The second element of the password is the maximum of $$$A[1]$$$, $$$A[3]$$$ (since the second subset contains indices $$$2$$$, $$$4$$$).Do not forget to read the string "Correct" / "Incorrect" after guessing the password.
Java 11
standard input
[ "math", "binary search", "implementation", "interactive" ]
b0bce8524eb69b695edc1394ff86b913
The first line of the input contains a single integer $$$t$$$ $$$(1 \leq t \leq 10)$$$ — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ $$$(2 \leq n \leq 1000, 1 \leq k \leq n)$$$ — the size of the array and the number of subsets. $$$k$$$ lines follow. The $$$i$$$-th line contains an integer $$$c$$$ $$$(1 \leq c \lt n)$$$ — the size of subset $$$S_i$$$, followed by $$$c$$$ distinct integers in the range $$$[1, n]$$$  — indices from the subset $$$S_i$$$. It is guaranteed that the intersection of any two subsets is empty.
2,100
null
standard output
PASSED
860e8fac8841423f14bc17bcf4955a60
train_002.jsonl
1590935700
This is an interactive problem.Ayush devised a new scheme to set the password of his lock. The lock has $$$k$$$ slots where each slot can hold integers from $$$1$$$ to $$$n$$$. The password $$$P$$$ is a sequence of $$$k$$$ integers each in the range $$$[1, n]$$$, $$$i$$$-th element of which goes into the $$$i$$$-th slot of the lock.To set the password of his lock, Ayush comes up with an array $$$A$$$ of $$$n$$$ integers each in the range $$$[1, n]$$$ (not necessarily distinct). He then picks $$$k$$$ non-empty mutually disjoint subsets of indices $$$S_1, S_2, ..., S_k$$$ $$$(S_i \underset{i \neq j} \cap S_j = \emptyset)$$$ and sets his password as $$$P_i = \max\limits_{j \notin S_i} A[j]$$$. In other words, the $$$i$$$-th integer in the password is equal to the maximum over all elements of $$$A$$$ whose indices do not belong to $$$S_i$$$.You are given the subsets of indices chosen by Ayush. You need to guess the password. To make a query, you can choose a non-empty subset of indices of the array and ask the maximum of all elements of the array with index in this subset. You can ask no more than 12 queries.
256 megabytes
import java.io.*; import java.util.*; public class CF1363D extends PrintWriter { CF1363D() { super(System.out, true); } Scanner sc = new Scanner(System.in); public static void main(String[] $) { CF1363D o = new CF1363D(); o.main(); o.flush(); } int[] cc; int[][] ii; int query(int l, int r) { int c = 0; for (int h = l; h < r; h++) c += cc[h]; print("? " + c); for (int h = l; h < r; h++) for (int i = 0; i < cc[h]; i++) print(" " + ii[h][i]); println(); return sc.nextInt(); } int query_(int k, int h_) { int c = 0; for (int h = 0; h < k; h++) if (h != h_) c += cc[h]; print("? " + c); for (int h = 0; h < k; h++) if (h != h_) for (int i = 0; i < cc[h]; i++) print(" " + ii[h][i]); println(); return sc.nextInt(); } void main() { int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int k = sc.nextInt(); cc = new int[k + 1]; ii = new int[k + 1][]; boolean[] used = new boolean[n + 1]; int sum = 0; for (int h = 0; h < k; h++) { int c = sc.nextInt(); sum += c; cc[h] = c; ii[h] = new int[c]; while (c-- > 0) { int i = sc.nextInt(); ii[h][c] = i; used[i] = true; } } if (sum < n) { int c = n - sum; cc[k] = c; ii[k] = new int[c]; for (int i = 1; i <= n; i++) if (!used[i]) ii[k][--c] = i; } int lower = 0, upper = sum == n ? k : k + 1; int x = query(lower, upper); while (upper - lower > 1) { int h = (lower + upper) / 2; if (query(lower, h) == x) upper = h; else lower = h; } int h_ = lower, y = query_(sum == n ? k : k + 1, h_); print("!"); for (int h = 0; h < k; h++) print(" " + (h == h_ ? y : x)); println(); sc.next(); } } }
Java
["1\n4 2\n2 1 3\n2 2 4\n\n1\n\n2\n\n3\n\n4\n\nCorrect"]
2 seconds
["? 1 1\n\n? 1 2\n\n? 1 3\n\n? 1 4\n\n! 4 3"]
NoteThe array $$$A$$$ in the example is $$$[1, 2, 3, 4]$$$. The length of the password is $$$2$$$. The first element of the password is the maximum of $$$A[2]$$$, $$$A[4]$$$ (since the first subset contains indices $$$1$$$ and $$$3$$$, we take maximum over remaining indices). The second element of the password is the maximum of $$$A[1]$$$, $$$A[3]$$$ (since the second subset contains indices $$$2$$$, $$$4$$$).Do not forget to read the string "Correct" / "Incorrect" after guessing the password.
Java 11
standard input
[ "math", "binary search", "implementation", "interactive" ]
b0bce8524eb69b695edc1394ff86b913
The first line of the input contains a single integer $$$t$$$ $$$(1 \leq t \leq 10)$$$ — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ $$$(2 \leq n \leq 1000, 1 \leq k \leq n)$$$ — the size of the array and the number of subsets. $$$k$$$ lines follow. The $$$i$$$-th line contains an integer $$$c$$$ $$$(1 \leq c \lt n)$$$ — the size of subset $$$S_i$$$, followed by $$$c$$$ distinct integers in the range $$$[1, n]$$$  — indices from the subset $$$S_i$$$. It is guaranteed that the intersection of any two subsets is empty.
2,100
null
standard output
PASSED
44644c004d27c28f1e2edb20eb1c83a1
train_002.jsonl
1590935700
This is an interactive problem.Ayush devised a new scheme to set the password of his lock. The lock has $$$k$$$ slots where each slot can hold integers from $$$1$$$ to $$$n$$$. The password $$$P$$$ is a sequence of $$$k$$$ integers each in the range $$$[1, n]$$$, $$$i$$$-th element of which goes into the $$$i$$$-th slot of the lock.To set the password of his lock, Ayush comes up with an array $$$A$$$ of $$$n$$$ integers each in the range $$$[1, n]$$$ (not necessarily distinct). He then picks $$$k$$$ non-empty mutually disjoint subsets of indices $$$S_1, S_2, ..., S_k$$$ $$$(S_i \underset{i \neq j} \cap S_j = \emptyset)$$$ and sets his password as $$$P_i = \max\limits_{j \notin S_i} A[j]$$$. In other words, the $$$i$$$-th integer in the password is equal to the maximum over all elements of $$$A$$$ whose indices do not belong to $$$S_i$$$.You are given the subsets of indices chosen by Ayush. You need to guess the password. To make a query, you can choose a non-empty subset of indices of the array and ask the maximum of all elements of the array with index in this subset. You can ask no more than 12 queries.
256 megabytes
import java.io.*; import java.math.*; import java.security.*; import java.text.*; import java.util.*; import java.util.concurrent.*; import java.util.function.*; import java.util.regex.*; import java.util.stream.*; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList; public class Main{ static long MOD = 998244353L; static long [] fac; static int[][] dir = new int[][]{{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; static long lMax = 0x3f3f3f3f3f3f3f3fL; static int iMax = 0x3f3f3f3f; static HashMap <Long, Long> memo = new HashMap(); static int n, m; static int[][] mat; static long res = 0L; static ArrayList <Integer> graph[]; static long cost[]; static int move[]; static boolean [] visitied; public static void main(String[] args) { MyScanner sc = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); // Start writing your solution here. ------------------------------------- int t = sc.nextInt(); //int t = 1; while(t-- > 0){ int n = sc.nextInt(); int k = sc.nextInt(); HashSet<Integer>[] sets = new HashSet[k]; for(int i = 0; i < k; i++) { sets[i] = new HashSet<>(); int j = sc.nextInt(); for(int jj = 0; jj < j; jj++) sets[i].add(sc.nextInt()); } StringBuilder sb = new StringBuilder(); sb.append("? " + n); for(int i = 1; i <= n; i++) sb.append(" " + i); System.out.println(sb.toString()); System.out.flush(); int max = sc.nextInt(); int lo = 1, hi = n, mid = 0; while(lo < hi) { mid = (lo + hi) / 2; sb = new StringBuilder(); sb.append("? " + (mid - lo + 1)); for(int i = lo; i <= mid; i++) sb.append(" " + i); System.out.println(sb.toString()); System.out.flush(); int cur = sc.nextInt(); if(cur == max) hi = mid; else lo = mid + 1; } int maxInd = lo; int extraSet = -1; int[] res = new int[k]; for(int i = 0; i < k; i++){ if(!sets[i].contains(maxInd)) res[i] = max; else extraSet = i; } if(extraSet != -1) { int howMany = n - sets[extraSet].size(); sb = new StringBuilder(); sb.append("? " + howMany); for(int i = 1; i <= n; i++) if(!sets[extraSet].contains(i)) sb.append(" " + i); System.out.println(sb.toString()); System.out.flush(); res[extraSet] = sc.nextInt(); } sb = new StringBuilder(); sb.append("!"); for(int i = 0; i < k; i++) sb.append(" " + res[i]); System.out.println(sb.toString()); System.out.flush(); String tmp = sc.nextLine(); } out.close(); } public static long C(int n, int m) { if(m == 0 || m == n) return 1l; if(m > n || m < 0) return 0l; long res = fac[n] * quickPOW((fac[m] * fac[n - m]) % MOD, MOD - 2) % MOD; return res; } public static long quickPOW(long n, long m) { long ans = 1l; while(m > 0) { if(m % 2 == 1) ans = (ans * n) % MOD; n = (n * n) % MOD; m >>= 1; } return ans; } public static int gcd(int a, int b) { if(a % b == 0) return b; return gcd(b, a % b); } public static long gcd(long a, long b) { if(a % b == 0) return b; return gcd(b, a % b); } public static long solve(long cur){ return 0L; } //-----------PrintWriter for faster output--------------------------------- public static PrintWriter out; //-----------MyScanner class for faster input---------- public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine(){ String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } //-------------------------------------------------------- }
Java
["1\n4 2\n2 1 3\n2 2 4\n\n1\n\n2\n\n3\n\n4\n\nCorrect"]
2 seconds
["? 1 1\n\n? 1 2\n\n? 1 3\n\n? 1 4\n\n! 4 3"]
NoteThe array $$$A$$$ in the example is $$$[1, 2, 3, 4]$$$. The length of the password is $$$2$$$. The first element of the password is the maximum of $$$A[2]$$$, $$$A[4]$$$ (since the first subset contains indices $$$1$$$ and $$$3$$$, we take maximum over remaining indices). The second element of the password is the maximum of $$$A[1]$$$, $$$A[3]$$$ (since the second subset contains indices $$$2$$$, $$$4$$$).Do not forget to read the string "Correct" / "Incorrect" after guessing the password.
Java 11
standard input
[ "math", "binary search", "implementation", "interactive" ]
b0bce8524eb69b695edc1394ff86b913
The first line of the input contains a single integer $$$t$$$ $$$(1 \leq t \leq 10)$$$ — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ $$$(2 \leq n \leq 1000, 1 \leq k \leq n)$$$ — the size of the array and the number of subsets. $$$k$$$ lines follow. The $$$i$$$-th line contains an integer $$$c$$$ $$$(1 \leq c \lt n)$$$ — the size of subset $$$S_i$$$, followed by $$$c$$$ distinct integers in the range $$$[1, n]$$$  — indices from the subset $$$S_i$$$. It is guaranteed that the intersection of any two subsets is empty.
2,100
null
standard output
PASSED
fdfd3f83856579bd498152a67fa40dd0
train_002.jsonl
1590935700
This is an interactive problem.Ayush devised a new scheme to set the password of his lock. The lock has $$$k$$$ slots where each slot can hold integers from $$$1$$$ to $$$n$$$. The password $$$P$$$ is a sequence of $$$k$$$ integers each in the range $$$[1, n]$$$, $$$i$$$-th element of which goes into the $$$i$$$-th slot of the lock.To set the password of his lock, Ayush comes up with an array $$$A$$$ of $$$n$$$ integers each in the range $$$[1, n]$$$ (not necessarily distinct). He then picks $$$k$$$ non-empty mutually disjoint subsets of indices $$$S_1, S_2, ..., S_k$$$ $$$(S_i \underset{i \neq j} \cap S_j = \emptyset)$$$ and sets his password as $$$P_i = \max\limits_{j \notin S_i} A[j]$$$. In other words, the $$$i$$$-th integer in the password is equal to the maximum over all elements of $$$A$$$ whose indices do not belong to $$$S_i$$$.You are given the subsets of indices chosen by Ayush. You need to guess the password. To make a query, you can choose a non-empty subset of indices of the array and ask the maximum of all elements of the array with index in this subset. You can ask no more than 12 queries.
256 megabytes
import java.io.*; import java.util.*; public class Main{ static void print(int[]arr) { pw.print("? "+arr.length); for(int i:arr)pw.print(" "+i); pw.println(); pw.flush(); } static void print(LinkedList<Integer>arr) { pw.print("? "+arr.size()); for(int i:arr)pw.print(" "+i); pw.println(); pw.flush(); } static void main() throws Exception{ int n=sc.nextInt(),k=sc.nextInt(); int[][]in=new int[k][]; for(int i=0;i<k;i++) { in[i]=sc.intArr(sc.nextInt()); } int[]arr=new int[n]; for(int i=0;i<n;i++) { arr[i]=i+1; } print(arr); int max=sc.nextInt(); // System.out.println(max); int lo=0,hi=k-1; int idxMax=0; while(lo<=hi) { int mid=(lo+hi)>>1; LinkedList<Integer>cur=new LinkedList<>(); for(int i=lo;i<=mid;i++) { for(int e:in[i]) { cur.add(e); } } print(cur); int ans=sc.nextInt(); if(ans==max) { idxMax=mid; hi=mid-1; } else { lo=mid+1; } } LinkedList<Integer>cur=new LinkedList<>(); HashSet<Integer>inSetMax=new HashSet<>(); for(int i:in[idxMax]) { inSetMax.add(i); } for(int i=1;i<=n;i++) { if(!inSetMax.contains(i)) { cur.add(i); } } print(cur); int scndMax=sc.nextInt(); pw.print("!"); for(int i=0;i<k;i++) { if(i==idxMax) { pw.print(" "+scndMax); } else { pw.print(" "+max); } } pw.println(); pw.flush(); String v=sc.nextLine(); } public static void main(String[] args) throws Exception{ pw=new PrintWriter(System.out); sc = new MScanner(System.in); int tc=sc.nextInt(); while(tc-->0)main(); pw.flush(); } static PrintWriter pw; static MScanner sc; static class MScanner { StringTokenizer st; BufferedReader br; public MScanner(InputStream system) { br = new BufferedReader(new InputStreamReader(system)); } public MScanner(String file) throws Exception { br = new BufferedReader(new FileReader(file)); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int[] intArr(int n) throws IOException { int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt(); return in; } public long[] longArr(int n) throws IOException { long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong(); return in; } public int[] intSortedArr(int n) throws IOException { int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt(); shuffle(in); Arrays.sort(in); return in; } public long[] longSortedArr(int n) throws IOException { long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong(); shuffle(in); Arrays.sort(in); return in; } public Integer[] IntegerArr(int n) throws IOException { Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt(); return in; } public Long[] LongArr(int n) throws IOException { Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong(); return in; } public String nextLine() throws IOException { return br.readLine(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public char nextChar() throws IOException { return next().charAt(0); } public long nextLong() throws IOException { return Long.parseLong(next()); } public boolean ready() throws IOException { return br.ready(); } public void waitForInput() throws InterruptedException { Thread.sleep(3000); } } static void shuffle(int[]in) { for(int i=0;i<in.length;i++) { int idx=(int)(Math.random()*in.length); int tmp=in[i]; in[i]=in[idx]; in[idx]=tmp; } } static void shuffle(long[]in) { for(int i=0;i<in.length;i++) { int idx=(int)(Math.random()*in.length); long tmp=in[i]; in[i]=in[idx]; in[idx]=tmp; } } }
Java
["1\n4 2\n2 1 3\n2 2 4\n\n1\n\n2\n\n3\n\n4\n\nCorrect"]
2 seconds
["? 1 1\n\n? 1 2\n\n? 1 3\n\n? 1 4\n\n! 4 3"]
NoteThe array $$$A$$$ in the example is $$$[1, 2, 3, 4]$$$. The length of the password is $$$2$$$. The first element of the password is the maximum of $$$A[2]$$$, $$$A[4]$$$ (since the first subset contains indices $$$1$$$ and $$$3$$$, we take maximum over remaining indices). The second element of the password is the maximum of $$$A[1]$$$, $$$A[3]$$$ (since the second subset contains indices $$$2$$$, $$$4$$$).Do not forget to read the string "Correct" / "Incorrect" after guessing the password.
Java 11
standard input
[ "math", "binary search", "implementation", "interactive" ]
b0bce8524eb69b695edc1394ff86b913
The first line of the input contains a single integer $$$t$$$ $$$(1 \leq t \leq 10)$$$ — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ $$$(2 \leq n \leq 1000, 1 \leq k \leq n)$$$ — the size of the array and the number of subsets. $$$k$$$ lines follow. The $$$i$$$-th line contains an integer $$$c$$$ $$$(1 \leq c \lt n)$$$ — the size of subset $$$S_i$$$, followed by $$$c$$$ distinct integers in the range $$$[1, n]$$$  — indices from the subset $$$S_i$$$. It is guaranteed that the intersection of any two subsets is empty.
2,100
null
standard output
PASSED
88dde7c20b3f03bad8c25be6d8de9ecc
train_002.jsonl
1590935700
This is an interactive problem.Ayush devised a new scheme to set the password of his lock. The lock has $$$k$$$ slots where each slot can hold integers from $$$1$$$ to $$$n$$$. The password $$$P$$$ is a sequence of $$$k$$$ integers each in the range $$$[1, n]$$$, $$$i$$$-th element of which goes into the $$$i$$$-th slot of the lock.To set the password of his lock, Ayush comes up with an array $$$A$$$ of $$$n$$$ integers each in the range $$$[1, n]$$$ (not necessarily distinct). He then picks $$$k$$$ non-empty mutually disjoint subsets of indices $$$S_1, S_2, ..., S_k$$$ $$$(S_i \underset{i \neq j} \cap S_j = \emptyset)$$$ and sets his password as $$$P_i = \max\limits_{j \notin S_i} A[j]$$$. In other words, the $$$i$$$-th integer in the password is equal to the maximum over all elements of $$$A$$$ whose indices do not belong to $$$S_i$$$.You are given the subsets of indices chosen by Ayush. You need to guess the password. To make a query, you can choose a non-empty subset of indices of the array and ask the maximum of all elements of the array with index in this subset. You can ask no more than 12 queries.
256 megabytes
import java.io.IOException; import java.io.InputStream; import java.util.*; public class Main { static int max; static FastReader in; static boolean ispresent(int l,int r)throws IOException{ StringBuilder sb=new StringBuilder(); sb.append("? "); sb.append(r-l+1).append(" "); for(int i=l;i<=r;i++){ sb.append(i).append(" "); } System.out.println(sb); int z=in.nextInt(); if(z==max) return true; return false; } public static void main(String args[]) throws IOException { in = new FastReader(System.in); int i, j; int t=in.nextInt(); while(t-->0){ int n=in.nextInt(); int k=in.nextInt(); HashSet<Integer> set[] =new HashSet[k]; for(i=0;i<k;i++){ int x=in.nextInt(); set[i]=new HashSet<>(); for(j=0;j<x;j++){ int z=in.nextInt(); set[i].add(z); } } StringBuilder sb = new StringBuilder(); sb.append("? "); sb.append(n).append(" "); for(i=1;i<=n;i++) sb.append(i).append(" "); System.out.println(sb); max=in.nextInt(); int l=1,r=n,pos=1; while(l<=r){ if(l==r) { pos=l; break; } if(l+1==r){ if(ispresent(l,l)) pos=l; else pos=r; break; } int m=(l+r)/2; if(ispresent(l,m)){ r=m; } else{ l=m+1; } } sb=new StringBuilder(); sb.append("! "); for(i=0;i<k;i++){ if(!set[i].contains(pos)) sb.append(max).append(" "); else{ StringBuilder sb1=new StringBuilder(); sb1.append("? "); sb1.append(n-set[i].size()).append(" "); for(j=1;j<=n;j++){ if(!set[i].contains(j)) sb1.append(j).append(" "); } System.out.println(sb1); sb.append(in.nextInt()).append(" "); } } System.out.println(sb); String str=in.next(); if(str.equals("Incorrect")) break; } } } class Node{ int nsize,atob,btoa,change; Node(int a,int b,int c,int d){ nsize=a; atob=b; btoa=c; change=d; } } class Node1{ int ab,ba; Node1(int x,int y){ ab=x; ba=y; } } class FastReader { byte[] buf = new byte[2048]; int index, total; InputStream in; FastReader(InputStream is) { in = is; } int scan() throws IOException { if (index >= total) { index = 0; total = in.read(buf); if (total <= 0) { return -1; } } return buf[index++]; } String next() throws IOException { int c; for (c = scan(); c <= 32; c = scan()) ; StringBuilder sb = new StringBuilder(); for (; c > 32; c = scan()) { sb.append((char) c); } return sb.toString(); } int nextInt() throws IOException { int c, val = 0; for (c = scan(); c <= 32; c = scan()) ; boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } }
Java
["1\n4 2\n2 1 3\n2 2 4\n\n1\n\n2\n\n3\n\n4\n\nCorrect"]
2 seconds
["? 1 1\n\n? 1 2\n\n? 1 3\n\n? 1 4\n\n! 4 3"]
NoteThe array $$$A$$$ in the example is $$$[1, 2, 3, 4]$$$. The length of the password is $$$2$$$. The first element of the password is the maximum of $$$A[2]$$$, $$$A[4]$$$ (since the first subset contains indices $$$1$$$ and $$$3$$$, we take maximum over remaining indices). The second element of the password is the maximum of $$$A[1]$$$, $$$A[3]$$$ (since the second subset contains indices $$$2$$$, $$$4$$$).Do not forget to read the string "Correct" / "Incorrect" after guessing the password.
Java 11
standard input
[ "math", "binary search", "implementation", "interactive" ]
b0bce8524eb69b695edc1394ff86b913
The first line of the input contains a single integer $$$t$$$ $$$(1 \leq t \leq 10)$$$ — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ $$$(2 \leq n \leq 1000, 1 \leq k \leq n)$$$ — the size of the array and the number of subsets. $$$k$$$ lines follow. The $$$i$$$-th line contains an integer $$$c$$$ $$$(1 \leq c \lt n)$$$ — the size of subset $$$S_i$$$, followed by $$$c$$$ distinct integers in the range $$$[1, n]$$$  — indices from the subset $$$S_i$$$. It is guaranteed that the intersection of any two subsets is empty.
2,100
null
standard output
PASSED
75aeb99fb3d3d2ba3b493fea4909c993
train_002.jsonl
1590935700
This is an interactive problem.Ayush devised a new scheme to set the password of his lock. The lock has $$$k$$$ slots where each slot can hold integers from $$$1$$$ to $$$n$$$. The password $$$P$$$ is a sequence of $$$k$$$ integers each in the range $$$[1, n]$$$, $$$i$$$-th element of which goes into the $$$i$$$-th slot of the lock.To set the password of his lock, Ayush comes up with an array $$$A$$$ of $$$n$$$ integers each in the range $$$[1, n]$$$ (not necessarily distinct). He then picks $$$k$$$ non-empty mutually disjoint subsets of indices $$$S_1, S_2, ..., S_k$$$ $$$(S_i \underset{i \neq j} \cap S_j = \emptyset)$$$ and sets his password as $$$P_i = \max\limits_{j \notin S_i} A[j]$$$. In other words, the $$$i$$$-th integer in the password is equal to the maximum over all elements of $$$A$$$ whose indices do not belong to $$$S_i$$$.You are given the subsets of indices chosen by Ayush. You need to guess the password. To make a query, you can choose a non-empty subset of indices of the array and ask the maximum of all elements of the array with index in this subset. You can ask no more than 12 queries.
256 megabytes
/** * @author egaeus * @mail sebegaeusprogram@gmail.com * @veredict Not sended * @url <https://codeforces.com/problemset/problem/> * @category ? * @date 2/06/2020 **/ import java.io.*; import java.util.*; import java.util.stream.Collectors; import java.util.stream.IntStream; import static java.lang.Integer.*; import static java.lang.Math.*; public class CF1363D { static int[][] sets; static void generateCase() { int T = 1; int N = 802, K = 802; StringBuilder sb = new StringBuilder(); sb.append(T).append("\n"); sb.append(N + " " + K).append("\n"); for (int i = 0; i < K; i++) sb.append(1 + " " + (i + 1) + "\n"); System.out.println(new String(sb)); } public static void main(String args[]) throws Throwable { //generateCase(); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int T = parseInt(in.readLine()); for (int t = 0; t < T; t++) { StringTokenizer st = new StringTokenizer(in.readLine()); int N = parseInt(st.nextToken()), K = parseInt(st.nextToken()); sets = new int[K][]; for (int i = 0; i < K; i++) { st = new StringTokenizer(in.readLine()); sets[i] = new int[parseInt(st.nextToken())]; for (int j = 0; j < sets[i].length; j++) sets[i][j] = parseInt(st.nextToken()); } System.out.println("? " + N); System.out.println(IntStream.range(1, N + 1).mapToObj(a -> a + "").collect(Collectors.joining(" "))); System.out.flush(); int max = parseInt(in.readLine()); int[] solution = new int[K]; f(0, K, solution, max, in, N); System.out.print("! "); System.out.println(IntStream.of(solution).mapToObj(a -> a + "").collect(Collectors.joining(" "))); System.out.flush(); in.readLine(); } } static void f(int a, int b, int[] solution, int max, BufferedReader in, int N) throws Throwable { if (b - a == 1) { TreeSet<Integer> set = new TreeSet<>(); for (int i = 1; i <= N; i++) set.add(i); for (int i : sets[a]) set.remove(i); System.out.println("? " + set.size()); System.out.println(set.stream().map(A -> A + "").collect(Collectors.joining(" "))); System.out.flush(); solution[a] = parseInt(in.readLine()); } else { int p = (a + b) / 2; int response = getMax(a, p, in); if (response < max) { Arrays.fill(solution, a, p, max); f(p, b, solution, max, in, N); } else { Arrays.fill(solution, p, b, max); f(a, p, solution, max, in, N); } } } static int getMax(int a, int b, BufferedReader in) throws Throwable { TreeSet<Integer> set = new TreeSet<>(); for (int i = a; i < b; i++) for (int t : sets[i]) set.add(t); System.out.println("? " + set.size()); System.out.println(set.stream().map(A -> A + "").collect(Collectors.joining(" "))); System.out.flush(); return parseInt(in.readLine()); } }
Java
["1\n4 2\n2 1 3\n2 2 4\n\n1\n\n2\n\n3\n\n4\n\nCorrect"]
2 seconds
["? 1 1\n\n? 1 2\n\n? 1 3\n\n? 1 4\n\n! 4 3"]
NoteThe array $$$A$$$ in the example is $$$[1, 2, 3, 4]$$$. The length of the password is $$$2$$$. The first element of the password is the maximum of $$$A[2]$$$, $$$A[4]$$$ (since the first subset contains indices $$$1$$$ and $$$3$$$, we take maximum over remaining indices). The second element of the password is the maximum of $$$A[1]$$$, $$$A[3]$$$ (since the second subset contains indices $$$2$$$, $$$4$$$).Do not forget to read the string "Correct" / "Incorrect" after guessing the password.
Java 11
standard input
[ "math", "binary search", "implementation", "interactive" ]
b0bce8524eb69b695edc1394ff86b913
The first line of the input contains a single integer $$$t$$$ $$$(1 \leq t \leq 10)$$$ — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ $$$(2 \leq n \leq 1000, 1 \leq k \leq n)$$$ — the size of the array and the number of subsets. $$$k$$$ lines follow. The $$$i$$$-th line contains an integer $$$c$$$ $$$(1 \leq c \lt n)$$$ — the size of subset $$$S_i$$$, followed by $$$c$$$ distinct integers in the range $$$[1, n]$$$  — indices from the subset $$$S_i$$$. It is guaranteed that the intersection of any two subsets is empty.
2,100
null
standard output
PASSED
a792ffc96a961c6f17faaff04609a696
train_002.jsonl
1590935700
This is an interactive problem.Ayush devised a new scheme to set the password of his lock. The lock has $$$k$$$ slots where each slot can hold integers from $$$1$$$ to $$$n$$$. The password $$$P$$$ is a sequence of $$$k$$$ integers each in the range $$$[1, n]$$$, $$$i$$$-th element of which goes into the $$$i$$$-th slot of the lock.To set the password of his lock, Ayush comes up with an array $$$A$$$ of $$$n$$$ integers each in the range $$$[1, n]$$$ (not necessarily distinct). He then picks $$$k$$$ non-empty mutually disjoint subsets of indices $$$S_1, S_2, ..., S_k$$$ $$$(S_i \underset{i \neq j} \cap S_j = \emptyset)$$$ and sets his password as $$$P_i = \max\limits_{j \notin S_i} A[j]$$$. In other words, the $$$i$$$-th integer in the password is equal to the maximum over all elements of $$$A$$$ whose indices do not belong to $$$S_i$$$.You are given the subsets of indices chosen by Ayush. You need to guess the password. To make a query, you can choose a non-empty subset of indices of the array and ask the maximum of all elements of the array with index in this subset. You can ask no more than 12 queries.
256 megabytes
import java.io.*; import java.util.*; public class F { static Scanner sc = new Scanner(); static int[] a; static int query(ArrayList<Integer> indices) throws IOException { StringBuilder sb = new StringBuilder("? "); sb.append(indices.size()); for (int idx : indices) sb.append(" " + idx); System.out.println(sb); return sc.nextInt(); } static ArrayList<Integer> getRange(int l, int r) { ArrayList<Integer> ans = new ArrayList(); for (int i = l; i <= r; i++) ans.add(i); return ans; } public static void main(String[] args) throws IOException { int tc = sc.nextInt(); while (tc-- > 0) { int n = sc.nextInt(), k = sc.nextInt(); int[][] subsets = new int[k][]; for (int i = 0; i < k; i++) { subsets[i] = new int[sc.nextInt()]; for (int j = 0; j < subsets[i].length; j++) subsets[i][j] = sc.nextInt(); } int max = query(getRange(1, n)); int lo = 1, hi = n; while (lo < hi) { int mid = lo + hi >> 1; int query = query(getRange(lo, mid)); if (query == max) { hi = mid; } else lo = mid + 1; } int[] ans = new int[k]; for (int i = 0; i < k; i++) { boolean haveMax = false; for (int x : subsets[i]) if (x == lo) haveMax = true; if (!haveMax) ans[i] = max; else { ArrayList<Integer> indices = new ArrayList(); HashSet<Integer> set = new HashSet(); for (int x : subsets[i]) set.add(x); for (int j = 1; j <= n; j++) if (!set.contains(j)) indices.add(j); ans[i] = query(indices); } } StringBuilder sb = new StringBuilder("!"); for (int x : ans) sb.append(" " + x); System.out.println(sb); if (!sc.next().equals("Correct")) break; } } static class Scanner { BufferedReader br; StringTokenizer st; Scanner() { br = new BufferedReader(new InputStreamReader(System.in)); } Scanner(String fileName) throws FileNotFoundException { br = new BufferedReader(new FileReader(fileName)); } String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } String nextLine() throws IOException { return br.readLine(); } int nextInt() throws IOException { return Integer.parseInt(next()); } long nextLong() throws NumberFormatException, IOException { return Long.parseLong(next()); } double nextDouble() throws NumberFormatException, IOException { return Double.parseDouble(next()); } boolean ready() throws IOException { return br.ready(); } int[] nxtArr(int n) throws IOException { int[] ans = new int[n]; for (int i = 0; i < n; i++) ans[i] = nextInt(); return ans; } } static void sort(int[] a) { shuffle(a); Arrays.sort(a); } static void shuffle(int[] a) { int n = a.length; Random rand = new Random(); for (int i = 0; i < n; i++) { int tmpIdx = rand.nextInt(n); int tmp = a[i]; a[i] = a[tmpIdx]; a[tmpIdx] = tmp; } } }
Java
["1\n4 2\n2 1 3\n2 2 4\n\n1\n\n2\n\n3\n\n4\n\nCorrect"]
2 seconds
["? 1 1\n\n? 1 2\n\n? 1 3\n\n? 1 4\n\n! 4 3"]
NoteThe array $$$A$$$ in the example is $$$[1, 2, 3, 4]$$$. The length of the password is $$$2$$$. The first element of the password is the maximum of $$$A[2]$$$, $$$A[4]$$$ (since the first subset contains indices $$$1$$$ and $$$3$$$, we take maximum over remaining indices). The second element of the password is the maximum of $$$A[1]$$$, $$$A[3]$$$ (since the second subset contains indices $$$2$$$, $$$4$$$).Do not forget to read the string "Correct" / "Incorrect" after guessing the password.
Java 11
standard input
[ "math", "binary search", "implementation", "interactive" ]
b0bce8524eb69b695edc1394ff86b913
The first line of the input contains a single integer $$$t$$$ $$$(1 \leq t \leq 10)$$$ — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ $$$(2 \leq n \leq 1000, 1 \leq k \leq n)$$$ — the size of the array and the number of subsets. $$$k$$$ lines follow. The $$$i$$$-th line contains an integer $$$c$$$ $$$(1 \leq c \lt n)$$$ — the size of subset $$$S_i$$$, followed by $$$c$$$ distinct integers in the range $$$[1, n]$$$  — indices from the subset $$$S_i$$$. It is guaranteed that the intersection of any two subsets is empty.
2,100
null
standard output
PASSED
b8406356ca60d94841aa0bd0de1ee5bd
train_002.jsonl
1590935700
This is an interactive problem.Ayush devised a new scheme to set the password of his lock. The lock has $$$k$$$ slots where each slot can hold integers from $$$1$$$ to $$$n$$$. The password $$$P$$$ is a sequence of $$$k$$$ integers each in the range $$$[1, n]$$$, $$$i$$$-th element of which goes into the $$$i$$$-th slot of the lock.To set the password of his lock, Ayush comes up with an array $$$A$$$ of $$$n$$$ integers each in the range $$$[1, n]$$$ (not necessarily distinct). He then picks $$$k$$$ non-empty mutually disjoint subsets of indices $$$S_1, S_2, ..., S_k$$$ $$$(S_i \underset{i \neq j} \cap S_j = \emptyset)$$$ and sets his password as $$$P_i = \max\limits_{j \notin S_i} A[j]$$$. In other words, the $$$i$$$-th integer in the password is equal to the maximum over all elements of $$$A$$$ whose indices do not belong to $$$S_i$$$.You are given the subsets of indices chosen by Ayush. You need to guess the password. To make a query, you can choose a non-empty subset of indices of the array and ask the maximum of all elements of the array with index in this subset. You can ask no more than 12 queries.
256 megabytes
import javax.swing.plaf.synth.SynthEditorPaneUI; import java.io.*; import java.util.*; public class Contest1 { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int t = sc.nextInt(); while (t-->0){ int n = sc.nextInt(); int k = sc.nextInt(); HashSet<Integer>hs = new HashSet<>(); for (int i =1;i<=n;i++)hs.add(i); ArrayList<Integer>[]arr = new ArrayList[k]; int all=0; for (int i =0;i<k;i++){ arr[i]=new ArrayList<>(); int c = sc.nextInt(); all+=c; while (c-->0){ int x = sc.nextInt(); arr[i].add(x); } } pw.print("? "+n+" "); for (int i =1;i<=n;i++){ pw.print(i+" "); } pw.println(); pw.flush(); int mx= sc.nextInt(); int low =1; int hi=n; int need=-1; while (low<=hi){ int mid =low+hi>>1; pw.print("? "+(mid-low+1)+" "); for (int i =low;i<=mid;i++){ pw.print(i+" "); } pw.println(); pw.flush(); int c = sc.nextInt(); if (c==mx){ need=mid; hi=mid-1; } else { low=mid+1; } } int[]ans = new int[k]; Arrays.fill(ans,mx); System.err.println(need); w:for (int i =0;i<k;i++){ for (int c:arr[i]){ if (c==need){ pw.print("? "+(n-arr[i].size())+" "); for (int j=1;j<=n;j++){ if (arr[i].contains(j)) continue ; pw.print(j+" "); } pw.println(); pw.flush(); ans[i]=sc.nextInt(); break w; } } } pw.print("! "); for (int x:ans) pw.print(x+" "); pw.println(); pw.flush(); sc.next(); } pw.flush(); } static long gcd(long a,long b){ if (a==0) return b; return gcd(b%a,a); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(FileReader r) { br = new BufferedReader(r); } public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public boolean ready() throws IOException { return br.ready(); } } }
Java
["1\n4 2\n2 1 3\n2 2 4\n\n1\n\n2\n\n3\n\n4\n\nCorrect"]
2 seconds
["? 1 1\n\n? 1 2\n\n? 1 3\n\n? 1 4\n\n! 4 3"]
NoteThe array $$$A$$$ in the example is $$$[1, 2, 3, 4]$$$. The length of the password is $$$2$$$. The first element of the password is the maximum of $$$A[2]$$$, $$$A[4]$$$ (since the first subset contains indices $$$1$$$ and $$$3$$$, we take maximum over remaining indices). The second element of the password is the maximum of $$$A[1]$$$, $$$A[3]$$$ (since the second subset contains indices $$$2$$$, $$$4$$$).Do not forget to read the string "Correct" / "Incorrect" after guessing the password.
Java 11
standard input
[ "math", "binary search", "implementation", "interactive" ]
b0bce8524eb69b695edc1394ff86b913
The first line of the input contains a single integer $$$t$$$ $$$(1 \leq t \leq 10)$$$ — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ $$$(2 \leq n \leq 1000, 1 \leq k \leq n)$$$ — the size of the array and the number of subsets. $$$k$$$ lines follow. The $$$i$$$-th line contains an integer $$$c$$$ $$$(1 \leq c \lt n)$$$ — the size of subset $$$S_i$$$, followed by $$$c$$$ distinct integers in the range $$$[1, n]$$$  — indices from the subset $$$S_i$$$. It is guaranteed that the intersection of any two subsets is empty.
2,100
null
standard output
PASSED
3e74719a1ecc02293bd69f4be8393a9c
train_002.jsonl
1590935700
This is an interactive problem.Ayush devised a new scheme to set the password of his lock. The lock has $$$k$$$ slots where each slot can hold integers from $$$1$$$ to $$$n$$$. The password $$$P$$$ is a sequence of $$$k$$$ integers each in the range $$$[1, n]$$$, $$$i$$$-th element of which goes into the $$$i$$$-th slot of the lock.To set the password of his lock, Ayush comes up with an array $$$A$$$ of $$$n$$$ integers each in the range $$$[1, n]$$$ (not necessarily distinct). He then picks $$$k$$$ non-empty mutually disjoint subsets of indices $$$S_1, S_2, ..., S_k$$$ $$$(S_i \underset{i \neq j} \cap S_j = \emptyset)$$$ and sets his password as $$$P_i = \max\limits_{j \notin S_i} A[j]$$$. In other words, the $$$i$$$-th integer in the password is equal to the maximum over all elements of $$$A$$$ whose indices do not belong to $$$S_i$$$.You are given the subsets of indices chosen by Ayush. You need to guess the password. To make a query, you can choose a non-empty subset of indices of the array and ask the maximum of all elements of the array with index in this subset. You can ask no more than 12 queries.
256 megabytes
import java.io.*; import java.util.*; import java.math.*; public class D { static final boolean RUN_TIMING = false; static PushbackReader in = new PushbackReader(new BufferedReader(new InputStreamReader(System.in)), 1024); static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), true); public void go() throws IOException { // in = new PushbackReader(new BufferedReader(new FileReader(new File("test.txt"))), 1024); // out = new PrintWriter(new FileWriter(new File("output.txt"))); int zzz = ipar(); for (int zz = 0; zz < zzz; zz++) { int n = ipar(); int k = ipar(); int[][] subsets = new int[k][]; for (int i = 0; i < k; i++) { subsets[i] = iapar(ipar()); } out.print("? "); out.print(n); for (int i = 1; i <= n; i++) { out.print(" "); out.print(i); } out.println(); int max = ipar(); int l = 1; int r = n; while (l < r) { int mid = (l+r)/2; out.print("? "); out.print(mid-l+1); for (int i = l; i <= mid; i++) { out.print(" "); out.print(i); } out.println(); int m = ipar(); if (max == m) { r = mid; } else { l = mid+1; } } int[] pass = new int[k]; for (int i = 0; i < k; i++) { boolean has = false; for (int e = 0; e < subsets[i].length; e++) { if (subsets[i][e] == l) { has = true; break; } } if (!has) { pass[i] = max; } else { out.print("? "); out.print(n - subsets[i].length); HashSet<Integer> set = new HashSet<>(); for (int x : subsets[i]) { set.add(x); } for (int e = 1; e <= n; e++) { if (!set.contains(e)) { out.print(" "); out.print(e); } } out.println(); pass[i] = ipar(); } } out.print("!"); for (int x : pass) { out.print(" "); out.print(x); } out.println(); String result = spar(); if (!result.equals("Correct")) { break; } } } public int ipar() throws IOException { return Integer.parseInt(spar()); } public int[] iapar(int n) throws IOException { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = ipar(); } return arr; } public long lpar() throws IOException { return Long.parseLong(spar()); } public long[] lapar(int n) throws IOException { long[] arr = new long[n]; for (int i = 0; i < n; i++) { arr[i] = lpar(); } return arr; } public double dpar() throws IOException { return Double.parseDouble(spar()); } public String spar() throws IOException { StringBuilder sb = new StringBuilder(1024); int c; do { c = in.read(); } while (Character.isWhitespace(c) && c != -1); if (c == -1) { throw new NoSuchElementException("Reached EOF"); } do { sb.append((char)c); c = in.read(); } while (!Character.isWhitespace(c) && c != -1); while (c != '\n' && Character.isWhitespace(c) && c != -1) { c = in.read(); } if (c != -1 && c != '\n') { in.unread(c); } return sb.toString(); } public String linepar() throws IOException { StringBuilder sb = new StringBuilder(1024); int c; while ((c = in.read()) != '\n' && c != -1) { if (c == '\r') { continue; } sb.append((char)c); } return sb.toString(); } public boolean haspar() throws IOException { String line = linepar(); if (line.isEmpty()) { return false; } in.unread('\n'); in.unread(line.toCharArray()); return true; } public static void main(String[] args) throws IOException { long time = 0; time -= System.nanoTime(); new D().go(); time += System.nanoTime(); if (RUN_TIMING) { System.out.printf("%.3f ms%n", time / 1000000.0); } out.flush(); in.close(); } }
Java
["1\n4 2\n2 1 3\n2 2 4\n\n1\n\n2\n\n3\n\n4\n\nCorrect"]
2 seconds
["? 1 1\n\n? 1 2\n\n? 1 3\n\n? 1 4\n\n! 4 3"]
NoteThe array $$$A$$$ in the example is $$$[1, 2, 3, 4]$$$. The length of the password is $$$2$$$. The first element of the password is the maximum of $$$A[2]$$$, $$$A[4]$$$ (since the first subset contains indices $$$1$$$ and $$$3$$$, we take maximum over remaining indices). The second element of the password is the maximum of $$$A[1]$$$, $$$A[3]$$$ (since the second subset contains indices $$$2$$$, $$$4$$$).Do not forget to read the string "Correct" / "Incorrect" after guessing the password.
Java 11
standard input
[ "math", "binary search", "implementation", "interactive" ]
b0bce8524eb69b695edc1394ff86b913
The first line of the input contains a single integer $$$t$$$ $$$(1 \leq t \leq 10)$$$ — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ $$$(2 \leq n \leq 1000, 1 \leq k \leq n)$$$ — the size of the array and the number of subsets. $$$k$$$ lines follow. The $$$i$$$-th line contains an integer $$$c$$$ $$$(1 \leq c \lt n)$$$ — the size of subset $$$S_i$$$, followed by $$$c$$$ distinct integers in the range $$$[1, n]$$$  — indices from the subset $$$S_i$$$. It is guaranteed that the intersection of any two subsets is empty.
2,100
null
standard output
PASSED
1e3f9c19ee7700aa08f0ab723d7ebfea
train_002.jsonl
1590935700
This is an interactive problem.Ayush devised a new scheme to set the password of his lock. The lock has $$$k$$$ slots where each slot can hold integers from $$$1$$$ to $$$n$$$. The password $$$P$$$ is a sequence of $$$k$$$ integers each in the range $$$[1, n]$$$, $$$i$$$-th element of which goes into the $$$i$$$-th slot of the lock.To set the password of his lock, Ayush comes up with an array $$$A$$$ of $$$n$$$ integers each in the range $$$[1, n]$$$ (not necessarily distinct). He then picks $$$k$$$ non-empty mutually disjoint subsets of indices $$$S_1, S_2, ..., S_k$$$ $$$(S_i \underset{i \neq j} \cap S_j = \emptyset)$$$ and sets his password as $$$P_i = \max\limits_{j \notin S_i} A[j]$$$. In other words, the $$$i$$$-th integer in the password is equal to the maximum over all elements of $$$A$$$ whose indices do not belong to $$$S_i$$$.You are given the subsets of indices chosen by Ayush. You need to guess the password. To make a query, you can choose a non-empty subset of indices of the array and ask the maximum of all elements of the array with index in this subset. You can ask no more than 12 queries.
256 megabytes
import java.io.*; import java.util.*; import static java.lang.Math.*; import static java.util.Arrays.*; public class cf1363d { public static void main(String[] args) throws IOException { int t = ri(); next: while(t --> 0) { int n = rni(), k = ni(), s[][] = new int[k][]; for(int i = 0; i < k; ++i) { int c = rni(); s[i] = new int[c]; for(int j = 0; j < c; ++j) { s[i][j] = ni(); } } int l = 1, r = n; int max = qry(l, r); while(l < r) { int m = l + (r - l) / 2; int qry = qry(l, m); if(qry == -1) { throw new RuntimeException("too many queries"); } if(qry == max) { r = m; } else { l = m + 1; } } for(int i = 0; i < k; ++i) { for(int j = 0; j < s[i].length; ++j) { if(s[i][j] == l) { int notmax = qry(n, s[i]), ans[] = new int[k]; for(int ii = 0; ii < k; ++ii) { if(ii == i) { ans[ii] = notmax; } else { ans[ii] = max; } } pr("! "); prln(ans); flush(); if("Correct".equals(rline())) { continue next; } else { throw new RuntimeException("incorrect"); } } } } int ans[] = new int[k]; fill(ans, max); pr("! "); prln(ans); flush(); if(!"Correct".equals(rline())) { throw new RuntimeException("incorrect"); } } close(); } static int qry(int n, int... x) throws IOException { pr("? "); pr(n - x.length); Set<Integer> s = new HashSet<>(); for(int i : x) { s.add(i); } for(int i = 1; i <= n; ++i) { if(!s.contains(i)) { pr(' '); pr(i); } } prln(); flush(); return ri(); } static int qry(int l, int r) throws IOException { pr("? "); pr(r - l + 1); for(int i = l; i <= r; ++i) { pr(' '); pr(i); } prln(); flush(); return ri(); } static BufferedReader __in = new BufferedReader(new InputStreamReader(System.in)); static PrintWriter __out = new PrintWriter(new OutputStreamWriter(System.out)); static StringTokenizer input; static Random rand = new Random(); // references // IBIG = 1e9 + 7 // IMAX ~= 2e10 // LMAX ~= 9e18 // constants static final int IBIG = 1000000007; static final int IMAX = 2147483647; static final int IMIN = -2147483648; static final long LMAX = 9223372036854775807L; static final long LMIN = -9223372036854775808L; // math util static int minof(int a, int b, int c) {return min(a, min(b, c));} static int minof(int... x) {if(x.length == 1) return x[0]; if(x.length == 2) return min(x[0], x[1]); if(x.length == 3) return min(x[0], min(x[1], x[2])); int min = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] < min) min = x[i]; return min;} static long minof(long a, long b, long c) {return min(a, min(b, c));} static long minof(long... x) {if(x.length == 1) return x[0]; if(x.length == 2) return min(x[0], x[1]); if(x.length == 3) return min(x[0], min(x[1], x[2])); long min = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] < min) min = x[i]; return min;} static int maxof(int a, int b, int c) {return max(a, max(b, c));} static int maxof(int... x) {if(x.length == 1) return x[0]; if(x.length == 2) return max(x[0], x[1]); if(x.length == 3) return max(x[0], max(x[1], x[2])); int max = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] > max) max = x[i]; return max;} static long maxof(long a, long b, long c) {return max(a, max(b, c));} static long maxof(long... x) {if(x.length == 1) return x[0]; if(x.length == 2) return max(x[0], x[1]); if(x.length == 3) return max(x[0], max(x[1], x[2])); long max = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] > max) max = x[i]; return max;} static int powi(int a, int b) {if(a == 0) return 0; int ans = 1; while(b > 0) {if((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;} static long powl(long a, int b) {if(a == 0) return 0; long ans = 1; while(b > 0) {if((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;} static int floori(double d) {return (int)d;} static int ceili(double d) {return (int)ceil(d);} static long floorl(double d) {return (long)d;} static long ceill(double d) {return (long)ceil(d);} static int randInt(int min, int max) {return rand.nextInt(max - min + 1) + min;} // array util static void reverse(int[] a) {for(int i = 0, n = a.length, half = n / 2; i < half; ++i) {int swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}} static void reverse(long[] a) {for(int i = 0, n = a.length, half = n / 2; i < half; ++i) {long swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}} static void reverse(double[] a) {for(int i = 0, n = a.length, half = n / 2; i < half; ++i) {double swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}} static void reverse(char[] a) {for(int i = 0, n = a.length, half = n / 2; i < half; ++i) {char swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}} static <T> void reverse(T[] a) {for(int i = 0, n = a.length, half = n / 2; i < half; ++i) {T swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}} static void shuffle(int[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); int swap = a[i]; a[i] = a[ind]; a[ind] = swap;}} static void shuffle(long[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); long swap = a[i]; a[i] = a[ind]; a[ind] = swap;}} static void shuffle(double[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); double swap = a[i]; a[i] = a[ind]; a[ind] = swap;}} static void shuffle(char[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); char swap = a[i]; a[i] = a[ind]; a[ind] = swap;}} static <T> void shuffle(T[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); T swap = a[i]; a[i] = a[ind]; a[ind] = swap;}} static void rsort(int[] a) {shuffle(a); sort(a);} static void rsort(long[] a) {shuffle(a); sort(a);} static void rsort(double[] a) {shuffle(a); sort(a);} static void rsort(char[] a) {shuffle(a); sort(a);} static <T> void rsort(T[] a) {shuffle(a); sort(a);} // graph util static List<List<Integer>> graph(int n) {List<List<Integer>> g = new ArrayList<>(); for(int i = 0; i < n; ++i) g.add(new ArrayList<>()); return g;} static void connect(List<List<Integer>> g, int u, int v) {g.get(u).add(v); g.get(v).add(u);} static void connectDirected(List<List<Integer>> g, int u, int v) {g.get(u).add(v);}; // input static void r() throws IOException {input = new StringTokenizer(__in.readLine());} static int ri() throws IOException {return Integer.parseInt(__in.readLine());} static long rl() throws IOException {return Long.parseLong(__in.readLine());} static int[] ria(int n) throws IOException {int[] a = new int[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Integer.parseInt(input.nextToken()); return a;} static int[] riam1(int n) throws IOException {int[] a = new int[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Integer.parseInt(input.nextToken()) - 1; return a;} static long[] rla(int n) throws IOException {long[] a = new long[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Long.parseLong(input.nextToken()); return a;} static char[] rcha() throws IOException {return __in.readLine().toCharArray();} static String rline() throws IOException {return __in.readLine();} static int rni() throws IOException {input = new StringTokenizer(__in.readLine()); return Integer.parseInt(input.nextToken());} static int ni() {return Integer.parseInt(input.nextToken());} static long rnl() throws IOException {input = new StringTokenizer(__in.readLine()); return Long.parseLong(input.nextToken());} static long nl() {return Long.parseLong(input.nextToken());} // output static void pr(int i) {__out.print(i);} static void prln(int i) {__out.println(i);} static void pr(long l) {__out.print(l);} static void prln(long l) {__out.println(l);} static void pr(double d) {__out.print(d);} static void prln(double d) {__out.println(d);} static void pr(char c) {__out.print(c);} static void prln(char c) {__out.println(c);} static void pr(char[] s) {__out.print(new String(s));} static void prln(char[] s) {__out.println(new String(s));} static void pr(String s) {__out.print(s);} static void prln(String s) {__out.println(s);} static void pr(Object o) {__out.print(o);} static void prln(Object o) {__out.println(o);} static void prln() {__out.println();} static void pryes() {__out.println("yes");} static void pry() {__out.println("Yes");} static void prY() {__out.println("YES");} static void prno() {__out.println("no");} static void prn() {__out.println("No");} static void prN() {__out.println("NO");} static void pryesno(boolean b) {__out.println(b ? "yes" : "no");}; static void pryn(boolean b) {__out.println(b ? "Yes" : "No");} static void prYN(boolean b) {__out.println(b ? "YES" : "NO");} static void prln(int... a) {for(int i = 0, len = a.length - 1; i < len; __out.print(a[i]), __out.print(' '), ++i); __out.println(a[a.length - 1]);} static void prln(long... a) {for(int i = 0, len = a.length - 1; i < len; __out.print(a[i]), __out.print(' '), ++i); __out.println(a[a.length - 1]);} static <T> void prln(Collection<T> c) {int n = c.size() - 1; Iterator<T> iter = c.iterator(); for(int i = 0; i < n; __out.print(iter.next()), __out.print(' '), ++i); __out.println(iter.next());} static void h() {__out.println("hlfd");} static void flush() {__out.flush();} static void close() {__out.close();} }
Java
["1\n4 2\n2 1 3\n2 2 4\n\n1\n\n2\n\n3\n\n4\n\nCorrect"]
2 seconds
["? 1 1\n\n? 1 2\n\n? 1 3\n\n? 1 4\n\n! 4 3"]
NoteThe array $$$A$$$ in the example is $$$[1, 2, 3, 4]$$$. The length of the password is $$$2$$$. The first element of the password is the maximum of $$$A[2]$$$, $$$A[4]$$$ (since the first subset contains indices $$$1$$$ and $$$3$$$, we take maximum over remaining indices). The second element of the password is the maximum of $$$A[1]$$$, $$$A[3]$$$ (since the second subset contains indices $$$2$$$, $$$4$$$).Do not forget to read the string "Correct" / "Incorrect" after guessing the password.
Java 11
standard input
[ "math", "binary search", "implementation", "interactive" ]
b0bce8524eb69b695edc1394ff86b913
The first line of the input contains a single integer $$$t$$$ $$$(1 \leq t \leq 10)$$$ — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ $$$(2 \leq n \leq 1000, 1 \leq k \leq n)$$$ — the size of the array and the number of subsets. $$$k$$$ lines follow. The $$$i$$$-th line contains an integer $$$c$$$ $$$(1 \leq c \lt n)$$$ — the size of subset $$$S_i$$$, followed by $$$c$$$ distinct integers in the range $$$[1, n]$$$  — indices from the subset $$$S_i$$$. It is guaranteed that the intersection of any two subsets is empty.
2,100
null
standard output
PASSED
50f448d8775f0aa3925346090396d56d
train_002.jsonl
1590935700
This is an interactive problem.Ayush devised a new scheme to set the password of his lock. The lock has $$$k$$$ slots where each slot can hold integers from $$$1$$$ to $$$n$$$. The password $$$P$$$ is a sequence of $$$k$$$ integers each in the range $$$[1, n]$$$, $$$i$$$-th element of which goes into the $$$i$$$-th slot of the lock.To set the password of his lock, Ayush comes up with an array $$$A$$$ of $$$n$$$ integers each in the range $$$[1, n]$$$ (not necessarily distinct). He then picks $$$k$$$ non-empty mutually disjoint subsets of indices $$$S_1, S_2, ..., S_k$$$ $$$(S_i \underset{i \neq j} \cap S_j = \emptyset)$$$ and sets his password as $$$P_i = \max\limits_{j \notin S_i} A[j]$$$. In other words, the $$$i$$$-th integer in the password is equal to the maximum over all elements of $$$A$$$ whose indices do not belong to $$$S_i$$$.You are given the subsets of indices chosen by Ayush. You need to guess the password. To make a query, you can choose a non-empty subset of indices of the array and ask the maximum of all elements of the array with index in this subset. You can ask no more than 12 queries.
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class Main { static PrintWriter out = new PrintWriter(System.out); static Reader in = new Reader(); public static void main(String[] args) throws IOException { Main solver = new Main(); solver.solve(); out.flush(); out.close(); } static int INF = (int)1e9; static int maxn = (int)1e5+5; static int mod = 998244353; static int n,m,q,k,t; void solve() throws IOException{ t = in.nextInt(); while (t --> 0) { n = in.nextInt(); k = in.nextInt(); ArrayList<Integer> arr[] = new ArrayList[k]; for (int i = 0; i < k; i++) arr[i] = new ArrayList<Integer>(); int[] pos = new int[n+1]; for (int i = 0; i < k; i++) { m = in.nextInt(); int tmp; for (int j = 0; j < m; j++) { tmp = in.nextInt(); arr[i].add(tmp); pos[tmp] = i+1; } } if (k == 1) { print(arr[0]); int res = in.nextInt(); out.println("! "+res); out.flush(); String s = in.next(); if (s.compareTo("Correct") == 0) continue; else return; } int max; out.print("? "+n); ArrayList<Integer> a = new ArrayList<>(); for (int i = 1; i <= n; i++) { out.print(" "+i); a.add(i); } out.println(); out.flush(); max = in.nextInt(); int[] ans = new int[k+1]; int maxi = 0; maxi = pos[bs(a, max)]; for (int i = 1; i <= k; i++) ans[i] = max; if (maxi != 0) { print(arr[maxi-1]); ans[maxi] = in.nextInt(); } out.print("!"); for (int i = 1; i <= k; i++) out.print(" "+ans[i]); out.println(); out.flush(); String s = in.next(); if (s.compareTo("Correct") != 0) return; } } //<> static int bs(ArrayList<Integer> a, int x) { int lo = 0, hi = a.size()-1, mid; int tmp = 0; while (lo < hi) { mid = (lo+hi)/2; printRange(a, lo, mid); tmp = in.nextInt(); if (tmp == x) { hi = mid; } else lo = mid+1; } return a.get(lo); } static void printRange(ArrayList<Integer> a, int l, int r) { out.print("? "+(r-l+1)); for (int i = l; i <= r; i++) { out.print(" "+a.get(i)); } out.println(); out.flush(); } static void print(ArrayList<Integer> a) { boolean[] vis = new boolean[n+1]; for (int e: a) vis[e] = true; int size = n-a.size(); out.print("? "+size); for (int i = 1; i <= n; i++) if (!vis[i]) out.print(" "+i); out.println(); out.flush(); } static class Reader { private InputStream mIs; private byte[] buf = new byte[1024]; private int curChar; private int numChars; public Reader() { this(System.in); } public Reader(InputStream is) { mIs = is; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = mIs.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public String nextLine() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); } public String next() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } double nextDouble() { return Double.parseDouble(next()); } public long nextLong() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } } }
Java
["1\n4 2\n2 1 3\n2 2 4\n\n1\n\n2\n\n3\n\n4\n\nCorrect"]
2 seconds
["? 1 1\n\n? 1 2\n\n? 1 3\n\n? 1 4\n\n! 4 3"]
NoteThe array $$$A$$$ in the example is $$$[1, 2, 3, 4]$$$. The length of the password is $$$2$$$. The first element of the password is the maximum of $$$A[2]$$$, $$$A[4]$$$ (since the first subset contains indices $$$1$$$ and $$$3$$$, we take maximum over remaining indices). The second element of the password is the maximum of $$$A[1]$$$, $$$A[3]$$$ (since the second subset contains indices $$$2$$$, $$$4$$$).Do not forget to read the string "Correct" / "Incorrect" after guessing the password.
Java 11
standard input
[ "math", "binary search", "implementation", "interactive" ]
b0bce8524eb69b695edc1394ff86b913
The first line of the input contains a single integer $$$t$$$ $$$(1 \leq t \leq 10)$$$ — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ $$$(2 \leq n \leq 1000, 1 \leq k \leq n)$$$ — the size of the array and the number of subsets. $$$k$$$ lines follow. The $$$i$$$-th line contains an integer $$$c$$$ $$$(1 \leq c \lt n)$$$ — the size of subset $$$S_i$$$, followed by $$$c$$$ distinct integers in the range $$$[1, n]$$$  — indices from the subset $$$S_i$$$. It is guaranteed that the intersection of any two subsets is empty.
2,100
null
standard output
PASSED
6f5ce4689f0683941eb606a0cde0cb4e
train_002.jsonl
1590935700
This is an interactive problem.Ayush devised a new scheme to set the password of his lock. The lock has $$$k$$$ slots where each slot can hold integers from $$$1$$$ to $$$n$$$. The password $$$P$$$ is a sequence of $$$k$$$ integers each in the range $$$[1, n]$$$, $$$i$$$-th element of which goes into the $$$i$$$-th slot of the lock.To set the password of his lock, Ayush comes up with an array $$$A$$$ of $$$n$$$ integers each in the range $$$[1, n]$$$ (not necessarily distinct). He then picks $$$k$$$ non-empty mutually disjoint subsets of indices $$$S_1, S_2, ..., S_k$$$ $$$(S_i \underset{i \neq j} \cap S_j = \emptyset)$$$ and sets his password as $$$P_i = \max\limits_{j \notin S_i} A[j]$$$. In other words, the $$$i$$$-th integer in the password is equal to the maximum over all elements of $$$A$$$ whose indices do not belong to $$$S_i$$$.You are given the subsets of indices chosen by Ayush. You need to guess the password. To make a query, you can choose a non-empty subset of indices of the array and ask the maximum of all elements of the array with index in this subset. You can ask no more than 12 queries.
256 megabytes
//package cf646; import java.io.*; import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; // What's the smallest input? // Check * for int/long overflow. // Check / for accidental rounding. // Are you using doubles? Can you avoid it? // Never compare after taking mod. // Mod the final result. // Initialize globals in solve() unless they are independent of the problem input. // Check for local/global name conflicts (n?). // Check initial values for max/min (not Integer.MIN_VALUE for long). public class D { static Random rand; static boolean MULTIPLE_CASES = true; static boolean CONSTRUCTIVE = false; static long MOD = (long) 1e9 + 7; static long BIG = (long) 2e9 + 10; static class Maximum { int ind, val; public Maximum(int ind, int val) { this.ind = ind; this.val = val; } } public static void solve(Reader in, PrintWriter out) { int n = in.ni(), k = in.ni(); Set<Integer>[] subsets = new Set[k]; for (int i = 0; i < k; i++) { int size = in.ni(); subsets[i] = new HashSet<>(size); for (int j = 0; j < size; j++) subsets[i].add(in.ni()); } Maximum max = getMaximum(n, in, out); int[] ans = new int[k]; for (int i = 0; i < k; i++) { if (subsets[i].contains(max.ind)) { ans[i] = querySubset(allBut(subsets[i], n), in, out); } else { ans[i] = max.val; } } out.print("! "); for (int i : ans) { out.print(i + " "); } out.println(); out.flush(); String result = in.next(); } static Set<Integer> allBut(Set<Integer> set, int n) { Set<Integer> out = new HashSet<>(); for (int i = 1; i <= n; i++) { if (!set.contains(i)) out.add(i); } return out; } static Maximum getMaximum(int n, Reader in, PrintWriter out) { int min = 1; int max = n; int mid = (min + max) / 2; int cand1 = queryRange(min, mid, in, out); int cand2 = queryRange(mid+1, max, in, out); int maxElt; if (cand1 > cand2) { max = mid; maxElt = cand1; } else { min = mid+1; maxElt = cand2; } while (min < max) { mid = (min + max) / 2; if (queryRange(min, mid, in, out) == maxElt) { max = mid; } else { min = mid + 1; } } return new Maximum(min, maxElt); } // incl static int queryRange(int l, int r, Reader in, PrintWriter out) { out.print("? " + (r - l + 1) + " "); for (int i = l; i <= r; i++) { out.print(i + " "); } out.println(); out.flush(); return in.ni(); } static int querySubset(Set<Integer> set, Reader in, PrintWriter out) { out.print("? " + set.size() + " "); for (int i : set) out.print(i + " "); out.println(); out.flush(); return in.ni(); } public static void main(String[] args) throws IOException { Reader in = null; PrintWriter out = null; for (String arg : args) { if (arg.startsWith("input")) { in = new Reader(arg); } else if (arg.startsWith("output")) { out = new PrintWriter(new FileWriter(arg)); } } if (in == null) in = new Reader(); if (out == null) out = new PrintWriter(new OutputStreamWriter(System.out)); if (MULTIPLE_CASES) { int tests = in.ni(); for (int t = 0; t < tests; t++) { solve(in, out); } } else { solve(in, out); } out.flush(); } static class Tester { public static void main(String[] args) throws IOException { Validator validator = new Validator(); File currentDir = new File("."); long before; long after; for (File inputFile : Arrays.stream(currentDir.listFiles()) .sorted(Comparator.comparing(File::getName)) .collect(Collectors.toList())) { if (!inputFile.getName().startsWith("input") || inputFile.getName().contains("sight") || inputFile.getName().contains("big")) continue; System.out.println("Test file: " + inputFile.getName()); before = System.nanoTime(); String outputFileName = "output" + inputFile.getName().substring(5); D.main(new String[]{inputFile.getName(), outputFileName}); after = System.nanoTime(); File outputFile = new File(outputFileName); if (!outputFile.exists()) { throw new IllegalStateException("Missing output file " + outputFile); } // TODO if verifier is implemented, remove this if (CONSTRUCTIVE) { System.out.println("INPUT:"); printFile(inputFile); System.out.printf("\nOUTPUT: (%d milliseconds)\n", (after - before) / 1000000L); printFile(outputFile); continue; } if (validator.validate(inputFile, outputFile)) { System.out.printf("OK (%d milliseconds)\n", (after - before) / 1000000L); } else { System.out.println("FAILED"); System.out.println("\nInput: "); printFile(inputFile); System.out.println("\nIncorrect Output: "); printFile(outputFile); return; } } System.out.println("\n-----------------\n"); File sightTestInput = new File("input-sight"); if (sightTestInput.exists()) { System.out.println("Running sight test... Input:"); printFile(sightTestInput); before = System.nanoTime(); System.out.println("\nOutput: "); D.main(new String[]{"input-sight"}); after = System.nanoTime(); System.out.printf("(%d milliseconds)\n", (after - before) / 1000000L); System.out.println("\n-----------------\n"); } File bigTestInput = new File("input-big"); if (bigTestInput.exists()) { System.out.println("Running big test..."); before = System.nanoTime(); D.main(new String[]{"input-big"}); after = System.nanoTime(); System.out.printf("(%d milliseconds)\n", (after - before) / 1000000L); } } static void printFile(File file) throws FileNotFoundException { BufferedReader reader = new BufferedReader(new FileReader(file)); reader.lines().forEach(System.out::println); } } static class Validator { boolean validate(File inputFile, File outputFile) throws IOException { File expectedOutputFile = new File("expected-output" + inputFile.getName().substring(5)); if (CONSTRUCTIVE || !expectedOutputFile.exists()) { return validateManual(inputFile, outputFile); } return areSame(outputFile, expectedOutputFile); } private boolean validateManual(File inputFile, File outputFile) throws IOException { if (CONSTRUCTIVE) { // Validate output against input Reader inputReader = new Reader(inputFile.getName()); Reader outputReader = new Reader(outputFile.getName()); // TODO implement manual validation throw new IllegalStateException("Missing expected output file"); } else { File naiveOutput = new File("naive-" + outputFile.getName()); Naive.main(new String[]{inputFile.getName(), naiveOutput.getName()}); return areSame(outputFile, naiveOutput); } } private boolean areSame(File file1, File file2) throws IOException { BufferedReader reader1 = new BufferedReader(new FileReader(file1)); BufferedReader reader2 = new BufferedReader(new FileReader(file2)); String line1; while ((line1 = reader1.readLine()) != null) { String line2 = reader2.readLine(); if (line2 == null) line2 = ""; // ok if one has an extra newline if (!line1.trim().equals(line2.trim())) { return false; } } String line2; while ((line2 = reader2.readLine()) != null) { if (!line2.trim().isEmpty()) { return false; } } return true; } } static class Naive { public static void solveNaive(Reader in, PrintWriter out) { throw new IllegalStateException("missing expected output file"); } public static void main(String[] args) throws IOException { Reader in = null; PrintWriter out = null; for (String arg : args) { if (arg.startsWith("input")) { in = new Reader(arg); } else if (arg.startsWith("naive-output")) { out = new PrintWriter(new FileWriter(arg)); } } if (in == null) in = new Reader(); if (out == null) out = new PrintWriter(new OutputStreamWriter(System.out)); int tests = in.ni(); for (int t = 0; t < tests; t++) { solveNaive(in, out); } out.flush(); out.close(); } } static boolean isPowerOfTwo(int x) { return x > 0 & (x & (x - 1)) == 0; } static int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } static void ruffleSort(int[] a) { int n = a.length; for (int i = 0; i < n; i++) { int oi = rand.nextInt(n), temp = a[oi]; a[oi] = a[i]; a[i] = temp; } Arrays.sort(a); } static void ruffleSort(long[] a) { int n = a.length; for (int i = 0; i < n; i++) { int oi = rand.nextInt(n); long temp = a[oi]; a[oi] = a[i]; a[i] = temp; } Arrays.sort(a); } /////////////////////////////////// ////////// FAST PAIR ////////// /////////////////////////////////// // Works on -1e9 <= x, y <= 1e9 static long pair(int x, int y) { x = (int) BIG / 2 - x; y = (int) BIG / 2 - y; return x * BIG + y; } static int x(long pair) { return (int) BIG / 2 - (int) (pair / BIG); } static int y(long pair) { return (int) BIG / 2 - (int) (pair % BIG); } static String str(long pair) { return String.format("(%d, %d)", x(pair), y(pair)); } /////////////////////////////////// ////////// BINARY SEARCH ////////// /////////////////////////////////// // return highest in range that still returns true // T T T F F F F // invariant: // - indicator(min) = true // - indicator(max+1) = false static int binarySearchHighest(int min, int max, Function<Integer, Boolean> indicator) { int a = min; int b = max; while (a != b) { int mid = (a % 2 != b % 2) ? 1 + (a + b) / 2 : (a + b) / 2; if (indicator.apply(mid)) { a = mid; } else { b = mid - 1; } } return a; } // return lowest in range that still returns true // F F F F T T T // invariant: // - indicator(min-1) = false // - indicator(max) = true static int binarySearchLowest(int min, int max, Function<Integer, Boolean> indicator) { int a = min; int b = max; while (a != b) { int mid = (a + b) / 2; if (indicator.apply(mid)) { b = mid; } else { a = mid + 1; } } return a; } static void insist(boolean bool) { if (!bool) throw new IllegalStateException(); } static class Reader { public BufferedReader reader; public StringTokenizer tokenizer; public Reader() { reader = new BufferedReader(new InputStreamReader(System.in), 32768); tokenizer = null; } public Reader(String fileName) throws FileNotFoundException { reader = new BufferedReader(new FileReader(fileName)); } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int ni() { return Integer.parseInt(next()); } public long nl() { return Long.parseLong(next()); } public int[] nis(int n) { int[] out = new int[n]; for (int i = 0; i < n; i++) { out[i] = ni(); } return out; } public long[] nls(int n) { long[] out = new long[n]; for (int i = 0; i < n; i++) { out[i] = nl(); } return out; } } }
Java
["1\n4 2\n2 1 3\n2 2 4\n\n1\n\n2\n\n3\n\n4\n\nCorrect"]
2 seconds
["? 1 1\n\n? 1 2\n\n? 1 3\n\n? 1 4\n\n! 4 3"]
NoteThe array $$$A$$$ in the example is $$$[1, 2, 3, 4]$$$. The length of the password is $$$2$$$. The first element of the password is the maximum of $$$A[2]$$$, $$$A[4]$$$ (since the first subset contains indices $$$1$$$ and $$$3$$$, we take maximum over remaining indices). The second element of the password is the maximum of $$$A[1]$$$, $$$A[3]$$$ (since the second subset contains indices $$$2$$$, $$$4$$$).Do not forget to read the string "Correct" / "Incorrect" after guessing the password.
Java 11
standard input
[ "math", "binary search", "implementation", "interactive" ]
b0bce8524eb69b695edc1394ff86b913
The first line of the input contains a single integer $$$t$$$ $$$(1 \leq t \leq 10)$$$ — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ $$$(2 \leq n \leq 1000, 1 \leq k \leq n)$$$ — the size of the array and the number of subsets. $$$k$$$ lines follow. The $$$i$$$-th line contains an integer $$$c$$$ $$$(1 \leq c \lt n)$$$ — the size of subset $$$S_i$$$, followed by $$$c$$$ distinct integers in the range $$$[1, n]$$$  — indices from the subset $$$S_i$$$. It is guaranteed that the intersection of any two subsets is empty.
2,100
null
standard output
PASSED
c7bb12b0b19f5fd7bff1e89cddb73a4b
train_002.jsonl
1590935700
This is an interactive problem.Ayush devised a new scheme to set the password of his lock. The lock has $$$k$$$ slots where each slot can hold integers from $$$1$$$ to $$$n$$$. The password $$$P$$$ is a sequence of $$$k$$$ integers each in the range $$$[1, n]$$$, $$$i$$$-th element of which goes into the $$$i$$$-th slot of the lock.To set the password of his lock, Ayush comes up with an array $$$A$$$ of $$$n$$$ integers each in the range $$$[1, n]$$$ (not necessarily distinct). He then picks $$$k$$$ non-empty mutually disjoint subsets of indices $$$S_1, S_2, ..., S_k$$$ $$$(S_i \underset{i \neq j} \cap S_j = \emptyset)$$$ and sets his password as $$$P_i = \max\limits_{j \notin S_i} A[j]$$$. In other words, the $$$i$$$-th integer in the password is equal to the maximum over all elements of $$$A$$$ whose indices do not belong to $$$S_i$$$.You are given the subsets of indices chosen by Ayush. You need to guess the password. To make a query, you can choose a non-empty subset of indices of the array and ask the maximum of all elements of the array with index in this subset. You can ask no more than 12 queries.
256 megabytes
//package round_646; import java.util.*; import java.io.*; public class Problem_D { static class Input { BufferedReader br; StringTokenizer st; public Input(Reader r) throws IOException { br = new BufferedReader(r); st = new StringTokenizer(br.readLine()); } public String nextLine() throws IOException { return br.readLine(); } public boolean hasNext() throws IOException { try { while(!st.hasMoreTokens()) { String s = br.readLine(); if(s==null) { return false; } st = new StringTokenizer(s); } return true; }catch (Exception e){ return false; } } public String next() throws IOException { if(!hasNext()) { return null; } return st.nextToken(); } public int nextInt() throws IOException { String s = next(); if(s==null) { return Integer.MIN_VALUE; } return Integer.parseInt(s); } public double nextDouble() throws IOException { String s = next(); if(s==null) { return Double.MIN_VALUE; } return Double.parseDouble(s); } public long nextLong() throws IOException { String s = next(); if(s==null) { return Long.MIN_VALUE; } return Long.parseLong(s); } public int countTokens() { return st.countTokens(); } public void close() throws IOException { br.close(); } } public static void main(String[] args) throws IOException{ // TODO Auto-generated method stub Problem_D program = new Problem_D(); program.Begin(); } void Begin() throws IOException{ Input in = new Input(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out)); int kase = in.nextInt(); while(kase-->0) { int n = in.nextInt(); int k = in.nextInt(); HashSet<Integer>[] al = new HashSet[k]; for(int i = 0; i<k; i++) { int c = in.nextInt(); al[i] = new HashSet<Integer>(); while(c-->0) { al[i].add(in.nextInt()); } } pw.printf("? %d",n); for(int i = 1; i<=n; i++) { pw.print(" "+i); } pw.println(); pw.flush(); int max = in.nextInt(); int l = 1, h = n; while(l<h) { int mid = (l+h)>>1; pw.printf("? %d",mid-l+1); for(int j = l; j<=mid; j++) { pw.print(" "+j); } pw.println(); pw.flush(); int x = in.nextInt(); if(x==max) { h = mid; }else { l = mid+1; } } int ind = -1; for(int j = 0; j<k; j++) { if(al[j].contains(l)) { ind = j; break; } } if(ind==-1) { pw.print("!"); for(int i = 0; i<k; i++) { pw.print(" "+max); } pw.println(); pw.flush(); }else { pw.printf("? %d", n-al[ind].size()); for(int i = 1; i<=n; i++) { if(!al[ind].contains(i)) { pw.print(" "+i); } } pw.println(); pw.flush(); int max2 = in.nextInt(); pw.print("!"); for(int i = 0; i<k; i++) { if(i!=ind) { pw.print(" "+max); }else { pw.print(" "+max2); } } pw.println(); pw.flush(); } String rep = in.next(); if(rep.equals("Incorrect")) { System.exit(0); } } pw.close(); in.close(); } }
Java
["1\n4 2\n2 1 3\n2 2 4\n\n1\n\n2\n\n3\n\n4\n\nCorrect"]
2 seconds
["? 1 1\n\n? 1 2\n\n? 1 3\n\n? 1 4\n\n! 4 3"]
NoteThe array $$$A$$$ in the example is $$$[1, 2, 3, 4]$$$. The length of the password is $$$2$$$. The first element of the password is the maximum of $$$A[2]$$$, $$$A[4]$$$ (since the first subset contains indices $$$1$$$ and $$$3$$$, we take maximum over remaining indices). The second element of the password is the maximum of $$$A[1]$$$, $$$A[3]$$$ (since the second subset contains indices $$$2$$$, $$$4$$$).Do not forget to read the string "Correct" / "Incorrect" after guessing the password.
Java 11
standard input
[ "math", "binary search", "implementation", "interactive" ]
b0bce8524eb69b695edc1394ff86b913
The first line of the input contains a single integer $$$t$$$ $$$(1 \leq t \leq 10)$$$ — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ $$$(2 \leq n \leq 1000, 1 \leq k \leq n)$$$ — the size of the array and the number of subsets. $$$k$$$ lines follow. The $$$i$$$-th line contains an integer $$$c$$$ $$$(1 \leq c \lt n)$$$ — the size of subset $$$S_i$$$, followed by $$$c$$$ distinct integers in the range $$$[1, n]$$$  — indices from the subset $$$S_i$$$. It is guaranteed that the intersection of any two subsets is empty.
2,100
null
standard output
PASSED
0e33166305844f84f1584714472b96a3
train_002.jsonl
1590935700
This is an interactive problem.Ayush devised a new scheme to set the password of his lock. The lock has $$$k$$$ slots where each slot can hold integers from $$$1$$$ to $$$n$$$. The password $$$P$$$ is a sequence of $$$k$$$ integers each in the range $$$[1, n]$$$, $$$i$$$-th element of which goes into the $$$i$$$-th slot of the lock.To set the password of his lock, Ayush comes up with an array $$$A$$$ of $$$n$$$ integers each in the range $$$[1, n]$$$ (not necessarily distinct). He then picks $$$k$$$ non-empty mutually disjoint subsets of indices $$$S_1, S_2, ..., S_k$$$ $$$(S_i \underset{i \neq j} \cap S_j = \emptyset)$$$ and sets his password as $$$P_i = \max\limits_{j \notin S_i} A[j]$$$. In other words, the $$$i$$$-th integer in the password is equal to the maximum over all elements of $$$A$$$ whose indices do not belong to $$$S_i$$$.You are given the subsets of indices chosen by Ayush. You need to guess the password. To make a query, you can choose a non-empty subset of indices of the array and ask the maximum of all elements of the array with index in this subset. You can ask no more than 12 queries.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; import java.util.*; public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); int t = in.nextInt(); for (int i=0;i<t;i++) { int n = in.nextInt(); int k = in.nextInt(); ArrayList<int[]> set_list = new ArrayList<int[]>(); ArrayList<Integer> list_index_ = new ArrayList<Integer>(); for (int j=0;j<k;j++) { int c = in.nextInt(); int[] S = new int[c]; for (int l=0;l<c;l++) { S[l] = in.nextInt(); } set_list.add(S); list_index_.add(j); } StringBuilder sb_ = new StringBuilder(); sb_.append("?"); sb_.append(" "+n); for (int j=0;j<n;j++) { sb_.append(" "+(j+1)); } out.println(sb_); out.flush(); int max = in.nextInt(); ArrayList<Integer> list_index = new ArrayList<Integer>(); for (int j=0;j<n;j++) list_index.add(j); int list_index_size = list_index.size(); while (list_index_size > 1) { StringBuilder sb = new StringBuilder(); sb.append("?"); int nums = 0; // for (int j=0;j<list_index.size()/2;j++) { // nums += set_list.get(j).length; // } nums += list_index.size()/2; sb.append(" "+nums); for (int j=0;j<list_index.size()/2;j++) { sb.append(" "+(list_index.get(j)+1)); // for (int l=0;l<set_list.get(list_index.get(j)).length;l++) { // sb.append(" "+(set_list.get(list_index.get(j))[l])); // } } out.println(sb); out.flush(); int x = in.nextInt(); // out.println(list_index); ArrayList<Integer> new_list_index = new ArrayList<Integer>(); if (x == max) { for (int j=0;j<list_index.size()/2;j++) new_list_index.add(list_index.get(j)); } else { // x < max for (int j=list_index.size()/2;j<list_index.size();j++) new_list_index.add(list_index.get(j)); } list_index = new_list_index; if (list_index.size() == 1) { StringBuilder ans = new StringBuilder(); StringBuilder last_q = new StringBuilder(); last_q.append("?"); int ssssss = 0; boolean[] indexxx = new boolean[n]; for (int j=0;j<k;j++) { boolean in_flagg = false; for (Integer tmp : set_list.get(j)) { indexxx[tmp-1] = true; if (tmp == list_index.get(0)+1) { in_flagg = true; } } if (!in_flagg) { ssssss += set_list.get(j).length; } } for (int j=0;j<n;j++) { if (!indexxx[j]) ssssss++; } // last_q.append(" "+(n-1)); last_q.append(" "+ssssss); for (int j=0;j<k;j++) { boolean in_flagg = false; for (Integer tmp : set_list.get(j)) { if (tmp == list_index.get(0)+1) { in_flagg = true; } } if (!in_flagg) { for (Integer tmp : set_list.get(j)) { last_q.append(" "+(tmp)); } } } for (int j=0;j<n;j++) { if (!indexxx[j]) last_q.append(" "+(j+1)); } // for (int j=0;j<n;j++) { // if (j != list_index.get(0)) { // last_q.append(" "+(j+1)); // } // } out.println(last_q); out.flush(); int last_ans = in.nextInt(); ans.append("!"); if (last_ans == max) { for (int j=0;j<k;j++) { ans.append(" "+(max)); } } else { // out.println("HHH"); // int other_max = 0; // for (int j=0;j<k;j++) { // if (j == list_index.get(0)) continue; // for (int tmp : set_list.get(j)) { // other_max = Math.max(other_max, tmp); // } // } for (int j=0;j<k;j++) { boolean in_flag = false; for (Integer lll : set_list.get(j)) { if ((list_index.get(0)+1) == lll) in_flag = true; } // if (j == list_index.get(0)) { if (in_flag) { ans.append(" "+(last_ans)); } else { ans.append(" "+(max)); } } } out.println(ans); out.flush(); String sssss = in.next(); } // out.println(list_index); // out.flush(); list_index_size = list_index.size(); // ArrayList // break; } // StringBuilder sb = new StringBuilder(); // sb.append("?"); // sb.append(" "+n); // for (int j=0;j<n;j++) { // sb.append(" "+(j+1)); // } // out.println(sb); // out.flush(); } out.close(); } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } } }
Java
["1\n4 2\n2 1 3\n2 2 4\n\n1\n\n2\n\n3\n\n4\n\nCorrect"]
2 seconds
["? 1 1\n\n? 1 2\n\n? 1 3\n\n? 1 4\n\n! 4 3"]
NoteThe array $$$A$$$ in the example is $$$[1, 2, 3, 4]$$$. The length of the password is $$$2$$$. The first element of the password is the maximum of $$$A[2]$$$, $$$A[4]$$$ (since the first subset contains indices $$$1$$$ and $$$3$$$, we take maximum over remaining indices). The second element of the password is the maximum of $$$A[1]$$$, $$$A[3]$$$ (since the second subset contains indices $$$2$$$, $$$4$$$).Do not forget to read the string "Correct" / "Incorrect" after guessing the password.
Java 11
standard input
[ "math", "binary search", "implementation", "interactive" ]
b0bce8524eb69b695edc1394ff86b913
The first line of the input contains a single integer $$$t$$$ $$$(1 \leq t \leq 10)$$$ — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ $$$(2 \leq n \leq 1000, 1 \leq k \leq n)$$$ — the size of the array and the number of subsets. $$$k$$$ lines follow. The $$$i$$$-th line contains an integer $$$c$$$ $$$(1 \leq c \lt n)$$$ — the size of subset $$$S_i$$$, followed by $$$c$$$ distinct integers in the range $$$[1, n]$$$  — indices from the subset $$$S_i$$$. It is guaranteed that the intersection of any two subsets is empty.
2,100
null
standard output
PASSED
d2cd7f381c4f7ad58f2895973e4597b7
train_002.jsonl
1590935700
This is an interactive problem.Ayush devised a new scheme to set the password of his lock. The lock has $$$k$$$ slots where each slot can hold integers from $$$1$$$ to $$$n$$$. The password $$$P$$$ is a sequence of $$$k$$$ integers each in the range $$$[1, n]$$$, $$$i$$$-th element of which goes into the $$$i$$$-th slot of the lock.To set the password of his lock, Ayush comes up with an array $$$A$$$ of $$$n$$$ integers each in the range $$$[1, n]$$$ (not necessarily distinct). He then picks $$$k$$$ non-empty mutually disjoint subsets of indices $$$S_1, S_2, ..., S_k$$$ $$$(S_i \underset{i \neq j} \cap S_j = \emptyset)$$$ and sets his password as $$$P_i = \max\limits_{j \notin S_i} A[j]$$$. In other words, the $$$i$$$-th integer in the password is equal to the maximum over all elements of $$$A$$$ whose indices do not belong to $$$S_i$$$.You are given the subsets of indices chosen by Ayush. You need to guess the password. To make a query, you can choose a non-empty subset of indices of the array and ask the maximum of all elements of the array with index in this subset. You can ask no more than 12 queries.
256 megabytes
import java.util.*; import java.io.*; public class D646 { public static void main(String [] args) { MyScanner sc = new MyScanner(); PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int k = sc.nextInt(); int [] a = new int[n + 1]; for (int i = 1; i <= k; i++) { int c = sc.nextInt(); for (int j = 0; j < c; j++) a[sc.nextInt()] = i; } System.out.print("? "); int ct = 0; for (int i = 1; i <= n; i++) if (a[i] != 0) ct++; System.out.print(ct + " "); for (int i = 1; i <= n; i++) if (a[i] != 0) System.out.print(i + " "); System.out.flush(); int inside = sc.nextInt(); int lo = 1; int hi = k; int [] ret = new int[k + 1]; while (lo < hi) { int mid = (lo + hi) / 2; System.out.print("? "); ct = 0; for (int i = 1; i <= n; i++) if (a[i] <= mid && a[i] >= lo) ct++; System.out.print(ct + " "); for (int i = 1; i <= n; i++) if (a[i] <= mid && a[i] >= lo) System.out.print(i + " "); System.out.flush(); int max = sc.nextInt(); if (max == inside) { for (int i = mid + 1; i <= hi; i++) ret[i] = inside; hi = mid; } else { for (int i = lo; i <= mid; i++) ret[i] = inside; lo = mid + 1; } } System.out.print("? "); ct = 0; for (int i = 1; i <= n; i++) if (a[i] != lo) ct++; System.out.print(ct + " "); for (int i = 1; i <= n; i++) if (a[i] != lo) System.out.print(i + " "); System.out.flush(); ret[lo] = sc.nextInt(); if (ret[lo] >= inside) { for (int i = 1; i <= k; i++) ret[i] = ret[lo]; } System.out.print("! "); for (int i = 1; i <= k; i++) System.out.print(ret[i] + " "); System.out.flush(); String s = sc.next(); System.out.flush(); } out.close(); } //-----------MyScanner class for faster input---------- public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine(){ String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["1\n4 2\n2 1 3\n2 2 4\n\n1\n\n2\n\n3\n\n4\n\nCorrect"]
2 seconds
["? 1 1\n\n? 1 2\n\n? 1 3\n\n? 1 4\n\n! 4 3"]
NoteThe array $$$A$$$ in the example is $$$[1, 2, 3, 4]$$$. The length of the password is $$$2$$$. The first element of the password is the maximum of $$$A[2]$$$, $$$A[4]$$$ (since the first subset contains indices $$$1$$$ and $$$3$$$, we take maximum over remaining indices). The second element of the password is the maximum of $$$A[1]$$$, $$$A[3]$$$ (since the second subset contains indices $$$2$$$, $$$4$$$).Do not forget to read the string "Correct" / "Incorrect" after guessing the password.
Java 11
standard input
[ "math", "binary search", "implementation", "interactive" ]
b0bce8524eb69b695edc1394ff86b913
The first line of the input contains a single integer $$$t$$$ $$$(1 \leq t \leq 10)$$$ — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ $$$(2 \leq n \leq 1000, 1 \leq k \leq n)$$$ — the size of the array and the number of subsets. $$$k$$$ lines follow. The $$$i$$$-th line contains an integer $$$c$$$ $$$(1 \leq c \lt n)$$$ — the size of subset $$$S_i$$$, followed by $$$c$$$ distinct integers in the range $$$[1, n]$$$  — indices from the subset $$$S_i$$$. It is guaranteed that the intersection of any two subsets is empty.
2,100
null
standard output
PASSED
56c26d2ded0d4864b528cb54f5ef93ae
train_003.jsonl
1390231800
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y), (x–1, y), (x, y + 1) and (x, y–1).Iahub wants to know how many Coders can be placed on an n × n chessboard, so that no Coder attacks any other Coder.
256 megabytes
import java.util.*; public class Coder { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int maxcoders = 0; if (n % 2 == 0) maxcoders = ((n * n) / 2); else maxcoders = ((n * n) + 1) / 2; System.out.println(maxcoders); for (int i = 0; i < n; i++) { StringBuilder sb = new StringBuilder(); for (int j = 1; j <= n; j++) { if (j % 2 != 0 && i%2 != 0) sb.append("."); else if (j % 2 == 0 && i%2 == 0) sb.append("."); else sb.append("C"); } System.out.println(sb); } in.close(); } }
Java
["2"]
1 second
["2\nC.\n.C"]
null
Java 7
standard input
[ "implementation" ]
1aede54b41d6fad3e74f24a6592198eb
The first line contains an integer n (1 ≤ n ≤ 1000).
800
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.
standard output
PASSED
ea1b20425277696765e24fa25ae87c4f
train_003.jsonl
1390231800
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y), (x–1, y), (x, y + 1) and (x, y–1).Iahub wants to know how many Coders can be placed on an n × n chessboard, so that no Coder attacks any other Coder.
256 megabytes
import java.awt.Point; import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashSet; import java.util.PriorityQueue; import java.util.StringTokenizer; /** * * @author Mojtaba */ public class Main { public static void main(String[] args) throws IOException { MyScanner in = new MyScanner(System.in); StringBuilder sb = new StringBuilder(""); int n = in.nextInt(); sb.append((int) Math.ceil(n * n / 2f)).append("\n"); for (int i = 0; i < n; i++) { boolean code = i % 2 == 0; for (int j = 0; j < n; j++, code = !code) { sb.append(code ? 'C' : '.'); } sb.append("\n"); } System.out.println(sb.toString().trim()); in.close(); } } class MyScanner { BufferedReader reader; StringTokenizer tokenizer; public MyScanner(InputStream stream) { this.reader = new BufferedReader(new InputStreamReader(stream)); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public int[] nextIntegerArray(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < a.length; i++) { a[i] = nextInt(); } return a; } public long[] nextLongArray(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < a.length; i++) { a[i] = nextLong(); } return a; } public int nextInt(int radix) throws IOException { return Integer.parseInt(next(), radix); } public long nextLong() throws IOException { return Long.parseLong(next()); } public long nextLong(int radix) throws IOException { return Long.parseLong(next(), radix); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public BigInteger nextBigInteger() throws IOException { return new BigInteger(next()); } public BigInteger nextBigInteger(int radix) throws IOException { return new BigInteger(next(), radix); } public String next() throws IOException { if (tokenizer == null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); return this.next(); } return tokenizer.nextToken(); } public void close() throws IOException { this.reader.close(); } }
Java
["2"]
1 second
["2\nC.\n.C"]
null
Java 7
standard input
[ "implementation" ]
1aede54b41d6fad3e74f24a6592198eb
The first line contains an integer n (1 ≤ n ≤ 1000).
800
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.
standard output
PASSED
876f97bac9b38caeb458a4192990436e
train_003.jsonl
1390231800
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y), (x–1, y), (x, y + 1) and (x, y–1).Iahub wants to know how many Coders can be placed on an n × n chessboard, so that no Coder attacks any other Coder.
256 megabytes
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ //package coder; /** * * @author samsung */ import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.StringTokenizer; public class Coder{ static class FastScanner{ BufferedReader s; StringTokenizer st; public FastScanner(){ st = new StringTokenizer(""); s = new BufferedReader(new InputStreamReader(System.in)); } public FastScanner(File f) throws FileNotFoundException{ st = new StringTokenizer(""); s = new BufferedReader (new FileReader(f)); } public int nextInt() throws IOException{ if(st.hasMoreTokens()) return Integer.parseInt(st.nextToken()); else{ st = new StringTokenizer(s.readLine()); return nextInt(); } } public double nextDouble() throws IOException{ if(st.hasMoreTokens()) return Double.parseDouble(st.nextToken()); else{ st = new StringTokenizer(s.readLine()); return nextDouble(); } } public long nextLong() throws IOException{ if(st.hasMoreTokens()) return Long.parseLong(st.nextToken()); else{ st = new StringTokenizer(s.readLine()); return nextLong(); } } public String nextString() throws IOException{ if(st.hasMoreTokens()) return st.nextToken(); else{ st = new StringTokenizer(s.readLine()); return nextString(); } } public String readLine() throws IOException{ return s.readLine(); } public void close() throws IOException{ s.close(); } } //Fastscanner class end static FastScanner in=new FastScanner(); static PrintWriter ww=new PrintWriter(new OutputStreamWriter(System.out)); public static void main(String args[])throws IOException { //Main ob=new Main(); Coder ob=new Coder(); ob.solve(); ww.close(); } public void solve()throws IOException { int n = in.nextInt(); int ans= 0; StringBuilder t = new StringBuilder(); for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if((i+j)%2==0) { ans++; t.append('C'); } else { t.append('.'); } } t.append("\n"); } System.out.println(ans); System.out.println(t); } }
Java
["2"]
1 second
["2\nC.\n.C"]
null
Java 7
standard input
[ "implementation" ]
1aede54b41d6fad3e74f24a6592198eb
The first line contains an integer n (1 ≤ n ≤ 1000).
800
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.
standard output
PASSED
25c9b1ca5a1e1775da185e54c602b880
train_003.jsonl
1390231800
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y), (x–1, y), (x, y + 1) and (x, y–1).Iahub wants to know how many Coders can be placed on an n × n chessboard, so that no Coder attacks any other Coder.
256 megabytes
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author Prasham */ import java.io.* ; public class NewClass { public static void main(String []args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()) ; //int a[][] = new int[n][n]; char c[][] = new char[n][n]; int sum = 0 ; int i,j,k ; i=j=k=0 ; for(i=0;i<n;i++) { for(j=0;j<n;j++) { if((i%2)==0 && (j%2)==0) { sum++ ; c[i][j]='C' ; } else if((i%2)!=0 && (j%2)!=0) { sum++ ; c[i][j] = 'C' ; } else { c[i][j]='.'; } } } System.out.println(sum) ; for(i=0;i<n;i++) { for(j=0;j<n;j++) { System.out.print(c[i][j]) ; } System.out.println(); } } }
Java
["2"]
1 second
["2\nC.\n.C"]
null
Java 7
standard input
[ "implementation" ]
1aede54b41d6fad3e74f24a6592198eb
The first line contains an integer n (1 ≤ n ≤ 1000).
800
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.
standard output
PASSED
0a754e4f0a5cb33b659eecdb06a87ecc
train_003.jsonl
1390231800
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y), (x–1, y), (x, y + 1) and (x, y–1).Iahub wants to know how many Coders can be placed on an n × n chessboard, so that no Coder attacks any other Coder.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String args[]){ Scanner scan=new Scanner(System.in); int matriz=scan.nextInt(); int resu=0; if(matriz%2==0) resu=(matriz*matriz)/2; else resu=((matriz*matriz)/2)+1; System.out.println(resu); String st1=new String(""); String st2=new String(""); for(int i=0; i<matriz ;i++) if(i%2==0) st1+="C"; else st1+="."; for(int i=0; i<matriz ;i++) if(i%2!=0) st2+="C"; else st2+="."; for(int i=0;i<matriz;i++){ if(i%2==0) System.out.println(st1); else System.out.println(st2); } scan.close(); } }
Java
["2"]
1 second
["2\nC.\n.C"]
null
Java 7
standard input
[ "implementation" ]
1aede54b41d6fad3e74f24a6592198eb
The first line contains an integer n (1 ≤ n ≤ 1000).
800
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.
standard output
PASSED
2c2b0394f4e1a04d930c1d110874011c
train_003.jsonl
1390231800
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y), (x–1, y), (x, y + 1) and (x, y–1).Iahub wants to know how many Coders can be placed on an n × n chessboard, so that no Coder attacks any other Coder.
256 megabytes
import java.util.Scanner; public class chees { public static void main(String[] args) { Scanner in =new Scanner(System.in); String ss=""; int x=in.nextInt(); int c=x*x; if(c%2==0) c=c/2; else c=(c/2)+1; for(int i=0;ss.length()<=x;i++){ ss+="C."; } System.out.println(c); int i=0; boolean b=true; while(++i<=x) { if(b) { System.out.println(ss.substring(0,0+x)); b=!b; } else { System.out.println(ss.substring(1,1+x)); b=!b; } } } }
Java
["2"]
1 second
["2\nC.\n.C"]
null
Java 7
standard input
[ "implementation" ]
1aede54b41d6fad3e74f24a6592198eb
The first line contains an integer n (1 ≤ n ≤ 1000).
800
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.
standard output
PASSED
e850e75c2087c76e8785ad4bb9a7d365
train_003.jsonl
1390231800
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y), (x–1, y), (x, y + 1) and (x, y–1).Iahub wants to know how many Coders can be placed on an n × n chessboard, so that no Coder attacks any other Coder.
256 megabytes
import java.io.PrintWriter; import java.util.Scanner; public class Coder { public static void main(String[] args) { Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int n = in.nextInt(); out.println((n*n+1)/2); for(int i = 0;i<n;i++){ for(int j = 0 ;j<n;j++){ if((i+j)%2==0){ out.print("C"); }else{ out.print("."); } } out.println(); } in.close(); out.close(); } }
Java
["2"]
1 second
["2\nC.\n.C"]
null
Java 7
standard input
[ "implementation" ]
1aede54b41d6fad3e74f24a6592198eb
The first line contains an integer n (1 ≤ n ≤ 1000).
800
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.
standard output
PASSED
67d1844a8d9ff1f0ec2fd173a7574cf7
train_003.jsonl
1390231800
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y), (x–1, y), (x, y + 1) and (x, y–1).Iahub wants to know how many Coders can be placed on an n × n chessboard, so that no Coder attacks any other Coder.
256 megabytes
import java.io.PrintWriter; import java.util.Scanner; public class Coder { public static void main(String[] args) { Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int n = in.nextInt(); out.println((n*n+1)/2); for(int i = 0;i<n;i++){ for(int j = 0 ;j<n;j++){ if((i+j)%2==0){ out.print("C"); }else{ out.print("."); } } out.println(); } in.close(); out.close(); } }
Java
["2"]
1 second
["2\nC.\n.C"]
null
Java 7
standard input
[ "implementation" ]
1aede54b41d6fad3e74f24a6592198eb
The first line contains an integer n (1 ≤ n ≤ 1000).
800
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.
standard output
PASSED
cf1172a3dea319c016623f8d583d1b18
train_003.jsonl
1390231800
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y), (x–1, y), (x, y + 1) and (x, y–1).Iahub wants to know how many Coders can be placed on an n × n chessboard, so that no Coder attacks any other Coder.
256 megabytes
import java.util.Scanner; /** * * @author Annie */ public class Coder { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Scanner s = new Scanner(System.in); int n = s.nextInt(); String a[]= new String[n]; for(int i=0;i<n;i++){ a[i]=""; for(int j=0;j<n;j++){ if((i+j)%2==0){ a[i]=a[i]+"C"; } else{ a[i]=a[i]+"."; } } } if(n%2==0){ System.out.println((n*n)/2); } else{ System.out.println((n*n + 1)/2); } for(int i=0;i<n;i++){ System.out.print(a[i]); System.out.println(); } } }
Java
["2"]
1 second
["2\nC.\n.C"]
null
Java 7
standard input
[ "implementation" ]
1aede54b41d6fad3e74f24a6592198eb
The first line contains an integer n (1 ≤ n ≤ 1000).
800
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.
standard output
PASSED
ec11d5ce9fc6fbe550055383267ede0f
train_003.jsonl
1390231800
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y), (x–1, y), (x, y + 1) and (x, y–1).Iahub wants to know how many Coders can be placed on an n × n chessboard, so that no Coder attacks any other Coder.
256 megabytes
import java.util.Scanner; import java.io.PrintWriter; import java.lang.*; public class Main { public static final PrintWriter out=new PrintWriter(System.out); public static void display(int a) { if(a%2==0){ int k=0; for(int i=1;i<=a;i++){ for(int j=1;j<=a;j++){ ++k; if(k%2!=0) out.print("C"); else out.print("."); } --k; out.println(); } out.flush(); } else{ int k=0; for(int i=1;i<=a;i++){ for(int j=1;j<=a;j++){ ++k; if(k%2!=0) out.print("C"); else out.print("."); } out.println(); } out.flush(); } } public static void main(String[] args) { int n=(new Scanner(System.in)).nextInt(); if(n%2==0) System.out.println((n*n)/2); else System.out.println(((n*n)+1)/2); display(n); } }
Java
["2"]
1 second
["2\nC.\n.C"]
null
Java 7
standard input
[ "implementation" ]
1aede54b41d6fad3e74f24a6592198eb
The first line contains an integer n (1 ≤ n ≤ 1000).
800
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.
standard output
PASSED
2a23d60ec461e3139c30aa90ed97aa4a
train_003.jsonl
1390231800
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y), (x–1, y), (x, y + 1) and (x, y–1).Iahub wants to know how many Coders can be placed on an n × n chessboard, so that no Coder attacks any other Coder.
256 megabytes
import java.util.*; public class Main { public static void main (String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); char[][] b= new char[n][n]; for(int i=0;i<n;i++) Arrays.fill(b[i],'.'); /*for(int i=0;i<n;i++) for(int j=0;j<n;j++){ if(i>0 && i<n-1 && j>0 && j<n-1){ if(b[i][j+1]=='.' && b[i+1][j]=='.' && b[i][j-1]=='.' && b[i-1][j]=='.') b[i][j]='C'; } else if(i==0 && j==0) { if(b[i][j+1]=='.' && b[i+1][j]=='.') b[i][j]='C'; } else if(i==n-1 && j==0){ if(b[i][j+1]=='.' && b[i-1][j]=='.') b[i][j]='C'; } else if(i==n-1 && j==n-1){ if(b[i][j-1]=='.' && b[i-1][j]=='.') b[i][j]='C'; } else if(j==n-1 && i==0){ if(b[i][j-1]=='.' && b[i+1][j]=='.') b[i][j]='C'; } else if(i==0){ if(b[i][j-1]=='.' && b[i+1][j]=='.' && b[i][j+1]=='.') b[i][j]='C'; } else if(i==n-1){ if(b[i][j-1]=='.' && b[i-1][j]=='.' && b[i][j+1]=='.') b[i][j]='C'; } else if(j==n-1){ if(b[i][j-1]=='.' && b[i-1][j]=='.' && b[i+1][j]=='.') b[i][j]='C'; } else if(j==0){ if(b[i][j+1]=='.' && b[i-1][j]=='.' && b[i+1][j]=='.') b[i][j]='C'; } }*/ boolean found=true; int sum=0; for(int i=0;i<n;i++){ for(int j=0;j<n;j++) { if(found){ b[i][j]='C'; sum++; found=false;} else { found=true; } } if(n%2==0) found=!found; } /*for(int i=0;i<n;i++){ for(int j=0;j<n;j++) System.out.print(b[i][j]+" "); System.out.println(); }*/ System.out.println(sum); for(int i=0;i<n;i++) System.out.println(String.valueOf(b[i])); } }
Java
["2"]
1 second
["2\nC.\n.C"]
null
Java 7
standard input
[ "implementation" ]
1aede54b41d6fad3e74f24a6592198eb
The first line contains an integer n (1 ≤ n ≤ 1000).
800
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.
standard output
PASSED
9e4206222e53c08405552726ceef0958
train_003.jsonl
1390231800
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y), (x–1, y), (x, y + 1) and (x, y–1).Iahub wants to know how many Coders can be placed on an n × n chessboard, so that no Coder attacks any other Coder.
256 megabytes
import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(), count = 0; char[][] values = new char[n + 2][n + 2]; for (int i = 0; i < n + 2; i++) Arrays.fill(values[i], '.'); for (int i = 1; i < n + 1; i++) { for (int j = 1; j < n + 1; j++) { if (values[i + 1][j] == '.' && values[i - 1][j] == '.' && values[i][j + 1] == '.' && values[i][j - 1] == '.') { values[i][j] = 'C'; count++; } } } System.out.println(count); for(int i = 1; i < n + 1; i ++){ for(int j = 1; j < n + 1; j ++){ System.out.print(values[i][j]); } System.out.println(); } } }
Java
["2"]
1 second
["2\nC.\n.C"]
null
Java 7
standard input
[ "implementation" ]
1aede54b41d6fad3e74f24a6592198eb
The first line contains an integer n (1 ≤ n ≤ 1000).
800
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.
standard output
PASSED
56ba9b37249b2d7e32fca98619d680a7
train_003.jsonl
1390231800
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y), (x–1, y), (x, y + 1) and (x, y–1).Iahub wants to know how many Coders can be placed on an n × n chessboard, so that no Coder attacks any other Coder.
256 megabytes
import java.util.Scanner; public class tr { public static void main (String args []){ Scanner s = new Scanner(System.in); int n = s.nextInt(); if(n%2==0){ System.out.println((n/2)*n); }else{ System.out.println(Math.round(Math.ceil(1.0*n/2)*Math.ceil(1.0*n/2)+(n/2)*(n/2))); } String one ="";String two = ""; for(int i =1;i<=n;i++){ one += (i%2==0?".":"C") ; } for(int i =1;i<=n;i++){ two += (i%2==1?".":"C") ; } for(int i =0;i<n;i++){ System.out.println(i%2==0?one:two); } }}
Java
["2"]
1 second
["2\nC.\n.C"]
null
Java 7
standard input
[ "implementation" ]
1aede54b41d6fad3e74f24a6592198eb
The first line contains an integer n (1 ≤ n ≤ 1000).
800
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.
standard output
PASSED
8ec29ecad062879e36fde5f0807f470f
train_003.jsonl
1390231800
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y), (x–1, y), (x, y + 1) and (x, y–1).Iahub wants to know how many Coders can be placed on an n × n chessboard, so that no Coder attacks any other Coder.
256 megabytes
import java.io.*; import java.util.*; /** * * @coder Altynbek Nurgaziyev */ public class A { void solution() throws Exception { int n = in.nextInt(); if (n * n % 2 == 0) { out.println(n * n / 2); } else { out.println(n * n / 2 + 1); } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if ((i + j) % 2 == 0) { out.print("C"); } else { out.print("."); } } out.println(); } } public static void main(String[] args) throws Exception { new A().run(); } Scanner in; PrintWriter out; void run() throws Exception { in = new Scanner(new InputStreamReader(System.in)); out = new PrintWriter(new OutputStreamWriter(System.out)); solution(); out.flush(); } class Scanner { final BufferedReader br; StringTokenizer st; Scanner(InputStreamReader stream) { br = new BufferedReader(stream); } String next() throws Exception { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } Integer nextInt() throws Exception { return Integer.parseInt(next()); } Long nextLong() throws Exception { return Long.parseLong(next()); } Double nextDouble() throws Exception { return Double.parseDouble(next()); } } }
Java
["2"]
1 second
["2\nC.\n.C"]
null
Java 7
standard input
[ "implementation" ]
1aede54b41d6fad3e74f24a6592198eb
The first line contains an integer n (1 ≤ n ≤ 1000).
800
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.
standard output
PASSED
061db2132b6c97b0e4e79a1ac4a3fa7e
train_003.jsonl
1390231800
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y), (x–1, y), (x, y + 1) and (x, y–1).Iahub wants to know how many Coders can be placed on an n × n chessboard, so that no Coder attacks any other Coder.
256 megabytes
import java.util.Scanner; public class A225 { public static void main(String[] args) { Scanner input = new Scanner(System.in); int n = input.nextInt(); int firstRow, secondRow; if (n % 2 != 0) { firstRow = n / 2 + 1; } else { firstRow = n / 2; } secondRow = n / 2; int sum = (n / 2) * (firstRow + secondRow); if (n % 2 != 0) { sum += firstRow; } System.out.println(sum); for (int i = 0; i < n / 2; i++) { for (int j = 0; j < n / 2; j++) { System.out.print("C."); } if (n % 2 != 0) { System.out.print("C"); } System.out.println(); for (int j = 0; j < n / 2; j++) { System.out.print(".C"); } if (n % 2 != 0) { System.out.print("."); } System.out.println(); } if (n % 2 != 0) { for (int j = 0; j < n / 2; j++) { System.out.print("C."); } System.out.println("C"); } } }
Java
["2"]
1 second
["2\nC.\n.C"]
null
Java 7
standard input
[ "implementation" ]
1aede54b41d6fad3e74f24a6592198eb
The first line contains an integer n (1 ≤ n ≤ 1000).
800
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.
standard output
PASSED
638b30066724e03807089b2ad94c4133
train_003.jsonl
1390231800
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y), (x–1, y), (x, y + 1) and (x, y–1).Iahub wants to know how many Coders can be placed on an n × n chessboard, so that no Coder attacks any other Coder.
256 megabytes
/* IMPORTANT: Multiple classes and nested static classes are supported */ /* * uncomment this if you want to read input. import java.io.BufferedReader; import java.io.InputStreamReader; */ import java.math.BigInteger; import java.util.*; public class Astone { public static void main(String args[] ) throws Exception { Scanner sc = new Scanner(System.in); int n=sc.nextInt(); int count=0; int a[]=new int[1001]; a[1]=1; int start=1; for(int i=3;i<1001;i+=2) { a[i]=a[i-2]+(4*start); start++; } if(n%2==0) System.out.println((n*n)/2); else System.out.println(a[n]); String one=""; String three=""; for(int i=0;i<n;i++) { if(i%2==0) { one+='C';three+='.';} else{ one+='.';three+='C';} } if(n%2==0) { StringBuffer sb=new StringBuffer(one); String two=sb.reverse().toString(); for(int i=0;i<n;i++) { if(i%2==0) System.out.println(one); else System.out.println(two); } } else { for(int i=0;i<n;i++) { if(i%2==0) System.out.println(one); else System.out.println(three); } } } }
Java
["2"]
1 second
["2\nC.\n.C"]
null
Java 7
standard input
[ "implementation" ]
1aede54b41d6fad3e74f24a6592198eb
The first line contains an integer n (1 ≤ n ≤ 1000).
800
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.
standard output
PASSED
138903a9f92b613b7019d1964120c417
train_003.jsonl
1390231800
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y), (x–1, y), (x, y + 1) and (x, y–1).Iahub wants to know how many Coders can be placed on an n × n chessboard, so that no Coder attacks any other Coder.
256 megabytes
//package TestOnly.Div2A_225.Code1; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class Main { FastScanner in; PrintWriter out; public void solve() throws IOException { int n = in.nextInt(); out.println((int) Math.ceil(n * n / 2.0)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i % 2 == 0) { if (j % 2 == 0) { out.print("C"); } else { out.print("."); } } else { if (j % 2 != 0) { out.print("C"); } else { out.print("."); } } } out.println(); } } public void run() { try { in = new FastScanner(); out = new PrintWriter(System.out); solve(); out.close(); } catch (IOException e) { e.printStackTrace(); } } class FastScanner { BufferedReader br; StringTokenizer st; FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } } public static void main(String[] arg) { new Main().run(); } }
Java
["2"]
1 second
["2\nC.\n.C"]
null
Java 7
standard input
[ "implementation" ]
1aede54b41d6fad3e74f24a6592198eb
The first line contains an integer n (1 ≤ n ≤ 1000).
800
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.
standard output
PASSED
ff665b330e3df6047a658295c9233280
train_003.jsonl
1390231800
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y), (x–1, y), (x, y + 1) and (x, y–1).Iahub wants to know how many Coders can be placed on an n × n chessboard, so that no Coder attacks any other Coder.
256 megabytes
//package Codeforces.Div2A_225; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; /* * some cheeky quote */ public class Main { FastScanner in; PrintWriter out; public void solve() throws IOException { int n = in.nextInt(); out.println((int) Math.ceil((n * n) / 2.0)); for (int i = 0; i < n; i++) { char prev = i % 2 == 0 ? 'C' : '.'; out.print(prev); for (int j = 1; j < n; j++) { prev = prev == 'C' ? '.' : 'C'; out.print(prev); } out.println(); } } public void run() { try { in = new FastScanner(); out = new PrintWriter(System.out); solve(); out.close(); } catch (IOException e) { e.printStackTrace(); } } class FastScanner { BufferedReader br; StringTokenizer st; FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } } public static void main(String[] arg) { new Main().run(); } }
Java
["2"]
1 second
["2\nC.\n.C"]
null
Java 7
standard input
[ "implementation" ]
1aede54b41d6fad3e74f24a6592198eb
The first line contains an integer n (1 ≤ n ≤ 1000).
800
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.
standard output
PASSED
1dc5b78c0cdcd020aca86da0e943b221
train_003.jsonl
1390231800
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y), (x–1, y), (x, y + 1) and (x, y–1).Iahub wants to know how many Coders can be placed on an n × n chessboard, so that no Coder attacks any other Coder.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int k = 0; System.out.println((int)Math.ceil((n*n+1)/2)); String s=""; for (int j = 0; j < n; j++) { for (int l = 0; l < n; l++) { if (l == k) { s+="C"; k += 2; } else { s+="."; } } k = (k + 1) % 2; System.out.println(s); s=""; } } }
Java
["2"]
1 second
["2\nC.\n.C"]
null
Java 7
standard input
[ "implementation" ]
1aede54b41d6fad3e74f24a6592198eb
The first line contains an integer n (1 ≤ n ≤ 1000).
800
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.
standard output
PASSED
2c3d774242a71bdf2d4231c4e68c11ab
train_003.jsonl
1390231800
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y), (x–1, y), (x, y + 1) and (x, y–1).Iahub wants to know how many Coders can be placed on an n × n chessboard, so that no Coder attacks any other Coder.
256 megabytes
import java.io.*; public class Coder { public static void main(String[] args) throws IOException { BufferedReader f = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(f.readLine()); System.out.println((n*n+1)/2); String str = ""; for (int i = 0; i < n+1; i++) str += i%2==0 ? 'C' : '.'; for (int i = 0; i < n; i++) if (i % 2 == 0) System.out.println(str.substring(0,n)); else System.out.println(str.substring(1)); } }
Java
["2"]
1 second
["2\nC.\n.C"]
null
Java 7
standard input
[ "implementation" ]
1aede54b41d6fad3e74f24a6592198eb
The first line contains an integer n (1 ≤ n ≤ 1000).
800
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.
standard output
PASSED
adb233e8e5873cb56d8e6b41a8d0b1e0
train_003.jsonl
1390231800
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y), (x–1, y), (x, y + 1) and (x, y–1).Iahub wants to know how many Coders can be placed on an n × n chessboard, so that no Coder attacks any other Coder.
256 megabytes
import java.io.*; import java.util.*; public class Main { static BufferedReader f; static StringTokenizer st; public static void main (String [] args) throws Exception { // Use BufferedReader rather than RandomAccessFile; it's much faster f = new BufferedReader(new java.io.InputStreamReader(System.in)); long unixTime = System.currentTimeMillis(); int n=nextInt(); StringBuilder a = new StringBuilder(""); StringBuilder b = new StringBuilder(""); int codersa=0; int codersb=0; for(int i=0;i<n;i++){ if(i%2==0){ a.append("C"); codersa++; b.append("."); }else{ b.append("C"); codersb++; a.append("."); } } int coders=0; for(int i=0;i<n;i++){ if(i%2==0){ coders+=codersa; }else{ coders+=codersb; } } String as = a.toString(); String bs=b.toString(); System.out.println(coders); for(int i=0;i<n;i++){ if(i%2==0){ System.out.println(as); }else{ System.out.println(bs); } } System.err.println("Time elapsed (ms): "+(System.currentTimeMillis()-unixTime)); System.exit(0); // don't omit this! } //Library static int nextInt() throws Exception { return Integer.parseInt(next()); } static long nextLong() throws Exception { return Long.parseLong(next()); } private static long gcd(long a, long b) { while (b > 0) { long temp = b; b = a % b; a = temp; } return a; } private static long lcm(long a, long b) { return a * (b / gcd(a, b)); } static String next() throws Exception { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(f.readLine()); } return st.nextToken(); } } class ii{ int a; int b; public ii(int a, int b){ this.a=a; this.b=b; } }
Java
["2"]
1 second
["2\nC.\n.C"]
null
Java 7
standard input
[ "implementation" ]
1aede54b41d6fad3e74f24a6592198eb
The first line contains an integer n (1 ≤ n ≤ 1000).
800
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.
standard output
PASSED
6aff56e5bd8b96119f307c5114fee583
train_003.jsonl
1390231800
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y), (x–1, y), (x, y + 1) and (x, y–1).Iahub wants to know how many Coders can be placed on an n × n chessboard, so that no Coder attacks any other Coder.
256 megabytes
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.math.BigInteger; import java.util.Scanner; import javax.swing.table.DefaultTableModel; public class Test { static void print(int[] a) { for(int i=0;i<a.length;i++) System.out.print(a[i]+" "); System.out.println(); } static String space(int n) { String res=""; for(int i=0;i<n;i++) res+=" "; return res; } static int sum(int a[]) { int res=0; for(int i=0;i<a.length;i++) res+=a[i]; return res; } static int[] sort(int list[]) { for(int i=0;i<list.length-1;i++) { for(int j=0;j<list.length-i-1;j++) { if(list[j]>list[j+1]) { int t=list[j]; list[j]=list[j+1]; list[j+1]=t; } } } return list; } public static void main(String args[]) { Scanner in=new Scanner(System.in); int n=in.nextInt(); int res=0; String str[]=new String[n]; for(int i=0;i<n;i++) str[i]=""; for(int i=1;i<n+1;i++) { if(i%2>0) { for(int j=1;j<n+1;j++) { if(j%2>0) {str[i-1]+="C"; res++;} else str[i-1]+="."; } continue; } else { for(int j=1;j<n+1;j++) { if(j%2>0) str[i-1]+="."; else {str[i-1]+="C"; res++;} } continue; } } System.out.println(res); for(int i=0;i<n;i++) System.out.println(str[i]); //for(int i=0;i<255;i++) System.out.println(i+" : "+(char)i); } }
Java
["2"]
1 second
["2\nC.\n.C"]
null
Java 7
standard input
[ "implementation" ]
1aede54b41d6fad3e74f24a6592198eb
The first line contains an integer n (1 ≤ n ≤ 1000).
800
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.
standard output
PASSED
5a44274e297a944017bad55ff57b10ad
train_003.jsonl
1390231800
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y), (x–1, y), (x, y + 1) and (x, y–1).Iahub wants to know how many Coders can be placed on an n × n chessboard, so that no Coder attacks any other Coder.
256 megabytes
import java.io.*; import java.math.*; import java.util.*; public class Main { InputReader input; PrintWriter output; void run(){ output = new PrintWriter(new OutputStreamWriter(System.out)); input = new InputReader(System.in); solve(); output.flush(); } public static void main(String[] args){ new Main().run(); } void solve() { int n = input.ni(); int cnt = ((n+1)/2)*((n+1)/2) + n/2*(n/2); output.println(cnt); for(int i = 0; i < n; i++) { if((i&1) == 0) { for(int j = 0; j < n; j++) { if((j&1) == 0) { output.print("C"); cnt++; } else output.print("."); } } else { for(int j = 0; j < n; j++) { if((j&1) != 0) { output.print("C"); cnt++; } else output.print("."); } } output.println(); } } class InputReader { private boolean finished = false; private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int peek() { if (numChars == -1) return -1; if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { return -1; } if (numChars <= 0) return -1; } return buf[curChar]; } public int ni() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nl() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String ns() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return isWhitespace(c); } public boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private String readLine0() { StringBuilder buf = new StringBuilder(); int c = read(); while (c != '\n' && c != -1) { if (c != '\r') buf.appendCodePoint(c); c = read(); } return buf.toString(); } public String readLine() { String s = readLine0(); while (s.trim().length() == 0) s = readLine0(); return s; } public String readLine(boolean ignoreEmptyLines) { if (ignoreEmptyLines) return readLine(); else return readLine0(); } public BigInteger readBigInteger() { try { return new BigInteger(ns()); } catch (NumberFormatException e) { throw new InputMismatchException(); } } public char readCharacter() { int c = read(); while (isSpaceChar(c)) c = read(); return (char) c; } public double readDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') return res * Math.pow(10, ni()); if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') return res * Math.pow(10, ni()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public boolean eof() { int value; while (isSpaceChar(value = peek()) && value != -1) read(); return value == -1; } public String next() { return ns(); } public SpaceCharFilter getFilter() { return filter; } public void setFilter(SpaceCharFilter filter) { this.filter = filter; } } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } }
Java
["2"]
1 second
["2\nC.\n.C"]
null
Java 7
standard input
[ "implementation" ]
1aede54b41d6fad3e74f24a6592198eb
The first line contains an integer n (1 ≤ n ≤ 1000).
800
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.
standard output
PASSED
e9dd7d674e6c224916b523aad3d479fd
train_003.jsonl
1390231800
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y), (x–1, y), (x, y + 1) and (x, y–1).Iahub wants to know how many Coders can be placed on an n × n chessboard, so that no Coder attacks any other Coder.
256 megabytes
import java.util.Scanner; public class Problem384 { /** * @param args */ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int countEven = 0; int countOdd = 0; StringBuilder sbEven = new StringBuilder(""); StringBuilder sbOdd = new StringBuilder(""); for (int i=0; i<n; i++) { if (i%2 == 0) { sbEven.append("C"); sbOdd.append("."); countEven++; } else { sbEven.append("."); sbOdd.append("C"); countOdd++; } } System.out.println(countEven * countEven + countOdd * countOdd); for (int i=0; i<n; i++) { if (i%2 == 0) { System.out.println(sbEven.toString()); } else { System.out.println(sbOdd.toString()); } } } }
Java
["2"]
1 second
["2\nC.\n.C"]
null
Java 7
standard input
[ "implementation" ]
1aede54b41d6fad3e74f24a6592198eb
The first line contains an integer n (1 ≤ n ≤ 1000).
800
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.
standard output
PASSED
65adfc5e96843d582b3cf6efdcd14af4
train_003.jsonl
1390231800
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y), (x–1, y), (x, y + 1) and (x, y–1).Iahub wants to know how many Coders can be placed on an n × n chessboard, so that no Coder attacks any other Coder.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[]args) { int n,i,j; String fila1; String fila2; Scanner s=new Scanner(System.in); n=s.nextInt(); fila1=new String("");; fila2=new String(""); if(n%2==0) System.out.println((n*n)/2); else System.out.println(((n*n)/2)+1); for(i=0;i<n;i++) { if(i%2==0) fila1+='C'; else fila1+='.'; } for(i=0;i<n;i++) { if(i%2==0) fila2+='.'; else fila2+='C'; } for(i=0;i<n;i++) { if(i%2==0) System.out.println(fila1); else System.out.println(fila2); } } }
Java
["2"]
1 second
["2\nC.\n.C"]
null
Java 7
standard input
[ "implementation" ]
1aede54b41d6fad3e74f24a6592198eb
The first line contains an integer n (1 ≤ n ≤ 1000).
800
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.
standard output
PASSED
b36bf7ffb3020dedc756c707062c7256
train_003.jsonl
1390231800
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y), (x–1, y), (x, y + 1) and (x, y–1).Iahub wants to know how many Coders can be placed on an n × n chessboard, so that no Coder attacks any other Coder.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String... args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); System.out.println((n*n+1)/2); for (int i=0; i<n; i++){ for (int j=0; j<n; j++){ System.out.print((i+j)%2==0?"C":"."); } System.out.println(); } } }
Java
["2"]
1 second
["2\nC.\n.C"]
null
Java 7
standard input
[ "implementation" ]
1aede54b41d6fad3e74f24a6592198eb
The first line contains an integer n (1 ≤ n ≤ 1000).
800
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.
standard output
PASSED
13bb39b2a43fcaec14f04ee9beae1950
train_003.jsonl
1390231800
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y), (x–1, y), (x, y + 1) and (x, y–1).Iahub wants to know how many Coders can be placed on an n × n chessboard, so that no Coder attacks any other Coder.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String... args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); System.out.println((n*n+1)/2); for (int i=0; i<n; i++){ for (int j=0; j<n; j++){ System.out.print((i+j)%2==0?"C":"."); } System.out.println(); } } }
Java
["2"]
1 second
["2\nC.\n.C"]
null
Java 7
standard input
[ "implementation" ]
1aede54b41d6fad3e74f24a6592198eb
The first line contains an integer n (1 ≤ n ≤ 1000).
800
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.
standard output
PASSED
38b0919bda01d157da27948c6fec249d
train_003.jsonl
1390231800
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y), (x–1, y), (x, y + 1) and (x, y–1).Iahub wants to know how many Coders can be placed on an n × n chessboard, so that no Coder attacks any other Coder.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class A { public static void main(String[] args) throws IOException { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(bf.readLine()); if(n%2==0){ System.out.println(n*n/2); } else{ System.out.println(n/2*n + (int)Math.ceil(n/2.0)); } String print = ""; for(int r = 1; r <= 1; ++r){ for (int c = 1; c <= n+1; c++) { if((r+c)%2==0) print += "C"; else print += "."; } } for(int r = 1; r <= n; ++r){ if(r%2==1){ System.out.println(print.substring(0, n)); } else{ System.out.println(print.substring(1, n+1)); } } } }
Java
["2"]
1 second
["2\nC.\n.C"]
null
Java 7
standard input
[ "implementation" ]
1aede54b41d6fad3e74f24a6592198eb
The first line contains an integer n (1 ≤ n ≤ 1000).
800
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.
standard output
PASSED
46f7765b28ed571609daee767c8250fe
train_003.jsonl
1390231800
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y), (x–1, y), (x, y + 1) and (x, y–1).Iahub wants to know how many Coders can be placed on an n × n chessboard, so that no Coder attacks any other Coder.
256 megabytes
import java.util.Scanner; public class A384 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); System.out.println((n / 2) * (n / 2) + (n / 2 + (n % 2)) * (n / 2 + (n % 2))); String [] st = new String[2]; for(int i = 1; i <= 2; i++){ String s = ""; int a = i % 2; for(int j = 1; j <= n; j++){ if (j % 2 == a){ s = s.concat("C"); }else{ s = s.concat("."); } } st[i-1] = s; } for(int i = 0; i< n; i++){ System.out.println(st[i % 2]); } sc.close(); } }
Java
["2"]
1 second
["2\nC.\n.C"]
null
Java 7
standard input
[ "implementation" ]
1aede54b41d6fad3e74f24a6592198eb
The first line contains an integer n (1 ≤ n ≤ 1000).
800
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.
standard output
PASSED
5e207dcef9329300e91969811ac7f301
train_003.jsonl
1390231800
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y), (x–1, y), (x, y + 1) and (x, y–1).Iahub wants to know how many Coders can be placed on an n × n chessboard, so that no Coder attacks any other Coder.
256 megabytes
/** * * @author Faruk */ import java.util.Arrays; import java.util.Scanner; import java.util.HashSet; import java.util.HashMap; import java.util.ArrayList; public class tmp { public static void main(String [] args){ Scanner scan = new Scanner(System.in); int n = scan.nextInt(); System.out.println(((n+1)/2)*((n+1)/2) + (n/2)*(n/2)); StringBuilder sb = new StringBuilder(); for(int i=0; i<n; i++){ for(int j=0; j<n; j++){ sb.append(i%2 == j%2 ? "C":"."); } sb.append("\n"); } System.out.println(sb.toString()); } }
Java
["2"]
1 second
["2\nC.\n.C"]
null
Java 7
standard input
[ "implementation" ]
1aede54b41d6fad3e74f24a6592198eb
The first line contains an integer n (1 ≤ n ≤ 1000).
800
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.
standard output
PASSED
32e066d8ad60b3b0fb315afc5e5d7c94
train_003.jsonl
1390231800
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y), (x–1, y), (x, y + 1) and (x, y–1).Iahub wants to know how many Coders can be placed on an n × n chessboard, so that no Coder attacks any other Coder.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); if (n%2 == 0) { System.out.println(n*n/2); for (int i=0; i<n; i++) { for (int j=0; j<n; j++) { if (i%2 == j%2) System.out.print("C"); else System.out.print("."); } System.out.println(); } } else { System.out.println(n*n/2+1); for (int i=0; i<n; i++) { for (int j=0; j<n; j++) { if (i%2 == j%2) System.out.print("C"); else System.out.print("."); } System.out.println(); } } } }
Java
["2"]
1 second
["2\nC.\n.C"]
null
Java 7
standard input
[ "implementation" ]
1aede54b41d6fad3e74f24a6592198eb
The first line contains an integer n (1 ≤ n ≤ 1000).
800
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.
standard output
PASSED
f47ed526fa272b4f39940c03a12dbc68
train_003.jsonl
1390231800
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y), (x–1, y), (x, y + 1) and (x, y–1).Iahub wants to know how many Coders can be placed on an n × n chessboard, so that no Coder attacks any other Coder.
256 megabytes
import com.sun.org.apache.xerces.internal.impl.xs.identity.Selector; import java.io.PrintStream; import java.util.Arrays; import java.util.PriorityQueue; import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); PrintStream out = System.out; int n = in.nextInt(); int total = 0; for(int i=0;i<n;i++) { total += ((i/2)*2)+1; } out.println(total); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if(i%2 == 0) { if(j%2 == 0) { out.print("C"); } else { out.print("."); } } else { if(j%2 == 0) { out.print("."); } else { out.print("C"); } } } out.println(); } out.flush(); out.close(); } }
Java
["2"]
1 second
["2\nC.\n.C"]
null
Java 7
standard input
[ "implementation" ]
1aede54b41d6fad3e74f24a6592198eb
The first line contains an integer n (1 ≤ n ≤ 1000).
800
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.
standard output
PASSED
bcb18479867cbafbe0d7e2606b24a751
train_003.jsonl
1390231800
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y), (x–1, y), (x, y + 1) and (x, y–1).Iahub wants to know how many Coders can be placed on an n × n chessboard, so that no Coder attacks any other Coder.
256 megabytes
import java.util.Scanner; public class Main{ public static void main(String[] args) { // TODO Auto-generated method stub Scanner key = new Scanner(System.in); int n = key.nextInt(); if (n % 2 == 0) { System.out.println(n / 2 * n); } else { System.out.println((n / 2) * (n / 2) + (n / 2 + 1) * (n / 2 + 1)); } String even = "", odd = ""; for (int j = 0; j < n; j++) { if (j % 2 == 0) { even += "C"; odd += "."; } else { even += "."; odd += "C"; } } for (int i = 0; i < n; i++) { if (i % 2 == 0) System.out.println(even); else System.out.println(odd); } } }
Java
["2"]
1 second
["2\nC.\n.C"]
null
Java 7
standard input
[ "implementation" ]
1aede54b41d6fad3e74f24a6592198eb
The first line contains an integer n (1 ≤ n ≤ 1000).
800
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.
standard output
PASSED
7308451964a9008d9075cfca28cb1e9d
train_003.jsonl
1390231800
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y), (x–1, y), (x, y + 1) and (x, y–1).Iahub wants to know how many Coders can be placed on an n × n chessboard, so that no Coder attacks any other Coder.
256 megabytes
import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileInputStream; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.StringTokenizer; /** * @author Jens Staahl */ public class Magnets { // some local config // static boolean test = false ; private boolean test = System.getProperty("ONLINE_JUDGE") == null; static String testDataFile = "testdata.txt"; // static String testDataFile = "testdata.txt"; private static String ENDL = "\n"; // Just solves the acutal kattis-problem ZKattio io; private void solve() throws Throwable { io = new ZKattio(stream); int n = io.getInt(); System.out.println(n*n/2 + ((n*n) % 2) ); for (int i = 0; i < n; i++) { StringBuilder sb = new StringBuilder(); for (int j = 0; j < n; j++) { if((i+j) % 2 == 0){ sb.append("C"); } else { sb.append("."); } } System.out.println(sb.toString()); } } public static void main(String[] args) throws Throwable { new Magnets().solve(); } public Magnets() throws Throwable { if (test) { stream = new FileInputStream(testDataFile); } } InputStream stream = System.in; BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));// outStream // = public class ZKattio extends PrintWriter { public ZKattio(InputStream i) { super(new BufferedOutputStream(System.out)); r = new BufferedReader(new InputStreamReader(i)); } public ZKattio(InputStream i, OutputStream o) { super(new BufferedOutputStream(o)); r = new BufferedReader(new InputStreamReader(i)); } public boolean hasMoreTokens() { return peekToken() != null; } public int getInt() { return Integer.parseInt(nextToken()); } public double getDouble() { return Double.parseDouble(nextToken()); } public long getLong() { return Long.parseLong(nextToken()); } public String getWord() { return nextToken(); } private BufferedReader r; private String line; private StringTokenizer st; private String token; private String peekToken() { if (token == null) try { while (st == null || !st.hasMoreTokens()) { line = r.readLine(); if (line == null) return null; st = new StringTokenizer(line); } token = st.nextToken(); } catch (IOException e) { } return token; } private String nextToken() { String ans = peekToken(); token = null; return ans; } } // System.out; }
Java
["2"]
1 second
["2\nC.\n.C"]
null
Java 7
standard input
[ "implementation" ]
1aede54b41d6fad3e74f24a6592198eb
The first line contains an integer n (1 ≤ n ≤ 1000).
800
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.
standard output
PASSED
1c64243a289555eebe0db0bdfe48d829
train_003.jsonl
1390231800
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y), (x–1, y), (x, y + 1) and (x, y–1).Iahub wants to know how many Coders can be placed on an n × n chessboard, so that no Coder attacks any other Coder.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import org.xml.sax.InputSource; public class Main { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader reader = new BufferedReader(new InputStreamReader( System.in)); int x = Integer.parseInt(reader.readLine()); char[][] ss = new char[x][x]; int c = 0; for (int i = 0; i < ss.length; i++) { if (i % 2 == 0) { for (int j = 0; j < ss[i].length; j++) { if (j % 2 == 0) { ss[i][j] = 'C'; c++; } else { ss[i][j] = '.'; } } } else { for (int j = 0; j < ss[i].length; j++) { if (j % 2 == 0) { ss[i][j] = '.'; } else { ss[i][j] = 'C'; c++; } } } } System.out.println(c); for (int i = 0; i < ss.length; i++) { for (int j = 0; j < ss[i].length; j++) { System.out.print(ss[i][j]); } System.out.println(); } } }
Java
["2"]
1 second
["2\nC.\n.C"]
null
Java 7
standard input
[ "implementation" ]
1aede54b41d6fad3e74f24a6592198eb
The first line contains an integer n (1 ≤ n ≤ 1000).
800
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.
standard output
PASSED
9df2c1c905c094d10262f45b743085b7
train_003.jsonl
1594996500
A permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ are permutations, and $$$[1, 1]$$$, $$$[0, 1]$$$, $$$[2, 2, 1, 4]$$$ are not.There was a permutation $$$p[1 \dots n]$$$. It was merged with itself. In other words, let's take two instances of $$$p$$$ and insert elements of the second $$$p$$$ into the first maintaining relative order of elements. The result is a sequence of the length $$$2n$$$.For example, if $$$p=[3, 1, 2]$$$ some possible results are: $$$[3, 1, 2, 3, 1, 2]$$$, $$$[3, 3, 1, 1, 2, 2]$$$, $$$[3, 1, 3, 1, 2, 2]$$$. The following sequences are not possible results of a merging: $$$[1, 3, 2, 1, 2, 3$$$], [$$$3, 1, 2, 3, 2, 1]$$$, $$$[3, 3, 1, 2, 2, 1]$$$.For example, if $$$p=[2, 1]$$$ the possible results are: $$$[2, 2, 1, 1]$$$, $$$[2, 1, 2, 1]$$$. The following sequences are not possible results of a merging: $$$[1, 1, 2, 2$$$], [$$$2, 1, 1, 2]$$$, $$$[1, 2, 2, 1]$$$.Your task is to restore the permutation $$$p$$$ by the given resulting sequence $$$a$$$. It is guaranteed that the answer exists and is unique.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.HashMap; import java.util.Scanner; public class ques2 { static void removeDups(int[] arr, int n) { HashMap<Integer, Boolean> mp = new HashMap<>(); for (int i = 0; i < n; ++i) { if (mp.get(arr[i]) == null) System.out.print(arr[i] + " "); mp.put(arr[i], true); } System.out.println(); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0) { int k = sc.nextInt(); int n= 2*k; int arr[]= new int[n]; for(int i=0;i<n;i++) { arr[i]= sc.nextInt(); } removeDups(arr, n); } } }
Java
["5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1"]
1 second
["1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1"]
null
Java 8
standard input
[ "greedy" ]
aaf91874cf5aa0fa302ffed2ccecdc76
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 400$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of permutation. The second line of the test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the array $$$a$$$ represents the result of merging of some permutation $$$p$$$ with the same permutation $$$p$$$.
800
For each test case, print the answer: $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), representing the initial permutation. It is guaranteed that the answer exists and is unique.
standard output
PASSED
e9fd3739905eb3b5fe043366a311581b
train_003.jsonl
1594996500
A permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ are permutations, and $$$[1, 1]$$$, $$$[0, 1]$$$, $$$[2, 2, 1, 4]$$$ are not.There was a permutation $$$p[1 \dots n]$$$. It was merged with itself. In other words, let's take two instances of $$$p$$$ and insert elements of the second $$$p$$$ into the first maintaining relative order of elements. The result is a sequence of the length $$$2n$$$.For example, if $$$p=[3, 1, 2]$$$ some possible results are: $$$[3, 1, 2, 3, 1, 2]$$$, $$$[3, 3, 1, 1, 2, 2]$$$, $$$[3, 1, 3, 1, 2, 2]$$$. The following sequences are not possible results of a merging: $$$[1, 3, 2, 1, 2, 3$$$], [$$$3, 1, 2, 3, 2, 1]$$$, $$$[3, 3, 1, 2, 2, 1]$$$.For example, if $$$p=[2, 1]$$$ the possible results are: $$$[2, 2, 1, 1]$$$, $$$[2, 1, 2, 1]$$$. The following sequences are not possible results of a merging: $$$[1, 1, 2, 2$$$], [$$$2, 1, 1, 2]$$$, $$$[1, 2, 2, 1]$$$.Your task is to restore the permutation $$$p$$$ by the given resulting sequence $$$a$$$. It is guaranteed that the answer exists and is unique.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int o = sc.nextInt(); while(o-->0) { int[] x=new int[sc.nextInt()+1]; String tttt = sc.nextLine(); String[] s = sc.nextLine().split(" "); for(int i=0;i<s.length;i++) { int t = Integer.parseInt(s[i]); if(x[t]==0) { System.out.print(t+" "); x[t]++; } } System.out.println(); } } }
Java
["5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1"]
1 second
["1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1"]
null
Java 8
standard input
[ "greedy" ]
aaf91874cf5aa0fa302ffed2ccecdc76
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 400$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of permutation. The second line of the test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the array $$$a$$$ represents the result of merging of some permutation $$$p$$$ with the same permutation $$$p$$$.
800
For each test case, print the answer: $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), representing the initial permutation. It is guaranteed that the answer exists and is unique.
standard output
PASSED
792637a4fd353fe9b73db9dd1628646a
train_003.jsonl
1594996500
A permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ are permutations, and $$$[1, 1]$$$, $$$[0, 1]$$$, $$$[2, 2, 1, 4]$$$ are not.There was a permutation $$$p[1 \dots n]$$$. It was merged with itself. In other words, let's take two instances of $$$p$$$ and insert elements of the second $$$p$$$ into the first maintaining relative order of elements. The result is a sequence of the length $$$2n$$$.For example, if $$$p=[3, 1, 2]$$$ some possible results are: $$$[3, 1, 2, 3, 1, 2]$$$, $$$[3, 3, 1, 1, 2, 2]$$$, $$$[3, 1, 3, 1, 2, 2]$$$. The following sequences are not possible results of a merging: $$$[1, 3, 2, 1, 2, 3$$$], [$$$3, 1, 2, 3, 2, 1]$$$, $$$[3, 3, 1, 2, 2, 1]$$$.For example, if $$$p=[2, 1]$$$ the possible results are: $$$[2, 2, 1, 1]$$$, $$$[2, 1, 2, 1]$$$. The following sequences are not possible results of a merging: $$$[1, 1, 2, 2$$$], [$$$2, 1, 1, 2]$$$, $$$[1, 2, 2, 1]$$$.Your task is to restore the permutation $$$p$$$ by the given resulting sequence $$$a$$$. It is guaranteed that the answer exists and is unique.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; public class MyClass { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0) { int n = sc.nextInt(); int[] a = new int[2*n]; for(int i=0;i<2*n;i++) { a[i] = sc.nextInt(); } HashMap<Integer,Integer> hs = new HashMap<Integer,Integer>(); for(int i=0;i<2*n;i++) { if(hs.containsKey(a[i])) { continue; } else { System.out.print(a[i]+" "); hs.put(a[i],1); } } System.out.println(); } } }
Java
["5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1"]
1 second
["1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1"]
null
Java 8
standard input
[ "greedy" ]
aaf91874cf5aa0fa302ffed2ccecdc76
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 400$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of permutation. The second line of the test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the array $$$a$$$ represents the result of merging of some permutation $$$p$$$ with the same permutation $$$p$$$.
800
For each test case, print the answer: $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), representing the initial permutation. It is guaranteed that the answer exists and is unique.
standard output
PASSED
e2a82b4baf189f7ae2b8551c28e85fae
train_003.jsonl
1594996500
A permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ are permutations, and $$$[1, 1]$$$, $$$[0, 1]$$$, $$$[2, 2, 1, 4]$$$ are not.There was a permutation $$$p[1 \dots n]$$$. It was merged with itself. In other words, let's take two instances of $$$p$$$ and insert elements of the second $$$p$$$ into the first maintaining relative order of elements. The result is a sequence of the length $$$2n$$$.For example, if $$$p=[3, 1, 2]$$$ some possible results are: $$$[3, 1, 2, 3, 1, 2]$$$, $$$[3, 3, 1, 1, 2, 2]$$$, $$$[3, 1, 3, 1, 2, 2]$$$. The following sequences are not possible results of a merging: $$$[1, 3, 2, 1, 2, 3$$$], [$$$3, 1, 2, 3, 2, 1]$$$, $$$[3, 3, 1, 2, 2, 1]$$$.For example, if $$$p=[2, 1]$$$ the possible results are: $$$[2, 2, 1, 1]$$$, $$$[2, 1, 2, 1]$$$. The following sequences are not possible results of a merging: $$$[1, 1, 2, 2$$$], [$$$2, 1, 1, 2]$$$, $$$[1, 2, 2, 1]$$$.Your task is to restore the permutation $$$p$$$ by the given resulting sequence $$$a$$$. It is guaranteed that the answer exists and is unique.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.ArrayList; import java.util.Scanner; //import java.util.Arrays; public class Algorithms { static Scanner sc = new Scanner(System.in); static ArrayList<Integer> k=new ArrayList<>(); public static void main(String[] args) { int t=sc.nextInt(); int n; int p; for(int i=0;i<t;i++) { n=sc.nextInt(); k.clear(); for(int c=0;c<n*2;c++){ k.add(p=sc.nextInt()); } for(int i1=0;i1<n*2;i1++){ for(int i2=i1+1;i2<n*2;i2++){ if(k.size()==n)break; if(k.get(i1)==k.get(i2)){ k.remove(i2); System.out.print(k.get(i1)+" "); break; } } } System.out.println(); } } }
Java
["5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1"]
1 second
["1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1"]
null
Java 8
standard input
[ "greedy" ]
aaf91874cf5aa0fa302ffed2ccecdc76
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 400$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of permutation. The second line of the test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the array $$$a$$$ represents the result of merging of some permutation $$$p$$$ with the same permutation $$$p$$$.
800
For each test case, print the answer: $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), representing the initial permutation. It is guaranteed that the answer exists and is unique.
standard output
PASSED
3a1059a4b0e3be7b5be90ea7dd4e358e
train_003.jsonl
1594996500
A permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ are permutations, and $$$[1, 1]$$$, $$$[0, 1]$$$, $$$[2, 2, 1, 4]$$$ are not.There was a permutation $$$p[1 \dots n]$$$. It was merged with itself. In other words, let's take two instances of $$$p$$$ and insert elements of the second $$$p$$$ into the first maintaining relative order of elements. The result is a sequence of the length $$$2n$$$.For example, if $$$p=[3, 1, 2]$$$ some possible results are: $$$[3, 1, 2, 3, 1, 2]$$$, $$$[3, 3, 1, 1, 2, 2]$$$, $$$[3, 1, 3, 1, 2, 2]$$$. The following sequences are not possible results of a merging: $$$[1, 3, 2, 1, 2, 3$$$], [$$$3, 1, 2, 3, 2, 1]$$$, $$$[3, 3, 1, 2, 2, 1]$$$.For example, if $$$p=[2, 1]$$$ the possible results are: $$$[2, 2, 1, 1]$$$, $$$[2, 1, 2, 1]$$$. The following sequences are not possible results of a merging: $$$[1, 1, 2, 2$$$], [$$$2, 1, 1, 2]$$$, $$$[1, 2, 2, 1]$$$.Your task is to restore the permutation $$$p$$$ by the given resulting sequence $$$a$$$. It is guaranteed that the answer exists and is unique.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.ArrayList; import java.util.Scanner; //import java.util.Arrays; public class Algorithms { static Scanner sc = new Scanner(System.in); static ArrayList<Integer> k=new ArrayList<>(); public static void main(String[] args) { int t=sc.nextInt(); int n; int p; for(int i=0;i<t;i++) { n=sc.nextInt(); k.clear(); for(int c=0;c<n*2;c++){ k.add(p=sc.nextInt()); } for(int i1=0;i1<n*2;i1++){ for(int i2=i1+1;i2<n*2;i2++){ if(k.size()==n)break; if(k.get(i1)==k.get(i2)){ k.remove(i2); break; } } } for(int x:k)System.out.print(x+" "); System.out.println(); } } }
Java
["5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1"]
1 second
["1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1"]
null
Java 8
standard input
[ "greedy" ]
aaf91874cf5aa0fa302ffed2ccecdc76
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 400$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of permutation. The second line of the test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the array $$$a$$$ represents the result of merging of some permutation $$$p$$$ with the same permutation $$$p$$$.
800
For each test case, print the answer: $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), representing the initial permutation. It is guaranteed that the answer exists and is unique.
standard output
PASSED
1c5ea7a6c8a5d4b6a96fe4477c5f519f
train_003.jsonl
1594996500
A permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ are permutations, and $$$[1, 1]$$$, $$$[0, 1]$$$, $$$[2, 2, 1, 4]$$$ are not.There was a permutation $$$p[1 \dots n]$$$. It was merged with itself. In other words, let's take two instances of $$$p$$$ and insert elements of the second $$$p$$$ into the first maintaining relative order of elements. The result is a sequence of the length $$$2n$$$.For example, if $$$p=[3, 1, 2]$$$ some possible results are: $$$[3, 1, 2, 3, 1, 2]$$$, $$$[3, 3, 1, 1, 2, 2]$$$, $$$[3, 1, 3, 1, 2, 2]$$$. The following sequences are not possible results of a merging: $$$[1, 3, 2, 1, 2, 3$$$], [$$$3, 1, 2, 3, 2, 1]$$$, $$$[3, 3, 1, 2, 2, 1]$$$.For example, if $$$p=[2, 1]$$$ the possible results are: $$$[2, 2, 1, 1]$$$, $$$[2, 1, 2, 1]$$$. The following sequences are not possible results of a merging: $$$[1, 1, 2, 2$$$], [$$$2, 1, 1, 2]$$$, $$$[1, 2, 2, 1]$$$.Your task is to restore the permutation $$$p$$$ by the given resulting sequence $$$a$$$. It is guaranteed that the answer exists and is unique.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.io.*; import java.util.*; public class MyClass { public static void main(String args[]) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader (System.in)); int t=Integer.parseInt(br.readLine()); while(t-- >0) { int n=Integer.parseInt(br.readLine()); String line[]=br.readLine().split(" "); int arr[]=new int[51]; Arrays.fill(arr,0); for(int i=0;i<2*n-1;i++) { int a=Integer.parseInt(line[i]); if(arr[a]==0) System.out.print(a+" "); arr[a]++; } System.out.println(); } } }
Java
["5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1"]
1 second
["1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1"]
null
Java 8
standard input
[ "greedy" ]
aaf91874cf5aa0fa302ffed2ccecdc76
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 400$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of permutation. The second line of the test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the array $$$a$$$ represents the result of merging of some permutation $$$p$$$ with the same permutation $$$p$$$.
800
For each test case, print the answer: $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), representing the initial permutation. It is guaranteed that the answer exists and is unique.
standard output
PASSED
93a0a083b7fc6152deaa91450011ce99
train_003.jsonl
1594996500
A permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ are permutations, and $$$[1, 1]$$$, $$$[0, 1]$$$, $$$[2, 2, 1, 4]$$$ are not.There was a permutation $$$p[1 \dots n]$$$. It was merged with itself. In other words, let's take two instances of $$$p$$$ and insert elements of the second $$$p$$$ into the first maintaining relative order of elements. The result is a sequence of the length $$$2n$$$.For example, if $$$p=[3, 1, 2]$$$ some possible results are: $$$[3, 1, 2, 3, 1, 2]$$$, $$$[3, 3, 1, 1, 2, 2]$$$, $$$[3, 1, 3, 1, 2, 2]$$$. The following sequences are not possible results of a merging: $$$[1, 3, 2, 1, 2, 3$$$], [$$$3, 1, 2, 3, 2, 1]$$$, $$$[3, 3, 1, 2, 2, 1]$$$.For example, if $$$p=[2, 1]$$$ the possible results are: $$$[2, 2, 1, 1]$$$, $$$[2, 1, 2, 1]$$$. The following sequences are not possible results of a merging: $$$[1, 1, 2, 2$$$], [$$$2, 1, 1, 2]$$$, $$$[1, 2, 2, 1]$$$.Your task is to restore the permutation $$$p$$$ by the given resulting sequence $$$a$$$. It is guaranteed that the answer exists and is unique.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.StringTokenizer; public class Q1{ static StringTokenizer st; static InputStreamReader ir; static BufferedReader br; public static void main(String[] args) throws IOException { ir=new InputStreamReader(System.in); br=new BufferedReader(ir); int test=Integer.parseInt(br.readLine()); while(test--!=0){ int n=Integer.parseInt(br.readLine()); int done[]=new int[n+4]; Arrays.fill(done, 0); ArrayList<Integer> arr=intArray(br.readLine()); for(int i=0;i<n*2;i++) { int no=arr.get(i); if(done[no]==0) System.out.print(no+" "); done[no]++; } System.out.println(); } } public static ArrayList<String> stringArray(String s){ ArrayList<String> a=new ArrayList<>(); st=new StringTokenizer(s); while(st.hasMoreTokens()) a.add(st.nextToken()); return a; } public static ArrayList<Integer> intArray(String s){ ArrayList<Integer> a=new ArrayList<>(); st=new StringTokenizer(s); while(st.hasMoreTokens()) a.add(Integer.parseInt(st.nextToken())); return a; } }
Java
["5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1"]
1 second
["1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1"]
null
Java 8
standard input
[ "greedy" ]
aaf91874cf5aa0fa302ffed2ccecdc76
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 400$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of permutation. The second line of the test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the array $$$a$$$ represents the result of merging of some permutation $$$p$$$ with the same permutation $$$p$$$.
800
For each test case, print the answer: $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), representing the initial permutation. It is guaranteed that the answer exists and is unique.
standard output
PASSED
8014701e62f19c3a9cedccd9a76deecf
train_003.jsonl
1594996500
A permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ are permutations, and $$$[1, 1]$$$, $$$[0, 1]$$$, $$$[2, 2, 1, 4]$$$ are not.There was a permutation $$$p[1 \dots n]$$$. It was merged with itself. In other words, let's take two instances of $$$p$$$ and insert elements of the second $$$p$$$ into the first maintaining relative order of elements. The result is a sequence of the length $$$2n$$$.For example, if $$$p=[3, 1, 2]$$$ some possible results are: $$$[3, 1, 2, 3, 1, 2]$$$, $$$[3, 3, 1, 1, 2, 2]$$$, $$$[3, 1, 3, 1, 2, 2]$$$. The following sequences are not possible results of a merging: $$$[1, 3, 2, 1, 2, 3$$$], [$$$3, 1, 2, 3, 2, 1]$$$, $$$[3, 3, 1, 2, 2, 1]$$$.For example, if $$$p=[2, 1]$$$ the possible results are: $$$[2, 2, 1, 1]$$$, $$$[2, 1, 2, 1]$$$. The following sequences are not possible results of a merging: $$$[1, 1, 2, 2$$$], [$$$2, 1, 1, 2]$$$, $$$[1, 2, 2, 1]$$$.Your task is to restore the permutation $$$p$$$ by the given resulting sequence $$$a$$$. It is guaranteed that the answer exists and is unique.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.StringTokenizer; public class Q2{ static StringTokenizer st; static InputStreamReader ir; static BufferedReader br; public static void main(String[] args) throws IOException { ir=new InputStreamReader(System.in); br=new BufferedReader(ir); int test=Integer.parseInt(br.readLine()); while(test--!=0){ int n=Integer.parseInt(br.readLine()); int done[]=new int[n+4]; Arrays.fill(done, 0); ArrayList<Integer> arr=intArray(br.readLine()); for(int i=0;i<n*2;i++) { int no=arr.get(i); if(done[no]==0) System.out.print(no+" "); done[no]++; } System.out.println(); } } public static ArrayList<String> stringArray(String s){ ArrayList<String> a=new ArrayList<>(); st=new StringTokenizer(s); while(st.hasMoreTokens()) a.add(st.nextToken()); return a; } public static ArrayList<Integer> intArray(String s){ ArrayList<Integer> a=new ArrayList<>(); st=new StringTokenizer(s); while(st.hasMoreTokens()) a.add(Integer.parseInt(st.nextToken())); return a; } }
Java
["5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1"]
1 second
["1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1"]
null
Java 8
standard input
[ "greedy" ]
aaf91874cf5aa0fa302ffed2ccecdc76
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 400$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of permutation. The second line of the test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the array $$$a$$$ represents the result of merging of some permutation $$$p$$$ with the same permutation $$$p$$$.
800
For each test case, print the answer: $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), representing the initial permutation. It is guaranteed that the answer exists and is unique.
standard output
PASSED
9b37d2df23175f04e6d647b1df61d63a
train_003.jsonl
1594996500
A permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ are permutations, and $$$[1, 1]$$$, $$$[0, 1]$$$, $$$[2, 2, 1, 4]$$$ are not.There was a permutation $$$p[1 \dots n]$$$. It was merged with itself. In other words, let's take two instances of $$$p$$$ and insert elements of the second $$$p$$$ into the first maintaining relative order of elements. The result is a sequence of the length $$$2n$$$.For example, if $$$p=[3, 1, 2]$$$ some possible results are: $$$[3, 1, 2, 3, 1, 2]$$$, $$$[3, 3, 1, 1, 2, 2]$$$, $$$[3, 1, 3, 1, 2, 2]$$$. The following sequences are not possible results of a merging: $$$[1, 3, 2, 1, 2, 3$$$], [$$$3, 1, 2, 3, 2, 1]$$$, $$$[3, 3, 1, 2, 2, 1]$$$.For example, if $$$p=[2, 1]$$$ the possible results are: $$$[2, 2, 1, 1]$$$, $$$[2, 1, 2, 1]$$$. The following sequences are not possible results of a merging: $$$[1, 1, 2, 2$$$], [$$$2, 1, 1, 2]$$$, $$$[1, 2, 2, 1]$$$.Your task is to restore the permutation $$$p$$$ by the given resulting sequence $$$a$$$. It is guaranteed that the answer exists and is unique.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.ArrayList; import java.util.HashSet; import java.util.Scanner; import java.util.Set; public class Codeforce { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int numberOfTestCase = scanner.nextInt(); while (numberOfTestCase > 0){ int subArraySize = scanner.nextInt(); Set<Integer> set = new HashSet<>(); ArrayList<Integer> result = new ArrayList<>(); for (int i = 0; i < 2*subArraySize; i++){ int input = scanner.nextInt(); if (!set.contains(input)){ set.add(input); result.add(input); } } for (int i = 0; i < subArraySize; i++) { System.out.print(result.get(i) + " "); } System.out.println(); numberOfTestCase--; } } }
Java
["5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1"]
1 second
["1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1"]
null
Java 8
standard input
[ "greedy" ]
aaf91874cf5aa0fa302ffed2ccecdc76
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 400$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of permutation. The second line of the test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the array $$$a$$$ represents the result of merging of some permutation $$$p$$$ with the same permutation $$$p$$$.
800
For each test case, print the answer: $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), representing the initial permutation. It is guaranteed that the answer exists and is unique.
standard output
PASSED
31dca4856d9578fbfcaa81e2c6d3f4d2
train_003.jsonl
1594996500
A permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ are permutations, and $$$[1, 1]$$$, $$$[0, 1]$$$, $$$[2, 2, 1, 4]$$$ are not.There was a permutation $$$p[1 \dots n]$$$. It was merged with itself. In other words, let's take two instances of $$$p$$$ and insert elements of the second $$$p$$$ into the first maintaining relative order of elements. The result is a sequence of the length $$$2n$$$.For example, if $$$p=[3, 1, 2]$$$ some possible results are: $$$[3, 1, 2, 3, 1, 2]$$$, $$$[3, 3, 1, 1, 2, 2]$$$, $$$[3, 1, 3, 1, 2, 2]$$$. The following sequences are not possible results of a merging: $$$[1, 3, 2, 1, 2, 3$$$], [$$$3, 1, 2, 3, 2, 1]$$$, $$$[3, 3, 1, 2, 2, 1]$$$.For example, if $$$p=[2, 1]$$$ the possible results are: $$$[2, 2, 1, 1]$$$, $$$[2, 1, 2, 1]$$$. The following sequences are not possible results of a merging: $$$[1, 1, 2, 2$$$], [$$$2, 1, 1, 2]$$$, $$$[1, 2, 2, 1]$$$.Your task is to restore the permutation $$$p$$$ by the given resulting sequence $$$a$$$. It is guaranteed that the answer exists and is unique.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t>0) { int n=sc.nextInt(); Set<Integer> set=new LinkedHashSet<>(); for(int i=0;i<2*n;i++) { set.add(sc.nextInt()); } for(Integer i:set) System.out.print(i+" "); System.out.println(""); t--; } } }
Java
["5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1"]
1 second
["1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1"]
null
Java 8
standard input
[ "greedy" ]
aaf91874cf5aa0fa302ffed2ccecdc76
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 400$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of permutation. The second line of the test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the array $$$a$$$ represents the result of merging of some permutation $$$p$$$ with the same permutation $$$p$$$.
800
For each test case, print the answer: $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), representing the initial permutation. It is guaranteed that the answer exists and is unique.
standard output
PASSED
b2b8ed7ad79cb8dd221ab8abe7c425a5
train_003.jsonl
1594996500
A permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ are permutations, and $$$[1, 1]$$$, $$$[0, 1]$$$, $$$[2, 2, 1, 4]$$$ are not.There was a permutation $$$p[1 \dots n]$$$. It was merged with itself. In other words, let's take two instances of $$$p$$$ and insert elements of the second $$$p$$$ into the first maintaining relative order of elements. The result is a sequence of the length $$$2n$$$.For example, if $$$p=[3, 1, 2]$$$ some possible results are: $$$[3, 1, 2, 3, 1, 2]$$$, $$$[3, 3, 1, 1, 2, 2]$$$, $$$[3, 1, 3, 1, 2, 2]$$$. The following sequences are not possible results of a merging: $$$[1, 3, 2, 1, 2, 3$$$], [$$$3, 1, 2, 3, 2, 1]$$$, $$$[3, 3, 1, 2, 2, 1]$$$.For example, if $$$p=[2, 1]$$$ the possible results are: $$$[2, 2, 1, 1]$$$, $$$[2, 1, 2, 1]$$$. The following sequences are not possible results of a merging: $$$[1, 1, 2, 2$$$], [$$$2, 1, 1, 2]$$$, $$$[1, 2, 2, 1]$$$.Your task is to restore the permutation $$$p$$$ by the given resulting sequence $$$a$$$. It is guaranteed that the answer exists and is unique.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0) { int n = sc.nextInt(); int[] a = new int[2*n]; for(int i=0;i<2*n;i++) a[i] = sc.nextInt(); HashSet<Integer> hs = new HashSet<>(); for(int i=0;i<2*n;i++) { if(!hs.contains(a[i])) { System.out.print(a[i]+" "); hs.add(a[i]); } } System.out.println(); } } }
Java
["5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1"]
1 second
["1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1"]
null
Java 8
standard input
[ "greedy" ]
aaf91874cf5aa0fa302ffed2ccecdc76
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 400$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of permutation. The second line of the test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the array $$$a$$$ represents the result of merging of some permutation $$$p$$$ with the same permutation $$$p$$$.
800
For each test case, print the answer: $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), representing the initial permutation. It is guaranteed that the answer exists and is unique.
standard output
PASSED
696cd2e1a66c1a73bd587cc61f1ace17
train_003.jsonl
1594996500
A permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ are permutations, and $$$[1, 1]$$$, $$$[0, 1]$$$, $$$[2, 2, 1, 4]$$$ are not.There was a permutation $$$p[1 \dots n]$$$. It was merged with itself. In other words, let's take two instances of $$$p$$$ and insert elements of the second $$$p$$$ into the first maintaining relative order of elements. The result is a sequence of the length $$$2n$$$.For example, if $$$p=[3, 1, 2]$$$ some possible results are: $$$[3, 1, 2, 3, 1, 2]$$$, $$$[3, 3, 1, 1, 2, 2]$$$, $$$[3, 1, 3, 1, 2, 2]$$$. The following sequences are not possible results of a merging: $$$[1, 3, 2, 1, 2, 3$$$], [$$$3, 1, 2, 3, 2, 1]$$$, $$$[3, 3, 1, 2, 2, 1]$$$.For example, if $$$p=[2, 1]$$$ the possible results are: $$$[2, 2, 1, 1]$$$, $$$[2, 1, 2, 1]$$$. The following sequences are not possible results of a merging: $$$[1, 1, 2, 2$$$], [$$$2, 1, 1, 2]$$$, $$$[1, 2, 2, 1]$$$.Your task is to restore the permutation $$$p$$$ by the given resulting sequence $$$a$$$. It is guaranteed that the answer exists and is unique.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; public class RestorethePermutationbyMerger { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int k=1;k<=t;k++) { int n=sc.nextInt(); int a[]=new int[2*n]; for(int i=0;i<2*n;i++) a[i]=sc.nextInt(); LinkedHashSet<Integer> set=new LinkedHashSet<Integer>(); for(int i=0;i<2*n;i++) { set.add(a[i]); } System.out.println(set.toString().replaceAll("[\\[|\\]|]","").replace(",","")); } } }
Java
["5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1"]
1 second
["1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1"]
null
Java 8
standard input
[ "greedy" ]
aaf91874cf5aa0fa302ffed2ccecdc76
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 400$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of permutation. The second line of the test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the array $$$a$$$ represents the result of merging of some permutation $$$p$$$ with the same permutation $$$p$$$.
800
For each test case, print the answer: $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), representing the initial permutation. It is guaranteed that the answer exists and is unique.
standard output
PASSED
3c5b5d5e5e91536fe5a671eb2ebd5bd6
train_003.jsonl
1594996500
A permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ are permutations, and $$$[1, 1]$$$, $$$[0, 1]$$$, $$$[2, 2, 1, 4]$$$ are not.There was a permutation $$$p[1 \dots n]$$$. It was merged with itself. In other words, let's take two instances of $$$p$$$ and insert elements of the second $$$p$$$ into the first maintaining relative order of elements. The result is a sequence of the length $$$2n$$$.For example, if $$$p=[3, 1, 2]$$$ some possible results are: $$$[3, 1, 2, 3, 1, 2]$$$, $$$[3, 3, 1, 1, 2, 2]$$$, $$$[3, 1, 3, 1, 2, 2]$$$. The following sequences are not possible results of a merging: $$$[1, 3, 2, 1, 2, 3$$$], [$$$3, 1, 2, 3, 2, 1]$$$, $$$[3, 3, 1, 2, 2, 1]$$$.For example, if $$$p=[2, 1]$$$ the possible results are: $$$[2, 2, 1, 1]$$$, $$$[2, 1, 2, 1]$$$. The following sequences are not possible results of a merging: $$$[1, 1, 2, 2$$$], [$$$2, 1, 1, 2]$$$, $$$[1, 2, 2, 1]$$$.Your task is to restore the permutation $$$p$$$ by the given resulting sequence $$$a$$$. It is guaranteed that the answer exists and is unique.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class Solution { public static void main(String args[]) { Scanner s=new Scanner(System.in); int t=s.nextInt(); while(t-->0) { int n=s.nextInt(); int arr[]=new int[2*n]; for(int i=0;i<2*n;i++) { arr[i]=s.nextInt(); } ArrayList<Integer> al=new ArrayList<>(); HashMap<Integer,Integer> map=new HashMap<>(); for(int i=0;i<2*n;i++) { if(!map.containsKey(arr[i])) { map.put(arr[i],1); al.add(arr[i]); } } for(int i=0;i<al.size();i++) { System.out.print(al.get(i)+" "); } System.out.println(); } } }
Java
["5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1"]
1 second
["1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1"]
null
Java 8
standard input
[ "greedy" ]
aaf91874cf5aa0fa302ffed2ccecdc76
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 400$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of permutation. The second line of the test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the array $$$a$$$ represents the result of merging of some permutation $$$p$$$ with the same permutation $$$p$$$.
800
For each test case, print the answer: $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), representing the initial permutation. It is guaranteed that the answer exists and is unique.
standard output
PASSED
0888924dda98fcfe1cb6367df4eec7c1
train_003.jsonl
1594996500
A permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ are permutations, and $$$[1, 1]$$$, $$$[0, 1]$$$, $$$[2, 2, 1, 4]$$$ are not.There was a permutation $$$p[1 \dots n]$$$. It was merged with itself. In other words, let's take two instances of $$$p$$$ and insert elements of the second $$$p$$$ into the first maintaining relative order of elements. The result is a sequence of the length $$$2n$$$.For example, if $$$p=[3, 1, 2]$$$ some possible results are: $$$[3, 1, 2, 3, 1, 2]$$$, $$$[3, 3, 1, 1, 2, 2]$$$, $$$[3, 1, 3, 1, 2, 2]$$$. The following sequences are not possible results of a merging: $$$[1, 3, 2, 1, 2, 3$$$], [$$$3, 1, 2, 3, 2, 1]$$$, $$$[3, 3, 1, 2, 2, 1]$$$.For example, if $$$p=[2, 1]$$$ the possible results are: $$$[2, 2, 1, 1]$$$, $$$[2, 1, 2, 1]$$$. The following sequences are not possible results of a merging: $$$[1, 1, 2, 2$$$], [$$$2, 1, 1, 2]$$$, $$$[1, 2, 2, 1]$$$.Your task is to restore the permutation $$$p$$$ by the given resulting sequence $$$a$$$. It is guaranteed that the answer exists and is unique.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; public class cfperm{ public static void main(String[]args) { Scanner scn=new Scanner(System.in); int tc=scn.nextInt(); for(int i9=0;i9<tc;i9++) { int n=scn.nextInt(); int[]inp=new int[2*n]; for(int i=0;i<2*n;i++) inp[i]=scn.nextInt(); boolean[]arr=new boolean[n+1]; int []res=new int[n]; int k=0; for(int i=0;i<2*n;i++) { if(arr[inp[i]]==false) { arr[inp[i]]=true; res[k]=inp[i]; k++; } } for(int i=0;i<n;i++) System.out.print(res[i]+" "); System.out.println(); } } }
Java
["5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1"]
1 second
["1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1"]
null
Java 8
standard input
[ "greedy" ]
aaf91874cf5aa0fa302ffed2ccecdc76
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 400$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of permutation. The second line of the test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the array $$$a$$$ represents the result of merging of some permutation $$$p$$$ with the same permutation $$$p$$$.
800
For each test case, print the answer: $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), representing the initial permutation. It is guaranteed that the answer exists and is unique.
standard output
PASSED
5fd42bc32a71224849226428083f79e7
train_003.jsonl
1594996500
A permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ are permutations, and $$$[1, 1]$$$, $$$[0, 1]$$$, $$$[2, 2, 1, 4]$$$ are not.There was a permutation $$$p[1 \dots n]$$$. It was merged with itself. In other words, let's take two instances of $$$p$$$ and insert elements of the second $$$p$$$ into the first maintaining relative order of elements. The result is a sequence of the length $$$2n$$$.For example, if $$$p=[3, 1, 2]$$$ some possible results are: $$$[3, 1, 2, 3, 1, 2]$$$, $$$[3, 3, 1, 1, 2, 2]$$$, $$$[3, 1, 3, 1, 2, 2]$$$. The following sequences are not possible results of a merging: $$$[1, 3, 2, 1, 2, 3$$$], [$$$3, 1, 2, 3, 2, 1]$$$, $$$[3, 3, 1, 2, 2, 1]$$$.For example, if $$$p=[2, 1]$$$ the possible results are: $$$[2, 2, 1, 1]$$$, $$$[2, 1, 2, 1]$$$. The following sequences are not possible results of a merging: $$$[1, 1, 2, 2$$$], [$$$2, 1, 1, 2]$$$, $$$[1, 2, 2, 1]$$$.Your task is to restore the permutation $$$p$$$ by the given resulting sequence $$$a$$$. It is guaranteed that the answer exists and is unique.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; /** * * @author Aaryan */ public class Test { public static void main(String[] args) { Scanner input = new Scanner(System.in); int tc = input.nextInt(); while(tc-->0){ HashMap<Integer,Integer> map = new HashMap<>(); int n = input.nextInt(); for(int i =0; i<2*n; i++){ int v = input.nextInt(); //System.out.println("v is "+v); if(!map.containsValue(v)){ map.put(i, v); } } for(int i=0; i<2*n; i++){ if(map.get(i)!=null){ System.out.print(map.get(i)+" "); } } System.out.println(); } } }
Java
["5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1"]
1 second
["1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1"]
null
Java 8
standard input
[ "greedy" ]
aaf91874cf5aa0fa302ffed2ccecdc76
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 400$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of permutation. The second line of the test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the array $$$a$$$ represents the result of merging of some permutation $$$p$$$ with the same permutation $$$p$$$.
800
For each test case, print the answer: $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), representing the initial permutation. It is guaranteed that the answer exists and is unique.
standard output
PASSED
6c17cc8610178442543a1c0c08ffbe09
train_003.jsonl
1594996500
A permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ are permutations, and $$$[1, 1]$$$, $$$[0, 1]$$$, $$$[2, 2, 1, 4]$$$ are not.There was a permutation $$$p[1 \dots n]$$$. It was merged with itself. In other words, let's take two instances of $$$p$$$ and insert elements of the second $$$p$$$ into the first maintaining relative order of elements. The result is a sequence of the length $$$2n$$$.For example, if $$$p=[3, 1, 2]$$$ some possible results are: $$$[3, 1, 2, 3, 1, 2]$$$, $$$[3, 3, 1, 1, 2, 2]$$$, $$$[3, 1, 3, 1, 2, 2]$$$. The following sequences are not possible results of a merging: $$$[1, 3, 2, 1, 2, 3$$$], [$$$3, 1, 2, 3, 2, 1]$$$, $$$[3, 3, 1, 2, 2, 1]$$$.For example, if $$$p=[2, 1]$$$ the possible results are: $$$[2, 2, 1, 1]$$$, $$$[2, 1, 2, 1]$$$. The following sequences are not possible results of a merging: $$$[1, 1, 2, 2$$$], [$$$2, 1, 1, 2]$$$, $$$[1, 2, 2, 1]$$$.Your task is to restore the permutation $$$p$$$ by the given resulting sequence $$$a$$$. It is guaranteed that the answer exists and is unique.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; /** * * @author Aaryan */ public class Test { public static void main(String[] args) { Scanner input = new Scanner(System.in); int tc = input.nextInt(); while(tc-->0){ int n = input.nextInt(); int a [] = new int[2*n]; int k [] = new int[2*n]; for(int i =0; i<a.length; i++){ int v = input.nextInt(); a[v]++; if(a[v]==1){ k[i]=v; } } for(int i=0; i<a.length; i++){ if(k[i]!=0){ System.out.print(k[i]+" "); } } System.out.println(); } } }
Java
["5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1"]
1 second
["1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1"]
null
Java 8
standard input
[ "greedy" ]
aaf91874cf5aa0fa302ffed2ccecdc76
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 400$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of permutation. The second line of the test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the array $$$a$$$ represents the result of merging of some permutation $$$p$$$ with the same permutation $$$p$$$.
800
For each test case, print the answer: $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), representing the initial permutation. It is guaranteed that the answer exists and is unique.
standard output
PASSED
2b1cf78bcdd96f219f9f9135c25c0160
train_003.jsonl
1594996500
A permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ are permutations, and $$$[1, 1]$$$, $$$[0, 1]$$$, $$$[2, 2, 1, 4]$$$ are not.There was a permutation $$$p[1 \dots n]$$$. It was merged with itself. In other words, let's take two instances of $$$p$$$ and insert elements of the second $$$p$$$ into the first maintaining relative order of elements. The result is a sequence of the length $$$2n$$$.For example, if $$$p=[3, 1, 2]$$$ some possible results are: $$$[3, 1, 2, 3, 1, 2]$$$, $$$[3, 3, 1, 1, 2, 2]$$$, $$$[3, 1, 3, 1, 2, 2]$$$. The following sequences are not possible results of a merging: $$$[1, 3, 2, 1, 2, 3$$$], [$$$3, 1, 2, 3, 2, 1]$$$, $$$[3, 3, 1, 2, 2, 1]$$$.For example, if $$$p=[2, 1]$$$ the possible results are: $$$[2, 2, 1, 1]$$$, $$$[2, 1, 2, 1]$$$. The following sequences are not possible results of a merging: $$$[1, 1, 2, 2$$$], [$$$2, 1, 1, 2]$$$, $$$[1, 2, 2, 1]$$$.Your task is to restore the permutation $$$p$$$ by the given resulting sequence $$$a$$$. It is guaranteed that the answer exists and is unique.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; import java.util.ArrayList; public class Main { public static void main(String[] args) { Scanner sc = new Scanner (System.in); int t,n,m; t = sc.nextInt(); while(t-->0){ n = sc.nextInt(); ArrayList<Integer> s = new ArrayList<Integer>(); n*=2; while(n-->0) { m = sc.nextInt(); if(!s.contains(m)) s.add(m); } for(int x : s) System.out.print(x+" "); System.out.println(); } } }
Java
["5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1"]
1 second
["1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1"]
null
Java 8
standard input
[ "greedy" ]
aaf91874cf5aa0fa302ffed2ccecdc76
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 400$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of permutation. The second line of the test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the array $$$a$$$ represents the result of merging of some permutation $$$p$$$ with the same permutation $$$p$$$.
800
For each test case, print the answer: $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), representing the initial permutation. It is guaranteed that the answer exists and is unique.
standard output
PASSED
761811eb8abef31cc54694e3932c0150
train_003.jsonl
1594996500
A permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ are permutations, and $$$[1, 1]$$$, $$$[0, 1]$$$, $$$[2, 2, 1, 4]$$$ are not.There was a permutation $$$p[1 \dots n]$$$. It was merged with itself. In other words, let's take two instances of $$$p$$$ and insert elements of the second $$$p$$$ into the first maintaining relative order of elements. The result is a sequence of the length $$$2n$$$.For example, if $$$p=[3, 1, 2]$$$ some possible results are: $$$[3, 1, 2, 3, 1, 2]$$$, $$$[3, 3, 1, 1, 2, 2]$$$, $$$[3, 1, 3, 1, 2, 2]$$$. The following sequences are not possible results of a merging: $$$[1, 3, 2, 1, 2, 3$$$], [$$$3, 1, 2, 3, 2, 1]$$$, $$$[3, 3, 1, 2, 2, 1]$$$.For example, if $$$p=[2, 1]$$$ the possible results are: $$$[2, 2, 1, 1]$$$, $$$[2, 1, 2, 1]$$$. The following sequences are not possible results of a merging: $$$[1, 1, 2, 2$$$], [$$$2, 1, 1, 2]$$$, $$$[1, 2, 2, 1]$$$.Your task is to restore the permutation $$$p$$$ by the given resulting sequence $$$a$$$. It is guaranteed that the answer exists and is unique.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; import java.io.*; public class Test{ public static void main(String[] args){ Scanner scn =new Scanner(System.in); int t = scn.nextInt(); for(int i=0;i<t;i++){ int n = scn.nextInt(); int arr[] = new int[2*n]; for(int j=0; j<2*n; j++){ arr[j] = scn.nextInt(); } int ans[] = new int[n]; HashMap<Integer , Integer> map = new HashMap<>(); int p=0; for(int j=0; j<2*n;j++){ if(!map.containsKey(arr[j])){ map.put(arr[j] , 1); ans[p] = arr[j]; p++; } else{ map.put(arr[j],1); } } for(int j=0;j<n;j++){ System.out.println(ans[j]); } } } }
Java
["5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1"]
1 second
["1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1"]
null
Java 8
standard input
[ "greedy" ]
aaf91874cf5aa0fa302ffed2ccecdc76
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 400$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of permutation. The second line of the test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the array $$$a$$$ represents the result of merging of some permutation $$$p$$$ with the same permutation $$$p$$$.
800
For each test case, print the answer: $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), representing the initial permutation. It is guaranteed that the answer exists and is unique.
standard output
PASSED
95002b983694f837de4c44f9eb3b5010
train_003.jsonl
1594996500
A permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ are permutations, and $$$[1, 1]$$$, $$$[0, 1]$$$, $$$[2, 2, 1, 4]$$$ are not.There was a permutation $$$p[1 \dots n]$$$. It was merged with itself. In other words, let's take two instances of $$$p$$$ and insert elements of the second $$$p$$$ into the first maintaining relative order of elements. The result is a sequence of the length $$$2n$$$.For example, if $$$p=[3, 1, 2]$$$ some possible results are: $$$[3, 1, 2, 3, 1, 2]$$$, $$$[3, 3, 1, 1, 2, 2]$$$, $$$[3, 1, 3, 1, 2, 2]$$$. The following sequences are not possible results of a merging: $$$[1, 3, 2, 1, 2, 3$$$], [$$$3, 1, 2, 3, 2, 1]$$$, $$$[3, 3, 1, 2, 2, 1]$$$.For example, if $$$p=[2, 1]$$$ the possible results are: $$$[2, 2, 1, 1]$$$, $$$[2, 1, 2, 1]$$$. The following sequences are not possible results of a merging: $$$[1, 1, 2, 2$$$], [$$$2, 1, 1, 2]$$$, $$$[1, 2, 2, 1]$$$.Your task is to restore the permutation $$$p$$$ by the given resulting sequence $$$a$$$. It is guaranteed that the answer exists and is unique.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; public class B656 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); Set<Integer> h= new LinkedHashSet<Integer>(); for(int i=0;i<2*n;i++) { h.add(sc.nextInt()); } Iterator<Integer> i =h.iterator(); while(i.hasNext()) { System.out.print(i.next()+" "); } System.out.println(); } } }
Java
["5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1"]
1 second
["1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1"]
null
Java 8
standard input
[ "greedy" ]
aaf91874cf5aa0fa302ffed2ccecdc76
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 400$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of permutation. The second line of the test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the array $$$a$$$ represents the result of merging of some permutation $$$p$$$ with the same permutation $$$p$$$.
800
For each test case, print the answer: $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), representing the initial permutation. It is guaranteed that the answer exists and is unique.
standard output
PASSED
46f04211dca2790f88ef77e59f6c08ea
train_003.jsonl
1594996500
A permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ are permutations, and $$$[1, 1]$$$, $$$[0, 1]$$$, $$$[2, 2, 1, 4]$$$ are not.There was a permutation $$$p[1 \dots n]$$$. It was merged with itself. In other words, let's take two instances of $$$p$$$ and insert elements of the second $$$p$$$ into the first maintaining relative order of elements. The result is a sequence of the length $$$2n$$$.For example, if $$$p=[3, 1, 2]$$$ some possible results are: $$$[3, 1, 2, 3, 1, 2]$$$, $$$[3, 3, 1, 1, 2, 2]$$$, $$$[3, 1, 3, 1, 2, 2]$$$. The following sequences are not possible results of a merging: $$$[1, 3, 2, 1, 2, 3$$$], [$$$3, 1, 2, 3, 2, 1]$$$, $$$[3, 3, 1, 2, 2, 1]$$$.For example, if $$$p=[2, 1]$$$ the possible results are: $$$[2, 2, 1, 1]$$$, $$$[2, 1, 2, 1]$$$. The following sequences are not possible results of a merging: $$$[1, 1, 2, 2$$$], [$$$2, 1, 1, 2]$$$, $$$[1, 2, 2, 1]$$$.Your task is to restore the permutation $$$p$$$ by the given resulting sequence $$$a$$$. It is guaranteed that the answer exists and is unique.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); while (t-- > 0) { int n = in.nextInt(); Set<Integer> set = new LinkedHashSet<>(); for (int i=0; i<2*n; i++) { set.add(in.nextInt()); } StringBuilder sb = new StringBuilder(); for (int val : set) { sb.append(val).append(" "); } System.out.println(sb); } } }
Java
["5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1"]
1 second
["1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1"]
null
Java 8
standard input
[ "greedy" ]
aaf91874cf5aa0fa302ffed2ccecdc76
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 400$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of permutation. The second line of the test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the array $$$a$$$ represents the result of merging of some permutation $$$p$$$ with the same permutation $$$p$$$.
800
For each test case, print the answer: $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), representing the initial permutation. It is guaranteed that the answer exists and is unique.
standard output
PASSED
3e2fda38e721b48679bb0e94b4f8a82d
train_003.jsonl
1594996500
A permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ are permutations, and $$$[1, 1]$$$, $$$[0, 1]$$$, $$$[2, 2, 1, 4]$$$ are not.There was a permutation $$$p[1 \dots n]$$$. It was merged with itself. In other words, let's take two instances of $$$p$$$ and insert elements of the second $$$p$$$ into the first maintaining relative order of elements. The result is a sequence of the length $$$2n$$$.For example, if $$$p=[3, 1, 2]$$$ some possible results are: $$$[3, 1, 2, 3, 1, 2]$$$, $$$[3, 3, 1, 1, 2, 2]$$$, $$$[3, 1, 3, 1, 2, 2]$$$. The following sequences are not possible results of a merging: $$$[1, 3, 2, 1, 2, 3$$$], [$$$3, 1, 2, 3, 2, 1]$$$, $$$[3, 3, 1, 2, 2, 1]$$$.For example, if $$$p=[2, 1]$$$ the possible results are: $$$[2, 2, 1, 1]$$$, $$$[2, 1, 2, 1]$$$. The following sequences are not possible results of a merging: $$$[1, 1, 2, 2$$$], [$$$2, 1, 1, 2]$$$, $$$[1, 2, 2, 1]$$$.Your task is to restore the permutation $$$p$$$ by the given resulting sequence $$$a$$$. It is guaranteed that the answer exists and is unique.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.HashSet; import java.util.Scanner; public class ProblemB { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); HashSet<Integer> set=new HashSet<>(); int[] res=new int[n]; for(int i=0;i<2*n;i++){ int num=sc.nextInt(); if(!set.contains(num)){ System.out.print(num+" "); set.add(num); } } System.out.println(); } } }
Java
["5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1"]
1 second
["1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1"]
null
Java 8
standard input
[ "greedy" ]
aaf91874cf5aa0fa302ffed2ccecdc76
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 400$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of permutation. The second line of the test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the array $$$a$$$ represents the result of merging of some permutation $$$p$$$ with the same permutation $$$p$$$.
800
For each test case, print the answer: $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), representing the initial permutation. It is guaranteed that the answer exists and is unique.
standard output
PASSED
88eca8938b57510273aa6f1baba5ded7
train_003.jsonl
1594996500
A permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ are permutations, and $$$[1, 1]$$$, $$$[0, 1]$$$, $$$[2, 2, 1, 4]$$$ are not.There was a permutation $$$p[1 \dots n]$$$. It was merged with itself. In other words, let's take two instances of $$$p$$$ and insert elements of the second $$$p$$$ into the first maintaining relative order of elements. The result is a sequence of the length $$$2n$$$.For example, if $$$p=[3, 1, 2]$$$ some possible results are: $$$[3, 1, 2, 3, 1, 2]$$$, $$$[3, 3, 1, 1, 2, 2]$$$, $$$[3, 1, 3, 1, 2, 2]$$$. The following sequences are not possible results of a merging: $$$[1, 3, 2, 1, 2, 3$$$], [$$$3, 1, 2, 3, 2, 1]$$$, $$$[3, 3, 1, 2, 2, 1]$$$.For example, if $$$p=[2, 1]$$$ the possible results are: $$$[2, 2, 1, 1]$$$, $$$[2, 1, 2, 1]$$$. The following sequences are not possible results of a merging: $$$[1, 1, 2, 2$$$], [$$$2, 1, 1, 2]$$$, $$$[1, 2, 2, 1]$$$.Your task is to restore the permutation $$$p$$$ by the given resulting sequence $$$a$$$. It is guaranteed that the answer exists and is unique.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; public class Main { public static void main(String args[]) { Scanner s = new Scanner(System.in); int t = s.nextInt(); while(t-- != 0){ int n = s.nextInt(); HashSet<Integer> set = new HashSet<>(); for(int i = 0; i < 2 * n; i++){ int k = s.nextInt(); if(!set.contains(k)){ System.out.print(k + " "); } set.add(k); } System.out.println(); } } }
Java
["5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1"]
1 second
["1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1"]
null
Java 8
standard input
[ "greedy" ]
aaf91874cf5aa0fa302ffed2ccecdc76
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 400$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of permutation. The second line of the test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the array $$$a$$$ represents the result of merging of some permutation $$$p$$$ with the same permutation $$$p$$$.
800
For each test case, print the answer: $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), representing the initial permutation. It is guaranteed that the answer exists and is unique.
standard output
PASSED
d95ae16f797753c31aeaf92c9aa03cbb
train_003.jsonl
1594996500
A permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ are permutations, and $$$[1, 1]$$$, $$$[0, 1]$$$, $$$[2, 2, 1, 4]$$$ are not.There was a permutation $$$p[1 \dots n]$$$. It was merged with itself. In other words, let's take two instances of $$$p$$$ and insert elements of the second $$$p$$$ into the first maintaining relative order of elements. The result is a sequence of the length $$$2n$$$.For example, if $$$p=[3, 1, 2]$$$ some possible results are: $$$[3, 1, 2, 3, 1, 2]$$$, $$$[3, 3, 1, 1, 2, 2]$$$, $$$[3, 1, 3, 1, 2, 2]$$$. The following sequences are not possible results of a merging: $$$[1, 3, 2, 1, 2, 3$$$], [$$$3, 1, 2, 3, 2, 1]$$$, $$$[3, 3, 1, 2, 2, 1]$$$.For example, if $$$p=[2, 1]$$$ the possible results are: $$$[2, 2, 1, 1]$$$, $$$[2, 1, 2, 1]$$$. The following sequences are not possible results of a merging: $$$[1, 1, 2, 2$$$], [$$$2, 1, 1, 2]$$$, $$$[1, 2, 2, 1]$$$.Your task is to restore the permutation $$$p$$$ by the given resulting sequence $$$a$$$. It is guaranteed that the answer exists and is unique.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.io.*; import java.util.*; public class Mohammad { public static void Mohammad_AboHasan() throws IOException { FastReader fr = new FastReader(); int t = fr.nextInt(); while(t-->0){ int n = fr.nextInt(); Set<Integer> set = new HashSet<>(); ArrayList<Integer> l = new ArrayList<>(); for (int i = 0; i < n*2; i++) { int r = fr.nextInt(); if(set.contains(r)) l.add(r); set.add(r); } for (int i = 0; i < l.size(); i++) { System.out.print(l.get(i) + " "); } System.out.println(""); } } //-----------------------------------|الحمدلله|-----------------------------------// public static void main(String[] args) throws IOException{ Mohammad_AboHasan(); } //-------------------------------------FAST I/O-------------------------------------// static class FastReader{ BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() throws IOException{ while (st == null || !st.hasMoreElements()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } int nextInt() throws IOException{ return Integer.parseInt(next()); } long nextLong() throws IOException{ return Long.parseLong(next()); } double nextDouble() throws IOException{ return Double.parseDouble(next()); } String nextLine() throws IOException{ String s = br.readLine(); return s; } } }
Java
["5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1"]
1 second
["1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1"]
null
Java 8
standard input
[ "greedy" ]
aaf91874cf5aa0fa302ffed2ccecdc76
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 400$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of permutation. The second line of the test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the array $$$a$$$ represents the result of merging of some permutation $$$p$$$ with the same permutation $$$p$$$.
800
For each test case, print the answer: $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), representing the initial permutation. It is guaranteed that the answer exists and is unique.
standard output
PASSED
aa0c7c0f822bb0d22bc3c28bdb21f6d2
train_003.jsonl
1594996500
A permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ are permutations, and $$$[1, 1]$$$, $$$[0, 1]$$$, $$$[2, 2, 1, 4]$$$ are not.There was a permutation $$$p[1 \dots n]$$$. It was merged with itself. In other words, let's take two instances of $$$p$$$ and insert elements of the second $$$p$$$ into the first maintaining relative order of elements. The result is a sequence of the length $$$2n$$$.For example, if $$$p=[3, 1, 2]$$$ some possible results are: $$$[3, 1, 2, 3, 1, 2]$$$, $$$[3, 3, 1, 1, 2, 2]$$$, $$$[3, 1, 3, 1, 2, 2]$$$. The following sequences are not possible results of a merging: $$$[1, 3, 2, 1, 2, 3$$$], [$$$3, 1, 2, 3, 2, 1]$$$, $$$[3, 3, 1, 2, 2, 1]$$$.For example, if $$$p=[2, 1]$$$ the possible results are: $$$[2, 2, 1, 1]$$$, $$$[2, 1, 2, 1]$$$. The following sequences are not possible results of a merging: $$$[1, 1, 2, 2$$$], [$$$2, 1, 1, 2]$$$, $$$[1, 2, 2, 1]$$$.Your task is to restore the permutation $$$p$$$ by the given resulting sequence $$$a$$$. It is guaranteed that the answer exists and is unique.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; public class RestorePermutation { public static BufferedReader br; public static void main(String[] args) { br = new BufferedReader(new InputStreamReader(System.in)); int test = Integer.parseInt(getInput().trim()); int n, num; String str[]; List<Integer> list; for(int t = 0; t < test; t++) { n = Integer.parseInt(getInput().trim()); str = getInput().trim().split("\\s+"); list = new ArrayList<>(); for(int i = 0; i < 2*n; i++) { num = Integer.parseInt(str[i]); if(list.isEmpty() || !list.contains(num)) list.add(num); } for(Integer ele : list) { System.out.print(ele+" "); } System.out.println(); } } public static String getInput() { String input = ""; try { input = br.readLine(); } catch(Exception e) {} return input; } }
Java
["5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1"]
1 second
["1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1"]
null
Java 8
standard input
[ "greedy" ]
aaf91874cf5aa0fa302ffed2ccecdc76
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 400$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of permutation. The second line of the test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the array $$$a$$$ represents the result of merging of some permutation $$$p$$$ with the same permutation $$$p$$$.
800
For each test case, print the answer: $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), representing the initial permutation. It is guaranteed that the answer exists and is unique.
standard output
PASSED
91ee969a059ec20c4baf3e67ca22ff08
train_003.jsonl
1594996500
A permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ are permutations, and $$$[1, 1]$$$, $$$[0, 1]$$$, $$$[2, 2, 1, 4]$$$ are not.There was a permutation $$$p[1 \dots n]$$$. It was merged with itself. In other words, let's take two instances of $$$p$$$ and insert elements of the second $$$p$$$ into the first maintaining relative order of elements. The result is a sequence of the length $$$2n$$$.For example, if $$$p=[3, 1, 2]$$$ some possible results are: $$$[3, 1, 2, 3, 1, 2]$$$, $$$[3, 3, 1, 1, 2, 2]$$$, $$$[3, 1, 3, 1, 2, 2]$$$. The following sequences are not possible results of a merging: $$$[1, 3, 2, 1, 2, 3$$$], [$$$3, 1, 2, 3, 2, 1]$$$, $$$[3, 3, 1, 2, 2, 1]$$$.For example, if $$$p=[2, 1]$$$ the possible results are: $$$[2, 2, 1, 1]$$$, $$$[2, 1, 2, 1]$$$. The following sequences are not possible results of a merging: $$$[1, 1, 2, 2$$$], [$$$2, 1, 1, 2]$$$, $$$[1, 2, 2, 1]$$$.Your task is to restore the permutation $$$p$$$ by the given resulting sequence $$$a$$$. It is guaranteed that the answer exists and is unique.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public final class RestoreThePermutationByMerger { private static final FastReader fr = new FastReader(); public static void main(String[] args) { int t = fr.nextInt(); while (t-- > 0) { final int n = fr.nextInt(); final int[] perm = new int[2 * n]; for (int i = 0; i < perm.length; i++) { perm[i] = fr.nextInt(); } final boolean[] seen = new boolean[n + 1]; final StringBuilder sb = new StringBuilder(3 * n); for (int i = 0; i < perm.length; i++) { final int a = perm[i]; if (seen[a]) continue; sb.append(a).append(' '); seen[a] = true; } System.out.println(sb); } } private static final class FastReader { private final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); private StringTokenizer st; public String nextLine() { try { return br.readLine(); } catch (IOException ex) { throw new RuntimeException(ex); } } public String next() { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(nextLine()); } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
Java
["5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1"]
1 second
["1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1"]
null
Java 8
standard input
[ "greedy" ]
aaf91874cf5aa0fa302ffed2ccecdc76
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 400$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of permutation. The second line of the test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the array $$$a$$$ represents the result of merging of some permutation $$$p$$$ with the same permutation $$$p$$$.
800
For each test case, print the answer: $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), representing the initial permutation. It is guaranteed that the answer exists and is unique.
standard output
PASSED
87484bc5426d6ac83953cf38115bb2ea
train_003.jsonl
1594996500
A permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ are permutations, and $$$[1, 1]$$$, $$$[0, 1]$$$, $$$[2, 2, 1, 4]$$$ are not.There was a permutation $$$p[1 \dots n]$$$. It was merged with itself. In other words, let's take two instances of $$$p$$$ and insert elements of the second $$$p$$$ into the first maintaining relative order of elements. The result is a sequence of the length $$$2n$$$.For example, if $$$p=[3, 1, 2]$$$ some possible results are: $$$[3, 1, 2, 3, 1, 2]$$$, $$$[3, 3, 1, 1, 2, 2]$$$, $$$[3, 1, 3, 1, 2, 2]$$$. The following sequences are not possible results of a merging: $$$[1, 3, 2, 1, 2, 3$$$], [$$$3, 1, 2, 3, 2, 1]$$$, $$$[3, 3, 1, 2, 2, 1]$$$.For example, if $$$p=[2, 1]$$$ the possible results are: $$$[2, 2, 1, 1]$$$, $$$[2, 1, 2, 1]$$$. The following sequences are not possible results of a merging: $$$[1, 1, 2, 2$$$], [$$$2, 1, 1, 2]$$$, $$$[1, 2, 2, 1]$$$.Your task is to restore the permutation $$$p$$$ by the given resulting sequence $$$a$$$. It is guaranteed that the answer exists and is unique.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.io.*; import java.util.*; public class B { private final FastReader fr = new FastReader(); public static void main(String[] args) { new B().solve(); } private void solve() { int t = fr.nextInt(); while (t-- > 0) { int n = fr.nextInt(); int[] input = new int[2 * n]; for (int i = 0; i < input.length; i++) { input[i] = fr.nextInt(); } Perm p = new Perm(input); p.solve(); } } class Perm { private final Map<Integer, int[]> map; private final Map<Integer, Integer> rMap; public Perm(int[] selfMerged) { map = new HashMap<>(selfMerged.length / 2, 1.0f); rMap = new HashMap<>(selfMerged.length, 1.0f); for (int i = 0; i < selfMerged.length; i++) { rMap.put(i, selfMerged[i]); int[] prev = map.get(selfMerged[i]); if (prev == null) { map.put(selfMerged[i], new int[]{i}); } else { map.replace(selfMerged[i], new int[]{prev[0], i}); } } } public void solve() { perms1 = new ArrayDeque<>(map.size()); perms2 = new ArrayDeque<>(map.size()); permutes(1); } private Deque<Integer> perms1; private Deque<Integer> perms2; private boolean found = false; private void permutes(int k) { if (found) return; if (k == map.size() + 1) { PermInstance i = new PermInstance(perms1.stream().mapToInt((a) -> a).toArray(), perms2.stream().mapToInt((a) -> a).toArray()); int[] permutation = i.permutation(); if (permutation != null) { for (int i1 = 0; i1 < permutation.length; i1++) { System.out.print(permutation[i1] + " "); } System.out.println(); found = true; return; } } else { int[] e = map.get(k); perms1.push(e[0]); perms2.push(e[1]); if (found) return; permutes(k + 1); perms1.pop(); perms2.pop(); perms1.push(e[1]); perms2.push(e[0]); if (found) return; permutes(k + 1); perms1.pop(); perms2.pop(); } } class PermInstance { private final int[] f, s; public PermInstance(int[] f, int[] s) { this.f = f; this.s = s; Arrays.sort(f); Arrays.sort(s); } public int[] permutation() { int[] fv = new int[f.length]; for (int i = 0; i < f.length; i++) { fv[i] = rMap.get(f[i]); } int[] sv = new int[s.length]; for (int i = 0; i < s.length; i++) { sv[i] = rMap.get(s[i]); } if (Arrays.equals(fv, sv)) return fv; else return null; } } } class FastReader { private final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); private StringTokenizer st; public String nextLine() { try { return br.readLine(); } catch (IOException ex) { throw new RuntimeException(ex); } } public String next() { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(nextLine()); } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
Java
["5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1"]
1 second
["1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1"]
null
Java 8
standard input
[ "greedy" ]
aaf91874cf5aa0fa302ffed2ccecdc76
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 400$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of permutation. The second line of the test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the array $$$a$$$ represents the result of merging of some permutation $$$p$$$ with the same permutation $$$p$$$.
800
For each test case, print the answer: $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), representing the initial permutation. It is guaranteed that the answer exists and is unique.
standard output
PASSED
e0941c1f7d9b3058fb708b619b577832
train_003.jsonl
1594996500
A permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ are permutations, and $$$[1, 1]$$$, $$$[0, 1]$$$, $$$[2, 2, 1, 4]$$$ are not.There was a permutation $$$p[1 \dots n]$$$. It was merged with itself. In other words, let's take two instances of $$$p$$$ and insert elements of the second $$$p$$$ into the first maintaining relative order of elements. The result is a sequence of the length $$$2n$$$.For example, if $$$p=[3, 1, 2]$$$ some possible results are: $$$[3, 1, 2, 3, 1, 2]$$$, $$$[3, 3, 1, 1, 2, 2]$$$, $$$[3, 1, 3, 1, 2, 2]$$$. The following sequences are not possible results of a merging: $$$[1, 3, 2, 1, 2, 3$$$], [$$$3, 1, 2, 3, 2, 1]$$$, $$$[3, 3, 1, 2, 2, 1]$$$.For example, if $$$p=[2, 1]$$$ the possible results are: $$$[2, 2, 1, 1]$$$, $$$[2, 1, 2, 1]$$$. The following sequences are not possible results of a merging: $$$[1, 1, 2, 2$$$], [$$$2, 1, 1, 2]$$$, $$$[1, 2, 2, 1]$$$.Your task is to restore the permutation $$$p$$$ by the given resulting sequence $$$a$$$. It is guaranteed that the answer exists and is unique.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.ArrayList; import java.util.Scanner; import static java.util.Collections.sort; public class Codeforces { public static void main(String[] args) { try { Scanner sc = new Scanner(System.in); ArrayList<Integer> a = new ArrayList<>(); int t = sc.nextInt(); for (int j = 0; j < t; j++) { int n=sc.nextInt(); int arr[]=new int[2*n]; for(int i=0;i<2*n;i++){ arr[i]=sc.nextInt(); } for(int i=0;i<arr.length;i++){ if(!a.contains(arr[i])){ System.out.print(arr[i]+" "); } a.add(arr[i]); } a.clear(); System.out.println(); } }catch (Exception e){ return; } } }
Java
["5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1"]
1 second
["1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1"]
null
Java 8
standard input
[ "greedy" ]
aaf91874cf5aa0fa302ffed2ccecdc76
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 400$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of permutation. The second line of the test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the array $$$a$$$ represents the result of merging of some permutation $$$p$$$ with the same permutation $$$p$$$.
800
For each test case, print the answer: $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), representing the initial permutation. It is guaranteed that the answer exists and is unique.
standard output
PASSED
8e8236cf5382ef5001b39f3b946be65f
train_003.jsonl
1594996500
A permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ are permutations, and $$$[1, 1]$$$, $$$[0, 1]$$$, $$$[2, 2, 1, 4]$$$ are not.There was a permutation $$$p[1 \dots n]$$$. It was merged with itself. In other words, let's take two instances of $$$p$$$ and insert elements of the second $$$p$$$ into the first maintaining relative order of elements. The result is a sequence of the length $$$2n$$$.For example, if $$$p=[3, 1, 2]$$$ some possible results are: $$$[3, 1, 2, 3, 1, 2]$$$, $$$[3, 3, 1, 1, 2, 2]$$$, $$$[3, 1, 3, 1, 2, 2]$$$. The following sequences are not possible results of a merging: $$$[1, 3, 2, 1, 2, 3$$$], [$$$3, 1, 2, 3, 2, 1]$$$, $$$[3, 3, 1, 2, 2, 1]$$$.For example, if $$$p=[2, 1]$$$ the possible results are: $$$[2, 2, 1, 1]$$$, $$$[2, 1, 2, 1]$$$. The following sequences are not possible results of a merging: $$$[1, 1, 2, 2$$$], [$$$2, 1, 1, 2]$$$, $$$[1, 2, 2, 1]$$$.Your task is to restore the permutation $$$p$$$ by the given resulting sequence $$$a$$$. It is guaranteed that the answer exists and is unique.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; import java.lang.*; public class RP{ public static void main(String[] agrs) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); ArrayList<Integer> a=new ArrayList<Integer>(); for(int j=0;j<t;j++) { int n=sc.nextInt(); int[] a1= new int[2*n]; int c=0; HashMap<Integer,Integer> map=new HashMap<Integer,Integer>(); for(int i=0;i<2*n;i++) { a1[i]=sc.nextInt(); } for(int k=0;k<2*n;k++) { if(!(map.containsKey(a1[k]))) { System.out.print(a1[k]+" "); c++; map.put(a1[k],1); } if(c==n) break; } System.out.print("\n"); map.clear(); } } }
Java
["5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1"]
1 second
["1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1"]
null
Java 8
standard input
[ "greedy" ]
aaf91874cf5aa0fa302ffed2ccecdc76
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 400$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of permutation. The second line of the test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the array $$$a$$$ represents the result of merging of some permutation $$$p$$$ with the same permutation $$$p$$$.
800
For each test case, print the answer: $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), representing the initial permutation. It is guaranteed that the answer exists and is unique.
standard output
PASSED
0b5755758c2e4f218f92017b4a73bc11
train_003.jsonl
1594996500
A permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ are permutations, and $$$[1, 1]$$$, $$$[0, 1]$$$, $$$[2, 2, 1, 4]$$$ are not.There was a permutation $$$p[1 \dots n]$$$. It was merged with itself. In other words, let's take two instances of $$$p$$$ and insert elements of the second $$$p$$$ into the first maintaining relative order of elements. The result is a sequence of the length $$$2n$$$.For example, if $$$p=[3, 1, 2]$$$ some possible results are: $$$[3, 1, 2, 3, 1, 2]$$$, $$$[3, 3, 1, 1, 2, 2]$$$, $$$[3, 1, 3, 1, 2, 2]$$$. The following sequences are not possible results of a merging: $$$[1, 3, 2, 1, 2, 3$$$], [$$$3, 1, 2, 3, 2, 1]$$$, $$$[3, 3, 1, 2, 2, 1]$$$.For example, if $$$p=[2, 1]$$$ the possible results are: $$$[2, 2, 1, 1]$$$, $$$[2, 1, 2, 1]$$$. The following sequences are not possible results of a merging: $$$[1, 1, 2, 2$$$], [$$$2, 1, 1, 2]$$$, $$$[1, 2, 2, 1]$$$.Your task is to restore the permutation $$$p$$$ by the given resulting sequence $$$a$$$. It is guaranteed that the answer exists and is unique.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.io.*; import java.util.*; public class test { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String n = sc.nextLine(); for (int i = 0; i<Integer.parseInt(n); i++) { String j = sc.nextLine(); String[] data = sc.nextLine().split(" "); solution(data, Integer.parseInt(j)); } } public static void solution(String[] data, int i){ List<String> list = new ArrayList<>(); String result = ""; for(String s : data){ if(list.size() == i) break; if(!list.contains(s)){ if(result!="") result = result+" "+s; else result = s; list.add(s); } } System.out.println(result); } }
Java
["5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1"]
1 second
["1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1"]
null
Java 8
standard input
[ "greedy" ]
aaf91874cf5aa0fa302ffed2ccecdc76
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 400$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of permutation. The second line of the test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the array $$$a$$$ represents the result of merging of some permutation $$$p$$$ with the same permutation $$$p$$$.
800
For each test case, print the answer: $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), representing the initial permutation. It is guaranteed that the answer exists and is unique.
standard output
PASSED
326f44b95570462db0ae020f072850ff
train_003.jsonl
1594996500
A permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ are permutations, and $$$[1, 1]$$$, $$$[0, 1]$$$, $$$[2, 2, 1, 4]$$$ are not.There was a permutation $$$p[1 \dots n]$$$. It was merged with itself. In other words, let's take two instances of $$$p$$$ and insert elements of the second $$$p$$$ into the first maintaining relative order of elements. The result is a sequence of the length $$$2n$$$.For example, if $$$p=[3, 1, 2]$$$ some possible results are: $$$[3, 1, 2, 3, 1, 2]$$$, $$$[3, 3, 1, 1, 2, 2]$$$, $$$[3, 1, 3, 1, 2, 2]$$$. The following sequences are not possible results of a merging: $$$[1, 3, 2, 1, 2, 3$$$], [$$$3, 1, 2, 3, 2, 1]$$$, $$$[3, 3, 1, 2, 2, 1]$$$.For example, if $$$p=[2, 1]$$$ the possible results are: $$$[2, 2, 1, 1]$$$, $$$[2, 1, 2, 1]$$$. The following sequences are not possible results of a merging: $$$[1, 1, 2, 2$$$], [$$$2, 1, 1, 2]$$$, $$$[1, 2, 2, 1]$$$.Your task is to restore the permutation $$$p$$$ by the given resulting sequence $$$a$$$. It is guaranteed that the answer exists and is unique.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; public class Solution { public static void fun() { Scanner s=new Scanner(System.in); } public static void main(String[] args) { Scanner s=new Scanner(System.in); int t=s.nextInt(); for(int i=0;i<t;i++) { int n=s.nextInt(); boolean[] temp=new boolean[n+1]; for(int j=1;j<=2*n;j++) { int x=s.nextInt(); if(!temp[x]) System.out.print(x+" "); temp[x]=true; } System.out.println(); } } }
Java
["5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1"]
1 second
["1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1"]
null
Java 8
standard input
[ "greedy" ]
aaf91874cf5aa0fa302ffed2ccecdc76
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 400$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of permutation. The second line of the test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the array $$$a$$$ represents the result of merging of some permutation $$$p$$$ with the same permutation $$$p$$$.
800
For each test case, print the answer: $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), representing the initial permutation. It is guaranteed that the answer exists and is unique.
standard output
PASSED
e6f4c434d9d8b46912254690b2aa5574
train_003.jsonl
1594996500
A permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ are permutations, and $$$[1, 1]$$$, $$$[0, 1]$$$, $$$[2, 2, 1, 4]$$$ are not.There was a permutation $$$p[1 \dots n]$$$. It was merged with itself. In other words, let's take two instances of $$$p$$$ and insert elements of the second $$$p$$$ into the first maintaining relative order of elements. The result is a sequence of the length $$$2n$$$.For example, if $$$p=[3, 1, 2]$$$ some possible results are: $$$[3, 1, 2, 3, 1, 2]$$$, $$$[3, 3, 1, 1, 2, 2]$$$, $$$[3, 1, 3, 1, 2, 2]$$$. The following sequences are not possible results of a merging: $$$[1, 3, 2, 1, 2, 3$$$], [$$$3, 1, 2, 3, 2, 1]$$$, $$$[3, 3, 1, 2, 2, 1]$$$.For example, if $$$p=[2, 1]$$$ the possible results are: $$$[2, 2, 1, 1]$$$, $$$[2, 1, 2, 1]$$$. The following sequences are not possible results of a merging: $$$[1, 1, 2, 2$$$], [$$$2, 1, 1, 2]$$$, $$$[1, 2, 2, 1]$$$.Your task is to restore the permutation $$$p$$$ by the given resulting sequence $$$a$$$. It is guaranteed that the answer exists and is unique.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); int tt=in.nextInt(); for(int t=0;t<tt;t++){ int n=in.nextInt(); int[] merge=new int[n]; ArrayList<Integer> l=new ArrayList<>(); for(int i=0;i<2*n;i++){ int temp=in.nextInt(); if(merge[temp-1]==0){ l.add(temp); merge[temp-1]++; } } for(int j=0;j<l.size();j++){ System.out.print(l.get(j)+" "); } System.out.println(); } } }
Java
["5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1"]
1 second
["1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1"]
null
Java 8
standard input
[ "greedy" ]
aaf91874cf5aa0fa302ffed2ccecdc76
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 400$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of permutation. The second line of the test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the array $$$a$$$ represents the result of merging of some permutation $$$p$$$ with the same permutation $$$p$$$.
800
For each test case, print the answer: $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), representing the initial permutation. It is guaranteed that the answer exists and is unique.
standard output
PASSED
6e91c91d69afba944b70b6f17e311efc
train_003.jsonl
1594996500
A permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ are permutations, and $$$[1, 1]$$$, $$$[0, 1]$$$, $$$[2, 2, 1, 4]$$$ are not.There was a permutation $$$p[1 \dots n]$$$. It was merged with itself. In other words, let's take two instances of $$$p$$$ and insert elements of the second $$$p$$$ into the first maintaining relative order of elements. The result is a sequence of the length $$$2n$$$.For example, if $$$p=[3, 1, 2]$$$ some possible results are: $$$[3, 1, 2, 3, 1, 2]$$$, $$$[3, 3, 1, 1, 2, 2]$$$, $$$[3, 1, 3, 1, 2, 2]$$$. The following sequences are not possible results of a merging: $$$[1, 3, 2, 1, 2, 3$$$], [$$$3, 1, 2, 3, 2, 1]$$$, $$$[3, 3, 1, 2, 2, 1]$$$.For example, if $$$p=[2, 1]$$$ the possible results are: $$$[2, 2, 1, 1]$$$, $$$[2, 1, 2, 1]$$$. The following sequences are not possible results of a merging: $$$[1, 1, 2, 2$$$], [$$$2, 1, 1, 2]$$$, $$$[1, 2, 2, 1]$$$.Your task is to restore the permutation $$$p$$$ by the given resulting sequence $$$a$$$. It is guaranteed that the answer exists and is unique.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.Scanner; import java.util.Set; import java.util.HashSet; /** * * @author lkoed */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int cases = sc.nextInt(); for(int i=0; i<cases;i++){ Set<Integer> s = new HashSet<>(); int len= sc.nextInt(); int[] ans = new int[len]; int j= 0; int p=0; while(j<2*len){ int in= sc.nextInt(); if(!s.contains(in)){ s.add(in); ans[p] = in; p++; } j++; } for(int c: ans){ System.out.printf(c+" "); } System.out.println(""); } } }
Java
["5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1"]
1 second
["1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1"]
null
Java 8
standard input
[ "greedy" ]
aaf91874cf5aa0fa302ffed2ccecdc76
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 400$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of permutation. The second line of the test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the array $$$a$$$ represents the result of merging of some permutation $$$p$$$ with the same permutation $$$p$$$.
800
For each test case, print the answer: $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), representing the initial permutation. It is guaranteed that the answer exists and is unique.
standard output
PASSED
7189b8f55da81e45f60a9f2d2cbd4bc1
train_003.jsonl
1594996500
A permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ are permutations, and $$$[1, 1]$$$, $$$[0, 1]$$$, $$$[2, 2, 1, 4]$$$ are not.There was a permutation $$$p[1 \dots n]$$$. It was merged with itself. In other words, let's take two instances of $$$p$$$ and insert elements of the second $$$p$$$ into the first maintaining relative order of elements. The result is a sequence of the length $$$2n$$$.For example, if $$$p=[3, 1, 2]$$$ some possible results are: $$$[3, 1, 2, 3, 1, 2]$$$, $$$[3, 3, 1, 1, 2, 2]$$$, $$$[3, 1, 3, 1, 2, 2]$$$. The following sequences are not possible results of a merging: $$$[1, 3, 2, 1, 2, 3$$$], [$$$3, 1, 2, 3, 2, 1]$$$, $$$[3, 3, 1, 2, 2, 1]$$$.For example, if $$$p=[2, 1]$$$ the possible results are: $$$[2, 2, 1, 1]$$$, $$$[2, 1, 2, 1]$$$. The following sequences are not possible results of a merging: $$$[1, 1, 2, 2$$$], [$$$2, 1, 1, 2]$$$, $$$[1, 2, 2, 1]$$$.Your task is to restore the permutation $$$p$$$ by the given resulting sequence $$$a$$$. It is guaranteed that the answer exists and is unique.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.nio.Buffer; import java.util.*; public class ssss { public static void main(String[] args){ try { PrintWriter out=new PrintWriter(System.out,true); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int t=Integer.parseInt(br.readLine()); for(int i=0;i<t;i++){ int n=Integer.parseInt(br.readLine()); String[] ss=br.readLine().split(" "); int[] arr=new int[2*n]; for(int j=0;j<2*n;j++){ arr[j]=Integer.parseInt(ss[j]); } HashSet<Integer> set=new HashSet<>(); StringBuilder str=new StringBuilder(""); for(int j=0;j<2*n;j++){ if(!set.contains(arr[j])){ str.append(arr[j]+" "); set.add(arr[j]); } } out.println(str); } out.close(); } catch (Exception e) { System.out.println("kkkk "+ e.getMessage()); } } static boolean isPal(String s){ StringBuilder str=new StringBuilder(s); str=str.reverse(); String ss=String.valueOf(str); if (ss.equals(s)) { return true; } return false; } static int mod(int a,int b){ if (a>b){ return a-b; } return b-a; } static void shuffle(int[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); int temp = a[i]; a[i] = a[r]; a[r] = temp; } } static int lcm(int a,int b){ long c=a*b; return (int)(c/hcf(a,b)); } static int hcf(int a,int b){ if(a==0){ return b; } if(b==0){ return a; } if(a>b) return hcf(a%b,b); return hcf(a,b%a); } static void dfs(ArrayList<HashSet<Integer>> list,boolean[] vis,int i){ vis[i]=true; Iterator<Integer> it=list.get(i).iterator(); while(it.hasNext()){ int u=it.next(); if(!vis[u]){ dfs(list,vis,u); } } } static int modInverse(int x,int m){ return power(x,m-2,m); } static int power(int x, int y, int m) { if (y == 0) return 1; long p = power(x, y / 2, m) % m; p = (p * p) % m; return (int)((y%2==0)? p : (x*p)%m); } static class pair{ int a,b; public pair(int a,int b){ this.a=a; this.b=b; } } }
Java
["5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1"]
1 second
["1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1"]
null
Java 8
standard input
[ "greedy" ]
aaf91874cf5aa0fa302ffed2ccecdc76
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 400$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of permutation. The second line of the test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the array $$$a$$$ represents the result of merging of some permutation $$$p$$$ with the same permutation $$$p$$$.
800
For each test case, print the answer: $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), representing the initial permutation. It is guaranteed that the answer exists and is unique.
standard output
PASSED
19f6edd0478e5d1753845b2a96c62d1a
train_003.jsonl
1594996500
A permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ are permutations, and $$$[1, 1]$$$, $$$[0, 1]$$$, $$$[2, 2, 1, 4]$$$ are not.There was a permutation $$$p[1 \dots n]$$$. It was merged with itself. In other words, let's take two instances of $$$p$$$ and insert elements of the second $$$p$$$ into the first maintaining relative order of elements. The result is a sequence of the length $$$2n$$$.For example, if $$$p=[3, 1, 2]$$$ some possible results are: $$$[3, 1, 2, 3, 1, 2]$$$, $$$[3, 3, 1, 1, 2, 2]$$$, $$$[3, 1, 3, 1, 2, 2]$$$. The following sequences are not possible results of a merging: $$$[1, 3, 2, 1, 2, 3$$$], [$$$3, 1, 2, 3, 2, 1]$$$, $$$[3, 3, 1, 2, 2, 1]$$$.For example, if $$$p=[2, 1]$$$ the possible results are: $$$[2, 2, 1, 1]$$$, $$$[2, 1, 2, 1]$$$. The following sequences are not possible results of a merging: $$$[1, 1, 2, 2$$$], [$$$2, 1, 1, 2]$$$, $$$[1, 2, 2, 1]$$$.Your task is to restore the permutation $$$p$$$ by the given resulting sequence $$$a$$$. It is guaranteed that the answer exists and is unique.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner s=new Scanner(System.in); int t=s.nextInt(); while(t-->0) { int n=s.nextInt(); int arr[]=new int[2*n]; for(int i=0;i<arr.length;i++) { arr[i]=s.nextInt(); } List<Integer> list=new ArrayList<Integer>(); for(int i=0;i<arr.length;i++) { if(!list.contains(arr[i])) { list.add(arr[i]); } } for(Integer num:list) { System.out.print(num+" "); } System.out.println(); } } }
Java
["5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1"]
1 second
["1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1"]
null
Java 8
standard input
[ "greedy" ]
aaf91874cf5aa0fa302ffed2ccecdc76
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 400$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of permutation. The second line of the test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the array $$$a$$$ represents the result of merging of some permutation $$$p$$$ with the same permutation $$$p$$$.
800
For each test case, print the answer: $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), representing the initial permutation. It is guaranteed that the answer exists and is unique.
standard output
PASSED
92c1bea49d9615d70d48472e7993b2c8
train_003.jsonl
1594996500
A permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ are permutations, and $$$[1, 1]$$$, $$$[0, 1]$$$, $$$[2, 2, 1, 4]$$$ are not.There was a permutation $$$p[1 \dots n]$$$. It was merged with itself. In other words, let's take two instances of $$$p$$$ and insert elements of the second $$$p$$$ into the first maintaining relative order of elements. The result is a sequence of the length $$$2n$$$.For example, if $$$p=[3, 1, 2]$$$ some possible results are: $$$[3, 1, 2, 3, 1, 2]$$$, $$$[3, 3, 1, 1, 2, 2]$$$, $$$[3, 1, 3, 1, 2, 2]$$$. The following sequences are not possible results of a merging: $$$[1, 3, 2, 1, 2, 3$$$], [$$$3, 1, 2, 3, 2, 1]$$$, $$$[3, 3, 1, 2, 2, 1]$$$.For example, if $$$p=[2, 1]$$$ the possible results are: $$$[2, 2, 1, 1]$$$, $$$[2, 1, 2, 1]$$$. The following sequences are not possible results of a merging: $$$[1, 1, 2, 2$$$], [$$$2, 1, 1, 2]$$$, $$$[1, 2, 2, 1]$$$.Your task is to restore the permutation $$$p$$$ by the given resulting sequence $$$a$$$. It is guaranteed that the answer exists and is unique.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; public class Main{ public static void main(String[] args){ int t; Scanner s=new Scanner(System.in); t=s.nextInt(); while(t!=0){ int n=s.nextInt(); int arr[]=new int[2*n]; for(int i=0;i<2*n;i++) { arr[i]=s.nextInt(); } HashMap<Integer,Integer> map=new HashMap<>(); for(int i=0;i<2*n;i++){ if(!map.containsKey(arr[i])){ map.put(arr[i],1); System.out.print(arr[i]+" "); } else continue; } System.out.println(); t--; } } }
Java
["5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1"]
1 second
["1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1"]
null
Java 8
standard input
[ "greedy" ]
aaf91874cf5aa0fa302ffed2ccecdc76
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 400$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of permutation. The second line of the test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the array $$$a$$$ represents the result of merging of some permutation $$$p$$$ with the same permutation $$$p$$$.
800
For each test case, print the answer: $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), representing the initial permutation. It is guaranteed that the answer exists and is unique.
standard output
PASSED
3f3aa0890d5ed1fa756dc94c8cf34eb6
train_003.jsonl
1594996500
A permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ are permutations, and $$$[1, 1]$$$, $$$[0, 1]$$$, $$$[2, 2, 1, 4]$$$ are not.There was a permutation $$$p[1 \dots n]$$$. It was merged with itself. In other words, let's take two instances of $$$p$$$ and insert elements of the second $$$p$$$ into the first maintaining relative order of elements. The result is a sequence of the length $$$2n$$$.For example, if $$$p=[3, 1, 2]$$$ some possible results are: $$$[3, 1, 2, 3, 1, 2]$$$, $$$[3, 3, 1, 1, 2, 2]$$$, $$$[3, 1, 3, 1, 2, 2]$$$. The following sequences are not possible results of a merging: $$$[1, 3, 2, 1, 2, 3$$$], [$$$3, 1, 2, 3, 2, 1]$$$, $$$[3, 3, 1, 2, 2, 1]$$$.For example, if $$$p=[2, 1]$$$ the possible results are: $$$[2, 2, 1, 1]$$$, $$$[2, 1, 2, 1]$$$. The following sequences are not possible results of a merging: $$$[1, 1, 2, 2$$$], [$$$2, 1, 1, 2]$$$, $$$[1, 2, 2, 1]$$$.Your task is to restore the permutation $$$p$$$ by the given resulting sequence $$$a$$$. It is guaranteed that the answer exists and is unique.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.io.*; import java.util.*; public class fhjskf { public static void main(String[] args) { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); Random gen = new Random(); int test = sc.nextInt(); while(test-- > 0) { int n = sc.nextInt(); int [] ar = new int[2*n]; for(int i=0;i<ar.length;i++) ar[i] = sc.nextInt(); LinkedHashSet<Integer> set = new LinkedHashSet<>(); for(int i : ar) set.add(i); for(int s :set) pw.print(s+" "); pw.println(); } pw.close(); } }
Java
["5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1"]
1 second
["1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1"]
null
Java 8
standard input
[ "greedy" ]
aaf91874cf5aa0fa302ffed2ccecdc76
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 400$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of permutation. The second line of the test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the array $$$a$$$ represents the result of merging of some permutation $$$p$$$ with the same permutation $$$p$$$.
800
For each test case, print the answer: $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), representing the initial permutation. It is guaranteed that the answer exists and is unique.
standard output
PASSED
5de537566056b83f921c0e5a4a4f4b14
train_003.jsonl
1594996500
A permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ are permutations, and $$$[1, 1]$$$, $$$[0, 1]$$$, $$$[2, 2, 1, 4]$$$ are not.There was a permutation $$$p[1 \dots n]$$$. It was merged with itself. In other words, let's take two instances of $$$p$$$ and insert elements of the second $$$p$$$ into the first maintaining relative order of elements. The result is a sequence of the length $$$2n$$$.For example, if $$$p=[3, 1, 2]$$$ some possible results are: $$$[3, 1, 2, 3, 1, 2]$$$, $$$[3, 3, 1, 1, 2, 2]$$$, $$$[3, 1, 3, 1, 2, 2]$$$. The following sequences are not possible results of a merging: $$$[1, 3, 2, 1, 2, 3$$$], [$$$3, 1, 2, 3, 2, 1]$$$, $$$[3, 3, 1, 2, 2, 1]$$$.For example, if $$$p=[2, 1]$$$ the possible results are: $$$[2, 2, 1, 1]$$$, $$$[2, 1, 2, 1]$$$. The following sequences are not possible results of a merging: $$$[1, 1, 2, 2$$$], [$$$2, 1, 1, 2]$$$, $$$[1, 2, 2, 1]$$$.Your task is to restore the permutation $$$p$$$ by the given resulting sequence $$$a$$$. It is guaranteed that the answer exists and is unique.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; import java.io.*; import java.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner (System.in); int t = in.nextInt(); for (int p=0; p<t; p++) { int n= in.nextInt(); //ArrayList<Integer> arr = new ArrayList<Integer>(); LinkedHashMap<Integer, Integer> map = new LinkedHashMap<>(); for (int i=0; i<2*n; i++) { int a = in.nextInt(); if (map.containsKey(a)) { int val = map.get(a); map.put(a,val+1); } else { map.put(a,1); } } for (int i: map.keySet()) { System.out.print(i+" "); } System.out.println(""); } } }
Java
["5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1"]
1 second
["1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1"]
null
Java 8
standard input
[ "greedy" ]
aaf91874cf5aa0fa302ffed2ccecdc76
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 400$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of permutation. The second line of the test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the array $$$a$$$ represents the result of merging of some permutation $$$p$$$ with the same permutation $$$p$$$.
800
For each test case, print the answer: $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), representing the initial permutation. It is guaranteed that the answer exists and is unique.
standard output
PASSED
c5f085100345f3b221cb5f1c5d2213ba
train_003.jsonl
1593873900
You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k &gt; 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge.
256 megabytes
import java.io.*; import java.math.*; import java.text.*; import java.util.*; public class test { public static void main(String args[]) {Scanner in=new Scanner(System.in); test ob=new test(); int tc,i,r,j,k,l,n,c,p=0,o,m; tc=in.nextInt(); for(i=0;i<tc;i++) { r=in.nextInt(); c=in.nextInt(); int a[][]=new int[r][c]; int b[][]=new int[r][c]; for(j=0;j<r;j++) {for(k=0;k<c;k++) a[j][k]=in.nextInt(); } for(j=0;j<r;j++) {for(k=0;k<c;k++) b[j][k]=4; } for(j=0;j<r;j++) { b[j][0]=3; b[j][c-1]=3; } for(k=0;k<c;k++) {b[0][k]=3; b[r-1][k]=3; } b[0][c-1]=2; b[r-1][0]=2; b[0][0]=2; b[r-1][c-1]=2; p=0; for(j=0;j<r;j++) {for(k=0;k<c;k++) {if(a[j][k]>b[j][k]) p++; }} if(p==0) {System.out.println("YES"); for(j=0;j<r;j++) { for(k=0;k<c;k++) { System.out.print(b[j][k]+" ");} System.out.println();} } else { System.out.println("NO");} } }}
Java
["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"]
1 second
["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"]
NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good.
Java 11
standard input
[ "constructive algorithms", "greedy" ]
8afcdfaabba66fb9cefc5b6ceabac0d0
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$)  — the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$.
1,200
If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them.
standard output
PASSED
645de078d856679eb0a351343b846b3b
train_003.jsonl
1593873900
You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k &gt; 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge.
256 megabytes
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Main { public static void main (String[] args) throws java.lang.Exception { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int test=0;test<t;test++){ int n=sc.nextInt(); int m=sc.nextInt(); int arr[][]=new int[n][m]; int flag=0; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ arr[i][j]=sc.nextInt(); if(arr[i][j]>4|| ((i==0||i==n-1)&&(j==0 || j==m-1)&&arr[i][j]>2)||(((i==0 ||i==n-1)&&arr[i][j]>3)||((j==0||j==m-1)&&arr[i][j]>3))){ flag=1; } } } if(flag==1){ System.out.println("NO"); } else{ System.out.println("YES"); for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ if((i==0||i==n-1)&&(j==0 || j==m-1)){ arr[i][j]=2; } else if(((i>0&&i<n-1)&&(j==0||j==m-1))||((j>0&&j<m-1)&&(i==0||i==n-1))) { arr[i][j]=3; } else{ arr[i][j]=4; } } } for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ System.out.print(arr[i][j]+" "); } System.out.println(""); } } } } }
Java
["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"]
1 second
["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"]
NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good.
Java 11
standard input
[ "constructive algorithms", "greedy" ]
8afcdfaabba66fb9cefc5b6ceabac0d0
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$)  — the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$.
1,200
If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them.
standard output
PASSED
49ce073444c12fe87c6b89b3ac3dcb4a
train_003.jsonl
1593873900
You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k &gt; 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge.
256 megabytes
import java.io.*; import java.util.Arrays; import java.util.StringTokenizer; public class B { static int[][] Z = new int[400][400]; private static void solve() throws Exception { int n = R.nextInt(); int m = R.nextInt(); boolean ans = true; for (int i = 0 ; i < n ; i ++ ) { for (int j = 0; j < m ; j ++ ) { int p = 4; if ( i == 0 || i == n-1 ) { p -- ; } if ( j == 0 || j == m-1 ) { p -- ; } int x = R.nextInt(); if ( x > p ) { ans = false ; } } } if (ans) { PW.println("YES"); } else { PW.println("NO"); return ; } for (int i = 0 ; i < n ; i ++ ) { for (int j = 0; j < m ; j ++ ) { int p = 4; if ( i == 0 || i == n-1 ) { p -- ; } if ( j == 0 || j == m-1 ) { p -- ; } PW.print(p); PW.print(' ' ); } PW.println(); } } private static Reader R = new Reader(); private static PrintWriter PW = new PrintWriter(System.out); public static void main(String[] args) throws Exception{ int T = R.nextInt(); for (int t = 0; t < T; t ++ ) { solve(); } PW.close(); } static void debug(Object... O) { System.out.print("DEBUG "); System.out.println(Arrays.deepToString(O)); } static class Reader { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextString() { return next(); } } }
Java
["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"]
1 second
["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"]
NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good.
Java 11
standard input
[ "constructive algorithms", "greedy" ]
8afcdfaabba66fb9cefc5b6ceabac0d0
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$)  — the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$.
1,200
If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them.
standard output
PASSED
8b1c41bab668072b46d9a51c5f14ebbb
train_003.jsonl
1593873900
You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k &gt; 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge.
256 megabytes
// Main Code at the Bottom import java.util.*; import java.lang.*; import java.io.*; import java.math.BigInteger; public class Main { //Fast IO class static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { boolean env=System.getProperty("ONLINE_JUDGE") != null; if(!env) { try { br=new BufferedReader(new FileReader("src\\input.txt")); } catch (FileNotFoundException e) { e.printStackTrace(); } } else br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static long MOD=1000000000+7; //debug static void debug(Object... o) { System.out.println(Arrays.deepToString(o)); } // Pair static class pair{ long x,y; pair(long a,long b){ this.x=a; this.y=b; } public boolean equals(Object obj) { if(obj == null || obj.getClass()!= this.getClass()) return false; pair p = (pair) obj; return (this.x==p.x && this.y==p.y); } public int hashCode() { return Objects.hash(x,y); } } static FastReader sc=new FastReader(); static PrintWriter out=new PrintWriter(System.out); //Main function(The main code starts from here) public static void main (String[] args) throws java.lang.Exception { int test=1; test=sc.nextInt(); while(test-->0){ int n=sc.nextInt(),m=sc.nextInt(); int a[][]=new int[n][m]; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) a[i][j]=sc.nextInt(); } int ans[][]=new int[n][m]; ans[0][0]=ans[0][m-1]=ans[n-1][0]=ans[n-1][m-1]=2; for(int i=1;i<n-1;i++) { for(int j=1;j<m-1;j++) ans[i][j]=4; } for(int i=0;i<n;i++) { for(int j=0;j<m;j++) if(ans[i][j]==0) ans[i][j]=3; } int f=0; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) if(a[i][j]>ans[i][j]) { f=1; break; } } if(f==1) out.println("NO"); else { out.println("YES"); for(int i=0;i<n;i++) { for(int j=0;j<m;j++) out.print(ans[i][j]+" "); out.println(); } } } out.flush(); out.close(); } }
Java
["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"]
1 second
["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"]
NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good.
Java 11
standard input
[ "constructive algorithms", "greedy" ]
8afcdfaabba66fb9cefc5b6ceabac0d0
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$)  — the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$.
1,200
If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them.
standard output
PASSED
2b44e3eb99c068b542bc3acc3915bd69
train_003.jsonl
1593873900
You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k &gt; 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge.
256 megabytes
import java.io.*; import java.util.*; public class Main { public static FastReader scan = new FastReader(); public static void main(String[] args) { int t = scan.nextInt(); while(t--> 0) { int n = scan.nextInt(); int m = scan.nextInt(); long a[][] = new long[n][m]; boolean ans = true; for(int i=0; i<n; i++) for(int j=0; j<m; j++) a[i][j] = scan.nextInt(); for(int i=0; i<n; i++) { for(int j=0; j<m; j++) { if(a[i][j] > 4) { ans = false; break; } int c = 4; if(i-1 < 0) --c; if(i+1 > n-1) --c; if(j-1 < 0) --c; if(j+1 > m-1) --c; if(a[i][j] == 3 && c < 3) { ans = false; break; } else if(a[i][j] == 4 && c < 4) { ans = false; break; } a[i][j] = c; } if(!ans) break; } if(ans) { System.out.println("YES"); for(int i=0; i<n; i++) { for(int j=0; j<m; j++) System.out.print(a[i][j] + " "); System.out.println(); } } else System.out.println("NO"); } } public static int gcd(int a, int b) { if(b == 0) return a; return gcd(b, a%b); } public static long abs(long a, long b) {return Math.abs(a - b);} public static long min(long a, long b) {return Math.min(a, b);} public static long max(long a, long b) {return Math.max(a, b);} public static int abs(int a, int b) {return Math.abs(a - b);} public static int min(int a, int b) {return Math.min(a, b);} public static int max(int a, int b) {return Math.max(a, b);} // sieveOfEratosthenes public static boolean[] sieve(int n) { boolean[] prime = new boolean[n+1]; Arrays.fill(prime, true); prime[0] = false; prime[1] = false; for(int i=2; i*i<n; i++) { if(prime[i] == true) { for(int j=i*2; j<=n; j+=i) { prime[j] = false; } } } return prime; } //smallestFactor function public static int smallestFactor(int n) { int i; for(i=2; i*i<=n; i++) { if(n%i == 0) break; } return i; } //isPrime public static boolean isPrime(int n) { boolean isPrime = true; for(int i=2; i*i<=n; i++) if(n % i == 0) isPrime = false; return isPrime; } //FastReader Class static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } char[] nextChar() { return next().toCharArray(); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } private static long gcd(long m, long n) { if(isINFL(-m)) return n; assertion((m>=0L) && (n>=0L)); if(m < n) return gcd(n, m); if(n == 0) return m; return gcd(n, m % n); } private static void assertion(boolean b) { if(!b) throw new AssertionError(); } private static long INFL = (long)1e17; private static boolean isINFL(long in) { if((in*10L)>INFL) return true; else return false; } }
Java
["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"]
1 second
["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"]
NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good.
Java 11
standard input
[ "constructive algorithms", "greedy" ]
8afcdfaabba66fb9cefc5b6ceabac0d0
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$)  — the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$.
1,200
If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them.
standard output
PASSED
e48c419fa9b7e0ce29ab14329ea21a76
train_003.jsonl
1593873900
You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k &gt; 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge.
256 megabytes
import java.util.Scanner; public class NeighborGrid { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int Case = sc.nextInt(); for (int i=0;i<Case;i++){ Solve(sc); } } private static void Solve(Scanner sc) { int n = sc.nextInt(); int m = sc.nextInt(); int [][] a = new int[m][n]; boolean Flag = true; for (int j=0;j<n;j++){ for (int i=0;i<m;i++){ a[i][j] = sc.nextInt(); if (a[i][j]>4){ Flag = false; //break; }else if (i==0&&j==0||i==0&&j==n-1||i==m-1&&j==0||i==m-1&&j==n-1){ if (a[i][j]>2){ Flag = false; //break; } }else if (i==0||j==0||i==m-1||j==n-1){ if (a[i][j]>3){ Flag =false; // break; } } } } if (Flag){ System.out.println("YES"); for (int j=0;j<n;j++){ for (int i=0;i<m;i++){ if (i==0&&j==0||i==0&&j==n-1||i==m-1&&j==0||i==m-1&&j==n-1){ System.out.print(2+" "); }else if (i==0||j==0||i==m-1||j==n-1){ System.out.print(3+" "); }else { System.out.print(4+" "); } } System.out.println(""); } }else { System.out.println("NO"); } } } /** * * if a[i][j] > 4 * NO * * * * * */
Java
["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"]
1 second
["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"]
NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good.
Java 11
standard input
[ "constructive algorithms", "greedy" ]
8afcdfaabba66fb9cefc5b6ceabac0d0
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$)  — the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$.
1,200
If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them.
standard output
PASSED
a149febf2ad27bc6c087c0d3713b42bf
train_003.jsonl
1593873900
You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k &gt; 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge.
256 megabytes
// package com.prashant; import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { // write your code here PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); Reader sc = new Reader(); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int m = sc.nextInt(); int[][] mat = new int[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { mat[i][j] = sc.nextInt(); } } boolean flag = false; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (mat[i][j] > 4) { flag = true; break; } else { int val = mat[i][j]; int cnt = 0; boolean flag1 = true, flag2 = true, flag3 = true, flag4 = true; if (i - 1 >= 0) { cnt++; } if (j - 1 >= 0) { cnt++; } if (j + 1 < m) { cnt++; } if (i + 1 < n) { cnt++; } if (val > cnt) { flag = true; break; } else { mat[i][j] = cnt; } } if (flag) { break; } } } if (flag) { out.println("No"); } else { out.println("Yes"); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { out.print(mat[i][j] + " "); } out.println(); } } } out.close(); } /*-------------------------------------------------------------------------------------*/ public static long gcd(long a, long b) { if (b == 0) { return a; } return gcd(b, a % b); } public static long power(long x, long y) { long res = 1; while (x > 0) { if (y % 2 == 0) { x *= x; y /= 2; } else { res *= x; y--; } } return res; } public static long lcm(long x, long y) { return (x * y) / gcd(x, y); } public static int lowerBound(Vector<Integer> v, int e) { int start = 0, end = v.size() - 1, ind = -1; while (start <= end) { int mid = (start + end) / 2; if (v.get(mid) == e) { ind = mid; break; } else if (v.get(mid) < e) { ind = mid + 1; start = mid + 1; } else { end = mid - 1; } } return ind; } // Fast I/p static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } }
Java
["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"]
1 second
["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"]
NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good.
Java 11
standard input
[ "constructive algorithms", "greedy" ]
8afcdfaabba66fb9cefc5b6ceabac0d0
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$)  — the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$.
1,200
If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them.
standard output
PASSED
35c86da3f91f434d105331e9798b21ce
train_003.jsonl
1593873900
You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k &gt; 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Learning { public static void main(String[] args) throws Exception { FastInput in = new FastInput(); int t = in.nextInt(); StringBuilder st = new StringBuilder(); while (t-- > 0) { int n = in.nextInt(); int m = in.nextInt(); int[][] arr = new int[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) arr[i][j] = in.nextInt(); } boolean f = true; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (i == 0 && j == 0 || i == 0 && j == m - 1 || i == n - 1 && j == m - 1 || i == n - 1 && j == 0) { if (arr[i][j] > 2) { f = false; break; } arr[i][j] = 2; } else if (i == 0 || j == 0 || i == n - 1 || j == m - 1) { if (arr[i][j] > 3) { f = false; break; } arr[i][j] = 3; } else { if (arr[i][j] > 4) { f = false; break; } arr[i][j] = 4; } } } if (!f) { st.append("NO\n"); continue; } st.append("YES\n"); for (int[] i : arr) { for (int j : i) { st.append(j).append(" "); } st.append("\n"); } } System.out.print(st.toString()); } // private static boolean DFS(int x, int y, int[][] arr, int n, int m, boolean[][] vis) { // vis[x][y] = true; // int r[] = new int[]{-1,1,0,0}; // int u[] = new int[]{0,0,-1,1}; // for(int i = 0;i<4;i++){ // int nx = r[i]+x; // int ny = u[i]+y; // if(nx>=0&&nx<n&&ny>=0&&ny<m){ // if(arr[nx][ny]==){ // // } // } // } // // } } class FastInput { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st; String next() throws IOException { if (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } Integer nextInt() throws IOException { return Integer.parseInt(next()); } Long nextLong() throws IOException { return Long.parseLong(next()); } }
Java
["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"]
1 second
["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"]
NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good.
Java 11
standard input
[ "constructive algorithms", "greedy" ]
8afcdfaabba66fb9cefc5b6ceabac0d0
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$)  — the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$.
1,200
If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them.
standard output
PASSED
7fc95cfe2f757d5e2cf4124f43d7a7eb
train_003.jsonl
1593873900
You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k &gt; 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge.
256 megabytes
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Codechef { static int n,m; public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner input = new Scanner(System.in); int test = input.nextInt(); while(test-->0){ n = input.nextInt(); m = input.nextInt(); int arr[][] = new int[n][m]; for(int i =0;i<n;i++){ for(int j =0;j<m;j++){ arr[i][j] = input.nextInt(); } } boolean ok = true; for(int i =0;i<n;i++){ for(int j =0;j<m;j++){ if(arr[i][j] == 0)continue; int sum =0; if(i-1>=0 && arr[i-1][j] != 0)sum++; if(j-1>=0 && arr[i][j-1] != 0)sum++; if(i+1<n && arr[i+1][j] != 0)sum++; if(j+1<m && arr[i][j+1] != 0)sum++; int diff = arr[i][j] - sum; if(diff == 0)continue; if(diff<0)arr[i][j] = sum; else{ if(!change(arr,diff,i,j)){ok = false;break;} } } if(!ok)break; } if(ok){ System.out.println("YES"); for(int i =0;i<n;i++){ for(int j =0;j<m;j++){ if(arr[i][j] == 0){System.out.print(arr[i][j]+" ");continue;} int sum =0; if(i-1>=0 && arr[i-1][j] != 0)sum++; if(j-1>=0 && arr[i][j-1] != 0)sum++; if(i+1<n && arr[i+1][j] != 0)sum++; if(j+1<m && arr[i][j+1] != 0)sum++; int diff = arr[i][j] - sum; if(diff == 0){System.out.print(arr[i][j]+" ");continue;} if(diff<0)arr[i][j] = sum; System.out.print(arr[i][j]+" "); } System.out.println(); } }else{ System.out.println("NO"); } } } public static boolean change(int arr[][],int val,int i,int j){ if(i-1>=0 && arr[i-1][j] == 0){ arr[i-1][j]++;val--; } if(val == 0)return true; if(j-1>=0 && arr[i][j-1] == 0){arr[i][j-1]++;val--;} if(val == 0)return true; if(i+1<n && arr[i+1][j] == 0){arr[i+1][j]++;val--;} if(val == 0)return true; if(j+1<m && arr[i][j+1] == 0){arr[i][j+1]++;val--;} return val == 0?true:false; } }
Java
["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"]
1 second
["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"]
NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good.
Java 11
standard input
[ "constructive algorithms", "greedy" ]
8afcdfaabba66fb9cefc5b6ceabac0d0
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$)  — the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$.
1,200
If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them.
standard output
PASSED
43f845ef1c946de4cad6946d9a3bc250
train_003.jsonl
1593873900
You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k &gt; 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class Task2 { public static void main(String[] args) throws IOException { new Task2().solve(); } private void solve() throws IOException { BufferedReader f = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); int t = Integer.parseInt(f.readLine()); for (int t1 = 0; t1 < t; t1++) { StringTokenizer tokenizer = new StringTokenizer(f.readLine()); int n = Integer.parseInt(tokenizer.nextToken()); int m = Integer.parseInt(tokenizer.nextToken()); int[][] map = new int[n][m]; for (int i = 0; i < n; i++) { tokenizer = new StringTokenizer(f.readLine()); for (int j = 0; j < m; j++) { map[i][j] = Integer.parseInt(tokenizer.nextToken()); } } boolean impossible = false; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { int max = 2; if (i != 0 && i != n - 1) max++; if (j != 0 && j != m - 1) max++; if (max < map[i][j]) impossible = true; map[i][j] = max; } } if (impossible) out.println("NO"); else { out.println("YES"); for (int i = 0; i < n; i++) { out.print(map[i][0]); for (int j = 1; j < m; j++) out.print(" " + map[i][j]); out.println(); } } } out.close(); } }
Java
["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"]
1 second
["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"]
NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good.
Java 11
standard input
[ "constructive algorithms", "greedy" ]
8afcdfaabba66fb9cefc5b6ceabac0d0
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$)  — the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$.
1,200
If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them.
standard output