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
d2003b493bcbc2af5bb3a4e9084317b7
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.List; import java.util.Scanner; import java.util.ArrayList; import java.util.Comparator; public class AllZeroSequence { public static void main(String[] args) { try(final Scanner scanner = new Scanner(System.in)){ int noTests = scanner.nextInt(); while(noTests-- >0){ final Integer n = scanner.nextInt(); final List<Integer> array = new ArrayList<>(); Integer count = 0; Integer count0 = 0; for(int i=0; i<n; i++){ array.add(scanner.nextInt()); if(array.get(i) == 0){ count0++; } } array.sort(Comparator.naturalOrder()); if(count0 > 0){ count = n - count0; } else { boolean checked = false; for(int i = 1; i<n;i++){ if(array.get(i) == array.get(i-1)){ checked = true; } } if(checked){ count = n; } else { count = n+1; } } System.out.println(count); } } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
2fd4f833af6c3669ab0492bd920b802b
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.*; /** * * @author ZatFa */ public class TokitsukazeAndAllZeroSequence { public static void main(String[]args){ Scanner input = new Scanner(System.in); int t = input.nextInt(); ArrayList <Integer> list = new ArrayList <> (); ArrayList <Integer> temp = new ArrayList <> (); int value; while(t != 0){ boolean canSort= false; int size = input.nextInt(); while (size != 0){ value = input.nextInt(); list.add(value); temp.add(value); size--; } int times = 0; for(int i = 0;i<list.size();i++){ temp.remove(0); if(list.contains(0)){ break; }else if(temp.contains(list.get(i))){ list.set(i, 0); times++; canSort = true; break; } } if(canSort == true || list.contains(0)){ Collections.sort(list); } for(int i = 0;i<list.size()-1;){ if(list.get(i) == 0 && list.get(i+1) == 0){ i++; }else if(list.get(i) > list.get(i+1)){ list.set(i, list.get(i+1)); times++; }else if(list.get(i) < list.get(i+1)){ list.set(i+1, list.get(i)); times++; }else if(list.get(i) == list.get(i+1)){ list.set(i, 0); times++; } } t--; list.removeAll(list); temp.removeAll(temp); System.out.println(times); } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
68dd58bcff7df9c0009572d236d2a93e
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.*; import java.io.*; import java.nio.Buffer; public class codeforce { public static void main(String[] args) throws Exception{ BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); Scanner read = new Scanner(System.in); int t = Integer.parseInt(bf.readLine()); while(t-->0){ int n = Integer.parseInt(bf.readLine()); int[] arr = new int[n]; String[] s = bf.readLine().split(" "); int count = 0; for(int i=0;i<n;i++){ arr[i] = Integer.parseInt(s[i]); if(arr[i]==0){ count++; } } if(count!=0){ System.out.println(n-count); } else{ Arrays.sort(arr); boolean check = false; for(int i=0;i<n-1;i++){ if(arr[i]==arr[i+1]){ check = true; break; } } if(check) System.out.println(n); else System.out.println(n + 1); } } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
128cdd4d9e773ca0afc6e558f125becf
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.*; public class Round_789 { static BufferedReader sc = new BufferedReader(new InputStreamReader(System.in)); static int mod = 998244353; static String toReturn = ""; static int steps = Integer.MAX_VALUE; static int maxlen = 1000005; /*MATHEMATICS FUNCTIONS START HERE MATHS MATHS MATHS MATHS*/ static long gcd(long a, long b) { if(b == 0) return a; else return gcd(b, a % b); } static long powerMod(long x, long y, int mod) { if(y == 0) return 1; long temp = powerMod(x, y / 2, mod); temp = ((temp % mod) * (temp % mod)) % mod; if(y % 2 == 0) return temp; else return ((x % mod) * (temp % mod)) % mod; } static long modInverse(long n, int p) { return powerMod(n, p - 2, p); } static long nCr(int n, int r, int mod, long [] fact, long [] ifact) { return ((fact[n] % mod) * ((ifact[r] * ifact[n - r]) % mod)) % mod; } static boolean isPrime(long a) { if(a == 1) return false; else if(a == 2 || a == 3 || a== 5) return true; else if(a % 2 == 0 || a % 3 == 0) return false; for(int i = 5; i * i <= a; i = i + 6) { if(a % i == 0 || a % (i + 2) == 0) return false; } return true; } static int [] seive(int a) { int [] toReturn = new int [a + 1]; for(int i = 0; i < a; i++) toReturn[i] = 1; toReturn[0] = 0; toReturn[1] = 0; toReturn[2] = 1; for(int i = 2; i * i <= a; i++) { if(toReturn[i] == 0) continue; for(int j = 2 * i; j <= a; j += i) toReturn[j] = 0; } return toReturn; } static long [] fact(int a) { long [] arr = new long[a + 1]; arr[0] = 1; for(int i = 1; i < a + 1; i++) { arr[i] = (arr[i - 1] * i) % mod; } return arr; } /*MATHS MATHS MATHS MATHS MATHEMATICS FUNCTIONS END HERE */ /*SWAP FUNCTION START HERE SWAP SWAP SWAP SWAP */ static void swap(int i, int j, int [] arr) { int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } /*SWAP SWAP SWAP SWAP SWAP FUNCTION END HERE*/ /*BINARY SEARCH METHODS START HERE * BINARY SEARCH * BINARY SEARCH * BINARY SEARCH * BINARY SEARCH */ static boolean BinaryCheck(long test, long [] arr, long health) { for(int i = 0; i <= arr.length - 1; i++) { if(i == arr.length - 1) health -= test; else if(arr[i + 1] - arr[i] > test) { health = health - test; }else { health = health - (arr[i + 1] - arr[i]); } if(health <= 0) return true; } return false; } static long binarySearchModified(long start1, long n, ArrayList<Long> arr, int a, long r) { long start = start1, end = n, ans = -1; while(start < end) { long mid = (start + end) / 2; //System.out.println(mid); if(arr.get((int)mid) + arr.get(a) <= r && mid != start1) { ans = mid; start = mid + 1; }else{ end = mid; } } //System.out.println(); return ans; } static long binarySearchModified1(int n, ArrayList<Long> arr, long poi) { long start = 0, end = n, ans = -1; while(start < end) { long mid = (start + end) / 2; //System.out.println(mid); if(arr.get((int)mid) <= poi) { ans = mid; start = mid + 1; } else { end = mid; } } //System.out.println(); return ans; } /*BINARY SEARCH * BINARY SEARCH * BINARY SEARCH * BINARY SEARCH * BINARY SEARCH BINARY SEARCH METHODS END HERE*/ /*RECURSIVE FUNCTION START HERE * RECURSIVE * RECURSIVE * RECURSIVE * RECURSIVE */ static int recurse(int x, int y, int n, int steps1, Integer [][] dp) { if(x > n || y > n) return 0; if(dp[x][y] != null) { return dp[x][y]; } else if(x == n || y == n) { return steps1; } return dp[x][y] = Math.max(recurse(x + y, y, n, steps1 + 1, dp), recurse(x, x + y, n, steps1 + 1, dp)); } /*RECURSIVE * RECURSIVE * RECURSIVE * RECURSIVE * RECURSIVE RECURSIVE FUNCTION END HERE*/ /*GRAPH FUNCTIONS START HERE * GRAPH * GRAPH * GRAPH * GRAPH * */ static class edge{ int from, to; long weight; public edge(int x, int y, long weight2) { this.from = x; this.to = y; this.weight = weight2; } } static class sort implements Comparator<pair>{ @Override public int compare(pair o1, pair o2) { // TODO Auto-generated method stub if(o1.b > o2.b) return 1; else return -1; } } static void addEdge(ArrayList<ArrayList<edge>> graph, int from, int to, long weight) { edge temp = new edge(from, to, weight); edge temp1 = new edge(to, from, weight); graph.get(from).add(temp); //graph.get(to).add(temp1); } static int ans = 0; static void dfs(ArrayList<ArrayList<edge>> graph, int vertex, boolean [] visited, int dest) { //System.out.println(graph.get(vertex).size()); if(ans == 2) return; if(vertex == dest) { ans++; return; } if(visited[vertex]) return; visited[vertex] = true; for(int i = 0; i < graph.get(vertex).size(); i++) { edge temp = graph.get(vertex).get(i); if(!visited[temp.to]) { //System.out.println(temp.to); //toReturn[(int) temp.weight] = weight; dfs(graph, temp.to, visited, dest); //weight = 5 - weight; } } } static void bfs(ArrayList<ArrayList<edge>> graph, int vertex, boolean [] visited, int [] toReturn, Queue<Integer> q, int weight) { if(visited[vertex]) return; visited[vertex] = true; if(graph.get(vertex).size() > 2) return; int first = weight; for(int i = 0; i < graph.get(vertex).size(); i++) { edge temp = graph.get(vertex).get(i); if(!visited[temp.to]) { q.add(temp.to); toReturn[(int) temp.weight] = weight; weight = 5 - weight; } } if(!q.isEmpty())bfs(graph, q.poll(), visited, toReturn, q, 5 - first); } static void topoSort(ArrayList<ArrayList<Integer>> graph, int vertex, boolean [] visited, ArrayList<Integer> toReturn) { if(visited[vertex]) return; visited[vertex] = true; for(int i = 0; i < graph.get(vertex).size(); i++) { if(!visited[graph.get(vertex).get(i)]) topoSort(graph, graph.get(vertex).get(i), visited, toReturn); } toReturn.add(vertex); } static boolean isCyclicDirected(ArrayList<ArrayList<Integer>> graph, int vertex, boolean [] visited, boolean [] reStack) { if(reStack[vertex]) return true; if(visited[vertex]) return false; reStack[vertex] = true; visited[vertex] = true; for(int i = 0; i < graph.get(vertex).size(); i++) { if(isCyclicDirected(graph, graph.get(vertex).get(i), visited, reStack)) return true; } reStack[vertex] = false; return false; } static int e = 0; static long mst(PriorityQueue<edge> pq, int nodes) { long weight = 0; while(!pq.isEmpty()) { edge temp = pq.poll(); int x = parent(parent, temp.to); int y = parent(parent, temp.from); if(x != y) { //System.out.println(temp.weight); union(x, y, rank, parent); weight += temp.weight; e++; } } return weight; } static void floyd(long [][] dist) { // to find min distance between two nodes for(int k = 0; k < dist.length; k++) { for(int i = 0; i < dist.length; i++) { for(int j = 0; j < dist.length; j++) { if(dist[i][j] > dist[i][k] + dist[k][j]) { dist[i][j] = dist[i][k] + dist[k][j]; } } } } } static void dijkstra(ArrayList<ArrayList<edge>> graph, long [] dist, int src) { for(int i = 0; i < dist.length; i++) dist[i] = Long.MAX_VALUE / 2; dist[src] = 0; boolean visited[] = new boolean[dist.length]; PriorityQueue<pair> pq = new PriorityQueue<>(new sort()); pq.add(new pair(src, 0)); while(!pq.isEmpty()) { pair temp = pq.poll(); int index = temp.a; for(int i = 0; i < graph.get(index).size(); i++) { if(dist[graph.get(index).get(i).to] > dist[index] + graph.get(index).get(i).weight) { dist[graph.get(index).get(i).to] = dist[index] + graph.get(index).get(i).weight; pq.add(new pair(graph.get(index).get(i).to, graph.get(index).get(i).weight)); } } } } static int parent1 = -1; static boolean ford(ArrayList<ArrayList<edge>> graph1, ArrayList<edge> graph, long [] dist, int src, int [] parent) { for(int i = 0; i < dist.length; i++) dist[i] = Long.MIN_VALUE / 2; dist[src] = 0; boolean hasNeg = false; for(int i = 0; i < dist.length - 1; i++) { for(int j = 0; j < graph.size(); j++) { int from = graph.get(j).from; int to = graph.get(j).to; long weight = graph.get(j).weight; if(dist[to] < dist[from] + weight) { dist[to] = dist[from] + weight; parent[to] = from; } } } for(int i = 0; i < graph.size(); i++) { int from = graph.get(i).from; int to = graph.get(i).to; long weight = graph.get(i).weight; if(dist[to] < dist[from] + weight) { parent1 = from; hasNeg = true; dfs(graph1, parent1, new boolean[dist.length], dist.length - 1); //System.out.println(ans); dfs(graph1, 0, new boolean[dist.length], parent1); //System.out.println(ans); if(ans == 2) break; else ans = 0; } } return hasNeg; } /*GRAPH FUNCTIONS END HERE * GRAPH * GRAPH * GRAPH * GRAPH */ /*disjoint Set START HERE * disjoint Set * disjoint Set * disjoint Set * disjoint Set */ static int [] rank; static int [] parent; static int parent(int [] parent, int x) { if(parent[x] == x) return x; else return parent[x] = parent(parent, parent[x]); } static boolean union(int x, int y, int [] rank, int [] parent) { if(parent(parent, x) == parent(parent, y)) { return true; } if(rank[x] > rank[y]) { swap(x, y, rank); } rank[x] += rank[y]; parent[y] = x; return false; } /*disjoint Set END HERE * disjoint Set * disjoint Set * disjoint Set * disjoint Set */ /*INPUT START HERE * INPUT * INPUT * INPUT * INPUT * INPUT */ static int nextInt() throws NumberFormatException, IOException { return Integer.parseInt(sc.readLine()); } static long nextLong() throws NumberFormatException, IOException { return Long.parseLong(sc.readLine()); } static long [] inputLongArr() throws NumberFormatException, IOException{ String [] s = sc.readLine().split(" "); long [] toReturn = new long[s.length]; for(int i = 0; i < s.length; i++) { toReturn[i] = Long.parseLong(s[i]); } return toReturn; } static int max = 0; static int [] inputIntArr() throws NumberFormatException, IOException{ String [] s = sc.readLine().split(" "); //System.out.println(s.length); int [] toReturn = new int[s.length]; for(int i = 0; i < s.length; i++) { toReturn[i] = Integer.parseInt(s[i]); } return toReturn; } /*INPUT * INPUT * INPUT * INPUT * INPUT * INPUT END HERE */ static long [] preCompute(int level) { long [] toReturn = new long[level]; toReturn[0] = 1; toReturn[1] = 16; for(int i = 2; i < level; i++) { toReturn[i] = ((toReturn[i - 1] % mod) * (toReturn[i - 1] % mod)) % mod; } return toReturn; } static class pair{ int a; long b; public pair(int x, long y) { this.a = x; this.b = y; } } static long smallestFactor(long a) { for(long i = 2; i * i <= a; i++) { if(a % i == 0) { return i; } } return a; } static int recurseRow(int [][] mat, int i, int j, int prev, int ans) { if(j >= mat[0].length) return ans; if(mat[i][j] == prev) { return recurseRow(mat, i, j + 1, prev, ans + 1); } else return ans; } static int recurseCol(int [][] mat, int i, int j, int prev, int ans) { if(i >= mat.length) return ans; if(mat[i][j] == prev) { return recurseCol(mat, i + 1, j, prev, ans + 1); } else return ans; } static int diff(char [] a, char [] b) { int sum = 0; for(int i = 0; i < a.length; i++) { sum += Math.abs((int)a[i] - (int)b[i]); } return sum; } static void solve() throws IOException { int n = nextInt(); int [] arr = inputIntArr(); int [] hash = new int[1001]; int count = arr.length; int zero = 0; for(int i = 0; i < arr.length; i++) { if(arr[i] == 0) zero++; } if(zero > 0) { System.out.println(arr.length - zero); return; } for(int i = 0; i < arr.length; i++) { if(hash[arr[i]] > 0 || arr[i] == 0) { if(arr[i] == 0) { System.out.println(arr.length - 1); return; } System.out.println(arr.length); return; }else { hash[arr[i]]++; } } System.out.println(2 + arr.length - 1); } public static void main(String[] args) throws IOException { // TODO Auto-generated method stub int t = Integer.parseInt(sc.readLine()); for(int i = 0; i < t; i++) solve(); } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
6c8537e7ca2ea8a596937eaa59e08ad9
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.HashSet; import java.util.StringTokenizer; public class cf1678A { // https://codeforces.com/problemset/problem/1678/A public static void main(String[] args) { Kattio io = new Kattio(); int t = io.nextInt(), n; HashSet<Integer> ints = new HashSet<>(); for (int i = 0; i < t; i++) { n = io.nextInt(); ints.clear(); boolean duplicate = false; int zeronum = 0; for (int k = 0; k < n; k++) { int tmp = io.nextInt(); zeronum += tmp == 0 ? 1 : 0; if (!ints.add(tmp)) duplicate = true; }; if (ints.contains(0)) { io.println(n-zeronum); } else if (duplicate) { io.println(n); } else { io.println(n+1); } } io.close(); } // Kattio static class Kattio extends PrintWriter { private BufferedReader r; private StringTokenizer st; // standard input public Kattio() { this(System.in,System.out); } public Kattio(InputStream i, OutputStream o) { super(o); r = new BufferedReader(new InputStreamReader(i)); } // USACO-style file input public Kattio(String problemName) throws IOException { super(problemName+".out"); r = new BufferedReader(new FileReader(problemName+".in")); } // returns null if no more input public String next() { try { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(r.readLine()); return st.nextToken(); } catch (Exception e) {} return null; } public String nextLine() { try { st = null; return r.readLine(); } catch (Exception e) {} return null; } public int nextInt() { return Integer.parseInt(next()); } public double nextDouble() { return Double.parseDouble(next()); } public long nextLong() { return Long.parseLong(next()); } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
6bcf2a8e7e9bd7dc5f55bf0345345582
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.HashSet; import java.util.StringTokenizer; public class cf1678A { // https://codeforces.com/problemset/problem/1678/A public static void main(String[] args) { Kattio io = new Kattio(); int t = io.nextInt(), n; HashSet<Integer> ints = new HashSet<>(); for (int i = 0; i < t; i++) { n = io.nextInt(); ints.clear(); boolean duplicate = false; boolean only0 = true; int zeronum = 0; for (int k = 0; k < n; k++) { int tmp = io.nextInt(); if (tmp != 0) only0 = false; zeronum += tmp == 0 ? 1 : 0; if (!ints.add(tmp)) duplicate = true; }; if (only0) { io.println(0); } else if (ints.contains(0)) { io.println(n-zeronum); } else if (duplicate) { io.println(n); } else { io.println(n+1); } } io.close(); } // Kattio static class Kattio extends PrintWriter { private BufferedReader r; private StringTokenizer st; // standard input public Kattio() { this(System.in,System.out); } public Kattio(InputStream i, OutputStream o) { super(o); r = new BufferedReader(new InputStreamReader(i)); } // USACO-style file input public Kattio(String problemName) throws IOException { super(problemName+".out"); r = new BufferedReader(new FileReader(problemName+".in")); } // returns null if no more input public String next() { try { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(r.readLine()); return st.nextToken(); } catch (Exception e) {} return null; } public String nextLine() { try { st = null; return r.readLine(); } catch (Exception e) {} return null; } public int nextInt() { return Integer.parseInt(next()); } public double nextDouble() { return Double.parseDouble(next()); } public long nextLong() { return Long.parseLong(next()); } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
53c806f822b02f631540ed8cf319236b
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.*; public class Main { public static void sort(int[] in) { shuffle(in); Arrays.sort(in); } public static void shuffle(int[] in) { for (int i = 0; i < in.length; i++) { int idx = (int) (Math.random() * in.length); int tmp = in[i]; in[i] = in[idx]; in[idx] = tmp; } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int trials = sc.nextInt(); while (trials > 0){ int length = sc.nextInt(); int[] arr = new int[length]; for (int i = 0; i < length; i++) arr[i] = sc.nextInt(); Arrays.sort(arr); int numofZeros = 0; for (int i = 1; i < length; i++) { if (arr[i] ==0) numofZeros++; } if (arr[0] ==0) System.out.println(arr.length -1 -numofZeros); else { boolean flag = true; for (int i = 0; i < length-1; i++) { if (arr[i] == arr[i+1]){ flag = false; break; } } if (!flag) System.out.println(arr.length-numofZeros); else System.out.println(arr.length+1-numofZeros); } trials--; } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
abc70e0460dc91fdd7bdbfddcc5479aa
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class TokitsukazeandAllZeroSequence { public static void main(String[] args) { Scanner sc=new Scanner (System.in); int t=sc.nextInt(); for(int i=0;i<t;i++) { int n=sc.nextInt(); int arr[]=new int[n]; for(int j=0;j<n;j++) { arr[j]=sc.nextInt(); } int count=0,zcount=0; Arrays.sort(arr); for(int k=0;k<n-1;k++) { if (arr[k]==arr[k+1] && arr[k]!=0) { count++; } if(arr[k]==0) { zcount++; } } if(count==0 && zcount==0) { System.out.println(n+1); } if(zcount>=1) { for(int m=1;m<=n;m++) { if(zcount==m&&arr[n-1]>0) { System.out.println(n-m); break; } if(zcount==arr.length-1&&arr[n-1]==0) { System.out.println("0"); break; } }} if(count>=1 &&zcount==0) { System.out.println(n); } } }}
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
6d5307a8cb91c00c643f67ec2ae3043c
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.*; import java.io.*; public class TokitsukazeandAllZeroSequence { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); int arr[]=new int[n]; int count=0; int ans=0; for(int i=0;i<n;i++) { arr[i]=sc.nextInt(); if(arr[i]==0) { ans++; } } Arrays.sort(arr); if(ans>0) { System.out.println(n-ans); } else { for(int i=0;i<n-1;i++) { if(arr[i]==arr[i+1]) { count++; } } if(count>=1) { System.out.println(n); } else { System.out.println(n+1); } count=0; } } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
310f350baf1ab02c0f12e822eb25062b
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int t = sc.nextInt(), n; int a[] = new int[100], min, sum, z; boolean c; while(t -- > 0){ sum = 0; z = 0; min = 101; c = false; n = sc.nextInt(); for(int i = 0; i < n; i ++){ a[i] = sc.nextInt(); sum += a[i]; if(a[i] == 0) z ++; if(a[i] < min) min = a[i]; } if(sum == 0) System.out.println('0'); else{ for(int i = 0; i < n - 1; i ++){ for(int j = i + 1; j < n; j ++){ if(a[j] == a[i]){ c = true; break; } } } if(c){ if(z != 0) System.out.println(n - z); else System.out.println(min > 0 ? n : n - 1); } else System.out.println(min > 0 ? n + 1 : n - 1); } } sc.close(); } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
42fbebe22bfd9bf7c64336af471e2529
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class TaskA { static void solve(FastScanner fs) { int n = fs.nextInt(); int a[] = fs.readArray(n); int num[] = new int[101]; int cnt = 0, dup = 0; for (int i = 0; i < n; i++) { if (a[i] == 0) { cnt++; } num[a[i]]++; if (a[i] != 0 && num[a[i]] > 1) { dup++; } } if (cnt > 0) { System.out.println(n - cnt); } else { if (dup > 0) System.out.println(n); else System.out.println(n + 1); } } 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 void printArrayWithSpace(int a[]) { for (int i = 0; i < a.length; i++) { System.out.print(a[i] + " "); } System.out.print("\n"); } 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 int countOdd(int L, int R) { int N = (R - L) / 2; if (R % 2 != 0 || L % 2 != 0) N++; return N; } 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()); } } public static void main(String[] args) { FastScanner fs = new FastScanner(); int c = fs.nextInt(); while (c-- > 0) { solve(fs); } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
224b7eda58b24a4c2ccbfefc22816aa2
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Scanner; import java.util.Set; public class Solution { static Scanner scan = new Scanner(System.in); private static final Integer INF = 32768; public static void main(String[] args) { int cas = scan.nextInt(); while(cas-->0){ int n = scan.nextInt(); int zeroCnt = 0; boolean seen = false; Set<Integer> set = new HashSet<>(); for (int i = 0; i < n; i++) { int x = scan.nextInt(); if (x==0) { zeroCnt++ ; }else{ if (set.contains(x)){ seen = true; } set.add(x); } } int ans = 0; if (zeroCnt>0) ans = n-zeroCnt; else { if (seen){ ans = n; }else ans = n+1; } System.out.println(ans); } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
39921b26f568362882a07efc7503d33d
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); // System.out.println(sc.nextByte()); allzero(sc); } private static void allzero(Scanner scanner){ int testcase=scanner.nextInt(); HashMap<Integer,Integer>map=new HashMap<>(); for(int i=0;i<testcase;i++){ map.clear(); int size=scanner.nextInt(); int[] arr=new int[size]; boolean zero=false; int countzer=0; for(int j=0;j<size;j++){ int z=scanner.nextInt(); arr[j]=z; if(z==0){ zero=true; countzer++; } if(map.containsKey(z)){ map.put(z,2); }else{ map.put(z,1); } } if(zero){ System.out.println(size-countzer); }else{ boolean hasmulti=false; for (int m:map.values()){ if(m>1){ hasmulti=true; // System.out.println(m+"m"); break; } } if(!hasmulti)System.out.println(size+1); else { System.out.println(size); } } } }}
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
87882507cb09bf3e0e4788ebd19cc2f3
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
//package Practise_problems; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.HashMap; import java.util.Random; import java.util.StringTokenizer; public class ZeroSequence { public static void main(String []args) { FastScanner fs=new FastScanner(); int t=fs.nextInt(); outer:while(t-->0) { int n=fs.nextInt(); int []arr=new int[n]; arr=fs.readArray(n); HashMap<Integer,Integer> map=new HashMap<>(); int zero=0; for(int val:arr) { zero+=val==0?1:0; map.put(val,map.getOrDefault(val, 0)+1); } if(zero>0) { System.out.println((n-zero)); } else { for(int key:map.keySet()) { if(map.get(key)>1) { System.out.println(n); continue outer; } } System.out.println((n+1)); } } } static final Random random=new Random(); static void ruffleSort(int[] a) { int n=a.length;//shuffle, then sort 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 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
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
03c576323dc5303ea5ee251946666bb9
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.*; public class A { public static void main(String[] args) { Scanner read= new Scanner(System.in); int t=read.nextInt(); for(int j=0;j<t;j++){ int n = read.nextInt(); boolean f = true; int cnt=0; Set<Integer> s = new HashSet<Integer>(); for (int i = 0; i < n; i++) { int x = read.nextInt(); if (x == 0) { f = false; } else { s.add(x); cnt++; } } if (f==false) { System.out.println(cnt); } else { if (s.size() == cnt) { System.out.println(n + 1); } else { System.out.println(n ); } } } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
b517514186ed4a278aadb7dbd2e2790b
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.HashSet; import java.util.Scanner; import java.util.Set; public class Solution { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int n = sc.nextInt(); for(int i = 0; i < n; i++) { int l = sc.nextInt(); int[] arr = new int[l]; for(int i2 = 0; i2< l; i2++) { arr[i2] = sc.nextInt(); } int zc = 0; Set<Integer> s = new HashSet<Integer>(); for(int t : arr) { s.add(t); if(t == 0){ zc++; } } if(s.size() != l || zc > 0) { System.out.println(l - zc); } else { System.out.println(l +1); } } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
6edf32fb88a37ad87c3abe258778ff07
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.io.*; import java.util.*; /** * @author atulanand */ public class Solution { static class Result { public int solve(int[] arr, int n) { int zero = 0; boolean same = false; Set<Integer> set = new HashSet<>(); for (int i : arr) { if (i == 0) { zero++; } if (set.contains(i)) { same = true; } else { set.add(i); } } int res = n - zero; // System.out.println(res); if (zero > 0) { } else if (same) { } else { res += 1; } // System.out.println(res); // System.out.println("res"); return res; } } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = inputInt(br); Result result = new Result(); StringBuilder sb = new StringBuilder(); while (t-- > 0) { int[] spec = inputIntArray(br); sb.append(result.solve(inputIntArray(br), spec[0])).append("\n"); } System.out.println(sb); } public static char[][] inputCharGrid(BufferedReader br, int rows) throws IOException { char[][] grid = new char[rows][]; for (int i = 0; i < grid.length; i++) { grid[i] = inputString(br).toCharArray(); } return grid; } public static int[][] inputIntGrid(BufferedReader br, int rows) throws IOException { int[][] grid = new int[rows][]; for (int i = 0; i < grid.length; i++) { grid[i] = inputIntArray(br); } return grid; } public static char[] inputCharArray(BufferedReader br) throws IOException { return inputString(br).toCharArray(); } public static String inputString(BufferedReader br) throws IOException { return br.readLine().trim(); } public static int inputInt(BufferedReader br) throws IOException { return Integer.parseInt(inputString(br)); } public static long inputLong(BufferedReader br) throws IOException { return Long.parseLong(inputString(br)); } public static int[] inputIntArray(BufferedReader br) throws IOException { String[] spec = inputString(br).split(" "); int[] arr = new int[spec.length]; for (int i = 0; i < spec.length; i++) arr[i] = Integer.parseInt(spec[i]); return arr; } public static int[] inputIntArrayW(BufferedReader br) throws IOException { String[] spec = inputString(br).split(""); int[] arr = new int[spec.length]; for (int i = 0; i < spec.length; i++) arr[i] = Integer.parseInt(spec[i]); return arr; } public static long[] inputLongArray(BufferedReader br) throws IOException { String[] spec = inputString(br).split(" "); long[] arr = new long[spec.length]; for (int i = 0; i < spec.length; i++) arr[i] = Long.parseLong(spec[i]); return arr; } private String stringify(char[] chs) { StringBuilder sb = new StringBuilder(); for (char ch : chs) { sb.append(ch); } return sb.toString(); } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
32719fc7b080d561d6bb4fa9d47b3541
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.nio.file.FileAlreadyExistsException; import java.util.*; public class roughCodeforces { public static boolean isok(long x, long h, long k){ long sum = 0; if(h > k){ long t1 = h - k; long t = t1 * k; sum += (k * (k + 1)) / 2; sum += t - (t1 * (t1 + 1) / 2); }else{ sum += (h * (h + 1)) / 2; } if(sum < x){ return true; } return false; } public static boolean binary_search(long[] a, long k){ long low = 0; long high = a.length - 1; long mid = 0; while(low <= high){ mid = low + (high - low) / 2; if(a[(int)mid] == k){ return true; }else if(a[(int)mid] < k){ low = mid + 1; }else{ high = mid - 1; } } return false; } public static long lowerbound(long a[], long ddp){ long low = 0; long high = a.length; long mid = 0; while(low < high){ mid = low + (high - low)/2; if(a[(int)mid] == ddp){ return mid; } if(a[(int)mid] < ddp){ low = mid + 1; }else{ high = mid; } } // if(low + 1 < a.length && a[(int)low + 1] <= ddp){ // low++; // } if(low == a.length && low != 0){ low--; return low; } if(a[(int)low] > ddp && low != 0){ low--; } return low; } public static long upperbound(long a[], long ddp){ long low = 0; long high = a.length; long mid = 0; while(low < high){ mid = low + (high - low) / 2; if(a[(int)mid] < ddp){ low = mid + 1;; }else{ high = mid; } } if(low == a.length){ return a.length - 1; } return low; } public static class pair{ long w; long h; public pair(long w, long h){ this.w = w; this.h = h; } } public static class trinary{ long a; long b; long c; public trinary(long a, long b, long c){ this.a = a; this.b = b; this.c = c; } } public static long lowerboundforpairs(pair a[], long pr){ long low = 0; long high = a.length; long mid = 0; while(low < high){ mid = low + (high - low)/2; if(a[(int)mid].w <= pr){ low = mid + 1; }else{ high = mid; } } // if(low + 1 < a.length && a[(int)low + 1] <= ddp){ // low++; // } // if(low == a.length && low != 0){ // low--; // return low; // } // if(a[(int)low].w > pr && low != 0){ // low--; // } return low; } public static pair[] sortpair(pair[] a){ Arrays.sort(a, new Comparator<pair>() { public int compare(pair p1, pair p2){ return (int)p1.w - (int)p2.w; } }); return a; } public static boolean ispalindrome(String s){ long i = 0; long j = s.length() - 1; boolean is = false; while(i < j){ if(s.charAt((int)i) == s.charAt((int)j)){ is = true; i++; j--; }else{ is = false; return is; } } return is; } public static void sort(long[] arr) { ArrayList<Long> a = new ArrayList<>(); for (long i : arr) { a.add(i); } Collections.sort(a); for (int i = 0; i < a.size(); i++) { arr[i] = a.get(i); } } public static void sortForObjecttypes(Long[] arr) { ArrayList<Long> a = new ArrayList<>(); for (Long i : arr) { a.add(i); } Collections.sort(a); for (int i = 0; i < a.size(); i++) { arr[i] = a.get(i); } } public static void main(String[] args) throws java.lang.Exception{ Scanner sc = new Scanner(System.in); StringBuilder sb = new StringBuilder(); long o = sc.nextLong(); while(o > 0){ long n = sc.nextLong(); long a[] = new long[(int)n]; long zeros = 0; for(long i = 0;i < n;i++){ a[(int)i] = sc.nextLong(); if(a[(int)i] == 0){ zeros++; } } Map<Long, Long> m = new HashMap<>(); for(long i = 0;i < n;i++){ if(!m.containsKey(a[(int)i])){ m.put(a[(int)i], (long)0); } m.put(a[(int)i], m.get(a[(int)i]) + 1); } if(zeros == n){ System.out.println(0); }else{ if(m.keySet().size() == n){ if(zeros != 0){ System.out.println(n - zeros); }else{ System.out.println(n + 1); } }else{ System.out.println(n - zeros); } } o--; } System.out.println(sb.toString()); } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
10411ecca733abf55fcbeb1e8f459f71
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.Scanner; public class Testing1 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); for(int w = 0; w < t; w++){ int n = in.nextInt(); int[] a = new int[n]; int[] num = new int[101]; for(int i = 0; i < n; i++){ a[i] = in.nextInt(); num[a[i]]++; } int ans = 0; block:{ if (num[0] > 0) { ans = a.length - num[0]; } else { for (int i = 1; i < num.length; i++) { if (num[i] > 1) { ans = a.length; break block; } } ans = a.length + 1; } } System.out.println(ans); } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
58562c99e776df27fb07db7112b96364
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class TokitsukazeandAllZeroSequence { public static void main(String[] args) { Scanner scn = new Scanner(System.in); int t = scn.nextInt(); while(t -- > 0){ int n = scn.nextInt(); int[] arry = new int[n]; for(int i=0; i<n; i++){ arry[i] = scn.nextInt(); } Arrays.sort(arry); boolean b = false; int count0 = 0; for(int i=0; i<n; i++){ if(arry[i] == 0) count0++; if(i<n-1 && arry[i] == arry[i+1]) b = true; } if(count0 > 0) System.out.println(n-count0); else if(b) System.out.println(n); else System.out.println(n+1); } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
dbcc1620543101a419bb0ae71d6f5e3a
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.*; public class coding { // static class FastReader { // private InputStream stream; // private byte[] buf = new byte[1024]; // private int curChar; // private int numChars; // private FastReader.SpaceCharFilter filter; // // public FastReader(InputStream stream) { // this.stream = stream; // } // // public int read() { // if (numChars == -1) throw new InputMismatchException(); // if (curChar >= numChars) { // curChar = 0; // try { // numChars = stream.read(buf); // } catch (IOException e) { // throw new InputMismatchException(); // } // if (numChars <= 0) return -1; // } // return buf[curChar++]; // } // // public int nextInt() { // int c = read(); // while (isSpaceChar(c)) c = read(); // int sgn = 1; // if (c == '-') { // sgn = -1; // c = read(); // } // int res = 0; // do { // if (c < '0' || c > '9') throw new InputMismatchException(); // res *= 10; // res += c - '0'; // c = read(); // } // while (!isSpaceChar(c)); // return res * sgn; // } // // public long nextLong() { // int c = read(); // while (isSpaceChar(c)) c = read(); // int sgn = 1; // if (c == '-') { // sgn = -1; // c = read(); // } // long res = 0; // do { // if (c < '0' || c > '9') throw new InputMismatchException(); // res *= 10; // res += c - '0'; // c = read(); // } while (!isSpaceChar(c)); // return res * sgn; // } // // public String next() { // int c = read(); // while (isSpaceChar(c)) c = read(); // StringBuilder res = new StringBuilder(); // do { // res.appendCodePoint(c); // c = read(); // } while (!isSpaceChar(c)); // return res.toString(); // } // // public boolean isSpaceChar(int c) { // if (filter != null) return filter.isSpaceChar(c); // return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; // } // // public long[] readLongArray(int size) { // long[] array = new long[size]; // for (int i = 0; i < size; i++) array[i] = nextLong(); // return array; // } // // public interface SpaceCharFilter { // public boolean isSpaceChar(int ch); // // } // // } // static int gcd(int a,int b) // { // int i=a%b; // while(i!=0) // { // a=b; // b=i; // i=a%b; // } // return b; // } public static void main(String args[] ) throws Exception { // InputStream inputStream = System.in; // OutputStream outputStream = System.out; // FastReader in = new FastReader(inputStream); // PrintWriter out = new PrintWriter(outputStream); Scanner sc=new Scanner(System.in); int t = sc.nextInt(); Map<Integer, Integer> map=new HashMap<Integer,Integer>(); while(t-->0) { int count=0; int n = sc.nextInt(); long arr[]=new long[n]; long brr[]=new long[n]; long crr[]=new long[n]; for(int i=0;i<n;i++) { arr[i]=sc.nextLong(); crr[i]=arr[i]; brr[i]=0; } Arrays.sort(arr); boolean p=true; int count1=0; for(int i=1;i<n;i++) { if(arr[i]==arr[i-1]) { p=false; break; } } for(int i=0;i<n;i++) { if(arr[i]==0) { count1++; } else { break; } } if(count1>0) { count=n-count1; } else { if(p==false) { count=n; } else { count=n+1; } } System.out.println(count); } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
f3b65e2d841162c2e08b9b304f480324
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.*; import java.io.*; import java.math.BigInteger; public class Main { public static void main(String[] args) throws FileNotFoundException,IOException, InterruptedException { Scanner s=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int t=s.nextInt(); while (t-->0) { int n=s.nextInt(); int []a=s.nextIntArr(n); HashSet<Integer>hs=new HashSet<>(); int cnt0=0; for (int x:a) { if (x==0) cnt0++; else hs.add(x); } int ans=0; if (cnt0>0) { ans=n-cnt0; } else { if (hs.size()<n) ans++; else ans+=2; ans+=n-1; } pw.println(ans); } pw.flush(); } static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } //returns INDEX public static Integer ceiling (int []arr, int x) { int lower=0,upper=arr.length-1; Integer index=-1; while (lower<=upper) { int mid=lower+(upper-lower)/2; if (arr[mid]>=x) { upper=mid-1; index=mid; } else lower=mid+1; } return index!=-1?arr[index]:(int)2e9; } public static Integer floor (int []arr,int x) { int lower=0,upper=arr.length-1; Integer index=-1; while (lower<=upper) { int mid=lower+(upper-lower)/2; if (arr[mid]<=x) { lower=mid+1; index=mid; } else upper=mid-1; } return index!=-1?arr[index]:(int)2e9; } public static void permute(char []a , int l, int r) { if (l == r) { // permutation in hand here System.out.println(Arrays.toString(a)); } else { for (int i = l; i <= r; i++) { a= swap(a,l,i); permute(a, l+1, r); a = swap(a,l,i); } } } public static void permute1(char []a , int l, int r) { if (l == r) { // permutation in hand here System.out.println(Arrays.toString(a)); } else { for (int i = l; i <= r; i++) { a= swap(a,l,i); permute(a, l+1, r); a = swap(a,l,i); } } } public static char[] swap(char []a, int l, int i) { char temp=a[l]; a[l]=a[i]; a[i]=temp; return a; } public static double log2(long m) { double result = (double)(Math.log(m) / Math.log(2)); return result; } public static void shuffle(int []a) { for (int i=0; i<a.length;i++) { int randIndex=(int)(Math.random()*a.length); int temp=a[i]; a[i]=a[randIndex]; a[randIndex]=temp; } } public static void shuffle(long []a) { for (int i=0; i<a.length;i++) { int randIndex=(int)(Math.random()*a.length); long temp=a[i]; a[i]=a[randIndex]; a[randIndex]=temp; } } } class Pair implements Comparable{ int x; int y; Pair(int x, int y) { this.x=x; this.y=y; } @Override public int compareTo(Object o) { Pair p=(Pair)o; return this.x-p.x; } public String toString() { return "("+x+","+y+")"; } } class Scanner { StringTokenizer st; BufferedReader br; public Scanner() { br = new BufferedReader(new InputStreamReader(System.in)); } public Scanner(String s) throws FileNotFoundException { br =new BufferedReader(new FileReader(s)); } public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));} public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException {return Integer.parseInt(next());} public long nextLong() throws IOException {return Long.parseLong(next());} public String nextLine() throws IOException {return br.readLine();} public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if(x.charAt(0) == '-') { neg = true; start++; } for(int i = start; i < x.length(); i++) if(x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if(dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg?-1:1); } public long[] nextLongArr(int n) throws IOException { long[] arr = new long[n]; for (int i = 0; i < n; i++) arr[i] = nextLong(); return arr; } public int[] nextIntArr(int n) throws IOException { int[] arr = new int[n]; for (int i = 0; i < arr.length; i++) arr[i] = nextInt(); return arr; } public boolean ready() throws IOException {return br.ready();} }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
ba38e17690f38359c37d744d10c04a7c
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class TokitsukazeandAllZeroSequence { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); int t = Integer.parseInt(br.readLine()); while (t-- > 0) { int n = Integer.parseInt(br.readLine()); String s = br.readLine(); StringTokenizer st = new StringTokenizer(s); int[] arr = new int[n]; int min = 0; Boolean allZeros = true; for (int i = 0; i < arr.length; i++) { arr[i] = Integer.parseInt(st.nextToken()); if(arr[i] != 0) allZeros = false; if(i == 0) { min = arr[i]; } if(arr[i] < min) { min = arr[i]; } } if(allZeros) { out.println(0); } else if(min == 0) { int ans = 0; for(int i=0; i<arr.length; i++) { if(arr[i] != 0) ans++; } out.println(ans); } else { Boolean foundDup = false; for (int i = 0; i < arr.length; i++) { for (int j = i+1; j < arr.length; j++) { if(arr[i] == arr[j]) { foundDup = true; break; } } } if(foundDup) { out.println(n); } else { out.println(n+1); } } } out.flush(); } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
b77b9703f3f2d26b739e21e0eb592443
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.*; public class Solution { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); while (n-->0) { int m = scanner.nextInt(); int[] arr = new int[m]; int count = 0; HashSet<Integer> set = new HashSet<>(); for (int i = 0; i<m; i++) { arr[i] = scanner.nextInt(); if (arr[i]!=0) count++; set.add(arr[i]); } if (count == m) { if (set.size() == m) { System.out.println(m+1); } else { System.out.println(m); } continue; } System.out.println(count); } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
ddaaa56d408f3fe92f63097e7f7af2b4
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; public class TokitsukazeAndSeqLite { private static int countOfOper(int lenghtOfSeq, int[] seq) { int min = lenghtOfSeq; boolean zeroFlag = false; for (int i = 0; i < lenghtOfSeq; i++) { if (seq[i] == 0) { min--; zeroFlag = true; } } if (zeroFlag) { return min; } for (int i = 0; i < lenghtOfSeq - 1; i++) { int j = i + 1; while (j < lenghtOfSeq) { if (seq[i] != seq[j]) { j++; } else { return lenghtOfSeq; } } } return lenghtOfSeq + 1; } public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); int numOfSeq = Integer.parseInt(bufferedReader.readLine()); for (int i = 0; i < numOfSeq; i++) { System.out.println(countOfOper(Integer.parseInt(bufferedReader.readLine()), Arrays.stream(bufferedReader.readLine().split(" ")).mapToInt(Integer::parseInt).toArray())); } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
64a791083d1b48cae90e60cfdcb84739
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.*; public class test { public static void main(String []args){ Scanner sc=new Scanner (System.in); int t=sc.nextInt(); while(t>0){ int c=0,n=sc.nextInt(); boolean flag1=false,flag2=false,flag3=true; int []arr=new int[n]; for(int i=0;i<=n-1;i++){ arr[i]=sc.nextInt(); if(arr[i]==0) flag1=true; if(arr[i]!=0){ flag3=false; c++; } for(int j=0;j<=i-1;j++){ if(arr[i]==arr[j]) flag2=true; } } if(flag3) System.out.println(arr[0]); else if(flag1) System.out.println(c); else if(flag2) System.out.println(n); else System.out.println(n+1); t--; } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
ce814ef31eeb9d3744da6dab554fd943
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.io.*; import java.util.*; public class A { static long TIME_START, TIME_END; public static class Task { public void solve(Scanner sc, PrintWriter pw) throws IOException { int n = sc.nextInt(); int[] arr = sc.readIntArray(n); Arrays.sort(arr); if (arr[0] == 0) { int count = 0; for (int i = 0; i < n; i++) { if (arr[i] == 0) count++; } pw.println(n - count); } else { for (int i = 1; i < n; i++) { if (arr[i - 1] == arr[i]) { pw.println(n); return; } } pw.println(n + 1); } } } public static void main(String... args) throws IOException { // Scanner sc = new Scanner(new FileReader(System.getenv("INPUT"))); Scanner sc = new Scanner(System.in); // PrintWriter pw = new PrintWriter(new BufferedOutputStream(new FileOutputStream(System.getenv("OUTPUT")))); PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out)); Task t = new Task(); int T = sc.nextInt(); while (T-- > 0) t.solve(sc, pw); pw.close(); } } class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader s) throws FileNotFoundException { br = new BufferedReader(s); } public String next() throws IOException { while (st == null || ! st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public int[] readIntArray(int n) throws IOException { int[] arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = nextInt(); return arr; } public long[] readLongArray(int n) throws IOException { long[] arr = new long[n]; for (int i = 0; i < n; i++) arr[i] = nextLong(); return arr; } public boolean ready() throws IOException { return br.ready(); } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
4e222c89dd4f09b9aa317ef47ba3cb4a
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.io.*; import java.util.*; public class ProblemA{ static long mod = 1000000007L; static MyScanner sc = new MyScanner(); //code here static void solve(){ int x = sc.nextInt(); int[] a = new int[x]; int[] b = new int[101]; for(int i=0;i<x;i++) { a[i] = sc.nextInt(); b[a[i]]++; } boolean repeat = false; for(int i=0;i<101;i++) { if(b[i] > 1) { repeat = true; break; } } if(b[0] > 0) out.println(x-b[0]); else if(repeat) { out.println(x); }else { out.println(x+1); } } // code ends static String sortString(String inputString) { char tempArray[] = inputString.toCharArray(); Arrays.sort(tempArray); return new String(tempArray); } static boolean isPali(String str){ int i = 0; int j = str.length()-1; while(i<j){ if(str.charAt(i)!=str.charAt(j)){ return false; } i++; j--; } return true; } 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 String reverse(String str){ char arr[] = str.toCharArray(); int i = 0; int j = arr.length-1; while(i<j){ char temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; i++; j--; } String st = new String(arr); return st; } static boolean isprime(int n){ if(n==1) return false; if(n==3 || n==2) 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; } static class Pair implements Comparable<Pair>{ int val; int ind; int ans; Pair(int v,int f){ val = v; ind = f; } public int compareTo(Pair p){ return p.val - this.val; } } public static void main(String[] args) { out = new PrintWriter(new BufferedOutputStream(System.out)); int t = sc.nextInt(); // int t= 1; while(t-- >0){ // solve(); 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; } } 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); // collections.sort uses nlogn in backend for (int i = 0; i < arr.length; i++){ arr[i] = list.get(i); } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
c4500b399879325d9b266b3f72034a91
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.math.BigInteger; import java.util.*; import static java.lang.System.*; public class Round_780_Div_3 { static MyScanner str = new MyScanner(); static ArrayList<Integer> list; final int mod = 1000000007; public static void main(String[] args) { long T = str.nextLong(); while (T-- > 0) { solve(); } } static void solve() { int n = str.nextInt(); int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = str.nextInt(); } Arrays.sort(a); int cnt0 = 0; int cnts = 0; for (int i = 0; i < n; i++) { if (a[i] == 0) { cnt0++; } if (i != n - 1) { if (a[i] == a[i + 1]) { cnts++; } } } if (cnt0 != 0) { out.println(n - cnt0); return; } if (cnts != 0) { out.println(n); return; } out.println(n + 1); } 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
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
69f2a6b37ff0a17e4ed8d5bfb4fd825e
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.*; public class main{ public static void main(String[]args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); int arr[]=new int[n]; boolean haveZero=false; boolean isSame=false; int noOfNonZeros=0; for(int i=0;i<n;i++) { arr[i]=sc.nextInt(); if(arr[i]==0) { haveZero=true; } if(arr[i]!=0){ noOfNonZeros++; } } //if it contains zero if(haveZero) { System.out.println(noOfNonZeros); continue; } //if contains same integer near to it for(int i=0;i<n;i++) { for(int j=i+1; j<n; j++) { if(arr[i]==arr[j]) { isSame=true; break; } } } if(isSame) { System.out.println(n); continue; } System.out.println(n+1); } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
1dfac8f1e8d61806d0b907a84d525fa6
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class A { public static void main(String[] args) throws java.lang.Exception { try { FastReader sc = new FastReader(); int t = sc.nextInt(); u: while (t-- > 0) { int n = sc.nextInt(); HashSet<Integer> hs=new HashSet<>(); int arr[]=sc.readArray(n); boolean flag=false,flag2=false; int c=0; for(int i=0;i<n;i++) { if(hs.contains(arr[i])) flag2=true; hs.add(arr[i]); if(arr[i]==0) { flag=true; c++; } } if(flag) { System.out.println(n-c); } else if(flag2) System.out.println(n); else System.out.println(n+1); } } catch (Exception e) { } finally { return; } } 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; } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
d551980e2e5624f44a0fb2c2bcedf940
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashMap; import java.util.StringTokenizer; public class A_Tokitsukaze_and_All_Zero_Sequence { 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 ni() { return Integer.parseInt(next()); } long nl() { return Long.parseLong(next()); } double nd() { return Double.parseDouble(next()); } String nL() { String str = ""; try { if (st.hasMoreTokens()) { str = st.nextToken("\n"); } else { str = br.readLine(); } } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) throws IOException { FastReader s = new FastReader(); int t = s.ni(); while (t-- > 0) { int n = s.ni(); int[] arr = new int[n]; HashMap<Integer,Integer> table = new HashMap<>(); for (int i = 0; i < n; i++) { arr[i] = s.ni(); if(table.get(arr[i]) == null){ table.put(arr[i],1); }else table.put(arr[i],table.get(arr[i])+1); } boolean getZero = false; if(table.get(0) != null && table.get(0) > 0){ System.out.println(n - table.get(0)); }else{ for(int val:table.values()){ if(val > 1){ getZero = true; } } if(getZero){ System.out.println(1+n-1); }else System.out.println(2+n-1); } } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
535096d135c73a436e750310324f162a
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
///package solution; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.HashSet; import java.util.Set; import java.util.StringTokenizer; public class Solution implements Runnable { public void solve() throws Exception { int testCase = sc.nextInt(); while (testCase-- > 0) { int n = sc.nextInt(); String[] str = in.readLine().split("\\s+"); int zero = 0; int []arr = new int[n]; for (int i = 0; i < str.length; i++) { arr[i] = Integer.valueOf(str[i]); } Arrays.sort(arr); for (int i = 0; i < arr.length; i++) { if (arr[i] == 0) { zero++; } } if (zero > 0) { int temp = arr.length-zero; out.println(temp); continue; } zero = 0; for (int i = 1; i < arr.length; i++) { if (arr[i] == arr[i-1]) { zero++; } } if (zero > 0) { out.println(arr.length); continue; } int temp = arr.length+1; out.println(temp); } } static Throwable uncaught; BufferedReader in; FastScanner sc; PrintWriter out; @Override public void run() { try { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); sc = new FastScanner(in); solve(); } catch (Throwable uncaught) { Solution.uncaught = uncaught; } finally { out.close(); } } public static void main(String[] args) throws Throwable { Thread thread = new Thread(null, new Solution(), "", (1 << 26)); thread.start(); thread.join(); if (Solution.uncaught != null) { throw Solution.uncaught; } } } class FastScanner { BufferedReader in; StringTokenizer st; public FastScanner(BufferedReader in) { this.in = in; } public String nextToken() throws Exception { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(in.readLine()); } return st.nextToken(); } public int nextInt() throws Exception { return Integer.parseInt(nextToken()); } public long nextLong() throws Exception { return Long.parseLong(nextToken()); } public double nextDouble() throws Exception { return Double.parseDouble(nextToken()); } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
31c16d70ecaa3bb201ae27d7cd4da61e
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.HashMap; import java.util.HashSet; import java.util.Scanner; public class Contest { public static void main(String[] args) { Scanner s = new Scanner(System.in); int t = s.nextInt(); while(t-->0) { // HashMap<Integer, Integer> h = new HashMap<>(); HashSet<Integer> h = new HashSet<>(); int n = s.nextInt(); int a[] = new int[n]; int num0 = 0; for(int i=0;i<n;i++) { a[i]=s.nextInt(); if(a[i]==0) { num0 += 1; } h.add(a[i]); // h.put(a[i], h.getOrDefault(a[i], 0)+1); // } // int minNum = 0; // for(int i:a) { // if(h.get(i)!=0) { // minNum += h.get(i); // h.put(i, 0); // } } // if(h.size()==n && num0==0) // System.out.println(n+1); // else // System.out.println(minNum-num0); if(num0==0 && h.size()==n) { System.out.println(n+1); }else { System.out.println(n-num0); } } s.close(); } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
83267fa34df8ef35ef7f0d15428c925a
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; import java.util.*; import java.io.PrintWriter; import java.io.OutputStream; import java.math.BigInteger; public class Solution{ public static void main(String[] args){ FastReader sc=new FastReader(); int p=sc.nextInt(); for(int j=0;j<p;j++){ int n=sc.nextInt(); int arr[]=new int[n]; for(int i=0;i<n;i++){ arr[i]=sc.nextInt(); } Arrays.sort(arr); int count=0; if(arr[0]==0){ int k=0; while(k<n && arr[k]==0) k++; System.out.println(n-k); } else { int flag=1; for(int i=0;i<n-1;i++){ if(arr[i]==arr[i+1]){ flag=0; break; } } if(flag==0){ System.out.println(n); } else{ System.out.println(n+1); } } } } 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
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
ccda690b8514db73c0ee2e0ad3c9f45c
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.StringTokenizer; public class 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()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) { FastReader r = new FastReader(); int t = r.nextInt(); while (t-- > 0) { int n = r.nextInt(); int[] nums = new int[n]; for (int i = 0; i < n; i++) { nums[i] = r.nextInt(); } Arrays.sort(nums); int count = 0; boolean zero = false; if (nums[0] == 0) zero = true; for (int i = 1; i < nums.length && !zero; i++) { if (nums[i] == nums[i - 1]) { zero = true; nums[i] = 0; count = 1; } } if (!zero) { nums[1] = nums[0]; nums[0] = 0; zero = true; count = 2; } for (int i = 0; i < nums.length; i++) { if (nums[i] != 0) count++; } System.out.println(count); } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
8747dc29d5c722fdda99d2185b0fb659
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.io.*; import java.util.InputMismatchException; public class A { public static void main(String[] args) throws IOException { ReadInput in = new ReadInput(System.in); PrintWriter writer = new PrintWriter(System.out); int t = in.nextInt(); for (int ti = 0; ti < t; ti++) { int n = in.nextInt(); int[] a = new int[n]; int[] count = new int[101]; boolean repeated = false; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); count[a[i]]++; if (count[a[i]] > 1) { repeated = true; } } int res = n; if (count[0] > 0) { res -= count[0]; } else { if (!repeated) { res++; } } writer.println(res); } in.close(); writer.flush(); writer.close(); } public static class ReadInput { private final BufferedReader source; private String next; public ReadInput(InputStream source) { this.source = new BufferedReader(new InputStreamReader(source)); } public ReadInput(String source) { this.source = new BufferedReader(new StringReader(source)); } public ReadInput(File source) throws IOException { this.source = new BufferedReader(new FileReader(source)); } public String next() throws IOException { if (next == null) { if (!hasNext()) { throw new InputMismatchException("Nothing to read"); } } String res = next; next = null; return res; } public int nextInt() throws IOException { return Integer.parseInt(next()); } public Long nextLong() throws IOException { return Long.parseLong(next()); } public Double nextDouble() throws IOException { return Double.parseDouble(next()); } public boolean hasNext() throws IOException { if (next != null) { return true; } StringBuilder sb = new StringBuilder(); int read = skipSpaces(); while (read != -1 && !testSpaces(read)) { sb.append((char) read); read = source.read(); } if (sb.length() > 0) { next = sb.toString(); return true; } else { return false; } } private int skipSpaces() throws IOException { int read; do { read = source.read(); } while (testSpaces(read)); return read; } private boolean testSpaces(int c) { return c == ' ' || c == '\r' || c == '\t' || c == '\n'; } public void close() throws IOException { next = null; source.close(); } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
42fcfa05fa0ad2babf2bbdc4913ba200
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.Scanner; public class check{ public static boolean isPresent(char ch, char[] arr){ for(int i=0;i<arr.length;i++){ if(ch==arr[i]) return true; } return false; } public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t>0){ int n=sc.nextInt(); int zeroCount=0; boolean twoIdentical=false; int[] arr=new int[n]; for(int i=0;i<n;i++){ arr[i]=sc.nextInt(); if(arr[i]==0) zeroCount++; for(int j=0;j<i;j++){ if(arr[j]==arr[i]) twoIdentical=true; } } if(zeroCount>0) System.out.println(n-zeroCount); else if(twoIdentical) System.out.println(n); else System.out.println(n+1); t--; } sc.close(); } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
81adb164d5a6d38ddb947b3879dccb00
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
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) { FastReader sc = new FastReader(); StringBuilder ss = new StringBuilder(); try { int t = sc.nextInt(); while(t-->0) { int n = sc.nextInt(); int a[] = new int[n]; for(int i = 0 ;i<n;i++) { a[i] = sc.nextInt(); } Arrays.sort(a); boolean flag = false; if(a[0] == 0) { int cnt = 0; for(int i = 0 ; i<n;i++) { if(a[i] == 0 ) { cnt++; } } long rem = n- cnt; ss.append(rem); } else { int cnt = 1; int max = Integer.MIN_VALUE; for(int i= 1 ; i <n;i++) { if(a[i] == a[i-1]) { cnt++; } else { max = Math.max(max, cnt); cnt = 1; } } max = Math.max(max, cnt); if(max == 1) { long moves = 2 + (n-1); ss.append(moves); } else { long moves = 1 + (n-1); ss.append(moves); } } ss.append("\n"); } System.out.println(ss); } catch(Exception e) { System.out.println(e.getMessage()); } } 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 long lcm(long a, long b) { long pr = a*b; return pr/gcd(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>{ long a; long b ; Pair(long a, long b){ this.a = a; this.b = b; } @Override public int compareTo(Pair o) { // TODO Auto-generated method stub return (int) (this.b - o.b); } } static int[] sieve(int n) { int a[] = new int[n+1]; Arrays.fill(a,-1); a[1] = 1; for(int i = 2 ; i*i <=n ; i++) { if(a[i] == -1) { for(int j = 2*i ; j<=n ; j+=i) { a[j] = 1; } } } // // int prime = -1; // for(int i = n ; i>=1 ; i--) { // if(a[i] == 1) { // a[i] =prime; // } // else { // prime = i; // a[i] = prime; // } // } return a; } static ArrayList<Integer> pf(long n) { ArrayList<Integer> al = new ArrayList<>(); while(n%2 == 0) { al.add(2); n = n/2; } for(int i = 3 ; i*i<=n ; i+=2) { while(n%i == 0) { al.add(i); n = n/i; } } if(n>2) { al.add( (int) n); } return al; } 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
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
15323a83c8ad5e68e0ddc981af0ed27c
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class A { static class RealScanner { 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()); } public boolean isSorted(List<Long> list) { for (int i = 0; i < list.size() - 1; i++) { if (list.get(i) > list.get(i + 1)) return false; } return true; } } public static void main(String[] args) { RealScanner sc = new RealScanner(); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); // Set<Integer> h = new HashSet<>(); // boolean check = true; // for (int i = 0; i < n; i++) { // int x = sc.nextInt(); // if (x == 0) { // check = false; // } else { // h.add(x); // } // } // if (!check){ // System.out.println(h.size()); // }else { // System.out.println(h.size()+1); // } List<Integer> l = new ArrayList<>(); for (int i = 0; i < n; i++) { l.add(sc.nextInt()); } Collections.sort(l); int count = 0; while (count < n && l.get(count) == 0) { count++; } boolean check = false; if (count > 0) { check = true; } else { for (int i = 0; i < n - 1; i++) { if (l.get(i).equals(l.get(i + 1))) { check = true; break; } } } if (count > 0) { System.out.println(n - count); } else if (check) { System.out.println(n); } else { System.out.println(n + 1); } } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
d949e0d9b31ee978646d061e3e8e1d68
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.Writer; import java.math.BigInteger; import java.util.InputMismatchException; /** * Built using CHelper plug-in * Built using CHelper plug-in * Actual solution is at the top * * @author Meet Patel */ 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); Task solver = new Task(); solver.solve(in, out); out.close(); } static class Task { public void solve(InputReader sc, OutputWriter out) { int t = sc.nextInt(); while(t-- > 0) { int n = sc.nextInt(); int[] a = new int[n]; boolean[] p = new boolean[105]; boolean f = false; int z = 0; for(int i = 0 ; i < n ; i++) { a[i] = sc.nextInt(); if (a[i] == 0) z++; if (p[a[i]]) f = true; p[a[i]] = true; } if (z == n) out.println(0); else if (z > 0) out.println(n - z); else out.println(f == true ? n : n + 1); } } } 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 print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) { writer.print(' '); } writer.print(objects[i]); } } public void println(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) { writer.print(' '); } writer.print(objects[i]); } writer.print('\n'); } public void close() { writer.close(); } } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private InputReader.SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public double nextDouble() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') { return res * Math.pow(10, nextInt()); } if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') { return res * Math.pow(10, nextInt()); } if (c < '0' || c > '9') { throw new InputMismatchException(); } m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public BigInteger readBigInteger() { try { return new BigInteger(nextString()); } catch (NumberFormatException e) { throw new InputMismatchException(); } } public int[] nextIntArray(int n){ int[] array = new int[n]; for(int i = 0; i < n ; ++i) array[i] = nextInt(); return array; } public long[] nextLongArray(int n){ long[] array = new long[n]; for(int i = 0 ; i < n ; ++i) array[i] = nextLong(); return array; } public char nextCharacter() { int c = read(); while (isSpaceChar(c)) { c = read(); } return (char) c; } public String nextString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { if (Character.isValidCodePoint(c)) { res.appendCodePoint(c); } c = read(); } while (!isSpaceChar(c)); return res.toString(); } public String next() { return nextString(); } public boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
cfc388149915ff19c76284ea0b4369ca
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.*; import java.io.*; public class A{ public static void main(String[] args) throws IOException,NumberFormatException{ try { FastScanner sc=new FastScanner(); int t=sc.nextInt(); while(t-->0) { Set<Integer> set=new HashSet<>(); int n=sc.nextInt(); int a[]=sc.readArray(n); boolean contains=false; int count0=0; for(int i:a) { if(i==0)count0++; if(set.contains(i)) { contains=true; } set.add(i); } if(set.contains(0)) { System.out.println(n-count0); } else if(contains) { System.out.println(n); } else { System.out.println(n+1); } } } catch(Exception e) { return ; } } public static int GCD(int a, int b) { if(b==0) { return a; } else { return GCD(b,a%b); } } public static boolean isPrime(int n) { if(n==0||n==1) { return false; } for(int i=2;i*i<=n;i++) { if(n%i==0) { return false; } } return true; } public static class Pair<L,R> { private L l; private R r; public Pair(L l, R r){ this.l = l; this.r = r; } public L getL(){ return l; } public R getR(){ return r; } public void setL(L l){ this.l = l; } public void setR(R r){ this.r = r; } } // public static void djikstra(int a[],ArrayList<Node> adj[] ,int src,int n) { // // Arrays.fill(a, Integer.MAX_VALUE); // a[src]=0; // PriorityQueue<Node> pq=new PriorityQueue<Node>(n, new Node()); // pq.add(new Node(src,0)); // // while(!pq.isEmpty()) { // Node node=pq.remove(); // int v=node.getV(); // int weight=node.getWeight(); // for(Node it: adj[v]) { // if(it.weight+weight<a[it.getV()]) { // a[it.getV()]=it.weight+weight; // pq.add(new Node(it.getV(),a[it.getV()])); // } // } // } // } static final Random random=new Random(); static void ruffleSort(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); } public 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()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long[] readLongArray(int n) { long[] a=new long[n]; for(int i=0; i<n ; i++) a[i]=nextLong(); return a; } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
78d9e9892e7947c7ddd00e252d5ac12b
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.*; import java.io.*; public class Solution { public static void main(String[] args) throws IOException { int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int[] arr = sc.nextIntArray(n); int duplicate = 0; int zero = 0; Arrays.sort(arr); for (int i = 0; i < arr.length; i++) { if (arr[i] == 0) zero++; } for (int i = 0; i < arr.length - 1; i++) { if (arr[i] == arr[i + 1]) duplicate++; } if (zero > 0) pw.println(arr.length - zero); else if (duplicate > 0) pw.println(arr.length); else pw.println(arr.length + 1); } pw.close(); } static int f(int num) { int res = 0; while (num > 0) { if (num % 2 == 0) num /= 2; else { num = (num - 1) / 2; res++; } } return res; } static HashMap Hash(int[] arr) { HashMap<Integer, Integer> map = new HashMap<>(); for (int i : arr) { map.put(i, map.getOrDefault(i, 0) + 1); } return map; } static HashMap Hash(char[] arr) { HashMap<Character, Integer> map = new HashMap<>(); for (char i : arr) { map.put(i, map.getOrDefault(i, 0) + 1); } return map; } static boolean isPrime(int n) { if (n <= 1) return false; for (int i = 2; i <= Math.sqrt(n); i++) if (n % i == 0) return false; return true; } public static long combination(long n, long r) { return factorial(n) / (factorial(n - r) * factorial(r)); } static long factorial(Long n) { if (n == 0) return 1; return n * factorial(n - 1); } static boolean isPalindrome(char[] str, int i, int j) { // While there are characters to compare while (i < j) { // If there is a mismatch if (str[i] != str[j]) return false; // Increment first pointer and // decrement the other i++; j--; } // Given string is a palindrome return true; } public static double log2(int N) { double result = (Math.log(N) / Math.log(2)); return result; } public static double log4(int N) { double result = (Math.log(N) / Math.log(4)); return result; } public static int setBit(int mask, int idx) { return mask | (1 << idx); } public static int clearBit(int mask, int idx) { return mask ^ (1 << idx); } public static boolean checkBit(int mask, int idx) { return (mask & (1 << idx)) != 0; } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader r) { br = new BufferedReader(r); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public long[] nextlongArray(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public Long[] nextLongArray(int n) throws IOException { Long[] a = new Long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public int[] nextIntArray(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public Integer[] nextIntegerArray(int n) throws IOException { Integer[] a = new Integer[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public boolean ready() throws IOException { return br.ready(); } } static class pair implements Comparable<pair> { long x; long y; public pair(long x, long y) { this.x = x; this.y = y; } public String toString() { return x + " " + y; } public boolean equals(Object o) { if (o instanceof pair) { pair p = (pair) o; return p.x == x && p.y == y; } return false; } public int hashCode() { return new Long(x).hashCode() * 31 + new Long(y).hashCode(); } public int compareTo(pair other) { if (this.x == other.x) { return Long.compare(this.y, other.y); } return Long.compare(this.x, other.x); } } static class tuble implements Comparable<tuble> { int x; int y; int z; public tuble(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } public String toString() { return x + " " + y + " " + z; } public int compareTo(tuble other) { if (this.x == other.x) { if (this.y == other.y) { return this.z - other.z; } return this.y - other.y; } else { return this.x - other.x; } } } public static String toString(int[] arr) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < arr.length; i++) { sb.append(arr[i] + " "); } return sb.toString().trim(); } public static String toString(ArrayList arr) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < arr.size(); i++) { sb.append(arr.get(i) + " "); } return sb.toString().trim(); } public static String toString(int[][] arr) { StringBuilder sb = new StringBuilder(); for (int[] i : arr) { sb.append(toString(i) + "\n"); } return sb.toString(); } public static String toString(boolean[] arr) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < arr.length; i++) { sb.append(arr[i] + " "); } return sb.toString().trim(); } public static String toString(Integer[] arr) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < arr.length; i++) { sb.append(arr[i] + " "); } return sb.toString().trim(); } public static String toString(String[] arr) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < arr.length; i++) { sb.append(arr[i] + " "); } return sb.toString().trim(); } public static String toString(char[] arr) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < arr.length; i++) { sb.append(arr[i] + " "); } return sb.toString().trim(); } static long mod = 1000000007; static Random rn = new Random(); static Scanner sc = new Scanner(System.in); static PrintWriter pw = new PrintWriter(System.out); }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
7326fe8ff6611933afce87fde7b68cdb
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.*; import java.io.*; public class TokitsukazeandAllZeroSequence { public static void main(String[] args) throws IOException { int t = readInt(); while(t-->0){ int n = readInt(); int [] arr = new int[n]; boolean zero = false; int count = 0; HashSet<Integer> dis = new HashSet(); for(int i = 0; i < n; i++){ arr[i] = readInt(); dis.add(arr[i]); if(arr[i] == 0){ zero = true; count++; } } if(zero == true){ System.out.println(n - count); }else if(dis.size() == n){ System.out.println(n + 1); }else{ System.out.println(n); } } } static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); static StringTokenizer st; static String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine().trim()); 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 readLine() throws IOException { return br.readLine().trim(); } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
df1c3d41f384d5d30e9187080413137e
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.io.PrintWriter; import java.util.Arrays; import java.util.Scanner; public class Prob1678A { public static void main(String[] args) { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int t = sc.nextInt(); while(t-->0) { int n = sc.nextInt(); Integer[] a = new Integer[n]; boolean dup = false; int ans = 0; for(int i = 0; i < n; i++) { a[i] = sc.nextInt(); if(i != n-1 && a[i] == a[i+1]) dup = true; } Arrays.sort(a); for(int i = 0; i < n; i++) { if(i != n-1 && a[i] == a[i+1]) dup = true; } if(a[0] == 0) { for(int i = 0; i < n; i++) { if(a[i] > 0) ans++; } }else { if(dup) { ans = n; }else { ans = n+1; } } pw.println(ans); } sc.close(); pw.close(); } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
2f954878c048e322aac19f8678106dd9
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.*; import java.io.*; import java.lang.*; public class Main { 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') { if (cnt != 0) { break; } else { continue; } } 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(); } } public static void main(String[] args) throws IOException { Reader sc = new Reader(); long t = sc.nextLong(); while (t-- > 0) { long zero = 0; long n = sc.nextLong(); LinkedList<Long> list = new LinkedList<>(); for (int i = 0; i < n; i++) { list.add(sc.nextLong()); if (list.get(i) == 0) zero++; } HashSet<Long> st = new HashSet<>(); st.addAll(list); if (zero > 0) System.out.println(n - zero); else if (st.size() == n) { System.out.println(n + 1); } else System.out.println(n ); } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
5772db88d3335de3778c49f68a138225
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
//<———My cp———— import java.util.*; import java.io.*; public class Day1{ public static void main(String[] args) throws Exception{ FastReader fr = new FastReader(System.in); int t = fr.nextInt(); while(t-->0){ int n = fr.nextInt(); int[] vals = new int[n]; for(int i = 0;i<vals.length;i++){ vals[i] = fr.nextInt(); } int zeroCount = 0; boolean duplicatesFound = false; Arrays.sort(vals); for(int i = 0;i<vals.length;i++){ if(vals[i]==0){ zeroCount++; } if(i!=0 && vals[i]!=0 && vals[i]==vals[i-1]){ duplicatesFound = true; } } if(duplicatesFound||zeroCount>0){ System.out.println(n-zeroCount); }else{ System.out.println(n+1); } } } 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
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
eb9e1e50b606b9e9548d130e963f6f71
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; import java.util.Vector; import static java.lang.Math.PI; import static java.lang.Math.pow; public class haha { static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String nextString() throws IOException { return br.readLine(); } 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()); } float nextFloat() { return Float.parseFloat(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()); } } static int minde(int a, int b, int c) { if(a < b) { if (c < a) return b - c; else if ( c < b) return b - a; else return c - a; } else { if(c < b) return a - c; else if(c < a) return a - b; else return c - b; } } public static void main(String []args) throws IOException { PrintWriter out = new PrintWriter(System.out,true); FastScanner sc = new FastScanner(); int n = sc.nextInt(); for(int i = 0; i < n ; i++) { int m = sc.nextInt(); int []a = new int[m]; for (int j = 0 ; j < m ; j++) { a[j] = sc.nextInt(); } Arrays.sort(a); int ju = 0; for (int j = 0 ; j < m - 1 ; j++) { if(a[j] == 0) { ju = 1; break; } else if(a[j] == a[j + 1]) { ju = 2; break; } } if(ju == 0) out.println(m + 1); else if(ju == 1) { int q = -1; for(int j = 1 ; j < m ; j++) { if(a[j] != 0) { q = j ; break; } } if(q == -1) out.println(0); else out.println(m - q); } else out.println(m); } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
7dfe91e5e3f00497d42711a31c1980b4
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { FastReader in = new FastReader(System.in); PrintWriter pw = new PrintWriter(System.out); int test = in.nextInt(); for(int tt=1;tt<=test;tt++) { int n = in.nextInt(); ArrayList<Integer> l = new ArrayList<>(); int c = 0; for(int i = 0;i<n;i++) { int v = in.nextInt(); if(v==0) { c++; } else if(!l.contains(v)) { l.add(v); } } if(c>0) { pw.println(n-c); } else if(l.size()==n) { pw.println(n+1); } else { pw.println(n); } } pw.close(); } static int rev(int n) { int r = 0; while(n!=0) { int rem = n%10; r=r*10+rem; n/=10; } return r; } static class FastReader { InputStream is; private byte[] inbuf = new byte[1024]; private int lenbuf = 0, ptrbuf = 0; public FastReader(InputStream is) { this.is = is; } public 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++]; } public boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } public int skip() { int b; while ((b = readByte()) != -1 && isSpaceChar(b)) ; return b; } public String next() { int b = skip(); StringBuilder sb = new StringBuilder(); while (!(isSpaceChar(b))) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public String nextLine() { int c = skip(); StringBuilder sb = new StringBuilder(); while (!isEndOfLine(c)) { sb.appendCodePoint(c); c = readByte(); } return sb.toString(); } public int nextInt() { 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 << 3) + (num << 1) + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } public long nextLong() { 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 << 3) + (num << 1) + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } public double nextDouble() { return Double.parseDouble(next()); } public char[] next(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); } public char readChar() { return (char) skip(); } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
16e24cf1e4afb65b77375b1c42d9e723
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.Arrays; import java.util.PriorityQueue; import java.util.Scanner; public class aa { public static void main(String[] args) { var in = new Scanner(System.in); int n = in.nextInt(); for(int i = 0; i < n; i++) { int m = in.nextInt(); int[] a = new int[m]; for(int j = 0; j < m; j++) a[j] = in.nextInt(); int nNonZero = 0; boolean hasEqual = false; Arrays.sort(a); for(int j =1 ; j < m ; j++){ if(a[j-1] != 0) nNonZero++; if(a[j-1] == a[j]) hasEqual = true; } if(a[m-1] != 0) nNonZero++; if(nNonZero == m && !hasEqual) System.out.println(nNonZero+1); else System.out.println(nNonZero); } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
0ae21aa412a8f59da1e9633e1e5c8b68
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner input=new Scanner(System.in); int caseNum=input.nextInt(); for (int i = 0; i < caseNum; i++) { int n = input.nextInt(); int[] num=new int[n]; for (int j = 0; j < n; j++) { num[j]=input.nextInt(); } if (getZeroCounts(num) > 0) { System.out.println(num.length - getZeroCounts(num)); } else if(isSame(num)){ System.out.println(num.length); } else { System.out.println(num.length + 1); } } } private static boolean isSame(int[] num) { for (int i = 0; i < num.length-1; i++) { for (int j = i+1; j < num.length; j++) { if (num[i] == num[j]) { return true; } } } return false; } private static int getZeroCounts(int[] num) { int count = 0; for (int i = 0; i < num.length; i++) { if (num[i] == 0) { count++; } } return count; } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
9f7f36130901f6f58af8871190da96f0
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
/* Enjoy the code :> Modular Arithematic 1. (a + b)%c = ((a%c)+(b%c))%c 2. (a - c)%c = ((a%c)-(b%c) + c)%c 3. (a * c)%c = ((a%c)*(b*c))%c 4. (a / b)%c = ((a%c)*(b-1%c))%c Modular Exponetion --> time complexity O(logN) */ import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; import static java.lang.System.out; import java.io.*; import java.util.*; import java.math.*; public class Main { static int N = 1000000; static int M = 1000000007; public static void main(String[] args) throws Exception{ fileConnect(); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); int t = Integer.parseInt(st.nextToken()); while(t-- > 0){ st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()); int[] arr = readArr(n, br, st); Arrays.sort(arr); int k=0, l=0; for(int i=1; i<n; i++){ if(arr[i] == arr[i-1]){ k++; } if(arr[i] != 0){ l++; } } if(arr[0] == 0){ System.out.println(l); }else if(k > 0){ System.out.println(n); }else { System.out.println(n+1); } } } // read array static int[] readArr(int N, BufferedReader br, StringTokenizer st) throws Exception { int[] arr = new int[N]; st = new StringTokenizer(br.readLine()); for(int i=0; i < N; i++) arr[i] = Integer.parseInt(st.nextToken()); return arr; } // print array static void printArr(int[] arr, int n){ for(int i=0; i<n; i++){ System.out.print(arr[i] + " "); } System.out.println(); } // gcd static long gcd(long a, long b){ if(b == 0) return a; return gcd(b, a%b); } // lcm public static long lcm(long a, long b){ return (a * b)/gcd(a, b); } // binary exponentiation static long binaryExp(long x, long n){ // calcute x ^ n; if(n == 0){ return 1; } else if(n%2 == 0){ return binaryExp(x*x, n/2); }else { return x * binaryExp(x*x, (n-1)/2); } } // modular exponentiation static long modExp(long x, long n, long m){ // calcute (x ^ n)%m; if(n == 0){ return 1; } else if(n%2 == 0){ long temp = (x * x)%m; return modExp(temp, n/2, m)%m; }else { long temp = (x * x)%m; return (x * modExp(temp, (n-1)/2, m))%m; } } // number is prime of not static boolean isPrime(int n){ if(n == 0 || n == 1) return false; if(n == 2 || n == 3) return true; for(int i=2; i*i<=n; i++){ if(n%i == 0){ return false; } } return true; } /* seive of erotheneses - mark all prime between 1 to maxN */ static void seiveOfEroth(){ int maxN = 1000000; boolean[] prime = new boolean[maxN + 1]; // false for prime and true for non-prime prime[0] = prime[1] = true; for(int i=2; i<=maxN; i++){ if(!prime[i]){ for(int j=i*i; j<=maxN; j+=i){ prime[j] = true; } } } } /* prime factorisation optimise solution time complexity = O(sqrt(N)) */ static void primeFactor(int n){ if(n == 1) System.out.print(n); for(int i=2; i*i<=n; i++){ if(n == 1) return; int cnt = 0; if(n%i == 0){ while(n%i == 0){ cnt++; n = n/i; } if(n != 1) System.out.print(i + " ^ " + cnt + " + "); else { System.out.print(i + " ^ " + cnt); } } } if(n > 1){ System.out.print(n + " ^ 1"); } } /* prime factorisation using seive -- time complexity - O(logN) -- use when multiple testcases */ static void primeFactor2(int n){ if(n == 1) System.out.print(1); int[] seive = new int[N+1]; seive[0] = 0; seive[1] = 1; // this loop mark all the position with first prime number divisor. for(int i=2; i<=N; i++){ if(seive[i] == 0){ for(int j=i; j<=N; j+=i){ if(seive[j] == 0){ seive[j] = i; } } } } // end of for loop while(n != 1){ if(n/seive[n] != 1) System.out.print(seive[n] + "*"); else System.out.print(seive[n]); n = n/seive[n]; }// end of while } /* Calculate the power of matrix */ static long[][] powerMatix(long[][] matrix, int dim, int n){ // create identity matrix long[][] identity = new long[dim][dim]; for(int i=0; i<dim; i++){ identity[i][i] = 1; } // printMatrix(identity, dim); if(n==0) return identity; if(n==1) return matrix; // time complexity O(n) // overtime O(n*( n^3)) // for(int i=1; i<n; i++){ // matrix = matmat(matrix, matrix, dim); // } // now use binary exponenition concept // new time complexity O(logN*(N^3)) long[][] temp = identity; int cnt = 0; while(n > 1){ if(n%2 == 1){ temp = multimat(matrix, temp, dim); n--; }else { matrix = multimat(matrix, matrix, dim); n = n/2; } } matrix = multimat(matrix, temp, dim); return matrix; } // print the matrix static void printMatrix(long[][] matrix, int dim){ for(int i=0; i<dim; i++){ for(int j=0; j<dim; j++){ System.out.print(matrix[i][j] + " "); } System.out.println(); } } // matrix multiplication // time complexity O(n^3) // this is for square matrix. static long[][] multimat(long[][] matrix, long[][] matrix2, int dim){ long[][] result = new long[dim][dim]; for(int i=0; i<dim; i++){ for(int j=0; j<dim; j++){ for(int k=0; k<dim; k++){ result[i][j] = (result[i][j] + ((matrix[i][k] % M)* (matrix2[k][j]%M))%M)%M; } } } // for(int i=0; i<dim; i++){ // for(int j=0; j<dim; j++){ // matrix[i][j] = result[i][j]; // } // } // printMatrix(result, dim); return result; } // FileInputOutput static void fileConnect(){ try { System.setIn(new FileInputStream("input.txt")); System.setOut(new PrintStream(new FileOutputStream("output.txt"))); } catch (Exception e) { System.err.println("Error"); } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
0e83bcc63b184d555f8f60bd741893e6
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.*; public class anshu { 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(); int[] arr = new int[n]; for(int i=0;i<n;i++) arr[i]=sc.nextInt(); Arrays.sort(arr); int count = 0,zero = 0; for(int i=0;i<n;i++) { if(arr[i]==0)zero++; else if(i<n-1 && arr[i]==arr[i+1]) { arr[i]=0; count++; } } int rem = n - count; if(zero == n) { System.out.println(0); } else if(zero!=0) { System.out.println(n-zero); } else if(count!=0) { System.out.println(rem+count); } else { count = 2; System.out.println(n + 1); } } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
4ea69279481c0e460450bb902e8a7c75
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.io.*; import java.util.*; public class Cses { static boolean[] table = new boolean[10001]; static StringBuilder sb =new StringBuilder(); static TreeSet<String> sn = new TreeSet<>(); static List<Long> sm = new ArrayList<>(); static int numberOfWays=0; static class Point { int a; int b; public Point(int a, int b){ this.a= a; this.b=b; } } static void sieveOfEratosthenes() { // Create a boolean array "prime[0..n]" and initialize // all entries it as true. A value in prime[i] will // finally be false if i is Not a prime, else true. for(int i=0;i<=10000;i++){ table[i] = true; } for(int p = 2; p*p <=100000000; p++) { // If prime[p] is not changed, then it is a prime if(table[p]) { // Update all multiples of p for(int i = p*p; i <= 100000000; i += p) table[i] = false; } } // Print all prime numbers } public static void minDistance(int[] tab , long s ,int index){ if(tab.length==index){ sm.add(s); return; } int go =tab[index]; index++; minDistance(tab,s,index); minDistance(tab,s+go,index); } public static void steps(int n, int start,int end){ int mid=0; if (n==0)return; if(start+end==3)mid = 3; if(start+end==4)mid = 2; if(start+end==5)mid = 1; steps(n-1,start,mid); sb.append(start).append(" ").append(end).append(System.lineSeparator()); steps(n-1,mid,end); } public static void print_rec(LinkedList<String> strings , StringBuilder s ){ if(strings.size()==0){ sn.add(String.valueOf(s)); return ;} for (int i = 0; i < strings.size(); i++) { StringBuilder ss = new StringBuilder(); LinkedList<String> subStrings = (LinkedList<String>) strings.clone(); subStrings.remove(i); ss.append(s).append(strings.get(i)); print_rec(subStrings , ss); } } static boolean[] ld = new boolean[15]; static boolean[] rd = new boolean[15]; static boolean[] col = new boolean[8]; static boolean[][] reserved = new boolean[8][8]; static void callNumberOfWays(int j){ if(j==8){ numberOfWays++; return; } for (int i = 0; i < 8; i++) { if(!ld[i + j] && !rd[i - j + 7] && !col[i] && !reserved[j][i]){ ld[i+j] = rd[i-j+7]=col[i]=true; callNumberOfWays(j+1); ld[i+j] = rd[i-j+7]=col[i]=false; } } } static int comp(String s1 , String s2){ char[] tab1 = s1.toCharArray(); char[] tab2 = s2.toCharArray(); int res =0; for (int i = 0; i < s1.length() ; i++) { res+=Math.abs(tab1[i] - tab2[i]); } return res; } static int binarySearch(ArrayList<Integer> arr, int l, int r, int x) { if (l == arr.size() )return -1; if(r<l)return l+1; if (r >= l) { int mid = l + (r - l) / 2; // If the element is present at the // middle itself if (arr.get(mid) == x) return mid+1; // If element is smaller than mid, then // it can only be present in left subarray if (arr.get(mid) > x) return binarySearch(arr, l, mid - 1, x); // Else the element can only be present // in right subarray return binarySearch(arr, mid + 1, r, x); } // We reach here when element is not present // in array return -1; } public static void main(String[] args) throws Exception { Reader s = new Reader(); BufferedReader b = new BufferedReader(new InputStreamReader(System.in)); int t =s.nextInt(); while (t-->0){ int n = s.nextInt(); int[] tab = new int[101]; for (int i = 0; i < n; i++) { tab[s.nextInt()]++; } if(tab[0]>0) System.out.println(n-tab[0]); else { boolean b1 = false; for (int i = 1; i < 101; i++) { if(tab[i]>1){b1=true;break;} } if (b1) System.out.println(n); else System.out.println(n+1); } } /* ArrayList<Integer> soo = new ArrayList<>(); for (int i = 0; i < m; i++) { soo.add(tab[i]); } Collections.sort(soo); for (int i = m-1; i >= 0; i--) { int cal = soo.get(i); int index =n-1; if(soo.get(i)>ab.get(n-1)){h.put(soo.get(i),-1);continue;}; for (int j = index; j >= 0; j--) { if(j==0){ h.put(soo.get(i), 1 ); break; } if (ab.get(j)>=soo.get(i) && ab.get(j-1)<soo.get(i) ){ h.put(soo.get(i),j); index=j; break; } } } for (int i = 0; i < m; i++) { System.out.println(h.get(tab[i])); }*/ } 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') { if (cnt != 0) { break; } else { continue; } } 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(); } } /* public static void main(String[] args) throws IOException { Reader s = new Reader(); int n = s.nextInt(); int k = s.nextInt(); int count = 0; while (n-- > 0) { int x = s.nextInt(); if (x % k == 0) count++; } System.out.println(count); }*/ }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
0597165588bfbd62c2c35034c487040f
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Solution { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); StringBuilder sb = new StringBuilder(); while (t-- > 0) { int n = Integer.parseInt(br.readLine()); String[] val = br.readLine().split(" "); HashMap<Integer, Integer> map = new HashMap<>(); int min = Integer.MAX_VALUE; int max = 0; for(int i=0;i<n;i++){ int key = Integer.parseInt(val[i]); map.put(key, map.getOrDefault(key, 0)+1); min = Math.min(min, key); max = Math.max(max, map.get(key)); } int ans; if(min==0) ans = n-map.get(min); else if(max>1) ans = n; else ans = n+1; System.out.println(ans); } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
df428326f223657325f4a83a783aa004
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; import java.lang.*; public class Solution{ static int mod=(int)1e9+7; static int mod1=998244353; static FastScanner sc = new FastScanner(); static StringBuffer ans; static long ct; public static void solve(){ int n=sc.nextInt(); int[] a=sc.readArray(n); int[] ct=new int[101]; boolean isPoss=false; for (int i:a ) { ct[i]++; if(ct[i]>1){ isPoss=true; } } if (ct[0]==n) { System.out.println("0"); return; } if (ct[0]>=1) { int ans=0; // System.out.println(n-1); for (int i=1;i<=100;i++) { ans+=ct[i]; } System.out.println(ans); }else{ if (isPoss) { System.out.println(n); }else{ System.out.println(n+1); } } } public static void main(String[] args) { // ans=new StringBuffer(""); int t = sc.nextInt(); outer: for (int tt = 0; tt < t; tt++) { solve(); } // System.out.println(ans); } static boolean isSubSequence(String str1, String str2, int m, int n) { int j = 0; for (int i = 0; i < n && j < m; i++) if (str1.charAt(j) == str2.charAt(i)) j++; return (j == m); } static int reverseDigits(int num) { int rev_num = 0; while (num > 0) { rev_num = rev_num * 10 + num % 10; num = num / 10; } return rev_num; } /* Function to check if n is Palindrome*/ static boolean isPalindrome(int n) { // get the reverse of n int rev_n = reverseDigits(n); // Check if rev_n and n are same or not. if (rev_n == n) return true; else return false; } 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 int[] LPS(String s){ int[] lps=new int[s.length()]; int i=0,j=1; while (j<s.length()) { if(s.charAt(i)==s.charAt(j)){ lps[j]=i+1; i++; j++; continue; }else{ if (i==0) { j++; continue; } i=lps[i-1]; while(s.charAt(i)!=s.charAt(j) && i!=0) { i=lps[i-1]; } if(s.charAt(i)==s.charAt(j)){ lps[j]=i+1; i++; } j++; } } return lps; } static long getPairsCount(int n, double sum,int[] arr) { HashMap<Double, Integer> hm = new HashMap<>(); for (int i = 0; i < n; i++) { if (!hm.containsKey((double)arr[i])) hm.put((double)arr[i], 0); hm.put((double)arr[i], hm.get((double)arr[i]) + 1); } long twice_count = 0; for (int i = 0; i < n; i++) { if (hm.get(sum - arr[i]) != null) twice_count += hm.get(sum - arr[i]); if (sum - (double)arr[i] == (double)arr[i]) twice_count--; } return twice_count / 2l; } static boolean[] sieveOfEratosthenes(int n) { boolean prime[] = new boolean[n + 1]; for (int i = 0; i <= n; i++) prime[i] = true; for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } prime[1]=false; return prime; } static long power(long x, long y, long p) { long res = 1l; x = x % p; if (x == 0) return 0; while (y > 0) { if ((y & 1) != 0) res = (res * x) % p; y>>=1; x = (x * x) % p; } return res; } public static int log2(int N) { int result = (int)(Math.log(N) / Math.log(2)); return result; } //////////////////////////////////////////////////////////////////////////////////// ////////////////////DO NOT READ AFTER THIS LINE ////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////// static long modFact(int n, int p) { if (n >= p) return 0; long result = 1l; for (int i = 2; i <= n; i++) result = (result * i) % p; return result; } static boolean isPalindrom(char[] arr, int i, int j) { boolean ok = true; while (i <= j) { if (arr[i] != arr[j]) { ok = false; break; } i++; j--; } return ok; } static int max(int a, int b) { return Math.max(a, b); } static int min(int a, int b) { return Math.min(a, b); } static long max(long a, long b) { return Math.max(a, b); } static long min(long a, long b) { return Math.min(a, b); } static int abs(int a) { return Math.abs(a); } static long abs(long a) { return Math.abs(a); } static void swap(long arr[], int i, int j) { long temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } static void swap(int arr[], int i, int j) { int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } static int maxArr(int arr[]) { int maxi = Integer.MIN_VALUE; for (int x : arr) maxi = max(maxi, x); return maxi; } static int minArr(int arr[]) { int mini = Integer.MAX_VALUE; for (int x : arr) mini = min(mini, x); return mini; } static long maxArr(long arr[]) { long maxi = Long.MIN_VALUE; for (long x : arr) maxi = max(maxi, x); return maxi; } static long minArr(long arr[]) { long mini = Long.MAX_VALUE; for (long x : arr) mini = min(mini, x); return mini; } static int lcm(int a,int b){ return (int)(((long)a*b)/(long)gcd(a,b)); } static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static void ruffleSort(int[] a) { int n = a.length; Random r = new Random(); for (int i = 0; i < a.length; i++) { int oi = r.nextInt(n); int temp = a[i]; a[i] = a[oi]; a[oi] = temp; } Arrays.sort(a); } public static int binarySearch(int a[], int target) { int left = 0; int right = a.length - 1; int mid = (left + right) / 2; int i = 0; while (left <= right) { if (a[mid] <= target) { i = mid + 1; left = mid + 1; } else { right = mid - 1; } mid = (left + right) / 2; } return i-1; } 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[] readLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } int[][] read2dArray(int n, int m) { int arr[][] = new int[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { arr[i][j] = nextInt(); } } return arr; } ArrayList<Integer> readArrayList(int n) { ArrayList<Integer> arr = new ArrayList<Integer>(); for (int i = 0; i < n; i++) { int a = nextInt(); arr.add(a); } return arr; } long nextLong() { return Long.parseLong(next()); } } static class Pair { int val; long coins; Pair(int val,long coins) { this.val=val; this.coins=coins; } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
444026eea2ee40c1d95fc844aaea5407
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
/* "Everything in the universe is balanced. Every disappointment you face in life will be balanced by something good for you! Keep going, never give up." Just have Patience + 1... */ import java.util.*; import java.lang.*; import java.io.*; public class Solution { public static void main(String[] args) throws java.lang.Exception { out = new PrintWriter(new BufferedOutputStream(System.out)); sc = new FastReader(); int test = sc.nextInt(); for (int t = 1; t <= test; t++) { solve(); } out.close(); } private static void solve() { int n = sc.nextInt(); int[] arr = new int[n]; boolean zero = false; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); if (arr[i] == 0) { zero = true; } } if (zero) { int operations = 0; for (int i = 0; i < n; i++) { if (arr[i] != 0) { operations++; } } out.println(operations); return; } for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (arr[i] == arr[j]) { int operations = 1; for (int k = 0; k < n; k++) { if (k != i && arr[i] != 0) { operations++; } } out.println(operations); return; } } } out.println(n + 1); } public static FastReader sc; public static PrintWriter out; static class FastReader { BufferedReader br; StringTokenizer str; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (str == null || !str.hasMoreElements()) { try { str = new StringTokenizer(br.readLine()); } catch (IOException lastMonthOfVacation) { lastMonthOfVacation.printStackTrace(); } } return str.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 lastMonthOfVacation) { lastMonthOfVacation.printStackTrace(); } return str; } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
8e1b0efc5c67922516ff20726e09b514
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.*; public class Solution { static Scanner sc = new Scanner(System.in); public static void solver() { int n = sc.nextInt(); int[] arr =new int[101]; boolean hasDuplicate = false; int zeros = 0; for(int i =0; i < n; i++){ int a = sc.nextInt(); arr[a] = arr[a]+1; if(a == 0)zeros++; if(arr[a] >= 2)hasDuplicate = true; } if(zeros > 0) System.out.println(n-zeros); else if(hasDuplicate) System.out.println(n); else System.out.println(n+1); } public static void main(String[] args) { int t = sc.nextInt(); while (t-- > 0) { solver(); } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
df13b1425ddf245998f7928a41981eb1
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class Main { public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t > 0){ t--; int n = sc.nextInt(); boolean zero = false; int zeroCount = 0; boolean duplicatePresent = false; int[] sequence = new int[n]; for(int i=0;i<n;i++){ sequence[i] = sc.nextInt(); if(sequence[i]==0){ zero=true; zeroCount++; } } Arrays.sort(sequence); if(zero){ System.out.println(n-zeroCount); } else{ for(int i=1;i<n;i++){ if(sequence[i]==sequence[i-1]){ duplicatePresent=true; } } if(duplicatePresent){ System.out.println(n); } else{ System.out.println(n+1); } } } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
4090e2a5eb125b83f9ffbc6a2f759a4d
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
/* AUTHOR-> HARSHIT AGGARWAL CODEFORCES HANDLE-> @harshit_agg FROM-> MAHARAJA AGRASEN INSTITUE OF TECHNOLOGY >> YOU CAN DO THIS << */ import java.util.*; import java.io.*; public class zerosequenceA { public static void main(String[] args) throws Exception { int t = scn.nextInt(); while (t-- > 0) { solver(); } } public static void solver() { int n = scn.nextInt(); int[] arr = nextIntArray(n); int[] freq = new int[101]; Arrays.fill(freq, 0); for(int i = 0; i < arr.length; i++){ freq[arr[i]]++; } int ans = 0; boolean pairfound = false; for(int i = 1; i < 101; i++){ if(freq[i] > 1){ pairfound = true; break; } } ans += arr.length-freq[0]; if(freq[0] == 0 && pairfound == true){ System.out.println(n); return; }else if(freq[0] == 0 && pairfound == false){ System.out.println(n+1); return; } System.out.println(ans); } //-------------------------------- HO JA BHAI ---------------------------------------------------- /* code ends here*/ //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx U T I L I T I E S xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx public static class Debug { public static final boolean LOCAL = System.getProperty("LOCAL")==null; private static <T> String ts(T t) { if(t==null) { return "null"; } try { return ts((Iterable) t); }catch(ClassCastException e) { if(t instanceof int[]) { String s = Arrays.toString((int[]) t); return "{"+s.substring(1, s.length()-1)+"}"; }else if(t instanceof long[]) { String s = Arrays.toString((long[]) t); return "{"+s.substring(1, s.length()-1)+"}"; }else if(t instanceof char[]) { String s = Arrays.toString((char[]) t); return "{"+s.substring(1, s.length()-1)+"}"; }else if(t instanceof double[]) { String s = Arrays.toString((double[]) t); return "{"+s.substring(1, s.length()-1)+"}"; }else if(t instanceof boolean[]) { String s = Arrays.toString((boolean[]) t); return "{"+s.substring(1, s.length()-1)+"}"; } try { return ts((Object[]) t); }catch(ClassCastException e1) { return t.toString(); } } } private static <T> String ts(T[] arr) { StringBuilder ret = new StringBuilder(); ret.append("{"); boolean first = true; for(T t: arr) { if(!first) { ret.append(", "); } first = false; ret.append(ts(t)); } ret.append("}"); return ret.toString(); } private static <T> String ts(Iterable<T> iter) { StringBuilder ret = new StringBuilder(); ret.append("{"); boolean first = true; for(T t: iter) { if(!first) { ret.append(", "); } first = false; ret.append(ts(t)); } ret.append("}"); return ret.toString(); } public static void dbg(Object... o) { if(LOCAL) { System.err.print("Line #"+Thread.currentThread().getStackTrace()[2].getLineNumber()+": ["); for(int i = 0; i<o.length; i++) { if(i!=0) { System.err.print(", "); } System.err.print(ts(o[i])); } System.err.println("]"); } } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { try { br = new BufferedReader(new FileReader("input.txt")); PrintStream out = new PrintStream(new FileOutputStream("output.txt")); System.setOut(out); } catch (Exception e) { 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; } } static int INF = (int) 1e9 + 7; // static int INF = 998244353; static int MAX = Integer.MAX_VALUE; // static int MAX = 2147483647 static int MIN = Integer.MIN_VALUE; // static int MIN = -2147483647 static class Pair implements Comparable<Pair> { int first, second; public Pair(int first, int second) { this.first = first; this.second = second; } public int compareTo(Pair o) { return this.first- o.first; } } static class LongPair { long first; long second; LongPair(long a, long b) { this.first = a; this.second = b; } } public static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } public static int LowerBound(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) r = m; else l = m; } return r; } public static int LowerBound(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) r = m; else l = m; } return r; } static int LowerBoundList(ArrayList<Integer> a, int x) { /* x is the key or target value */int l = -1, r = a.size(); while (l + 1 < r) { int m = (l + r) >>> 1; if (a.get(m) >= x) r = m; else l = m; } return r; } static boolean[] prime; public static void sieveOfEratosthenes(int n) { prime = new boolean[n + 1]; for (int i = 0; i < n; i++) prime[i] = true; for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } } public 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; } public 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; } public static long lcm(long a, long b) { return (a * b) / gcd(a, b); } public static void swap(int[] arr, int i, int j) { if (i != j) { arr[i] ^= arr[j]; arr[j] ^= arr[i]; arr[i] ^= arr[j]; } } public static long[] nextLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = scn.nextLong(); return a; } public static int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = scn.nextInt(); } return a; } public int[][] nextIntMatrix(int n, int m) { int[][] grid = new int[n][m]; for (int i = 0; i < n; i++) { grid[i] = nextIntArray(m); } return grid; } public static int smallest_divisor(int n) { int i; for (i = 2; i <= Math.sqrt(n); ++i) { if (n % i == 0) { return i; } } return n; } public static FastReader scn = new FastReader(); //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
a98e7de553382fb572328f94bb7398e6
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.*; import java.io.*; public class Practice { static boolean multipleTC = true; final static int mod2 = 1000000007; final static int mod = 998244353; final double E = 2.7182818284590452354; final double PI = 3.14159265358979323846; int MAX = 1005; void pre() throws Exception { } // All the best void solve(int TC) throws Exception { int n = ni(), arr[] = readArr(n); HashMap<Integer, Integer> mp = new HashMap<>(); boolean isZero = false; int count = 0; for (int i : arr) { if (i == 0) isZero = true; else count++; mp.put(i, mp.getOrDefault(i, 0) + 1); } if (isZero) { pn(count); } else { int ans =0; for (var e : mp.entrySet()) { ans += e.getValue() - 1; } if(ans ==0) { pn(n+1); }else { pn(n); } } } boolean isSorted(int arr[]) { for (int i = 0; i < arr.length - 1; i++) { if (arr[i] > arr[i + 1]) { return false; } } return true; } public long pow(long base, long exp) { long res = 1; while (exp > 0) { if ((exp & 1) == 1) res = res * base; base = base * base; exp >>= 1; } return res; } public static long gcd(long a, long b) { if (a > b) a = (a + b) - (b = a); if (a == 0L) return b; return gcd(b % a, a); } double dist(int x1, int y1, int x2, int y2) { double a = x1 - x2, b = y1 - y2; return Math.sqrt((a * a) + (b * b)); } int[] readArr(int n) throws Exception { int arr[] = new int[n]; for (int i = 0; i < n; i++) { arr[i] = ni(); } return arr; } void sort(int arr[], int left, int right) { ArrayList<Integer> list = new ArrayList<>(); for (int i = left; i <= right; i++) list.add(arr[i]); Collections.sort(list); for (int i = left; i <= right; i++) arr[i] = list.get(i - left); } void sort(int arr[]) { ArrayList<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); } public long max(long... arr) { long max = arr[0]; for (long itr : arr) max = Math.max(max, itr); return max; } public int max(int... arr) { int max = arr[0]; for (int itr : arr) max = Math.max(max, itr); return max; } public long min(long... arr) { long min = arr[0]; for (long itr : arr) min = Math.min(min, itr); return min; } public int min(int... arr) { int min = arr[0]; for (int itr : arr) min = Math.min(min, itr); return min; } public long sum(long... arr) { long sum = 0; for (long itr : arr) sum += itr; return sum; } public long sum(int... arr) { long sum = 0; for (int itr : arr) sum += itr; return sum; } String bin(long n) { return Long.toBinaryString(n); } String bin(int n) { return Integer.toBinaryString(n); } static int bitCount(int x) { return x == 0 ? 0 : (1 + bitCount(x & (x - 1))); } static void dbg(Object... o) { System.err.println(Arrays.deepToString(o)); } int bit(long n) { return (n == 0) ? 0 : (1 + bit(n & (n - 1))); } int abs(int a) { return (a < 0) ? -a : a; } long abs(long a) { return (a < 0) ? -a : a; } void p(Object o) { out.print(o); } void pn(Object o) { out.println(o); } void pni(Object o) { out.println(o); out.flush(); } void pn(int[] arr) { int n = arr.length; StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { sb.append(arr[i] + " "); } pn(sb); } void pn(long[] arr) { int n = arr.length; StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { sb.append(arr[i] + " "); } pn(sb); } String n() throws Exception { return in.next(); } String nln() throws Exception { return in.nextLine(); } int ni() throws Exception { return Integer.parseInt(in.next()); } long nl() throws Exception { return Long.parseLong(in.next()); } double nd() throws Exception { return Double.parseDouble(in.next()); } public static void main(String[] args) throws Exception { new Practice().run(); } FastReader in; PrintWriter out; void run() throws Exception { in = new FastReader(); out = new PrintWriter(System.out); int T = (multipleTC) ? ni() : 1; pre(); for (int t = 1; t <= T; t++) solve(t); out.flush(); out.close(); } class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } public FastReader(String s) throws Exception { br = new BufferedReader(new FileReader(s)); } String next() throws Exception { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { throw new Exception(e.toString()); } } return st.nextToken(); } String nextLine() throws Exception { String str = ""; try { str = br.readLine(); } catch (IOException e) { throw new Exception(e.toString()); } return str; } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
736488e1ad059d5332c28fc1e463bfe0
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.io.IOException; import java.util.HashMap; import java.util.Scanner; public class codeforces1678A { public static void main(String[] args) throws IOException { Scanner in = new Scanner(System.in); int t = in.nextInt(); for (int j = 0;j < t; j++) { int n = in.nextInt(); int arr[] = new int[n]; HashMap<Integer, Boolean> map = new HashMap<>(); int zeros = 0; for (int i = 0; i < n; i++) { arr[i] = in.nextInt(); if (arr[i] == 0) zeros++; map.put(arr[i], true); } if (zeros != 0) System.out.println(n - zeros); else if (map.size() != n) System.out.println(n); else System.out.println(n + 1); } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
ebc2884f7a8cca2edba6c8caa9405223
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Main { 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 a, b; Pair(int a, int b) { this.a = a; this.b = b; } public int compareTo(Pair o) { return this.a - o.a; } } public static void main (String[] args) throws java.lang.Exception { // your code goes here // InputStreamReader r = new InputStreamReader(System.in); // BufferedReader br = new BufferedReader(r); FastReader scn = new FastReader(); BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out)); int t = scn.nextInt(); while (t-- > 0) { int n = scn.nextInt(); int[] arr = new int[n]; int same = 0; int count = 0; int sum = 0; HashSet<Integer> set = new HashSet<>(); for(int i=0; i<n; i++){ arr[i] = scn.nextInt(); if(arr[i] == 0){ count++; }else if(set.size()> 0 && set.contains(arr[i])){ same++; } sum += arr[i]; set.add(arr[i]); } int ans = 0; if(sum == 0){ ans = 0; }else if(count > 0){ ans = n - count; }else if(same > 0){ ans = n; }else{ ans = n+1; } output.write(ans+"\n"); output.flush(); } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
e31f4ec1283c6315814558ae0b05f5ae
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Main { public static void main(String[] args) { FastScanner in = new FastScanner(); int t = in.nextInt(); while (t > 0) { int n = in.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = in.nextInt(); } solve(n, arr); t--; } } 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()); } } static void solve(int n, int[] a) { Map<Integer, Integer> mp = new HashMap<Integer, Integer>(); for (int i = 0; i < n; i++) { if (mp.containsKey(a[i])) { mp.put(a[i], mp.get(a[i]) + 1); } else mp.put(a[i], 1); } if (!mp.containsKey(0) && mp.size() == n) { System.out.println(n + 1); } else { if (mp.get(0) == null) System.out.println(n); else System.out.println(n - mp.get(0)); } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
926e5cc977583d70b743a2ef2a7976a2
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); while (t > 0) { int n = in.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = in.nextInt(); } solve(n, arr); t--; } } 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()); } } static void solve(int n, int[] a) { Map<Integer, Integer> mp = new HashMap<Integer, Integer>(); for (int i = 0; i < n; i++) { if (mp.containsKey(a[i])) { mp.put(a[i], mp.get(a[i]) + 1); } else mp.put(a[i], 1); } if (!mp.containsKey(0) && mp.size() == n) { System.out.println(n + 1); } else { if (mp.get(0) == null) System.out.println(n); else System.out.println(n - mp.get(0)); } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
bf1050b8e3057a28f2011f92ba38cb9e
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.io.*; import java.util.*; public class Main { InputStream is; PrintWriter out = new PrintWriter(System.out); ; String INPUT = ""; void run() throws Exception { is = System.in; solve(); out.flush(); out.close(); } public static void main(String[] args) throws Exception { new Main().run(); } public byte[] inbuf = new byte[1024]; public int lenbuf = 0, ptrbuf = 0; public 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++]; } public boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } public int skip() { // continue; String; charAt; println(); ArrayList; Integer; Long; // long; Queue; Deque; LinkedList; Pair; double; binarySearch; // s.toCharArray; length(); length; getOrDefault; break; // Map.Entry<Integer, Integer> e; HashMap; TreeMap; int b; while ((b = readByte()) != -1 && isSpaceChar(b)) ; return b; } public double nd() { return Double.parseDouble(ns()); } public char nc() { return (char) skip(); } private String ns() { int b = skip(); StringBuilder sb = new StringBuilder(); while (!(isSpaceChar(b))) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } private int ni() { return (int) nl(); } private 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(); } } class Pair { int first; int second; Pair(int a, int b) { first = a; second = b; } } int[] na(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = ni(); return arr; } long[] nal(int n) { long[] arr = new long[n]; for (int i = 0; i < n; i++) arr[i] = nl(); return arr; } void solve() { int test_case = ni(); while (test_case-- > 0) { int n = ni(); int[] arr = na(n); Arrays.sort(arr); int countZero = 0; int countNonZero = 0; for(int i=0; i<n; i++) { if(arr[i] == 0) { countZero++; } else { countNonZero++; } } if(countZero > 0) { out.println(countNonZero); } else { int min = Integer.MAX_VALUE; for(int i=0; i<n-1; i++) { int diff = arr[i+1] - arr[i]; min = Math.min(min, diff); } if(min == 0) out.println(countNonZero); else out.println(countNonZero + 1); } } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
dae8e3b5304753fc8b1d55395c0e13e7
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
// package div_2_789; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class A{ public static void main(String[] args){ FastReader sc = new FastReader(); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); int a[]=sc.fastArray(n); sort(a); int cnt=0; for(int i:a)if(i==0)cnt++; if(cnt!=0) { System.out.println(n-cnt); }else { boolean hasdup=false; for(int i=1;i<n;i++) { if(a[i]==a[i-1]) { hasdup=true; break; } } if(hasdup)System.out.println(n); else System.out.println(n+1); } } } static int pow(int a,int b) { if(b==0)return 1; if(b==1)return a; return a*pow(a,b-1); } static void sort(int a[]) { ArrayList<Integer> aa= new ArrayList<>(); for(int i:a)aa.add(i); Collections.sort(aa); int j=0; for(int i:aa)a[j++]=i; } static class pair { int x;int y; pair(int x,int y){ this.x=x; this.y=y; } } static ArrayList<Integer> primeFac(int n){ ArrayList<Integer>ans = new ArrayList<Integer>(); int lp[]=new int [n+1]; Arrays.fill(lp, 0); //0-prime for(int i=2;i<=n;i++) { if(lp[i]==0) { for(int j=i;j<=n;j+=i) { if(lp[j]==0) lp[j]=i; } } } int fac=n; while(fac>1) { ans.add(lp[fac]); fac=fac/lp[fac]; } print(ans); return ans; } static ArrayList<Long> prime_in_given_range(long l,long r){ ArrayList<Long> ans= new ArrayList<>(); int n=(int)Math.sqrt(r)+1; int prime[]=sieve_of_Eratosthenes(n); long res[]=new long [(int)(r-l)+1]; for(int i=0;i<=r-l;i++) { res[i]=i+l; } for(int i=0;i<prime.length;i++) { if(prime[i]==1) { System.out.println(2); for(int j=Math.max((int)i*i, (int)(l+i-1)/i*i);j<=r;j+=i) { res[j-(int)l]=0; } } } for(long i:res) if(i!=0)ans.add(i); return ans; } static int [] sieve_of_Eratosthenes(int n) { int prime[]=new int [n]; Arrays.fill(prime, 1); // 1-prime | 0-not prime prime[0]=prime[1]=0; for(int i=2;i<n;i++) { if(prime[i]==1) { for(int j=i*i;j<n;j+=i) { prime[j]=0; } } } return prime; } static long binpow(long a,long b) { long res=1; if(b==0)return 1; if(a==0)return 0; while(b>0) { if((b&1)==1) { res*=a; } a*=a; b>>=1; } return res; } static void print(int a[]) { System.out.println(a.length); for(int i:a) { System.out.print(i+" "); } System.out.println(); } static void print(long a[]) { System.out.println(a.length); for(long i:a) { System.out.print(i+" "); } System.out.println(); } static long rolling_hashcode(String s ,int st,int end,long Hashcode,int n) { if(end>=s.length()) return -1; int mod=1000000007; Hashcode=Hashcode-(s.charAt(st-1)*(long)Math.pow(27,n-1)); Hashcode*=10; Hashcode=(Hashcode+(long)s.charAt(end))%mod; return Hashcode; } static long hashcode(String s,int n) { long code=0; for(int i=0;i<n;i++) { code+=((long)s.charAt(i)*(long)Math.pow(27, n-i-1)%1000000007); } return code; } static void print(ArrayList<Integer> a) { System.out.println(a.size()); for(long i:a) { System.out.print(i+" "); } System.out.println(); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } int [] fastArray(int n) { int a[]=new int [n]; for(int i=0;i<n;i++) { a[i]=nextInt(); } return a; } 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
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
4cd473ef6a2fda35b64eaafe9bca234b
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.*; public class Rough { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int t =sc.nextInt() ; while(t > 0) { int size = sc.nextInt() ; int [] arr = new int[size]; for(int i = 0 ; i < size ; i++) { arr[i] = sc.nextInt() ; } Arrays.sort(arr); boolean zero =false ; for(int i : arr) { if(i == 0) { zero = true ; } } int countzeroes = 0 ; for(int i : arr) { if(i == 0) { countzeroes++ ; } } boolean eqpair = false ; for(int i = 1 ; i < size ; i++) { if(arr[i-1] == arr[i]) { eqpair = true ; } } if(zero) { System.out.println(arr.length - countzeroes); }else if(eqpair) { System.out.println(arr.length); }else { System.out.println(arr.length+1); } t-- ; } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
341430b9006fd8648369de38c40a0718
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.io.*; import java.util.*; public class JavaApplication { static BufferedReader in; static StringTokenizer st; public String getLine() throws IOException { return in.readLine(); } public String getToken() throws IOException { if (st == null || !st.hasMoreTokens()) st = new StringTokenizer(getLine()); return st.nextToken(); } public int getInt() throws IOException { return Integer.parseInt(getToken()); } public long getLong() throws IOException { return Long.parseLong(getToken()); } public void Solve() throws IOException { int t = getInt(); while (t-- > 0) { int n = getInt(); int a[] = new int[n]; boolean isZero = false; boolean isEquals = false; int numberOfZeros = 0; for (int i = 0; i < n; i++) { a[i] = getInt(); if (a[i] == 0) { isZero = true; numberOfZeros++; } } if (isZero) { System.out.println(n - numberOfZeros); continue; } for (int i = 0; i < n - 1; i++) { for (int j = 0; j < n; j++) { if (i != j && a[i] == a[j]) { isEquals = true; break; } } if (isEquals) break; } System.out.println(isEquals ? n : n + 1); } } public static void main(String[] args) throws java.lang.Exception { in = new BufferedReader(new InputStreamReader(System.in)); new JavaApplication().Solve(); return; } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
57efa896d371141e01bae9bdc126b00f
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.*;import java.io.*; public class k{ // static boolean f(int []a){ // int n=a.length; // ArrayList<Integer> x=new ArrayList<>(); // ArrayList<Integer> y=new ArrayList<>(); // if(n==1 || n==2)return true; // if(a[n-1]>=a[n-2]){y.add(a[n-1]);x.add(a[n-2]);} // else{x.add(a[n-1]);y.add(a[n-2]);} // i=n-3; // while(i>=0){ // if(x.size()==y.size()){ // if(a[i]>=x.get(x.size()-1) && a[i]<=y.get(y.size()-1)){ // y.add(a[i]); // } // else // return false; // } // else{ // } // } // } // static long g(long []a,long sum){ // long l=0,h=sum,ans=0,max=sum; // while(l<=h){ // long m=l+(h-l)/2; // if(m%2!=0){ // if((m/2)*2+(m/2)+1>=max){ // ans=m; // h=m-1; // } // else { // l=m+1; // } // } // else { // if((m/2)*2+m/2>=max){ // ans=m; // h=m-1; // } // else // l=m+1; // } // } // return ans; // } public static void main(String ...asada)throws IOException{ // String s=sc.nextLine(); // int g=0,b=0,n=s.length(); // for(int i=0;i<n;i++){ // char ch=s.charAt(i); // if(ch=='G') // g++; // else // b++; // } // char temp; // int l=0; // if(g==b) // l=1; // if(g>=b) // temp='G'; // else // temp='B'; // int c=0; // for(int i=0;i<n;i++){ // char ch=s.charAt(i); // if(ch!=temp) // c++; // if(temp=='G') // temp='B'; // else // temp='G'; // } // if(l!=1) // System.out.print(c/2); // else // System.out.print(Math.min(n-c,c)/2); BufferedReader br =new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw =new BufferedWriter(new OutputStreamWriter(System.out)); // int t=Integer.parseInt(br.readLine()); // while(t-->0){ // int n=Integer.parseInt(br.readLine()); // long []a=new long[n]; // String []c=br.readLine().split(" "); // long sum=0,max=0; // for(int i=0;i<n;i++){ // a[i]=Long.parseLong(c[i]); // if(max<a[i]) // max=a[i]; // } // for(long i:a) // sum+=max-i; // bw.write(g(a,sum)+"\n"); // bw.flush(); // } // while(t-->0){ // int n=Integer.parseInt(br.readLine()); // String s=br.readLine(); // int i=1,c=0; // while(i<n){ // if(c==2 && s.charAt(i)==s.charAt(i-1)){ // i++; // } // else if(s.charAt(i)<s.charAt(i-1)){ // i++; // c=2; // } // else // break; // } // StringBuilder b=new StringBuilder(s.substring(0,i)); // b.reverse(); // bw.write(s.substring(0,i)+b+"\n"); // } //while(t-->0){ // String s=br.readLine(); // int n=s.length(); // Map<Character,Integer> m=new HashMap<>(); // int []a=new int[26];int c=0; // for(int i=0;i<n;i++){ // if(a[s.charAt(i)-'a']==0)c++; // a[s.charAt(i)-'a']++; // m.put(s.charAt(i),1); // } // boolean f=true; // int i=0; // while(i<n){ // if(a[s.charAt(i)-'a']>1){ // int j=i+1;int k=c; // Map<Character,Integer> mp=new HashMap<>(m); // while(j<n){ // if(s.charAt(j)==s.charAt(i)) // break; // else{ // if(mp.get(s.charAt(j))==1) // k--; // mp.put(s.charAt(j),0); // } // j++; // } // a[s.charAt(i)-'a']--; // if(k!=1) // { // f=false;break; // } // } // i++; // } // if(f) // bw.write("YES\n"); // else // bw.write("NO\n"); // int n=Integer.parseInt(br.readLine()); // String []s=br.readLine().split(" "); // int []a=new int[n]; // int m=Integer.parseInt(br.readLine()); // String []st=br.readLine().split(" "); // int []b=new int[m]; // long x=0,y=0;boolean f=true; // for(int i=0;i<n;i++){ // a[i]=Integer.parseInt(s[i]);x+=a[i]; // } // for(int i=0;i<m;i++){ // b[i]=Integer.parseInt(st[i]);y+=b[i]; // } // if(x!=y){ // bw.write(-1+"\n");f=false; // } // int i=0,j=0,s1=0,s2=0,c=0; // while(i<n && j<m){ // if(a[i]==b[j]){ // i++;j++;s1=0;s2=0;c++; // } // else if(a[i]!=b[j]){ // s1=a[i];s2=b[j];i++;j++; // while(i<n && j<m){ // if(s1==s2){ // s1=0;s2=0; // break; // } // else if(s1<s2){ // s1+=a[i];i++; // } // else // { // s2+=b[j];j++; // } // } // c++; // } // } // if(f){ // bw.write(c+"\n"); // } // if(n==1){ // bw.write("YES\n");continue; // } // for(int i=1;i<n;i++){ // if(a[i]-a[i-1]==3 && l==1){ // a[i]=a[i]-1;l=0; // } // else if(a[i]-a[i-1]>2){ // // bw.write(Arrays.toString(a)+"\n"); // f=false;break; // } // else if(a[i]-a[i-1]==2){ // a[i]=a[i]-1; // } // else if(l!=0) // l=1; // // bw.write(i+" "+f+" "+l+"\n"); // } // if(f) // bw.write("YES\n"); // else // bw.write("NO\n"); // } int t=Integer.parseInt(br.readLine()); while(t-->0){ int n=Integer.parseInt(br.readLine()); String []sp=br.readLine().split(" "); int []a=new int[n]; Set<Integer> s=new HashSet<Integer> (); boolean f=false; for(int i=0;i<n;i++){ a[i]=Integer.parseInt(sp[i]); if(s.contains(a[i])) f=true; s.add(a[i]); } int i=0; Arrays.sort(a); while(i<n && a[i]==0){ i++; } if(a[0]==0) bw.write(n-i+"\n"); else if(f) bw.write(n-i+"\n"); else bw.write(n+1-i+"\n"); } bw.flush(); } // while(t-->0){ // int n=Integer.parseInt(br.readLine()); // String []s=br.readLine().split(" "); // long []a=new long[n]; // for(int i=0;i<n;i++) // a[i]=Long.parseLong(s[i]); // boolean f=false,m=false; // int i=n-2;long c=a[n-1],ans=0; // while(i>=0){ // while(a[i]>=a[i+1]){ // if(a[i]==0 && f){ // m=true;break; // } // a[i]=a[i]/2;ans++; // if(a[i]==0) // f=true; // } // if(m)break; // i--; // } // if(m)bw.write(-1+"\n"); // else // bw.write(ans+"\n"); // } // while(t-->0){ // String []s=br.readLine().split(" "); // long a=Long.parseLong(s[0]); // long b=Long.parseLong(s[1]); // long c=Long.parseLong(s[2]); // long x=Long.parseLong(s[3]); // long y=Long.parseLong(s[4]); // if(a<x){ // if(a+c>=x) // c-=x-a; // else{ // bw.write("NO\n"); // continue; // } // } // if(b<y){ // if(b+c>=y) // c-=y-b; // else{ // bw.write("NO\n"); // continue; // } // } // bw.write("YES\n"); // int n=Integer.parseInt(br.readLine()); // String []s=br.readLine().split(" "); // int []a=new int[n]; // for(int i=0;i<n;i++) // a[i]=Integer.parseInt(s[i]); // if(f(a)) // bw.write("yes\n"); // else // bw.write("no\n"); // String s=br.readLine(); // int i=s.charAt(0)-'a'; // if(s.charAt(0)<=s.charAt(1)) // bw.write(25*i+s.charAt(1)-'a'+"\n"); // else // bw.write(25*i+s.charAt(1)-'a'+1+"\n"); // String []s=br.readLine().split(" "); // int a=Integer.parseInt(s[0]); // int b=Integer.parseInt(s[1]); // if(a<=b && b%a==0) // bw.write(1+" "+b/a+"\n"); // else // bw.write(0+" "+0+"\n"); // int n=Integer.parseInt(br.readLine()); // long []a=new long[n]; // String []s=br.readLine().split(" "); // boolean f=true; // for(int i=0;i<n;i++){ // a[i]=Integer.parseInt(s[i]); // if(i!=0 && a[i]<a[i-1])f=false; // } // if (a[n - 1] < 0) { // if (f) { // bw.write(0+"\n"); // } else { // bw.write(-1+"\n"); // } // } // else{ // bw.write(n-2+"\n"); // for(int i=0;i<n-2;i++) // bw.write((i+1)+" "+(n-1)+" "+n+"\n"); // } // } // } } // static int f(String s,int []last,int []dp){ // int n=s.length(); // last[s.charAt(0)-'a']=0; // for(int i=1;i<n;i++){ // if(last[s.charAt(i)-'a']==-1){ // dp[i]=dp[i-1]; // } // else { // if(last[s.charAt(i)-'a']!=0) // dp[i]=Math.max(dp[i-1],2+dp[last[s.charAt(i)-'a']-1]); // else // dp[i]=Math.max(dp[i-1],2); // } // last[s.charAt(i)-'a']=i; // } // return dp[s.length()-1]; // }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
1ac47816b0cc47e3c10782d08588ac92
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
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; int N, arr[]; void init(){ N = ni(); arr = new int[N + 1]; for(int i = 1; i <= N; i++){ arr[i] = ni(); } } void process(int testNumber){ init(); for(int i = 1; i <= N; i++){ if(arr[i] == 0){ int count = 0; for(int j = 1; j <= N; j++){ if(arr[j] != 0){ count += 1; } } pn(count); return; } } for(int i = 1; i < N; i++){ for(int j = i + 1; j <= N; j++){ if(arr[i] == arr[j]){ pn(N); return; } } } pn(N + 1); } 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
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
45939031e32f22d8ec77858dc29e381f
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.io.*; import java.util.*; import java.lang.*; public class Codeforces { public static void main(String[] args) { Scanner input= new Scanner(System.in); int t=input.nextInt(); while(t-->0){ int n=input.nextInt(); int[] ar=new int[n]; boolean ok=false; int zeros=0; int equals=0; for(int i=0;i<n;i++) { ar[i]=input.nextInt(); if(ar[i]==0){ ok=true;zeros++;} } boolean ok1=false; Arrays.sort(ar); for(int i=1;i<n;i++) { if(ar[i]==ar[i-1]) { ok1=true; } } if(ok==true) { System.out.println(n-zeros); } else if(ok1==true) { System.out.println(n); } else { System.out.println(n+1); } } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
b8bbcf191096cc2f9d00e6fdfdc242ac
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.*; import java.math.*; import java.io.*; public class Main { static ArrayList<Integer> prime = new ArrayList<>(); static long mod = 1000000007; static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine().trim(); } catch (Exception e) { e.printStackTrace(); } return str; } } static class FastWriter { private final BufferedWriter bw; public FastWriter() { this.bw = new BufferedWriter(new OutputStreamWriter(System.out)); } public void print(Object object) throws IOException { bw.append("" + object); } public void println(Object object) throws IOException { print(object); bw.append("\n"); } public void close() throws IOException { bw.close(); } } public static void main(String[] args) { try { FastReader in = new FastReader(); FastWriter out = new FastWriter(); int testCases = in.nextInt(); while ( testCases-- > 0 ) { int n = in.nextInt(); int zero = 0; boolean bool = false; HashSet<Integer> hs = new HashSet<>(); for ( int i = 0; i < n; ++i ) { int x = in.nextInt(); if ( x == 0 ) zero++; if ( hs.contains(x) ) bool = true; hs.add(x); } long ans = 0; if ( zero >= 1 ) { ans = n - zero; } else { if ( bool ) { ans += 2; } else { ans += 3; } ans += n - 2; } out.println(ans); } out.close(); } catch (Exception e) { return; } } public static long pow( long k , long n ) { long ans = 1; while ( n > 0 ) { if ( n % 2 == 1 ) { ans += (ans * k) % mod; n--; } else { k = (k * k) % mod; n /= 2; } } return ans % mod; } public static long fact(long n ) { long ans = 0; for (int i = 1; i < n; ++i) { ans += (long)i; } return ans; } public static boolean isValid( long mid, long arr[] , long k ) { long req = 0; for ( int i = 1; i < arr.length; ++i) { req += Math.min( (arr[i] - arr[i - 1] ) , mid ); } req += mid; if ( req >= k ) return true; return false; } public static String sortString(String inputString) { char tempArray[] = inputString.toCharArray(); Arrays.sort(tempArray); return new String(tempArray); } private static void reverse( ArrayList<Long> arr , int i, int j ) { while ( i <= j ) { swap( arr, i, j); i++; j--; } } private static void swap( ArrayList<Long> arr , int i, int j ) { long temp = arr.get(i); arr.set(i, arr.get(j)); arr.set(j, temp); } private static boolean isPrime(long n ) { if ( n == 1 ) return true; for ( int i = 2; i <= Math.sqrt(n); i++) { if ( n % i == 0 ) { return false ; } } return true; } private static boolean[] sieve() { int n = 100000000; boolean sieve[] = new boolean[n + 1]; Arrays.fill(sieve, true); for ( int i = 2; i * i <= n; i++) { for ( int j = i * i; j <= n; j += i) { sieve[j] = false; } } return sieve; } private static ArrayList<Integer> generatePrimes(int n ) { boolean sieve[] = sieve(); for ( int i = 2; i <= n; i++) { if ( sieve[i] == true ) { prime.add(i); } } return prime; } private static void segmentedSieve( int l , int r ) { int n = (int) Math.sqrt(r); ArrayList<Integer> pr = generatePrimes(n); int dummy[] = new int[r - l + 1]; Arrays.fill(dummy, 1); for ( int p : pr ) { int firstMultiple = (l / p) * p; if ( firstMultiple < l ) firstMultiple += p; for ( int j = Math.max(firstMultiple, p * p); j <= r; j += p) { dummy[j - l] = 0; } } for ( int i = l; i <= r; i++) { if ( dummy[i - l] == 1 ) { System.out.println(i); } } } private static int[] primeFactors() { int n = 1000000; int prime[] = new int[n + 1]; for (int i = 1; i <= n; i++) { prime[i] = i; } for (int i = 2; i * i <= n; i++) { if ( prime[i] == i ) { for (int j = i * i; j <= n; j += i) { if ( prime[j] == j ) { prime[j] = i; } } } } return prime; } private static boolean isPalindrome(String s ) { int i = 0, j = s.length() - 1; while ( i <= j ) { if ( s.charAt(i) != s.charAt(j) ) { return false; } i++; j--; } return true; } private static long power( long a , long b ) { long ans = 1; while ( b > 0 ) { if ( (b & 1) != 0 ) { ans = binMultiply(ans, a); } a = binMultiply(a, a ); b >>= 1; } return ans; } private static int GCD ( int a , int b ) { if ( b == 0) return a; return GCD( b , a % b); } private static long binMultiply(long a , long b ) { long ans = 0; while ( b > 0 ) { if ( (b & 1) != 0 ) { ans = (ans + a ); // if m is given in ques than use ans = ans+a % m ; } a = (a + a); // if m is given in ques than use a = (a+a)%m; b >>= 1; } return ans; } private static int binarySearch(int l , int r , int[] arr , int find ) { int mid = l + (r - l) / 2; if ( arr[mid] == find ) { return mid; } else if ( arr[mid] > find ) { return binarySearch(l, mid - 1, arr, find); } return binarySearch(mid + 1, r, arr, find); } private static int upper_bound(ArrayList<Integer> arr , int element ) { int l = 0 ; int h = arr.size(); int mid = 0; while ( h - l > 0 ) { mid = l + (h - l) / 2; if ( arr.get(mid) <= element ) { l = mid + 1; } else { h = mid ; } } if ( arr.get(l) > element ) return l; if ( arr.get(h) > element ) return h; return -1; } private static int lower_bound(ArrayList<Integer> arr , int element ) { int l = 0 ; int h = arr.size(); int mid = 0; while ( h - l > 0 ) { mid = l + (h - l) / 2; if ( arr.get(mid) < element ) { l = mid + 1; } else { h = mid ; } } if ( arr.get(l) >= element ) return l; if ( arr.get(h) >= element ) return h; return -1; } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
7431e921e212136d3bf41439e0c2a2ea
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
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(); int[] arr = new int[n]; for(int i = 0; i < n; i++) { arr[i] = sc.nextInt(); } Arrays.sort(arr); int z = 0; for(int i = 0; i < n; i++) { if(arr[i] == 0) z++; } boolean f = false; if(z > 0) System.out.println(n-z); else { for(int i = 1; i < n; i++) { if(arr[i] == arr[i-1]) { f = true; break; } } System.out.println(f ? n : n+1); } } sc.close(); } } // 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(); // int[] count = new int[101]; // for(int i = 0; i < n; i++) { // count[sc.nextInt()] += 1; // } // int zero = count[0]; // if(zero > 0) // System.out.println(n-zero); // else { // boolean flag = false; // for(int i = 0; i < n; i++) { // if(count[i] > 1) { // flag = true; // break; // } // } // System.out.println(flag ? n : n+1); // } // } // sc.close(); // } // } // int[] arr = new int[n]; // int cnt = 0; // for(int i = 0; i < n; i++) { // arr[i] = sc.nextInt(); // if(arr[i] == 0) // cnt++; // } // 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(); // String s = sc.next(); // boolean[] count = new boolean[26]; // int k = sc.nextInt(); // for(int i = 0; i < k; i++) { // char c = sc.next().charAt(0); // count[c-'a'] = true; // } // int res = 0, last = 0; // for(int i = 0; i < n; i++) { // if(count[s.charAt(i)-'a']) { // if(i - last >= res) // res = Math.max(res, i-last); // last = i; // } // } // System.out.println(res); // } // sc.close(); // } // } // import java.io.*; // import java.util.*; // public class Solution { // public static void main(String[] args) throws IOException { // BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); // PrintWriter wr = new PrintWriter(System.out); // int T = Integer.parseInt(br.readLine().trim()); // for(int t_i = 0; t_i < T; t_i++) // { // String S = br.readLine(); // long X = Long.parseLong(br.readLine().trim()); // int out_ = MaximumLengthSubsequence(S, X); // System.out.println(out_); // } // wr.close(); // br.close(); // } // static int MaximumLengthSubsequence(String S, long X){ // // Write your code here // return 0; // } // }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
41f22197e3fa5b4cca87022d386dc08b
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Codechef { public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); // boolean flag = false; while(t-->0){ int n = sc.nextInt(); int[] arr = new int[n]; for(int i = 0; i<n; i++){ arr[i]=sc.nextInt(); } HashSet<Integer> hs = new HashSet<>(); int count = 0; boolean flag = false; for(int i = 0; i<n; i++){ if(arr[i]==0){ flag=true; count++; } } if(flag){ System.out.println(n-count); } else{ for(int i = 0; i<n; i++){ if(hs.contains(arr[i])){ arr[i]=0; count++; flag=true; break; }else{ hs.add(arr[i]); } } if(flag){ for(int i = 0; i<n; i++){ if(arr[i]!=0){ count++; } } }else{ count=n+1; } System.out.println(count); } } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
d432244aa31704a91a008f55b67d209a
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.*; public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int test = sc.nextInt(); while(test -- > 0) { int n = sc.nextInt(); int[] arr = new int[n]; boolean isZ = false; for(int i=0; i<n; i++) { arr[i] = sc.nextInt(); if (arr[i] == 0) isZ = true; } long ans = 0; if (isZ) { for(int i=0; i<n; i++) { if (arr[i] != 0) ans++; } System.out.println(ans); } else { boolean isp = false; for(int i=0; i<n; i++) { for(int j=i+1; j<n; j++) { if (arr[i] == arr[j]) { ans = n; isp = true; break; } } } if (isp) System.out.println(ans); else System.out.println(n+1); } } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
a30cd9fabfa069fff853aef2d3f5bf0a
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.StringTokenizer; public class A { public static void main(String[] args) throws IOException { Scanner sc=new Scanner(System.in); int T=sc.nextInt(); outer: for (int t=0; t<T; t++) { int n=sc.nextInt(); int a[] = new int[n]; //Begin solving here int zeroCount = 0; for (int i=0; i<n; i++) { a[i] = sc.nextInt(); if (a[i] == 0) zeroCount ++; } if (zeroCount > 0) System.out.println(n - zeroCount); else { int[] numbers= new int[101]; for (int i=0; i<n; i++) { if (numbers[a[i]] > 0) { System.out.println(n); continue outer; } else numbers[a[i]] += 1; } System.out.println(n + 1); } } } } class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(String s) throws FileNotFoundException { br = new BufferedReader(new InputStreamReader(new FileInputStream(s))); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { String result = ""; while (st.hasMoreTokens()) result += st.nextToken(); st = new StringTokenizer(br.readLine()); return result; } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
95d89c7e4bcc6688e900a9695198ba23
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class problem1{ public static void main(String[] args) { Scanner sh = new Scanner(System.in); int t = sh.nextInt(); while(t>0){ int n = sh.nextInt(); Map<Integer,Integer> a = new HashMap<>(); long total = 0; int containszero = 0; for(int i =0; i<n; i++){ int x = sh.nextInt(); if(x == 0){ containszero++; }else{ if(a.containsKey(x)){ total++; }else{ a.put(x, i); } } } if(a.size() == n){ System.out.println(n+1); }else{ System.out.println(total + a.size()); } t--;} } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
1555166dc89d6bf1c94eb841cf4f3f1d
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.HashMap; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); int T = s.nextInt(); for(int t=0;t<T;t++) { int n = s.nextInt(); int ip, max=0, sol; HashMap<Integer, Integer> map = new HashMap<Integer, Integer>(); for(int i=0;i<n;i++) { ip = s.nextInt(); map.put(ip, map.getOrDefault(ip, 0) + 1); max = Math.max(max, map.get(ip)); } if(map.containsKey(0)) { sol = n - map.get(0); } else if(max > 1) { sol = n; } else { sol = n + 1; } System.out.println(sol); } s.close(); } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
64232252f749779d2c812b5699657a47
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Scanner; public class ZeroSequence { static int t; static int n; static ArrayList<Integer> input; public static boolean allOs(ArrayList<Integer> inputArr) { for(int i = 0; i < inputArr.size(); i++) if(inputArr.get(i) != 0) return false; return true; } public static boolean hasNonzeroDuplicates(ArrayList<Integer> inputlist) { for(int i = 1; i < inputlist.size(); i++) if(inputlist.get(i) == inputlist.get(i-1) && input.get(i) != 0) return true; return false; } public static int firstNonZeroIndexToChange(ArrayList<Integer> list) { for(int i = 0; i < list.size(); i++) if(list.get(i) != 0) return i; return -1; } public static int compute(ArrayList<Integer> inputArr) { // int num0s = 0; // for(int i = 0; i < inputArr.length; i++) // { // if(inputArr[i] == 0) // num0s+=1; // } // // if(num0s == inputArr.length) // return 0; // else if(num0s >= 1) // return inputArr.length - num0s; // else // { // // find duplicates // Arrays.sort(inputArr); // int numDups = 0; // for(int i = 1; i < inputArr.length; i++) // if(inputArr[i] == inputArr[i-1]) // numDups+=1; // return inputArr.length - numDups + 1; // } int result = 0; if(firstNonZeroIndexToChange(inputArr) == -1) return 0; Collections.sort(inputArr); while(firstNonZeroIndexToChange(inputArr) != -1) { // 0, 0, 1, 2 // 0, 0, 1, 1 // 0, 0, 1 // 1, 2 // duplicate, change lower one to 0 int curr = firstNonZeroIndexToChange(inputArr); if(hasNonzeroDuplicates(inputArr)) { inputArr.set(curr, 0); result+=1; Collections.sort(inputArr); } else { if(curr == 0) inputArr.set(curr+1, inputArr.get(curr)); else inputArr.set(curr, inputArr.get(curr-1)); result+=1; Collections.sort(inputArr); } } return result; } public static void main(String[] args) { Scanner in = new Scanner(System.in); t = in.nextInt(); for(int i = 0; i < t; i++) { in.nextLine(); n = in.nextInt(); input = new ArrayList<>(); in.nextLine(); for(int j = 0; j < n; j++) { input.add(in.nextInt()); } System.out.println(compute(input)); } in.close(); } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
35ba02caa3e02cf2af61b527010c9fd9
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; public class A_Tokitsukaze_and_All_Zero_Sequence { public static void main(String[] args) { try { FastReader s = new FastReader(); int t = s.nextInt(); while (t-- > 0) { int n = s.nextInt(); int[] arr = new int[n]; arr = s.readArray(n); int flag1 = 0, flag2 = 0, c = 0; for (int i = 0; i < n; i++) { if (arr[i] != 0) continue; else { flag1 = 1; c++; } } Arrays.sort(arr); for (int i = 0; i < n - 1; i++) { if (arr[i] == arr[i + 1]) { flag2 = 1; break; } } if (flag1 == 1) { System.out.println(n - c); } else if (flag2 == 1) System.out.println(n); else System.out.println(n + 1); } } catch (Exception e) { return; } } 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; } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
cc8ad86144afb38d8cb3db188527b784
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.*; public class CFZS { public static void main(String[] args) { Scanner sn=new Scanner(System.in); int t=sn.nextInt(); while(t-->0){ int n=sn.nextInt(); int a[]=new int[n]; for(int i=0;i<n;i++) a[i]=sn.nextInt(); System.out.println(check(a, n)); } } public static int check(int a[],int n){ HashMap<Integer,Integer> map=new HashMap<>(); // int flag=0; // for(int i=0;i<n-1;i++){ // if(a[i]==a[i+1] && a[i]!=0 && a[i+1]!=0) // { // flag=1; // } // } // if(flag==0)return n+1; for(int i:a) map.put(i, map.getOrDefault(i, 0)+1); //System.out.println(map.toString()); int ans=0; int dist=map.size(); for(Map.Entry<Integer,Integer> e:map.entrySet()){ if(e.getKey()==0) dist-=1; if(e.getValue()>1 && e.getKey()!=0){ ans+=e.getValue()-1; } } if(ans==0 && dist==map.size())return dist+1; return ans+dist; } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
36d814f776ee70ab3ed9c78fe7dd5347
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.*; public class PC { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); sc.nextLine(); for (int z = 0; z < t; z++) { // String s = sc.nextLine(); // String ts = sc.nextLine(); int n = sc.nextInt(); HashSet<Integer> map = new HashSet<>(); boolean dup = false; int zcount = 0; for(int i=0;i<n;i++){ int temp = sc.nextInt(); if(temp == 0) { zcount++; // System.out.println(n-1); // break; } else if(map.contains(temp)){ dup = true; // System.out.println(n); // break; } else map.add(temp); } if(zcount==0 && dup == false) System.out.println(n+1); else if(zcount == 0 && dup == true) System.out.println(n); else System.out.println(n-zcount); // if(!done) System.out.println(n+1); // return } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
d5349907d21beb32963557430dbd20d5
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.*; import java.io.*; public class Main { static PrintWriter out = new PrintWriter(System.out); static FastReader sc = new FastReader(); public static void main (String[] args) throws java.lang.Exception { int t = i(); int te=t; //String.format("%.10f",ans) Scanner sco=new Scanner(System.in); while(t-- > 0){ int n=i(); int arr[]=new int[n]; arr=input(n); HashSet<Integer> set=new HashSet<>(); int c=0; for(int i=0;i<n;i++){ set.add((arr[i])); if(arr[i]==0){ c++; } } if(set.contains(0)&&set.size()==arr.length){ out.println(n-1); } else if(set.contains(0)&&set.size()!=arr.length){ out.println(n-c); } else if(set.size()!=arr.length){ out.println(n); } else{ out.println(n+1); } } out.close(); } public static void msort(int[] arr){ ArrayList<Integer> doop = new ArrayList<>(); for(int x : arr){ doop.add(x); } Collections.sort(doop); for(int i = 0;i < arr.length;i++){ arr[i] = doop.get(i); } } static int i() { return sc.nextInt(); } static long l() { return sc.nextLong(); } static int[] input(int N){ int A[]=new int[N]; for(int i=0; i<N; i++) { A[i]=sc.nextInt(); } return A; } static long[] inputLong(int N) { long A[]=new long[N]; for(int i=0; i<A.length; i++)A[i]=sc.nextLong(); return A; } public static int lastset(int num){ int ans=1; while(num>0){ if((num&1)>0){ return ans; } ans++; num=num>>1; } return -1; } } 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 Pair implements Comparable<Pair>{ int x; int y; Pair(int x, int y){ this.x = x; this.y = y; } @Override public int compareTo(Pair obj) { // we sort objects on the basis of Student Id return (this.x - obj.x); } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
86e8a192aab235cd49837093414dfd13
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.*; public class Problem1678A { public static Scanner scanner = new Scanner(System.in); public static void main(String[] args) { int tc = scanner.nextInt(); while (tc-->0){ int n = scanner.nextInt(); int [] array = new int[n]; int hsh[] = new int[105]; boolean isZero = false; int cnt =0; for (int i =0;i< array.length;i++){ array[i] = scanner.nextInt(); hsh[array[i]]++; if (array[i]==0){ isZero = true; cnt++; } } if (isZero) { if (cnt == n) { System.out.println(0); continue; }else{ System.out.println(n-cnt); continue; } } boolean flag = false; for (int i =0;i< hsh.length;i++){ if (hsh[i]>=2){ flag = true; break; } } if (flag){ System.out.println(n); }else System.out.println(n+1); } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
a6d931fc2a3386d7e97036cf9c30eab4
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
/* * way to red */ import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; import static java.lang.System.out; import java.util.*; import java.io.*; import java.math.*; public class CF789A { public static void main(String AC[]) throws Exception { BufferedReader infile = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(infile.readLine()); int T = Integer.parseInt(st.nextToken()); StringBuilder sb = new StringBuilder(); while(T-->0) { st = new StringTokenizer(infile.readLine()); // long N = Long.parseLong(st.nextToken()); int N = Integer.parseInt(st.nextToken()); int[] arr = readArr(N, infile, st); // String s = String.valueOf(st.nextToken()); HashSet<Integer>hs = new HashSet<>(); int c =0; for(int x:arr) { if(x!=0) { hs.add(x); }else { c++; } } if(c>0) { sb.append(N-c).append('\n'); }else if(hs.size()==N) { sb.append(N+1).append('\n'); }else { sb.append(N).append('\n'); } } out.print(sb); out.flush(); //BufferedReader infile = new BufferedReader(new FileReader("input.txt")); //System.setOut(new PrintStream(new File("output.txt"))); } static final int mod = 1_000_000_007; public static int[] readArr(int N, BufferedReader infile, StringTokenizer st) throws Exception { int[] arr = new int[N]; st = new StringTokenizer(infile.readLine()); for(int i=0; i < N; i++) arr[i] = Integer.parseInt(st.nextToken()); return arr; } public static long[] readArr2(int N, BufferedReader infile, StringTokenizer st) throws Exception { long[] arr = new long[N]; st = new StringTokenizer(infile.readLine()); for(int i=0; i < N; i++) arr[i] = Long.parseLong(st.nextToken()); return arr; } public static void print(int[] arr) { //for debugging only for(int x: arr) out.print(x+" "); out.println(); } //input shenanigans /* Random stuff to try when stuck: -if it's 2C then it's dp -for combo/probability problems, expand the given form we're interested in -make everything the same then build an answer (constructive, make everything 0 then do something) -something appears in parts of 2 --> model as graph -assume a greedy then try to show why it works -find way to simplify into one variable if multiple exist -treat it like fmc (note any passing thoughts/algo that could be used so you can revisit them) -find lower and upper bounds on answer -figure out what ur trying to find and isolate it -see what observations you have and come up with more continuations -work backwards (in constructive, go from the goal to the start) -turn into prefix/suffix sum argument (often works if problem revolves around adjacent array elements) -instead of solving for answer, try solving for complement (ex, find n-(min) instead of max) -draw something -simulate a process -dont implement something unless if ur fairly confident its correct -after 3 bad submissions move on to next problem if applicable -do something instead of nothing and stay organized -write stuff down Random stuff to check when wa: -if code is way too long/cancer then reassess -switched N/M -int overflow -switched variables -wrong MOD -hardcoded edge case incorrectly Random stuff to check when tle: -continue instead of break -condition in for/while loop bad Random stuff to check when rte: -switched N/M -long to int/int overflow -division by 0 -edge case for empty list/data structure/N=1 */ public static boolean isPrime(long n) { if(n < 2) return false; if(n == 2 || n == 3) return true; if(n%2 == 0 || n%3 == 0) return false; long sqrtN = (long)Math.sqrt(n)+1; for(long i = 6L; i <= sqrtN; i += 6) { if(n%(i-1) == 0 || n%(i+1) == 0) return false; } return true; } public static long gcd(long a, long b) { if(a > b) a = (a+b)-(b=a); if(a == 0L) return b; return gcd(b%a, a); } public static long totient(long n) { long result = n; for (int p = 2; p*p <= n; ++p) if (n % p == 0) { while(n%p == 0) n /= p; result -= result/p; } if (n > 1) result -= result/n; return result; /* find phi(i) from 1 to N fast O(N*loglogN) long[] arr = new long[N+1]; for(int i=1; i <= N; i++) arr[i] = i; for(int v=2; v <= N; v++) if(arr[v] == v) for(int a=v; a <= N; a+=v) arr[a] -= arr[a]/v; */ } public static ArrayList<Integer> findDiv(int N) { //gens all divisors of N ArrayList<Integer> ls1 = new ArrayList<Integer>(); ArrayList<Integer> ls2 = new ArrayList<Integer>(); for(int i=1; i <= (int)(Math.sqrt(N)+0.00000001); i++) if(N%i == 0) { ls1.add(i); ls2.add(N/i); } Collections.reverse(ls2); for(int b: ls2) if(b != ls1.get(ls1.size()-1)) ls1.add(b); return ls1; } public static void sort(int[] arr) { //because Arrays.sort() uses quicksort which is dumb //Collections.sort() uses merge sort ArrayList<Integer> ls = new ArrayList<Integer>(); for(int x: arr) ls.add(x); Collections.sort(ls); for(int i=0; i < arr.length; i++) arr[i] = ls.get(i); } public static long power(long x, long y, long p) { //0^0 = 1 long res = 1L; x = x%p; while(y > 0) { if((y&1)==1) res = (res*x)%p; y >>= 1; x = (x*x)%p; } return res; } //custom multiset (replace with HashMap if needed) public static void push(TreeMap<Integer, Integer> map, int k, int v) { //map[k] += v; if(!map.containsKey(k)) map.put(k, v); else map.put(k, map.get(k)+v); } public static void pull(TreeMap<Integer, Integer> map, int k, int v) { //assumes map[k] >= v //map[k] -= v int lol = map.get(k); if(lol == v) map.remove(k); else map.put(k, lol-v); } public static int[] compress(int[] arr) { ArrayList<Integer> ls = new ArrayList<Integer>(); for(int x: arr) ls.add(x); Collections.sort(ls); HashMap<Integer, Integer> map = new HashMap<Integer, Integer>(); int boof = 1; //min value for(int x: ls) if(!map.containsKey(x)) map.put(x, boof++); int[] brr = new int[arr.length]; for(int i=0; i < arr.length; i++) brr[i] = map.get(arr[i]); return brr; } public static long[][] multiply(long[][] left, long[][] right) { long MOD = 1000000007L; int N = left.length; int M = right[0].length; long[][] res = new long[N][M]; for(int a=0; a < N; a++) for(int b=0; b < M; b++) for(int c=0; c < left[0].length; c++) { res[a][b] += (left[a][c]*right[c][b])%MOD; if(res[a][b] >= MOD) res[a][b] -= MOD; } return res; } public static long[][] power(long[][] grid, long pow) { long[][] res = new long[grid.length][grid[0].length]; for(int i=0; i < res.length; i++) res[i][i] = 1L; long[][] curr = grid.clone(); while(pow > 0) { if((pow&1L) == 1L) res = multiply(curr, res); pow >>= 1; curr = multiply(curr, curr); } return res; } /* * Data Structures */ class DSU { public int[] dsu; public int[] size; public DSU(int N) { dsu = new int[N+1]; size = new int[N+1]; for(int i=0; i <= N; i++) { dsu[i] = i; size[i] = 1; } } //with path compression, no find by rank public int find(int x) { return dsu[x] == x ? x : (dsu[x] = find(dsu[x])); } public void merge(int x, int y) { int fx = find(x); int fy = find(y); dsu[fx] = fy; } public void merge(int x, int y, boolean sized) { int fx = find(x); int fy = find(y); size[fy] += size[fx]; dsu[fx] = fy; } } class FenwickTree { //Binary Indexed Tree //1 indexed public int[] tree; public int size; public FenwickTree(int size) { this.size = size; tree = new int[size+5]; } public void add(int i, int v) { while(i <= size) { tree[i] += v; i += i&-i; } } public int find(int i) { int res = 0; while(i >= 1) { res += tree[i]; i -= i&-i; } return res; } public int find(int l, int r) { return find(r)-find(l-1); } } class SegmentTree { //Tlatoani's segment tree //iterative implementation = low constant runtime factor //range query, non lazy final int[] val; final int treeFrom; final int length; public SegmentTree(int treeFrom, int treeTo) { this.treeFrom = treeFrom; int length = treeTo - treeFrom + 1; int l; for (l = 0; (1 << l) < length; l++); val = new int[1 << (l + 1)]; this.length = 1 << l; } public void update(int index, int delta) { //replaces value int node = index - treeFrom + length; val[node] = delta; for (node >>= 1; node > 0; node >>= 1) val[node] = comb(val[node << 1], val[(node << 1) + 1]); } public int query(int from, int to) { //inclusive bounds if (to < from) return 0; //0 or 1? from += length - treeFrom; to += length - treeFrom + 1; //0 or 1? int res = 0; for (; from + (from & -from) <= to; from += from & -from) res = comb(res, val[from / (from & -from)]); for (; to - (to & -to) >= from; to -= to & -to) res = comb(res, val[(to - (to & -to)) / (to & -to)]); return res; } public int comb(int a, int b) { //change this return Math.max(a,b); } } class LazySegTree { //definitions private int NULL = -1; private int[] tree; private int[] lazy; private int length; public LazySegTree(int N) { length = N; int b; for(b=0; (1<<b) < length; b++); tree = new int[1<<(b+1)]; lazy = new int[1<<(b+1)]; } public int query(int left, int right) { //left and right are 0-indexed return get(1, 0, length-1, left, right); } private int get(int v, int currL, int currR, int L, int R) { if(L > R) return NULL; if(L <= currL && currR <= R) return tree[v]; propagate(v); int mid = (currL+currR)/2; return comb(get(v*2, currL, mid, L, Math.min(R, mid)), get(v*2+1, mid+1, currR, Math.max(L, mid+1), R)); } public void update(int left, int right, int delta) { add(1, 0, length-1, left, right, delta); } private void add(int v, int currL, int currR, int L, int R, int delta) { if(L > R) return; if(currL == L && currR == R) { //exact covering tree[v] += delta; lazy[v] += delta; return; } propagate(v); int mid = (currL+currR)/2; add(v*2, currL, mid, L, Math.min(R, mid), delta); add(v*2+1, mid+1, currR, Math.max(L, mid+1), R, delta); tree[v] = comb(tree[v*2], tree[v*2+1]); } private void propagate(int v) { //tree[v] already has lazy[v] if(lazy[v] == 0) return; tree[v*2] += lazy[v]; lazy[v*2] += lazy[v]; tree[v*2+1] += lazy[v]; lazy[v*2+1] += lazy[v]; lazy[v] = 0; } private int comb(int a, int b) { return Math.max(a,b); } } class RangeBit { //FenwickTree and RangeBit are faster than LazySegTree by constant factor final int[] value; final int[] weightedVal; public RangeBit(int treeTo) { value = new int[treeTo+2]; weightedVal = new int[treeTo+2]; } private void updateHelper(int index, int delta) { int weightedDelta = index*delta; for(int j = index; j < value.length; j += j & -j) { value[j] += delta; weightedVal[j] += weightedDelta; } } public void update(int from, int to, int delta) { updateHelper(from, delta); updateHelper(to + 1, -delta); } private int query(int to) { int res = 0; int weightedRes = 0; for (int j = to; j > 0; j -= j & -j) { res += value[j]; weightedRes += weightedVal[j]; } return ((to + 1)*res)-weightedRes; } public int query(int from, int to) { if (to < from) return 0; return query(to) - query(from - 1); } } class SparseTable { public int[] log; public int[][] table; public int N; public int K; public SparseTable(int N) { this.N = N; log = new int[N+2]; K = Integer.numberOfTrailingZeros(Integer.highestOneBit(N)); table = new int[N][K+1]; sparsywarsy(); } private void sparsywarsy() { log[1] = 0; for(int i=2; i <= N+1; i++) log[i] = log[i/2]+1; } public void lift(int[] arr) { int n = arr.length; for(int i=0; i < n; i++) table[i][0] = arr[i]; for(int j=1; j <= K; j++) for(int i=0; i + (1 << j) <= n; i++) table[i][j] = Math.min(table[i][j-1], table[i+(1 << (j - 1))][j-1]); } public int query(int L, int R) { //inclusive, 1 indexed L--; R--; int mexico = log[R-L+1]; return Math.min(table[L][mexico], table[R-(1 << mexico)+1][mexico]); } } class LCA { public int N, root; public ArrayDeque<Integer>[] edges; private int[] enter; private int[] exit; private int LOG = 17; //change this private int[][] dp; public LCA(int n, ArrayDeque<Integer>[] edges, int r) { N = n; root = r; enter = new int[N+1]; exit = new int[N+1]; dp = new int[N+1][LOG]; this.edges = edges; int[] time = new int[1]; //change to iterative dfs if N is large dfs(root, 0, time); dp[root][0] = 1; for(int b=1; b < LOG; b++) for(int v=1; v <= N; v++) dp[v][b] = dp[dp[v][b-1]][b-1]; } private void dfs(int curr, int par, int[] time) { dp[curr][0] = par; enter[curr] = ++time[0]; for(int next: edges[curr]) if(next != par) dfs(next, curr, time); exit[curr] = ++time[0]; } public int lca(int x, int y) { if(isAnc(x, y)) return x; if(isAnc(y, x)) return y; int curr = x; for(int b=LOG-1; b >= 0; b--) { int temp = dp[curr][b]; if(!isAnc(temp, y)) curr = temp; } return dp[curr][0]; } private boolean isAnc(int anc, int curr) { return enter[anc] <= enter[curr] && exit[anc] >= exit[curr]; } } class BitSet { private int CONS = 62; //safe public long[] sets; public int size; public BitSet(int N) { size = N; if(N%CONS == 0) sets = new long[N/CONS]; else sets = new long[N/CONS+1]; } public void add(int i) { int dex = i/CONS; int thing = i%CONS; sets[dex] |= (1L << thing); } public int and(BitSet oth) { int boof = Math.min(sets.length, oth.sets.length); int res = 0; for(int i=0; i < boof; i++) res += Long.bitCount(sets[i] & oth.sets[i]); return res; } public int xor(BitSet oth) { int boof = Math.min(sets.length, oth.sets.length); int res = 0; for(int i=0; i < boof; i++) res += Long.bitCount(sets[i] ^ oth.sets[i]); return res; } } class MaxFlow { //Dinic with optimizations (see magic array in dfs function) public int N, source, sink; public ArrayList<Edge>[] edges; private int[] depth; public MaxFlow(int n, int x, int y) { N = n; source = x; sink = y; edges = new ArrayList[N+1]; for(int i=0; i <= N; i++) edges[i] = new ArrayList<Edge>(); depth = new int[N+1]; } public void addEdge(int from, int to, long cap) { Edge forward = new Edge(from, to, cap); Edge backward = new Edge(to, from, 0L); forward.residual = backward; backward.residual = forward; edges[from].add(forward); edges[to].add(backward); } public long mfmc() { long res = 0L; int[] magic = new int[N+1]; while(assignDepths()) { long flow = dfs(source, Long.MAX_VALUE/2, magic); while(flow > 0) { res += flow; flow = dfs(source, Long.MAX_VALUE/2, magic); } magic = new int[N+1]; } return res; } private boolean assignDepths() { Arrays.fill(depth, -69); ArrayDeque<Integer> q = new ArrayDeque<Integer>(); q.add(source); depth[source] = 0; while(q.size() > 0) { int curr = q.poll(); for(Edge e: edges[curr]) if(e.capacityLeft() > 0 && depth[e.to] == -69) { depth[e.to] = depth[curr]+1; q.add(e.to); } } return depth[sink] != -69; } private long dfs(int curr, long bottleneck, int[] magic) { if(curr == sink) return bottleneck; for(; magic[curr] < edges[curr].size(); magic[curr]++) { Edge e = edges[curr].get(magic[curr]); if(e.capacityLeft() > 0 && depth[e.to]-depth[curr] == 1) { long val = dfs(e.to, Math.min(bottleneck, e.capacityLeft()), magic); if(val > 0) { e.augment(val); return val; } } } return 0L; //no flow } private class Edge { public int from, to; public long flow, capacity; public Edge residual; public Edge(int f, int t, long cap) { from = f; to = t; capacity = cap; } public long capacityLeft() { return capacity-flow; } public void augment(long val) { flow += val; residual.flow -= val; } } } class FastScanner { //I don't understand how this works lmao private int BS = 1 << 16; private char NC = (char) 0; private byte[] buf = new byte[BS]; private int bId = 0, size = 0; private char c = NC; private double cnt = 1; private BufferedInputStream in; public FastScanner() { in = new BufferedInputStream(System.in, BS); } public FastScanner(String s) { try { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } catch (Exception e) { in = new BufferedInputStream(System.in, BS); } } private char getChar() { 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 int[] nextInts(int N) { int[] res = new int[N]; for (int i = 0; i < N; i++) { res[i] = (int) nextLong(); } return res; } public long[] nextLongs(int N) { long[] res = new long[N]; for (int i = 0; i < N; i++) { res[i] = nextLong(); } return res; } public long nextLong() { cnt = 1; boolean neg = false; if (c == NC) c = getChar(); for (; (c < '0' || c > '9'); c = getChar()) { if (c == '-') neg = true; } long res = 0; for (; c >= '0' && c <= '9'; c = getChar()) { res = (res << 3) + (res << 1) + c - '0'; cnt *= 10; } return neg ? -res : res; } public double nextDouble() { double cur = nextLong(); return c != '.' ? cur : cur + nextLong() / cnt; } public double[] nextDoubles(int N) { double[] res = new double[N]; for (int i = 0; i < N; i++) { res[i] = nextDouble(); } return res; } public String next() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c > 32) { res.append(c); c = getChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c != '\n') { res.append(c); c = getChar(); } return res.toString(); } public boolean hasNext() { if (c > 32) return true; while (true) { c = getChar(); if (c == NC) return false; else if (c > 32) return true; } } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
0a599d41709dc03e2a3cf5faa1d88eda
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashSet; import java.util.StringTokenizer; public class TokitsukazeAndAllZeroSequence { public static void main(String[] args) throws Exception { var br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine().trim()); var sb = new StringBuilder(); while(t -- > 0) { int N = Integer.parseInt(br.readLine().trim()); int arr[] = nextIntArray(N, br); sb.append(solve(arr)).append("\n"); } br.close(); System.out.println(sb); } private static int solve(int arr[]) { int zeroCount = 0; boolean duplicate = false; HashSet<Integer> hs = new HashSet<>(); for(int i : arr) { if(hs.contains(i)) duplicate = true; hs.add(i); if(i == 0) zeroCount++; } if(zeroCount > 0) return arr.length - zeroCount; if(duplicate) return arr.length; return arr.length+1; } private static int[] nextIntArray(int N, BufferedReader br) throws IOException { var st = new StringTokenizer(br.readLine().trim(), " "); int arr[] = new int[N]; for(int i = 0; i < arr.length; i++) arr[i] = Integer.parseInt(st.nextToken()); return arr; } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
214c9213cab75a5a941731d86fea04e1
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class Main { public static void process()throws IOException { int n=ni(); int arr[]=iarr(n); int zero=0,dup=0; Set<Integer> set=new HashSet<>(); for(int i=0;i<n;i++) { if(arr[i]==0) zero++; else { if(set.contains(arr[i])) dup++; set.add(arr[i]); } } if(zero!=0) pn(n-zero); else if(dup!=0) pn(n); else pn(n+1); } static AnotherReader sc; static PrintWriter out; public static void main(String[]args)throws IOException { out = new PrintWriter(System.out); sc=new AnotherReader(); boolean oj = true; //oj = System.getProperty("ONLINE_JUDGE") != null; //if(!oj) sc=new AnotherReader(100); long s = System.currentTimeMillis(); int T=ni(); while(T-->0) process(); out.flush(); if(!oj) System.out.println(System.currentTimeMillis()-s+"ms"); System.out.close(); } static void sort(long arr[],int n) { shuffle(arr,n); Arrays.sort(arr); } static void shuffle(long arr[],int n) { Random r=new Random(); for(int i=0;i<n;i++) { long temp=arr[i]; int pos=i+r.nextInt(n-i); arr[i]=arr[pos]; arr[pos]=temp; } } static void pn(Object o){out.println(o);} static void p(Object o){out.print(o);} static void pni(Object o){out.println(o);System.out.flush();} static int ni()throws IOException{return sc.nextInt();} static long nl()throws IOException{return sc.nextLong();} static double nd()throws IOException{return sc.nextDouble();} static String nln()throws IOException{return sc.nextLine();} static String nn()throws IOException{return sc.next();} static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);} static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);} static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));} static int[] iarr(int N)throws IOException{int[]ARR=new int[N];for(int i=0;i<N;i++){ARR[i]=ni();}return ARR;} static long[] larr(int N)throws IOException{long[]ARR=new long[N];for(int i=0;i<N;i++){ARR[i]=nl();}return ARR;} static boolean multipleTC=false; ///////////////////////////////////////////////////////////////////////////////////////////////////////// static class AnotherReader{BufferedReader br; StringTokenizer st; AnotherReader()throws FileNotFoundException{ br=new BufferedReader(new InputStreamReader(System.in));} AnotherReader(int a)throws FileNotFoundException{ br = new BufferedReader(new FileReader("input.txt"));} String next()throws IOException{ while (st == null || !st.hasMoreElements()) {try{ st = new StringTokenizer(br.readLine());} catch (IOException e){ e.printStackTrace(); }} return st.nextToken(); } int nextInt() throws IOException{ return Integer.parseInt(next());} long nextLong() throws IOException {return Long.parseLong(next());} double nextDouble()throws IOException { return Double.parseDouble(next()); } String nextLine() throws IOException{ String str = ""; try{ str = br.readLine();} catch (IOException e){ e.printStackTrace();} return str;}} ///////////////////////////////////////////////////////////////////////////////////////////////////////////// } /* var urlSchema=new mongoose.Schema({ originalUrl:{type: String} shortenedUrl:{type:String} expirationDate:{type: Number,default: 48} timeCreated: {type: Date,deafult:Date.now} }) */
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
6610871dda6e5643320dbfcab1f2de91
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
//package com.company; import java.math.BigInteger; import java.util.*; import java.lang.*; import java.io.*; public class Main { public static FastScanner fs = new FastScanner(); public static Scanner sc = new Scanner(System.in); public static PrintWriter out = new PrintWriter(System.out); public static int inf = 1000000007; public static BigInteger infb = new BigInteger("1000000007"); public static long lmax= (long) 1e18; public static boolean flag=false; public static StringBuilder sb=new StringBuilder(); /////// For printing elements in 1D-array public static void print1d(long[] arr) { for (long x : arr) { out.print(x + " "); } out.println(); } /////// For printing elements in 2D-array public static void print2d(long[][] arr) { for(int i=0;i<arr.length;i++){ for(int j=0;j<arr[0].length;j++){ out.print(arr[i][j]+" "); } out.println(); } out.println(); } /////// For freq of elements in array public static long[] freq(long[] freq_arr, long[] arr) { for (long j : arr) { freq_arr[(int) j]++; } return freq_arr; } /////// For sum elements in array public static long sum(long[] arr) { long sum = 0; for (int i=0;i<arr.length;i++) { sum += arr[i]; } return sum; } /////// For storing elements in array 1D public static long[] scan1d(long[] arr) { for (int i = 0; i < arr.length; i++) { arr[i] = fs.nextLong(); } return arr; } /////// For storing elements in array 2D public static long[][] scan2d(long[][] arr) { for (int i = 0; i < arr.length; i++) { arr[i][0] = fs.nextLong(); arr[i][1] = fs.nextLong(); } return arr; } /////// For copying elements in array public static long[] copy_arr(long[] arr, long[] arr1) { for (int i = 0; i < arr.length; i++) { arr1[i] = arr[i]; } return arr; } /////// For GCD public static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } /// gcd of array static long gcd_arr(long arr[], long n) { long result = 0; for (long element: arr){ result = gcd(result, element); if(result == 1) { return 1; } } return result; } //////// Forprime public static boolean isPrime(long n) { if (n < 2) return false; if (n == 2 || n == 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; long sqrtN = (long) Math.sqrt(n) + 1; for (long i = 6L; i <= sqrtN; i += 6) { if (n % (i - 1) == 0 || n % (i + 1) == 0) return false; } return true; } //////Using array as Set public static boolean[] arr_set(boolean[] arr, int n) { for (int i = 0; i < n; i++) { int x = sc.nextInt(); arr[x] = true; } return arr; } /// Fidning min in array public static long min_arr(long[] arr,int l,int r){ long min=arr[l]; for(int i=l;i<r;i++){ min=Math.min(min,arr[i]); } return min; } /// Fidning max in array public static long max_arr(long[] arr,int l,int r){ long max=arr[l]; for(int i=l;i<r;i++){ max=Math.max(max,arr[i]); } return max; } ///prefix sum public static long[] pre_sum(long[] arr){ long[] prefix_sum=new long[arr.length]; prefix_sum[0]=arr[0]; for(int i=1;i<arr.length;i++){ prefix_sum[i]=prefix_sum[i-1]+arr[i]; } return prefix_sum; } ///sorted_arr public static boolean sorted_arr(long[] arr,long[] arr_sorted){ for(int i=0;i<arr.length;i++){ if(arr[i]!=arr_sorted[i]){ return false; } } return true; } public static boolean sorted_arr_increasing(long ar[],long n){ for(long i=0;i<n-1;i++){ if(ar[(int) i]>ar[(int) (i+1)]) return false; } return true; } 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()); } long[] readArray(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()); } } public static long fact(long n) { long fact = 1; for (long i = 1; i <= n; i++) { fact *= i; } return fact; } public static long nCr(long n, long r) { long res = 1; for (long i = 0; i < r; i++) { res *= (n - i); res /= (i + 1); } return res; } public static long pCr(long n, long r) { return fact(n) / (fact(n-r)); } static boolean isSubSequence(String str1, String strm, int m, int n) { int j = 0; for (int i = 0; i < n && j < m; i++) if (str1.charAt(j) == strm.charAt(i)) j++; return (j == m); } public static boolean cmp(int a, int b) { return a > b; } static boolean palindrome(String x){ String s=""; for(int i=x.length()-1;i>=0;i--){ s+=x.charAt(i); } if(s.equals(x)){ return true; } return false; } public static class pair { long a; long b; pair(long a, long b){ this.a=a; this.b=b; } } static String toBinary(int x, int len) { if (len > 0) { return String.format("%" + len + "s", Integer.toBinaryString(x)).replaceAll(" ", "0"); } return null; } static long maxSubArraySum(long[] a) { int size = a.length; long max_so_far = Long.MIN_VALUE, max_ending_here = 0; for (int i = 0; i < size; i++) { max_ending_here = max_ending_here + a[i]; if (max_so_far < max_ending_here) max_so_far = max_ending_here; if (max_ending_here < 0) max_ending_here = 0; } return max_so_far; } public static List<Integer> primeNumbers = new LinkedList<>(); public static void primeChecker(int n) { boolean prime[] = new boolean[n + 1]; Arrays.fill(prime, true); for (int p = 2; p * p <= n; p++) { if (prime[p]) { for (int i = p * 2; i <= n; i += p) { prime[i] = false; } } } for (int i = 2; i <= n; i++) { if (prime[i]) { primeNumbers.add(i); } } } public static void main(String[] args) throws IOException { // (fact(n)/(fact(i)*fact(n-i))) // for(Map.Entry<String,Integer> entry : tree Map.entrySet()) { // String key = entry.getKey(); // Integer value = entry.getValue(); // // } //File in = new File("input.txt"); //Writer wr= new FileWriter("output.txt"); //BigInteger n = new BigInteger(String.valueOf(sc.nextInt())); //StringBuilder sb= new StringBuilder(); //Arrays.sort(myArr, (a, b) -> a[0] - b[0]); for index at 0 long t=fs.nextLong(); while (t-->0){ long n=fs.nextLong(); HashSet<Long> hs = new HashSet<>(); long co=0; for (int i=0;i<n;i++){ long x=fs.nextLong(); if (x==0){ co++; } hs.add(x); } if (co>0){ out.println(n-co); }else if (co==0 && hs.size()<n){ out.println(n); }else { out.println(n+1); } } out.flush(); } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
d808b2e5a48eb2469da8ab5d3e2bad7f
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
/*----------- ---------------* Author : Ryan Ranaut __Hope is a big word, never lose it__ ------------- --------------*/ import java.io.*; import java.util.*; public class Codeforces2 { static PrintWriter out = new PrintWriter(System.out); static final int mod = 1_000_000_007; 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()); } int[] readIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long[] readLongArray(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()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } /*--------------------------------------------------------------------------*/ //Try seeing general case //Minimization Maximization - BS..... Connections - Graphs..... //Greedy not worthy - Try DP //Think edge cases public static void main(String[] args) { FastReader s = new FastReader(); int t = s.nextInt(); while(t-->0) { int n = s.nextInt(); int[] a = s.readIntArray(n); out.println(find(n, a)); } out.close(); } public static int find(int n, int[] a) { int zeros = 0, cnt = 0; for(int x: a) { if(x == 0) zeros++; } if(zeros > 0) return n - zeros; sort(a); for(int i=1;i<n;i++) { if(a[i] == a[i-1]) cnt++; } return cnt > 0 ? n : n+1; } /*----------------------------------End of the road--------------------------------------*/ static class DSU { int[] parent; int[] ranks; int[] groupSize; int size; public DSU(int n) { size = n; parent = new int[n];//0 based ranks = new int[n]; groupSize = new int[n];//Size of each component for (int i = 0; i < n; i++) { parent[i] = i; ranks[i] = 1; groupSize[i] = 1; } } public int find(int x)//Path Compression { if (parent[x] == x) return x; else return parent[x] = find(parent[x]); } public void union(int x, int y)//Union by rank { int x_rep = find(x); int y_rep = find(y); if (x_rep == y_rep) return; if (ranks[x_rep] < ranks[y_rep]) { parent[x_rep] = y_rep; groupSize[y_rep] += groupSize[x_rep]; } else if (ranks[x_rep] > ranks[y_rep]) { parent[y_rep] = x_rep; groupSize[x_rep] += groupSize[y_rep]; } else { parent[y_rep] = x_rep; ranks[x_rep]++; groupSize[x_rep] += groupSize[y_rep]; } size--;//Total connected components } } public static int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); } public static long gcd(long x, long y) { return y == 0L ? x : gcd(y, x % y); } 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); } public static long pow(long a, long b) { if (b == 0L) return 1L; long tmp = 1; while (b > 1L) { if ((b & 1L) == 1) tmp *= a; a *= a; b >>= 1; } return (tmp * a); } public static long modPow(long a, long b, long mod) { if (b == 0L) return 1L; long tmp = 1; while (b > 1L) { if ((b & 1L) == 1L) tmp *= a; a *= a; a %= mod; tmp %= mod; b >>= 1; } return (tmp * a) % mod; } static long mul(long a, long b) { return a * b; } static long fact(int n) { long ans = 1; for (int i = 2; i <= n; i++) ans = mul(ans, i); return ans; } static long fastPow(long base, long exp) { if (exp == 0) return 1; long half = fastPow(base, exp / 2); if (exp % 2 == 0) return mul(half, half); return mul(half, mul(half, base)); } static void debug(int... a) { for (int x : a) out.print(x + " "); out.println(); } static void debug(long... a) { for (long x : a) out.print(x + " "); out.println(); } static void debugMatrix(int[][] a) { for (int[] x : a) out.println(Arrays.toString(x)); } static void debugMatrix(long[][] a) { for (long[] x : a) out.println(Arrays.toString(x)); } static void reverseArray(int[] a) { int n = a.length; int[] arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = a[n - i - 1]; for (int i = 0; i < n; i++) a[i] = arr[i]; } static void reverseArray(long[] a) { int n = a.length; long[] arr = new long[n]; for (int i = 0; i < n; i++) arr[i] = a[n - i - 1]; for (int i = 0; i < n; i++) a[i] = arr[i]; } static void sort(int[] a) { ArrayList<Integer> ls = new ArrayList<>(); for (int x : a) ls.add(x); Collections.sort(ls); for (int i = 0; i < a.length; i++) a[i] = ls.get(i); } static void sort(long[] a) { ArrayList<Long> ls = new ArrayList<>(); for (long x : a) ls.add(x); Collections.sort(ls); for (int i = 0; i < a.length; i++) a[i] = ls.get(i); } static class Pair { int x, y; Pair(int x, int y) { this.x = x; this.y = y; } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
5c5ffee094c55a276f0f29c60702dc1f
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.io.*; import java.util.HashSet; import java.util.StringTokenizer; public class CodeForces789_1 { final static class IO { final static class Reader { BufferedReader reader; StringTokenizer tokenizer = null; Reader() { reader = new BufferedReader(new InputStreamReader(System.in)); } private void initializer() throws IOException { tokenizer = new StringTokenizer(reader.readLine()); } private String nextToken() throws IOException { if (tokenizer == null || !tokenizer.hasMoreTokens()) initializer(); return tokenizer.nextToken(); } public void close() throws IOException { reader.close(); } public int[] nextIntArray(int n) throws IOException { int []data=new int[n]; for (int i=0;i<n;i++) data[i]=Integer.parseInt(nextToken()); return data; } public float[] nextFloatArray(int n) throws IOException { float []data=new float[n]; for (int i=0;i<n;i++) data[i]=Float.parseFloat(nextToken()); return data; } public double[] nextDoubleArray(int n) throws IOException { double []data=new double[n]; for (int i=0;i<n;i++) data[i]=Double.parseDouble(nextToken()); return data; } public String[] nextStringArray(int n) throws IOException { String []data=new String[n]; for (int i=0;i<n;i++) data[i]=nextToken(); return data; } public String nextLine() throws IOException { return reader.readLine(); } public String next() throws IOException { return nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(nextToken()); } public float nextFloat() throws IOException { return Float.parseFloat(nextToken()); } public double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } } final static class Writer{ PrintWriter writer; Writer(){ writer=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); } public void print(int val){ writer.print(val); } public void print(char c){ writer.print(c); } public void print(String str){ writer.print(str); } public void print(double d){ writer.print(d); } public void print(float f){ writer.print(f); } public void println(int val){ writer.println(val); } public void println(char c){ writer.println(c); } public void println(String str){ writer.println(str); } public void println(double d){ writer.println(d); } public void println(float f){ writer.println(f); } public void close(){ writer.flush(); } } } public static void main(String[] args) throws IOException { IO.Reader scanner = new IO.Reader(); IO.Writer writer = new IO.Writer(); int T = scanner.nextInt(); outer: while (T-->0){ int n = scanner.nextInt(); int [] data = scanner.nextIntArray(n); int zero_count =0; for (int i :data) if (i==0) zero_count++; if (zero_count==0){ HashSet<Integer> set = new HashSet<>(); for (int i =0;i<data.length;i++){ if (set.contains(data[i])){ writer.println(n); continue outer; } set.add(data[i]); } writer.println(n+1); } else{ writer.println(n-zero_count); } } writer.close(); } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
867e764e11f6e7a7c02f5abb6ee604e2
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.*; public class r789 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); int[] arr=new int[n]; Map<Integer,Integer> map=new HashMap<>(); boolean check=false; boolean check2=false; for(int i=0;i<n;i++){ arr[i]=sc.nextInt(); if(arr[i]==0){ check2=true; } map.put(arr[i],map.getOrDefault(arr[i],0)+1); if(map.get(arr[i])>1){ check=true; } } if(check2){ System.out.println(n-map.get(0)); continue; } if(check){ System.out.println(n); }else{ System.out.println(n+1); } } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
72744667174204134ef225e2f3581a17
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.*; import java.io.*; public class TokitsukazeAndAllZeroSequence{ public static void main(String[] args) { MyScanner sc = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); //CODE HERE int t=sc.nextInt(); while (t-->0){ int n=sc.nextInt(),cnt=0,z=0; int[] arr=new int[n]; for(int i=0;i<n;i++){ arr[i]=sc.nextInt(); if(arr[i]==0){ z++; } } Arrays.sort(arr);boolean ok=false; if(arr[0]==0){ out.println(n-z); continue; } for (int i=0;i<n-1;i++){ if(arr[i]==arr[i+1]){ ok=true; } } if(ok){ out.println(n-z); }else{ out.println(n+1-z); } } out.flush(); 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(); } 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
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
95a79f07322605276ce260d795837791
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.*; import java.util.Map.Entry; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.math.*; import java.sql.Array; public class imp { static final Random random = new Random(); static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine().trim(); } catch (Exception e) { e.printStackTrace(); } return str; } } static class FastWriter { private final BufferedWriter bw; public FastWriter() { this.bw = new BufferedWriter(new OutputStreamWriter(System.out)); } public void print(Object object) throws IOException { bw.append("" + object); } public void println(Object object) throws IOException { print(object); bw.append("\n"); } public void close() throws IOException { bw.close(); } } static void ruffleSort(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 void ruffleSort(long[] a) { int n = a.length; for (int i = 0; i < n; i++) { long oi = random.nextInt(n), temp = a[(int) oi]; a[(int) oi] = a[i]; a[i] = temp; } Arrays.sort(a); } public static class Pair implements Comparable<Pair> { int x; int y; public Pair(int x, int y) { this.x = x; this.y = y; } public int compareTo(Pair other) { return (int) (this.y - other.y); } public boolean equals(Pair other) { if (this.x == other.x && this.y == other.y) return true; return false; } public int hashCode() { return 31 * x + y; } // // TODO Auto-generated method stub } static int power(int x, int y, int p) { int res = 1; x = x % p; while (y > 0) { if (y % 2 == 1) res = (res * x) % p; // y must be even now y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } // Returns n^(-1) mod p static int modInverse(int n, int p) { return power(n, p - 2, p); } // Returns nCr % p using Fermat's // little theorem. static int nCrModPFermat(int n, int r, int p) { if (n < r) return 0; // Base case if (r == 0) return 1; // Fill factorial array so that we // can find all factorial of r, n // and n-r int[] fac = new int[n + 1]; fac[0] = 1; for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % p; return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; } static int nCrModp(int n, int r, int p) { if (r > n - r) r = n - r; // The array C is going to store last // row of pascal triangle at the end. // And last entry of last row is nCr int C[] = new int[r + 1]; C[0] = 1; // Top row of Pascal Triangle // One by constructs remaining rows of Pascal // Triangle from top to bottom for (int i = 1; i <= n; i++) { // Fill entries of current row using previous // row values for (int j = Math.min(i, r); j > 0; j--) // nCj = (n-1)Cj + (n-1)C(j-1); C[j] = (C[j] + C[j - 1]) % p; } return C[r]; } static int gcd(int a, int b) { // Everything divides 0 if (a == 0) return b; if (b == 0) return a; // base case if (a == b) return a; // a is greater if (a > b) return gcd(a - b, b); return gcd(a, b - a); } public static class Node { int root; ArrayList<Node> al; Node par; public Node(int root, ArrayList<Node> al, Node par) { this.root = root; this.al = al; this.par = par; } } public static long __gcd(long a, long b) { if (b == 0) return a; return __gcd(b, a % b); } public static class DSU { int n; int par[]; int rank[]; public DSU(int n) { this.n = n; par = new int[n + 1]; rank = new int[n + 1]; for (int i = 1; i <= n; i++) { par[i] = i; rank[i] = 0; } } public int findPar(int node) { if (node == par[node]) { return node; } return par[node] = findPar(par[node]);//path compression } public void union(int u, int v) { u = findPar(u); v = findPar(v); if (rank[u] < rank[v]) { par[u] = v; } else if (rank[u] > rank[v]) { par[v] = u; } else { par[v] = u; rank[u]++; } } } public static Set<Integer> fact(int n){ Set<Integer> set=new HashSet<>(); for (int i=1; i<=Math.sqrt(n); i++) { if (n%i==0) { if (n/i == i) set.add(i); else { set.add(i); set.add(n/i); } } } return set; } static void merge(int arr[], int l, int m, int r) { int a[]=new int[arr.length]; int i=l; int j=m+1; int k=l; while(i<=m&&j<=r) { if(arr[i]<arr[j]) a[k++]=arr[i++]; else a[k++]=arr[j++]; } if(i>m) { while(j<=r) a[k++]=arr[j++]; } else { while(i<=m) a[k++]=arr[i++]; } for(int x=l;x<=r;x++) arr[x]=a[x]; } static void mergeSort(int arr[], int l, int r) { if(l<r) { int mid=(l+r)/2; mergeSort(arr, l, mid); mergeSort(arr, mid+1, r); merge(arr, l, mid, r); } } public static void main(String args[]) throws IOException { FastReader sc=new FastReader(); int t=sc.nextInt(); while (t-->0){ int n=sc.nextInt(); Set<Integer> set=new HashSet<>(); int count=0; boolean fl=false; for (int i = 0; i < n; i++) { int val=sc.nextInt(); if(set.contains(val)){ fl=true; } if(val==0){ count++; fl=true; } set.add(val); } int res=0; if(fl){ res=n-count; }else{ res=n+1; } System.out.println(res); } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
bd344885d7ffdeef18c9ee098c6b9d15
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.*; import java.io.*; public class A { static class Scan { private byte[] buf=new byte[1024]; private int index; private InputStream in; private int total; public Scan() { in=System.in; } public int scan()throws IOException { if(total<0) throw new InputMismatchException(); if(index>=total) { index=0; total=in.read(buf); if(total<=0) return -1; } return buf[index++]; } public int scanInt()throws IOException { int integer=0; int n=scan(); while(isWhiteSpace(n)) n=scan(); int neg=1; if(n=='-') { neg=-1; n=scan(); } while(!isWhiteSpace(n)) { if(n>='0'&&n<='9') { integer*=10; integer+=n-'0'; n=scan(); } else throw new InputMismatchException(); } return neg*integer; } public double scanDouble()throws IOException { double doub=0; int n=scan(); while(isWhiteSpace(n)) n=scan(); int neg=1; if(n=='-') { neg=-1; n=scan(); } while(!isWhiteSpace(n)&&n!='.') { if(n>='0'&&n<='9') { doub*=10; doub+=n-'0'; n=scan(); } else throw new InputMismatchException(); } if(n=='.') { n=scan(); double temp=1; while(!isWhiteSpace(n)) { if(n>='0'&&n<='9') { temp/=10; doub+=(n-'0')*temp; n=scan(); } else throw new InputMismatchException(); } } return doub*neg; } public String scanString()throws IOException { StringBuilder sb=new StringBuilder(); int n=scan(); while(isWhiteSpace(n)) n=scan(); while(!isWhiteSpace(n)) { sb.append((char)n); n=scan(); } return sb.toString(); } private boolean isWhiteSpace(int n) { if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1) return true; return false; } } public static void sort(int arr[],int l,int r) { //sort(arr,0,n-1); if(l==r) { return; } int mid=(l+r)/2; sort(arr,l,mid); sort(arr,mid+1,r); merge(arr,l,mid,mid+1,r); } public static void merge(int arr[],int l1,int r1,int l2,int r2) { int tmp[]=new int[r2-l1+1]; int indx1=l1,indx2=l2; //sorting the two halves using a tmp array for(int i=0;i<tmp.length;i++) { if(indx1>r1) { tmp[i]=arr[indx2]; indx2++; continue; } if(indx2>r2) { tmp[i]=arr[indx1]; indx1++; continue; } if(arr[indx1]<arr[indx2]) { tmp[i]=arr[indx1]; indx1++; continue; } tmp[i]=arr[indx2]; indx2++; } //Copying the elements of tmp into the main array for(int i=0,j=l1;i<tmp.length;i++,j++) { arr[j]=tmp[i]; } } public static void sort(long arr[],int l,int r) { //sort(arr,0,n-1); if(l==r) { return; } int mid=(l+r)/2; sort(arr,l,mid); sort(arr,mid+1,r); merge(arr,l,mid,mid+1,r); } public static void merge(long arr[],int l1,int r1,int l2,int r2) { long tmp[]=new long[r2-l1+1]; int indx1=l1,indx2=l2; //sorting the two halves using a tmp array for(int i=0;i<tmp.length;i++) { if(indx1>r1) { tmp[i]=arr[indx2]; indx2++; continue; } if(indx2>r2) { tmp[i]=arr[indx1]; indx1++; continue; } if(arr[indx1]<arr[indx2]) { tmp[i]=arr[indx1]; indx1++; continue; } tmp[i]=arr[indx2]; indx2++; } //Copying the elements of tmp into the main array for(int i=0,j=l1;i<tmp.length;i++,j++) { arr[j]=tmp[i]; } } public static void main(String args[]) throws IOException { Scan input=new Scan(); StringBuilder ans=new StringBuilder(""); int test=input.scanInt(); for(int tt=1;tt<=test;tt++) { int n=input.scanInt(); int arr[]=new int[n]; for(int i=0;i<n;i++) { arr[i]=input.scanInt(); } int cnt=0; sort(arr,0,n-1); int zero=0; boolean same=false; for(int i=0;i<n;i++) { if(arr[i]==0) { zero++; } } for(int i=0;i<n-1;i++) { if(arr[i]==arr[i+1]) { same=true; } } if(zero>0) { cnt=(n-zero); } else if(same) { cnt=n; } else { cnt=n+1; } ans.append(cnt+"\n"); } System.out.print(ans); } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
cf32f9ca07f03c59b63cad581a3d809e
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
// import static java.lang.System.out; import static java.lang.Math.*; import static java.lang.System.*; import java.lang.reflect.Array; import java.util.*; import java.io.*; import java.math.*; public class Main { static FastReader sc; static long mod = ((long) 1e9) + 7; static long lmax=Long.MAX_VALUE; static long lmin=Long.MIN_VALUE; static int imax=Integer.MAX_VALUE; static int imin=Integer.MIN_VALUE; // static FastWriter out; static FastWriter out; public static void main(String hi[]) throws IOException { // initializeIO(); out = new FastWriter(); sc = new FastReader(); long startTimeProg = System.currentTimeMillis(); long endTimeProg = Long.MAX_VALUE; int t = sc.nextInt(); // int t=1; // boolean[] seave=sieveOfEratosthenes((int)(1e5)); // int[] seave2=sieveOfEratosthenesInt((long)sqrt(1e9)); // debug(seave2); while (t-- != 0) { int n=sc.nextInt(); int[] arr=readIntArray(n); sort(arr); int c=0; for(int i=0;i<n;i++){ if(arr[i]==0)c++; } if(c>0){ print(n-c); }else{ boolean done=false; for(int i=1;i<n;i++){ if(arr[i]==arr[i-1]){ done=true; } } if(done){ print(n); }else{ print(n+1); } } } endTimeProg = System.currentTimeMillis(); debug("[finished : " + (endTimeProg - startTimeProg) + ".ms ]"); // System.out.println(String.format("%.9f", max)); } private static boolean isPeak(int[] arr,int i,int l,int r){ if(i==l||i==r)return false; return (arr[i+1]<arr[i]&&arr[i]>arr[i-1]); } private static boolean isPeak(long[] arr,int i,int l,int r){ if(i==l||i==r)return false; return (arr[i+1]<arr[i]&&arr[i]>arr[i-1]); } private static long kadens(List<Long> li, int l, int r) { long max = Long.MIN_VALUE; long ans = 0; for (int i = l; i <= r; i++) { ans += li.get(i); max = max(ans, max); if (ans < 0) ans = 0; } return max; } public static boolean isNumeric(String strNum) { if (strNum == null) { return false; } try { double d = Double.parseDouble(strNum); } catch (NumberFormatException nfe) { return false; } return true; } private static boolean isSorted(List<Integer> li) { int n = li.size(); if (n <= 1) return true; for (int i = 0; i < n - 1; i++) { if (li.get(i) > li.get(i + 1)) return false; } return true; } static boolean isPowerOfTwo(long x) { return x != 0 && ((x & (x - 1)) == 0); } private static boolean ispallindromeList(List<Integer> res) { int l = 0, r = res.size() - 1; while (l < r) { if (res.get(l) != res.get(r)) return false; l++; r--; } return true; } private static class Pair { int first = 0; int sec = 0; int[] arr; char ch; String s; Map<Integer, Integer> map; Pair(int first, int sec) { this.first = first; this.sec = sec; } Pair(int[] arr) { this.map = new HashMap<>(); for (int x : arr) this.map.put(x, map.getOrDefault(x, 0) + 1); this.arr = arr; } Pair(char ch, int first) { this.ch = ch; this.first = first; } Pair(String s, int first) { this.s = s; this.first = first; } } private static int sizeOfSubstring(int st, int e) { int s = e - st + 1; return (s * (s + 1)) / 2; } private static Set<Long> factors(long n) { Set<Long> res = new HashSet<>(); // res.add(n); for (long i = 1; i * i <= (n); i++) { if (n % i == 0) { res.add(i); if (n / i != i) { res.add(n / i); } } } return res; } private static long fact(long n) { if (n <= 2) return n; return n * fact(n - 1); } private static long ncr(long n, long r) { return fact(n) / (fact(r) * fact(n - r)); } private static int lessThen(long[] nums, long val, boolean work, int l, int r) { int i = -1; if (work) i = 0; while (l <= r) { int mid = l + ((r - l) / 2); if (nums[mid] <= val) { i = mid; l = mid + 1; } else { r = mid - 1; } } return i; } private static int lessThen(List<Long> nums, long val, boolean work, int l, int r) { int i = -1; if (work) i = 0; while (l <= r) { int mid = l + ((r - l) / 2); if (nums.get(mid) <= val) { i = mid; l = mid + 1; } else { r = mid - 1; } } return i; } private static int lessThen(List<Integer> nums, int val, boolean work, int l, int r) { int i = -1; if (work) i = 0; while (l <= r) { int mid = l + ((r - l) / 2); if (nums.get(mid) <= val) { i = mid; l = mid + 1; } else { r = mid - 1; } } return i; } private static int greaterThen(List<Long> nums, long val, boolean work, int l, int r) { int i = -1; if (work) i = r; while (l <= r) { int mid = l + ((r - l) / 2); if (nums.get(mid) >= val) { i = mid; r = mid - 1; } else { l = mid + 1; } } return i; } private static int greaterThen(List<Integer> nums, int val, boolean work) { int i = -1, l = 0, r = nums.size() - 1; if (work) i = r; while (l <= r) { int mid = l + ((r - l) / 2); if (nums.get(mid) >= val) { i = mid; r = mid - 1; } else { l = mid + 1; } } return i; } private static int greaterThen(long[] nums, long val, boolean work, int l, int r) { int i = -1; if (work) i = r; while (l <= r) { int mid = l + ((r - l) / 2); if (nums[mid] >= val) { i = mid; r = mid - 1; } else { l = mid + 1; } } return i; } private static long gcd(long[] arr) { long ans = 0; for (long x : arr) { ans = gcd(x, ans); } return ans; } private static int gcd(int[] arr) { int ans = 0; for (int x : arr) { ans = gcd(x, ans); } return ans; } private static long sumOfAp(long a, long n, long d) { long val = (n * (2 * a + ((n - 1) * d))); return val / 2; } //geometrics private static double areaOftriangle(double x1, double y1, double x2, double y2, double x3, double y3) { double[] mid_point = midOfaLine(x1, y1, x2, y2); // debug(Arrays.toString(mid_point)+" "+x1+" "+y1+" "+x2+" "+y2+" "+x3+" "+" "+y3); double height = distanceBetweenPoints(mid_point[0], mid_point[1], x3, y3); double wight = distanceBetweenPoints(x1, y1, x2, y2); // debug(height+" "+wight); return (height * wight) / 2; } private static double distanceBetweenPoints(double x1, double y1, double x2, double y2) { double x = x2 - x1; double y = y2 - y1; return (Math.pow(x, 2) + Math.pow(y, 2)); } public static boolean isPerfectSquareByUsingSqrt(long n) { if (n <= 0) { return false; } double squareRoot = Math.sqrt(n); long tst = (long) (squareRoot + 0.5); return tst * tst == n; } private static double[] midOfaLine(double x1, double y1, double x2, double y2) { double[] mid = new double[2]; mid[0] = (x1 + x2) / 2; mid[1] = (y1 + y2) / 2; return mid; } private static long sumOfN(long n) { return (n * (n + 1)) / 2; } private static long power(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; } /* Function to calculate x raised to the power y in O(logn)*/ static long power(long x, long y) { long temp; if (y == 0) return 1l; temp = power(x, y / 2); if (y % 2 == 0) return (temp * temp); else return (x * temp * temp); } private static StringBuilder reverseString(String s) { StringBuilder sb = new StringBuilder(s); int l = 0, r = sb.length() - 1; while (l <= r) { char ch = sb.charAt(l); sb.setCharAt(l, sb.charAt(r)); sb.setCharAt(r, ch); l++; r--; } return sb; } private static void swap(List<Integer> li, int i, int j) { int t = li.get(i); li.set(i, li.get(j)); li.set(j, t); } static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } static long lcm(long a, long b) { return (a / gcd(a, b)) * b; } private static String decimalToString(int x) { return Integer.toBinaryString(x); } private static String decimalToString(long x) { return Long.toBinaryString(x); } private static boolean isPallindrome(String s, int l, int r) { while (l < r) { if (s.charAt(l) != s.charAt(r)) return false; l++; r--; } return true; } private static boolean isSubsequence(String s, String t) { if (s == null || t == null) return false; Map<Character, List<Integer>> map = new HashMap<>(); //<character, index> //preprocess t for (int i = 0; i < t.length(); i++) { char curr = t.charAt(i); if (!map.containsKey(curr)) { map.put(curr, new ArrayList<Integer>()); } map.get(curr).add(i); } int prev = -1; //index of previous character for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (map.get(c) == null) { return false; } else { List<Integer> list = map.get(c); prev = lessThen(list, prev, false, 0, list.size() - 1); if (prev == -1) { return false; } prev++; } } return true; } private static StringBuilder removeLeadingZero(StringBuilder sb) { int i = 0; while (i < sb.length() && sb.charAt(i) == '0') i++; // debug("remove "+i); if (i == sb.length()) return new StringBuilder(); return new StringBuilder(sb.substring(i, sb.length())); } private static StringBuilder removeEndingZero(StringBuilder sb) { int i = sb.length() - 1; while (i >= 0 && sb.charAt(i) == '0') i--; // debug("remove "+i); if (i < 0) return new StringBuilder(); return new StringBuilder(sb.substring(0, i + 1)); } private static int stringToDecimal(String binaryString) { // debug(decimalToString(n<<1)); return Integer.parseInt(binaryString, 2); } private static int stringToInt(String s) { return Integer.parseInt(s); } private static String toString(long val) { return String.valueOf(val); } private static void debug(int[][] arr) { for (int i = 0; i < arr.length; i++) { err.println(Arrays.toString(arr[i])); } } private static void debug(long[][] arr) { for (int i = 0; i < arr.length; i++) { err.println(Arrays.toString(arr[i])); } } private static void debug(List<int[]> arr) { for (int[] a : arr) { err.println(Arrays.toString(a)); } } private static void debug(float[][] arr) { for (int i = 0; i < arr.length; i++) { err.println(Arrays.toString(arr[i])); } } private static void debug(double[][] arr) { for (int i = 0; i < arr.length; i++) { err.println(Arrays.toString(arr[i])); } } private static void debug(boolean[][] arr) { for (int i = 0; i < arr.length; i++) { err.println(Arrays.toString(arr[i])); } } private static void print(String s) throws IOException { out.println(s); } private static void debug(String s) throws IOException { err.println(s); } private static int charToIntS(char c) { return ((((int) (c - '0')) % 48)); } private static void print(double s) throws IOException { out.println(s); } private static void debug(char[] s1) throws IOException { debug(Arrays.toString(s1)); } private static void print(float s) throws IOException { out.println(s); } private static void print(long s) throws IOException { out.println(s); } private static void print(int s) throws IOException { out.println(s); } private static void debug(double s) throws IOException { err.println(s); } private static void debug(float s) throws IOException { err.println(s); } private static void debug(long s) { err.println(s); } private static void debug(int s) { err.println(s); } private 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 (int i = 3; i * i <= n; i += 2) { if (n % i == 0) return false; } return true; } private static List<List<Integer>> readUndirectedGraph(int n) { List<List<Integer>> graph = new ArrayList<>(); for (int i = 0; i <= n; i++) { graph.add(new ArrayList<>()); } for (int i = 0; i < n; i++) { int x = sc.nextInt(); int y = sc.nextInt(); graph.get(x).add(y); graph.get(y).add(x); } return graph; } private static List<List<Integer>> readUndirectedGraph(int[][] intervals, int n) { List<List<Integer>> graph = new ArrayList<>(); for (int i = 0; i <= n; i++) { graph.add(new ArrayList<>()); } for (int i = 0; i < intervals.length; i++) { int x = intervals[i][0]; int y = intervals[i][1]; graph.get(x).add(y); graph.get(y).add(x); } return graph; } private static List<List<Integer>> readDirectedGraph(int[][] intervals, int n) { List<List<Integer>> graph = new ArrayList<>(); for (int i = 0; i <= n; i++) { graph.add(new ArrayList<>()); } for (int i = 0; i < intervals.length; i++) { int x = intervals[i][0]; int y = intervals[i][1]; graph.get(x).add(y); // graph.get(y).add(x); } return graph; } private static List<List<Integer>> readDirectedGraph(int n) { List<List<Integer>> graph = new ArrayList<>(); for (int i = 0; i <= n; i++) { graph.add(new ArrayList<>()); } for (int i = 0; i < n; i++) { int x = sc.nextInt(); int y = sc.nextInt(); graph.get(x).add(y); // graph.get(y).add(x); } return graph; } static String[] readStringArray(int n) { String[] arr = new String[n]; for (int i = 0; i < n; i++) { arr[i] = sc.next(); } return arr; } private static Map<Character, Integer> freq(String s) { Map<Character, Integer> map = new HashMap<>(); for (char c : s.toCharArray()) { map.put(c, map.getOrDefault(c, 0) + 1); } return map; } private static Map<Long, Integer> freq(long[] arr) { Map<Long, Integer> map = new HashMap<>(); for (long x : arr) { map.put(x, map.getOrDefault(x, 0) + 1); } return map; } private static Map<Integer, Integer> freq(int[] arr) { Map<Integer, Integer> map = new HashMap<>(); for (int x : arr) { map.put(x, map.getOrDefault(x, 0) + 1); } return map; } static boolean[] sieveOfEratosthenes(long n) { boolean prime[] = new boolean[(int) 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; } } return prime; } static int[] sieveOfEratosthenesInt(long n) { boolean prime[] = new boolean[(int) n + 1]; Set<Integer> li = new HashSet<>(); for (int i = 1; i <= n; i++) { prime[i] = true; li.add(i); } for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) { li.remove(i); prime[i] = false; } } } int[] arr = new int[li.size()]; int i = 0; for (int x : li) { arr[i++] = x; } return arr; } public static long Kadens(List<Long> prices) { long sofar = 0; long max_v = 0; for (int i = 0; i < prices.size(); i++) { sofar += prices.get(i); if (sofar < 0) { sofar = 0; } max_v = Math.max(max_v, sofar); } return max_v; } public static int Kadens(int[] prices) { int sofar = 0; int max_v = 0; for (int i = 0; i < prices.length; i++) { sofar += prices[i]; if (sofar < 0) { sofar = 0; } max_v = Math.max(max_v, sofar); } return max_v; } static boolean isMemberAC(int a, int d, int x) { // If difference is 0, then x must // be same as a. if (d == 0) return (x == a); // Else difference between x and a // must be divisible by d. return ((x - a) % d == 0 && (x - a) / d >= 0); } static boolean isMemberAC(long a, long d, long x) { // If difference is 0, then x must // be same as a. if (d == 0) return (x == a); // Else difference between x and a // must be divisible by d. return ((x - a) % d == 0 && (x - a) / d >= 0); } private static void sort(int[] arr) { int n = arr.length; List<Integer> li = new ArrayList<>(); for (int x : arr) { li.add(x); } Collections.sort(li); for (int i = 0; i < n; i++) { arr[i] = li.get(i); } } private static void sortReverse(int[] arr) { int n = arr.length; List<Integer> li = new ArrayList<>(); for (int x : arr) { li.add(x); } Collections.sort(li, Collections.reverseOrder()); for (int i = 0; i < n; i++) { arr[i] = li.get(i); } } private static void sort(double[] arr) { int n = arr.length; List<Double> li = new ArrayList<>(); for (double x : arr) { li.add(x); } Collections.sort(li); for (int i = 0; i < n; i++) { arr[i] = li.get(i); } } private static void sortReverse(double[] arr) { int n = arr.length; List<Double> li = new ArrayList<>(); for (double x : arr) { li.add(x); } Collections.sort(li, Collections.reverseOrder()); for (int i = 0; i < n; i++) { arr[i] = li.get(i); } } private static void sortReverse(long[] arr) { int n = arr.length; List<Long> li = new ArrayList<>(); for (long x : arr) { li.add(x); } Collections.sort(li, Collections.reverseOrder()); for (int i = 0; i < n; i++) { arr[i] = li.get(i); } } private static void sort(long[] arr) { int n = arr.length; List<Long> li = new ArrayList<>(); for (long x : arr) { li.add(x); } Collections.sort(li); for (int i = 0; i < n; i++) { arr[i] = li.get(i); } } private static long sum(int[] arr) { long sum = 0; for (int x : arr) { sum += x; } return sum; } private static long sum(long[] arr) { long sum = 0; for (long x : arr) { sum += x; } return sum; } private static long evenSumFibo(long n) { long l1 = 0, l2 = 2; long sum = 0; while (l2 < n) { long l3 = (4 * l2) + l1; sum += l2; if (l3 > n) break; l1 = l2; l2 = l3; } return sum; } private static void initializeIO() { try { System.setIn(new FileInputStream("input")); System.setOut(new PrintStream(new FileOutputStream("output.txt"))); System.setErr(new PrintStream(new FileOutputStream("error.txt"))); } catch (Exception e) { System.err.println(e.getMessage()); } } private static int maxOfArray(int[] arr) { int max = Integer.MIN_VALUE; for (int x : arr) { max = Math.max(max, x); } return max; } private static long maxOfArray(long[] arr) { long max = Long.MIN_VALUE; for (long x : arr) { max = Math.max(max, x); } return max; } private static int[][] readIntIntervals(int n, int m) { int[][] arr = new int[n][m]; for (int j = 0; j < n; j++) { for (int i = 0; i < m; i++) { arr[j][i] = sc.nextInt(); } } return arr; } private static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } private static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } private static int[] readIntArray(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); } return arr; } private static double[] readDoubleArray(int n) { double[] arr = new double[n]; for (int i = 0; i < n; i++) { arr[i] = sc.nextDouble(); } return arr; } private static long[] readLongArray(int n) { long[] arr = new long[n]; for (int i = 0; i < n; i++) { arr[i] = sc.nextLong(); } return arr; } private static void print(int[] arr) throws IOException { out.println(Arrays.toString(arr)); } private static void print(long[] arr) throws IOException { out.println(Arrays.toString(arr)); } private static void print(String[] arr) throws IOException { out.println(Arrays.toString(arr)); } private static void print(double[] arr) throws IOException { out.println(Arrays.toString(arr)); } private static void debug(String[] arr) { err.println(Arrays.toString(arr)); } private static void debug(Boolean[][] arr) { for (int i = 0; i < arr.length; i++) err.println(Arrays.toString(arr[i])); } private static void debug(int[] arr) { err.println(Arrays.toString(arr)); } private static void debug(long[] arr) { err.println(Arrays.toString(arr)); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine().trim(); } catch (Exception e) { e.printStackTrace(); } return str; } } static class FastWriter { BufferedWriter bw; List<String> list = new ArrayList<>(); Set<String> set = new HashSet<>(); FastWriter() { bw = new BufferedWriter(new OutputStreamWriter(System.out)); } <T> void print(T obj) throws IOException { bw.write(obj.toString()); bw.flush(); } void println() throws IOException { print("\n"); } <T> void println(T obj) throws IOException { print(obj.toString() + "\n"); } void print(int[] arr) throws IOException { for (int x : arr) { print(x + " "); } println(); } void print(long[] arr) throws IOException { for (long x : arr) { print(x + " "); } println(); } void print(double[] arr) throws IOException { for (double x : arr) { print(x + " "); } println(); } void printCharN(char c, int n) throws IOException { for (int i = 0; i < n; i++) { print(c); } } } static class Dsu { int[] parent, size; Dsu(int n) { parent = new int[n + 1]; size = new int[n + 1]; for (int i = 0; i <= n; i++) { parent[i] = i; size[i] = 1; } } private int findParent(int u) { if (parent[u] == u) return u; return parent[u] = findParent(parent[u]); } private boolean union(int u, int v) { // System.out.println("uf "+u+" "+v); int pu = findParent(u); // System.out.println("uf2 "+pu+" "+v); int pv = findParent(v); // System.out.println("uf3 " + u + " " + pv); if (pu == pv) return false; if (size[pu] <= size[pv]) { parent[pu] = pv; size[pv] += size[pu]; } else { parent[pv] = pu; size[pu] += size[pv]; } return true; } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
ece1105fafaddbd0c5f1469b4aa36a0e
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
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 void main(String args[]) throws IOException{ FastReader sc = new FastReader(); BufferedOutputStream out = new BufferedOutputStream(System.out); int t = sc.nextInt(); while(t-->0){ int n = sc.nextInt(); int arr[] = new int[n]; for(int i=0;i<n;i++) arr[i] = sc.nextInt(); boolean hasZero = false; int c = 0; HashSet<Integer> set = new HashSet<>(); for(int x : arr){ if(x == 0){ hasZero = true; c++; } set.add(x); } int ans = 0; if(hasZero) ans = n-1-(c-1); else if(hasZero && set.size() == 1) ans = 0; else if(set.size() < n) ans = n; else if(set.size() == n) ans = n+1; out.write(((ans) + "\n").getBytes()); } out.flush(); } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
3928a717a6dcb4f0b3c8b2236539fd44
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t1=sc.nextInt(); for(int j1=0;j1<t1;j1++){ int n=sc.nextInt(); int a[]=new int[n]; int c=0; int d=0; for(int i=0;i<a.length;i++){ a[i]=sc.nextInt(); } Arrays.sort(a); for(int i=0;i<a.length;i++){ if(a[i]==0){ c++; }else if(i!=0 && a[i]==a[i-1]){ d=1; } } if(c!=0){ int ans=a.length-c; System.out.println(ans); }else{ if(d==1){ System.out.println(a.length); }else{ int ans=a.length+1; System.out.println(ans); } } }}}
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 11
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
6b1900c654deaf825349f95c332be2fe
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
//package com.company; import java.util.*; import java.util.Stack; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); while(t-- > 0){ int n = in.nextInt(); int[] arr = new int[n]; int flag = -1; int count = 0; for (int i = 0; i < n; i++) { arr[i] = in.nextInt(); } Arrays.sort(arr); for (int j = 0; j < n-1; j++) { if(arr[0] == 0 && j == 0){ count++; flag = 0; } if(arr[j+1] == 0){ count++; } if(arr[j] == arr[j+1] && arr[j] != 0){ if(flag == 0){ break; } flag = 1; break; } } if(flag == 0 && count == 1){ System.out.println(n-1); }else if(flag == 1){ System.out.println(n); }else if(flag == 0 && count > 1){ System.out.println(n-count); }else { System.out.println(n+1); } } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 17
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output
PASSED
b1a8ec8845f1fbda3e5fb84910f5df76
train_108.jsonl
1652020500
Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). If $$$a_i = a_j$$$, change one of them to $$$0$$$. Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.
256 megabytes
import java.util.HashSet; import java.util.Scanner; public class problem10 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t= sc.nextInt(); while(t-- > 0){ int n = sc.nextInt(); int arr[] = new int[n]; int no_zer0=0; HashSet<Integer> set = new HashSet<>(); for(int i=0;i<n;i++){ arr[i]= sc.nextInt(); if(arr[i]>0){ no_zer0++; } set.add(arr[i]); } if(set.size()==1 && set.contains(0)){ System.out.println("0"); } else if(set.contains(0)){ System.out.println(no_zer0); } else{ if(set.size()==n){ System.out.println(n+1); } else{ System.out.println(n); } } } } }
Java
["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0"]
1 second
["4\n3\n2"]
NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 &lt; a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 &lt; a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.
Java 17
standard input
[ "implementation" ]
ad242f98f1c8eb8d30789ec672fc95a0
The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.
800
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.
standard output