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
714f65c77aaf08909e1a4748d67b597f
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.*; import java.io.BufferedReader; import java.io.InputStreamReader; 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); TaskA solver = new TaskA(); // int a = 1; int t; t = in.nextInt(); //t = 1; while (t > 0) { // out.print("Case #"+(a++)+": "); solver.call(in,out); t--; } out.close(); } static class TaskA { public void call(InputReader in, PrintWriter out) { int n; n = in.nextInt(); List<Integer> list = new ArrayList<>(); for (int i = 1; i <= n; i++) { list.add(i); } while (n > 4){ List<Integer> list1; if(n % 4==0){ list1 = ans(list, in); } else if(n%4==1){ list1 = ans(list, in); list1.add(list.get(n - 1)); } else if(n%4==2){ list1 = ans(list, in); list1.add(list.get(n - 2)); list1.add(list.get(n - 1)); } else{ list1 = ans(list, in); list1.add(list.get(n - 3)); list1.add(list.get(n - 2)); list1.add(list.get(n - 1)); } list = new ArrayList<>(list1); n = list.size(); } if(list.size()==3){ for (int i = 1; i <= n; i++) { if(!list.contains(i)){ list.add(i); break; } } } if(list.size()==4){ list = ans(list, in); } System.out.println("! "+list.get(0) +" "+list.get(list.size() - 1)); } public List<Integer> ans(List<Integer> list, InputReader in){ int n = list.size(); int a, b, c, d, max, e; List<Integer> list1 = new ArrayList<>(); for (int i = 0; i < n - 3; i+=4) { e = 0; int[] arr = new int[4]; a = query(list.get(i), list.get(i + 1), list.get(i + 2), in); b = query(list.get(i), list.get(i + 1), list.get(i + 3), in); c = query(list.get(i), list.get(i + 2), list.get(i + 3), in); d = query(list.get(i + 1), list.get(i + 2), list.get(i + 3), in); max = Math.max(a, Math.max(b, Math.max(c, d))); if(a==max){ arr[0]++; arr[1]++; arr[2]++; e++; } if(b==max){ arr[0]++; arr[1]++; arr[3]++; e++; } if(c==max && e < 2){ arr[0]++; arr[2]++; arr[3]++; e++; } if(d==max && e < 2){ arr[1]++; arr[2]++; arr[3]++; } for (int j = 0; j < 4; j++) { if(arr[j] > 1){ list1.add(list.get(i + j)); } } } return list1; } public int query(int i, int j, int k, InputReader in){ System.out.println("? "+i+" "+j+" "+k); System.out.flush(); int a = in.nextInt(); System.out.flush(); return a; } } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } static class answer implements Comparable<answer>{ int a, b; public answer(int a, int b) { this.a = a; this.b = b; } @Override public int compareTo(answer o) { return Integer.compare(o.a, this.a); } } static class answer1 implements Comparable<answer1>{ int a, b, c; public answer1(int a, int b, int c) { this.a = a; this.b = b; this.c = c; } @Override public int compareTo(answer1 o) { return (o.a - this.a); } } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static void sort(long[] a) { ArrayList<Long> l = new ArrayList<>(); for (Long i:a) l.add(i); l.sort(Collections.reverseOrder()); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static final Random random=new Random(); static void shuffleSort(int[] a) { int n = a.length; for (int i=0; i<n; i++) { int oi= random.nextInt(n), temp=a[oi]; a[oi]=a[i]; a[i]=temp; } Arrays.sort(a); } 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()); } public double nextDouble() { return Double.parseDouble(next()); } } }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 8
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
10bf84f0e319f0c8d46a19beb1ed7470
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
import java.util.*; import java.io.*; public class tr0 { static PrintWriter out; static StringBuilder sb; static long mod = (long) 998244353; static long inf = (long) 1e16; static int n, l, k; static TreeSet<Integer>[] ad, ad1, ad2; static ArrayList<int[]>[] quer; static int[][] remove, add; static int[][][] memo; static boolean vis[]; static long[] inv, f, ncr[]; static HashMap<Integer, Integer> hm; static int[] pre, suf, Smax[], Smin[]; static int idmax, idmin; static ArrayList<Integer> av; static HashMap<Integer, Integer> mm; static boolean[] msks; static int[] lazy[], lazyCount; static int[][] a; static long ans, tem, c; static ArrayList<Integer> gl; static int[] ar; static String s; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); out = new PrintWriter(System.out); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); TreeMap<Integer, Integer> tm = new TreeMap<>(); PriorityQueue<int[]> pr = new PriorityQueue<>((x, y) -> y[0] - x[0]); for (int i = 3; i <= n; i++) { out.println("? " + 1 + " " + 2 + " " + i); out.flush(); int d = sc.nextInt(); tm.put(d, i); pr.add(new int[] { d, i }); } int max1 = pr.peek()[0]; int k1 = pr.poll()[1]; PriorityQueue<int[]> pr2 = new PriorityQueue<>((x, y) -> y[0] - x[0]); for (int i = 3; i <= n; i++) { if (i == k1) continue; out.println("? " + 1 + " " + k1 + " " + i); out.flush(); int d = sc.nextInt(); pr2.add(new int[] { d, i }); } int max2 = pr2.peek()[0]; int k2 = pr2.poll()[1]; out.println("? " + 1 + " " + k1 + " " + k2); out.flush(); int d1 = sc.nextInt(); out.println("? " + 2 + " " + k1 + " " + k2); out.flush(); int d2 = sc.nextInt(); int max = Math.max(max1, max2); if (tm.size() == 1 && d1 <= max1 && d2 <= max1) { out.println("! " + 1 + " " + 2); out.flush(); continue; } if (d1 == d2 && d1 >= max1) { out.println("! " + k1 + " " + k2); out.flush(); continue; } else { if (d1 == max) { out.println("! " + k1 + " " + 1); out.flush(); continue; } else if (d2 == max) { out.println("! " + k1 + " " + 2); out.flush(); continue; } else throw new Exception(); } } } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream system) { br = new BufferedReader(new InputStreamReader(system)); } public Scanner(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 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 int[] nextArrInt(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public long[] nextArrLong(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public int[] nextArrIntSorted(int n) throws IOException { int[] a = new int[n]; Integer[] a1 = new Integer[n]; for (int i = 0; i < n; i++) a1[i] = nextInt(); Arrays.sort(a1); for (int i = 0; i < n; i++) a[i] = a1[i].intValue(); return a; } public long[] nextArrLongSorted(int n) throws IOException { long[] a = new long[n]; Long[] a1 = new Long[n]; for (int i = 0; i < n; i++) a1[i] = nextLong(); Arrays.sort(a1); for (int i = 0; i < n; i++) a[i] = a1[i].longValue(); return a; } public boolean ready() throws IOException { return br.ready(); } public void waitForInput() throws InterruptedException { Thread.sleep(3000); } } }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 8
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
6b426b9c5125dd302bc67996eef73e81
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
import java.io.*; import java.util.*; public class Main { public static final Comparator<int[]> PAIR_COMPARATOR = (o1, o2) -> { if (o1[0] == o2[0]) { return Long.compare(o1[1], o2[1]); } return Long.compare(o1[0], o2[0]); }; public static void main(String[] args) throws FileNotFoundException { PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); InputReader in = new InputReader(System.in); int t = in.nextInt(); for (int ii = 0; ii < t; ii++) { int n = in.nextInt(); int d = query(out, in, 0, 1, 2); int[] triple = {0, 1, 2}; for (int i = 3; i < n; i++) { int d1 = query(out, in, triple[0], triple[1], i); int d2 = query(out, in, triple[1], triple[2], i); if (i == n - 1) { int d3 = query(out, in, triple[0], triple[2], i); int[][] diffs = {{d, 3}, {d1, 2}, {d2, 0}, {d3, 1}}; Arrays.sort(diffs, PAIR_COMPARATOR); Set<Integer> all = new HashSet<>(); all.add(0); all.add(1); all.add(2); all.add(3); all.remove(diffs[3][1]); all.remove(diffs[2][1]); String s = "! "; for (int elem : all) { if (elem == 3) { s += (i + 1) + " "; } else { s += (triple[elem] + 1) + " "; } } out.println(s); out.flush(); } if (d1 >= d2) { if (d1 >= d) { triple = new int[]{triple[0], triple[1], i}; d = d1; } } else { if (d2 >= d) { triple = new int[]{triple[1], triple[2], i}; d = d2; } } } } out.close(); } private static int query(PrintWriter out, InputReader in, int a, int b, int c) { out.println("? " + (a + 1) + " " + (b + 1) + " " + (c + 1) + " "); out.flush(); return in.nextInt(); } private static void outputArray(int[] ans, PrintWriter out, boolean addOne) { StringBuilder str = new StringBuilder(); for (long an : ans) { str.append(addOne ? (an + 1) : an).append(" "); } out.println(str); // out.flush(); } private static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } private String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public String nextString() { try { return reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public char nextChar() { return next().charAt(0); } public String nextWord() { return next(); } private List<Integer>[] readTree(int n) { return readGraph(n, n - 1); } private List<Integer>[] readGraph(int n, int m) { List<Integer>[] result = new List[n]; for (int i = 0; i < n; i++) { result[i] = new ArrayList<>(); } for (int i = 0; i < m; i++) { int u = nextInt() - 1; int v = nextInt() - 1; result[u].add(v); result[v].add(u); } return result; } private Map<Integer, Long>[] readWeightedGraph(int n, int m) { Map<Integer, Long>[] result = new HashMap[n]; for (int i = 0; i < n; i++) { result[i] = new HashMap<>(); } for (int i = 0; i < m; i++) { int u = nextInt() - 1; int v = nextInt() - 1; long w = nextLong(); result[u].put(v, Math.min(w, result[u].getOrDefault(v, Long.MAX_VALUE))); result[v].put(u, Math.min(w, result[v].getOrDefault(u, Long.MAX_VALUE))); } return result; } private int[] readArray(int size, boolean subOne) { int[] a = new int[size]; for (int i = 0; i < size; i++) { a[i] = nextInt() + (subOne ? -1 : 0); } return a; } private long[] readLongArray(int size) { long[] a = new long[size]; for (int i = 0; i < size; i++) { a[i] = nextLong(); } return a; } } }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 8
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
bd165071d0846922f3e73047835218aa
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
import java.io.*; import java.util.*; public final class D { static PrintWriter out; public static void main(String[] args) { FastScanner fs = new FastScanner(); out = new PrintWriter(System.out); int T = fs.nextInt(); for(int tt = 0; tt < T; ++tt){ int n = fs.nextInt(); int[] curr = new int[]{0,1,0,0}; for(int i = 2; i < n - 1; i += 2){ curr[2]= i; curr[3]= i + 1; PriorityQueue<Pair> pq = new PriorityQueue<>(); query(curr[1], curr[2], curr[3]); int val = fs.nextInt(); pq.add(new Pair(curr[0], val)); query(curr[0], curr[2], curr[3]); val= fs.nextInt(); pq.add(new Pair(curr[1], val)); query(curr[0], curr[1], curr[3]); val = fs.nextInt(); pq.add(new Pair(curr[2], val)); query(curr[0], curr[1], curr[2]); val = fs.nextInt(); pq.add(new Pair(curr[3], val)); curr[0] = pq.poll().fst; curr[1] = pq.poll().fst; } if(n % 2 != 0){ int other = 0; while (curr[0] == other || curr[1] == other) other++; curr[2] = n - 1; curr[3] = other; PriorityQueue<Pair> pq = new PriorityQueue<>(); query(curr[1], curr[2], curr[3]); int val = fs.nextInt(); pq.add(new Pair(curr[0], val)); query(curr[0], curr[2], curr[3]); val= fs.nextInt(); pq.add(new Pair(curr[1], val)); query(curr[0], curr[1], curr[3]); val = fs.nextInt(); pq.add(new Pair(curr[2], val)); query(curr[0], curr[1], curr[2]); val = fs.nextInt(); pq.add(new Pair(curr[3], val)); curr[0] = pq.poll().fst; curr[1] = pq.poll().fst; } out.println("! " + (curr[0] + 1) + " " + (curr[1] + 1)); out.flush(); } } static void query(int i, int j, int k){ out.println("? " + (++i) + " " + (++j) + " " + (++k)); out.flush(); } static class Pair implements Comparable<Pair> { int fst; int sec; public Pair(int fst, int sec) { this.fst = fst; this.sec = sec; } public int compareTo(Pair o) { return this.sec - o.sec; } } static final Random random = new Random(); static final int mod = 1_000_000_007; static long add(long a, long b) { return (a + b) % mod; } static long sub(long a, long b) { return ((a - b) % mod + mod) % mod; } static void sort(int[] a) { ArrayList<Integer> l = new ArrayList<>(); for (int i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } static long mul(long a, long b) { return (a * b) % mod; } static long exp(long base, long exp) { if (exp == 0) return 1; long half = exp(base, exp / 2); if (exp % 2 == 0) return mul(half, half); return mul(half, mul(half, base)); } static long[] factorials = new long[2_000_001]; static long[] invFactorials = new long[2_000_001]; static void precompFacts() { factorials[0] = invFactorials[0] = 1; for (int i = 1; i < factorials.length; i++) factorials[i] = mul(factorials[i - 1], i); invFactorials[factorials.length - 1] = exp(factorials[factorials.length - 1], mod - 2); for (int i = invFactorials.length - 2; i >= 0; i--) invFactorials[i] = mul(invFactorials[i + 1], i + 1); } static long nCk(int n, int k) { return mul(factorials[n], mul(invFactorials[k], invFactorials[n - k])); } static class FastScanner { 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()); } } }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 8
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
699fcde512abaace265a49d053e4e7da
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
import java.util.Arrays; import java.util.HashMap; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.util.Random; import java.io.FileWriter; import java.io.PrintWriter; /* Solution Created: 13:55:02 08/02/2022 Custom Competitive programming helper. */ public class Main { public static int[] bad() { int[][] x = new int[4][2]; x[0][0] = ask(1, 2, 3); x[1][0] = ask(1, 2, 4); x[2][0] = ask(1, 3, 4); x[3][0] = ask(2, 3, 4); x[0][1] = 4; x[1][1] = 3; x[2][1] = 2; x[3][1] = 1; Arrays.sort(x, (a,b)->(a[0]-b[0])); return new int[] {x[2][1],x[3][1]}; } public static void solve() { a = new HashMap<>(); int n = in.nextInt(); int[] x = bad(); int a = x[0], b = x[1], curDif = -1, mxOrMin = 1; for(int i = 1; i<=n; i++) { if(i == a || i == b) continue; int q = ask(a,b,i); if(q>curDif) { mxOrMin = i; curDif = q; } } curDif = -1; int second = -1; for(int i = 1; i<=n; i++) { if(i == mxOrMin || i == a || i == b) continue; int q = ask(a,mxOrMin,i); if(q>curDif) { second = i; curDif = q; } } say(mxOrMin, second); } static HashMap<String, Integer> a; static int ask(int i, int j, int k) { int[] x = new int[] {i,j,k}; Util.sortArray(x); String id = x[0]+":"+x[1]+":"+x[2]; if(a.containsKey(id)) return a.get(id); out.println("? "+i+" "+j+" "+k); out.flush(); int ans = in.nextInt(); a.put(id, ans); return ans; } static void say(int i, int j) { out.println("! "+i+" "+j); out.flush(); } public static void main(String[] args) { in = new Reader(); out = new Writer(); int t = in.nextInt(); while(t-->0) solve(); out.exit(); } static Reader in; static Writer out; static class Reader { static BufferedReader br; static StringTokenizer st; public Reader() { this.br = new BufferedReader(new InputStreamReader(System.in)); } public Reader(String f){ try { this.br = new BufferedReader(new FileReader(f)); } catch (IOException e) { e.printStackTrace(); } } public int[] na(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public double[] nd(int n) { double[] a = new double[n]; for (int i = 0; i < n; i++) a[i] = nextDouble(); return a; } public long[] nl(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public char[] nca() { return next().toCharArray(); } public String[] ns(int n) { String[] a = new String[n]; for (int i = 0; i < n; i++) a[i] = next(); return a; } public int nextInt() { ensureNext(); return Integer.parseInt(st.nextToken()); } public double nextDouble() { ensureNext(); return Double.parseDouble(st.nextToken()); } public Long nextLong() { ensureNext(); return Long.parseLong(st.nextToken()); } public String next() { ensureNext(); return st.nextToken(); } public String nextLine() { try { return br.readLine(); } catch (Exception e) { e.printStackTrace(); return null; } } private void ensureNext() { if (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } } } static class Util{ private static Random random = new Random(); static long[] fact; public static void initFactorial(int n, long mod) { fact = new long[n+1]; fact[0] = 1; for (int i = 1; i < n+1; i++) fact[i] = (fact[i - 1] * i) % mod; } public static long modInverse(long a, long MOD) { long[] gcdE = gcdExtended(a, MOD); if (gcdE[0] != 1) return -1; // Inverted doesn't exist long x = gcdE[1]; return (x % MOD + MOD) % MOD; } public static long[] gcdExtended(long p, long q) { if (q == 0) return new long[] { p, 1, 0 }; long[] vals = gcdExtended(q, p % q); long tmp = vals[2]; vals[2] = vals[1] - (p / q) * vals[2]; vals[1] = tmp; return vals; } public static long nCr(int n, int r, long MOD) { if (r == 0) return 1; return (fact[n] * modInverse(fact[r], MOD) % MOD * modInverse(fact[n - r], MOD) % MOD) % MOD; } public static long nCr(int n, int r) { return (fact[n]/fact[r])/fact[n-r]; } public static long nPr(int n, int r, long MOD) { if (r == 0) return 1; return (fact[n] * modInverse(fact[n - r], MOD) % MOD) % MOD; } public static long nPr(int n, int r) { return fact[n]/fact[n-r]; } public static boolean isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } public static boolean[] getSieve(int n) { boolean[] isPrime = new boolean[n+1]; for (int i = 2; i <= n; i++) isPrime[i] = true; for (int i = 2; i*i <= n; i++) if (isPrime[i]) for (int j = i; i*j <= n; j++) isPrime[i*j] = false; return isPrime; } static long pow(long x, long pow, long mod){ long res = 1; x = x % mod; if (x == 0) return 0; while (pow > 0){ if ((pow & 1) != 0) res = (res * x) % mod; pow >>= 1; x = (x * x) % mod; } return res; } public static int gcd(int a, int b) { int tmp = 0; while(b != 0) { tmp = b; b = a%b; a = tmp; } return a; } public static long gcd(long a, long b) { long tmp = 0; while(b != 0) { tmp = b; b = a%b; a = tmp; } return a; } public static int random(int min, int max) { return random.nextInt(max-min+1)+min; } public static void dbg(Object... o) { System.out.println(Arrays.deepToString(o)); } public static void reverse(int[] s, int l , int r) { for(int i = l; i<=(l+r)/2; i++) { int tmp = s[i]; s[i] = s[r+l-i]; s[r+l-i] = tmp; } } public static void reverse(int[] s) { reverse(s, 0, s.length-1); } public static void reverse(long[] s, int l , int r) { for(int i = l; i<=(l+r)/2; i++) { long tmp = s[i]; s[i] = s[r+l-i]; s[r+l-i] = tmp; } } public static void reverse(long[] s) { reverse(s, 0, s.length-1); } public static void reverse(float[] s, int l , int r) { for(int i = l; i<=(l+r)/2; i++) { float tmp = s[i]; s[i] = s[r+l-i]; s[r+l-i] = tmp; } } public static void reverse(float[] s) { reverse(s, 0, s.length-1); } public static void reverse(double[] s, int l , int r) { for(int i = l; i<=(l+r)/2; i++) { double tmp = s[i]; s[i] = s[r+l-i]; s[r+l-i] = tmp; } } public static void reverse(double[] s) { reverse(s, 0, s.length-1); } public static void reverse(char[] s, int l , int r) { for(int i = l; i<=(l+r)/2; i++) { char tmp = s[i]; s[i] = s[r+l-i]; s[r+l-i] = tmp; } } public static void reverse(char[] s) { reverse(s, 0, s.length-1); } public static <T> void reverse(T[] s, int l , int r) { for(int i = l; i<=(l+r)/2; i++) { T tmp = s[i]; s[i] = s[r+l-i]; s[r+l-i] = tmp; } } public static <T> void reverse(T[] s) { reverse(s, 0, s.length-1); } public static void shuffle(int[] s) { for (int i = 0; i < s.length; ++i) { int j = random.nextInt(i + 1); int t = s[i]; s[i] = s[j]; s[j] = t; } } public static void shuffle(long[] s) { for (int i = 0; i < s.length; ++i) { int j = random.nextInt(i + 1); long t = s[i]; s[i] = s[j]; s[j] = t; } } public static void shuffle(float[] s) { for (int i = 0; i < s.length; ++i) { int j = random.nextInt(i + 1); float t = s[i]; s[i] = s[j]; s[j] = t; } } public static void shuffle(double[] s) { for (int i = 0; i < s.length; ++i) { int j = random.nextInt(i + 1); double t = s[i]; s[i] = s[j]; s[j] = t; } } public static void shuffle(char[] s) { for (int i = 0; i < s.length; ++i) { int j = random.nextInt(i + 1); char t = s[i]; s[i] = s[j]; s[j] = t; } } public static <T> void shuffle(T[] s) { for (int i = 0; i < s.length; ++i) { int j = random.nextInt(i + 1); T t = s[i]; s[i] = s[j]; s[j] = t; } } public static void sortArray(int[] a) { shuffle(a); Arrays.sort(a); } public static void sortArray(long[] a) { shuffle(a); Arrays.sort(a); } public static void sortArray(float[] a) { shuffle(a); Arrays.sort(a); } public static void sortArray(double[] a) { shuffle(a); Arrays.sort(a); } public static void sortArray(char[] a) { shuffle(a); Arrays.sort(a); } public static <T extends Comparable<T>> void sortArray(T[] a) { Arrays.sort(a); } public static int[][] rotate90(int[][] a){ int n = a.length, m = a[0].length; int[][] ans = new int[m][n]; for(int i = 0; i<n; i++) for(int j = 0; j<m; j++) ans[m-j-1][i] = a[i][j]; return ans; } public static char[][] rotate90(char[][] a){ int n = a.length, m = a[0].length; char[][] ans = new char[m][n]; for(int i = 0; i<n; i++) for(int j = 0; j<m; j++) ans[m-j-1][i] = a[i][j]; return ans; } } static class Writer { private PrintWriter pw; public Writer(){ pw = new PrintWriter(System.out); } public Writer(String f){ try { pw = new PrintWriter(new FileWriter(f)); } catch (IOException e) { e.printStackTrace(); } } public void yesNo(boolean condition) { println(condition?"YES":"NO"); } public void printArray(int[] a) { for(int i = 0; i<a.length; i++) print(a[i]+" "); } public void printlnArray(int[] a) { for(int i = 0; i<a.length; i++) print(a[i]+" "); pw.println(); } public void printArray(long[] a) { for(int i = 0; i<a.length; i++) print(a[i]+" "); } public void printlnArray(long[] a) { for(int i = 0; i<a.length; i++) print(a[i]+" "); pw.println(); } public void print(Object o) { pw.print(o.toString()); } public void println(Object o) { pw.println(o.toString()); } public void println() { pw.println(); } public void flush() { pw.flush(); } public void exit() { pw.close(); } } }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
43964ba4b01b8b2ce661985cb197bbe3
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
import java.io.*; import java.util.*; public class Main { static class Scanner { Scanner(InputStream in) { this.in = in; } InputStream in; byte[] bb = new byte[1 << 15]; int i, n; byte getc() { if (i == n) { i = n = 0; try { n = in.read(bb); } catch (IOException e) {} } return i < n ? bb[i++] : 0; } int nextInt() { byte c = 0; while (c <= ' ') c = getc(); boolean negate = false; if (c == '-') { negate = true; c = getc(); } int a = 0; while (c > ' ') { a = a * 10 + c - '0'; c = getc(); } if (negate) return -a; return a; } long nextLong() { byte c = 0; while (c <= ' ') c = getc(); long a = 0; while (c > ' ') { a = a * 10 + c - '0'; c = getc(); } return a; } } private static int populate(BufferedWriter out, Scanner in, int a, int b, int c, HashMap<HashSet<Integer> , Integer> setToDiff, boolean nowrite) throws Exception { out.write("? " + a + " " + b + " " + c + "\n"); out.flush(); int diff = in.nextInt(); if (diff == -1) { throw new Exception(); } if (!nowrite) return diff; HashSet<Integer> set = new HashSet<>(); set.add(a); set.add(b); set.add(c); setToDiff.put(set, diff); return 0; } public static void main(String[] args) throws Exception { Scanner in = new Scanner(System.in); //BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)); int T = in.nextInt(); for (int ts=1; ts<=T; ts++) { int N = in.nextInt(); HashMap<HashSet<Integer> , Integer> setToDiff = new HashMap<>(); populate(out, in, 1, 2, 3, setToDiff, true); populate(out, in, 1, 2, 4, setToDiff, true); populate(out, in, 1, 3, 4, setToDiff, true); populate(out, in, 2, 3, 4, setToDiff, true); int maxdiff = -1; for (Map.Entry<HashSet<Integer> , Integer> entry : setToDiff.entrySet()) { if (entry.getValue() > maxdiff) { maxdiff = entry.getValue(); } } Set<Integer> unordered = new HashSet<>(); for (int i=1; i<=4; i++) { unordered.add(i); } List<Integer> ordered = new ArrayList<>(); while (unordered.size() > 0) { Map<Integer, Integer> num2Counts = new HashMap<>(); int maxOccurrence = 0; Integer maxNum = 0; for (int i=1; i<=4; i++) { for (HashSet<Integer> set : setToDiff.keySet()) { for (Integer num : set) { if (unordered.contains(num) && setToDiff.get(set) == maxdiff) { num2Counts.put(num, num2Counts.getOrDefault(num, 0) + 1); if (num2Counts.get(num) > maxOccurrence) { maxOccurrence = num2Counts.get(num); maxNum = num; } } } } } ordered.add(maxNum); //out.write("adding " + maxNum + "\n"); unordered.remove(maxNum); } // Integer temp = ordered.get(2); ordered.set(2, ordered.get(1)); ordered.set(1, ordered.get(3)); /*int maxdiff = -1; HashSet<HashSet<Integer> > sets = new HashSet<>(); for (Map.Entry<HashSet<Integer> , Integer> entry : setToDiff.entrySet()) { if (entry.getValue() > maxdiff) { maxdiff = entry.getValue(); sets.clear(); sets.add(entry.getKey()); } else if (entry.getValue() == maxdiff) { if (sets.size() < 2) { sets.add(entry.getKey()); } } } List<Integer> ordered = new ArrayList<>(); int midnum = -1; for (int i=1; i<=4; i++) { int appeared = 0; for (HashSet<Integer> set : sets) { for (Integer num : set) { if (num == i) { appeared++; } } } if (appeared == 2) { ordered.add(i); } else { midnum = i; } } ordered.add(1, midnum);*/ /*out.write("ordered start\n"); for (Integer num : ordered) { out.write(num + " "); } out.write("\nordered end\n");*/ for (int i=5; i<=N; i++) { int border1 = ordered.get(0); int border2 = ordered.get(2); int middle = ordered.get(1); int b1middle = populate(out, in, border1, middle, i, setToDiff, false); int b1b2 = populate(out, in, border1, border2, i, setToDiff, false); /*HashSet<Integer> b1b2 = new HashSet<>(); b1b2.add(border1); b1b2.add(border2); b1b2.add(i);*/ if (b1b2 > maxdiff) { maxdiff = b1b2; /*HashSet<Integer> b1middle = new HashSet<>(); b1middle.add(border1); b1middle.add(middle); b1middle.add(i);*/ if (b1middle < maxdiff) { // remove border1 ordered.clear(); ordered.add(i); ordered.add(middle); ordered.add(border2); } else { // remove border2 ordered.clear(); ordered.add(i); ordered.add(middle); ordered.add(border1); } } else if (b1middle > maxdiff) { maxdiff = b1middle; ordered.clear(); ordered.add(i); ordered.add(border1); ordered.add(middle); } } out.write("! " + ordered.get(0) + " " + ordered.get(2) + "\n"); out.flush(); //System.out.flush(); //if (T == 80 && ts == 21) break; } //in.close(); out.close(); } }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
415b370b852be9162968f36eec9620a5
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
// have faith in yourself!! /* Naive mistakes in java : --> Arrays.sort(primitive) is O(n^2) --> Never use '=' to compare to Integer data types, instead use 'equals()' --> -4 % 3 = -1, actually it should be 2, so add '+n' to modulo result */ import java.io.*; import java.util.*; public class CodeForces { public static void main(String[] args) throws IOException { openIO(); int testCase = 1; testCase = sc. nextInt(); for (int i = 1; i <= testCase; i++) solve(i); closeIO(); } /*-------------------------------------------EDITING CODE STARTS HERE-------------------------------------------*/ public static void solve(int tCase) throws IOException { int n = sc.nextInt(); int a = 1, b = n; int c = 0; int mx = -1; boolean isSame = true; for(int i=2;i<n;i++){ int curr = getQuery(a,b,i); if(mx!=-1 && mx !=curr)isSame = false; if(curr > mx){ mx = curr; c = i; } } if(isSame){ if(getQuery(1,2,3)<mx || getQuery(n,n-1,n-2)<mx)c = n; } b = c; isSame = true; mx = -1; for(int i=1;i<=n;i++){ if(i==a || i==b)continue;; int curr = getQuery(a,b,i); if(mx!=-1 && mx !=curr)isSame = false; if(curr > mx){ mx = curr; c = i; } } if(isSame)c=1; a = c; System.out.println("! "+a+" "+b); System.out.flush(); } private static int getQuery(int a , int b , int c)throws IOException{ System.out.println("? "+a+" "+b+" "+c); int x = sc.nextInt(); System.out.flush(); return x; } /*-------------------------------------------EDITING CODE ENDS HERE-------------------------------------------*/ public static int mod = (int) 1e9 + 7; // public static int mod = 998244353; public static int inf_int = (int) 2e9; public static long inf_long = (long) 2e18; public static void _sort(int[] arr, boolean isAscending) { int n = arr.length; List<Integer> list = new ArrayList<>(); for (int ele : arr) list.add(ele); Collections.sort(list); if (!isAscending) Collections.reverse(list); for (int i = 0; i < n; i++) arr[i] = list.get(i); } public static void _sort(long[] arr, boolean isAscending) { int n = arr.length; List<Long> list = new ArrayList<>(); for (long ele : arr) list.add(ele); Collections.sort(list); if (!isAscending) Collections.reverse(list); for (int i = 0; i < n; i++) arr[i] = list.get(i); } // time : O(1), space : O(1) public static int _digitCount(long num,int base){ // this will give the # of digits needed for a number num in format : base return (int)(1 + Math.log(num)/Math.log(base)); } // time : O(n), space: O(n) public static long _fact(int n){ // simple factorial calculator long ans = 1; for(int i=2;i<=n;i++) ans = ans * i % mod; return ans; } // time for pre-computation of factorial and inverse-factorial table : O(nlog(mod)) public static long[] factorial , inverseFact; public static void _ncr_precompute(int n){ factorial = new long[n+1]; inverseFact = new long[n+1]; factorial[0] = inverseFact[0] = 1; for (int i = 1; i <=n; i++) { factorial[i] = (factorial[i - 1] * i) % mod; inverseFact[i] = _power(factorial[i], mod - 2); } } // time of factorial calculation after pre-computation is O(1) public static int _ncr(int n,int r){ if(r > n)return 0; return (int)(factorial[n] * inverseFact[r] % mod * inverseFact[n - r] % mod); } public static int _npr(int n,int r){ if(r > n)return 0; return (int)(factorial[n] * inverseFact[n - r] % mod); } // euclidean algorithm time O(max (loga ,logb)) public static long _gcd(long a, long b) { while (a>0){ long x = a; a = b % a; b = x; } return b; // if (a == 0) // return b; // return _gcd(b % a, a); } // lcm(a,b) * gcd(a,b) = a * b public static long _lcm(long a, long b) { return (a / _gcd(a, b)) * b; } // binary exponentiation time O(logn) public static long _power(long x, long n) { long ans = 1; while (n > 0) { if ((n & 1) == 1) { ans *= x; ans %= mod; n--; } else { x *= x; x %= mod; n >>= 1; } } return ans; } //sieve or first divisor time : O(mx * log ( log (mx) ) ) public static int[] _seive(int mx){ int[] firstDivisor = new int[mx+1]; for(int i=0;i<=mx;i++)firstDivisor[i] = i; for(int i=2;i*i<=mx;i++) if(firstDivisor[i] == i) for(int j = i*i;j<=mx;j+=i) firstDivisor[j] = i; return firstDivisor; } // check if x is a prime # of not. time : O( n ^ 1/2 ) private static boolean _isPrime(long x){ for(long i=2;i*i<=x;i++) if(x%i==0)return false; return true; } static class Pair<K, V>{ K ff; V ss; public Pair(K ff, V ss) { this.ff = ff; this.ss = ss; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; Pair<?, ?> pair = (Pair<?, ?>) o; return ff.equals(pair.ff) && ss.equals(pair.ss); } @Override public int hashCode() { return Objects.hash(ff, ss); } @Override public String toString(){ return ff.toString()+" "+ss.toString(); } } static FastestReader sc; static PrintWriter out; private static void openIO() throws IOException { sc = new FastestReader(); out = new PrintWriter(System.out); } /*-------------------------------------------FAST INPUT STARTS HERE---------------------------------------------*/ public static void closeIO() throws IOException { out.flush(); out.close(); sc.close(); } private static final class FastestReader { private static final int BUFFER_SIZE = 1 << 16; private final DataInputStream din; private final byte[] buffer; private int bufferPointer, bytesRead; public FastestReader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public FastestReader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } private static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private int skip() throws IOException { int b; //noinspection StatementWithEmptyBody while ((b = read()) != -1 && isSpaceChar(b)) { } return b; } public String next() throws IOException { int b = skip(); final StringBuilder sb = new StringBuilder(); while (!isSpaceChar(b)) { // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = read(); } return sb.toString(); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } final 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(); } final 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(); } final 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 { din.close(); } } /*---------------------------------------------FAST INPUT ENDS HERE ---------------------------------------------*/ }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
5b30c90a7dfbf8d3b09c2639ada55182
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
import java.util.*; import javax.print.DocFlavor.INPUT_STREAM; import java.io.*; import java.math.*; import java.sql.Array; import java.sql.SQLIntegrityConstraintViolationException; public class Main { private static class MyScanner { private static final int BUF_SIZE = 2048; BufferedReader br; private MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } private boolean isSpace(char c) { return c == '\n' || c == '\r' || c == ' '; } String next() { try { StringBuilder sb = new StringBuilder(); int r; while ((r = br.read()) != -1 && isSpace((char)r)); if (r == -1) { return null; } sb.append((char) r); while ((r = br.read()) != -1 && !isSpace((char)r)) { sb.append((char)r); } return sb.toString(); } catch (IOException e) { e.printStackTrace(); } return null; } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } static class Reader{ BufferedReader br; StringTokenizer st; public Reader() { 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 = (long)(1e9 + 7); static void sort(long[] arr ) { ArrayList<Long> al = new ArrayList<>(); for(long e:arr) al.add(e); Collections.sort(al); for(int i = 0 ; i<al.size(); i++) arr[i] = al.get(i); } static void sort(int[] arr ) { ArrayList<Integer> al = new ArrayList<>(); for(int e:arr) al.add(e); Collections.sort(al); for(int i = 0 ; i<al.size(); i++) arr[i] = al.get(i); } static void sort(char[] arr) { ArrayList<Character> al = new ArrayList<Character>(); for(char cc:arr) al.add(cc); Collections.sort(al); for(int i = 0 ;i<arr.length ;i++) arr[i] = al.get(i); } static long mod_mul( long... a) { long ans = a[0]%mod; for(int i = 1 ; i<a.length ; i++) { ans = (ans * (a[i]%mod))%mod; } return ans; } static long mod_sum( long... a) { long ans = 0; for(long e:a) { ans = (ans + e)%mod; } return ans; } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static void print(long[] arr) { System.out.println("---print---"); for(long e:arr) System.out.print(e+" "); System.out.println("-----------"); } static void print(int[] arr) { System.out.println("---print---"); for(long e:arr) System.out.print(e+" "); System.out.println("-----------"); } static boolean[] prime(int num) { boolean[] bool = new boolean[num]; for (int i = 0; i< bool.length; i++) { bool[i] = true; } for (int i = 2; i< Math.sqrt(num); i++) { if(bool[i] == true) { for(int j = (i*i); j<num; j = j+i) { bool[j] = false; } } } if(num >= 0) { bool[0] = false; bool[1] = false; } return bool; } static long modInverse(long a, long m) { long g = gcd(a, m); return power(a, m - 2); } static long lcm(long a , long b) { return (a*b)/gcd(a, b); } static int lcm(int a , int b) { return (int)((a*b)/gcd(a, b)); } static long power(long x, long y){ if(y<0) return 0; long m = mod; if (y == 0) return 1; long p = power(x, y / 2) % m; p = (int)((p * (long)p) % m); if (y % 2 == 0) return p; else return (int)((x * (long)p) % m); } static class Combinations{ private long[] z; // factorial private long[] z1; // inverse factorial private long[] z2; // incerse number private long mod; public Combinations(long N , long mod) { this.mod = mod; z = new long[(int)N+1]; z1 = new long[(int)N+1]; z[0] = 1; for(int i =1 ; i<=N ; i++) z[i] = (z[i-1]*i)%mod; z2 = new long[(int)N+1]; z2[0] = z2[1] = 1; for (int i = 2; i <= N; i++) z2[i] = z2[(int)(mod % i)] * (mod - mod / i) % mod; z1[0] = z1[1] = 1; for (int i = 2; i <= N; i++) z1[i] = (z2[i] * z1[i - 1]) % mod; } long fac(long n) { return z[(int)n]; } long invrsNum(long n) { return z2[(int)n]; } long invrsFac(long n) { return z1[(int)n]; } long ncr(long N, long R) { if(R<0 || R>N ) return 0; long ans = ((z[(int)N] * z1[(int)R]) % mod * z1[(int)(N - R)]) % mod; return ans; } } static class DisjointUnionSets { int[] rank, parent; int n; public DisjointUnionSets(int n) { rank = new int[n]; parent = new int[n]; this.n = n; makeSet(); } void makeSet() { for (int i = 0; i < n; i++) { parent[i] = i; } } int find(int x) { if (parent[x] != x) { parent[x] = find(parent[x]); } return parent[x]; } void union(int x, int y) { int xRoot = find(x), yRoot = find(y); if (xRoot == yRoot) return; if (rank[xRoot] < rank[yRoot]) parent[xRoot] = yRoot; else if (rank[yRoot] < rank[xRoot]) parent[yRoot] = xRoot; else { parent[yRoot] = xRoot; rank[xRoot] = rank[xRoot] + 1; } } } static int max(int... a ) { int max = a[0]; for(int e:a) max = Math.max(max, e); return max; } static long max(long... a ) { long max = a[0]; for(long e:a) max = Math.max(max, e); return max; } static int min(int... a ) { int min = a[0]; for(int e:a) min = Math.min(e, min); return min; } static long min(long... a ) { long min = a[0]; for(long e:a) min = Math.min(e, min); return min; } static int[] KMP(String str) { int n = str.length(); int[] kmp = new int[n]; for(int i = 1 ; i<n ; i++) { int j = kmp[i-1]; while(j>0 && str.charAt(i) != str.charAt(j)) { j = kmp[j-1]; } if(str.charAt(i) == str.charAt(j)) j++; kmp[i] = j; } return kmp; } /************************************************ Query **************************************************************************************/ /***************************************** Sparse Table ********************************************************/ static class SparseTable{ private long[][] st; SparseTable(long[] arr){ int n = arr.length; st = new long[n][25]; log = new int[n+2]; build_log(n+1); build(arr); } private void build(long[] arr) { int n = arr.length; for(int i = n-1 ; i>=0 ; i--) { for(int j = 0 ; j<25 ; j++) { int r = i + (1<<j)-1; if(r>=n) break; if(j == 0 ) st[i][j] = arr[i]; else st[i][j] = Math.min(st[i][j-1] , st[ i + ( 1 << (j-1) ) ][ j-1 ] ); } } } public long gcd(long a ,long b) { if(a == 0) return b; return gcd(b%a , a); } public long query(int l ,int r) { int w = r-l+1; int power = log[w]; return Math.min(st[l][power],st[r - (1<<power) + 1][power]); } private int[] log; void build_log(int n) { log[1] = 0; for(int i = 2 ; i<=n ; i++) { log[i] = 1 + log[i/2]; } } } /******************************************************** Segement Tree *****************************************************/ static class SegmentTree{ long[] tree; long[] arr; int n; SegmentTree(long[] arr){ this.n = arr.length; tree = new long[4*n+1]; this.arr = arr; buildTree(0, n-1, 1); } void buildTree(int s ,int e ,int index ) { if(s == e) { tree[index] = arr[s]; return; } int mid = (s+e)/2; buildTree( s, mid, 2*index); buildTree( mid+1, e, 2*index+1); tree[index] = gcd(tree[2*index] , tree[2*index+1]); } long query(int si ,int ei) { return query(0 ,n-1 , si ,ei , 1 ); } private long query( int ss ,int se ,int qs , int qe,int index) { if(ss>=qs && se<=qe) return tree[index]; if(qe<ss || se<qs) return (long)(0); int mid = (ss + se)/2; long left = query( ss , mid , qs ,qe , 2*index); long right= query(mid + 1 , se , qs ,qe , 2*index+1); return gcd(left, right); } public void update(int index , int val) { arr[index] = val; // for(long e:arr) System.out.print(e+" "); update(index , 0 , n-1 , 1); } private void update(int id ,int si , int ei , int index) { if(id < si || id>ei) return; if(si == ei ) { tree[index] = arr[id]; return; } if(si > ei) return; int mid = (ei + si)/2; update( id, si, mid , 2*index); update( id , mid+1, ei , 2*index+1); tree[index] = Math.min(tree[2*index] ,tree[2*index+1]); } } /* ***************************************************************************************************************************************************/ // static MyScanner sc = new MyScanner(); // only in case of less memory static Reader sc = new Reader(); static int TC; static StringBuilder sb = new StringBuilder(); public static void main(String args[]) throws IOException { int tc = 1; tc = sc.nextInt(); TC = 0; for(int i = 1 ; i<=tc ; i++) { TC++; // sb.append("Case #" + i + ": " ); // During KickStart && HackerCup TEST_CASE(); } System.out.print(sb); } static class Pair implements Comparable<Pair>{ int x; int y; Pair(int x , int y){ this.x = x; this.y = y; } @Override public int compareTo(Main.Pair o) { if(this.x != o.x) return Integer.compare(this.x , o.x); else return Integer.compare(this.y, o.y); } } static void TEST_CASE() { int n = sc.nextInt(); int[] ans = fnc(1, 2, 3, 4); if(n == 4) { System.out.println("! "+ans[0]+" "+ans[1]); System.out.flush(); return; } for(int i = 5 ; i+1<=n ; i+=2) { ans = fnc(ans[0] , ans[1] , i , i+1); } if(n%2 == 1) { int ind = -1; for(int i = 1 ; i<n ; i++) { if(ans[0] != i && ans[1] != i) { ind = i; break; } } ans = fnc(ans[0] , ans[1] , ind,n); } System.out.println("! "+ans[0]+" "+ans[1]); System.out.flush(); } static int[] fnc(int i , int j , int k ,int l) { int[] ans = new int[3]; int d1 = query(i, j, k); int d2 = query(i, j, l); int d3 = query(i ,k, l); int d4 = query(j ,k, l); int max = max(d1 , d2 , d3 , d4); if(max == d1 && max == d2) { ans[0] = i; ans[1] = j; }else if(max == d1 && max == d3) { ans[0] = i; ans[1] = k; }else if(max == d1 && max == d4) { ans[0] = j; ans[1] = k; }else if(max == d2 && max == d3 ) { ans[0] = i; ans[1] = l; }else if(max == d2 && max == d4) { ans[0] = j; ans[1] = l; }else if(max == d3 && max == d4) { ans[0] = k; ans[1] = l; } ans[2] = max; return ans; } static int query(int i ,int j , int k) { System.out.println("? "+i+" "+j+" "+k); System.out.flush(); return sc.nextInt(); } } /*******************************************************************************************************************************************************/ /** */
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
e265bff514c0223f8481f9f01cd7b1b0
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
import java.io.*; import java.util.*; public class D { public static void main(String[] args) { while (N-- > 0) { solve(); } out.close(); } public static void solve() { int M = sc.nextInt(); int max = 0; int potential0 = 0; int potentialMax = 0; for (int i = 3; i <= M; i++) { out.println("? 1 2 " + i); out.flush(); int tmp = sc.nextInt(); if (tmp > max) { max = tmp; potential0 = i; } } max = 0; for (int i = 2; i <= M; i++) { if (i == potential0) { continue; } else { out.println("? 1 " + potential0 + " " + i); out.flush(); int tmp = sc.nextInt(); if (tmp > max) { max = tmp; potentialMax = i; } } } int notRelated = 2; int tmp; while (notRelated == potential0 || notRelated == potentialMax) { notRelated++; } out.println("? " + potential0 + " " + potentialMax + " " + notRelated); out.flush(); tmp = sc.nextInt(); if (tmp == max) { out.println("! " + potential0 + " " + potentialMax); out.flush(); return; } out.println("? 1 " + potentialMax + " " + notRelated); out.flush(); tmp = sc.nextInt(); if (tmp == max) { out.println("! " + 1 + " " + potentialMax); out.flush(); return; } out.println("! " + 1 + " " + potential0); out.flush(); } private static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); private static MyScanner sc = new MyScanner(); private static int N = sc.nextInt(); private final static int MOD = 1000000007; @SuppressWarnings("unused") private 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()); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
28668fa08f7241733fec9562691f8406
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
import java.io.*; import java.util.*; public class cp { static int mod=(int)1e9+7; // static Reader sc=new Reader(); static FastReader sc=new FastReader(System.in); static int[] sp; static int size=(int)1e6; static int[] arInt; static long[] arLong; public static void main(String[] args) throws IOException { long tc=sc.nextLong(); // Scanner sc=new Scanner(System.in); // int tc=1; // print_int(pre); // primeSet=new HashSet<>(); // primeCnt=new int[(int)1e9]; // sieveOfEratosthenes((int)1e9); while(tc-->0) { int n=sc.nextInt(); int a=2,b=3; int x=query(1, 2, 3); int y=query(1, n-1, n); if(y<x) { a=n-1; b=n; } int c=-1; int max=int_min; for(int i=1;i<=n;i++) { if(i==a || i==b) continue; int val=query(a, b, i); if(val>max) { max=val; c=i; } } int cnt=0,cnt2=0; for(int i=1;i<=n;i++) { if(i==a || i==c) continue; cnt2++; int val=query(a, c, i); if(val>max) { cnt=0; max=val; b=i; } if (val==max) { // b=i; cnt++; } } if (cnt==cnt2) { System.out.println("! "+a+" "+c); } else { System.out.println("! "+b+" "+c); } } System.out.flush(); // out.flush(); // out.close(); // System.gc(); } /* ...SOLUTION ENDS HERE...........SOLUTION ENDS HERE... */ static int query(int a,int b,int c) throws IOException { int ans=0; System.out.println("?"+" "+a+" "+b+" "+c); ans=sc.nextInt(); System.out.flush(); return ans; } static void mapping(int a[]) { Pair[] temp=new Pair[a.length]; for (int i = 0; i < temp.length; i++) { temp[i]=new Pair(a[i], i); } Arrays.sort(temp); int k=0; for (int i = 0; i < temp.length; i++) { a[temp[i].y]=k++; } } static boolean palin(String s) { for(int i=0;i<s.length()/2;i++) if(s.charAt(i)!=s.charAt(s.length()-i-1)) return false; return true; } static class temp implements Comparable<temp>{ int x; int y; int sec; public temp(int x,int y,int l) { // TODO Auto-generated constructor stub this.x=x; this.y=y; this.sec=l; } @Override public int compareTo(cp.temp o) { // TODO Auto-generated method stub return this.sec-o.sec; } } static class Node{ int x; int y; ArrayList<Integer> edges; public Node(int x,int y) { // TODO Auto-generated constructor stub this.x=x; this.y=y; this.edges=new ArrayList<>(); } } static int lis(int arr[],int n) { int ans=0; int dp[]=new int[n+1]; Arrays.fill(dp, int_max); dp[0]=int_min; for(int i=0;i<n;i++) { int j=UpperBound(dp,arr[i]); if(dp[j-1]<=arr[i] && arr[i]<dp[j]) dp[j]=arr[i]; } for(int i=0;i<=n;i++) { if(dp[i]<int_max) ans=i; } return ans; } static long get(long n) { return n*(n+1)/2L; } static boolean go(ArrayList<Pair> caves,int k) { for(Pair each:caves) { if(k<=each.x) return false; k+=each.y; } return true; } static String revString(String s) { char arr[]=s.toCharArray(); int n=s.length(); for(int i=0;i<n/2;i++) { char temp=arr[i]; arr[i]=arr[n-i-1]; arr[n-i-1]=temp; } return String.valueOf(arr); } static void dfs(Graph gp,boolean[] vis,int node,int[] dp) { vis[node]=true; dp[node]=0; for(Integer child:gp.list[node]) { if(!vis[child]) { dfs(gp, vis, child, dp); } dp[node]=Math.max(dp[node], 1+dp[child]); } } // Fuction return the number of set bits in n static int SetBits(int n) { int cnt=0; while(n>0) { if((n&1)==1) { cnt++; } n=n>>1; } return cnt; } static boolean isPowerOfTwo(int n) { return (int)(Math.ceil((Math.log(n) / Math.log(2)))) == (int)(Math.floor(((Math.log(n) / Math.log(2))))); } static void arrInt(int n) throws IOException { arInt=new int[n]; for (int i = 0; i < arInt.length; i++) { arInt[i]=sc.nextInt(); } } static void arrLong(int n) throws IOException { arLong=new long[n]; for (int i = 0; i < arLong.length; i++) { arLong[i]=sc.nextLong(); } } static ArrayList<Integer> add(int id,int c) { ArrayList<Integer> newArr=new ArrayList<>(); for(int i=0;i<id;i++) newArr.add(arInt[i]); newArr.add(c); for(int i=id;i<arInt.length;i++) { newArr.add(arInt[i]); } return newArr; } // function to find first index >= y static int upper(ArrayList<Integer> arr, int n, int x) { int l = 0, h = n - 1; while (h-l>1) { int mid = (l + h) / 2; if (arr.get(mid) <= x) l=mid+1; else { h=mid; } } if(arr.get(l)>x) { return l; } if(arr.get(h)>x) return h; return -1; } static int upper(ArrayList<Long> arr, int n, long x) { int l = 0, h = n - 1; while (h-l>1) { int mid = (l + h) / 2; if (arr.get(mid) <= x) l=mid+1; else { h=mid; } } if(arr.get(l)>x) { return l; } if(arr.get(h)>x) return h; return -1; } static int lower(ArrayList<Integer> arr, int n, int x) { int l = 0, h = n - 1; while (h-l>1) { int mid = (l + h) / 2; if (arr.get(mid) < x) l=mid+1; else { h=mid; } } if(arr.get(l)>=x) { return l; } if(arr.get(h)>=x) return h; return -1; } static int N = 501; // Array to store inverse of 1 to N static long[] factorialNumInverse = new long[N + 1]; // Array to precompute inverse of 1! to N! static long[] naturalNumInverse = new long[N + 1]; // Array to store factorial of first N numbers static long[] fact = new long[N + 1]; // Function to precompute inverse of numbers public static void InverseofNumber(int p) { naturalNumInverse[0] = naturalNumInverse[1] = 1; for(int i = 2; i <= N; i++) naturalNumInverse[i] = naturalNumInverse[p % i] * (long)(p - p / i) % p; } // Function to precompute inverse of factorials public static void InverseofFactorial(int p) { factorialNumInverse[0] = factorialNumInverse[1] = 1; // Precompute inverse of natural numbers for(int i = 2; i <= N; i++) factorialNumInverse[i] = (naturalNumInverse[i] * factorialNumInverse[i - 1]) % p; } // Function to calculate factorial of 1 to N public static void factorial(int p) { fact[0] = 1; // Precompute factorials for(int i = 1; i <= N; i++) { fact[i] = (fact[i - 1] * (long)i) % p; } } // Function to return nCr % p in O(1) time public static long Binomial(int N, int R, int p) { // n C r = n!*inverse(r!)*inverse((n-r)!) long ans = ((fact[N] * factorialNumInverse[R]) % p * factorialNumInverse[N - R]) % p; return ans; } static String tr(String s) { int now = 0; while (now + 1 < s.length() && s.charAt(now)== '0') ++now; return s.substring(now); } static ArrayList<Integer> ans; static void dfs(int node,Graph gg,int cnt,int k,ArrayList<Integer> temp) { if(cnt==k) return; for(Integer each:gg.list[node]) { if(each==0) { temp.add(each); ans=new ArrayList<>(temp); temp.remove(temp.size()-1); continue; } temp.add(each); dfs(each,gg,cnt+1,k,temp); temp.remove(temp.size()-1); } return; } static boolean isPrime(long n) { // Corner cases if (n <= 1) return false; if (n <= 3) return true; // This is checked so that we can skip // middle five numbers in below loop if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static ArrayList<Integer> commDiv(int a, int b) { // find gcd of a, b int n = gcd(a, b); // Count divisors of n. ArrayList<Integer> Div=new ArrayList<>(); for (int i = 1; i <= Math.sqrt(n); i++) { // if 'i' is factor of n if (n % i == 0) { // check if divisors are equal if (n / i == i) Div.add(i); else { Div.add(i); Div.add(n/i); } } } return Div; } static HashSet<Integer> factors(int x) { HashSet<Integer> a=new HashSet<Integer>(); for(int i=2;i*i<=x;i++) { if(x%i==0) { a.add(i); a.add(x/i); } } return a; } static void primeFactors(int n,HashSet<Integer> factors) { // Print the number of 2s that divide n while (n%2==0) { factors.add(2); n /= 2; } // n must be odd at this point. So we can // skip one element (Note i = i +2) for (int i = 3; i <= Math.sqrt(n); i+= 2) { // While i divides n, print i and divide n while (n%i == 0) { factors.add(i); n /= i; } } // This condition is to handle the case when // n is a prime number greater than 2 if (n > 2) factors.add(n); } // static class Node // { // int vertex; // HashSet<Node> adj; // int deg; // Node(int ver) // { // vertex=ver; // deg=0; // adj=new HashSet<Node>(); // } // @Override // public String toString() // { // return vertex+" "; // } // } static class Tuple{ int a; int b; int c; public Tuple(int a,int b,int c) { this.a=a; this.b=b; this.c=c; } } //function to find prime factors of n static HashMap<Long,Long> findFactors(long n2) { HashMap<Long,Long> ans=new HashMap<>(); if(n2%2==0) { ans.put(2L, 0L); // cnt++; while((n2&1)==0) { n2=n2>>1; ans.put(2L, ans.get(2L)+1); // } } for(long i=3;i*i<=n2;i+=2) { if(n2%i==0) { ans.put((long)i, 0L); // cnt++; while(n2%i==0) { n2=n2/i; ans.put((long)i, ans.get((long)i)+1); } } } if(n2!=1) { ans.put(n2, ans.getOrDefault(n2, (long) 0)+1); } return ans; } //fenwick tree implementaion static class fwt { int n; long BITree[]; fwt(int n) { this.n=n; BITree=new long[n+1]; } fwt(int arr[], int n) { this.n=n; BITree=new long[n+1]; for(int i = 0; i < n; i++) updateBIT(n, i, arr[i]); } long getSum(int index) { long sum = 0; index = index + 1; while(index>0) { sum += BITree[index]; index -= index & (-index); } return sum; } void updateBIT(int n, int index,int val) { index = index + 1; while(index <= n) { BITree[index] += val; index += index & (-index); } } long sum(int l, int r) { return getSum(r) - getSum(l - 1); } void print() { for(int i=0;i<n;i++) out.print(getSum(i)+" "); out.println(); } } static class sparseTable{ int n; long[][]dp; int log2[]; int P; void buildTable(long[] arr) { n=arr.length; P=(int)Math.floor(Math.log(n)/Math.log(2)); log2=new int[n+1]; log2[0]=log2[1]=0; for(int i=2;i<=n;i++) { log2[i]=log2[i/2]+1; } dp=new long[P+1][n]; for(int i=0;i<n;i++) { dp[0][i]=arr[i]; } for(int p=1;p<=P;p++) { for(int i=0;i+(1<<p)<=n;i++) { long left=dp[p-1][i]; long right=dp[p-1][i+(1<<(p-1))]; dp[p][i]=gcd(left, right); } } } long maxQuery(int l,int r) { int len=r-l+1; int p=(int)Math.floor(log2[len]); long left=dp[p][l]; long right=dp[p][r-(1<<p)+1]; return gcd(left, right); } } //Function to find number of set bits static int setBitNumber(long n) { if (n == 0) return 0; int msb = 0; n = n / 2; while (n != 0) { n = n / 2; msb++; } return msb; } static int getFirstSetBitPos(long n) { return (int)((Math.log10(n & -n)) / Math.log10(2)) + 1; } static ArrayList<Integer> primes; static HashSet<Integer> primeSet; static boolean prime[]; static int primeCnt[]; static void sieveOfEratosthenes(int n) { prime= new boolean[n + 1]; for (int i = 2; i <= n; i++) prime[i] = true; for (int p = 2; p * p <= n; p++) { // If prime[p] is not changed, then it is a // prime if (prime[p] == true) { // Update all multiples of p for (int i = p * p; i <= n; i += p) prime[i] = false; } } // Print all prime numbers for (int i = 2; i <= n; i++) { if (prime[i] == true) primeCnt[i]=primeCnt[i-1]+1; } } static long mod(long a, long b) { long c = a % b; return (c < 0) ? c + b : c; } static void swap(long arr[],int i,int j) { long temp=arr[i]; arr[i]=arr[j]; arr[j]=temp; } static boolean util(int a,int b,int c) { if(b>a)util(b, a, c); while(c>=a) { c-=a; if(c%b==0) return true; } return (c%b==0); } static void flag(boolean flag) { out.println(flag ? "YES" : "NO"); out.flush(); } static void print(int a[]) { int n=a.length; for(int i=0;i<n;i++) { out.print(a[i]+" "); } out.println(); out.flush(); } static void print(long a[]) { int n=a.length; for(int i=0;i<n;i++) { out.print(a[i]+" "); } out.println(); out.flush(); } static void print_int(ArrayList<Integer> al) { int si=al.size(); for(int i=0;i<si;i++) { out.print(al.get(i)+" "); } out.println(); out.flush(); } static void print_long(ArrayList<Long> al) { int si=al.size(); for(int i=0;i<si;i++) { out.print(al.get(i)+" "); } out.println(); out.flush(); } static void printYesNo(boolean condition) { if (condition) { out.println("YES"); } else { out.println("NO"); } } static int LowerBound(int a[], int x) { // x is the target value or key int l=-1,r=a.length; while(l+1<r) { int m=(l+r)>>>1; if(a[m]>=x) r=m; else l=m; } return r; } static int lowerIndex(int arr[], int n, int x) { int l = 0, h = n - 1; while (l<=h) { int mid = (l + h) / 2; if (arr[mid] >= x) h = mid -1 ; else l = mid + 1; } return l; } // function to find last index <= y static int upperIndex(int arr[], int n, int y) { int l = 0, h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr[mid] <= y) l = mid + 1; else h = mid - 1; } return h; } static int upperIndex(long arr[], int n, long y) { int l = 0, h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr[mid] <= y) l = mid + 1; else h = mid - 1; } return h; } static int UpperBound(int a[], int x) {// x is the key or target value int l=-1,r=a.length; while(l+1<r) { int m=(l+r)>>>1; if(a[m]<=x) l=m; else r=m; } return l+1; } static int UpperBound(long a[], long x) {// x is the key or target value int l=-1,r=a.length; while(l+1<r) { int m=(l+r)>>>1; if(a[m]<=x) l=m; else r=m; } return l+1; } static class DisjointUnionSets { int[] rank, parent; int n; // Constructor public DisjointUnionSets(int n) { rank = new int[n]; parent = new int[n]; this.n = n; makeSet(); } // Creates n sets with single item in each void makeSet() { for (int i = 0; i < n; i++) parent[i] = i; } int find(int x) { if (parent[x] != x) { parent[x] = find(parent[x]); } return parent[x]; } // Unites the set that includes x and the set // that includes x void union(int x, int y) { int xRoot = find(x), yRoot = find(y); if (xRoot == yRoot) return; if (rank[xRoot] < rank[yRoot]) parent[xRoot] = yRoot; else if (rank[yRoot] < rank[xRoot]) parent[yRoot] = xRoot; else // if ranks are the same { parent[yRoot] = xRoot; rank[xRoot] = rank[xRoot] + 1; } // if(xRoot!=yRoot) // parent[y]=x; } int connectedComponents() { int cnt=0; for(int i=0;i<n;i++) { if(parent[i]==i) cnt++; } return cnt; } } static class Graph { int v; ArrayList<Integer> list[]; Graph(int v) { this.v=v; list=new ArrayList[v+1]; for(int i=1;i<=v;i++) list[i]=new ArrayList<Integer>(); } void addEdge(int a, int b) { this.list[a].add(b); } } // static class GraphMap{ // Map<String,ArrayList<String>> graph; // GraphMap() { // // TODO Auto-generated constructor stub // graph=new HashMap<String,ArrayList<String>>(); // // } // void addEdge(String a,String b) // { // if(graph.containsKey(a)) // this.graph.get(a).add(b); // else { // this.graph.put(a, new ArrayList<>()); // this.graph.get(a).add(b); // } // } // } // static void dfsMap(GraphMap g,HashSet<String> vis,String src,int ok) // { // vis.add(src); // // if(g.graph.get(src)!=null) // { // for(String each:g.graph.get(src)) // { // if(!vis.contains(each)) // { // dfsMap(g, vis, each, ok+1); // } // } // } // // cnt=Math.max(cnt, ok); // } static double sum[]; static long cnt; // static void DFS(Graph g, boolean[] visited, int u) // { // visited[u]=true; // // for(int i=0;i<g.list[u].size();i++) // { // int v=g.list[u].get(i); // // if(!visited[v]) // { // cnt1=cnt1*2; // DFS(g, visited, v); // // } // // } // // // } static class Pair implements Comparable<Pair> { int x; int y; Pair(int x,int y) { this.x=x; this.y=y; } @Override public int compareTo(Pair o) { // TODO Auto-generated method stub return this.x-o.x; } } static long sum_array(int a[]) { int n=a.length; long sum=0; for(int i=0;i<n;i++) sum+=a[i]; return sum; } static long sum_array(long a[]) { int n=a.length; long sum=0; for(int i=0;i<n;i++) sum+=a[i]; return sum; } static void sort(int[] a) { ArrayList<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static void sort(long[] a) { ArrayList<Long> l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static void reverse_array(int a[]) { int n=a.length; int i,t; for (i = 0; i < n / 2; i++) { t = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = t; } } static void reverse_array(long a[]) { int n=a.length; int i; long t; for (i = 0; i < n / 2; i++) { t = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = t; } } // static long modInverse(long a, long m) // { // long g = gcd(a, m); // // return power(a, m - 2, m); // // } static long power(long x, long y) { long res = 1; x = x % mod; if (x == 0) return 0; while (y > 0) { if ((y & 1) != 0) res = (res * x) % mod; y = y >> 1; // y = y/2 x = (x * x) % mod; } return res; } static int power(int x, int y) { int res = 1; x = x % mod; if (x == 0) return 0; while (y > 0) { if ((y & 1) != 0) res = (res * x) % mod; y = y >> 1; // y = y/2 x = (x * x) % mod; } return res; } static long gcd(long a, long b) { if (a == 0) return b; //cnt+=a/b; return gcd(b%a,a); } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b%a, a); } static 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; } long nextLong() throws IOException { 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; } } 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(); } } static PrintWriter out=new PrintWriter(System.out); static int int_max=Integer.MAX_VALUE; static int int_min=Integer.MIN_VALUE; static long long_max=Long.MAX_VALUE; static long long_min=Long.MIN_VALUE; }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
d029a09dc506d3284435c02f3a6ed940
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.io.Writer; import java.io.OutputStreamWriter; import java.io.BufferedReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); DFindingZero solver = new DFindingZero(); int testCount = Integer.parseInt(in.next()); for (int i = 1; i <= testCount; i++) solver.solve(i, in, out); out.close(); } static class DFindingZero { public void solve(int testNumber, InputReader in, OutputWriter out) { int n = in.nextInt(); int id = -1, val = -1; boolean flag = false; for (int i = 2; i < n; i++) { int v = q(1, n, i, in); if (val != -1 && v != val) { flag = true; } if (v > val) { val = v; id = i; } } // if(!flag){ // System.out.println("! "+"1 "+n); // return; // } int v1 = val; int last = -1; int id1 = -1; for (int i = 1; i < n; i++) { int v; if (i + 1 == id) { v = q(i, id, i + 2, in); } else { v = q(i, id, i + 1, in); } if (v == val && last == v) { id1 = i; } if (i + 1 == id) i++; last = v; if (v > val) val = v; } if (val == v1 && !flag) { System.out.println("! 1 " + n); return; } if (id1 != -1) { System.out.println("! " + id + " " + id1); } else { int other = -1; for (int i = 2; i < n; i++) { if (i != id) { other = i; break; } } if (q(1, other, id, in) > q(n, other, id, in)) { System.out.println("! " + "1 " + id); } else { System.out.println("! " + n + " " + id); } } } int q(int i, int j, int k, InputReader in) { System.out.println("? " + i + " " + j + " " + k); return in.nextInt(); } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void close() { writer.close(); } } static class InputReader { BufferedReader reader; 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()); } } }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
d18567768ac17cfb2a9f0a40b6082182
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
import java.io.*; import java.util.*; public class FindZero { //io static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static PrintWriter out = new PrintWriter(System.out); public static void main(String[] args) throws IOException { //parse input int T = Integer.parseInt(br.readLine()); for (int i=0;i<T;i++) solve(); } public static void solve() throws IOException { //setup int N = Integer.parseInt(br.readLine()); ArrayList<Integer> queue = new ArrayList<>(); for (int i=1;i<=N;i++) queue.add(i); while (queue.size()>2){ int[] safe = handleQuaternion(new int[]{queue.remove(0),queue.remove(0),queue.remove(0),queue.remove(0)}); queue.add(safe[0]); queue.add(safe[1]); //dummy add so that queue will be even sized (happens only once) if (queue.size()%2==1) queue.add(safe[2]); } System.out.println("! "+queue.get(0)+" "+queue.get(1)); } public static int[] handleQuaternion(int[] quart) throws IOException { Pair[] res = new Pair[4]; for (int i=0;i<4;i++){ res[i] = new Pair(i, response(quart, i)); } Arrays.sort(res,(a,b)->a.value-b.value); return new int[]{quart[res[0].index],quart[res[1].index],quart[res[2].index]}; } public static int response(int[] quart, int spec) throws IOException { StringBuilder query = new StringBuilder(); query.append("? "); for (int i=0;i<4;i++){ if (i!=spec) query.append(quart[i]+" "); } System.out.println(query); return Integer.parseInt(br.readLine()); } private static class Pair { int index; int value; public Pair(int i, int v){ index=i; value=v; } } }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
0d284c89f5c0457a394a2f3687e86c3a
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
/** * @Author: Luminous! * @Date: 2022/02/06/23:45 * @Description: CF1634D */ import java.io.*; import java.math.*; import java.util.*; public class CF1634D { static final int INF = 0x3f3f3f3f; static final long LNF = 0x3f3f3f3f3f3f3f3fL; public static void main(String[] args) throws IOException { initReader(); int T = nextInt(); for (int i = 1; i <= T; i++) solve(); pw.flush(); } /***************************************************************************************/ public static void solve() throws IOException { int n = nextInt(); int[] arr = new int[n + 1]; Arrays.fill(arr, -1); for (int i = 3; i <= n; i++) { arr[i] = query(1, 2, i); } if (check(arr) && query(2, 3, 4) < arr[3]) { print(1, 2); return; } int inx = getMaxIndex(arr, 3, n); for (int i = 2; i <= n; i++) { if (i == inx) { arr[i] = -1; continue; } arr[i] = query(1, i, inx); } if (check(arr)) { print(1, inx); return; } print(getMaxIndex(arr, 2, n), inx); } public static int query(int i, int j, int k) throws IOException{ pw.println("? " + i + " " + j + " " + k); pw.flush(); return nextInt(); } public static void print(int i, int j) { pw.println("! " + i + " " + j); pw.flush(); return; } public static boolean check(int[] arr) { HashSet<Integer> set = new HashSet<>(); for (int i = 1; i < arr.length; i++) { if (arr[i] != -1) { set.add(arr[i]); } } return set.size() == 1; } public static int getMaxIndex(int[] arr, int l, int r) { int inx = l; for (int i = l; i <= r; i++) { if (arr[i] > arr[inx]) { inx = i; } } return inx; } /***************************************************************************************/ /***************************************************************************************/ static BufferedReader reader; static StringTokenizer tokenizer; static PrintWriter pw; public static void initReader() throws IOException { reader = new BufferedReader(new InputStreamReader(System.in)); tokenizer = new StringTokenizer(""); pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); // 从文件读写 // reader = new BufferedReader(new FileReader("test.in")); // tokenizer = new StringTokenizer(""); // pw = new PrintWriter(new BufferedWriter(new FileWriter("test1.out"))); } public static boolean hasNext() { try { while (!tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } } catch (Exception e) { return false; } return true; } public static String next() throws IOException { while (!tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } return tokenizer.nextToken(); } public static String nextLine() { try { return reader.readLine(); } catch (Exception e) { return null; } } public static int nextInt() throws IOException { return Integer.parseInt(next()); } public static long nextLong() throws IOException { return Long.parseLong(next()); } public static double nextDouble() throws IOException { return Double.parseDouble(next()); } public static char nextChar() throws IOException { return next().charAt(0); } }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
617e34f3e0fdcbfa8b6a1d2654f4629d
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
/** * @Author: Luminous! * @Date: 2022/02/06/23:45 * @Description: CF1634D */ import java.io.*; import java.math.*; import java.util.*; public class CF1634D { static final int INF = 0x3f3f3f3f; static final long LNF = 0x3f3f3f3f3f3f3f3fL; public static void main(String[] args) throws IOException { initReader(); int T = nextInt(); for (int i = 1; i <= T; i++) solve(); pw.flush(); } /***************************************************************************************/ public static void solve() throws IOException { int n = nextInt(); int[] arr = new int[n + 1]; Arrays.fill(arr, -1); for (int i = 3; i <= n; i++) { arr[i] = query(1, 2, i); } if (check(arr) && query(2, 3, 4) < arr[3]) { print(1, 2); return; } int inx = getMaxIndex(arr, 3, n); for (int i = 2; i <= n; i++) { if (i == inx) { arr[i] = -1; continue; } arr[i] = query(1, i, inx); } if (check(arr)) { print(1, inx); return; } print(getMaxIndex(arr, 2, n), inx); pw.flush(); } public static int query(int i, int j, int k) throws IOException{ pw.println("? " + i + " " + j + " " + k); pw.flush(); return nextInt(); } public static void print(int i, int j) { pw.println("! " + i + " " + j); pw.flush(); return; } public static boolean check(int[] arr) { HashSet<Integer> set = new HashSet<>(); for (int i = 1; i < arr.length; i++) { if (arr[i] != -1) { set.add(arr[i]); } } return set.size() == 1; } public static int getMaxIndex(int[] arr, int l, int r) { int inx = l; for (int i = l; i <= r; i++) { if (arr[i] > arr[inx]) { inx = i; } } return inx; } /***************************************************************************************/ /***************************************************************************************/ static BufferedReader reader; static StringTokenizer tokenizer; static PrintWriter pw; public static void initReader() throws IOException { reader = new BufferedReader(new InputStreamReader(System.in)); tokenizer = new StringTokenizer(""); pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); // 从文件读写 // reader = new BufferedReader(new FileReader("test.in")); // tokenizer = new StringTokenizer(""); // pw = new PrintWriter(new BufferedWriter(new FileWriter("test1.out"))); } public static boolean hasNext() { try { while (!tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } } catch (Exception e) { return false; } return true; } public static String next() throws IOException { while (!tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } return tokenizer.nextToken(); } public static String nextLine() { try { return reader.readLine(); } catch (Exception e) { return null; } } public static int nextInt() throws IOException { return Integer.parseInt(next()); } public static long nextLong() throws IOException { return Long.parseLong(next()); } public static double nextDouble() throws IOException { return Double.parseDouble(next()); } public static char nextChar() throws IOException { return next().charAt(0); } }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
78567e43ddf43041dbd0a2f79646ddfe
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
/** * @Author: Luminous! * @Date: 2022/02/06/23:45 * @Description: CF1634D */ import java.io.*; import java.math.*; import java.util.*; public class CF1634D { static final int INF = 0x3f3f3f3f; static final long LNF = 0x3f3f3f3f3f3f3f3fL; public static void main(String[] args) throws IOException { initReader(); int T = nextInt(); for (int i = 1; i <= T; i++) solve(); pw.flush(); } /***************************************************************************************/ public static void solve() throws IOException { int n = nextInt(); int[] arr = new int[n + 1]; Arrays.fill(arr, -1); for (int i = 3; i <= n; i++) { arr[i] = query(1, 2, i); } if (check(arr) && query(2, 3, 4) < arr[3]) { pw.println("! " + 1 + " " + 2); pw.flush(); return; } int inx = getMaxIndex(arr, 3, n); for (int i = 2; i <= n; i++) { if (i == inx) { arr[i] = -1; continue; } arr[i] = query(1, i, inx); } if (check(arr)) { pw.println("! " + 1 + " " + inx); pw.flush(); return; } pw.println("! " + getMaxIndex(arr, 2, n) + " " + inx); pw.flush(); } public static int query(int i, int j, int k) throws IOException{ pw.println("? " + i + " " + j + " " + k); pw.flush(); return nextInt(); } public static boolean check(int[] arr) { HashSet<Integer> set = new HashSet<>(); for (int i = 1; i < arr.length; i++) { if (arr[i] != -1) { set.add(arr[i]); } } return set.size() == 1; } public static int getMaxIndex(int[] arr, int l, int r) { int inx = l; for (int i = l; i <= r; i++) { if (arr[i] > arr[inx]) { inx = i; } } return inx; } /***************************************************************************************/ /***************************************************************************************/ static BufferedReader reader; static StringTokenizer tokenizer; static PrintWriter pw; public static void initReader() throws IOException { reader = new BufferedReader(new InputStreamReader(System.in)); tokenizer = new StringTokenizer(""); pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); // 从文件读写 // reader = new BufferedReader(new FileReader("test.in")); // tokenizer = new StringTokenizer(""); // pw = new PrintWriter(new BufferedWriter(new FileWriter("test1.out"))); } public static boolean hasNext() { try { while (!tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } } catch (Exception e) { return false; } return true; } public static String next() throws IOException { while (!tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } return tokenizer.nextToken(); } public static String nextLine() { try { return reader.readLine(); } catch (Exception e) { return null; } } public static int nextInt() throws IOException { return Integer.parseInt(next()); } public static long nextLong() throws IOException { return Long.parseLong(next()); } public static double nextDouble() throws IOException { return Double.parseDouble(next()); } public static char nextChar() throws IOException { return next().charAt(0); } }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
39414a954b3e811d8fcd79802c448db3
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class D { public static FastScanner s = new FastScanner(); public static PrintWriter out = new PrintWriter(System.out); public static void main(String[] args) { int lines = s.nextInt(); for (int i = 0; i < lines; i += 1) { solve(s.nextInt()); } out.close(); } public static void solve(int n) { int a, b; a = 1; b = 2; int q[]; int val[]; int max; int occ[]; for (int i = 3; i <= n; i += 2) { q = new int[]{a, b, i, i == n ? (a != 1 && b != 1 ? 1 : (a != 2 && b != 2 ? 2 : 3)) : i + 1}; val = new int[4]; max = 0; for (int j = 0; j < 4; j++) { out.println("? " + (j != 0 ? q[0] : "") + " " + (j != 1 ? q[1] : "") + " " + (j != 2 ? q[2] : "") + " " + (j != 3 ? q[3] : "")); out.flush(); val[j] = s.nextInt(); max = Math.max(max, val[j]); } occ = new int[4]; for (int j = 0; j < 4; j++) if (val[j] == max) for (int k = 0; k < 4; k++) if (k != j) occ[k]++; max = 0; for (int j = 0; j < 4; j++) max = Math.max(max, occ[j]); a = -1; b = -1; for (int j = 0; j < 4; j++) { if (occ[j] == max) if (a == -1) { a = q[j]; } else { b = q[j]; break; } } if (b != -1) continue; for (int j = 0; j < 4; j++) { if (occ[j] == 2) if (a == -1) { a = q[j]; } else { b = q[j]; break; } } } out.println("! " + a + " " + b); out.flush(); } static class FastScanner {//copied from secondthread 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()); } } }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
22e2ac3ed3fe67c7ba2a9fdec64d359c
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
import java.io.*; import java.util.*; //# Solution public class new1{ static FastReader s = new FastReader(); static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } public static int ask(int a, int b, int c) { System.out.println("? " + a + " " + b + " " + c); System.out.flush(); return s.nextInt(); } public static int[] getMax(int[] arr, int n) { int[] arr1 = new int[4]; arr1[0] = ask(arr[1], arr[2], arr[3]); arr1[1] = ask(arr[0], arr[2], arr[3]); arr1[2] = ask(arr[0], arr[1], arr[3]); arr1[3] = ask(arr[0], arr[1], arr[2]); //System.out.println(Arrays.toString(arr1)); int[] arr2 = new int[4]; int count = 0; for(int i = 0; i <= 3; i++) { for(int j = 0; j <= 3; j++) { if(i != j) { if(count == 0 && arr1[i] == arr1[j] && arr1[i] == Math.max(Math.max(arr1[0], arr1[1]), Math.max(arr1[2], arr1[3]))) { arr2[i] = 1; arr2[j] = 1; count = count + 2; } } } } int[] ans = new int[2]; int ind = 0; for(int i = 0; i < 4; i++) { if(arr2[i] == 0) { ans[ind] = arr[i]; ind++; } } return ans; } public static void main(String[] args) throws IOException{ BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out)); int t = s.nextInt(); for(int z = 0; z < t; z++) { int n = s.nextInt(); int[] arr1 = new int[4]; arr1[0] = 1; arr1[1] = 2; int i = 3; int rem = -1; while(i <= n) { arr1[2] = i; i++; if(i == n + 1) { arr1[3] = rem; } else arr1[3] = i; i++; int[] arr2 = getMax(arr1, n); if(arr1[0] != arr2[0] && arr1[0] != arr2[1]) rem = arr1[0]; else if(arr1[1] != arr2[0] && arr1[1] != arr2[1]) rem = arr1[1]; else if(arr1[2] != arr2[0] && arr1[2] != arr2[1]) rem = arr1[2]; arr1[0] = arr2[0]; arr1[1] = arr2[1]; } System.out.println("! " + arr1[0] + " " + arr1[1]); System.out.flush(); } //output.flush(); } } 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(); } public 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\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
2b44e1918ddde06bd3e0fcb5fc9c9dc1
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
// package c1634; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.lang.invoke.MethodHandles; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Random; import java.util.Scanner; import java.util.StringTokenizer; import java.util.TreeSet; // // Codeforces Round #770 (Div. 2) 2022-02-06 06:35 // D. Finding Zero // https://codeforces.com/contest/1634/problem/D // time limit per test 1 second; memory limit per test 256 megabytes // public class Pseudo for 'Source should satisfy regex [^{}]*public\s+(final)?\s*class\s+(\w+).*' // // We picked an array of whole numbers a_1, a_2, ..., a_n (0 <= a_i <= 10^9) and concealed zero in // it! Your goal is to find the location of this zero, that is, to find i such that a_i = 0. // // You are allowed to make several queries to guess the answer. For each query, you can think up // three distinct indices i, j, k, and we will tell you the value of \max(a_i, a_j, a_k) - \min(a_i, // a_j, a_k). In other words, we will tell you the difference between the maximum and the minimum // number among a_i, a_j and a_k. // // You are allowed to make no more than 2 * n - 2 queries, and after that you have two tries to // guess where the zero is. That is, you have to tell us two numbers i and j and you win if a_i = 0 // or a_j = 0. // // Can you guess where we hid the zero? // // Note that the array in each test case is fixed beforehand and will not change during the game. In // other words, the interactor is not adaptive. // // Input // // Each test contains multiple test cases. The first line contains the number of test cases t (1 <= // t <= 500). Description of the test cases follows. // // The first and only line of each test case contains an integer n (4 <= n <= 1000)-- the length of // the array that we picked. // // It is guaranteed that the sum of n over all test cases does not exceed 3000. // // Output // // For each test case, the interaction starts with reading n. // // To make a query, print "? " (without quotes, 1 <= i, j, k <= n, indices must be distinct). Then // you should read our response from standard input, that is, \max(a_i, a_j, a_k) - \min(a_i, a_j, // a_k). // // If the response is -1, it means your program has made an invalid query or has run out of tries. // Your program must terminate immediately after reading -1, and you will get a verdict Wrong // answer. Otherwise you may get any verdict, because the program will continue reading from the // closed stream. Note that if the query is correct, the answer will never be -1 because \max(a_i, // a_j, a_k) - \min(a_i, a_j, a_k) >= 0. // // To give the final answer, print "! " (without the quotes). Printing the same number twice (that // is, i = j) is allowed. Note that giving this answer is not counted towards the limit of 2 * n - 2 // queries. After that, your program must continue to solve the remaining test cases, or exit if all // test cases have been solved. // // After printing a query, don't forget to output line feed and flush the output buffer. Otherwise // you will get the verdict Idleness limit exceeded. To flush the buffer, use: // * fflush(stdout) or cout.flush() in C++; // * System.out.flush() in Java; // * flush(output) in Pascal; // * stdout.flush() in Python; // * Read documentation for other languages. // // The first line must contain an integer t (1 <= t <= 500)-- the count of test cases. // // The first line of each test case must contain an integer n (4 <= n <= 1000)-- the length of the // hidden array. // // The second line of each test case must contain n integers separated by spaces-- a_1, a_2, ..., // a_n (0 <= a_i <= 10^9). There must also be zero in this array. // // The sum of n over all test cases must not exceed 3000.</div> // // Example /* input: 1 4 2 3 3 2 output: ? 1 2 3 ? 2 3 4 ? 3 4 1 ? 4 1 2 ! 2 3 */ // Note // // Array from sample: [1, 2, 0, 3]. // public class C1634D { static final int MOD = 998244353; static final Random RAND = new Random(); static void solve(int n, int[] a, MyScanner in) { // Specially handle n = 4 if (n == 4) { int[] arr = new int[5]; arr[1] = ask(2, 3, 4, a, in); arr[2] = ask(1, 3, 4, a, in); arr[3] = ask(1, 2, 4, a, in); arr[4] = ask(1, 2, 3, a, in); TreeSet<Integer> midxes = new TreeSet<>(getMaxIdxes(arr, 1, n)); // Examples: // 1 2 0 3 -> 3 3 2 2 // 43 96 0 2 -> 96 43 94 96 // 2 2 0 2 -> 2 2 0 2 // Size of midxes will be 2 or 3 myAssert(midxes.size() >= 2); List<Integer> exclude = new ArrayList<>(); for (int i = 1; i <= n; i++) { if (!midxes.contains(i)) { exclude.add(i); } } guess(exclude.get(0), exclude.size() > 1 ? exclude.get(1) : 1, a); return; } int[] ab = new int[n+1]; for (int k = 3; k <= n; k++) { ab[k] = ask(1, 2, k, a, in); } if (in == null) System.err.format(" ab: %s\n", Arrays.toString(ab)); // Indexes of the maximal value in ab[3,n] List<Integer> abmidxes = getMaxIdxes(ab, 3, n); if (in == null) System.err.format(" abmidxes: %s\n", traceListInt(abmidxes)); // Let midxes be the set of indexes of the maximal value and i0 be the index of 0. // Cases regarding ab: // 1. a[1,2] contains both 0 and any max, then abmidxes will contains the whole range [3,n]. // However the reverse is not necessarily true. For example: 1 1 0 2 2 // 2. a[1,2] contains 0 but not max, then abmidxes will be same as midxes // 3. a[1,2] contains max but not 0, regardless single or multiple max, abmidxes will be {i0}. // 4. a[1,2] contain v1 and v2 where 0 < v1 <= v2 < max // a) if max - v1 > v2, then abmidxes will be midxes // b) if max - v1 = v2, then abmidxes will be midxes U {i0} // c) if max - v1 < v2, then abmidxes will be {i0} // if (abmidxes.size() == n - 2) { // We claim two cases: // 1. 0 x v w ... // 2. x-d d x x x ... 0 ... x x where d >= x - d // We query (i, i+1, i+2) for i in [3,n-2] and if all answer is smaller, it will be case 1 int[] a2 = new int[n+1]; boolean allSmaller = true; for (int i = 3; i <= n - 2; i++) { a2[i] = ask(i, i+1, i+2, a, in); if (a2[i] >= ab[3]) { allSmaller = false; break; } } if (allSmaller) { guess(1, 2, a); } else { List<Integer> midxes = getMaxIdxes(a2, 3, n); myAssert(midxes.size() <= 3); int j0 = midxes.get(0); int j1 = j0 + 1; int j2 = j0 + 2; int x = a2[j0]; int i0 = j2; if (ask(1, j1, j2, a, in) < x) { i0 = j0; } else if (ask(1, j0, j2, a, in) < x) { i0 = j1; } guess(i0, 1, a); } return; } else if (abmidxes.size() == 1) { // the single value is either i0 (3 or 4c) or the single im (2 or 4a). // We need find im from i0 or i0 from im to form an answer pair int i0m = abmidxes.get(0); int[] ah = new int[n+1]; for (int i = 1; i <= n; i++) { if (i == i0m) { continue; } int j = getNextSkipOne(n, i, i0m); ah[i] = ask(i, j, i0m, a, in); } if (in == null) System.err.format(" ah: %s\n", Arrays.toString(ah)); // There should be two maximal values that are consecutive (circular and skip h) List<Integer> ahmidxes = getMaxIdxes(ah, 1, n); if (in == null) System.err.format(" ahmidxes: %s\n", traceListInt(ahmidxes)); // If i0m is i0 and multiple max, size of ahmidxes will exceed 2 myAssert(ahmidxes.size() >= 2); int j0 = ahmidxes.get(0); int j1 = ahmidxes.get(1); if (ahmidxes.size() > 2) { guess(i0m, j0, a); } else { // 1 2 3 4 ... h-1 h h+1 ... n-1 n // * * // ^ // * * // ^ // * * // ^ // * * // ^ // * * // ^ myAssert(j1 == getNextSkipOne(n, j0, i0m) || j0 == getNextSkipOne(n, j1, i0m)); int im0 = j1 == getNextSkipOne(n, j0, i0m) ? j1 : j0; guess(i0m, im0, a); } } else { // abmidxes contains whole midxes and possibly i0 as well int j0 = abmidxes.get(0); int j1 = abmidxes.get(1); int[] aj = new int[n+1]; for (int i = 1; i <= n; i++) { if (i == j0 || i == j1) { continue; } aj[i] = ask(i, j0, j1, a, in); } List<Integer> ajmidxes = getMaxIdxes(aj, 1, n); if (ajmidxes.size() == n - 2) { guess(j0, j1, a); } else { myAssert(ajmidxes.size() == 1); guess(ajmidxes.get(0), j0, a); } } } static int ask(int i, int j, int k, int[] a, MyScanner in) { if (in != null) { System.out.format("? %d %d %d\n", i, j, k); System.out.flush(); return in.nextInt(); } else { int n = a.length - 1; myAssert(i >= 1 && i <= n); myAssert(j >= 1 && j <= n); myAssert(k >= 1 && k <= n); int max = Math.max(Math.max(a[i], a[j]), a[k]); int min = Math.min(Math.min(a[i], a[j]), a[k]); System.out.format("? %2d %2d %2d -> %d\n", i, j, k, max - min); return max - min; } } static boolean guessedOk = false; static void guess(int i, int j, int[] a) { System.out.format("! %d %d\n", i, j); if (a != null) { myAssert(a[i] == 0 || a[j] == 0); guessedOk = true; } } static boolean isSame(int[] arr, int b, int e) { for (int i = b + 1; i <= e; i++) { if (arr[i] != arr[b]) { return false; } } return true; } static int getMaxValue(int[] a) { int m = 0; for (int v : a) { m = Math.max(m, v); } return m; } static List<Integer> getMaxIdxes(int[] arr, int b, int e) { int max = arr[b]; for (int i = b + 1; i <= e; i++) { max = Math.max(max, arr[i]); } List<Integer> idxes = new ArrayList<>(); for (int i = b; i <= e; i++) { if (arr[i] == max) { idxes.add(i); } } return idxes; } static List<Integer> getCommon(List<Integer> idxes1, List<Integer> idxes2) { List<Integer> idxes = new ArrayList<>(); int i2 = 0; int n2 = idxes2.size(); for (int v : idxes1) { while (i2 < n2 && idxes2.get(i2) < v) { i2++; } if (i2 >= n2) { break; } if (idxes2.get(i2) == v) { idxes.add(v); } } return idxes; } static void doTest() { long t0 = System.currentTimeMillis(); guessedOk = false; solve(5, new int[] {0,1, 1, 0,2,2}, null); myAssert(guessedOk); for (int t = 0; t < 10; t++) { int n = 5; int[] a = new int[n+1]; for (int i = 1; i <= n; i++) { a[i] = 1 + RAND.nextInt(2); } int jj = 1 + RAND.nextInt(n); a[jj] = 0; System.err.format(" a: %s\n", Arrays.toString(a)); guessedOk = false; solve(n, a, null); myAssert(guessedOk); } System.out.format("%d msec\n", System.currentTimeMillis() - t0); System.exit(0); } static int getNextSkipOne(int n, int i, int skip) { int j = i + 1; if (j == skip) { j++; } if (j == n + 1) { j = 1; } return j; } public static String traceListInt(List<Integer> values) { StringBuilder sb = new StringBuilder(); sb.append('['); int n = values.size(); for (int i = 0; i < n; i++) { if (i < 16 || i >= n - 16) { if (i > 0) { sb.append(','); } sb.append(values.get(i)); } if (n > 32 && i == 16) { sb.append(",..."); } } sb.append(']'); return sb.toString(); } public static void main(String[] args) { // doTest(); MyScanner in = new MyScanner(); int T = in.nextInt(); for (int t = 1; t <= T; t++) { int n = in.nextInt(); solve(n, null, in); } } static Scanner getInputScanner() { try { final String USERDIR = System.getProperty("user.dir"); final String CNAME = MethodHandles.lookup().lookupClass().getSimpleName(); final File fin = new File(USERDIR + "/io/c" + CNAME.substring(1,5) + "/" + CNAME + ".in"); return fin.exists() ? new Scanner(fin) : new Scanner(System.in); } catch (Exception e) { return new Scanner(System.in); } } static void output(int[] a) { if (a == null) { System.out.println("-1"); return; } StringBuilder sb = new StringBuilder(); for (int v : a) { sb.append(v); sb.append(' '); if (sb.length() > 500) { System.out.print(sb.toString()); sb.setLength(0); } } System.out.println(sb.toString()); } static void myAssert(boolean cond) { if (!cond) { throw new RuntimeException("Unexpected"); } } static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { try { final String USERDIR = System.getProperty("user.dir"); String cname = MethodHandles.lookup().lookupClass().getCanonicalName(); // C1621C.MyIo -> C1621C int i = cname.lastIndexOf('.'); if (i > 0) { cname = cname.substring(0, i); } final File fin = new File(USERDIR + "/io/c" + cname.substring(1,5) + "/" + cname + ".in"); br = new BufferedReader(new InputStreamReader(fin.exists() ? new FileInputStream(fin) : System.in)); } catch (Exception e) { br = new BufferedReader(new InputStreamReader(System.in)); } } public String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } } }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
581763bb8c9df7fdfe8b2536b820724e
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
import java.io.*; import java.util.Arrays; import java.util.Comparator; import java.util.Random; import java.util.StringTokenizer; public class codeforces_770_D { private static void solve(FastIOAdapter in, PrintWriter out) { int n = in.nextInt(); int f = 1, s = 2; int prevSeen = 2; while (prevSeen != n) { int next = prevSeen + 1; int next2 = -1; if (prevSeen + 2 <= n) next2 = prevSeen + 2; else for (int i = 1; i <= 3; i++) { if (i != f && i != s) { next2 = i; break; } } ask(out, s, next, next2); int not1 = in.nextInt(); ask(out, f, next, next2); int not2 = in.nextInt(); ask(out, f, s, next2); int not3 = in.nextInt(); ask(out, f, s, next); int not4 = in.nextInt(); int[][] a = new int[][]{{not1, f}, {not2, s}, {not3, next}, {not4, next2}}; Arrays.sort(a, (i1, i2) -> { if (i1[0] != i2[0]) return Integer.compare(i1[0], i2[0]); else return Integer.compare(i1[1], i2[1]); }); f = a[0][1]; s = a[1][1]; prevSeen = Math.max(next, next2); } out.println("! " + f + " " + s); out.flush(); } private static void ask(PrintWriter out, int n1, int n2, int n3) { out.println("? " + n1 + " " + n2 + " " + n3); out.flush(); } public static void main(String[] args) throws Exception { try (FastIOAdapter ioAdapter = new FastIOAdapter()) { int count = 1; count = ioAdapter.nextInt(); while (count-- > 0) { solve(ioAdapter, ioAdapter.out); } } } static void ruffleSort(int[] arr) { int n = arr.length; Random rnd = new Random(); for (int i = 0; i < n; ++i) { int tmp = arr[i]; int randomPos = i + rnd.nextInt(n - i); arr[i] = arr[randomPos]; arr[randomPos] = tmp; } Arrays.sort(arr); } static class FastIOAdapter implements AutoCloseable { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter((System.out)))); StringTokenizer st = new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } String nextLine() { try { return br.readLine(); } catch (IOException e) { e.printStackTrace(); return null; } } 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[] readArrayLong(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } long nextLong() { return Long.parseLong(next()); } @Override public void close() throws Exception { out.flush(); out.close(); br.close(); } } }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
2c48c88762d303143c25b6e789306637
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
import java.io.*; import java.util.InputMismatchException; public class E1634D { static FastIO io = new FastIO(); public static void main(String[] args) { int t = io.nextInt(); while (t-- > 0) { int n = io.nextInt(); int fMaxDiff = -1; int firstExtreme = -1; int secondExtreme = -1; boolean firstSame = true; for (int i = 3; i <= n; i++) { int p = get(1, 2, i); firstSame &= p == fMaxDiff || fMaxDiff == -1; if (p > fMaxDiff) { fMaxDiff = p; firstExtreme = i; secondExtreme = -1; } else if (p == fMaxDiff) secondExtreme = i; } boolean same = true; int maxDiff = -1; if (secondExtreme == -1) secondExtreme = 1; int ans = -1; for (int i = 1; i <= n; i++) { if (i == firstExtreme || i == secondExtreme) continue; int p = get(firstExtreme, secondExtreme, i); same &= p == maxDiff || maxDiff == -1; if (p > maxDiff) { maxDiff = p; ans = i; } } if (maxDiff <= fMaxDiff && firstSame) io.println("! 1 2 "); else if (same) io.println("! " + firstExtreme + " " + secondExtreme); else io.println("! " + firstExtreme + " " + ans); io.flush(); } io.close(); } static int get(int i, int j, int k) { io.println("? " + i + " " + j + " " + k); io.flush(); return io.nextInt(); } private static class FastIO extends PrintWriter { private final InputStream stream; private final byte[] buf = new byte[1 << 16]; private int curChar, numChars; // standard input public FastIO() { this(System.in, System.out); } public FastIO(InputStream i, OutputStream o) { super(o); stream = i; } // file input public FastIO(String i, String o) throws IOException { super(new FileWriter(o)); stream = new FileInputStream(i); } // throws InputMismatchException() if previously detected end of file private int nextByte() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars == -1) return -1; // end of file } return buf[curChar++]; } // to read in entire lines, replace c <= ' ' // with a function that checks whether c is a line break public String next() { int c; do { c = nextByte(); } while (c <= ' '); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = nextByte(); } while (c > ' '); return res.toString(); } public int nextInt() { // nextLong() would be implemented similarly int c; do { c = nextByte(); } while (c <= ' '); int sgn = 1; if (c == '-') { sgn = -1; c = nextByte(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res = 10 * res + c - '0'; c = nextByte(); } while (c > ' '); return res * sgn; } public long nextLong() { // nextLong() would be implemented similarly int c; do { c = nextByte(); } while (c <= ' '); int sgn = 1; if (c == '-') { sgn = -1; c = nextByte(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res = 10 * res + c - '0'; c = nextByte(); } while (c > ' '); return res * sgn; } public double nextDouble() { return Double.parseDouble(next()); } } }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
98785a704e12f73c57f5d5a00c937a19
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
// Generated by Code Flattener. // https://plugins.jetbrains.com/plugin/9979-idea-code-flattener import java.io.*; import java.util.*; import java.util.stream.Collectors; public class Main { protected int getN(FastReader in, FastWriter out) { return in.nextInt(); } protected int ask(FastReader in, FastWriter out, int i, int j, int k) { out.println("?", i, j, k); out.flush(); return in.nextInt(); } static class Node { List<Integer> list; int result; public Node(List<Integer> list) { this.list = new ArrayList<>(list); } } private List<Integer> ask(FastReader in, FastWriter out, List<Integer> subList) { int a = subList.get(0); int b = subList.get(1); int c = subList.get(2); int d = subList.get(3); List<Node> list = new ArrayList<>(); list.add(new Node(List.of(a, b, c))); list.add(new Node(List.of(a, b, d))); list.add(new Node(List.of(a, c, d))); list.add(new Node(List.of(b, c, d))); for (Node node : list) { node.result = ask(in, out, node.list.get(0), node.list.get(1), node.list.get(2)); } list.sort(Comparator.comparing(node -> -node.result)); Node n1 = list.get(0); Node n2 = list.get(1); n1.list.retainAll(n2.list); subList.removeAll(n1.list); return subList; } public void solve(FastReader in, FastWriter out) { int n = getN(in, out); Set<Integer> set = new HashSet<>(); for (int i = 1; i <= n; i++) { set.add(i); } List<Integer> removed = new ArrayList<>(); while (set.size() >= 4) { List<Integer> a = set.stream().limit(4).collect(Collectors.toList()); List<Integer> tmp = ask(in, out, a); for (Integer el : tmp) { removed.add(el); set.remove(el); } if (set.size() == 3) { set.add(removed.get(0)); } } Iterator<Integer> iterator = set.iterator(); out.println("! " + iterator.next() + " " + iterator.next()); out.flush(); } public Config getConfig() { return Config.standard(true); } public static void main(String[] args) { boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null; Main main = new Main(); Problem problem = new Problem(); problem.setSolution(main::solve); problem.setConfig(main.getConfig()); problem.execute(); } private static class Config { public static Config standard(boolean multiTest) { return new Config(null, null, multiTest); } private final String inputFileName; private final String outputFileName; private final boolean multiTest; public Config(String inputFileName, String outputFileName, boolean multiTest) { this.inputFileName = inputFileName; this.outputFileName = outputFileName; this.multiTest = multiTest; } public String getInputFileName() { return inputFileName; } public String getOutputFileName() { return outputFileName; } public boolean isMultiTest() { return multiTest; } } private static class Problem { private Executable solution; private Config config; private Executable init; public void execute() { if (solution == null) { throw new RuntimeException("please, set solution"); } FastReader in = new FastReader(config.getInputFileName()); FastWriter out = new FastWriter(config.getOutputFileName()); if (init != null) { init.run(in, out); } if (!config.isMultiTest()) { solution.run(in, out); } else { int times = in.nextInt(); for (int i = 0; i < times; i++) { solution.run(in, out); } } out.close(); } public void setSolution(Executable solution) { this.solution = solution; } public void setConfig(Config config) { this.config = config; } } private static class FastReader { private final BufferedReader br; private StringTokenizer st; public FastReader(String fileName) { if (fileName != null) { try { File file = new File(getClass().getClassLoader().getResource(fileName).getFile()); br = new BufferedReader(new FileReader(file)); } catch (FileNotFoundException e) { throw new RuntimeException(e); } } else { br = new BufferedReader(new InputStreamReader(System.in)); } } public String next() { while (st == null || !st.hasMoreElements()) { st = new StringTokenizer(nextLine()); } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public String nextLine() { try { String line = br.readLine(); if (line == null) { throw new RuntimeException("empty line"); } st = null; return line; } catch (IOException e) { throw new RuntimeException(e); } } } private static class FastWriter { final private PrintWriter printWriter; public FastWriter(String fileName) { if (fileName != null) { try { printWriter = new PrintWriter(new FileWriter(fileName)); } catch (IOException e) { throw new RuntimeException(e); } } else { printWriter = new PrintWriter(new BufferedOutputStream(System.out)); } } public void println(String s) { printWriter.println(s); } public void println(Object... objs) { for (int i = 0; i < objs.length - 1; i++) { printWriter.print(objs[i] + " "); } printWriter.println(objs[objs.length - 1]); } public void flush() { printWriter.flush(); } public void close() { printWriter.close(); } } private interface Executable { void run(FastReader in, FastWriter out); } }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
8ec227d10ef149e8fe7efb94bb939127
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
import java.io.*; import java.util.*; public class D_Finding_Zero { static final int INT_MOD = (int) 1e9 + 7; static final long LONG_MOD = (long) 1e9 + 7; static final int INT_POSITIVE_INFINITY = Integer.MAX_VALUE; static final long LONG_POSITIVE_INFINITY = Long.MAX_VALUE; static final int INT_NEGATIVE_INFINITY = Integer.MIN_VALUE; static final long LONG_NEGATIVE_INFINITY = Long.MIN_VALUE; static StringBuilder result = new StringBuilder(); public static void main(String args[]) throws IOException { FastReader fr = new FastReader(); FastWriter fw = new FastWriter(); int tc = fr.nextInt(); while (tc-- > 0) { int n = fr.nextInt(); int a = 1; int b = 2; int c = 3; fw.write("? 1 2 3\n"); int abc = fr.nextInt(); for (int i = 4; i <= n; i++) { fw.write("? " + a + " " + b + " " + i + "\n"); int abd = fr.nextInt(); fw.write("? " + a + " " + c + " " + i + "\n"); int acd = fr.nextInt(); if ((abc > abd) && (abc > acd)) { int t = a; a = b; b = c; c = t; continue; } if ((abd > abc) && (abd > acd)) { int t = a; a = b; b = i; c = t; abc = abd; continue; } if ((acd > abc) && (acd > abd)) { int t = a; a = c; b = i; c = t; abc = acd; continue; } if (abc == abd) { continue; } if (acd == abc) { b = c; c = i; abc = acd; continue; } if (acd == abd) { b = i; abc = acd; continue; } } fw.write("! " + a + " " + b + "\n"); } } static void helper() { } static void reverse(int[] nums, int i, int j) { while (i < j) { swap(nums, i++, j--); } } static void swap(int[] nums, int i, int j) { int temp = nums[i]; nums[i] = nums[j]; nums[j] = temp; } static boolean isPrime(long x) { if (x <= 1) return false; for (long i = 2; i * i <= x; i++) if (x % i == 0) return false; return true; } static boolean[] sieve(int n) { boolean[] sieve = new boolean[n + 1]; Arrays.fill(sieve, true); sieve[0] = sieve[1] = false; for (int i = 2; i * i <= n; i++) { if (sieve[i]) { for (int j = i * i; j <= n; j += i) { sieve[j] = false; } } } return sieve; } static boolean isFibonacci(long x) { return isPerfectSquare(5 * x * x + 4); } static boolean isPerfectSquare(long x) { if (x <= 1) return true; long low = 1; long high = x; long mid = 0; while (low <= high) { mid = low + (high - low) / 2l; if (mid * mid == x) return true; else if (mid * mid < x) low = mid + 1; else high = mid - 1; } return false; } static long lcm(long a, long b) { return a * b / gcd(a, b); } static long gcd(long a, long b) { if (b > a) return gcd(b, a); if (b == 0) return a; return gcd(b, a % b); } static long pow(long b, long e) { long curr = b; long res = 1; while (e != 0) { if ((e & 1) != 0) { res = (res * curr) % LONG_MOD; } curr = (curr * curr) % LONG_MOD; e >>= 1; } return res; } static double log(double x, double base) { return Math.log(x) / Math.log(base); } } /* user-defined data structures */ class Pair { long a; long b; public Pair(long a, long b) { this.a = a; this.b = b; } } class Tair { int a; int b; int c; public Tair(int a, int b, int c) { this.a = a; this.b = b; this.c = c; } } class Fair { int a; int b; int c; int i; public Fair(int a, int b, int c, int i) { this.a = a; this.b = b; this.c = c; this.i = i; } } class Point { int x; int y; int z; public Point(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } } /* User defined data structures ends here */ /* IO class */ class FastReader { InputStreamReader isr; BufferedReader br; StringTokenizer st; public FastReader() { isr = new InputStreamReader(System.in); br = new BufferedReader(isr); } 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; } } class FastWriter { OutputStreamWriter osw; BufferedWriter bw; public FastWriter() { osw = new OutputStreamWriter(System.out); bw = new BufferedWriter(osw); } void write(String text) { try { bw.write(text); bw.flush(); } catch (IOException e) { e.printStackTrace(); } } } class FastFileReader { FileInputStream fis; InputStreamReader isr; BufferedReader br; StringTokenizer st; public FastFileReader(String fileName) throws FileNotFoundException { fis = new FileInputStream(fileName); isr = new InputStreamReader(fis); br = new BufferedReader(isr); } 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; } } class FastFileWriter { FileOutputStream fos; OutputStreamWriter osw; BufferedWriter bw; public FastFileWriter(String fileName) throws FileNotFoundException { fos = new FileOutputStream(fileName); osw = new OutputStreamWriter(fos); bw = new BufferedWriter(osw); } void write(String text) { try { bw.write(text); bw.flush(); } catch (IOException e) { e.printStackTrace(); } } } /* IO class ends here */
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
56d69b75321df48c28d50988b98203b4
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class D { static Scanner in; public static void main(String[] args) { in = new Scanner(System.in); int inputs = in.nextInt(); while(inputs-->0) { int n = in.nextInt(); ArrayList<Pair> list = new ArrayList<>(); list.add(query(1, 2, 3)); list.add(query(1, 2, 4)); list.add(query(1, 3, 4)); list.add(query(2, 3, 4)); Collections.sort(list); int diff = list.get(0).val; list.get(0).indices.retainAll(list.get(1).indices); int a = list.get(0).indices.get(0); int b = list.get(0).indices.get(1); int fill = -1; for(int i = 1; i <= 4; i++) { if(i != a && i != b) { fill = i; break; } } for(int i = 5; i <= n; i++) { Pair q1 = query(a, fill, i); Pair q2 = query(b, fill, i); if(Math.max(q1.val, q2.val) < diff) { continue; } if(q1.val > q2.val) { b = i; diff = q1.val; } else { a = i; diff = q2.val; } } System.out.println("! " + a + " " + b); System.out.flush(); } } public static Pair query(int a, int b, int c) { System.out.println("? " + a + " " + b + " " + c); System.out.flush(); return new Pair(in.nextInt(), a, b, c); } } class Pair implements Comparable<Pair> { int val; ArrayList<Integer> indices; public Pair(int v, int a, int b, int c) { indices = new ArrayList<>(); val = v; indices.add(a); indices.add(b); indices.add(c); } public int compareTo(Pair p) { return p.val - val; } }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
054170667dda5477e03a3c4b82785c8b
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
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; /** * Built using CHelper plug-in * Actual solution is at the top * * @author null */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Input in = new Input(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskD solver = new TaskD(); solver.solve(1, in, out); out.close(); } static class TaskD { private void solve(Input in, PrintWriter out) throws Exception { int kt = in.readInt(); for (int nt = 0; nt < kt; nt++) { int n = in.readInt(); int a = 1; int b = 2; int c = 3; out.println("? 1 2 3"); out.flush(); int abc = in.readInt(); for (int d = 4; d <= n; d++) { out.println("? " + a + " " + b + " " + d); out.flush(); int abd = in.readInt(); out.println("? " + a + " " + c + " " + d); out.flush(); int acd = in.readInt(); if ((abc > abd) && (abc > acd)) { int t = a; a = b; b = c; c = t; continue; } if ((abd > abc) && (abd > acd)) { int t = a; a = b; b = d; c = t; abc = abd; continue; } if ((acd > abc) && (acd > abd)) { int t = a; a = c; b = d; c = t; abc = acd; continue; } if (abc == abd) { continue; } if (acd == abc) { b = c; c = d; abc = acd; continue; } if (acd == abd) { b = d; abc = acd; continue; } System.exit(111); } out.println("! " + a + " " + b); out.flush(); } } public void solve(int testNumber, Input in, PrintWriter out) { try { solve(in, out); } catch (Exception e) { throw new RuntimeException(e); } } } static class Input { public final BufferedReader reader; private String line = ""; private int pos = 0; public Input(InputStream inputStream) { reader = new BufferedReader(new InputStreamReader(inputStream)); } private boolean isSpace(char ch) { return ch <= 32; } public String readWord() throws IOException { skip(); int start = pos; while (pos < line.length() && !isSpace(line.charAt(pos))) { pos++; } return line.substring(start, pos); } public int readInt() throws IOException { return Integer.parseInt(readWord()); } private void skip() throws IOException { while (true) { if (pos >= line.length()) { line = reader.readLine(); pos = 0; } while (pos < line.length() && isSpace(line.charAt(pos))) { pos++; } if (pos < line.length()) { return; } } } } }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
44b4f4021b7c57eb2bd096f612845519
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class Main { PrintWriter out = new PrintWriter(System.out); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer tok = new StringTokenizer(""); String next() throws IOException { if (!tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); } return tok.nextToken(); } int ni() throws IOException { return Integer.parseInt(next()); } long nl() throws IOException { return Long.parseLong(next()); } int[] na(int n) throws IOException { int[]A=new int[n]; for (int i=0;i<n;i++) A[i]=ni(); return A; } long mod=1000000007; void solve() throws IOException { for (int tc=ni();tc>0;tc--) { int n=ni(); int a1=-1; int max=0; for (int i=3;i<=n;i++) { int u=query(1,2,i); if (u>max) { max=u; a1=i; } } int a2=-1; max=0; for (int i=2;i<=n;i++) { if (i==a1) continue; int u=query(1,a1,i); if (u>max) { max=u; a2=i; } } int a3=1; int a4=2; while (a4==a2 || a4==a1) a4++; if (query(a1,a2,a4)==max) out.println("! "+a1+" "+a2); else if (query(a1,a3,a4)==max) out.println("! "+a1+" "+a3); else out.println("! "+a2+" "+a3); out.flush(); } out.flush(); } int query(int a,int b,int c) throws IOException{ out.println("? "+a+" "+b+" "+c); out.flush(); int r=ni(); if (r==-1) System.exit(0); return r; } int gcd(int a,int b) { return(b==0?a:gcd(b,a%b)); } long gcd(long a,long b) { return(b==0?a:gcd(b,a%b)); } long mp(long a,long p) { long r=1; while(p>0) { if ((p&1)==1) r=(r*a)%mod; p>>=1; a=(a*a)%mod; } return r; } public static void main(String[] args) throws IOException { new Main().solve(); } }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
9496f4ac3153d7209f36c887c695cd48
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
//Utilities import java.io.*; import java.util.*; public class a { static int t; static int n; static HashSet<Integer> set; public static void main(String[] args) throws IOException { t = in.iscan(); while (t-- > 0) { n = in.iscan(); set = new HashSet<Integer>(); for (int i = 1; i <= n; i++) { set.add(i); while (set.size() < 4 && i + 1 <= n) { set.add(i+1); i++; } if (set.size() < 4) { for (int j = 1; j <= n; j++) { if (!set.contains(j)) { set.add(j); } if (set.size() == 4) break; } if (set.size() < 4) { break; } } int[] a = new int[4]; int idx = 0; for (int xx : set) { a[idx] = xx; idx++; } int[] d = new int[4]; System.out.println("? " + a[0] + " " + a[1] + " " + a[2]); System.out.flush(); d[0] = in.iscan(); System.out.println("? " + a[0] + " " + a[1] + " " + a[3]); System.out.flush(); d[1] = in.iscan(); System.out.println("? " + a[0] + " " + a[2] + " " + a[3]); System.out.flush(); d[2] = in.iscan(); System.out.println("? " + a[1] + " " + a[2] + " " + a[3]); System.out.flush(); d[3] = in.iscan(); if (d[0] == d[1] && d[0] == d[2] && d[0] == d[3]) { set.clear(); continue; } int largestDif = Math.max(Math.max(d[0], d[1]), Math.max(d[2], d[3])); for (int j = 0; j < 4; j++) { if (d[j] != largestDif) { if (j == 0) { if (d[1] == largestDif) set.remove(a[2]); if (d[2] == largestDif) set.remove(a[1]); if (d[3] == largestDif) set.remove(a[0]); } else if (j == 1) { if (d[0] == largestDif) set.remove(a[3]); if (d[2] == largestDif) set.remove(a[1]); if (d[3] == largestDif) set.remove(a[0]); } else if (j == 2) { if (d[0] == largestDif) set.remove(a[3]); if (d[1] == largestDif) set.remove(a[2]); if (d[3] == largestDif) set.remove(a[0]); } else { if (d[0] == largestDif) set.remove(a[3]); if (d[1] == largestDif) set.remove(a[2]); if (d[2] == largestDif) set.remove(a[1]); } } } } int x = -1, y = -1; for (int xx : set) { if (x == -1) x = xx; else if (y == -1) y = xx; } if (y == -1) { y = x; } System.out.println("! " + x + " " + y); System.out.flush(); } out.close(); } static INPUT in = new INPUT(System.in); static PrintWriter out = new PrintWriter(System.out); private static class INPUT { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar, numChars; public INPUT (InputStream stream) { this.stream = stream; } public INPUT (String file) throws IOException { this.stream = new FileInputStream (file); } public int cscan () throws IOException { if (curChar >= numChars) { curChar = 0; numChars = stream.read (buf); } if (numChars == -1) return numChars; return buf[curChar++]; } public int iscan () throws IOException { int c = cscan (), sgn = 1; while (space (c)) c = cscan (); if (c == '-') { sgn = -1; c = cscan (); } int res = 0; do { res = (res << 1) + (res << 3); res += c - '0'; c = cscan (); } while (!space (c)); return res * sgn; } public String sscan () throws IOException { int c = cscan (); while (space (c)) c = cscan (); StringBuilder res = new StringBuilder (); do { res.appendCodePoint (c); c = cscan (); } while (!space (c)); return res.toString (); } public double dscan () throws IOException { int c = cscan (), sgn = 1; while (space (c)) c = cscan (); if (c == '-') { sgn = -1; c = cscan (); } double res = 0; while (!space (c) && c != '.') { if (c == 'e' || c == 'E') return res * UTILITIES.fast_pow (10, iscan ()); res *= 10; res += c - '0'; c = cscan (); } if (c == '.') { c = cscan (); double m = 1; while (!space (c)) { if (c == 'e' || c == 'E') return res * UTILITIES.fast_pow (10, iscan ()); m /= 10; res += (c - '0') * m; c = cscan (); } } return res * sgn; } public long lscan () throws IOException { int c = cscan (), sgn = 1; while (space (c)) c = cscan (); if (c == '-') { sgn = -1; c = cscan (); } long res = 0; do { res = (res << 1) + (res << 3); res += c - '0'; c = cscan (); } while (!space (c)); return res * sgn; } public boolean space (int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } } public static class UTILITIES { static final double EPS = 10e-6; public static void sort(int[] a, boolean increasing) { ArrayList<Integer> arr = new ArrayList<Integer>(); int n = a.length; for (int i = 0; i < n; i++) { arr.add(a[i]); } Collections.sort(arr); for (int i = 0; i < n; i++) { if (increasing) { a[i] = arr.get(i); } else { a[i] = arr.get(n-1-i); } } } public static void sort(long[] a, boolean increasing) { ArrayList<Long> arr = new ArrayList<Long>(); int n = a.length; for (int i = 0; i < n; i++) { arr.add(a[i]); } Collections.sort(arr); for (int i = 0; i < n; i++) { if (increasing) { a[i] = arr.get(i); } else { a[i] = arr.get(n-1-i); } } } public static void sort(double[] a, boolean increasing) { ArrayList<Double> arr = new ArrayList<Double>(); int n = a.length; for (int i = 0; i < n; i++) { arr.add(a[i]); } Collections.sort(arr); for (int i = 0; i < n; i++) { if (increasing) { a[i] = arr.get(i); } else { a[i] = arr.get(n-1-i); } } } public static int lower_bound (int[] arr, int x) { int low = 0, high = arr.length, mid = -1; while (low < high) { mid = (low + high) / 2; if (arr[mid] >= x) high = mid; else low = mid + 1; } return low; } public static int upper_bound (int[] arr, int x) { int low = 0, high = arr.length, mid = -1; while (low < high) { mid = (low + high) / 2; if (arr[mid] > x) high = mid; else low = mid + 1; } return low; } public static void updateMap(HashMap<Integer, Integer> map, int key, int v) { if (!map.containsKey(key)) { map.put(key, v); } else { map.put(key, map.get(key) + v); } if (map.get(key) == 0) { map.remove(key); } } public static long gcd (long a, long b) { return b == 0 ? a : gcd (b, a % b); } public static long lcm (long a, long b) { return a * b / gcd (a, b); } public static long fast_pow_mod (long b, long x, int mod) { if (x == 0) return 1; if (x == 1) return b; if (x % 2 == 0) return fast_pow_mod (b * b % mod, x / 2, mod) % mod; return b * fast_pow_mod (b * b % mod, x / 2, mod) % mod; } public static long fast_pow (long b, long x) { if (x == 0) return 1; if (x == 1) return b; if (x % 2 == 0) return fast_pow (b * b, x / 2); return b * fast_pow (b * b, x / 2); } public static long choose (long n, long k) { k = Math.min (k, n - k); long val = 1; for (int i = 0; i < k; ++i) val = val * (n - i) / (i + 1); return val; } public static long permute (int n, int k) { if (n < k) return 0; long val = 1; for (int i = 0; i < k; ++i) val = (val * (n - i)); return val; } // start of permutation and lower/upper bound template public static void nextPermutation(int[] nums) { //find first decreasing digit int mark = -1; for (int i = nums.length - 1; i > 0; i--) { if (nums[i] > nums[i - 1]) { mark = i - 1; break; } } if (mark == -1) { reverse(nums, 0, nums.length - 1); return; } int idx = nums.length-1; for (int i = nums.length-1; i >= mark+1; i--) { if (nums[i] > nums[mark]) { idx = i; break; } } swap(nums, mark, idx); reverse(nums, mark + 1, nums.length - 1); } public static void swap(int[] nums, int i, int j) { int t = nums[i]; nums[i] = nums[j]; nums[j] = t; } public static void reverse(int[] nums, int i, int j) { while (i < j) { swap(nums, i, j); i++; j--; } } static int lower_bound (int[] arr, int hi, int cmp) { int low = 0, high = hi, mid = -1; while (low < high) { mid = (low + high) / 2; if (arr[mid] >= cmp) high = mid; else low = mid + 1; } return low; } static int upper_bound (int[] arr, int hi, int cmp) { int low = 0, high = hi, mid = -1; while (low < high) { mid = (low + high) / 2; if (arr[mid] > cmp) high = mid; else low = mid + 1; } return low; } // end of permutation and lower/upper bound template } }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
2021d20b4d1823b40fab731f44beef7d
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
import java.io.PrintWriter; import java.util.Scanner; public class FindingZero { static Scanner sc = new Scanner(System.in); static PrintWriter pw = new PrintWriter(System.out); public static void main(String[] args) { int t = sc.nextInt(); while( t > 0 ) { solve(); t--; } pw.flush(); } static void solve() { int N = sc.nextInt(); int[] ans = {0,1}; int[] res = new int[4]; int hoge = -1; int max = -1; for( int i = 2; i < N; i+=2 ) { if( i == N-1 ) { res[0] = query(ans[0],ans[1],i); res[1] = query(ans[0],ans[1],hoge); res[2] = query(ans[0],i,hoge); res[3] = query(ans[1],i,hoge); max = get_max(res); if( res[0] == max ) { if( res[0] == res[1] ) { ans[0] = ans[0]; ans[1] = ans[1]; }else if( res[0] == res[2] ) { ans[0] = ans[0]; ans[1] = i; }else if( res[0] == res[3] ) { ans[0] = ans[1]; ans[1] = i; } }else if( res[1] == max ) { if( res[1] == res[2] ) { ans[0] = ans[0]; ans[1] = hoge; }else if( res[1] == res[3] ) { ans[0] = ans[1]; ans[1] = hoge; } }else { ans[0] = i; ans[1] = hoge; } }else { res[0] = query(ans[0],ans[1],i); res[1] = query(ans[0],ans[1],i+1); res[2] = query(ans[0],i,i+1); res[3] = query(ans[1],i,i+1); max = get_max(res); if( res[0] == max ) { if( res[0] == res[1] ) { hoge = i; ans[0] = ans[0]; ans[1] = ans[1]; }else if( res[0] == res[2] ) { hoge = ans[1]; ans[0] = ans[0]; ans[1] = i; }else if( res[0] == res[3] ) { hoge = ans[0]; ans[0] = ans[1]; ans[1] = i; } }else if( res[1] == max ) { if( res[1] == res[2] ) { hoge = ans[1]; ans[0] = ans[0]; ans[1] = i+1; }else if( res[1] == res[3] ) { hoge = ans[0]; ans[0] = ans[1]; ans[1] = i+1; } }else { hoge = ans[0]; ans[0] = i; ans[1] = i+1; } } } answer_query(ans[0],ans[1]); } static int get_max(int[] arr) { int max = 0; for( int val : arr ) max = Math.max(max, val); return max; } static void answer_query(int i, int j) { i++; j++; pw.print('!'); pw.print(' '); pw.print(i); pw.print(' '); pw.println(j); pw.flush(); } static int query(int i, int j, int k) { i++; j++; k++; pw.print('?'); pw.print(' '); pw.print(i); pw.print(' '); pw.print(j); pw.print(' '); pw.println(k); pw.flush(); return sc.nextInt(); } }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
f789d61e82759e0cf1404d1fa1569c70
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
// JAI SHREE RAM, HAR HAR MAHADEV, HARE KRISHNA import java.util.*; import java.util.stream.*; import java.lang.*; import java.math.BigInteger; import java.text.DecimalFormat; import java.io.*; public class Eshan { static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer st; static PrintWriter out = new PrintWriter(System.out); static DecimalFormat df = new DecimalFormat("0.0000000"); final static int mod = (int) (1e9 + 7); final static int MAX = Integer.MAX_VALUE; final static int MIN = Integer.MIN_VALUE; static Random rand = new Random(); // ======================= MAIN ================================== public static void main(String[] args) throws IOException { long time = System.currentTimeMillis(); boolean oj = System.getProperty("ONLINE_JUDGE") != null; // ==== start ==== int t = readInt(); // int t = 1; preprocess(); while (t-- > 0) { solve(); } out.flush(); // ==== end ==== if (!oj) System.out.println(Arrays.deepToString(new Object[] { System.currentTimeMillis() - time + " ms" })); } private static void solve() throws IOException { int n = readInt(); Set<Integer> diff1 = new HashSet<>(); int max1 = 0, idx1 = -1; for (int i = 3; i <= n; i++) { out.println("? 1 2 " + i); out.flush(); int d = readInt(); diff1.add(d); if (d > max1) { max1 = d; idx1 = i; } } Set<Integer> diff2 = new HashSet<>(); int max2 = 0, idx2 = -1; for (int i = 2; i <= n; i++) { if (i != idx1) { out.println("? 1 " + idx1 + " " + i); out.flush(); int d = readInt(); diff2.add(d); if (d > max2) { max2 = d; idx2 = i; } } } if (diff1.size() == 1) { if (idx2 <= 2) { out.println("! 1 2"); out.flush(); } else { out.println("! " + idx1 + " " + idx2); out.flush(); } } else if (diff2.size() == 1) { out.println("! 1 " + idx1); out.flush(); } else { out.println("! " + idx1 + " " + idx2); out.flush(); } } private static void preprocess() { } // ======================= FOR INPUT ================================== static String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(readLine()); return st.nextToken(); } static long readLong() throws IOException { return Long.parseLong(next()); } static int readInt() throws IOException { return Integer.parseInt(next()); } static double readDouble() throws IOException { return Double.parseDouble(next()); } static char readCharacter() throws IOException { return next().charAt(0); } static String readString() throws IOException { return next(); } static String readLine() throws IOException { return br.readLine().trim(); } static int[] readIntArray(int n) throws IOException { int[] arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = readInt(); return arr; } static int[][] read2DIntArray(int n, int m) throws IOException { int[][] arr = new int[n][m]; for (int i = 0; i < n; i++) arr[i] = readIntArray(m); return arr; } static List<Integer> readIntList(int n) throws IOException { List<Integer> list = new ArrayList<>(); for (int i = 0; i < n; i++) list.add(readInt()); return list; } static long[] readLongArray(int n) throws IOException { long[] arr = new long[n]; for (int i = 0; i < n; i++) arr[i] = readLong(); return arr; } static long[][] read2DLongArray(int n, int m) throws IOException { long[][] arr = new long[n][m]; for (int i = 0; i < n; i++) arr[i] = readLongArray(m); return arr; } static List<Long> readLongList(int n) throws IOException { List<Long> list = new ArrayList<>(); for (int i = 0; i < n; i++) list.add(readLong()); return list; } static char[] readCharArray(int n) throws IOException { return readString().toCharArray(); } static char[][] readMatrix(int n, int m) throws IOException { char[][] mat = new char[n][m]; for (int i = 0; i < n; i++) mat[i] = readCharArray(m); return mat; } // ========================= FOR OUTPUT ================================== private static void printIList(List<Integer> list) { for (int i = 0; i < list.size(); i++) out.print(list.get(i) + " "); out.println(" "); } private static void printLList(List<Long> list) { for (int i = 0; i < list.size(); i++) out.print(list.get(i) + " "); out.println(" "); } private static void printIArray(int[] arr) { for (int i = 0; i < arr.length; i++) out.print(arr[i] + " "); out.println(" "); } private static void print2DIArray(int[][] arr) { for (int i = 0; i < arr.length; i++) printIArray(arr[i]); } private static void printLArray(long[] arr) { for (int i = 0; i < arr.length; i++) out.print(arr[i] + " "); out.println(" "); } private static void print2DLArray(long[][] arr) { for (int i = 0; i < arr.length; i++) printLArray(arr[i]); } // ====================== TO CHECK IF STRING IS NUMBER ======================== private static boolean isInteger(String s) { try { Integer.parseInt(s); } catch (NumberFormatException e) { return false; } catch (NullPointerException e) { return false; } return true; } private static boolean isLong(String s) { try { Long.parseLong(s); } catch (NumberFormatException e) { return false; } catch (NullPointerException e) { return false; } return true; } // ==================== FASTER SORT ================================ private static void sort(int[] arr) { int n = arr.length; List<Integer> list = new ArrayList<>(); for (int i = 0; i < n; i++) list.add(arr[i]); Collections.sort(list); for (int i = 0; i < n; i++) arr[i] = list.get(i); } private static void sort(long[] arr) { int n = arr.length; List<Long> list = new ArrayList<>(); for (int i = 0; i < n; i++) list.add(arr[i]); Collections.sort(list); for (int i = 0; i < n; i++) arr[i] = list.get(i); } // ==================== MATHEMATICAL FUNCTIONS =========================== private static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } private static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } private static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } private static long lcm(long a, long b) { return (a / gcd(a, b)) * b; } private static long power(long a, long b) { if (b == 0) return 1L; long ans = power(a, b >> 1); ans *= ans; if ((b & 1) == 1) ans *= a; return ans; } private static int mod_power(int a, int b) { if (b == 0) return 1; int temp = mod_power(a, b / 2); temp %= mod; temp = (int) ((1L * temp * temp) % mod); if ((b & 1) == 1) temp = (int) ((1L * temp * a) % mod); return temp; } private static int multiply(int a, int b) { return (int) ((((1L * a) % mod) * ((1L * b) % mod)) % mod); } private static boolean isPrime(long n) { for (long i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } private static long nCr(long n, long r) { if (n - r > r) r = n - r; long ans = 1L; for (long i = r + 1; i <= n; i++) ans *= i; for (long i = 2; i <= n - r; i++) ans /= i; return ans; } // ==================== Primes using Seive ===================== private static List<Integer> SeivePrime(int n) { boolean[] prime = new boolean[n + 1]; Arrays.fill(prime, true); for (int i = 2; i * i <= n; i++) { if (prime[i]) { for (int j = i * i; j <= n; j += i) prime[j] = false; } } List<Integer> list = new ArrayList<>(); for (int i = 2; i <= n; i++) if (prime[i]) list.add(i); return list; } // ==================== STRING FUNCTIONS ================================ private static boolean isPalindrome(String str) { int i = 0, j = str.length() - 1; while (i < j) if (str.charAt(i++) != str.charAt(j--)) return false; return true; } private static String reverseString(String str) { StringBuilder sb = new StringBuilder(str); return sb.reverse().toString(); } // ==================== LIS & LNDS ================================ private static int LIS(int arr[], int n) { List<Integer> list = new ArrayList<>(); for (int i = 0; i < n; i++) { int idx = find(list, arr[i]); if (idx < list.size()) list.set(idx, arr[i]); else list.add(arr[i]); } return list.size(); } private static int find(List<Integer> list, int val) { int ret = list.size(), i = 0, j = list.size() - 1; while (i <= j) { int mid = (i + j) / 2; if (list.get(mid) >= val) { ret = mid; j = mid - 1; } else { i = mid + 1; } } return ret; } private static int LNDS(int[] arr, int n) { List<Integer> list = new ArrayList<>(); for (int i = 0; i < n; i++) { int idx = find2(list, arr[i]); if (idx < list.size()) list.set(idx, arr[i]); else list.add(arr[i]); } return list.size(); } private static int find2(List<Integer> list, int val) { int ret = list.size(), i = 0, j = list.size() - 1; while (i <= j) { int mid = (i + j) / 2; if (list.get(mid) <= val) { i = mid + 1; } else { ret = mid; j = mid - 1; } } return ret; } // ==================== UNION FIND ===================== private static int find(int x, int[] parent) { if (parent[x] == x) return x; return parent[x] = find(parent[x], parent); } private static boolean union(int x, int y, int[] parent, int[] rank) { int lx = find(x, parent), ly = find(y, parent); if (lx == ly) return true; if (rank[lx] > rank[ly]) parent[ly] = lx; else if (rank[lx] < rank[ly]) parent[lx] = ly; else { parent[lx] = ly; rank[ly]++; } return false; } // ==================== SEGMENT TREE (RANGE SUM) ===================== public static class SegmentTree { int n; int[] arr, tree, lazy; SegmentTree(int arr[]) { this.arr = arr; this.n = arr.length; this.tree = new int[(n << 2)]; this.lazy = new int[(n << 2)]; build(1, 0, n - 1); } void build(int id, int start, int end) { if (start == end) tree[id] = arr[start]; else { int mid = (start + end) / 2, left = (id << 1), right = left + 1; build(left, start, mid); build(right, mid + 1, end); tree[id] = tree[left] + tree[right]; } } void update(int l, int r, int val) { update(1, 0, n - 1, l, r, val); } void update(int id, int start, int end, int l, int r, int val) { distribute(id, start, end); if (end < l || r < start) return; if (start == end) tree[id] += val; else if (l <= start && end <= r) { lazy[id] += val; distribute(id, start, end); } else { int mid = (start + end) / 2, left = (id << 1), right = left + 1; update(left, start, mid, l, r, val); update(right, mid + 1, end, l, r, val); tree[id] = tree[left] + tree[right]; } } int query(int l, int r) { return query(1, 0, n - 1, l, r); } int query(int id, int start, int end, int l, int r) { if (end < l || r < start) return 0; distribute(id, start, end); if (start == end) return tree[id]; else if (l <= start && end <= r) return tree[id]; else { int mid = (start + end) / 2, left = (id << 1), right = left + 1; return query(left, start, mid, l, r) + query(right, mid + 1, end, l, r); } } void distribute(int id, int start, int end) { if (start == end) tree[id] += lazy[id]; else { tree[id] += lazy[id] * (end - start + 1); lazy[(id << 1)] += lazy[id]; lazy[(id << 1) + 1] += lazy[id]; } lazy[id] = 0; } } // ==================== TRIE ================================ static class Trie { class Node { Node[] children; boolean isEnd; Node() { children = new Node[26]; } } Node root; Trie() { root = new Node(); } public void insert(String word) { Node curr = root; for (char ch : word.toCharArray()) { if (curr.children[ch - 'a'] == null) curr.children[ch - 'a'] = new Node(); curr = curr.children[ch - 'a']; } curr.isEnd = true; } public boolean find(String word) { Node curr = root; for (char ch : word.toCharArray()) { if (curr.children[ch - 'a'] == null) return false; curr = curr.children[ch - 'a']; } return curr.isEnd; } } // ==================== FENWICK TREE ================================ static class FT { long[] tree; int n; FT(int[] arr, int n) { this.n = n; this.tree = new long[n + 1]; for (int i = 1; i <= n; i++) { update(i, arr[i - 1]); } } void update(int idx, int val) { while (idx <= n) { tree[idx] += val; idx += idx & -idx; } } long query(int l, int r) { return getSum(r) - getSum(l - 1); } long getSum(int idx) { long ans = 0L; while (idx > 0) { ans += tree[idx]; idx -= idx & -idx; } return ans; } } // ==================== BINARY INDEX TREE ================================ static class BIT { long[][] tree; int n, m; BIT(int[][] mat, int n, int m) { this.n = n; this.m = m; tree = new long[n + 1][m + 1]; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { update(i, j, mat[i - 1][j - 1]); } } } void update(int x, int y, int val) { while (x <= n) { int t = y; while (t <= m) { tree[x][t] += val; t += t & -t; } x += x & -x; } } long query(int x1, int y1, int x2, int y2) { return getSum(x2, y2) - getSum(x1 - 1, y2) - getSum(x2, y1 - 1) + getSum(x1 - 1, y1 - 1); } long getSum(int x, int y) { long ans = 0L; while (x > 0) { int t = y; while (t > 0) { ans += tree[x][t]; t -= t & -t; } x -= x & -x; } return ans; } } // ==================== OTHER CLASSES ================================ static class Pair implements Comparable<Pair> { int first, second; Pair(int first, int second) { this.first = first; this.second = second; } public int compareTo(Pair o) { return this.first - o.first; } } static class DequeNode { DequeNode prev, next; int val; DequeNode(int val) { this.val = val; } DequeNode(int val, DequeNode prev, DequeNode next) { this.val = val; this.prev = prev; this.next = next; } } }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
2f8781a0c5d218ca5402380f31ec96c6
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
import java.io.*; import java.util.*; public class D { static class Pair{ int one, two; int non_zero1, non_zero2; Pair(int one, int two, int non_zero1, int non_zero2){ this.one = one; this.two = two; this.non_zero1 = non_zero1; this.non_zero2 = non_zero2; } } static Pair getMaxMinIndex(Soumit sc, int a, int b, int c, int d) throws IOException { System.out.println("? "+b+" "+c+" "+d); System.out.flush(); int va = sc.nextInt(); System.out.println("? "+a+" "+c+" "+d); System.out.flush(); int vb = sc.nextInt(); System.out.println("? "+b+" "+a+" "+d); System.out.flush(); int vc = sc.nextInt(); System.out.println("? "+b+" "+c+" "+a); System.out.flush(); int vd = sc.nextInt(); if(va==vb && vb==vc && vc==vd){ return new Pair(a, b, c, d); } if(va==vb && vb==vc){ return new Pair(d, a, b, c); } else if(va==vc && vc==vd){ return new Pair(b, a, c, d); } else if(va==vb && vb==vd){ return new Pair(c, a, b, d); } else if(vb==vc && vc==vd){ return new Pair(a, b, c, d); } if(va==vb && ((vc!=vd) || (vc==vd && va>vc))) { return new Pair(c, d, a, b); } else if(va==vc && ((vb!=vd) || (vb==vd && va>vb))) { return new Pair(b, d, a, c); } else if(va==vd && ((vc!=vb) || (vc==vb && va>vc))) { return new Pair(b, c, a, d); } else if(vb==vc && ((va!=vd) || (va==vd && vb>vd))) { return new Pair(a, d, b, c); } else if(vb==vd && ((va!=vc) || (va==vc && vb>vc))) { return new Pair(a, c, b, d); } else { return new Pair(a, b, c, d); } } public static void main(String[] args) throws IOException { Soumit sc = new Soumit(); int t = sc.nextInt(); while(t-->0){ int n = sc.nextInt(); List<Integer> nonZeroIndexList = new ArrayList<>(); int a1 = 1, a2 = 2; for(int i=3;i<=n;i+=2){ if(i+1>n) break; Pair p = getMaxMinIndex(sc, a1, a2, i, i+1); a1 = p.one; a2 = p.two; nonZeroIndexList.add(p.non_zero1); nonZeroIndexList.add(p.non_zero2); } if(n%2==1){ Pair p = getMaxMinIndex(sc, a1, a2, n, nonZeroIndexList.get(0)); a1 = p.one; a2 = p.two; } System.out.println("! "+a1+" "+a2); System.out.flush(); } sc.close(); } static class Soumit { final private int BUFFER_SIZE = 1 << 18; final private DataInputStream din; final private byte[] buffer; private PrintWriter pw; private int bufferPointer, bytesRead; StringTokenizer st; public Soumit() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Soumit(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public void streamOutput(String file) throws IOException { FileWriter fw = new FileWriter(file); BufferedWriter bw = new BufferedWriter(fw); pw = new PrintWriter(bw); } public void println(String a) { pw.println(a); } public void print(String a) { pw.print(a); } public String readLine() throws IOException { byte[] buf = new byte[3000064]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } public void sort(int[] arr) { ArrayList<Integer> arlist = new ArrayList<>(); for (int i : arr) arlist.add(i); Collections.sort(arlist); for (int i = 0; i < arr.length; i++) arr[i] = arlist.get(i); } public void sort(long[] arr) { ArrayList<Long> arlist = new ArrayList<>(); for (long i : arr) arlist.add(i); Collections.sort(arlist); for (int i = 0; i < arr.length; i++) arr[i] = arlist.get(i); } public int[] nextIntArray(int n) throws IOException { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = nextInt(); } return arr; } public long[] nextLongArray(int n) throws IOException { long[] arr = new long[n]; for (int i = 0; i < n; i++) { arr[i] = nextLong(); } return arr; } public double[] nextDoubleArray(int n) throws IOException { double[] arr = new double[n]; for (int i = 0; i < n; i++) { arr[i] = nextDouble(); } return arr; } 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;*/ if (din != null) din.close(); if (pw != null) pw.close(); } } }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
9a916f04543281bdae5ba917e4c7e04c
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
import java.io.*; import java.util.InputMismatchException; public class E1634D { static FastIO io = new FastIO(); public static void main(String[] args) { int t = io.nextInt(); while (t-- > 0) { int n = io.nextInt(); int fMaxDiff = -1; int firstExtreme = -1; int secondExtreme = -1; boolean firstSame = true; for (int i = 3; i <= n; i++) { int p = get(1, 2, i); firstSame &= p == fMaxDiff || fMaxDiff == -1; if (p > fMaxDiff) { fMaxDiff = p; firstExtreme = i; secondExtreme = -1; } else if (p == fMaxDiff) secondExtreme = i; } boolean same = true; int maxDiff = -1; if (secondExtreme == -1) secondExtreme = 1; int ans = -1; for (int i = 1; i <= n; i++) { if (i == firstExtreme || i == secondExtreme) continue; int p = get(firstExtreme, secondExtreme, i); same &= p == maxDiff || maxDiff == -1; if (p > maxDiff) { maxDiff = p; ans = i; } } if (maxDiff <= fMaxDiff && firstSame) io.println("! 1 2 "); else if (same) io.println("! " + firstExtreme + " " + secondExtreme); else io.println("! " + firstExtreme + " " + ans); io.flush(); } io.close(); } static int get(int i, int j, int k) { io.println("? " + i + " " + j + " " + k); io.flush(); return io.nextInt(); } private static class FastIO extends PrintWriter { private final InputStream stream; private final byte[] buf = new byte[1 << 16]; private int curChar, numChars; // standard input public FastIO() { this(System.in, System.out); } public FastIO(InputStream i, OutputStream o) { super(o); stream = i; } // file input public FastIO(String i, String o) throws IOException { super(new FileWriter(o)); stream = new FileInputStream(i); } // throws InputMismatchException() if previously detected end of file private int nextByte() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars == -1) return -1; // end of file } return buf[curChar++]; } // to read in entire lines, replace c <= ' ' // with a function that checks whether c is a line break public String next() { int c; do { c = nextByte(); } while (c <= ' '); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = nextByte(); } while (c > ' '); return res.toString(); } public int nextInt() { // nextLong() would be implemented similarly int c; do { c = nextByte(); } while (c <= ' '); int sgn = 1; if (c == '-') { sgn = -1; c = nextByte(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res = 10 * res + c - '0'; c = nextByte(); } while (c > ' '); return res * sgn; } public long nextLong() { // nextLong() would be implemented similarly int c; do { c = nextByte(); } while (c <= ' '); int sgn = 1; if (c == '-') { sgn = -1; c = nextByte(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res = 10 * res + c - '0'; c = nextByte(); } while (c > ' '); return res * sgn; } public double nextDouble() { return Double.parseDouble(next()); } } }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
eae4dcc838d967502569d5ea109babcd
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; /** * @author Peter Li * @version 02/06/2022 */ public class DFindingZero { static int ask(int i, int j, int k) { System.out.printf("? %d %d %d\n", i, j ,k); System.out.flush(); int r = ni(); if (r == -1) { throw new RuntimeException(); } return r; } static void solution(int i, int j) { System.out.printf("! %d %d\n", i, j); System.out.flush(); } static void solve() { int n = ni(); int[] results = new int[n + 1]; int max = 0; int index = 0; for (int i = 3; i <= n; i++) { results[i] = ask(1, 2, i); if (results[i] > max) { max = results[i]; index = i; } } int max2 = 0; int index2 = 0; int[] results2 = new int[n + 1]; for (int i = 2; i <= n; i++) { if (i == index) { results2[i] = 0; continue; } results2[i] = i == 2 ? results[index] : ask(1, index, i); if (results2[i] > max2) { max2 = results2[i]; index2 = i; } } // System.out.printf("max = %d, max2 = %d\n", max, max2); if (max >= max2) { int o = -1; for (int i = 3; i <= n; i++) { if (i != index) { o = i; break; } } if (results[o] == max) { solution(1, 2); } else if (ask(2, index, o) == max) { solution(2, index); } else { solution(1, index); } return; } solution(index, index2); } public static void main(String[] args) throws IOException { int t = ni(); while (t-- > 0) { solve(); } } private static final String DELIMINATOR = " \n\r\f\t"; private final static BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 1 << 15); private static StringTokenizer st = new StringTokenizer("", DELIMINATOR); private static boolean hasNext() { makeStringTokenizerReady(); return st.hasMoreTokens(); } private static void makeStringTokenizerReady() { while (!st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine(), DELIMINATOR); } catch (IOException e) { e.printStackTrace(); } } } private static String ns() { makeStringTokenizerReady(); return st.nextToken(); } private static long nl() { return Long.parseLong(ns()); } private static int ni() { return (int) nl(); } private static double nd() { return Double.parseDouble(ns()); } private static int[] na(int n) { int[] ans = new int[n]; for (int i = 0; i < n; i++) { ans[i] = ni(); } return ans; } private static String[] nsa(int n) { String[] ans = new String[n]; for (int i = 0; i < n; i++) { ans[i] = ns(); } return ans; } }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
eee4e36d71dcfedd26fd57129579aa64
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
import java.io.*; import java.util.*; public class q4 { public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); // public static long mod = 1000000007; public static void solve() throws Exception { String[] parts = br.readLine().split(" "); int n = Integer.parseInt(parts[0]); boolean[] used = new boolean[n + 1]; int i = n,j = n - 1,k = n - 2,l = n - 3; while(i > 0 || j > 0 || k > 0 || l > 0){ if(i > 0 && (used[i] || i == j || i == k || i == l)) i--; else if(j > 0 && (used[j] || j == k || j == l)) j--; else if(k > 0 && (used[k] || k == l)) k--; else if(l > 0 && used[l]) l--; else{ int count = 0; if(i == 0) { count++; i = n; while(!used[i]) i--; } if(j == 0) { count++; j = n; while(!used[j]) j--; } if(k == 0) { count++; k = n; while(!used[k]) k--; } if(l == 0) { count++; l = n; while(!used[l]) l--; } if(count >= 2) break; System.out.println("? " + i + " " + j + " " + k); int v1 = Integer.parseInt(br.readLine()); System.out.println("? " + i + " " + j + " " + l); int v2 = Integer.parseInt(br.readLine()); System.out.println("? " + i + " " + k + " " + l); int v3 = Integer.parseInt(br.readLine()); System.out.println("? " + j + " " + k + " " + l); int v4 = Integer.parseInt(br.readLine()); int max = Math.max(v1,Math.max(v2,Math.max(v3,v4))); if(v1 == max && v2 == max){ used[k--] = true; used[l--] = true; }else if(v1 == max && v3 == max){ used[j--] = true; used[l--] = true; }else if(v1 == max && v4 == max){ used[i--] = true; used[l--] = true; }else if(v2 == max && v3 == max){ used[j--] = true; used[k--] = true; }else if(v2 == max && v4 == max){ used[i--] = true; used[k--] = true; }else if(v3 == max && v4 == max){ used[i--] = true; used[j--] = true; } } } int cnt = 0; System.out.print("! "); for(i = 1;i <= n;i++) { if(!used[i]) { System.out.print(i + " "); cnt++; } } if(cnt == 1) System.out.print(n + " "); System.out.println(); } public static void main(String[] args) throws Exception { int tests = Integer.parseInt(br.readLine()); for (int test = 1; test <= tests; test++) { solve(); } } // public static ArrayList<Integer> primes; // public static void seive(int n){ // primes = new ArrayList<>(); // boolean[] arr = new boolean[n + 1]; // Arrays.fill(arr,true); // // for(int i = 2;i * i <= n;i++){ // if(arr[i]) { // for (int j = i * i; j <= n; j += i) { // arr[j] = false; // } // } // } // for(int i = 2;i <= n;i++) if(arr[i]) primes.add(i); // } // public static void sort(int[] arr){ // ArrayList<Integer> temp = new ArrayList<>(); // for(int val : arr) temp.add(val); // // Collections.sort(temp); // // for(int i = 0;i < arr.length;i++) arr[i] = temp.get(i); // } // public static void sort(long[] arr){ // ArrayList<Long> temp = new ArrayList<>(); // for(long val : arr) temp.add(val); // // Collections.sort(temp); // // for(int i = 0;i < arr.length;i++) arr[i] = temp.get(i); // } // // public static long power(long a,long b,long mod){ // if(b == 0) return 1; // // long p = power(a,b / 2,mod); // p = (p * p) % mod; // // if(b % 2 == 1) return (p * a) % mod; // return p; // } // public static long modDivide(long a,long b,long mod){ // return ((a % mod) * (power(b,mod - 2,mod) % mod)) % mod; // } // // public static int GCD(int a,int b){ // return b == 0 ? a : GCD(b,a % b); // } // public static long GCD(long a,long b){ // return b == 0 ? a : GCD(b,a % b); // } // // public static int LCM(int a,int b){ // return a * b / GCD(a,b); // } // public static long LCM(long a,long b){ // return a * b / GCD(a,b); // } }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
741ef6cd376839264d7e99c1f311988c
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
import java.util.ArrayDeque; import java.util.Scanner; public class Main { public static void main(String[] args) { var sc = new Scanner(System.in); int T = Integer.parseInt(sc.next()); for(int t = 0; t < T; t++){ int n = Integer.parseInt(sc.next()); var deque = new ArrayDeque<Integer>(); for(int i = 1; i <= n; i++){ deque.add(i); } var deque2 = new ArrayDeque<Integer>(); while(deque.size() > 2){ while(deque.size() < 4){ deque.add(deque2.poll()); } var a = new int[4]; for(int i = 0; i < 4; i++){ a[i] = deque.poll(); } var b = new int[4]; System.out.println("? " + a[1] + " " + a[2] + " " + a[3]); System.out.flush(); b[0] = Integer.parseInt(sc.next()); if(b[0] == -1) return; System.out.println("? " + a[0] + " " + a[2] + " " + a[3]); System.out.flush(); b[1] = Integer.parseInt(sc.next()); if(b[1] == -1) return; System.out.println("? " + a[0] + " " + a[1] + " " + a[3]); System.out.flush(); b[2] = Integer.parseInt(sc.next()); if(b[2] == -1) return; System.out.println("? " + a[0] + " " + a[1] + " " + a[2]); System.out.flush(); b[3] = Integer.parseInt(sc.next()); if(b[3] == -1) return; int max = 0; for(int i = 0; i < 4; i++){ max = Math.max(b[i], max); } for(int i = 0; i < 4; i++){ if(b[i] != max){ deque.add(a[i]); }else{ deque2.add(a[i]); } } } if(deque.size() == 1){ System.out.println("! " + deque.poll() + " 1"); }else{ System.out.println("! " + deque.poll() + " " + deque.poll()); } System.out.flush(); } } }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
9aef605908d1373488ada7783ab106be
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
import java.util.*; import java.io.*; public class FindingZero { public static void main(String[] args) throws IOException { Reader in = new Reader(); PrintWriter out = new PrintWriter(System.out); int T = in.nextInt(); for (int t = 0; t < T; t++) { int N = in.nextInt(); int[] dist = new int[N]; int max = 2; for (int i = 2; i < N; i++) { out.println("? 1 2 " + (i + 1)); out.flush(); dist[i] = in.nextInt(); if (dist[i] > dist[max]) { max = i; } } dist[1] = dist[max]; int max2 = 1; for (int i = 2; i < N; i++) { if (i == max) { continue; } out.println("? 1 " + (max + 1) + " " + (i + 1)); out.flush(); dist[i] = in.nextInt(); if (dist[i] > dist[max2]) { max2 = i; } } int size = dist[max2]; int[] arr = new int[]{0, max, max2}; int next = 0; while (next == arr[0] || next == arr[1] || next == arr[2]) { next++; } List<Integer> res = new ArrayList<>(); for (int i = 0; i < 3; i++) { int[] arr2 = Arrays.copyOf(arr, 3); arr2[i] = next; out.println("? " + (arr2[0] + 1) + " " + (arr2[1] + 1) + " " + (arr2[2] + 1)); out.flush(); if (in.nextInt() < size) { res.add(arr[i]); } } out.println("! " + (res.get(0) + 1) + " " + (res.size() == 1 ? res.get(0) + 1 : res.get(1) + 1)); out.flush(); } out.close(); } public static int gcd(int a, int b) { if (a == 0) { return b; } return gcd(b % a, a); } static class Reader { BufferedReader in; StringTokenizer st; public Reader() { in = new BufferedReader(new InputStreamReader(System.in)); st = new StringTokenizer(""); } public String nextLine() throws IOException { st = new StringTokenizer(""); return in.readLine(); } public String next() throws IOException { while (!st.hasMoreTokens()) { st = new StringTokenizer(in.readLine()); } return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } } public static void sort(int[] arr) { List<Integer> list = new ArrayList<>(); for (int i : arr) { list.add(i); } Collections.sort(list); for (int i = 0; i < arr.length; i++) { arr[i] = list.get(i); } } }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
c78be53a8eec868e57ce4f2936ae8d1c
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
import java.io.*; import java.math.BigInteger; import java.util.*; public class Main { static int MOD = 1000000007; // After writing solution, quick scan for: // array out of bounds // special cases e.g. n=1? // npe, particularly in maps // // Big numbers arithmetic bugs: // int overflow // if (x : long) and (y : int), [y = x] does not compile, but [y += x] does // sorting, or taking max, after MOD void solve() throws IOException { int T = ri(); for (int Ti = 0; Ti < T; Ti++) { int n = ri(); // 4 <= n <= 1000 queriesMade = 0; // nums are the indices that are still in the game nums = new ArrayList<>(); for (int i = 1; i <= n; i++) nums.add(i); while (nums.size() > 3) { List<Integer> next = new ArrayList<>(); int i = 0; while (i + 3 < nums.size()) { int a = query(i, i+1, i+2); int b = query(i, i+2, i+3); int c = query(i, i+1, i+3); int d = query(i+1, i+2, i+3); int max = Math.max(a, Math.max(b, Math.max(c, d))); if (a == max && b == max) { next.add(nums.get(i)); next.add(nums.get(i+2)); } else if (a == max && c == max) { next.add(nums.get(i)); next.add(nums.get(i+1)); } else if (a == max && d == max) { next.add(nums.get(i+1)); next.add(nums.get(i+2)); } else if (b == max && c == max) { next.add(nums.get(i)); next.add(nums.get(i+3)); } else if (b == max && d == max) { next.add(nums.get(i+2)); next.add(nums.get(i+3)); } else if (c == max && d == max) { next.add(nums.get(i+1)); next.add(nums.get(i+3)); } i += 4; } while (i < nums.size()) { next.add(nums.get(i)); i++; } if (next.size() == 3) { int a = next.get(0); int b = next.get(1); int c = next.get(2); int d = -1; // find an arbitrary guy for (int ii = 1; d == -1 && ii <= n; ii++) { if (ii != a && ii != b && ii != c) { d = ii; } } next.add(d); } nums = next; } if (nums.size() == 1) { int x = nums.get(0); pw.println("! " + x + " " + x); } else if (nums.size() == 2) { int x = nums.get(0); int y = nums.get(1); pw.println("! " + x + " " + y); } else { // pw.println(nums); } pw.flush(); } } // IMPORTANT // DID YOU CHECK THE COMMON MISTAKES ABOVE? List<Integer> nums; int queriesMade; int query(int i, int j, int k) throws IOException { queriesMade++; pw.println("? " + nums.get(i) + " " + nums.get(j) + " " + nums.get(k)); pw.flush(); return ri(); } // Template code below BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out); public static void main(String[] args) throws IOException { Main m = new Main(); m.solve(); m.close(); } void close() throws IOException { pw.flush(); pw.close(); br.close(); } int ri() throws IOException { return Integer.parseInt(br.readLine().trim()); } long rl() throws IOException { return Long.parseLong(br.readLine().trim()); } int[] ril(int n) throws IOException { int[] nums = new int[n]; int c = 0; for (int i = 0; i < n; i++) { int sign = 1; c = br.read(); int x = 0; if (c == '-') { sign = -1; c = br.read(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = br.read(); } nums[i] = x * sign; } while (c != '\n' && c != -1) c = br.read(); return nums; } long[] rll(int n) throws IOException { long[] nums = new long[n]; int c = 0; for (int i = 0; i < n; i++) { int sign = 1; c = br.read(); long x = 0; if (c == '-') { sign = -1; c = br.read(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = br.read(); } nums[i] = x * sign; } while (c != '\n' && c != -1) c = br.read(); return nums; } int[] rkil() throws IOException { int c = br.read(); int x = 0; while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = br.read(); } return ril(x); } long[] rkll() throws IOException { int c = br.read(); int x = 0; while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = br.read(); } return rll(x); } char[] rs() throws IOException { return br.readLine().toCharArray(); } void sort(int[] A) { Random r = new Random(); for (int i = A.length-1; i > 0; i--) { int j = r.nextInt(i+1); int temp = A[i]; A[i] = A[j]; A[j] = temp; } Arrays.sort(A); } void printDouble(double d) { pw.printf("%.16f", d); } }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
127b399c538573420ad4697294fc8a14
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
import java.io.*; import java.util.*; public class CF1634D extends PrintWriter { CF1634D() { super(System.out, true); } Scanner sc = new Scanner(System.in); public static void main(String[] $) { CF1634D o = new CF1634D(); o.main(); o.flush(); } int query(int i, int j, int k) { println("? " + i + " " + j + " " + k); return sc.nextInt(); } void main() { int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int i = 1, j = 2, d = 0; for (int k = 3; k <= n; k += 2) { int l; if (k < n) l = k + 1; else if (i != 1 && j != 1) l = 1; else if (i != 2 && j != 2) l = 2; else l = 3; int ijk = query(i, j, k); int ijl = query(i, j, l); int ikl = query(i, k, l); int jkl = query(j, k, l); d = Math.max(d, ijk); d = Math.max(d, ijl); d = Math.max(d, ikl); d = Math.max(d, jkl); if (ijk == d && ijl == d) { i = i; j = j; } else if (ijk == d && ikl == d) { i = i; j = k; } else if (ijl == d && ikl == d) { i = i; j = l; } else if (ijk == d && jkl == d) { i = j; j = k; } else if (ijl == d && jkl == d) { i = j; j = l; } else if (ikl == d && jkl == d) { i = k; j = l; } } println("! " + i + " " + j); } } }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
b43e38d6869cd0967fc3683472a0ce86
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
import java.io.*; import java.util.*; import static java.lang.Math.*; public class D{ static int cnt; static int query(int a, int b, int c) throws IOException{ if (debug) { System.out.println(++cnt + " queries"); return max(arr[a], max(arr[b], arr[c])) - min(arr[a], min(arr[b], arr[c])); } System.out.println("? " + ++a + " " + ++b + " " + ++c); return readInt(); } static boolean debug = false; static int[] arr = new int[] {1,2,0,3}; public static void main(String[] args) throws IOException{ // br = new BufferedReader(new FileReader(".in")); // out = new PrintWriter(new FileWriter(".out")); // new Thread(null, new (), "fisa balls", 1<<28).start(); int t= readInt(); while(t-->0) { int n =readInt(); int cur = query(0,1,2); int i = 0, j = 1, k = 2; for (int l = 3; l < n; l++) { int next = query(i, j, l); int next2 = query(i, l, k); if (cur >= max(next,next2)) continue; // Can't improve cur = max(next,next2); if (next > next2) { k=l; } else { j=l; } } int tar = 0; for (tar = 0; tar < n; tar++) if (tar != i && tar != j && tar != k) break; int test1 = query(i, j, tar); int test2 = query(i, tar, k); int test3 = query(tar, j, k); //System.out.println("MAx diff is " + cur); // System.out.println(i + " " + j + " " + k); int a1 = 0, a2 = 0; if (test1 >= max(test2,test3)) { a1=i; a2=j; } else if (test2 >= max(test1,test3)) { a1 = i; a2 = k; } else { a1 = j; a2 = k; } System.out.println("! " + ++a1 + " " + ++a2); } } static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); //static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); static StringTokenizer st = new StringTokenizer(""); static String read() throws IOException{ while (!st.hasMoreElements()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public static int readInt() throws IOException{return Integer.parseInt(read());} public static long readLong() throws IOException{return Long.parseLong(read());} }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
4721ad2f23c9ddc876e889f5ba2b9884
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
import java.io.*; import java.util.*; public class Codeforces { public static void main(String args[])throws Exception { BufferedReader bu=new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb=new StringBuilder(); int t=Integer.parseInt(bu.readLine()); while(t-->0) { int n=Integer.parseInt(bu.readLine()); int i,max1[]=new int[n],max2[]=new int[n]; for(i=2;i<n;i++) { System.out.println("? 1 2 "+(i+1)); System.out.flush(); max1[i]=Integer.parseInt(bu.readLine()); } int m1=2,m2; for(i=3;i<n;i++) if(max1[i]>max1[m1]) m1=i; for(i=2;i<n;i++) if(i!=m1) { System.out.println("? 1 "+(m1+1)+" "+(i+1)); System.out.flush(); max2[i]=Integer.parseInt(bu.readLine()); } m2=0; max2[0]=-1; for(i=2;i<n;i++) if(i!=m1 && max2[i]>max2[m2]) m2=i; int op[]={0,1,m1,m2},c[][][]=new int[4][4][4],j,k; for(i=0;i<4;i++) for(j=0;j<4;j++) Arrays.fill(c[i][j],-1); c[0][1][2]=max1[m1]; c[0][1][3]=max1[m2]; c[0][2][3]=max2[m2]; System.out.println("? 2 "+(m1+1)+" "+(m2+1)); System.out.flush(); c[1][2][3]=Integer.parseInt(bu.readLine()); for(i=0;i<4;i++) for(j=0;j<4;j++) for(k=0;k<4;k++) if(i==j || i==k || k==j) continue; else //all permutations of the 3 indices { int mx=Math.max(Math.max(Math.max(c[i][j][k],c[i][k][j]),Math.max(c[j][i][k],c[j][k][i])),Math.max(c[k][i][j],c[k][j][i])); c[i][j][k]=c[i][k][j]=c[j][i][k]=c[j][k][i]=c[k][i][j]=c[k][j][i]=mx; } int hi=-1,cnh=0; ArrayList<Integer> ans=new ArrayList<>(); for(i=0;i<4;i++) for(j=i+1;j<4;j++) //check most occurring pair { int mc=-1,cnt=0; for(k=0;k<4;k++) if(k!=i && k!=j) mc=Math.max(mc,c[i][j][k]); for(k=0;k<4;k++) if(k!=i && k!=j && mc==c[i][j][k]) cnt++; if(mc>hi) { hi=mc; cnh=cnt; ans.clear(); ans.add(op[i]); ans.add(op[j]); } else if(mc==hi && cnt>cnh) { cnh=cnt; ans.clear(); ans.add(op[i]); ans.add(op[j]); } } System.out.println("! "+(ans.get(0)+1)+" "+(ans.get(1)+1)); System.out.flush(); } } }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
e10e418e4b48563384a6770067c32890
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
import java.io.*; import java.util.*; public class CodeForces { static reader input = new reader(); static PrintWriter output = new PrintWriter(System.out); public static void main(String[] args) throws IOException { D(); output.close(); } public static void A() { } public static void B(){ int t=input.nextInt(); for(int i=0;i<t;i++) { int n = input.nextInt(), a = input.nextInt(); long y= input.nextLong(); long sum=0; for(int j=0;j<n;j++) sum+=input.nextInt(); if((a+sum)%2==y%2){ output.println("Alice"); }else{ output.println("Bob"); } } } public static void C(){ int t= input.nextInt(); for(int x=0;x<t;x++){ int n=input.nextInt(),k= input.nextInt(); int odd=((n*k)+1)/2,even=(n*k)/2; if(odd%k!=0||even%k!=0){ output.println("NO"); }else{ output.println("YES"); int curr1=1,curr2=2; for(int i=0;i<n;i++){ if(curr1<=n*k){ for(int j=0;j<k;j++){ output.print(curr1+" "); curr1+=2; } }else{ for(int j=0;j<k;j++){ output.print(curr2+" "); curr2+=2; } } output.println(); } } } } public static void D(){ int t=input.nextInt(); for(int i=0;i<t;i++){ int n= input.nextInt(); int ans1=1,ans2=2; for(int j=3;j<n;j+=2){ int sort[]=new int[4]; output.println("? "+ans1+" "+ans2+" "+j); output.flush(); int val4=input.nextInt(); sort[0]=val4; output.println("? "+ans1+" "+ans2+" "+(j+1)); output.flush(); int val3=input.nextInt(); sort[1]=val3; output.println("? "+ans1+" "+j+" "+(j+1)); output.flush(); int val2=input.nextInt(); sort[2]=val2; output.println("? "+ans2+" "+j+" "+(j+1)); output.flush(); int val1=input.nextInt(); sort[3]=val1; Arrays.sort(sort); int temp1,temp2; if(sort[0]==val1){ temp1=ans1; if(sort[1]==val2){ temp2=ans2; }else if(sort[1]==val3) { temp2 = j; }else { temp2 = j + 1; } }else if(sort[0]==val2){ temp1=ans2; if(sort[1]==val1){ temp2=ans1; }else if(sort[1]==val3) { temp2 = j; }else { temp2 = j + 1; } }else if(sort[0]==val3){ temp1=j; if(sort[1]==val1){ temp2=ans1; }else if(sort[1]==val2) { temp2 = ans2; }else { temp2 = j + 1; } }else{ temp1=j+1; if(sort[1]==val1){ temp2=ans1; }else if(sort[1]==val2) { temp2 = ans2; }else { temp2 = j; } } ans1=temp1; ans2=temp2; } if(n%2==1){ int sort[]=new int[4]; int temp=0; for(int j=1;j<n;j++){ if(j!=ans1&&j!=ans2){ temp=j; break; } } output.println("? "+ans1+" "+ans2+" "+n); output.flush(); int val4=input.nextInt(); sort[0]=val4; output.println("? "+ans1+" "+ans2+" "+(temp)); output.flush(); int val3=input.nextInt(); sort[1]=val3; output.println("? "+ans1+" "+n+" "+(temp)); output.flush(); int val2=input.nextInt(); sort[2]=val2; output.println("? "+ans2+" "+n+" "+(temp)); output.flush(); int val1=input.nextInt(); sort[3]=val1; Arrays.sort(sort); int temp1,temp2; if(sort[0]==val1){ temp1=ans1; if(sort[1]==val2){ temp2=ans2; }else if(sort[1]==val3) { temp2 = n; }else { temp2 = temp; } }else if(sort[0]==val2){ temp1=ans2; if(sort[1]==val1){ temp2=ans1; }else if(sort[1]==val3) { temp2 = n; }else { temp2 = temp; } }else if(sort[0]==val3){ temp1=n; if(sort[1]==val1){ temp2=ans1; }else if(sort[1]==val2) { temp2 = ans2; }else { temp2 = temp; } }else{ temp1=temp; if(sort[1]==val1){ temp2=ans1; }else if(sort[1]==val2) { temp2 = ans2; }else { temp2 = n; } } ans1=temp1; ans2=temp2; } output.println("! "+ans1+" "+ans2); output.flush(); } } public static void E(){ } public static void F(){ } public static long Factorial(int a){ long ans=1; for(int i=1;i<=a;i++){ ans*=i; } return ans; } public static long LCM(long a,long b){ return (a*b)/GCD(a,b); } public static long GCD(long a,long b){ if(a==0) return b; else if(b==0) return a; else return GCD(b%a,a); } public static boolean isPrime(long num){ if(num==1) return false; else if(num==2||num==3) return true; else if(num%2==0||num%3==0) return false; else{ for(long i=5;i*i<=num;i+=6){ if(num%i==0||num%(i+2)==0) return false; } } return true; } public static ArrayList<Integer> SieveofEratothenis(){ ArrayList<Integer>ans=new ArrayList<>(); boolean visited[]=new boolean[1000000]; for(int i=2;i<1000000;i++){ if(!visited[i]){ ans.add(i); for(long j=(long)i*i;j<1000000;j+=i){ visited[(int)j]=true; } } } return ans; } public static int EulerTotient(int n){ int ans=n; for(int i=2;i*i<=n;i++){ if(n%i==0){ while(n%i==0){ n/=i; } ans/=i; ans*=(i-1); if(n==1) break; } } if(n!=1) { ans /= n; ans *= (n - 1); } return ans; } public static void mergesort(long arr[],int start,int end){//start and end must be indexes if(start<end) { int mid=(start+end)/2; mergesort(arr,start,mid); mergesort(arr, mid+1, end); merge(arr, start,mid,end); } } public static void merge(long arr[],int start,int mid,int end){ int lsize=mid-start+1,rsize=end-mid; long l[]=new long[lsize],r[]=new long[rsize]; for(int i=start;i<=mid;i++){ l[i-start]=arr[i]; } for(int i=mid+1;i<=end;i++){ r[i-mid-1]=arr[i]; } int i=0,j=0,k=start; while(i<lsize&&j<rsize){ if(l[i]<=r[j]){ arr[k++]=l[i++]; }else{ arr[k++]=r[j++]; } } while(i<lsize) arr[k++]=l[i++]; while(j<rsize) arr[k++]=r[j++]; } } class Value{ long ans; Value(int ans) { this.ans=ans; } } class Triple{ int x,y,z; Triple(int x,int y,int z){ this.x=x; this.y=y; this.z=z; } } class Pair{ int num; int val; Pair(int num,int val){ this.num=num; this.val=val; } @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Pair)) return false; Pair pair = (Pair) o; return num == pair.num && val == pair.val; } @Override public int hashCode() { return Objects.hash(num, val); } } class IO{ BufferedReader bf; PrintWriter pw; StringTokenizer st; public IO() throws IOException { bf = new BufferedReader(new FileReader("input.txt")); pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt"))); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(bf.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 = bf.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public int[] nextIntArray(int arraySize) { int array[] = new int[arraySize]; for (int i = 0; i < arraySize; i++) { array[i] = nextInt(); } return array; } public long[] nextLongArray(int arraySize) { long array[] = new long[arraySize]; for (int i = 0; i < arraySize; i++) { array[i] = nextLong(); } return array; } } class reader { BufferedReader br; StringTokenizer st; public reader() { 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; } public int[] nextIntArray(int arraySize) { int array[] = new int[arraySize]; for (int i = 0; i < arraySize; i++) { array[i] = nextInt(); } return array; } public long[] nextLongArray(int arraySize) { long array[] = new long[arraySize]; for (int i = 0; i < arraySize; i++) { array[i] = nextLong(); } return array; } }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
b9aed1b1c04b3060809d4567ca730bf1
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
import java.util.*; import java.util.stream.Collectors; public class D_Zero { public static void main(String[] args) { Scanner in = new Scanner(System.in); int tasks = in.nextInt(); while (tasks-- > 0) { int length = in.nextInt(); List<Integer> workingSet = new ArrayList<>(List.of(1, 2)); int index = 3; while (index <= length) { workingSet.add(index++); if (index > length) { workingSet.add(getFirstMissingIndex(workingSet, length)); } else { workingSet.add(index++); } workingSet = reduceSet(in, workingSet); } System.out.println("! " + workingSet.stream().map(Objects::toString).collect(Collectors.joining(" "))); } } private static int getFirstMissingIndex(List<Integer> workingSet, int length) { for (int i = 1; i <= length; i++) { if (!workingSet.contains(i)) { return i; } } throw new IllegalStateException(); } private static List<Integer> reduceSet(Scanner in, List<Integer> workingSet) { Map<Integer, Long> results = new HashMap<>(); for (Integer index : workingSet) { List<Integer> complementarySet = new ArrayList<>(workingSet); complementarySet.remove(index); System.out.println("? " + complementarySet.stream().map(Objects::toString).collect(Collectors.joining(" "))); results.put(index, in.nextLong()); } return results.entrySet().stream() .sorted(Comparator.comparingLong(Map.Entry::getValue)) .limit(2) .map(Map.Entry::getKey) .collect(Collectors.toList()); } }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
9e9ec3cc6e8c097d137c5233e39ef0aa
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
import java.util.*; import java.io.*; public class Main { 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()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static FastReader obj = new FastReader(); public static PrintWriter out = new PrintWriter(System.out); public static void sort(long[] a) { ArrayList<Long> arr = new ArrayList<>(); for (int i = 0; i < a.length; i++) arr.add(a[i]); Collections.sort(arr); for (int i = 0; i < arr.size(); i++) a[i] = arr.get(i); } public static void revsort(long[] a) { ArrayList<Long> arr = new ArrayList<>(); for (int i = 0; i < a.length; i++) arr.add(a[i]); Collections.sort(arr, Collections.reverseOrder()); for (int i = 0; i < arr.size(); i++) a[i] = arr.get(i); } //Cover the small test cases like for n=1 . public static class pair { long a; long b; pair(long x, long y) { a = x; b = y; } } public static long l() { return obj.nextLong(); } public static int i() { return obj.nextInt(); } public static String s() { return obj.next(); } public static long[] l(int n) { long[] arr = new long[n]; for (int i = 0; i < n; i++) arr[i] = l(); return arr; } public static int[] i(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = i(); return arr; } public static long ceil(long a, long b) { return (a + b - 1) / b; } public static void p(long val) { out.println(val); } public static void p(String s) { out.println(s); } public static void pl(long[] arr) { for (int i = 0; i < arr.length; i++) { out.print(arr[i] + " "); } out.println(); } public static void p(int[] arr) { for (int i = 0; i < arr.length; i++) { out.print(arr[i] + " "); } out.println(); } public static void sortpair(Vector<pair> arr) { //ascending just change return 1 to return -1 and vice versa to get descending. //compare based on value of pair.a arr.sort(new Comparator<pair>() { public int compare(pair o1, pair o2) { long val = o1.a - o2.a; if (val == 0) return 0; else if (val > 0) return 1; else return -1; } }); } // Take of the small test cases such as when n=1,2 etc. // remember in case of fenwick tree ft is 1 based but our array should be 0 based. // in fenwick tree when we update some index it doesn't change the value to val but it // adds the val value in it so remember to add val-a[i] instead of just adding val. //in case of finding the inverse mod do it (biexpo(a,mod-2)%mod + mod )%mod public static int ask(int a,int b,int c) { System.out.println("? "+a+" "+b+" "+c); System.out.flush(); int g=i(); return g; } public static void p(int a,int b) { System.out.println("! "+a+" "+b); System.out.flush(); } public static void main(String[] args) { int len = i(); while (len-- != 0) { int n = i(); int a=2; int b=3; if(ask(1,2,3)>ask(1,3,4)) { a=3; b=4; } int max=0; int in=0; for(int i=1;i<=n;i++) { if(i==a || i==b)continue; int g=ask(a,b,i); if(max<g) { max=g; in=i; } } int c=in; HashSet<Integer> h=new HashSet<>(); max=0; in=0; for(int i=1;i<=n;i++) { if(i==a || i==c)continue; int g=ask(a,i,c); h.add(g); if(g>max) { max=g; in=i; } } if(h.size()==1) { p(a,c); } else { p(in,c); } } out.flush(); } }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
b44a5c0c7f7bd693cbe302c1daa4736f
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
import java.io.*; import java.util.*; public class CF1634D extends PrintWriter { CF1634D() { super(System.out, true); } Scanner sc = new Scanner(System.in); public static void main(String[] $) { CF1634D o = new CF1634D(); o.main(); o.flush(); } int query(int i, int j, int k) { println("? " + i + " " + j + " " + k); return sc.nextInt(); } void main() { int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int i = 1, j = 2, d = 0; for (int k = 3; k <= n; k += 2) { int l; if (k < n) l = k + 1; else if (i != 1 && j != 1) l = 1; else if (i != 2 && j != 2) l = 2; else l = 3; int ijk = query(i, j, k); int ijl = query(i, j, l); int ikl = query(i, k, l); int jkl = query(j, k, l); d = Math.max(d, ijk); d = Math.max(d, ijl); d = Math.max(d, ikl); d = Math.max(d, jkl); if (ijk == d && ijl == d) { i = i; j = j; } else if (ijk == d && ikl == d) { i = i; j = k; } else if (ijl == d && ikl == d) { i = i; j = l; } else if (ijk == d && jkl == d) { i = j; j = k; } else if (ijl == d && jkl == d) { i = j; j = l; } else if (ikl == d && jkl == d) { i = k; j = l; } } println("! " + i + " " + j); } } }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
6bf7c91f49005170fa7ad894e5a21ac1
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
import java.io.*; import java.util.*; public class D { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); int t = Integer.parseInt(br.readLine()); while(t --> 0) { int n = Integer.parseInt(br.readLine()); int max = -1; ArrayList<Integer> vals = new ArrayList<Integer>(); for(int i = 2; i < n; i++) { pw.println("? " + "1 2 " + (i+1)); pw.flush(); int res = Integer.parseInt(br.readLine()); if(res > max) { vals.clear(); max = res; } if(res == max) vals.add(i); } if(vals.size() == 1) { int i1 = vals.get(0); int i2 = 0; int nmax = -1; ArrayList<Integer> nvals = new ArrayList<Integer>(); for(int i = 0; i < n; i++) { if(i != i1 && i != i2) { pw.println("? " + (1+i1) + " " + (1+i2) + " " + (1+i)); pw.flush(); int res = Integer.parseInt(br.readLine()); if(res > nmax) { nvals.clear(); nmax = res; } if(res == nmax) nvals.add(i); } } if(nvals.size() > 1) pw.println("! 1" + " " + (i1+1)); else pw.println("! " + (nvals.get(0)+1) + " " + (i1+1)); pw.flush(); }else { int i1 = vals.get(0); int i2 = vals.get(1); int nmax = -1; ArrayList<Integer> nvals = new ArrayList<Integer>(); for(int i = 0; i < n; i++) { if(i != i1 && i != i2) { pw.println("? " + (1+i1) + " " + (1+i2) + " " + (1+i)); pw.flush(); int res = Integer.parseInt(br.readLine()); if(res > nmax) { nvals.clear(); nmax = res; } if(res == nmax) nvals.add(i); } } if(nmax < max) { pw.println("! " + 1 + " " + 2); pw.flush(); }else if(nvals.size() > 1) { pw.println("! " + (i1+1) + " " + (1+i2)); pw.flush(); }else { pw.println("! " + (1+nvals.get(0)) + " " + (1+nvals.get(0))); pw.flush(); } } } pw.close(); } }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
05358a13b8d0dc8e935d864093dc258d
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
import java.io.*; import java.util.*; public class d { public static void main(String[] args) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); int numcases = Integer.parseInt(in.readLine()); for (int casenum = 0; casenum < numcases; casenum++) { int n = Integer.parseInt(in.readLine()); int[] usefulness = new int[n]; TreeSet<Integer> use = new TreeSet<>(); TreeSet<Integer> elim = new TreeSet<>(); for (int i = 0; i < n; i++) { use.add(i); } while (use.size() >= 3) { int[] q = new int[4]; int[] qs = new int[4]; q[0] = use.first(); q[1] = use.higher(q[0]); q[2] = use.higher(q[1]); q[3] = use.higher(q[2]) == null ? elim.first() : use.higher(q[2]); int[][] inp = new int[4][3]; for (int i = 0; i < 4; i++) { int cnt = 0; for (int j = 0; j < 4; j++) { if (i == j) continue; inp[i][cnt] = q[j]; cnt++; } qs[i] = query(inp[i], in); } int max = Math.max(Math.max(qs[0], qs[1]), Math.max(qs[2], qs[3])); int maxcnt = 0; for (int i : qs) { if (i == max) maxcnt++; } if (maxcnt == 4) { for (int k : q) { use.remove(k); elim.add(k); } } else if (maxcnt == 3) { int not = 0; for (int i = 0; i < qs.length; i++) { if (qs[i] != max) { not = i; } } for (int i : inp[not]) { use.remove(i); elim.add(i); } } else if (maxcnt == 2) { Set<Integer> set = new HashSet<>(); for (int i = 0; i < inp.length; i++) { if (qs[i] == max) { if (set.size() == 0) { for (int k : inp[i]) { set.add(k); } } else { Set<Integer> set2 = new HashSet<>(); for (int k : inp[i]) { set2.add(k); } set.retainAll(set2); } } } for (int i : q) { if (!set.contains(i)) { use.remove(i); elim.add(i); } } } } System.out.println("! " + (use.first() + 1) + " " + (use.last() + 1)); } in.close(); out.close(); } public static int query(int[] q, BufferedReader in) throws Exception { System.out.println("? " + (q[0] + 1) + " " + (q[1] + 1) + " " + (q[2] + 1)); System.out.flush(); int answer = Integer.parseInt(in.readLine()); return answer; } }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
db459574fa75ff4bd497d8aba6f22151
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
import java.io.*; import java.util.*; public class Main { private static void run(Judge judge, boolean wrapper) { judge = wrapper ? new JudgeWrapper(judge) : judge; int t = Integer.parseInt(judge.next()); for (int i = 0; i < t; i++) { Solver solver = new Solver(judge); solver.run(); } } private static void runOnline(boolean wrapper) { run(new OnlineJudge(), wrapper); } private static void runOffline(boolean wrapper) { // TODO: Set problem instance secret. OfflineJudge judge = new OfflineJudge( new int[][] { new int[] { 2, 1, 6, 3, 4, 2, 6, 0, 1, 2, 3 }, new int[] {1, 2, 3, 4, 0} }); run(judge, wrapper); } public static void main(String[] args) { // Switch OnlineJudge, OfflineJudge // runOffline(true); runOnline(false); } } class Solver { final Judge judge; Solver(Judge judge) { this.judge = judge; } private String makeQuery(int[] indexes) { return String.format("? %d %d %d", indexes[0], indexes[1], indexes[2]); } private String makeAnswerQuery(int i, int j) { return String.format("! %d %d", i, j); } private int nextInt() { return Integer.parseInt(judge.next()); } public void run() { int n = nextInt(); int[] indexes = new int[] {1, 2, 3}; judge.putQuery(makeQuery(indexes)); int diff = nextInt(); for (int i = 4; i <= n; i++) { int[] tempIndexes1 = new int[] { indexes[0], indexes[1], i }; int[] tempIndexes2 = new int[] { indexes[1], indexes[2], i }; // int[] tempIndexes3 = new int[] {indexes[2], indexes[0], i}; judge.putQuery(makeQuery(tempIndexes1)); int tempDiff1 = nextInt(); judge.putQuery(makeQuery(tempIndexes2)); int tempDiff2 = nextInt(); if (tempDiff1 > tempDiff2 && tempDiff1 > diff) { indexes = tempIndexes1; // require 0 diff = tempDiff1; } else if (tempDiff2 > tempDiff1 && tempDiff2 > diff) { indexes = tempIndexes2; // require 2 diff = tempDiff2; } else if (tempDiff1 == tempDiff2 && tempDiff1 > diff) { indexes = tempIndexes1; // require 1 diff = tempDiff1; } } { int otherIndex = 0; for (int i = 1; i <= n; i++) { if (indexes[0] != i && indexes[1] != i && indexes[2] != i) { otherIndex = i; break; } } int[] tempIndexes1 = new int[] {indexes[0], indexes[1], otherIndex}; int[] tempIndexes2 = new int[] {indexes[1], indexes[2], otherIndex}; int[] tempIndexes3 = new int[] {indexes[2], indexes[0], otherIndex}; judge.putQuery(makeQuery(tempIndexes1)); int tempDiff1 = nextInt(); judge.putQuery(makeQuery(tempIndexes2)); int tempDiff2 = nextInt(); judge.putQuery(makeQuery(tempIndexes3)); int tempDiff3 = nextInt(); if (tempDiff1 >= tempDiff2 && tempDiff1 >= tempDiff3) { judge.putQuery(makeAnswerQuery(indexes[0], indexes[1])); } else if (tempDiff2 >= tempDiff3 && tempDiff2 >= tempDiff1) { judge.putQuery(makeAnswerQuery(indexes[1], indexes[2])); } else { judge.putQuery(makeAnswerQuery(indexes[2], indexes[0])); } } } } class OfflineJudge implements Judge { private final Deque<String> deque; private final int[][] am; private int instanceIndex; private int counter; public OfflineJudge(int[][] am) { this.am = am; this.counter = 0; this.instanceIndex = 0; deque = new ArrayDeque<>(); deque.add(Integer.toString(am.length)); deque.add(Integer.toString(am[0].length)); } @Override public String next() { return deque.pollFirst(); } @Override public void putQuery(String query) { String[] list = query.split(" "); int[] as = am[instanceIndex]; if (list[0].equals("?")) { if (counter >= 2 * as.length - 2) { throw new RuntimeException(); } int i = Integer.parseInt(list[1]) - 1; int j = Integer.parseInt(list[2]) - 1; int k = Integer.parseInt(list[3]) - 1; int[] vs = new int[] {as[i], as[j], as[k]}; Arrays.sort(vs); deque.addLast(Integer.toString(vs[2] - vs[0])); this.counter++; } else if (list[0].equals("!")) { int i = Integer.parseInt(list[1]) - 1; int j = Integer.parseInt(list[2]) - 1; if (as[i] == 0 || as[j] == 0) { System.err.println("AC"); } else { System.err.println("WA"); } instanceIndex++; counter = 0; if (instanceIndex < am.length) { deque.add(Integer.toString(am[instanceIndex].length)); } } else { throw new RuntimeException(); } } } interface Judge { String next(); void putQuery(String query); } class JudgeWrapper implements Judge { Judge judge; JudgeWrapper(Judge judge) { this.judge = judge; } @Override public void putQuery(String query) { System.err.println("Query: " + query); judge.putQuery(query); } @Override public String next() { String judgeResponse = judge.next(); System.err.println("Judge: " + judgeResponse); return judgeResponse; } } class OnlineJudge implements Judge { final ContestReader reader; OnlineJudge() { reader = new ContestReader(System.in); } @Override public String next() { return reader.next(); } @Override public void putQuery(String query) { System.out.println(query); } } class ContestReader { private static final int BUFFER_SIZE = 1024; private final InputStream stream; private final byte[] buffer; private int pointer; private int bufferLength; ContestReader(InputStream stream) { this.stream = stream; this.buffer = new byte[BUFFER_SIZE]; this.pointer = 0; this.bufferLength = 0; } private boolean hasNextByte() { if (pointer < bufferLength) { return true; } pointer = 0; try { bufferLength = stream.read(buffer); } catch (IOException e) { throw new RuntimeException(e); } return bufferLength > 0; } private int readByte() { if (hasNextByte()) { return buffer[pointer++]; } else { return -1; } } private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126; } public boolean hasNext() { while (hasNextByte() && !isPrintableChar(buffer[pointer])) { pointer++; } return hasNextByte(); } public String next() { if (!hasNext()) { throw new NoSuchElementException(); } StringBuilder sb = new StringBuilder(); while (true) { int b = readByte(); if (!isPrintableChar(b)) { break; } sb.appendCodePoint(b); } return sb.toString(); } public String nextLine() { if (!hasNext()) { throw new NoSuchElementException(); } StringBuilder sb = new StringBuilder(); while (true) { int b = readByte(); if (!isPrintableChar(b) && b != 0x20) { break; } sb.appendCodePoint(b); } return sb.toString(); } public char nextChar() { return next().charAt(0); } public int nextInt() { if (!hasNext()) { throw new NoSuchElementException(); } int n = 0; boolean minus = false; { int b = readByte(); if (b == '-') { minus = true; } else if ('0' <= b && b <= '9') { n = b - '0'; } else { throw new NumberFormatException(); } } while (true) { int b = readByte(); if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; } else if (b == -1 || !isPrintableChar(b)) { return minus ? -n : n; } else { throw new NumberFormatException(); } } } public long nextLong() { if (!hasNext()) { throw new NoSuchElementException(); } long n = 0; boolean minus = false; { int b = readByte(); if (b == '-') { minus = true; } else if ('0' <= b && b <= '9') { n = b - '0'; } else { throw new NumberFormatException(); } } while (true) { int b = readByte(); if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; } else if (b == -1 || !isPrintableChar(b)) { return minus ? -n : n; } else { throw new NumberFormatException(); } } } public double nextDouble() { return Double.parseDouble(next()); } public String[] next(int n) { String[] array = new String[n]; for (int i = 0; i < n; i++) { array[i] = next(); } return array; } public String[] nextLine(int n) { String[] array = new String[n]; for (int i = 0; i < n; i++) { array[i] = nextLine(); } return array; } public char[] nextChar(int n) { char[] array = new char[n]; for (int i = 0; i < n; i++) { array[i] = nextChar(); } return array; } public int[] nextInt(int n) { int[] array = new int[n]; for (int i = 0; i < n; i++) { array[i] = nextInt(); } return array; } public long[] nextLong(int n) { long[] array = new long[n]; for (int i = 0; i < n; i++) { array[i] = nextLong(); } return array; } public double[] nextDouble(int n) { double[] array = new double[n]; for (int i = 0; i < n; i++) { array[i] = nextDouble(); } return array; } public char[] nextCharArray() { return next().toCharArray(); } public String[][] next(int n, int m) { String[][] matrix = new String[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { matrix[i][j] = next(); } } return matrix; } public int[][] nextInt(int n, int m) { int[][] matrix = new int[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { matrix[i][j] = nextInt(); } } return matrix; } public char[][] nextChar(int n, int m) { char[][] matrix = new char[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { matrix[i][j] = nextChar(); } } return matrix; } public long[][] nextLong(int n, int m) { long[][] matrix = new long[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { matrix[i][j] = nextLong(); } } return matrix; } public double[][] nextDouble(int n, int m) { double[][] matrix = new double[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { matrix[i][j] = nextDouble(); } } return matrix; } public char[][] nextCharArray(int n) { char[][] matrix = new char[n][]; for (int i = 0; i < n; i++) { matrix[i] = next().toCharArray(); } return matrix; } }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
55154b24d113001b2fe6bbe7a9dc2207
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
import java.util.*; import java.util.function.Consumer; @SuppressWarnings("unused") public class Main { private static void solve() { int t = ni(); for (int i = 0; i < t; i++) { int n = ni(); if (n < 0) throw new RuntimeException(); solve(n); } // Random gen = new Random(); // for (int i = 0; i < 10000; i++) { // int n = 4 + gen.nextInt(3); // ans = new int[n]; // cnt = 0; // for (int j = 0; j < n; j++) { // ans[j] = gen.nextInt(300) + 1; // } // ans[gen.nextInt(ans.length)] = 0; // solve(n); // } } private static void solve(int n) { // n: 4-1000 int maxDiff = 0; int maxDIffArg = -1; Set<Integer> set = new HashSet<>(); for (int i = 2; i < n; i++) { // n - 2 int ret = ask(0, 1, i); set.add(ret); if (ret > maxDiff) { maxDiff = ret; maxDIffArg = i; } } int other = maxDIffArg != n - 1 ? n - 1 : n - 2; int v1 = ask(maxDIffArg, other, 0); int v2 = ask(maxDIffArg, other, 1); if (Math.max(v1, v2) < maxDiff) { ans(0, 1); return; } other = v1 > v2 ? 1 : 0; int maxDiff2 = 0; int maxDiffArg2 = -1; for (int i = 0; i < n; i++) { // n - 2 if (i == maxDIffArg || i == other) continue; int ret = ask(other, maxDIffArg, i); if (ret > maxDiff2) { maxDiff2 = ret; maxDiffArg2 = i; } } ans(maxDIffArg, maxDiffArg2); } private static void ans(int i, int j) { out.println("! " + (i + 1) + " " + (j + 1)); out.flush(); } private static int ask(int i, int j, int k) { // max call: 2n - 2 out.println("? " + (i + 1) + " " + (j + 1) + " " + (k + 1)); out.flush(); // return max(a[i], a[j], a[k]) - min(a[i], a[j], a[k]); int ret = ni(); if (ret < 0) throw new RuntimeException(); return ret; } // static int[] ans; // static int cnt = 0; // private static void ans(int i, int j) { // if (ans[i] != 0 && ans[j] != 0) // throw new RuntimeException(); // } // private static int ask(int i, int j, int k) { // cnt++; // if (cnt > ans.length * 2 - 2) // throw new RuntimeException(); // // return max(a[i], a[j], a[k]) - min(a[i], a[j], a[k]); // return Math.max(ans[i], Math.max(ans[j], ans[k])) - Math.min(ans[i], Math.min(ans[j], ans[k])); // } public static void main(String[] args) { new Thread(null, new Runnable() { @Override public void run() { long start = System.currentTimeMillis(); String debug = args.length > 0 ? args[0] : null; if (debug != null) { try { is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug)); } catch (Exception e) { throw new RuntimeException(e); } } reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768); solve(); out.flush(); tr((System.currentTimeMillis() - start) + "ms"); } }, "", 64000000).start(); } private static java.io.InputStream is = System.in; private static java.io.PrintWriter out = new java.io.PrintWriter(System.out); private static java.util.StringTokenizer tokenizer = null; private static java.io.BufferedReader reader; public static String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new java.util.StringTokenizer(reader.readLine()); } catch (Exception e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } private static double nd() { return Double.parseDouble(next()); } private static long nl() { return Long.parseLong(next()); } private static int[] na(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = ni(); return a; } private static char[] ns() { return next().toCharArray(); } private static long[] nal(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nl(); return a; } private static int[][] ntable(int n, int m) { int[][] table = new int[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { table[i][j] = ni(); } } return table; } private static int[][] nlist(int n, int m) { int[][] table = new int[m][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { table[j][i] = ni(); } } return table; } private static int ni() { return Integer.parseInt(next()); } private static void tr(Object... o) { if (is != System.in) System.out.println(java.util.Arrays.deepToString(o)); } }
Java
["1\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
e0c512b36abd3f197e7bb1b4f7279080
train_108.jsonl
1644158100
This is an interactive problem.We picked an array of whole numbers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $$$i$$$ such that $$$a_i = 0$$$.You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $$$i, j, k$$$, and we will tell you the value of $$$\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$$$. In other words, we will tell you the difference between the maximum and the minimum number among $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$.You are allowed to make no more than $$$2 \cdot n - 2$$$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $$$i$$$ and $$$j$$$ and you win if $$$a_i = 0$$$ or $$$a_j = 0$$$.Can you guess where we hid the zero?Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.
256 megabytes
import java.util.*; import java.io.*; public class _770 { static MyScanner sc; public static void main(String[] args) { sc = new MyScanner(); PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); long a = query(0, 1, 2); long b = query(0, 1, 3); long c = query(1, 2, 3); long d = query(0, 2, 3); long max = Math.max(Math.max(a, b), Math.max(c, d)); int f = -1; int s = -1; if (a == max && b == max) { f = 0; s = 1; } else if (a == max && c == max) { f = 1; s = 2; } else if (a == max && d == max) { f = 0; s = 2; } else if (b == max && c == max) { f = 1; s = 3; } else if (b == max && d == max) { f = 0; s = 3; } else if (c == max && d == max) { f = 2; s = 3; } for (int i = 4; i < n; i += 2) { int x; int y = -1; if (i == n - 1) { x = n - 1; for (int j = 0; j < 4; j++) { if (f != j && s != j && x != j) { y = j; break; } } } else { x = i; y = i + 1; } a = query(f, s, x); b = query(f, s, y); c = query(f, x, y); d = query(s, x, y); max = Math.max(Math.max(a, b), Math.max(c, d)); int nf = -1; int ns = -1; if (a == max && b == max) { nf = f; ns = s; } else if (a == max && c == max) { nf = f; ns = x; } else if (a == max && d == max) { nf = s; ns = x; } else if (b == max && c == max) { nf = f; ns = y; } else if (b == max && d == max) { nf = s; ns = y; } else if (c == max && d == max) { nf = x; ns = y; } f = nf; s = ns; } System.out.println("! " + (f + 1) + " " + (s + 1)); } out.close(); } static long query(int i, int j, int k) { System.out.println("? " + (i + 1) + " " + ( j + 1) + " " + (k + 1)); System.out.flush(); return sc.nextLong(); } static void sort(int[] a) { ArrayList<Integer> q = new ArrayList<>(); for (int i : a) q.add(i); Collections.sort(q); for (int i = 0; i < a.length; i++) a[i] = q.get(i); } static void sort(long[] a) { ArrayList<Long> q = new ArrayList<>(); for (long i : a) q.add(i); Collections.sort(q); for (int i = 0; i < a.length; i++) a[i] = q.get(i); } //-----------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\n\n4\n\n2\n\n3\n\n3\n\n2"]
1 second
["? 1 2 3\n\n? 2 3 4\n\n? 3 4 1\n\n? 4 1 2\n\n! 2 3"]
NoteArray from sample: $$$[1, 2, 0, 3]$$$.
Java 11
standard input
[ "constructive algorithms", "interactive", "math" ]
84e79bd83c51a4966b496bb767ec4f0d
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first and only line of each test case contains an integer $$$n$$$ ($$$4 \le n \le 1000$$$) — the length of the array that we picked. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
2,000
null
standard output
PASSED
0d5977b2362e8a2a1d594abff42bfefe
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import java.io.*; import java.util.Arrays; import java.util.Random; import java.util.StringTokenizer; public class codeforces_770_B { private static void solve(FastIOAdapter in, PrintWriter out) { int n = in.nextInt(); int x = in.nextInt(); long y = in.nextLong(); int[] a = in.readArray(n); long sum = 0; for (int i = 0; i < n; i++) { sum += a[i]; } if ((x + sum) % 2 == y % 2) out.println("Alice"); else out.println("Bob"); } public static void main(String[] args) throws Exception { try (FastIOAdapter ioAdapter = new FastIOAdapter()) { int count = 1; count = ioAdapter.nextInt(); while (count-- > 0) { solve(ioAdapter, ioAdapter.out); } } } static void ruffleSort(int[] arr) { int n = arr.length; Random rnd = new Random(); for (int i = 0; i < n; ++i) { int tmp = arr[i]; int randomPos = i + rnd.nextInt(n - i); arr[i] = arr[randomPos]; arr[randomPos] = tmp; } Arrays.sort(arr); } static class FastIOAdapter implements AutoCloseable { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter((System.out)))); StringTokenizer st = new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } String nextLine() { try { return br.readLine(); } catch (IOException e) { e.printStackTrace(); return null; } } 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[] readArrayLong(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } long nextLong() { return Long.parseLong(next()); } @Override public void close() throws Exception { out.flush(); out.close(); br.close(); } } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
3e8b6153db456ac8a130a8796101dda5
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import java.math.BigInteger; import java.util.*; public class ProblemB { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int tests = scanner.nextInt(); for(int i=0;i<tests;i++){ int lenOfArr=scanner.nextInt(); long aliceInitialNum=scanner.nextLong(); long target=scanner.nextLong(); int[] arr=new int[lenOfArr]; arr[0]=scanner.nextInt(); boolean lastParityEven= (arr[0] + aliceInitialNum) % 2 == 0; for(int j=1;j<lenOfArr;j++){ arr[j]=scanner.nextInt(); if(lastParityEven){ if(arr[j]%2!=0) lastParityEven=false; } else{ if(arr[j]%2!=0) lastParityEven=true; } } if(target%2==0 && lastParityEven) System.out.println("Alice"); else{ if(target%2!=0 && !lastParityEven) System.out.println("Alice"); else System.out.println("Bob"); } } } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
e646d86d19a9da94bf939b8296234b84
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class Main { // -- static variables --- // static FastReader sc = new FastReader(); static PrintWriter out = new PrintWriter(System.out); static int mod = (int) 1000000007; public static void main(String[] args) throws Exception { int t =sc.nextInt(); while (t-- > 0) Main.go(); // out.println(); out.flush(); } // >>>>>>>>>>>>>>>>>>> Code Starts <<<<<<<<<<<<<<<<<<<< // static class pair { int x, y; pair(int x, int y) { this.x = x; this.y = y; } } static void go() throws Exception { int n=sc.nextInt(),x=sc.nextInt(); long y=sc.nextLong(); int a[]=sc.intArray(n); long sum=0; // a+b and a^b has parity common for(int i=0;i<n;i++)sum+=a[i]; if((x+sum)%2==y%2) { out.println("Alice"); }else { out.println("Bob"); } } static boolean check(String s) { int l=0,r=s.length()-1; while(l<=r) { if(s.charAt(l)!=s.charAt(r)) { return false; } l++;r--; } return true; } static long lcm(long a, long b) { return a * b / gcd(a, b); } // >>>>>>>>>>> Code Ends <<<<<<<<< // // --For Rounding--// static double round(double value, int places) { if (places < 0) throw new IllegalArgumentException(); BigDecimal bd = new BigDecimal(Double.toString(value)); bd = bd.setScale(places, RoundingMode.HALF_UP); return bd.doubleValue(); } // ----Greatest Common Divisor-----// static long gcd(long a, long b) { if (b == 0) { return a; } return gcd(b, a % b); } // --- permutations and Combinations ---// static long fact[]; static long invfact[]; static long ncr(int n, int k) { if (k < 0 || k > n) { return 0; } long x = fact[n]; long y = fact[k]; long yy = fact[n - k]; long ans = (x / y); ans = (ans / yy); return ans; } // ---sieve---// static int prime[] = new int[1000006]; // static void sieve() { // Arrays.fill(prime, 1); // prime[0] = 0; // prime[1] = 0; // for (int i = 2; i * i <= 1000005; i++) { // if (prime[i] == 1) // for (int j = i * i; j <= 1000005; j += i) { // prime[j] = 0; // } // } // } // ---- Manual sort ------// static void sort(long[] a) { ArrayList<Long> aa = new ArrayList<>(); for (long i : a) { aa.add(i); } Collections.sort(aa); for (int i = 0; i < a.length; i++) a[i] = aa.get(i); } static void sort(int[] a) { ArrayList<Integer> aa = new ArrayList<>(); for (int i : a) { aa.add(i); } Collections.sort(aa); for (int i = 0; i < a.length; i++) a[i] = aa.get(i); } // --- Fast exponentiation ---// static long pow(long x, long y) { long res = 1l; while (y != 0) { if (y % 2 == 1) { res = (x * res); } y /= 2; x = (x * x); } return res; } // >>>>>>>>>>>>>>> Fast IO <<<<<<<<<<<<<< // 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()); } int[] intArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) a[i] = sc.nextInt(); return a; } long[] longArray(int n) { long a[] = new long[n]; for (int i = 0; i < n; i++) a[i] = sc.nextLong(); return a; } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
6b86209cbb55db1f0dc71e5baed02ccd
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.util.*; import java.io.*; public class Main { // Graph // prefix sums //inputs public static void main(String args[])throws Exception{ Input sc=new Input(); precalculates p=new precalculates(); StringBuilder sb=new StringBuilder(); int t=sc.readInt(); for(int f=0;f<t;f++){ long d[]=sc.readArrayLong(); long a[]=sc.readArrayLong(); int n=(int)d[0]; long al=d[1],bo=al+3,y=d[2]; HashMap<Long,Boolean> map=new HashMap<>(); long ans=0; for(int i=0;i<n;i++){ ans=ans+a[i]; } if(al%2==0){ if(y%2==0 && ans%2==0) sb.append("Alice"); else if(y%2==0 && ans%2!=0){ sb.append("Bob"); }else if(y%2!=0 && ans%2==0){ sb.append("Bob"); }else{ sb.append("Alice"); } }else { if(y%2==0 && ans%2==0) sb.append("Bob"); else if(y%2==0 && ans%2!=0){ sb.append("Alice"); }else if(y%2!=0 && ans%2==0){ sb.append("Alice"); }else{ sb.append("Bob"); } } sb.append("\n"); } System.out.print(sb); } public static boolean fun(long a[],int choice,long curr,long tar,int i,HashMap<Long,Boolean> map){ if(i>=a.length){ if(curr==tar) return true; else return false; } if(map.containsKey(curr)){ return map.get(curr); } boolean ans=false; ans=ans | fun(a,0,curr+a[i],tar,i+1,map); if( ans){ map.put(curr,ans); return ans; } ans=ans | fun(a,1,curr^a[i],tar,i+1,map); map.put(curr,ans); return ans; } } class Input{ BufferedReader br; StringTokenizer st; Input(){ br=new BufferedReader(new InputStreamReader(System.in)); st=new StringTokenizer(""); } public int[] readArray() throws Exception{ st=new StringTokenizer(br.readLine()); int a[]=new int[st.countTokens()]; for(int i=0;i<a.length;i++){ a[i]=Integer.parseInt(st.nextToken()); } return a; } public long[] readArrayLong() throws Exception{ st=new StringTokenizer(br.readLine()); long a[]=new long[st.countTokens()]; for(int i=0;i<a.length;i++){ a[i]=Long.parseLong(st.nextToken()); } return a; } public int readInt() throws Exception{ st=new StringTokenizer(br.readLine()); return Integer.parseInt(st.nextToken()); } public long readLong() throws Exception{ st=new StringTokenizer(br.readLine()); return Long.parseLong(st.nextToken()); } public String readString() throws Exception{ return br.readLine(); } public int[][] read2dArray(int n,int m)throws Exception{ int a[][]=new int[n][m]; for(int i=0;i<n;i++){ st=new StringTokenizer(br.readLine()); for(int j=0;j<m;j++){ a[i][j]=Integer.parseInt(st.nextToken()); } } return a; } } class precalculates{ public long gcd(long p, long q) { if (q == 0) return p; else return gcd(q, p % q); } public int[] prefixSumOneDimentional(int a[]){ int n=a.length; int dp[]=new int[n]; for(int i=0;i<n;i++){ if(i==0) dp[i]=a[i]; else dp[i]=dp[i-1]+a[i]; } return dp; } public int[] postSumOneDimentional(int a[]) { int n = a.length; int dp[] = new int[n]; for (int i = n - 1; i >= 0; i--) { if (i == n - 1) dp[i] = a[i]; else dp[i] = dp[i + 1] + a[i]; } return dp; } public int[][] prefixSum2d(int a[][]){ int n=a.length;int m=a[0].length; int dp[][]=new int[n+1][m+1]; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ dp[i][j]=a[i-1][j-1]+dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]; } } return dp; } public long pow(long a,long b){ long mod=998244353; long ans=1; if(b<=0) return 1; if(b%2==0){ ans=pow(a,b/2)%mod; return ((ans%mod)*(ans%mod))%mod; }else{ ans=pow(a,b-1)%mod; return ((a%mod)*(ans%mod))%mod; } } } class GraphInteger{ HashMap<Integer,vertex> vtces; class vertex{ HashMap<Integer,Integer> children; public vertex(){ children=new HashMap<>(); } } public GraphInteger(){ vtces=new HashMap<>(); } public void addVertex(int a){ vtces.put(a,new vertex()); } public void addEdge(int a,int b,int cost){ if(!vtces.containsKey(a)){ vtces.put(a,new vertex()); } if(!vtces.containsKey(b)){ vtces.put(b,new vertex()); } vtces.get(a).children.put(b,cost); // vtces.get(b).children.put(a,cost); } public boolean isCyclicDirected(){ boolean isdone[]=new boolean[vtces.size()+1]; boolean check[]=new boolean[vtces.size()+1]; for(int i=1;i<=vtces.size();i++) { if (!isdone[i] && isCyclicDirected(i,isdone, check)) { return true; } } return false; } private boolean isCyclicDirected(int i,boolean isdone[],boolean check[]){ if(check[i]) return true; if(isdone[i]) return false; check[i]=true; isdone[i]=true; Set<Integer> set=vtces.get(i).children.keySet(); for(Integer ii:set){ if(isCyclicDirected(ii,isdone,check)) return true; } check[i]=false; return false; } } class union_find { int n; int[] sz; int[] par; union_find(int nval) { n = nval; sz = new int[n + 1]; par = new int[n + 1]; for (int i = 0; i <= n; i++) { par[i] = i; sz[i] = 1; } } int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } boolean find(int a, int b) { return root(a) == root(b); } int union(int a, int b) { int ra = root(a); int rb = root(b); if (ra == rb) return 0; if(a==b) return 0; if (sz[a] > sz[b]) { int temp = ra; ra = rb; rb = temp; } par[ra] = rb; sz[rb] += sz[ra]; return 1; } } /* static int mod=998244353; private static int add(int x, int y) { x += y; return x % MOD; } private static int mul(int x, int y) { int res = (int) (((long) x * y) % MOD); return res; } private static int binpow(int x, int y) { int z = 1; while (y > 0) { if (y % 2 != 0) z = mul(z, x); x = mul(x, x); y >>= 1; } return z; } private static int inv(int x) { return binpow(x, MOD - 2); } private static int devide(int x, int y) { return mul(x, inv(y)); } private static int C(int n, int k, int[] fact) { return devide(fact[n], mul(fact[k], fact[n-k])); } */
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
ced0b4faecfa12f944042597fbf845fe
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import java.io.*; import java.util.*; public class ComdeFormces { public static void main(String[] args) throws Exception{ // TODO Auto-generated method stub FastReader sc=new FastReader(); BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out)); int t=sc.nextInt(); while(t--!=0) { int n=sc.nextInt(); long x=sc.nextLong(); long y=sc.nextLong(); int a[]=new int[n]; for(int i=0;i<n;i++)a[i]=sc.nextInt(); int fb=0; for(int i=0;i<n;i++) { int temp=a[i]&1; if(temp==1)fb++; } String ans=""; if(y%2==0) { if((x%2==0 && fb%2==0) || (x%2!=0 && fb%2!=0))ans="Alice"; else ans="Bob"; } else { if((x%2==0 && fb%2!=0) || (x%2!=0 && fb%2==0))ans="Alice"; else ans="Bob"; } log.write(ans+"\n"); log.flush(); } } public static String rever(String s) { char a[]=s.toCharArray(); for(int i=0;i<a.length/2;i++) { char temp=a[i]; a[i]=a[a.length-1-i]; a[a.length-1-i]=temp; } return String.valueOf(a); } static boolean bsch(long k,long hc,long dc,long hm,long dm,long w,long a) { long s=0; long e=k; while(s<=e) { long b=k-s; long nhc=hc+s*a; long ndc=dc+b*w; long moves=hm%ndc==0?hm/ndc:(hm/ndc)+1; long moves2=nhc%dm==0?nhc/dm:(nhc/dm)+1; if(moves2>=moves)return true; s++; } return false; } //static ArrayList<Integer> pr(int n){ // boolean vis[]=new boolean[n+1]; // vis[0]=false; // vis[1]=false; // for(int i=2;i<=n;i++) { // if(vis[i]) { // for(int j=2*i;j<=n;j+=i) { // vis[j]=false; // } // } // } //} static int subset(int a[],int j,int dp[][], int sum) { if(j==0) { if(sum==0 || sum-a[j]==0)return 1; else return 0; } if(sum==0)return 1; if(dp[j][sum]>0)return dp[j][sum]; // p("for j="+j+"sum="+sum,"s"); if(sum-a[j]>=0) { int p=subset(a,j-1,dp,sum-a[j]); int q=subset(a,j-1,dp,sum); return dp[j][sum]=p+q; } else{ return dp[j][sum]=subset(a,j-1,dp,sum); } } static long slv(int a[],int b[],long dp[][],int end,int k,int i) { if(i<1 ) { if(k==0) { return (end-a[0])*b[0]; } else return Integer.MAX_VALUE; } if(k<0)return Integer.MAX_VALUE; if(k==0) { return (end-a[0])*b[0]; } if(dp[i][k]!=0)return dp[i][k]; long ans1=slv(a,b,dp,a[i],k-1,i-1); long ans2=slv(a,b,dp,end,k,i-1); long val=(end-a[i])*b[i]; return dp[i][k]=Math.min(val+ans1,ans2); } static int bss(int[] a,int s, long k) { int e=a.length-1; // int max=-1; while(s<=e) { int m=s+(e-s)/2; if(a[m]==k) { return m; } else if(a[m]<k)s=m+1; else e=m-1; } return -1; } static int solv(int[] a,int len) { if(len%2==0) { int ans=0; for(int i=0;i<a.length;i++){ if(a[i]>0){ if(a[i]%2==0) { ans+=a[i]; } else if(a[i]%2!=0) { ans+=(a[i]/2)*2; } } } int cnt=ans/len; return cnt; } else { int ans=0,one=0; for(int i=0;i<a.length;i++){ if(a[i]>0){ if(a[i]%2==0) { ans+=a[i]; } else { ans+=(a[i]/2)*2; one++; } } } int n=len-1; int cnt=ans/n; int mod=cnt%n+one; if(cnt>=mod)return cnt; return mod; } } //debug static pair bss(ArrayList<pair> a,int el,int ind) { int s=0; int e=a.size()-1; pair ans=new pair(-1,-1); while(s<=e) { int m=s+(e-s)/2; if(a.get(m).a==el) { ans=a.get(m); e=m-1; } if(a.get(m).a>el)e=m-1; else s=m+1; } return ans; } public static <E> void p(E[][] a,String s) { System.out.println(s); for(int i=0;i<a.length;i++) { for(int j=0;j<a[0].length;j++) { System.out.print(a[i][j]+" "); } System.out.println(); } } public static void p(int[] a,String s) { System.out.print(s+"="); for(int i=0;i<a.length;i++)System.out.print(a[i]+" "); System.out.println(); } public static <E> void p(E a,String s){ System.out.println(s+"="+a); } public static <E> void p(ArrayList<E> a,String s){ System.out.println(s+"="+a); } public static <E> void p(LinkedList<E> a,String s){ System.out.println(s+"="+a); } public static <E> void p(HashSet<E> a,String s){ System.out.println(s+"="+a); } public static <E> void p(Stack<E> a,String s){ System.out.println(s+"="+a); } public static <E> void p(Queue<E> a,String s){ System.out.println(s+"="+a); } //utils static ArrayList<Integer> divisors(int n){ ArrayList<Integer> ar=new ArrayList<>(); for (int i=2; i<=Math.sqrt(n); i++){ if (n%i == 0){ if (n/i == i) { ar.add(i); } else { ar.add(i); ar.add(n/i); } } } return ar; } static int primeDivisor(int n){ ArrayList<Integer> ar=new ArrayList<>(); int cnt=0; boolean pr=false; while(n%2==0) { pr=true; n/=2; } if(pr)ar.add(2); for(int i=3;i*i<=n;i+=2) { pr=false; while(n%i==0) { n/=i; pr=true; } if(pr)ar.add(i); } if(n>2) ar.add(n); return ar.size(); } static String rev(String s) { char temp[]=s.toCharArray(); for(int i=0;i<temp.length/2;i++) { char tp=temp[i]; temp[i]=temp[temp.length-1-i]; temp[temp.length-1-i]=tp; } return String.valueOf(temp); } static int bs(ArrayList<pair> arr,int el) { int start=0; int end=arr.size()-1; while(start<=end) { int mid=start+(end-start)/2; if(arr.get(mid).a==el)return mid; else if(arr.get(mid).a<el)start=mid+1; else end=mid-1; } if(start>arr.size()-1)return -2; return -1; } static long find(int s,long a[]) { if(s>=a.length)return -1; long num=a[s]; for(int i=s;i<a.length;i+=2) { num=gcd(num,a[i]); if(num==1 || num==0)return -1; } return num; } static long gcd(long a,long b) { if(b==0)return a; else return gcd(b,a%b); } static int gcd(int a,int b) { if(b==0)return a; else return gcd(b,a%b); } static long factmod(long n,long mod,long img) { if(n==0)return 1; long ans=1; long temp=1; while(n--!=0) { if(temp!=img) { ans=((ans%mod)*((temp)%mod))%mod; } temp++; } return ans%mod; } static int bs(long a[] ,long num) { int start=0; int end=a.length-1; while(start<=end) { int mid=start+(end-start)/2; if(a[mid]==num) { return mid; } else if(a[mid]<num)start=mid+1; else end=mid-1; } return start; } static int ncr(int n, int r){ if(r>n-r)r=n-r; int ans=1; for(int i=0;i<r;i++){ ans*=(n-i); ans/=(i+1); } return ans; } public static class trip{ int a,b,c; public trip(int a,int b,int c) { this.a=a; this.b=b; this.c=c; } public int compareTo(trip q) { return this.c-q.c; } } static void mergesort(int[] a,int start,int end) { if(start>=end)return ; int mid=start+(end-start)/2; mergesort(a,start,mid); mergesort(a,mid+1,end); merge(a,start,mid,end); } static void merge(int[] a, int start,int mid,int end) { int ptr1=start; int ptr2=mid+1; int b[]=new int[end-start+1]; int i=0; while(ptr1<=mid && ptr2<=end) { if(a[ptr1]<=a[ptr2]) { b[i]=a[ptr1]; ptr1++; i++; } else { b[i]=a[ptr2]; ptr2++; i++; } } while(ptr1<=mid) { b[i]=a[ptr1]; ptr1++; i++; } while(ptr2<=end) { b[i]=a[ptr2]; ptr2++; i++; } for(int j=start;j<=end;j++) { a[j]=b[j-start]; } } public static class FastReader { BufferedReader b; StringTokenizer s; public FastReader() { b=new BufferedReader(new InputStreamReader(System.in)); } String next() { while(s==null ||!s.hasMoreElements()) { try { s=new StringTokenizer(b.readLine()); } catch(IOException e) { e.printStackTrace(); } } return s.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str=""; try { str=b.readLine(); } catch(IOException e) { e.printStackTrace(); } return str; } boolean hasNext() { if (s != null && s.hasMoreTokens()) { return true; } String tmp; try { b.mark(1000); tmp = b.readLine(); if (tmp == null) { return false; } b.reset(); } catch (IOException e) { return false; } return true; } } public static class pair{ int a; int b; public pair(int a,int b) { this.a=a; this.b=b; } public int compareTo(pair b) { return this.a-b.a; } public int compareToo(pair b) { return this.b-b.b; } @Override public String toString() { return "{"+this.a+" "+this.b+"}"; } } static long pow(long a, long pw) { long temp; if(pw==0)return 1; temp=pow(a,pw/2); if(pw%2==0)return temp*temp; return a*temp*temp; } static int pow(int a, int pw) { int temp; if(pw==0)return 1; temp=pow(a,pw/2); if(pw%2==0)return temp*temp; return a*temp*temp; } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
ecc419841220791d169bd4806defcdd5
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
//package extra; import java.io.*; public class Main { public static void main(String[] args) throws IOException { // BufferedReader br = new BufferedReader(new FileReader(".in")); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); // PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(".out"))); PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out)); int test = Integer.parseInt(br.readLine()); for(int tests = 0;tests < test;tests++){ String[] in = br.readLine().split(" "); long n = Long.parseLong(in[0]), x = Long.parseLong(in[1]), y = Long.parseLong(in[2]); long sum = x + y; in = br.readLine().split(" "); for(int i = 0;i < n;i++) sum += Integer.parseInt(in[i]); if(sum % 2 == 0) pw.println("Alice"); else pw.println("Bob"); } pw.close(); } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
28dd8035a866b81a608229da15002cac
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import java.util.ArrayList; import java.util.Scanner; public class Queue1 { public static void main(String[] args) { Scanner s=new Scanner(System.in); int t=s.nextInt(); for(int i=0;i<t;i++){ int len=s.nextInt(); int x=s.nextInt(); long y=s.nextLong(); ArrayList<Integer> arr=new ArrayList<>(len); for(int j=0;j<len;j++){ arr.add(s.nextInt()); } int count=0; if(x%2==0){ for(int k=0;k<len;k++){ if(k==0){ if(arr.get(k)%2==1){ count=1; } } else{ if(count%2==0 && arr.get(k)%2==1){ count=1; } else{ if(count%2==1 && arr.get(k)%2==1){ count=0; } } } } } else{ for(int k=0;k<len;k++){ if(k==0){ if(arr.get(k)%2==0){ count=1; } } else{ if(count%2==0 && arr.get(k)%2==1){ count=1; } else{ if(count%2==1 && arr.get(k)%2==1){ count=0; } } } } } if(((count)%2)==(y%2)){ System.out.println("Alice"); } else{ System.out.println("Bob"); } } } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
7c22c46d7b8421b2c09880be2703d176
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import java.util.*; public class FortuneTelling_B { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0) { int n = sc.nextInt(); long x = sc.nextLong(); long y = sc.nextLong(); long xor = x; for(int i = 0; i<n; i++) { xor = xor^(sc.nextLong()); } if(xor%2==y%2) { System.out.println("Alice"); } else { System.out.println("Bob"); } } } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
669ce801443f8d45bc7db02a2c6ea0b2
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import java.util.*; import java.math.*; //import java.io.*; public class Experiment { static Scanner in=new Scanner(System.in); static int global=0; // static BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); static class Pair implements Comparable<Pair>{ String s;char ch;int swap; Pair(String s,char ch,int swap){ this.s=s; this.ch=ch; this.swap=swap; } public int compareTo(Pair o){ if(swap%2==0) return o.ch-this.ch; else return this.ch-o.ch; // Sort return this.first-o.first; pair on the basis of first parameter in ascending order // return o.first-this.first to sort on basis of first parameter in descending order // return this.second -o.second to Sort pair on the basis of second parameter in ascending order //return o.second-this.second to sort on basis of second parameter in descending order } } public static void sort(int ar[],int l,int r) { if(l<r) { int m=l+(r-l)/2; sort(ar,l,m); sort(ar,m+1,r); merge(ar,l,m,r); } } public static int hcf(int x,int y) { if(y==0) return x; return hcf(y,x%y); } public static void merge(int ar[],int l,int m,int r) { int n1=m-l+1;int n2=r-m; int L[]=new int[n1]; int R[]=new int[n2]; for(int i=0;i<n1;i++) L[i]=ar[l+i]; for(int i=0;i<n2;i++) R[i]=ar[m+i+1]; int i=0;int j=0;int k=l; while(i<n1 && j<n2) { if(L[i]<=R[j]) { ar[k++]=L[i++]; }else { ar[k++]=R[j++]; } } while(i<n1) ar[k++]=L[i++]; while(j<n2) ar[k++]=R[j++]; } public static int[] sort(int ar[]) { sort(ar,0,ar.length-1); //Array.sort uses O(n^2) in its worst case ,so better use merge sort return ar; } public static void rec(int ar[],int n,long d,long tar) { } public static void func() { int n=in.nextInt();long x=in.nextLong();long y=in.nextLong(); long sum=0; int ar[]=new int[n]; for(int i=0;i<n;i++) { ar[i]=in.nextInt();sum+=ar[i]; } sum+=x; if((sum%2==0 && y%2==0) || (sum%2!=0 && y%2!=0)) System.out.println("Alice"); else System.out.println("Bob"); } public static void main(String[] args) { int t=in.nextInt(); while(t-->0) { func(); global=0; } } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
21523ab05cd36b8a9244546efb20d079
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class B { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(reader.readLine()); StringBuilder res = new StringBuilder(); for (int i = 0; i < t; i++) { StringTokenizer stringTokenizer = new StringTokenizer(reader.readLine()); int n = Integer.parseInt(stringTokenizer.nextToken()); long x = Integer.parseInt(stringTokenizer.nextToken()); long y = Long.parseLong(stringTokenizer.nextToken()); long sum = 0; stringTokenizer = new StringTokenizer(reader.readLine()); for (int j = 0; j < n; j++) { sum += Integer.parseInt(stringTokenizer.nextToken());; } if ((sum + x) % 2 == y % 2) { res.append("Alice\n"); } else { res.append("Bob\n"); } } System.out.println(res); } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
6455175f97e2c8b630b122486fb3a62f
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import java.io.*; import java.util.*; public class B_Fortune_Telling { static final int INT_MOD = (int) 1e9 + 7; static final long LONG_MOD = (long) 1e9 + 7; static final int INT_POSITIVE_INFINITY = Integer.MAX_VALUE; static final long LONG_POSITIVE_INFINITY = Long.MAX_VALUE; static final int INT_NEGATIVE_INFINITY = Integer.MIN_VALUE; static final long LONG_NEGATIVE_INFINITY = Long.MIN_VALUE; static StringBuilder result = new StringBuilder(); public static void main(String args[]) throws IOException { FastReader fr = new FastReader(); FastWriter fw = new FastWriter(); // FastFileReader ffr = new FastFileReader("input.txt"); // FastFileWriter ffw = new FastFileWriter("output.txt"); int tc; tc = fr.nextInt(); // tc = ffr.nextInt(); while (tc-- > 0) { long n = fr.nextLong(); long x = fr.nextLong(); long y = fr.nextLong(); long[] arr = new long[(int) n]; long parity = (x & 1); for (int i = 0; i < n; i++) { arr[i] = fr.nextLong(); parity = (parity ^ arr[i]); } if ((y & 1) == (parity & 1)) result.append("Alice\n"); else result.append("Bob\n"); } fw.write(result.toString()); // ffw.write(result.toString()); } static void swap(int[] nums, int i, int j) { int temp = nums[i]; nums[i] = nums[j]; nums[j] = temp; } static boolean isPrime(long x) { if (x <= 1) return false; for (long i = 2; i * i <= x; i++) if (x % i == 0) return false; return true; } static boolean[] sieve(int n) { boolean[] sieve = new boolean[n + 1]; Arrays.fill(sieve, true); sieve[0] = sieve[1] = false; for (int i = 2; i * i <= n; i++) { if (sieve[i]) { for (int j = i * i; j <= n; j += i) { sieve[j] = false; } } } return sieve; } static boolean isFibonacci(long x) { return isPerfectSquare(5 * x * x + 4); } static boolean isPerfectSquare(long x) { if (x <= 1) return true; long low = 1; long high = x; long mid = 0; while (low <= high) { mid = low + (high - low) / 2l; if (mid * mid == x) return true; else if (mid * mid < x) low = mid + 1; else high = mid - 1; } return false; } static long lcm(long a, long b) { return a * b / gcd(a, b); } static long gcd(long a, long b) { if (b > a) return gcd(b, a); if (b == 0) return a; return gcd(b, a % b); } static long pow(long b, long e) { long curr = b; long res = 1; while (e != 0) { if ((e & 1) != 0) { res = (res * curr) % LONG_MOD; } curr = (curr * curr) % LONG_MOD; e >>= 1; } return res; } static double log(double x, double base) { return Math.log(x) / Math.log(base); } } /* user-defined data structures */ class Pair { long a; long b; public Pair(long a, long b) { this.a = a; this.b = b; } } class Tair { int a; int b; int c; public Tair(int a, int b, int c) { this.a = a; this.b = b; this.c = c; } } class Fair { int a; int b; int c; int d; public Fair(int a, int b, int c, int d) { this.a = a; this.b = b; this.c = c; this.d = d; } } class Point { int x; int y; int z; public Point(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } } /* User defined data structures ends here */ /* IO class */ class FastReader { InputStreamReader isr; BufferedReader br; StringTokenizer st; public FastReader() { isr = new InputStreamReader(System.in); br = new BufferedReader(isr); } 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; } } class FastWriter { OutputStreamWriter osw; BufferedWriter bw; public FastWriter() { osw = new OutputStreamWriter(System.out); bw = new BufferedWriter(osw); } void write(String text) { try { bw.write(text); bw.flush(); } catch (IOException e) { e.printStackTrace(); } } } class FastFileReader { FileInputStream fis; InputStreamReader isr; BufferedReader br; StringTokenizer st; public FastFileReader(String fileName) throws FileNotFoundException { fis = new FileInputStream(fileName); isr = new InputStreamReader(fis); br = new BufferedReader(isr); } 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; } } class FastFileWriter { FileOutputStream fos; OutputStreamWriter osw; BufferedWriter bw; public FastFileWriter(String fileName) throws FileNotFoundException { fos = new FileOutputStream(fileName); osw = new OutputStreamWriter(fos); bw = new BufferedWriter(osw); } void write(String text) { try { bw.write(text); bw.flush(); } catch (IOException e) { e.printStackTrace(); } } } /* IO class ends here */
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
af72283f1a746d61686d885280dd81b1
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Scanner; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Scanner in = new Scanner(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } static class TaskB { public void solve(int testNumber, Scanner in, PrintWriter out) { int T = in.nextInt(); while (T-- > 0) { solveOne(in, out); } } private void solveOne(Scanner in, PrintWriter out) { int N = in.nextInt(); long X = in.nextLong(); long Y = in.nextLong(); long[] A = L.readLongArray(N, in); long sum = X; for (long a : A) sum += a; if ((sum % 2 == 0) == (Y % 2 == 0)) { out.println("Alice"); } else { out.println("Bob"); } } } static class L { public static long[] readLongArray(int size, Scanner in) { long[] array = new long[size]; for (int i = 0; i < size; i++) { array[i] = in.nextLong(); } return array; } } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
9f377963d951b732ca315d81a49e99b3
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
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(); long x = sc.nextLong(), y = sc.nextLong(), arr[] = new long[n]; for(int i=0;i<n;i++) arr[i] = sc.nextLong(); long sum = 0; for(long k : arr){ sum += k; } if(sum % 2 == 0){ if((x+y) % 2 == 0){ System.out.println("Alice"); } else { System.out.println("Bob"); } } else { if((x+y) % 2 != 0){ System.out.println("Alice"); } else { System.out.println("Bob"); } } } } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
f7ea301fa2b7bc4ed950746201161070
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; import java.util.Map.Entry; public class codeforces { static int mod = 1000000007; public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNext()) { int t = sc.nextInt(); while(t-->0) { int n = sc.nextInt(); long x = sc.nextLong(); long y = sc.nextLong(); long a[] = new long[n]; for(int i = 0 ; i <n;i++) { a[i]= sc.nextLong(); } long cnt = 0; for(int i = 0 ; i<n;i++){ if(a[i] %2 != 0 ) { cnt++; } } if(cnt%2 == 0) { if(x%2 == y %2) { System.out.println("Alice"); } else { System.out.println("Bob"); } } else { if(x%2 == y%2) { System.out.println("Bob"); } else { System.out.println("Alice"); } } } } } static long pow(long a, long b) { long ans = 1; long temp = a; while(b>0) { if((b&1) == 1) { ans*=temp; } temp = temp*temp; b = b>>1; } return ans; } static long ncr(int n, int r) { return fact(n) / (fact(r) * fact(n - r)); } static long fact(long n) { long res = 1; for (int i = 2; i <= n; i++) { res = (res * i); } return res; } static long gcd(long a, long b) { if(b == 0) { return a; } return gcd(b , a%b); } static ArrayList<Integer> factor(long n) { ArrayList<Integer> al = new ArrayList<>(); for(int i = 1 ; i*i<=n;i++) { if(n%i == 0) { if(n/i == i) { al.add(i); } else { al.add(i); al.add((int) (n/i)); } } } return al; } static class Pair implements Comparable<Pair>{ int a; int b ; int c; int d; Pair(int a, int b, int c, int d){ this.a = a; this.b = b; this.c = c; this.d = d; } @Override public int compareTo(Pair o) { // TODO Auto-generated method stub int temp = (this.b - o.b); if(temp == 0) { int temp1 = this.a - o.a; if(temp1 == 0) { return this.c - o.c; } return temp1; } return temp; } } static ArrayList<Integer> sieve(int n) { boolean a[] = new boolean[n+1]; Arrays.fill(a, false); for(int i = 2 ; i*i <=n ; i++) { if(!a[i]) { for(int j = 2*i ; j<=n ; j+=i) { a[j] = true; } } } ArrayList<Integer> al = new ArrayList<>(); for(int i = 2 ; i <=n;i++) { if(!a[i]) { al.add(i); } } return al; } static ArrayList<Long> pf(long n) { ArrayList<Long> al = new ArrayList<>(); while(n%2 == 0) { al.add(2l); n = n/2; } for(long i = 3 ; i*i<=n ; i+=2) { while(n%i == 0) { al.add(i); n = n/i; } } if(n>2) { al.add( n); } return al; } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
b461a56928cf1a61312d2b36bcf0795b
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class A { public static void main(String[] args) throws IOException { InputStreamReader re=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(re); int t = Integer.parseInt(br.readLine()); int i,j,l; for(i=0;i<t;i++) { String s = br.readLine(); String [] c = s.split(" "); int n = Integer.parseInt(c[0]); long x = Long.parseLong(c[1]); long y = Long.parseLong(c[2]); long[] arr = new long[n]; s = br.readLine(); String [] ce = s.split(" "); int even = 0; for(j=0;j<n;j++) { arr[j] = Long.parseLong(ce[j]); if(arr[j]%2!=0) even++; } if(even%2==0) { if(x%2==y%2) System.out.println("Alice"); else System.out.println("Bob"); } else { if(x%2!=y%2) System.out.println("Alice"); else System.out.println("Bob"); } } } static long solve(long[] arr,long l,long r, int n,int k) { int j; if(l<=r) { long m = l+(r-l)/2; long sum = arr[0]+m; for(j=1;j<n;j++) { if((double)arr[j]> (double)(sum*k)/(double)100) break; sum+=arr[j]; } if(j==n) return solve(arr,l,m-1,n,k); else return solve(arr,m+1,r,n,k); } return l; } static long factorial(long n) { return (n == 1 || n == 0) ? 1 : n * factorial(n - 1); } static long setbitNumber(long n) { long k = (int)(Math.log(n) / Math.log(2)); return 1 << k; } static void leftrotate(int arr[],int i, int n) { int t = arr[i]; int f; int j = i+1; for(;j<=n;j++) { f = arr[j]; arr[j] = t; t = f; } arr[i] = t; } static int search(int l, int r,int x, int[]arr) { if (r >= l) { int mid = l + (r - l) / 2; if (arr[mid] == x) return mid; if (arr[mid] > x) return search( l, mid - 1, x,arr); return search( mid + 1, r, x,arr); } return -1; } static long combination(long n, long k){ // nCr combination long res = 1; if (k > n - k) k = n - k; // Calculate value of // [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1] for (int i = 0; i < k; ++i) { res *= (n - i); res /= (i + 1); } return res; } static long modpower(long x, long y, long p) { long res = 1; // Initialize result x = x % p; // Update x if it is more than or // equal to p if (x == 0) return 0; // In case x is divisible by p; while (y > 0) { // If y is odd, multiply x with result if ((y & 1) != 0) res = (res * x) % p; // y must be even now y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } static int xor(int n){ // If n is a multiple of 4 if (n % 4 == 0) return n; // If n%4 gives remainder 1 if (n % 4 == 1) return 1; // If n%4 gives remainder 2 if (n % 4 == 2) return n + 1; return 0; } static int getsum(int n) // sum of digits { int sum = 0; while (n != 0) { sum = sum + n % 10; n = n/10; } return sum; } static boolean isPrime(int n) // check prime { if (n <= 1) return false; else if (n == 2) return true; else if (n % 2 == 0) return false; for (int i = 3; i <= Math.sqrt(n); i += 2) { if (n % i == 0) return false; } return true; } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
eb06cdf6b9f40e4d49af2ec170d3f436
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import java.util.Scanner; public class Fortune_Telling { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int t = scanner.nextInt(); for(int i = 0; i < t; i++){ int n = scanner.nextInt(); long a = scanner.nextLong(); long b = a + 3; long y = scanner.nextLong(); long sum = 0; for(int j = 0; j < n; j++){ sum ^= scanner.nextLong(); } if((a ^ sum) % 2 == y % 2){ System.out.println("Alice"); } else{ System.out.println("Bob"); } } } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
4bd3be86777f12c3d58fa7f2c2330ca0
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import java.util.Scanner; public class Fortune_Telling { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int t = scanner.nextInt(); for(int i = 0; i < t; i++){ int n = scanner.nextInt(); long a = scanner.nextLong(); long b = a + 3; long y = scanner.nextLong(); long sum = 0; for(int j = 0; j < n; j++){ sum += scanner.nextLong(); } if((a + sum) % 2 == y % 2){ System.out.println("Alice"); } else{ System.out.println("Bob"); } } } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
251140068069950264b6e508cc3334b9
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import java.util.Scanner; public class Fortune_Telling { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int t = scanner.nextInt(); for(int i = 0; i < t; i++){ int n = scanner.nextInt(); long a = scanner.nextLong(); long b = a + 3; long y = scanner.nextLong(); long[] arr = new long[n]; for(int j = 0; j < arr.length; j++){ arr[j] = scanner.nextLong(); } long sum = 0; for(int j = 0; j < arr.length; j++){ sum += arr[j]; } if((a + sum) % 2 == y % 2){ System.out.println("Alice"); } else{ System.out.println("Bob"); } } } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
1e7fd2ac78182dd622c416095c2c278e
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class Codechef { public static void main (String[] args) throws java.lang.Exception { try{ Scanner s = new Scanner(System.in); int t = s.nextInt(); StringBuffer sb = new StringBuffer(); while(t-- > 0){ int n = s.nextInt(); long x = s.nextLong(); long y = s.nextLong(); int a[] = new int[n]; long sum = 0; for(int i = 0; i < n; i++){ a[i] = s.nextInt(); sum += a[i]; } if((sum + x) % 2 == y % 2){ sb.append("Alice\n"); }else sb.append("Bob\n"); } System.out.println(sb); }catch(Exception e){} } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
97af6d91047567df5786b757e1529abb
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { final Solver solver = new Solver(); final Scanner in = new Scanner(System.in); StringBuilder stringBuilder = new StringBuilder(); int testCases = in.nextInt(); in.nextLine(); solver.solve(testCases, in, stringBuilder); } } class Solver { public void solve(int n, Scanner in, StringBuilder sb) { for(int i = 0; i < n; i++) { int arLen = in.nextInt(); int alice = in.nextInt(); int bob = alice + 3; long target = in.nextLong(); in.nextLine(); String[] ar = in.nextLine().split(" "); int sum = 0; for(int k = 0; k < arLen; k++) { sum += Integer.valueOf(ar[k]); } if(sum % 2 ==0) { if(alice % 2 == target % 2){ sb.append("Alice\n"); } else { sb.append("Bob\n"); } } else { if (alice % 2 != target % 2) { sb.append("Alice\n"); } else { sb.append("Bob\n"); } } } System.out.println(sb); } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
c1faab0423520b46e89bbfb6c4615c88
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
// code designed and developed by Naaru import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.*; import java.util.concurrent.ArrayBlockingQueue; // Solution public class Solution { static InputStream is; static PrintWriter out; static String INPUT = ""; static void solve() { // for the purpose of CF T is replaced by 1 as it takes each test case separate so when you will use for KickStart use the T = ni() where ni() would be the no of testcases for (int T = ni(), cas = 1; T > 0; T--, cas++) { // out.print("Case #" + cas + ": "); go(); } } static void go() { int n = ni(); long x = nl(); long y = nl(); long bobNO = x + 3; int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = ni(); } long oddCount = 0 ; for (int i = 0; i < n; i++) { if ( arr[i]% 2 == 1){ oddCount ++ ; } } x+= oddCount ; if ( (x % 2 == 0 && y%2 == 0) || ( x%2 == 1 && y%2 == 1)){ out.println("Alice"); }else{ out.println("Bob"); } } static boolean isPalindrome(String str) { int i = 0, j = str.length() - 1; while (i < j) { if (str.charAt(i) != str.charAt(j)) return false; i++; j--; } return true; } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } static long lcm(long a, long b) { return (a * b) / gcd(a, b); } // main function public static void main(String[] args) throws Exception { long S = System.currentTimeMillis(); is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes()); out = new PrintWriter(System.out); solve(); out.flush(); long G = System.currentTimeMillis(); tr(G - S + "ms"); } private static boolean eof() { if (lenbuf == -1) return true; int lptr = ptrbuf; while (lptr < lenbuf) if (!isSpaceChar(inbuf[lptr++])) return false; try { is.mark(1000); while (true) { int b = is.read(); if (b == -1) { is.reset(); return true; } else if (!isSpaceChar(b)) { is.reset(); return false; } } } catch (IOException e) { return true; } } private static byte[] inbuf = new byte[1024]; static int lenbuf = 0, ptrbuf = 0; private static int readByte() { if (lenbuf == -1) throw new InputMismatchException(); if (ptrbuf >= lenbuf) { ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if (lenbuf <= 0) return -1; } return inbuf[ptrbuf++]; } private static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } // private static boolean isSpaceChar(int c) { return !(c >= 32 && c <= 126); } private static int skip() { int b; while ((b = readByte()) != -1 && isSpaceChar(b)); return b; } private static double nd() { return Double.parseDouble(ns()); } private static char nc() { return (char) skip(); } private static String ns() { int b = skip(); StringBuilder sb = new StringBuilder(); while (!(isSpaceChar(b))) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } private static char[] ns(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while (p < n && !(isSpaceChar(b))) { buf[p++] = (char) b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } private static char[][] nm(int n, int m) { char[][] map = new char[n][]; for (int i = 0; i < n; i++) map[i] = ns(m); return map; } private static int[] na(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = ni(); return a; } private static int ni() { int num = 0, b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } private static long nl() { long num = 0; int b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } private static void tr(Object... o) { if (INPUT.length() != 0) System.out.println(Arrays.deepToString(o)); } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
f080649bf4da515e8674d53b0075e753
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import java.util.Scanner; public class FortuneTelling { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t-- > 0){ int n = sc.nextInt(); int x = sc.nextInt(); long y = sc.nextLong(); int[] a = new int[n]; int count = 0; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); count += a[i] % 2; } if (count % 2 == 0) { if (x % 2 == y % 2) { System.out.println("Alice"); } else { System.out.println("Bob"); } } else { if (x % 2 != y % 2) { System.out.println("Alice"); } else { System.out.println("Bob"); } } } } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
00ae7b8455a39b8714dd10a36aa8c803
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import java.util.*; import java.io.*; public class B { static FastScanner fs = new FastScanner(); static PrintWriter pw = new PrintWriter(System.out); static StringBuilder sb = new StringBuilder(""); static ArrayList<ArrayList<Integer>> E = new ArrayList<>(); static int[] ans; public static void main(String[] args) { int t = fs.nextInt(); for (int tt = 0; tt < t; tt++) { int n = fs.nextInt(); int x = fs.nextInt(); long y = fs.nextLong(); int s = 0; for (int i = 0; i < n; i++) s += fs.nextInt(); if ((s + x + y) % 2 == 0) sb.append("Alice\n"); else sb.append("Bob\n"); } pw.print(sb.toString()); pw.close(); } static void sort(long[] a) { ArrayList<Long> al = new ArrayList<>(); for (long i : a) al.add(i); Collections.sort(al); for (int i = 0; i < a.length; i++) a[i] = al.get(i); } static class FastScanner { 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) {}return st.nextToken();} int nextInt() {return Integer.parseInt(next());} long nextLong() {return Long.parseLong(next());} double nextDouble() {return Double.parseDouble(next());} } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
217e4bfc5720ecd95b7f8e1e5b33767a
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws IOException { var io = new Kattio(System.in, System.out); solve(io); io.close(); } public static void solve(Kattio io) { int cases = io.nextInt(); while(cases != 0) { int n = io.nextInt(); long x = io.nextLong(); long target = io.nextLong(); for(int i = 0 ; i < n; i++) { x = x ^ io.nextInt(); } if(x % 2 == target % 2) { io.println("Alice"); } else { io.println("Bob"); } cases --; } } } class Kattio extends PrintWriter { public Kattio(InputStream i) { super(new BufferedOutputStream(System.out)); r = new BufferedReader(new InputStreamReader(i)); } public Kattio(InputStream i, OutputStream o) { super(new BufferedOutputStream(o)); r = new BufferedReader(new InputStreamReader(i)); } public boolean hasMoreTokens() { return peekToken() != null; } public int nextInt() { return Integer.parseInt(nextToken()); } public double nextDouble() { return Double.parseDouble(nextToken()); } public long nextLong() { return Long.parseLong(nextToken()); } public String next() { 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; } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
d0e4397e5dea0f6e6c7d8bb91ae8671b
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int T = scan.nextInt(); while (T-->0) { long n = scan.nextLong(); long x = scan.nextLong(); long y = scan.nextLong(); long sum = 0; for (int i = 0; i < n; i++) { sum+=scan.nextInt(); } if ((x+sum)%2==y%2) {System.out.println("Alice");} else {System.out.println("Bob");} } } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
d41506819765543aff93efc29738fc68
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import java.util.*; public class Solution{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0){ int n = sc.nextInt(); long x = sc.nextLong(); long y = sc.nextLong(); long sum = 0; for(int i=0;i<n;i++) sum+=sc.nextLong(); if((sum+x)%2==y%2) System.out.println("Alice"); else System.out.println("Bob"); } } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
433909f86ae81750ed6f2033236e2c61
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import java.util.*; public class HelloWorld{ public static void main(String []args){ Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0) { long n = sc.nextLong(); long x = sc.nextLong(); long y = sc.nextLong(); long sum = 0; for(int i=0; i<n; i++) { long a = sc.nextLong(); sum+=a; } if((sum+x+y)%2==0) System.out.println("Alice"); else System.out.println("Bob"); } } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
737f73ed6efe41a691a9bf86f6d918f8
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import java.util.*; import java.io.*; public class Codeforces_1634B { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st; int t = Integer.parseInt(br.readLine()); int n; Long x, y; while((t--) > 0) { st = new StringTokenizer(br.readLine()); n = Integer.parseInt(st.nextToken()); x = Long.parseLong(st.nextToken()); y = Long.parseLong(st.nextToken()); Long sum = Long.valueOf(0); st = new StringTokenizer(br.readLine()); for (int i = 0; i < n; i++) { sum ^= Long.parseLong(st.nextToken()); } if (sum % 2 == 0) { if (x % 2 == y % 2) { System.out.println("Alice"); continue; } System.out.println("Bob"); } else { if (x % 2 != y % 2) { System.out.println("Alice"); continue; } System.out.println("Bob"); } } } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
6f74da3d7aa5939af6da4d7932c7d32e
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import java.util.*; import java.io.*; public class Codeforces_1634B { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st; int t = Integer.parseInt(br.readLine()); int n; Long x, y; while((t--) > 0) { st = new StringTokenizer(br.readLine()); n = Integer.parseInt(st.nextToken()); x = Long.parseLong(st.nextToken()); y = Long.parseLong(st.nextToken()); Long sum = Long.valueOf(0); st = new StringTokenizer(br.readLine()); for (int i = 0; i < n; i++) { sum += Long.parseLong(st.nextToken()); } if (sum % 2 == 0) { if (x % 2 == y % 2) { System.out.println("Alice"); continue; } System.out.println("Bob"); } else { if (x % 2 != y % 2) { System.out.println("Alice"); continue; } System.out.println("Bob"); } } } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
1d278ffdd949426d99db2b05241fb552
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
//package com.codeforces.Practise; import java.io.*; public class NotUnderstadingQuestionProperly { public static void main(String[] args)throws IOException { Reader scan=new Reader(); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); int t=scan.nextInt(); while (t-->0) { long n=scan.nextLong(); long x=scan.nextLong(); long y=scan.nextLong(); long sum=x; for (int i = 0; i < n; i++){ long val=scan.nextLong(); sum+=val; } String ans="Bob"; if(sum%2==y%2)ans="Alice"; bw.write(ans+""); bw.newLine(); bw.flush(); } } //FAST READER static class Reader { public int BS = 1<<16; public char NC = (char)0; byte[] buf = new byte[BS]; int bId = 0, size = 0; char c = NC; double num = 1; BufferedInputStream in; public Reader() { in = new BufferedInputStream(System.in, BS); } public Reader(String s) throws FileNotFoundException { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } public char nextChar(){ while(bId==size) { try { size = in.read(buf); }catch(Exception e) { return NC; } if(size==-1)return NC; bId=0; } return (char)buf[bId++]; } public int nextInt() { return (int)nextLong(); } public long nextLong() { num=1; boolean neg = false; if(c==NC)c=nextChar(); for(;(c<'0' || c>'9'); c = nextChar()) { if(c=='-')neg=true; } long res = 0; for(; c>='0' && c <='9'; c=nextChar()) { res = (res<<3)+(res<<1)+c-'0'; num*=10; } return neg?-res:res; } public double nextDouble() { double cur = nextLong(); return c!='.' ? cur:cur+(cur < 0 ? -1*nextLong()/num : nextLong()/num); } public String next() { StringBuilder res = new StringBuilder(); while(c<=32)c=nextChar(); while(c>32) { res.append(c); c=nextChar(); } return res.toString(); } } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
ea963ff3cded45a874231a2593086895
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import java.util.*; public class FortuneTelling { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); long a=sc.nextLong()&1; long b=sc.nextLong()&1; long c=0; for(int i=0;i<n;i++) { c=sc.nextInt()&1; if(a==c) { a=0; } else { a=1; } } // System.out.println(a+" "+b); if(a==b) { System.out.println("Alice"); } else { System.out.println("Bob"); } } } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
48a0a7e5fe0522644cb14c6c76f79730
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
// JAI SHREE RAM, HAR HAR MAHADEV, HARE KRISHNA import java.util.*; import java.util.stream.*; import java.lang.*; import java.math.BigInteger; import java.text.DecimalFormat; import java.io.*; public class Eshan { static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer st; static PrintWriter out = new PrintWriter(System.out); static DecimalFormat df = new DecimalFormat("0.0000000"); final static int mod = (int) (1e9 + 7); final static int MAX = Integer.MAX_VALUE; final static int MIN = Integer.MIN_VALUE; static Random rand = new Random(); // ======================= MAIN ================================== public static void main(String[] args) throws IOException { long time = System.currentTimeMillis(); boolean oj = System.getProperty("ONLINE_JUDGE") != null; // ==== start ==== int t = readInt(); // int t = 1; preprocess(); while (t-- > 0) { solve(); } out.flush(); // ==== end ==== if (!oj) System.out.println(Arrays.deepToString(new Object[] { System.currentTimeMillis() - time + " ms" })); } private static void solve() throws IOException { int n = readInt(); long x = readLong(), y = readLong(); for (int i = 0; i < n; i++) x += readInt(); if ((x & 1) == (y & 1)) out.println("Alice"); else out.println("Bob"); } private static void preprocess() { } // ======================= FOR INPUT ================================== static String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(readLine()); return st.nextToken(); } static long readLong() throws IOException { return Long.parseLong(next()); } static int readInt() throws IOException { return Integer.parseInt(next()); } static double readDouble() throws IOException { return Double.parseDouble(next()); } static char readCharacter() throws IOException { return next().charAt(0); } static String readString() throws IOException { return next(); } static String readLine() throws IOException { return br.readLine().trim(); } static int[] readIntArray(int n) throws IOException { int[] arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = readInt(); return arr; } static int[][] read2DIntArray(int n, int m) throws IOException { int[][] arr = new int[n][m]; for (int i = 0; i < n; i++) arr[i] = readIntArray(m); return arr; } static List<Integer> readIntList(int n) throws IOException { List<Integer> list = new ArrayList<>(); for (int i = 0; i < n; i++) list.add(readInt()); return list; } static long[] readLongArray(int n) throws IOException { long[] arr = new long[n]; for (int i = 0; i < n; i++) arr[i] = readLong(); return arr; } static long[][] read2DLongArray(int n, int m) throws IOException { long[][] arr = new long[n][m]; for (int i = 0; i < n; i++) arr[i] = readLongArray(m); return arr; } static List<Long> readLongList(int n) throws IOException { List<Long> list = new ArrayList<>(); for (int i = 0; i < n; i++) list.add(readLong()); return list; } static char[] readCharArray(int n) throws IOException { return readString().toCharArray(); } static char[][] readMatrix(int n, int m) throws IOException { char[][] mat = new char[n][m]; for (int i = 0; i < n; i++) mat[i] = readCharArray(m); return mat; } // ========================= FOR OUTPUT ================================== private static void printIList(List<Integer> list) { for (int i = 0; i < list.size(); i++) out.print(list.get(i) + " "); out.println(" "); } private static void printLList(List<Long> list) { for (int i = 0; i < list.size(); i++) out.print(list.get(i) + " "); out.println(" "); } private static void printIArray(int[] arr) { for (int i = 0; i < arr.length; i++) out.print(arr[i] + " "); out.println(" "); } private static void print2DIArray(int[][] arr) { for (int i = 0; i < arr.length; i++) printIArray(arr[i]); } private static void printLArray(long[] arr) { for (int i = 0; i < arr.length; i++) out.print(arr[i] + " "); out.println(" "); } private static void print2DLArray(long[][] arr) { for (int i = 0; i < arr.length; i++) printLArray(arr[i]); } // ====================== TO CHECK IF STRING IS NUMBER ======================== private static boolean isInteger(String s) { try { Integer.parseInt(s); } catch (NumberFormatException e) { return false; } catch (NullPointerException e) { return false; } return true; } private static boolean isLong(String s) { try { Long.parseLong(s); } catch (NumberFormatException e) { return false; } catch (NullPointerException e) { return false; } return true; } // ==================== FASTER SORT ================================ private static void sort(int[] arr) { int n = arr.length; List<Integer> list = new ArrayList<>(); for (int i = 0; i < n; i++) list.add(arr[i]); Collections.sort(list); for (int i = 0; i < n; i++) arr[i] = list.get(i); } private static void sort(long[] arr) { int n = arr.length; List<Long> list = new ArrayList<>(); for (int i = 0; i < n; i++) list.add(arr[i]); Collections.sort(list); for (int i = 0; i < n; i++) arr[i] = list.get(i); } // ==================== MATHEMATICAL FUNCTIONS =========================== private static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } private static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } private static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } private static long lcm(long a, long b) { return (a / gcd(a, b)) * b; } private static long power(long a, long b) { if (b == 0) return 1L; long ans = power(a, b >> 1); ans *= ans; if ((b & 1) == 1) ans *= a; return ans; } private static int mod_power(int a, int b) { if (b == 0) return 1; int temp = mod_power(a, b / 2); temp %= mod; temp = (int) ((1L * temp * temp) % mod); if ((b & 1) == 1) temp = (int) ((1L * temp * a) % mod); return temp; } private static int multiply(int a, int b) { return (int) ((((1L * a) % mod) * ((1L * b) % mod)) % mod); } private static boolean isPrime(long n) { for (long i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } private static long nCr(long n, long r) { if (n - r > r) r = n - r; long ans = 1L; for (long i = r + 1; i <= n; i++) ans *= i; for (long i = 2; i <= n - r; i++) ans /= i; return ans; } // ==================== Primes using Seive ===================== private static List<Integer> SeivePrime(int n) { boolean[] prime = new boolean[n + 1]; Arrays.fill(prime, true); for (int i = 2; i * i <= n; i++) { if (prime[i]) { for (int j = i * i; j <= n; j += i) prime[j] = false; } } List<Integer> list = new ArrayList<>(); for (int i = 2; i <= n; i++) if (prime[i]) list.add(i); return list; } // ==================== STRING FUNCTIONS ================================ private static boolean isPalindrome(String str) { int i = 0, j = str.length() - 1; while (i < j) if (str.charAt(i++) != str.charAt(j--)) return false; return true; } private static String reverseString(String str) { StringBuilder sb = new StringBuilder(str); return sb.reverse().toString(); } // ==================== LIS & LNDS ================================ private static int LIS(int arr[], int n) { List<Integer> list = new ArrayList<>(); for (int i = 0; i < n; i++) { int idx = find(list, arr[i]); if (idx < list.size()) list.set(idx, arr[i]); else list.add(arr[i]); } return list.size(); } private static int find(List<Integer> list, int val) { int ret = list.size(), i = 0, j = list.size() - 1; while (i <= j) { int mid = (i + j) / 2; if (list.get(mid) >= val) { ret = mid; j = mid - 1; } else { i = mid + 1; } } return ret; } private static int LNDS(int[] arr, int n) { List<Integer> list = new ArrayList<>(); for (int i = 0; i < n; i++) { int idx = find2(list, arr[i]); if (idx < list.size()) list.set(idx, arr[i]); else list.add(arr[i]); } return list.size(); } private static int find2(List<Integer> list, int val) { int ret = list.size(), i = 0, j = list.size() - 1; while (i <= j) { int mid = (i + j) / 2; if (list.get(mid) <= val) { i = mid + 1; } else { ret = mid; j = mid - 1; } } return ret; } // ==================== UNION FIND ===================== private static int find(int x, int[] parent) { if (parent[x] == x) return x; return parent[x] = find(parent[x], parent); } private static boolean union(int x, int y, int[] parent, int[] rank) { int lx = find(x, parent), ly = find(y, parent); if (lx == ly) return true; if (rank[lx] > rank[ly]) parent[ly] = lx; else if (rank[lx] < rank[ly]) parent[lx] = ly; else { parent[lx] = ly; rank[ly]++; } return false; } // ==================== SEGMENT TREE (RANGE SUM) ===================== public static class SegmentTree { int n; int[] arr, tree, lazy; SegmentTree(int arr[]) { this.arr = arr; this.n = arr.length; this.tree = new int[(n << 2)]; this.lazy = new int[(n << 2)]; build(1, 0, n - 1); } void build(int id, int start, int end) { if (start == end) tree[id] = arr[start]; else { int mid = (start + end) / 2, left = (id << 1), right = left + 1; build(left, start, mid); build(right, mid + 1, end); tree[id] = tree[left] + tree[right]; } } void update(int l, int r, int val) { update(1, 0, n - 1, l, r, val); } void update(int id, int start, int end, int l, int r, int val) { distribute(id, start, end); if (end < l || r < start) return; if (start == end) tree[id] += val; else if (l <= start && end <= r) { lazy[id] += val; distribute(id, start, end); } else { int mid = (start + end) / 2, left = (id << 1), right = left + 1; update(left, start, mid, l, r, val); update(right, mid + 1, end, l, r, val); tree[id] = tree[left] + tree[right]; } } int query(int l, int r) { return query(1, 0, n - 1, l, r); } int query(int id, int start, int end, int l, int r) { if (end < l || r < start) return 0; distribute(id, start, end); if (start == end) return tree[id]; else if (l <= start && end <= r) return tree[id]; else { int mid = (start + end) / 2, left = (id << 1), right = left + 1; return query(left, start, mid, l, r) + query(right, mid + 1, end, l, r); } } void distribute(int id, int start, int end) { if (start == end) tree[id] += lazy[id]; else { tree[id] += lazy[id] * (end - start + 1); lazy[(id << 1)] += lazy[id]; lazy[(id << 1) + 1] += lazy[id]; } lazy[id] = 0; } } // ==================== TRIE ================================ static class Trie { class Node { Node[] children; boolean isEnd; Node() { children = new Node[26]; } } Node root; Trie() { root = new Node(); } public void insert(String word) { Node curr = root; for (char ch : word.toCharArray()) { if (curr.children[ch - 'a'] == null) curr.children[ch - 'a'] = new Node(); curr = curr.children[ch - 'a']; } curr.isEnd = true; } public boolean find(String word) { Node curr = root; for (char ch : word.toCharArray()) { if (curr.children[ch - 'a'] == null) return false; curr = curr.children[ch - 'a']; } return curr.isEnd; } } // ==================== FENWICK TREE ================================ static class FT { long[] tree; int n; FT(int[] arr, int n) { this.n = n; this.tree = new long[n + 1]; for (int i = 1; i <= n; i++) { update(i, arr[i - 1]); } } void update(int idx, int val) { while (idx <= n) { tree[idx] += val; idx += idx & -idx; } } long query(int l, int r) { return getSum(r) - getSum(l - 1); } long getSum(int idx) { long ans = 0L; while (idx > 0) { ans += tree[idx]; idx -= idx & -idx; } return ans; } } // ==================== BINARY INDEX TREE ================================ static class BIT { long[][] tree; int n, m; BIT(int[][] mat, int n, int m) { this.n = n; this.m = m; tree = new long[n + 1][m + 1]; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { update(i, j, mat[i - 1][j - 1]); } } } void update(int x, int y, int val) { while (x <= n) { int t = y; while (t <= m) { tree[x][t] += val; t += t & -t; } x += x & -x; } } long query(int x1, int y1, int x2, int y2) { return getSum(x2, y2) - getSum(x1 - 1, y2) - getSum(x2, y1 - 1) + getSum(x1 - 1, y1 - 1); } long getSum(int x, int y) { long ans = 0L; while (x > 0) { int t = y; while (t > 0) { ans += tree[x][t]; t -= t & -t; } x -= x & -x; } return ans; } } // ==================== OTHER CLASSES ================================ static class Pair implements Comparable<Pair> { int first, second; Pair(int first, int second) { this.first = first; this.second = second; } public int compareTo(Pair o) { return this.first - o.first; } } static class DequeNode { DequeNode prev, next; int val; DequeNode(int val) { this.val = val; } DequeNode(int val, DequeNode prev, DequeNode next) { this.val = val; this.prev = prev; this.next = next; } } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
299ff31f4832a8536941e604c62ef2cc
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import java.util.ArrayList; import java.util.Scanner; public class ReverseAndConcatinate { public static void main(String[] args) { int testCase=0; Scanner input = new Scanner(System.in); testCase= input.nextInt(); while(0!=testCase--){ double arrLen = input.nextInt(); long alice = input.nextLong(); long y = input.nextLong(); long sum=0; for(int i=0;i<arrLen;i++) sum+= input.nextInt(); if((y%2==0 && (alice+sum)%2==0) || (y%2==1 && ((alice+sum)%2==1))) System.out.println("Alice"); else System.out.println("Bob"); } } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
145fadb3bb3c5a2dcce1ed96b8a293ef
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; import java.io.*; import java.util.*; public class B { static int mod=(int)1e9+7; public static void main(String[] args) { var io = new Copied(System.in, System.out); // int k=1; int t = 1; t = io.nextInt(); for (int i = 0; i < t; i++) { // out.println("Case #" + k + ": "); solve(io); // k++; } io.close(); } public static void solve(Copied io) { long n=io.nextLong(),x=io.nextLong(),y=io.nextLong(); long a[]=io.nextLongs((int)n); long sum=0; for(long l:a) sum+=l; if(sum%2==(max(x,y)-min(x,y))%2){ io.println("Alice"); } else{ io.println("Bob"); } } public static String sortString(String inputString) { char tempArray[] = inputString.toCharArray(); Arrays.sort(tempArray); return new String(tempArray); } static int power(int x, int y, int p) { int res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if ((y & 1) != 0) res = (res * x) % p; y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } static void sort(int[] a) { ArrayList<Integer> l = new ArrayList<>(); for (int i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } public static void printArr(int[] arr) { for (int x : arr) System.out.print(x + " "); System.out.println(); } public static int[] listToInt(ArrayList<Integer> a){ int n=a.size(); int arr[]=new int[n]; for(int i=0;i<n;i++){ arr[i]=a.get(i); } return arr; } static int mod_mul(int a, int b){ a = a % mod; b = b % mod; return (((a * b) % mod) + mod) % mod;} static int mod_add(int a, int b){ a = a % mod; b = b % mod; return (((a + b) % mod) + mod) % mod;} static int mod_sub(int a, int b){ a = a % mod; b = b % mod; return (((a - b) % mod) + mod) % mod;} } class Pair { int a,b; Pair(int a,int b) { this.a=a; this.b=b; } } class DescendingOrder<T> implements Comparator<T>{ @Override public int compare(Object o1,Object o2){ // -1 if want to swap and (1,0) otherwise. int addingNumber=(Integer) o1,existingNumber=(Integer) o2; if(addingNumber>existingNumber) return -1; else if(addingNumber<existingNumber) return 1; else return 0; } } class Copied extends PrintWriter { public Copied(InputStream i) { super(new BufferedOutputStream(System.out)); r = new BufferedReader(new InputStreamReader(i)); } public Copied(InputStream i, OutputStream o) { super(new BufferedOutputStream(o)); r = new BufferedReader(new InputStreamReader(i)); } public boolean hasMoreTokens() { return peekToken() != null; } public int nextInt() { return Integer.parseInt(nextToken()); } public double nextDouble() { return Double.parseDouble(nextToken()); } public long nextLong() { return Long.parseLong(nextToken()); } public String next() { return nextToken(); } public double[] nextDoubles(int N) { double[] res = new double[N]; for (int i = 0; i < N; i++) { res[i] = nextDouble(); } return res; } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public long[] nextLongs(int N) { long[] res = new long[N]; for (int i = 0; i < N; i++) { res[i] = nextLong(); } return res; } 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; } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
0e4c1650d6e080cbb9ed01768f965d2d
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import java.util.*; public class fortune_telling { public static void main(String[]args){ Scanner s = new Scanner(System.in); int test = s.nextInt(); while(test --> 0){ long n = s.nextLong(); long x = s.nextLong(); long y = s.nextLong(); while(n --> 0){ long numbers = s.nextLong(); x ^= numbers; } System.out.println((x&1) == (y&1) ? "Alice" : "Bob"); } } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
67c94065151e2e0c24a0ccf9dadee6fe
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import java.util.*; public class IncString { public static void main(String[] args) { int t; Scanner sc = new Scanner(System.in); t = sc.nextInt(); while(t-- > 0) { long n = sc.nextLong(); long x = sc.nextLong(); long y = sc.nextLong(); long arr[] = new long[(int)n]; int cnt = 0; for(int i=0;i<n;i++) { arr[i] = sc.nextLong(); if(arr[i]%2 != 0) cnt++; } cnt %= 2; if(cnt == 1) { if(y%2 != 0) { if(x%2 == 0) System.out.println("Alice"); else System.out.println("Bob"); } else { if(x%2 != 0) System.out.println("Alice"); else System.out.println("Bob"); } } else { if(y%2 != 0) { if(x%2 != 0) System.out.println("Alice"); else System.out.println("Bob"); } else { if(x%2 == 0) System.out.println("Alice"); else System.out.println("Bob"); } } } } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
4543891e804e304cbb62f65f9c805d70
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import java.io.*; import java.util.*; public class Solution { public static void main (String[] args) throws java.lang.Exception { int t=1; t = sc.nextInt(); while(t-->0){ long n = sc.nextLong(), x = sc.nextLong(), y = sc.nextLong(), sum=0; for(int i=0; i<n; i++){ sum+=sc.nextLong();; } if((sum+x-y)%2==0){ System.out.println("Alice"); }else{ System.out.println("Bob"); } // if(x%2==0){ // if(sum%2==0){ // if(y%2==0){ // System.out.println("Alice"); // }else{ // System.out.println("Bob"); // } // }else{ // if(y%2==0){ // System.out.println("Bob"); // }else{ // System.out.println("Alice"); // } // } // }else{ // if(sum%2==0){ // if(y%2==0){ // System.out.println("Bob"); // }else{ // System.out.println("Alice"); // } // }else{ // if(y%2==0){ // System.out.println("Alice"); // }else{ // System.out.println("Bob"); // } // } // } } } // Fast Reader Class public static FastReader sc = new FastReader(); public static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)); 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()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); }return str; } } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
65a2ea00962218a7a6c3b02810201069
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import java.io.*; import java.util.*; public class Solution { public static void main (String[] args) throws java.lang.Exception { int t=1; t = sc.nextInt(); while(t-->0){ long n = sc.nextLong(); long x = sc.nextLong(); long y = sc.nextLong(); long sum=0; for(int i=0; i<n; i++){ long temp = sc.nextLong(); sum+=temp; } if(x%2==0){ if(sum%2==0){ if(y%2==0){ System.out.println("Alice"); }else{ System.out.println("Bob"); } }else{ if(y%2==0){ System.out.println("Bob"); }else{ System.out.println("Alice"); } } }else{ if(sum%2==0){ if(y%2==0){ System.out.println("Bob"); }else{ System.out.println("Alice"); } }else{ if(y%2==0){ System.out.println("Alice"); }else{ System.out.println("Bob"); } } } } } // Fast Reader Class public static FastReader sc = new FastReader(); public static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)); 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()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); }return str; } } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
619d244f71a579fa8cf13fbd34559a15
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Scanner; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.Writer; import java.lang.reflect.Array; import java.io.DataInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; import org.w3c.dom.NamedNodeMap; import java.io.*; import java.math.*; import java.util.*; import java.util.Arrays; import java.util.Comparator; import java.util.*; public class ispcff { public static void main(String[] args) throws java.lang.Exception { ispcff.FastReader sc =new FastReader(); int t = sc.nextInt(); for(int i =0;i<t;i++) { int n = sc.nextInt(); long x = sc.nextLong() ; long y = sc.nextLong(); long arr[]= new long [n]; long sum=0; for (int e =0;e<n;e++) { arr[e]= sc.nextLong(); sum+=arr[e]; } if(((sum+x+y)%2==0)) { System.out.println("Alice"); } else { System.out.println("Bob"); } } } 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()); } float nextFloat() { return Float.parseFloat(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long[] readArrayLong(int n) { long[] a=new long[n]; for (int i=0; i<n; i++) a[i]=nextLong(); return a; } } public static int[] radixSort2(int[] a) { int n = a.length; int[] c0 = new int[0x101]; int[] c1 = new int[0x101]; int[] c2 = new int[0x101]; int[] c3 = new int[0x101]; for(int v : a) { c0[(v&0xff)+1]++; c1[(v>>>8&0xff)+1]++; c2[(v>>>16&0xff)+1]++; c3[(v>>>24^0x80)+1]++; } for(int i = 0;i < 0xff;i++) { c0[i+1] += c0[i]; c1[i+1] += c1[i]; c2[i+1] += c2[i]; c3[i+1] += c3[i]; } int[] t = new int[n]; for(int v : a)t[c0[v&0xff]++] = v; for(int v : t)a[c1[v>>>8&0xff]++] = v; for(int v : a)t[c2[v>>>16&0xff]++] = v; for(int v : t)a[c3[v>>>24^0x80]++] = v; return a; } static void reverse_sorted(int[] arr) { ArrayList<Integer> list = new ArrayList<>(); for(int i=0;i<arr.length;i++) { list.add(arr[i]); } Collections.sort(list , Collections.reverseOrder()); for(int i=0;i<arr.length;i++) { arr[i] = list.get(i); } } static int LowerBound(int a[], int x) { // x is the target value or key int l=-1,r=a.length; while(l+1<r) { int m=(l+r)>>>1; if(a[m]>=x) r=m; else l=m; } return r; } static int UpperBound(ArrayList<Integer> list, int x) {// x is the key or target value int l=-1,r=list.size(); while(l+1<r) { int m=(l+r)>>>1; if(list.get(m)<=x) l=m; else r=m; } return l+1; } public static HashMap<String, Integer> sortByValue(HashMap<String, Integer> hm) { // Create a list from elements of HashMap List<Map.Entry<String, Integer> > list = new LinkedList<Map.Entry<String, Integer> >(hm.entrySet()); // Sort the list Collections.sort(list, new Comparator<Map.Entry<String, Integer> >() { public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) { return (o1.getValue()).compareTo(o2.getValue()); } }); // put data from sorted list to hashmap HashMap<String, Integer> temp = new LinkedHashMap<String, Integer>(); for (Map.Entry<String, Integer> aa : list) { temp.put(aa.getKey(), aa.getValue()); } return temp; } static class Queue_Pair implements Comparable<Queue_Pair> { int first , second; public Queue_Pair(int first, int second) { this.first=first; this.second=second; } public int compareTo(Queue_Pair o) { return Integer.compare(o.first, first); } } static void leftRotate(int arr[], int d, int n) { for (int i = 0; i < d; i++) leftRotatebyOne(arr, n); } static void leftRotatebyOne(int arr[], int n) { int i, temp; temp = arr[0]; for (i = 0; i < n - 1; i++) arr[i] = arr[i + 1]; arr[n-1] = temp; } static boolean isPalindrome(String str) { // Pointers pointing to the beginning // and the end of the string int i = 0, j = str.length() - 1; // While there are characters to compare while (i < j) { // If there is a mismatch if (str.charAt(i) != str.charAt(j)) return false; // Increment first pointer and // decrement the other i++; j--; } // Given string is a palindrome return true; } static boolean palindrome_array(char arr[], int n) { // Initialise flag to zero. int flag = 0; // Loop till array size n/2. for (int i = 0; i <= n / 2 && n != 0; i++) { // Check if first and last element are different // Then set flag to 1. if (arr[i] != arr[n - i - 1]) { flag = 1; break; } } // If flag is set then print Not Palindrome // else print Palindrome. if (flag == 1) return false; else return true; } static boolean allElementsEqual(long[] arr,int n) { int z=0; for(int i=0;i<n-1;i++) { if(arr[i]==arr[i+1]) { z++; } } if(z==n-1) { return true; } else { return false; } } static boolean allElementsDistinct(int[] arr,int n) { int z=0; for(int i=0;i<n-1;i++) { if(arr[i]!=arr[i+1]) { z++; } } if(z==n-1) { return true; } else { return false; } } public static void reverse(int[] array) { // Length of the array int n = array.length; // Swaping the first half elements with last half // elements for (int i = 0; i < n / 2; i++) { // Storing the first half elements temporarily int temp = array[i]; // Assigning the first half to the last half array[i] = array[n - i - 1]; // Assigning the last half to the first half array[n - i - 1] = temp; } } public static void reverse_Long(long[] array) { // Length of the array int n = array.length; // Swaping the first half elements with last half // elements for (int i = 0; i < n / 2; i++) { // Storing the first half elements temporarily long temp = array[i]; // Assigning the first half to the last half array[i] = array[n - i - 1]; // Assigning the last half to the first half array[n - i - 1] = temp; } } static boolean isSorted(int[] a) { for (int i = 0; i < a.length - 1; i++) { if (a[i] > a[i + 1]) { return false; } } return true; } static boolean isReverseSorted(int[] a) { for (int i = 0; i < a.length - 1; i++) { if (a[i] < a[i + 1]) { return false; } } return true; } static int[] rearrangeEvenAndOdd(int arr[], int n) { ArrayList<Integer> list = new ArrayList<>(); for(int i=0;i<n;i++) { if(arr[i]%2==0) { list.add(arr[i]); } } for(int i=0;i<n;i++) { if(arr[i]%2!=0) { list.add(arr[i]); } } int len = list.size(); int[] array = list.stream().mapToInt(i->i).toArray(); return array; } static long[] rearrangeEvenAndOddLong(long arr[], int n) { ArrayList<Long> list = new ArrayList<>(); for(int i=0;i<n;i++) { if(arr[i]%2==0) { list.add(arr[i]); } } for(int i=0;i<n;i++) { if(arr[i]%2!=0) { list.add(arr[i]); } } int len = list.size(); long[] array = list.stream().mapToLong(i->i).toArray(); return array; } static boolean isPrime(long n) { // Check if number is less than // equal to 1 if (n <= 1) return false; // Check if number is 2 else if (n == 2) return true; // Check if n is a multiple of 2 else if (n % 2 == 0) return false; // If not, then just check the odds for (long i = 3; i <= Math.sqrt(n); i += 2) { if (n % i == 0) return false; } return true; } static long getSum(long n) { long sum = 0; while (n != 0) { sum = sum + n % 10; n = n/10; } return sum; } static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } static long gcdLong(long a, long b) { if (b == 0) return a; return gcdLong(b, a % b); } static void swap(int i, int j) { int temp = i; i = j; j = temp; } static int countDigit(int n) { return (int)Math.floor(Math.log10(n) + 1); } //Arrays.sort(arr, Comparator.comparingDouble(o -> o[0])); // q.replace(i, i+1, "4"); // StringBuilder q = new StringBuilder(w); }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
619b77436e7f36ab3ffe5052e5f31281
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
// have faith in yourself!! /* Naive mistakes in java : --> Arrays.sort(primitive) is O(n^2) --> Never use '=' to compare to Integer data types, instead use 'equals()' --> -4 % 3 = -1, actually it should be 2, so add '+n' to modulo result */ import java.io.*; import java.util.*; public class CodeForces { public static void main(String[] args) throws IOException { openIO(); int testCase = 1; testCase = sc. nextInt(); for (int i = 1; i <= testCase; i++) solve(i); closeIO(); } /*-------------------------------------------EDITING CODE STARTS HERE-------------------------------------------*/ public static void solve(int tCase) throws IOException { int n = sc.nextInt(); long sum = sc.nextInt(); long y = sc.nextLong(); for(int i=0;i<n;i++)sum += sc.nextInt(); if((sum % 2) == y % 2)out.println("Alice"); else out.println("Bob"); } /*-------------------------------------------EDITING CODE ENDS HERE-------------------------------------------*/ public static int mod = (int) 1e9 + 7; // public static int mod = 998244353; public static int inf_int = (int) 2e9; public static long inf_long = (long) 2e18; public static void _sort(int[] arr, boolean isAscending) { int n = arr.length; List<Integer> list = new ArrayList<>(); for (int ele : arr) list.add(ele); Collections.sort(list); if (!isAscending) Collections.reverse(list); for (int i = 0; i < n; i++) arr[i] = list.get(i); } public static void _sort(long[] arr, boolean isAscending) { int n = arr.length; List<Long> list = new ArrayList<>(); for (long ele : arr) list.add(ele); Collections.sort(list); if (!isAscending) Collections.reverse(list); for (int i = 0; i < n; i++) arr[i] = list.get(i); } // time : O(1), space : O(1) public static int _digitCount(long num,int base){ // this will give the # of digits needed for a number num in format : base return (int)(1 + Math.log(num)/Math.log(base)); } // time : O(n), space: O(n) public static long _fact(int n){ // simple factorial calculator long ans = 1; for(int i=2;i<=n;i++) ans = ans * i % mod; return ans; } // time for pre-computation of factorial and inverse-factorial table : O(nlog(mod)) public static long[] factorial , inverseFact; public static void _ncr_precompute(int n){ factorial = new long[n+1]; inverseFact = new long[n+1]; factorial[0] = inverseFact[0] = 1; for (int i = 1; i <=n; i++) { factorial[i] = (factorial[i - 1] * i) % mod; inverseFact[i] = _power(factorial[i], mod - 2); } } // time of factorial calculation after pre-computation is O(1) public static int _ncr(int n,int r){ if(r > n)return 0; return (int)(factorial[n] * inverseFact[r] % mod * inverseFact[n - r] % mod); } public static int _npr(int n,int r){ if(r > n)return 0; return (int)(factorial[n] * inverseFact[n - r] % mod); } // euclidean algorithm time O(max (loga ,logb)) public static long _gcd(long a, long b) { while (a>0){ long x = a; a = b % a; b = x; } return b; // if (a == 0) // return b; // return _gcd(b % a, a); } // lcm(a,b) * gcd(a,b) = a * b public static long _lcm(long a, long b) { return (a / _gcd(a, b)) * b; } // binary exponentiation time O(logn) public static long _power(long x, long n) { long ans = 1; while (n > 0) { if ((n & 1) == 1) { ans *= x; ans %= mod; n--; } else { x *= x; x %= mod; n >>= 1; } } return ans; } //sieve or first divisor time : O(mx * log ( log (mx) ) ) public static int[] _seive(int mx){ int[] firstDivisor = new int[mx+1]; for(int i=0;i<=mx;i++)firstDivisor[i] = i; for(int i=2;i*i<=mx;i++) if(firstDivisor[i] == i) for(int j = i*i;j<=mx;j+=i) firstDivisor[j] = i; return firstDivisor; } // check if x is a prime # of not. time : O( n ^ 1/2 ) private static boolean _isPrime(long x){ for(long i=2;i*i<=x;i++) if(x%i==0)return false; return true; } static class Pair<K, V>{ K ff; V ss; public Pair(K ff, V ss) { this.ff = ff; this.ss = ss; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; Pair<?, ?> pair = (Pair<?, ?>) o; return ff.equals(pair.ff) && ss.equals(pair.ss); } @Override public int hashCode() { return Objects.hash(ff, ss); } @Override public String toString(){ return ff.toString()+" "+ss.toString(); } } static FastestReader sc; static PrintWriter out; private static void openIO() throws IOException { sc = new FastestReader(); out = new PrintWriter(System.out); } /*-------------------------------------------FAST INPUT STARTS HERE---------------------------------------------*/ public static void closeIO() throws IOException { out.flush(); out.close(); sc.close(); } private static final class FastestReader { private static final int BUFFER_SIZE = 1 << 16; private final DataInputStream din; private final byte[] buffer; private int bufferPointer, bytesRead; public FastestReader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public FastestReader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } private static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private int skip() throws IOException { int b; //noinspection StatementWithEmptyBody while ((b = read()) != -1 && isSpaceChar(b)) { } return b; } public String next() throws IOException { int b = skip(); final StringBuilder sb = new StringBuilder(); while (!isSpaceChar(b)) { // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = read(); } return sb.toString(); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } final 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(); } final 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(); } final 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 { din.close(); } } /*---------------------------------------------FAST INPUT ENDS HERE ---------------------------------------------*/ }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
5724084b3d5a1247835c2caa86dc846d
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
// have faith in yourself!! /* Naive mistakes in java : --> Arrays.sort(primitive) is O(n^2) --> Never use '=' to compare to Integer data types, instead use 'equals()' --> -4 % 3 = -1, actually it should be 2, so add '+n' to modulo result */ import java.io.*; import java.util.*; public class CodeForces { public static void main(String[] args) throws IOException { openIO(); int testCase = 1; testCase = sc. nextInt(); for (int i = 1; i <= testCase; i++) solve(i); closeIO(); } /*-------------------------------------------EDITING CODE STARTS HERE-------------------------------------------*/ public static void solve(int tCase) throws IOException { int n = sc.nextInt(); int x = sc.nextInt(); long y = sc.nextLong(); long sum = x; int oddC = x%2==0?0:1; for(int i=0;i<n;i++){ int z=sc.nextInt(); if(z%2==1)oddC++; } if(oddC % 2 == y % 2)out.println("Alice"); else out.println("Bob"); } /*-------------------------------------------EDITING CODE ENDS HERE-------------------------------------------*/ public static int mod = (int) 1e9 + 7; // public static int mod = 998244353; public static int inf_int = (int) 2e9; public static long inf_long = (long) 2e18; public static void _sort(int[] arr, boolean isAscending) { int n = arr.length; List<Integer> list = new ArrayList<>(); for (int ele : arr) list.add(ele); Collections.sort(list); if (!isAscending) Collections.reverse(list); for (int i = 0; i < n; i++) arr[i] = list.get(i); } public static void _sort(long[] arr, boolean isAscending) { int n = arr.length; List<Long> list = new ArrayList<>(); for (long ele : arr) list.add(ele); Collections.sort(list); if (!isAscending) Collections.reverse(list); for (int i = 0; i < n; i++) arr[i] = list.get(i); } // time : O(1), space : O(1) public static int _digitCount(long num,int base){ // this will give the # of digits needed for a number num in format : base return (int)(1 + Math.log(num)/Math.log(base)); } // time : O(n), space: O(n) public static long _fact(int n){ // simple factorial calculator long ans = 1; for(int i=2;i<=n;i++) ans = ans * i % mod; return ans; } // time for pre-computation of factorial and inverse-factorial table : O(nlog(mod)) public static long[] factorial , inverseFact; public static void _ncr_precompute(int n){ factorial = new long[n+1]; inverseFact = new long[n+1]; factorial[0] = inverseFact[0] = 1; for (int i = 1; i <=n; i++) { factorial[i] = (factorial[i - 1] * i) % mod; inverseFact[i] = _power(factorial[i], mod - 2); } } // time of factorial calculation after pre-computation is O(1) public static int _ncr(int n,int r){ if(r > n)return 0; return (int)(factorial[n] * inverseFact[r] % mod * inverseFact[n - r] % mod); } public static int _npr(int n,int r){ if(r > n)return 0; return (int)(factorial[n] * inverseFact[n - r] % mod); } // euclidean algorithm time O(max (loga ,logb)) public static long _gcd(long a, long b) { while (a>0){ long x = a; a = b % a; b = x; } return b; // if (a == 0) // return b; // return _gcd(b % a, a); } // lcm(a,b) * gcd(a,b) = a * b public static long _lcm(long a, long b) { return (a / _gcd(a, b)) * b; } // binary exponentiation time O(logn) public static long _power(long x, long n) { long ans = 1; while (n > 0) { if ((n & 1) == 1) { ans *= x; ans %= mod; n--; } else { x *= x; x %= mod; n >>= 1; } } return ans; } //sieve or first divisor time : O(mx * log ( log (mx) ) ) public static int[] _seive(int mx){ int[] firstDivisor = new int[mx+1]; for(int i=0;i<=mx;i++)firstDivisor[i] = i; for(int i=2;i*i<=mx;i++) if(firstDivisor[i] == i) for(int j = i*i;j<=mx;j+=i) firstDivisor[j] = i; return firstDivisor; } // check if x is a prime # of not. time : O( n ^ 1/2 ) private static boolean _isPrime(long x){ for(long i=2;i*i<=x;i++) if(x%i==0)return false; return true; } static class Pair<K, V>{ K ff; V ss; public Pair(K ff, V ss) { this.ff = ff; this.ss = ss; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; Pair<?, ?> pair = (Pair<?, ?>) o; return ff.equals(pair.ff) && ss.equals(pair.ss); } @Override public int hashCode() { return Objects.hash(ff, ss); } @Override public String toString(){ return ff.toString()+" "+ss.toString(); } } static FastestReader sc; static PrintWriter out; private static void openIO() throws IOException { sc = new FastestReader(); out = new PrintWriter(System.out); } /*-------------------------------------------FAST INPUT STARTS HERE---------------------------------------------*/ public static void closeIO() throws IOException { out.flush(); out.close(); sc.close(); } private static final class FastestReader { private static final int BUFFER_SIZE = 1 << 16; private final DataInputStream din; private final byte[] buffer; private int bufferPointer, bytesRead; public FastestReader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public FastestReader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } private static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private int skip() throws IOException { int b; //noinspection StatementWithEmptyBody while ((b = read()) != -1 && isSpaceChar(b)) { } return b; } public String next() throws IOException { int b = skip(); final StringBuilder sb = new StringBuilder(); while (!isSpaceChar(b)) { // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = read(); } return sb.toString(); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } final 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(); } final 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(); } final 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 { din.close(); } } /*---------------------------------------------FAST INPUT ENDS HERE ---------------------------------------------*/ }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
7e71bfaf7cf44b030a8ffe7a02af07ba
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
// import java.io.*; // import java.util.*; // public class Main{ // 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()); // } // String nextLine() // { // String str = ""; // try { // str = br.readLine(); // } // catch (IOException e) { // e.printStackTrace(); // } // return str; // } // } // public static class Pair implements Comparable<Pair> // { // double cpu; // int tu; // int op; // int cost; // Pair(double cpu,int tu,int op,int cost) // { // this.cpu=cpu; // this.tu=tu; // this.op=op; // this.cost=cost; // } // public int compareTo(Pair o) // { // return (int)(o.cpu-this.cpu); // } // } // public static void main(String[] args) throws Exception { // FastReader sc = new FastReader(); // int t=sc.nextInt(); // while(t-->0) // { // int n=sc.nextInt(); // int k=sc.nextInt(); // int[] val=new int[n]; // int[] coins=new int[n]; // for(int i=0;i<n;i++) // { // val[i]=sc.nextInt(); // } // for(int i=0;i<n;i++) // { // coins[i]=sc.nextInt(); // } // Pair cost[]=new Pair[n]; // for(int i=0;i<n;i++) // { // double sum=val[i]/(i+1)+1; // int op=Math.log(10)/Math.sum; // if(val[i]%(i+1)!=0) // { // op++; // } // int tu=val[i]; // double cpu=coins[i]/val[i]; // cost[i]=new Pair(cpu,tu,op,coins[i]); // } // Arrays.sort(cost); // for( Pair i:cost) // { // System.out.print(i.cpu+","+i.op+"-"+i.cost+"**"); // } // System.out.println(); // long ans=0; // for(int i=0;i<n;i++) // { // long amt=cost[i].cost; // if(cost[i].op<=k) // { // k-=cost[i].op; // ans+=amt; // System.out.print(cost[i].op+" "); // } // } // System.out.println(ans); // } // } // } import java.io.*; import java.util.*; import javax.lang.model.element.Element; public class Main{ 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()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static class Pair implements Comparable<Pair> { int i; int j; Pair(int i,int j) { this.i=i; this.j=j; } public int compareTo(Pair o) { return this.i-o.i; } } public static void main(String[] args) throws Exception { FastReader sc = new FastReader(); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); int x=sc.nextInt(); long y=sc.nextLong(); long[] arr=new long[n]; for(int i=0;i<n;i++) { arr[i]=sc.nextLong(); } int val=0; for(long i:arr) { val+=i&1; } if((x+val)%2!=y%2) System.out.println("Bob"); else System.out.println("Alice"); } } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
3ff054008968a56ed64c49319b55c028
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import java.awt.geom.Arc2D; import java.io.*; import java.math.BigInteger; import java.util.*; public class Main { static int INF=0x3f3f3f3f; public static void main(String[] args) throws IOException{ initReader(); int t=nextInt(); for(int i=1;i<=t;i++) { int n=nextInt(); long x=nextLong(); long y=nextLong(); for(int j=1;j<=n;j++) { int a=nextInt(); x+=a; } if(x%2==y%2)pw.println("Alice"); else pw.println("Bob"); } pw.close(); } static BufferedReader reader; static StringTokenizer tokenizer; static PrintWriter pw; public static void initReader()throws IOException { reader=new BufferedReader(new InputStreamReader(System.in)); tokenizer=new StringTokenizer(""); pw=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); } public static boolean hasNext(){ try { while (!tokenizer.hasMoreTokens()){ tokenizer=new StringTokenizer(reader.readLine()); } }catch (Exception e){ return false; } return true; } public static String next() throws IOException{ while (!tokenizer.hasMoreTokens()){ tokenizer=new StringTokenizer(reader.readLine()); } return tokenizer.nextToken(); } public static String nextLine(){ try { return reader.readLine(); }catch (Exception e){ return null; } } public static int nextInt()throws IOException{ return Integer.parseInt(next()); } public static long nextLong() throws IOException{ return Long.parseLong(next()); } public static double nextDouble()throws IOException{ return Double.parseDouble(next()); } public static char nextChar() throws IOException{ return next().charAt(0); } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
7933b228477e67aa18859d9eb7b0e735
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
/** * @author Nitin Bhakar * */ import java.io.*; import java.util.*; public class Codeforces{ static long mod = 1000000007; static long m = 998244353; static int ninf = Integer.MIN_VALUE; static int inf = Integer.MAX_VALUE; static void swap(int[] a,int i,int j) {int temp = a[i]; a[i] = a[j]; a[j] = temp;} static void priArr(int[] a) {for(int i=0;i<a.length;i++) out.print(a[i] + " ");out.println();} static long gcd(long a,long b){if(b==0) return a; return gcd(b,a%b);} static int gcd(int a,int b){ if(b==0) return a;return gcd(b,a%b);} static void sieve(boolean[] a, int n) {a[1] = false; for(int i=2;i*i<=n;i++) { if(a[i]) { for(int j=i*i;j<=n;j+=i) a[j] = false;}}} static int getRanNum(int lo, int hi) {return (int)Math.random()*(hi-lo+1)+lo;} private static void sort(int[] arr) {List<Integer> list = new ArrayList<>();for (int i=0; i<arr.length; i++)list.add(arr[i]);Collections.sort(list);for (int i = 0; i < arr.length; i++)arr[i] = list.get(i);} private static long power(int n, int m) {long res = 1;while(m>0) {if(m%2 != 0) {res *= n; m--;}n *=n;m/=2;}return res;} static long modInv(long x,long mod) {return expo(x,mod-2,mod)%mod;} static long expo(long x,long k,long mod) {long res = 1;while(k>0) {if(k%2 != 0) {res = (res*x)%mod;k--;}x = (x*x)%mod;k /= 2;}return res%mod;} static long lcm(int a, int b){return a*(b/gcd(a,b));} static long lcm(long a, long b){return a*(b/gcd(a,b));} //map.put(a[i],map.getOrDefault(a[i],0)+1); // map.putIfAbsent; // StringBuilder ans = new StringBuilder(); static MyScanner sc = new MyScanner(); // static long[][] dp; //<----------------------------------------------WRITE HERE-------------------------------------------> static void solve(){ int n = sc.nextInt(); int x = sc.nextInt(); long y = sc.nextLong(); int[] a = sc.readIntArray(n); long sum = 0; for(int i: a) sum += i; if(sum%2 == Math.abs(y-x)%2) out.println("Alice"); else out.println("Bob"); } //<----------------------------------------------WRITE HERE-------------------------------------------> static class Pair { int v1; long v2; Pair(){} Pair(int v,long f){ v1 = v; v2 = f; } // public int compareTo(Pair p){ // if(this.v1 == p.v1) return this.v2-p.v2; // return this.v1-p.v1; // } } public static void main(String[] args) { out = new PrintWriter(new BufferedOutputStream(System.out)); int t = sc.nextInt(); // int t= 1; while(t-- >0){ solve(); } // Stop writing your solution here. ------------------------------------- out.close(); } //-----------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(); } public int[] readIntArray(int n){ int arr[] = new int[n]; for(int i = 0;i<n;i++){ arr[i] = Integer.parseInt(next()); } return arr; } int[] reverse(int arr[]){ int n= arr.length; int i = 0; int j = n-1; while(i<j){ int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; j--;i++; } return arr; } long[] readLongArray(int n){ long arr[] = new long[n]; for(int i = 0;i<n;i++){ arr[i] = Long.parseLong(next()); } return arr; } 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
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
b8a05b4eec164ca4c3c5cf3ac112cfd8
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class Main { static final PrintWriter out =new PrintWriter(System.out); static final FastReader sc = new FastReader(); //I invented a new word!Plagiarism! //Did you hear about the mathematician who’s afraid of negative numbers?He’ll stop at nothing to avoid them //What do Alexander the Great and Winnie the Pooh have in common? Same middle name. //I finally decided to sell my vacuum cleaner. All it was doing was gathering dust! //ArrayList<Integer> a=new ArrayList <Integer>(); //PriorityQueue<Integer> pq=new PriorityQueue<>(); //char[] a = s.toCharArray(); // char s[]=sc.next().toCharArray(); public static boolean sorted(int a[]) { int n=a.length,i; int b[]=new int[n]; for(i=0;i<n;i++) b[i]=a[i]; Arrays.sort(b); for(i=0;i<n;i++) { if(a[i]!=b[i]) return false; } return true; } public static void main (String[] args) throws java.lang.Exception { int tes=sc.nextInt(); while(tes-->0) { int n=sc.nextInt(); long x=sc.nextLong(); long y=sc.nextLong(); int i; long sum=x; for(i=0;i<n;i++) { int p=sc.nextInt(); sum+=p; } if(sum%2==(y%2)) System.out.println("Alice"); else System.out.println("Bob"); } } public static int first(ArrayList<Integer> arr, int low, int high, int x, int n) { if (high >= low) { int mid = low + (high - low) / 2; if ((mid == 0 || x > arr.get(mid-1)) && arr.get(mid) == x) return mid; else if (x > arr.get(mid)) return first(arr, (mid + 1), high, x, n); else return first(arr, low, (mid - 1), x, n); } return -1; } public static int last(ArrayList<Long> arr, int low, int high, long x, int n) { if (high >= low) { int mid = low + (high - low) / 2; if ((mid == n - 1 || x < arr.get(mid+1)) && arr.get(mid) == x) return mid; else if (x < arr.get(mid)) return last(arr, low, (mid - 1), x, n); else return last(arr, (mid + 1), high, x, n); } return -1; } public static int lower_bound(ArrayList<Long> ar,int lo , int hi , long k) { //Collections.sort(ar); int s=lo; int e=hi; while (s !=e) { int mid = s+e>>1; if (ar.get((int)mid) <k) { s=mid+1; } else { e=mid; } } if(s==ar.size()) { return -1; } return s; } public static int upper_bound(ArrayList<Long> ar,int lo , int hi, long k) { //Collections.sort(ar); int s=lo; int e=hi; while (s !=e) { int mid = s+e>>1; if (ar.get(mid) <=k) { s=mid+1; } else { e=mid; } } if(s==ar.size()) { return -1; } return s; } static boolean isPrime(long N) { if (N<=1) return false; if (N<=3) return true; if (N%2 == 0 || N%3 == 0) return false; for (int i=5; i*i<=N; i=i+6) if (N%i == 0 || N%(i+2) == 0) return false; return true; } static int countBits(long a) { return (int)(Math.log(a)/Math.log(2)+1); } static long fact(long N) { long mod=1000000007; long n=2; if(N<=1)return 1; else { for(int i=3; i<=N; i++)n=(n*i)%mod; } return n; } private static boolean isInteger(String s) { try { Integer.parseInt(s); } catch (NumberFormatException e) { return false; } catch (NullPointerException e) { return false; } return true; } private static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } private static long lcm(long a, long b) { return (a / gcd(a, b)) * b; } private static boolean isPalindrome(String str) { int i = 0, j = str.length() - 1; while (i < j) if (str.charAt(i++) != str.charAt(j--)) return false; return true; } private static String reverseString(String str) { StringBuilder sb = new StringBuilder(str); return sb.reverse().toString(); } 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()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
c7605bc874a90d4f76cbc06a829c2e8c
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; import java.util.*; import java.io.*; import java.math.*; public class B_Fortune_Telling { static long mod = Long.MAX_VALUE; public static void main(String[] args) { OutputStream outputStream = System.out; PrintWriter out = new PrintWriter(outputStream); FastReader f = new FastReader(); int t = f.nextInt(); while(t-- > 0){ solve(f, out); } out.close(); } public static void solve(FastReader f, PrintWriter out) { int n = f.nextInt(); long x = f.nextLong(); long y = f.nextLong(); long arr[] = f.nextArray(n); int oddCount = 0; for(int i = 0; i < n; i++) { if(arr[i]%2 == 1) { oddCount++; } } if(y%2 == 0) { if(oddCount%2 == 0) { if(x%2 == 0) { out.println("Alice"); } else { out.println("Bob"); } } else { if(x%2 == 0) { out.println("Bob"); } else { out.println("Alice"); } } } else { if(oddCount%2 == 0) { if(x%2 == 0) { out.println("Bob"); } else { out.println("Alice"); } } else { if(x%2 == 0) { out.println("Alice"); } else { out.println("Bob"); } } } } // Sort an array public static void sort(int arr[]) { ArrayList<Integer> al = new ArrayList<>(); for(int i: arr) { al.add(i); } Collections.sort(al); for(int i = 0; i < arr.length; i++) { arr[i] = al.get(i); } } // Find all divisors of n public static void allDivisors(int n) { for(int i = 1; i*i <= n; i++) { if(n%i == 0) { System.out.println(i + " "); if(i != n/i) { System.out.println(n/i + " "); } } } } // Check if n is prime or not public static boolean isPrime(int n) { if(n < 1) return false; if(n == 2 || n == 3) return true; if(n % 2 == 0 || n % 3 == 0) return false; for(int i = 5; i*i <= n; i += 6) { if(n % i == 0 || n % (i+2) == 0) { return false; } } return true; } // Find gcd of a and b public static long gcd(long a, long b) { long dividend = a > b ? a : b; long divisor = a < b ? a : b; while(divisor > 0) { long reminder = dividend % divisor; dividend = divisor; divisor = reminder; } return dividend; } // Find lcm of a and b public static long lcm(long a, long b) { long lcm = gcd(a, b); long hcf = (a * b) / lcm; return hcf; } // Find factorial in O(n) time public static long fact(int n) { long res = 1; for(int i = 2; i <= n; i++) { res *= res * i; } return res; } // Find power in O(logb) time public static long power(long a, long b) { long res = 1; while(b > 0) { if((b&1) == 1) { res = (res * a)%mod; } a = (a * a)%mod; b >>= 1; } return res; } // Find nCr public static long nCr(int n, int r) { if(r < 0 || r > n) { return 0; } long ans = fact(n) / (fact(r) * fact(n-r)); return ans; } // Find nPr public static long nPr(int n, int r) { if(r < 0 || r > n) { return 0; } long ans = fact(n) / fact(r); return ans; } // sort all characters of a string public static String sortString(String inputString) { char tempArray[] = inputString.toCharArray(); Arrays.sort(tempArray); return new String(tempArray); } // User defined class for fast I/O 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(); } boolean hasNext() { if (st != null && st.hasMoreTokens()) { return true; } String tmp; try { br.mark(1000); tmp = br.readLine(); if (tmp == null) { return false; } br.reset(); } catch (IOException e) { return false; } return true; } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } float nextFloat() { return Float.parseFloat(next()); } boolean nextBoolean() { return Boolean.parseBoolean(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } long[] nextArray(int n) { long[] a = new long[n]; for(int i=0; i<n; i++) { a[i] = nextInt(); } return a; } } } /** Dec Char Dec Char Dec Char Dec Char --------- --------- --------- ---------- 0 NUL (null) 32 SPACE 64 @ 96 ` 1 SOH (start of heading) 33 ! 65 A 97 a 2 STX (start of text) 34 " 66 B 98 b 3 ETX (end of text) 35 # 67 C 99 c 4 EOT (end of transmission) 36 $ 68 D 100 d 5 ENQ (enquiry) 37 % 69 E 101 e 6 ACK (acknowledge) 38 & 70 F 102 f 7 BEL (bell) 39 ' 71 G 103 g 8 BS (backspace) 40 ( 72 H 104 h 9 TAB (horizontal tab) 41 ) 73 I 105 i 10 LF (NL line feed, new line) 42 * 74 J 106 j 11 VT (vertical tab) 43 + 75 K 107 k 12 FF (NP form feed, new page) 44 , 76 L 108 l 13 CR (carriage return) 45 - 77 M 109 m 14 SO (shift out) 46 . 78 N 110 n 15 SI (shift in) 47 / 79 O 111 o 16 DLE (data link escape) 48 0 80 P 112 p 17 DC1 (device control 1) 49 1 81 Q 113 q 18 DC2 (device control 2) 50 2 82 R 114 r 19 DC3 (device control 3) 51 3 83 S 115 s 20 DC4 (device control 4) 52 4 84 T 116 t 21 NAK (negative acknowledge) 53 5 85 U 117 u 22 SYN (synchronous idle) 54 6 86 V 118 v 23 ETB (end of trans. block) 55 7 87 W 119 w 24 CAN (cancel) 56 8 88 X 120 x 25 EM (end of medium) 57 9 89 Y 121 y 26 SUB (substitute) 58 : 90 Z 122 z 27 ESC (escape) 59 ; 91 [ 123 { 28 FS (file separator) 60 < 92 \ 124 | 29 GS (group separator) 61 = 93 ] 125 } 30 RS (record separator) 62 > 94 ^ 126 ~ 31 US (unit separator) 63 ? 95 _ 127 DEL */ // (a/b)%mod == (a * moduloInverse(b)) % mod; // moduloInverse(b) = power(b, mod-2);
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
c7f0ea01512323dfe003379611a396c8
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import java.util.*; import java.io.*; public class Main { static ContestScanner sc = new ContestScanner(System.in); static PrintWriter pw = new PrintWriter(System.out); static StringBuilder sb = new StringBuilder(); static long mod = (long) 1e9 + 7; public static void main(String[] args) throws Exception { int T = sc.nextInt(); for(int i = 0; i < T; i++)solve(); //solve(); pw.flush(); } public static void solve() { int N = sc.nextInt(); long X = sc.nextLong()%2; long Y = sc.nextLong()%2; for(int i = 0; i < N; i++){ X ^= (sc.nextLong()%2); } pw.println(X == Y ? "Alice" : "Bob"); } static class GeekInteger { public static void save_sort(int[] array) { shuffle(array); Arrays.sort(array); } public static int[] shuffle(int[] array) { int n = array.length; Random random = new Random(); for (int i = 0, j; i < n; i++) { j = i + random.nextInt(n - i); int randomElement = array[j]; array[j] = array[i]; array[i] = randomElement; } return array; } public static void save_sort(long[] array) { shuffle(array); Arrays.sort(array); } public static long[] shuffle(long[] array) { int n = array.length; Random random = new Random(); for (int i = 0, j; i < n; i++) { j = i + random.nextInt(n - i); long randomElement = array[j]; array[j] = array[i]; array[i] = randomElement; } return array; } } } /** * 処理は[s, t) の半開区間で指定すること * 例えばtree[0]の値を取得したい場合はfind(0,1)で取得できる。 * 初期値を設定したい場合は、for(int i = 0; i < N; i++) st.update(i,i+1,A[i]);のようにadd()メソッドを経由しないと正常に動かない */ class LazySegmentTree{ long[] tree,lazy; boolean[] bool; int N; long INF = (long)1e18; public LazySegmentTree(int n){ int now = 1; while(now < n){ now *= 2; } this.N = now; this.tree = new long[N*2]; Arrays.fill(this.tree,-INF); this.lazy = new long[N*2]; this.bool = new boolean[N*2]; } public void eval(int k, int l, int r){ if(bool[k]){ tree[k] = lazy[k]; if(r-l > 1){ lazy[k*2+1] = lazy[k*2+2] = lazy[k]; bool[k*2+1] = bool[k*2+2] = true; } bool[k] = false; } } public void update(int a, int b, long x){ update(a,b,x,0,0,N); } public void update(int a, int b, long x, int k, int l, int r){ if(r < 0) r = N; eval(k, l, r); if(b <= l || r <= a) return; if(a <= l && r <= b) { lazy[k] = x; bool[k] = true; eval(k, l, r); } else { update(a, b, x, 2*k+1, l, (l+r)/2); update(a, b, x, 2*k+2, (l+r)/2, r); tree[k] = Math.max(tree[2*k+1], tree[2*k+2]); } return; } public long find(int a, int b){ return find(a,b,0,0,N); } public long find(int a, int b, int k, int l, int r) { if(r < 0) r = N; eval(k, l, r); if(b <= l || r <= a) return -INF; if(a <= l && r <= b) return tree[k]; long vl = find(a, b, 2*k+1, l, (l+r)/2); long vr = find(a, b, 2*k+2, (l+r)/2, r); return Math.max(vl, vr); } } /** * refercence : https://github.com/NASU41/AtCoderLibraryForJava/blob/master/ContestIO/ContestScanner.java */ class ContestScanner { private final java.io.InputStream in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; private static final long LONG_MAX_TENTHS = 922337203685477580L; private static final int LONG_MAX_LAST_DIGIT = 7; private static final int LONG_MIN_LAST_DIGIT = 8; public ContestScanner(java.io.InputStream in){ this.in = in; } public ContestScanner(java.io.File file) throws java.io.FileNotFoundException { this(new java.io.BufferedInputStream(new java.io.FileInputStream(file))); } public ContestScanner(){ this(System.in); } private boolean hasNextByte() { if (ptr < buflen) { return true; }else{ ptr = 0; try { buflen = in.read(buffer); } catch (java.io.IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false; } } return true; } private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1; } private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126; } public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte(); } public String next() { if (!hasNext()) throw new java.util.NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while(isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong() { if (!hasNext()) throw new java.util.NoSuchElementException(); long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while (true) { if ('0' <= b && b <= '9') { int digit = b - '0'; if (n >= LONG_MAX_TENTHS) { if (n == LONG_MAX_TENTHS) { if (minus) { if (digit <= LONG_MIN_LAST_DIGIT) { n = -n * 10 - digit; b = readByte(); if (!isPrintableChar(b)) { return n; } else if (b < '0' || '9' < b) { throw new NumberFormatException( String.format("%d%s... is not number", n, Character.toString(b)) ); } } } else { if (digit <= LONG_MAX_LAST_DIGIT) { n = n * 10 + digit; b = readByte(); if (!isPrintableChar(b)) { return n; } else if (b < '0' || '9' < b) { throw new NumberFormatException( String.format("%d%s... is not number", n, Character.toString(b)) ); } } } } throw new ArithmeticException( String.format("%s%d%d... overflows long.", minus ? "-" : "", n, digit) ); } n = n * 10 + digit; }else if(b == -1 || !isPrintableChar(b)){ return minus ? -n : n; }else{ throw new NumberFormatException(); } b = readByte(); } } public int nextInt() { long nl = nextLong(); if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException(); return (int) nl; } public double nextDouble() { return Double.parseDouble(next()); } public long[] nextLongArray(int length){ long[] array = new long[length]; for(int i=0; i<length; i++) array[i] = this.nextLong(); return array; } public long[] nextLongArray(int length, java.util.function.LongUnaryOperator map){ long[] array = new long[length]; for(int i=0; i<length; i++) array[i] = map.applyAsLong(this.nextLong()); return array; } public int[] nextIntArray(int length){ int[] array = new int[length]; for(int i=0; i<length; i++) array[i] = this.nextInt(); return array; } public int[] nextIntArray(int length, java.util.function.IntUnaryOperator map){ int[] array = new int[length]; for(int i=0; i<length; i++) array[i] = map.applyAsInt(this.nextInt()); return array; } public double[] nextDoubleArray(int length){ double[] array = new double[length]; for(int i=0; i<length; i++) array[i] = this.nextDouble(); return array; } public double[] nextDoubleArray(int length, java.util.function.DoubleUnaryOperator map){ double[] array = new double[length]; for(int i=0; i<length; i++) array[i] = map.applyAsDouble(this.nextDouble()); return array; } public long[][] nextLongMatrix(int height, int width){ long[][] mat = new long[height][width]; for(int h=0; h<height; h++) for(int w=0; w<width; w++){ mat[h][w] = this.nextLong(); } return mat; } public int[][] nextIntMatrix(int height, int width){ int[][] mat = new int[height][width]; for(int h=0; h<height; h++) for(int w=0; w<width; w++){ mat[h][w] = this.nextInt(); } return mat; } public double[][] nextDoubleMatrix(int height, int width){ double[][] mat = new double[height][width]; for(int h=0; h<height; h++) for(int w=0; w<width; w++){ mat[h][w] = this.nextDouble(); } return mat; } public char[][] nextCharMatrix(int height, int width){ char[][] mat = new char[height][width]; for(int h=0; h<height; h++){ String s = this.next(); for(int w=0; w<width; w++){ mat[h][w] = s.charAt(w); } } return mat; } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
3d9e9d229e5f2779247385040254e45b
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import java.util.*; import java.io.*; public class B_Fortune_Telling{ public static void main(String[] args) throws Exception{ FastReader fr = new FastReader(System.in); int t = fr.nextInt(); while(t-->0){ long n = fr.nextLong(); long x = fr.nextLong(); long y = fr.nextLong(); long total = x; for(int i =0;i<n;i++){ total=total^fr.nextInt(); } if(y%2==total%2){ System.out.println("Alice"); }else{ System.out.println("Bob"); } } } public static void print(Object val){ System.out.print(val); } public static void println(Object val){ System.out.println(val); } public static int[] sort(int[] vals){ ArrayList<Integer> values = new ArrayList<>(); for(int i = 0;i<vals.length;i++){ values.add(vals[i]); } Collections.sort(values); for(int i =0;i<values.size();i++){ vals[i] = values.get(i); } return vals; } public static long[] sort(long[] vals){ ArrayList<Long> values = new ArrayList<>(); for(int i = 0;i<vals.length;i++){ values.add(vals[i]); } Collections.sort(values); for(int i =0;i<values.size();i++){ vals[i] = values.get(i); } return vals; } public static void reverseArray(long[] vals){ int startIndex = 0; int endIndex = vals.length-1; while(startIndex<=endIndex){ long temp = vals[startIndex]; vals[startIndex] = vals[endIndex]; vals[endIndex] = temp; startIndex++; endIndex--; } } public static void reverseArray(int[] vals){ int startIndex = 0; int endIndex = vals.length-1; while(startIndex<=endIndex){ int temp = vals[startIndex]; vals[startIndex] = vals[endIndex]; vals[endIndex] = temp; startIndex++; endIndex--; } } static 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; } long nextLong() throws IOException { 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 static int GCD(int numA, int numB){ if(numA==0){ return numB; }else if(numB==0){ return numA; }else{ if(numA>numB){ return GCD(numA%numB,numB); }else{ return GCD(numA,numB%numA); } } } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
23d133e55751ae781d31a862362f2e7f
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
//Utilities import java.io.*; import java.util.*; public class a { static int t; static int n; static long x, y; static int[] a; static long sum; static int par; public static void main(String[] args) throws IOException { t = in.iscan(); while (t-- > 0) { n = in.iscan(); x = in.lscan(); y = in.lscan(); a = new int[n]; sum = 0; for (int i = 0; i < n; i++) { a[i] = in.iscan(); sum += a[i]; } if (sum % 2 == 0) { par = (int)(x % 2); } else { par = (int)(x % 2) ^ 1; } if (par == y % 2) { out.println("Alice"); } else { out.println("Bob"); } } out.close(); } static INPUT in = new INPUT(System.in); static PrintWriter out = new PrintWriter(System.out); private static class INPUT { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar, numChars; public INPUT (InputStream stream) { this.stream = stream; } public INPUT (String file) throws IOException { this.stream = new FileInputStream (file); } public int cscan () throws IOException { if (curChar >= numChars) { curChar = 0; numChars = stream.read (buf); } if (numChars == -1) return numChars; return buf[curChar++]; } public int iscan () throws IOException { int c = cscan (), sgn = 1; while (space (c)) c = cscan (); if (c == '-') { sgn = -1; c = cscan (); } int res = 0; do { res = (res << 1) + (res << 3); res += c - '0'; c = cscan (); } while (!space (c)); return res * sgn; } public String sscan () throws IOException { int c = cscan (); while (space (c)) c = cscan (); StringBuilder res = new StringBuilder (); do { res.appendCodePoint (c); c = cscan (); } while (!space (c)); return res.toString (); } public double dscan () throws IOException { int c = cscan (), sgn = 1; while (space (c)) c = cscan (); if (c == '-') { sgn = -1; c = cscan (); } double res = 0; while (!space (c) && c != '.') { if (c == 'e' || c == 'E') return res * UTILITIES.fast_pow (10, iscan ()); res *= 10; res += c - '0'; c = cscan (); } if (c == '.') { c = cscan (); double m = 1; while (!space (c)) { if (c == 'e' || c == 'E') return res * UTILITIES.fast_pow (10, iscan ()); m /= 10; res += (c - '0') * m; c = cscan (); } } return res * sgn; } public long lscan () throws IOException { int c = cscan (), sgn = 1; while (space (c)) c = cscan (); if (c == '-') { sgn = -1; c = cscan (); } long res = 0; do { res = (res << 1) + (res << 3); res += c - '0'; c = cscan (); } while (!space (c)); return res * sgn; } public boolean space (int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } } public static class UTILITIES { static final double EPS = 10e-6; public static void sort(int[] a, boolean increasing) { ArrayList<Integer> arr = new ArrayList<Integer>(); int n = a.length; for (int i = 0; i < n; i++) { arr.add(a[i]); } Collections.sort(arr); for (int i = 0; i < n; i++) { if (increasing) { a[i] = arr.get(i); } else { a[i] = arr.get(n-1-i); } } } public static void sort(long[] a, boolean increasing) { ArrayList<Long> arr = new ArrayList<Long>(); int n = a.length; for (int i = 0; i < n; i++) { arr.add(a[i]); } Collections.sort(arr); for (int i = 0; i < n; i++) { if (increasing) { a[i] = arr.get(i); } else { a[i] = arr.get(n-1-i); } } } public static void sort(double[] a, boolean increasing) { ArrayList<Double> arr = new ArrayList<Double>(); int n = a.length; for (int i = 0; i < n; i++) { arr.add(a[i]); } Collections.sort(arr); for (int i = 0; i < n; i++) { if (increasing) { a[i] = arr.get(i); } else { a[i] = arr.get(n-1-i); } } } public static int lower_bound (int[] arr, int x) { int low = 0, high = arr.length, mid = -1; while (low < high) { mid = (low + high) / 2; if (arr[mid] >= x) high = mid; else low = mid + 1; } return low; } public static int upper_bound (int[] arr, int x) { int low = 0, high = arr.length, mid = -1; while (low < high) { mid = (low + high) / 2; if (arr[mid] > x) high = mid; else low = mid + 1; } return low; } public static void updateMap(HashMap<Integer, Integer> map, int key, int v) { if (!map.containsKey(key)) { map.put(key, v); } else { map.put(key, map.get(key) + v); } if (map.get(key) == 0) { map.remove(key); } } public static long gcd (long a, long b) { return b == 0 ? a : gcd (b, a % b); } public static long lcm (long a, long b) { return a * b / gcd (a, b); } public static long fast_pow_mod (long b, long x, int mod) { if (x == 0) return 1; if (x == 1) return b; if (x % 2 == 0) return fast_pow_mod (b * b % mod, x / 2, mod) % mod; return b * fast_pow_mod (b * b % mod, x / 2, mod) % mod; } public static long fast_pow (long b, long x) { if (x == 0) return 1; if (x == 1) return b; if (x % 2 == 0) return fast_pow (b * b, x / 2); return b * fast_pow (b * b, x / 2); } public static long choose (long n, long k) { k = Math.min (k, n - k); long val = 1; for (int i = 0; i < k; ++i) val = val * (n - i) / (i + 1); return val; } public static long permute (int n, int k) { if (n < k) return 0; long val = 1; for (int i = 0; i < k; ++i) val = (val * (n - i)); return val; } // start of permutation and lower/upper bound template public static void nextPermutation(int[] nums) { //find first decreasing digit int mark = -1; for (int i = nums.length - 1; i > 0; i--) { if (nums[i] > nums[i - 1]) { mark = i - 1; break; } } if (mark == -1) { reverse(nums, 0, nums.length - 1); return; } int idx = nums.length-1; for (int i = nums.length-1; i >= mark+1; i--) { if (nums[i] > nums[mark]) { idx = i; break; } } swap(nums, mark, idx); reverse(nums, mark + 1, nums.length - 1); } public static void swap(int[] nums, int i, int j) { int t = nums[i]; nums[i] = nums[j]; nums[j] = t; } public static void reverse(int[] nums, int i, int j) { while (i < j) { swap(nums, i, j); i++; j--; } } static int lower_bound (int[] arr, int hi, int cmp) { int low = 0, high = hi, mid = -1; while (low < high) { mid = (low + high) / 2; if (arr[mid] >= cmp) high = mid; else low = mid + 1; } return low; } static int upper_bound (int[] arr, int hi, int cmp) { int low = 0, high = hi, mid = -1; while (low < high) { mid = (low + high) / 2; if (arr[mid] > cmp) high = mid; else low = mid + 1; } return low; } // end of permutation and lower/upper bound template } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
e7e8c4a2f32fc223d246a0d04b59d5ef
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { FastReader sc = new FastReader(); PrintWriter writer = new PrintWriter(System.out); long mod = 1000000007; int t = sc.nextInt(); while(t-->0) { int n = sc.nextInt(); long alice = sc.nextLong(); long bob = alice+3; long y = sc.nextLong(); long sum = 0; for(int i = 0; i <n; i++)sum+=sc.nextLong(); if(alice%2==1) { if(sum%2==1) { if(y%2==0)writer.println("Alice"); else writer.println("Bob"); }else { if(y%2==1)writer.println("Alice"); else writer.println("Bob"); } }else { if(sum%2==1) { if(y%2==1)writer.println("Alice"); else writer.println("Bob"); }else { if(y%2==0)writer.println("Alice"); else writer.println("Bob"); } } } writer.flush(); writer.close(); } private static long power (long a, long n, long p) { long res = 1; while(n!=0) { if(n%2==1) { res=(res*a)%p; n--; }else { a= (a*a)%p; n/=2; } } return res; } private static boolean isPrime(int c) { for (int i = 2; i*i <= c; i++) { if(c%i==0)return false; } return true; } private static int find(int a , int arr[]) { if(arr[a] != a) return arr[a] = find(arr[a], arr); return arr[a]; } private static void union(int a, int b, int arr[]) { int aa = find(a,arr); int bb = find(b, arr); arr[aa] = bb; } private static int gcd(int a, int b) { if(a==0)return b; return gcd(b%a, a); } public static int[] readIntArray(int size, FastReader s) { int[] array = new int[size]; for (int i = 0; i < size; i++) { array[i] = s.nextInt(); } return array; } 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()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } } class Four{ int a, b, c, d; public Four(int a, int b, int c, int d) { this.a =a; this.b = b; this.c = c; this.d = d; } @Override public String toString() { return this.a + " " + this.b + " " + this.c + " " + this.d; } } class Pair implements Comparable<Pair>{ long a; long b; Pair(long a, long b){ this.a = a; this.b = b; } @Override public boolean equals(Object obj) { if(this == obj) return true; if(obj == null || obj.getClass()!= this.getClass()) return false; Pair pair = (Pair) obj; return (pair.a == this.a && pair.b == this.b); } @Override public int hashCode() { return Objects.hash(a,b); } @Override public int compareTo(Pair o) { if(this.a == o.a) { return Long.compare(this.b, o.b); }else { return Long.compare(this.a, o.a); } } @Override public String toString() { return this.a + " " + this.b; } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
d628685d22d7efc0344f859b670eb976
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class Main{ public static void main(String[]args){ long s = System.currentTimeMillis(); new Solver().run(); System.err.println(System.currentTimeMillis()-s+"ms"); } } class Solver{ final long mod = (long)1e9+7l; final boolean DEBUG = true, MULTIPLE_TC = true; FastReader sc; PrintWriter out; long N, X, Y; void init(){ N = nl(); X = nl(); Y = nl(); for(int i = 1; i <= N; i++){ X = (X ^ nl()); } } void process(int testNumber){ init(); pn(((X & 1) == (Y & 1)) ? "Alice" : "Bob"); } void run(){ sc = new FastReader(); out = new PrintWriter(System.out); int t = MULTIPLE_TC ? ni() : 1; for(int test = 1; test <= t; test++){ process(test); } out.flush(); } void trace(Object... o){ if(!DEBUG) return; System.err.println(Arrays.deepToString(o)); }; void pn(Object o){ out.println(o); } void p(Object o){ out.print(o); } int ni(){ return Integer.parseInt(sc.next()); } long nl(){ return Long.parseLong(sc.next()); } double nd(){ return Double.parseDouble(sc.next()); } String nln(){ return sc.nextLine(); } long gcd(long a, long b){ return (b==0)?a:gcd(b,a%b);} int gcd(int a, int b){ return (b==0)?a:gcd(b,a%b); } 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(); } String nextLine(){ String str = ""; try{ str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } } class pair implements Comparable<pair> { int first, second; public pair(int first, int second){ this.first = first; this.second = second; } @Override public int compareTo(pair ob){ if(this.first != ob.first) return this.first - ob.first; return this.second - ob.second; } @Override public String toString(){ return this.first + " " + this.second; } static public pair from(int f, int s){ return new pair(f, s); } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
64bde44f2aaaa59a299d8d3bd283b21d
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import java.io.*; import java.util.*; public class fortunetelling { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); StringTokenizer st = new StringTokenizer(br.readLine()); int t = Integer.parseInt(st.nextToken()); for (int c = 0; c < t; c++) { st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()); long x = Long.parseLong(st.nextToken()); long y = Long.parseLong(st.nextToken()); st = new StringTokenizer(br.readLine()); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = Integer.parseInt(st.nextToken()); } boolean ans = avb(n, x, y, a); // true = alice, false = bob if (ans) { pw.println("Alice"); } else { pw.println("Bob"); } } pw.close(); } public static boolean avb(int n, long x, long y, int[] a) { long sum = sum(a); if (((sum + x + y) % 2) == 0) { return true; } else { return false; } } public static long sum(int[] arr) { long ret = 0; for (int i = 0; i < arr.length; i++) { ret += (long) arr[i]; } return ret; } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output
PASSED
88ebd638a40d101929e464bdc3c4ecdd
train_108.jsonl
1644158100
Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.
256 megabytes
import java.math.BigInteger; import java.util.*; import static java.lang.System.out; public class Round_780_Div_3 { static Scanner str = new Scanner(System.in); static ArrayList<Integer> list; public static void main(String[] args) { int t = str.nextInt(); while (t-- > 0) { solve(); } } static void solve() { long n = str.nextLong(); long x = str.nextLong(); long y = str.nextLong(); long a[] = new long[(int) n]; for (int i = 0; i < n; i++) { a[i] = str.nextInt(); x += a[i]; } if (x % 2 == y % 2) out.println("Alice"); else out.println("Bob"); } }
Java
["4\n\n1 7 9\n\n2\n\n2 0 2\n\n1 3\n\n4 0 1\n\n1 2 3 4\n\n2 1000000000 3000000000\n\n1000000000 1000000000"]
1 second
["Alice\nAlice\nBob\nAlice"]
NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.
Java 11
standard input
[ "bitmasks", "math" ]
d17752513405fc68d838e9b3792c7bef
On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,400
For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".
standard output