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
1aaa55b08b81c1856f89988f9730fcca
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { Reader s = new Reader(); Scanner sc = new Scanner(System.in); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st; try { int t = Integer.parseInt(br.readLine()); // BufferedReader bu = new BufferedReader(new InputStreamReader(System.in)); // StringBuilder sb = new StringBuilder(); // String[] str = bu.readLine().split(" "); // // int t = Integer.parseInt(str[0]); while (t-- > 0) { // str = bu.readLine().split(" "); // solve(str[0],str[1]); // } int n = Integer.parseInt(br.readLine()); String[][] ss = new String[3][n]; HashMap<String, Integer> hs = new HashMap<>(); for (int i = 0; i < 3; i++) { st = new StringTokenizer(br.readLine(), " "); for (int j = 0; j < n; j++) { ss[i][j] = st.nextToken(); if (hs.get(ss[i][j]) == null) { hs.put(ss[i][j], 1); } else { int yo = hs.get(ss[i][j]); hs.replace(ss[i][j], ++yo); } } } solve(n, hs, ss); } } catch (Exception e) { return; } } public static void solve(int n, HashMap<String, Integer> hs, String[][] ss) { int a = 0, b = 0, c = 0; for (int i = 0; i < n; i++) { if (hs.get(ss[0][i]) == 1) a += 3; else if (hs.get(ss[0][i]) == 2) a += 1; // System.out.println("word is: " + s1[i]); // System.out.println("a = " + a); } for (int i = 0; i < n; i++) { if (hs.get(ss[1][i]) == 1) b += 3; else if (hs.get(ss[1][i]) == 2) b += 1; // System.out.println("word is: " + s2[i]); // System.out.println("b = " + a); } for (int i = 0; i < n; i++) { if (hs.get(ss[2][i]) == 1) c += 3; else if (hs.get(ss[2][i]) == 2) c += 1; // System.out.println("word is: " + s3[i]); // System.out.println("c = " + a); } System.out.println(a + " " + b + " " + c); // hs.forEach((k,v) -> { // if(v==1) // }); } 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(); } } static class SortingString { int oldIndex; int ch; public SortingString(int oldIndex, int ch) { this.oldIndex = oldIndex; this.ch = ch; } } static class SortingComparator implements Comparator<SortingString> { public int compare(SortingString a, SortingString b) { return a.oldIndex - b.oldIndex; } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
3620b2b8c9e302954c1c1ec80ba5134f
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { Reader s = new Reader(); Scanner sc = new Scanner(System.in); try { int t = sc.nextInt(); // BufferedReader bu = new BufferedReader(new InputStreamReader(System.in)); // StringBuilder sb = new StringBuilder(); // String[] str = bu.readLine().split(" "); // // int t = Integer.parseInt(str[0]); while (t-- > 0) { // str = bu.readLine().split(" "); // solve(str[0],str[1]); // } // int n = sc.nextInt(); String[] s1 = new String[n]; String[] s2 = new String[n]; String[] s3 = new String[n]; String[][] ss = new String[3][n]; HashMap<String, Integer> hs = new HashMap<>(); for (int i = 0; i < 3; i++) { for (int j = 0; j < n; j++) { ss[i][j] = sc.next(); if (hs.get(ss[i][j]) == null) { hs.put(ss[i][j], 1); } else { int yo = hs.get(ss[i][j]); hs.replace(ss[i][j], ++yo); } } } solve(n, s1, s2, s3, hs, ss); } } catch (Exception e) { return; } } public static void solve(int n, String[] s1, String[] s2, String[] s3, HashMap<String, Integer> hs, String[][] ss) { int a = 0, b = 0, c = 0; for (int i = 0; i < n; i++) { if (hs.get(ss[0][i]) == 1) a += 3; else if (hs.get(ss[0][i]) == 2) a += 1; // System.out.println("word is: " + s1[i]); // System.out.println("a = " + a); } for (int i = 0; i < n; i++) { if (hs.get(ss[1][i]) == 1) b += 3; else if (hs.get(ss[1][i]) == 2) b += 1; // System.out.println("word is: " + s2[i]); // System.out.println("b = " + a); } for (int i = 0; i < n; i++) { if (hs.get(ss[2][i]) == 1) c += 3; else if (hs.get(ss[2][i]) == 2) c += 1; // System.out.println("word is: " + s3[i]); // System.out.println("c = " + a); } System.out.println(a + " " + b + " " + c); // hs.forEach((k,v) -> { // if(v==1) // }); } 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(); } } static class SortingString { int oldIndex; int ch; public SortingString(int oldIndex, int ch) { this.oldIndex = oldIndex; this.ch = ch; } } static class SortingComparator implements Comparator<SortingString> { public int compare(SortingString a, SortingString b) { return a.oldIndex - b.oldIndex; } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
91546d2603e7d4bacdcb485448ebaf22
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.*; public class WordGame3_1 { public static void main(String[] args) throws Exception { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(reader.readLine()); for (int i = 0; i < t; i++) { int wordCount = Integer.parseInt(reader.readLine()); List<List<String>> arrWords = new ArrayList<>(); Map<String,Integer> map = new HashMap<>(); for (int j = 0; j < 3; j++){ arrWords.add(Arrays.asList(reader.readLine().split(" "))); } for (int j = 0; j < 3; j++){ for (int k = 0; k < wordCount; k++){ String word = arrWords.get(j).get(k); if (map.containsKey(word)){ Integer count = map.get(word); map.put(word, ++count); } else{ map.put(word, 1); } } } for (int j = 0; j < 3; j++){ int score = 0; for (int k = 0; k < wordCount; k++){ String word = arrWords.get(j).get(k); Integer count = map.get(word); if (count == 2) score++; if (count == 1) score += 3; } System.out.print(score + " "); } System.out.println(); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
d0e858daef685e54256d8bb2ec666eb5
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.HashSet; import java.util.Scanner; import java.util.Set; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int t = scan.nextInt(); while (t-- > 0) { int size = scan.nextInt(); Set<String> m12 = new HashSet<String>(); Set<String> m13 = new HashSet<String>(); Set<String> m23 = new HashSet<String>(); Set<String> total = new HashSet<String>(); String[] arr = new String[size]; String[] arr2 = new String[size]; for (int i = 0; i < size; i++) { arr[i] = scan.next(); total.add(arr[i]); } for (int i = 0; i < size; i++) { String s2 = scan.next(); m12.add(s2); m12.add(arr[i]); arr2[i] = s2; total.add(s2); } int M12 = size * 2 - m12.size(); for (int i = 0; i < size; i++) { String s3 = scan.next(); m13.add(s3); m13.add(arr[i]); arr[i] = s3; total.add(s3); } int M13 = size * 2 - m13.size(); for (int i = 0; i < size; i++) { m23.add(arr[i]); m23.add(arr2[i]); } int M23 = size * 2 - m23.size(); int tot = size * 3 - total.size(); int tt = M12 + M13 + M23 - tot; M12 -= tt; M13 -= tt; M23 -= tt; size -= tt; int one1 = M12 + M13; int one2 = M12 + M23; int one3 = M13 + M23; int three1 = (size - one1) * 3; int three2 = (size - one2) * 3; int three3 = (size - one3) * 3; int total1 = one1 + three1; int total2 = one2 + three2; int total3 = one3 + three3; System.out.println(total1 + " " + total2 + " " + total3); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
7427a54b4a70ad5776c0da54fbce6977
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.HashSet; import java.util.Scanner; import java.util.Set; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int N = in.nextInt(); in.nextLine(); while(N-->0) { int words = in.nextInt(); in.nextLine(); Set<String> aSet = new HashSet<>(); Set<String> bSet = new HashSet<>(); Set<String> cSet = new HashSet<>(); Set<String> masterSet = new HashSet<>(); String[] aLine = in.nextLine().split(" "); String[] bLine = in.nextLine().split(" "); String[] cLine = in.nextLine().split(" "); int aCount = 0; int bCount = 0; int cCount = 0; boolean a = false; boolean b = false; boolean c = false; for(int i = 0; i < words; i++) { aSet.add(aLine[i]); bSet.add(bLine[i]); cSet.add(cLine[i]); masterSet.add(aLine[i]); masterSet.add(bLine[i]); masterSet.add(cLine[i]); } for(String word: masterSet) { a = !aSet.add(word); b = !bSet.add(word); c = !cSet.add(word); if(a && b && !c) { aCount++; bCount++; } if(a && !b && c) { aCount++; cCount++; } if(!a && b && c) { cCount++; bCount++; } if(a && !b && !c) { aCount+= 3; } if(!a && b && !c) { bCount += 3; } if(!a && !b && c) { cCount += 3; } } System.out.println(aCount + " " + bCount + " " + cCount); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
36025fe1b37a3ba848d146fd8989259e
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.io.*; import java.util.*; public class Main { static int T; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out); StringTokenizer st = new StringTokenizer(br.readLine()); T = Integer.parseInt(st.nextToken()); for (int t = 0; t < T; t++) { int N = Integer.parseInt(br.readLine()); String[] a = br.readLine().split(" "); String[] b = br.readLine().split(" "); String[] c = br.readLine().split(" "); HashMap<String, Integer> mapa = new HashMap<>(); HashMap<String, Integer> mapb = new HashMap<>(); HashMap<String, Integer> mapc = new HashMap<>(); for(int i = 0; i<N; i++){ mapa.put(a[i], mapa.getOrDefault(a[i], 0) + 1); mapb.put(b[i], mapa.getOrDefault(b[i], 0) + 1); mapc.put(c[i], mapa.getOrDefault(c[i], 0) + 1); } int one = 0; int two = 0; int three = 0; for(int i = 0; i<N; i++){ one += givePoints(a[i], mapa, mapb, mapc); } for(int i = 0; i<N; i++){ two += givePoints(b[i], mapa, mapb, mapc); } for(int i = 0; i<N; i++){ three += givePoints(c[i], mapa, mapb, mapc); } pw.println(one + " " + two + " " + three); } pw.close(); } public static int givePoints(String word, HashMap<String, Integer> one, HashMap<String, Integer> two, HashMap<String, Integer> three) { int cnt = 0; cnt += contains(word, one) ? 1 : 0; cnt += contains(word,two) ? 1 : 0; cnt += contains(word, three) ? 1 : 0; if (cnt == 1) return 3; if (cnt == 2) return 1; return 0; } public static boolean contains(String word, HashMap<String, Integer> map){ return map.containsKey(word); } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
2266cbcdf712b23e8e84819ab314c4b0
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Scanner; public class WordGame { public static void main(String[] args) { int testCases; Scanner s = new Scanner(System.in); int numberWords; testCases = s.nextInt(); for (int i = 0; i < testCases; i++) { numberWords = s.nextInt(); int[] counts = { 0, 0, 0 }; HashMap<String, List<Integer>> h = new HashMap<String, List<Integer>>(); List<String> wordsPlayer1 = new ArrayList<String>(); List<String> wordsPlayer2 = new ArrayList<String>(); List<String> wordsPlayer3 = new ArrayList<String>(); for (List<String> wordsPlayer : List.of(wordsPlayer1, wordsPlayer2, wordsPlayer3)) { for (int j = 0; j < numberWords; j++) { wordsPlayer.add(s.next()); } } for (int j = 0; j < numberWords; j++) { List<Integer> l1 = new ArrayList<Integer>(); List<Integer> l2 = new ArrayList<Integer>(); List<Integer> l3 = new ArrayList<Integer>(); l1 = h.getOrDefault(wordsPlayer1.get(j), l1); h.put(wordsPlayer1.get(j), l1); l2 = h.getOrDefault(wordsPlayer2.get(j), l2); h.put(wordsPlayer2.get(j), l2); l3 = h.getOrDefault(wordsPlayer3.get(j), l3); h.put(wordsPlayer3.get(j), l3); l1.add(0); l2.add(1); l3.add(2); h.put(wordsPlayer1.get(j), l1); h.put(wordsPlayer2.get(j), l2); h.put(wordsPlayer3.get(j), l3); } for (String key : h.keySet()) { for (int idx : h.get(key)) { if (h.get(key).size() == 1) { counts[idx] += 3; } else if (h.get(key).size() == 2) { counts[idx] += 1; } } } System.out.println(String.format("%d %d %d", counts[0], counts[1], counts[2])); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
68352742f776feabe06524901609b176
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int test = sc.nextInt(); while(test-->0){ int res[] = new int[3]; int n = sc.nextInt(); String s[][] = new String[3][n]; HashMap<String, Integer> mp = new HashMap<>(); for(int i=0; i<3; i++){ for(int j=0; j<n; j++){ s[i][j] = sc.next(); if(!mp.containsKey(s[i][j])) mp.put(s[i][j],1); else mp.replace(s[i][j], mp.get(s[i][j])+1); } } for(int i=0; i<3; i++){ for(int j=0; j<n; j++){ int cur = mp.get(s[i][j]); if (cur==1) res[i]+=3; else if (cur==2) res[i]+=1; } System.out.print(res[i]); System.out.print(" "); } System.out.print("\n"); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
de15b1624f448a92e725c89b3dd1b0e3
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.io.BufferedReader; import java.io.*; import java.io.InputStreamReader; import java.util.Scanner; import java.util.*; public class Yoo { 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; } } static int gcd(int a, int b) { int result = Math.min(a, b); // Find Minimum of a nd b while (result > 0) { if (a % result == 0 && b % result == 0) { break; } result--; } return result; // return gcd of a nd b } public static void main(String[] args) { FastReader sc=new FastReader(); int i,j=0; int t = sc.nextInt(); while(t-->0) { int n = sc.nextInt(); HashSet<String> hm1 = new HashSet<String>(); HashSet<String> hm2 = new HashSet<String>(); HashSet<String> hm3 = new HashSet<String>(); for(i=0;i<n;i++) { hm1.add(sc.next()); } for(i=0;i<n;i++) { hm2.add(sc.next()); } for(i=0;i<n;i++) { hm3.add(sc.next()); } //System.out.println(hm1); //System.out.println(hm2); //System.out.println(hm3); Iterator<String> it1 = hm1.iterator(); Iterator<String> it2 = hm2.iterator(); Iterator<String> it3 = hm3.iterator(); long a= 0; long b= 0; long c= 0; while(it1.hasNext()) { String s = it1.next(); if(hm2.contains(s) && hm3.contains(s)) a=a; else if(hm2.contains(s) || hm3.contains(s) ) a++; else a+=3; } while(it2.hasNext()) { String s = it2.next(); if(hm1.contains(s) && hm3.contains(s)) b=b; else if(hm1.contains(s) || hm3.contains(s) ) b++; else b+=3; } while(it3.hasNext()) { String s = it3.next(); if(hm2.contains(s) && hm1.contains(s)) c=c; else if(hm2.contains(s) || hm1.contains(s) ) c++; else c+=3; } System.out.println(a+" "+b+" "+c); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
437bf5c283eaf61155ebfd21810a9a20
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
//package Algorithm; import java.awt.List; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.ListIterator; import java.util.Map; import java.util.PriorityQueue; import java.util.Queue; import java.util.Stack; import java.util.StringTokenizer; import javax.xml.stream.events.StartDocument; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); StringTokenizer st = new StringTokenizer(br.readLine()); int T = Integer.parseInt(st.nextToken()); for (int test = 1; test <= T; test++) { st = new StringTokenizer(br.readLine()); int N = Integer.parseInt(st.nextToken()); HashMap<String, Integer> a = new HashMap<>(); HashMap<String, Integer> b = new HashMap<>(); HashMap<String, Integer> c = new HashMap<>(); String[] str1 = new String[N]; String[] str2 = new String[N]; String[] str3 = new String[N]; st = new StringTokenizer(br.readLine()); for (int i = 0; i < N; i++) { str1[i] = st.nextToken(); a.put(str1[i],1); } st = new StringTokenizer(br.readLine()); for (int i = 0; i < N; i++) { str2[i] = st.nextToken(); b.put(str2[i],1); } st = new StringTokenizer(br.readLine()); for (int i = 0; i < N; i++) { str3[i] = st.nextToken(); c.put(str3[i],1); } int point1 = 0; int point2 = 0; int point3 = 0; for(int i=0;i<N;i++) { int check = 0; if(b.get(str1[i])!=null) { check++; } if(c.get(str1[i])!=null) { check++; } if(check==0) { point1 += 3; } else if(check==1) { point1++; } } for(int i=0;i<N;i++) { int check = 0; if(a.get(str2[i])!=null) { check++; } if(c.get(str2[i])!=null) { check++; } if(check==0) { point2 += 3; } else if(check==1) { point2++; } } for(int i=0;i<N;i++) { int check = 0; if(b.get(str3[i])!=null) { check++; } if(a.get(str3[i])!=null) { check++; } if(check==0) { point3 += 3; } else if(check==1) { point3++; } } bw.write(point1+" "+point2+" "+point3+"\n"); } bw.flush(); } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
1e7fd7823eefa88fb6b6af98faa4ff6a
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.io.*; import java.util.*; public class Solve { static final int MOD = 1000000007; static int count = 0; public static void main(String[] args) { Reader in = new Reader(); PrintWriter out = new PrintWriter(System.out); int t = in.readInt(); while (t-- > 0) solve(in, out); out.close(); } /* 3 1 abc def abc 3 orz for qaq qaq orz for cod for ces 5 iat roc hem ica lly bac ter iol ogi sts bac roc lly iol iat */ private static void solve(Reader in, PrintWriter out) { int n = in.readInt(); String a = in.readLine(); String b = in.readLine(); String c = in.readLine(); HashMap<String, Integer> map = new HashMap<>(); for (String i : a.split(" ")) { map.put(i, map.getOrDefault(i, 0) + 1); } for (String i : b.split(" ")) { map.put(i, map.getOrDefault(i, 0) + 1); } for (String i : c.split(" ")) { map.put(i, map.getOrDefault(i, 0) + 1); } int c1 = 0; for (String i : a.split(" ")) { if (map.get(i) == 1) { c1 += 3; } else if (map.get(i) == 2) { c1 += 1; } } int c2 = 0; for (String i : b.split(" ")) { if (map.get(i) == 1) { c2 += 3; } else if (map.get(i) == 2) { c2 += 1; } } int c3 = 0; for (String i : c.split(" ")) { if (map.get(i) == 1) { c3 += 3; } else if (map.get(i) == 2) { c3 += 1; } } out.println(c1 + " " + c2 + " " + c3); } private static int lowerBound(int[] nums, int target) { int low = 0; int high = nums.length - 1; int ans = -1; while (low <= high) { int mid = low + (high - low) / 2; if (nums[mid] == target) { ans = mid; high = mid - 1; } else { if (nums[mid] > target) { high = mid - 1; } else { low = mid + 1; } } } return ans; } private static int upperBound(int[] nums, int target) { int low = 0; int high = nums.length - 1; int ans = -1; while (low <= high) { int mid = low + (high - low) / 2; if (nums[mid] == target) { ans = mid; low = mid + 1; } else { if (nums[mid] > target) { high = mid - 1; } else { low = mid + 1; } } } return ans; } private static long power(long n, long p, long m) { long result = 1; while (p > 0) { if (p % 2 == 1) result = (result * n) % m; n = (n * n) % m; p >>= 1; } return result; } private int gcd(int a, int b) { if (b == 0) return a; else return gcd(b, a % b); } private static void sort(int a[], int n) { List<Integer> list = new ArrayList<>(); for (int i : a) list.add(i); Collections.sort(list); for (int i = 0; i < n; i++) a[i] = list.get(i); } private static void sieve(int n) { boolean[] prime = new boolean[n]; for (int i = 0; i < n; i++) prime[i] = true; for (int i = 2; i * i < n; i++) { if (prime[i]) { for (int j = i * i; j < n; j += i) prime[j] = false; } } for (int i = 2; i < prime.length; i++) { if (prime[i]) System.out.print(i + " "); } } private static void segmentedSieve(int low, int high) { int sqrt = (int) Math.sqrt(high); int[] prime = new int[sqrt + 1]; boolean[] arr = new boolean[sqrt + 1]; for (int i = 0; i <= sqrt; i++) arr[i] = true; int k = 0; for (int i = 2; i <= sqrt; i++) { // generate all prime numbers till square root of high if (arr[i]) { prime[k] = i; k++; for (int j = i * i; j <= sqrt; j += i) arr[j] = false; } } // System.out.println(Arrays.toString(prime)); int diff = high - low + 1; // arr size of required length arr = new boolean[diff]; for (int i = 0; i < diff; i++) arr[i] = true; for (int i = 0; i < k; i++) { // mark false to multiple of prime numbers in the range of low to high int div = (low / prime[i]) * prime[i]; // It gives multiple of prime[i] nearest to low if (div < low || div == prime[i]) div += prime[i]; for (int j = div; j <= high; j += prime[i]) { if (j != prime[i]) arr[j - low] = false; } } for (int i = 0; i < diff; i++) { // print prime numbers in the given segment if (arr[i] && (i + low) != 1) { System.out.print(i + low + " "); } } System.out.println(); } static class Pair implements Comparable<Pair> { int a; int b; public Pair(int a, int b) { this.a = a; this.b = b; } @Override public int compareTo(Pair o) { if (this.a > o.a) return this.a - o.a; else if (this.a < o.a) return this.b - o.b; else return 0; } } static class Reader { BufferedReader br; StringTokenizer st; public Reader() { br = new BufferedReader(new InputStreamReader(System.in)); } String read() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int readInt() { return Integer.parseInt(read()); } String readLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } long readLong() { return Long.parseLong(read()); } double readDouble() { return Double.parseDouble(read()); } int[] readIntArray(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = readInt(); return arr; } long[] readLongArray(int n) { long[] arr = new long[n]; for (int i = 0; i < n; i++) arr[i] = readLong(); return arr; } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
82d22ee8201d2428d04ce3025b34089e
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.io.IOException; import java.util.HashMap; import java.util.Scanner; public class test{ public static void main(String[] args) throws IOException { Scanner sc=new Scanner(System.in); int count=Integer.parseInt(sc.nextLine()); String[] arr=new String[3]; for(int i=0;i<count;i++){ int n=Integer.parseInt(sc.nextLine()); arr[0]=sc.nextLine(); arr[1]=sc.nextLine(); arr[2]=sc.nextLine(); HashMap<String,Integer> map=new HashMap<String,Integer>(); for(String str:arr){ String[] s=str.split(" "); for(String k:s){ if(map.get(k)==null) map.put(k,1); else map.put(k,map.get(k)+1); } } int score=0; for(String str:arr){ String[] s=str.split(" "); score=0; for(String k:s){ if(map.get(k)==1) score+=3; if(map.get(k)==2) score+=1; if(map.get(k)==3) score+=0; } System.out.print(score+" "); } System.out.print("\n"); } sc.close(); } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
17d48c6716d4e87aa0fcaf39b82cff0c
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.HashMap; import java.util.StringTokenizer; public class App { public static void main(String[] args) throws Exception { final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(reader.readLine()); while(t > 0) { solve(reader); t -= 1; } reader.close(); } public static void solve(BufferedReader reader) throws Exception { int n = Integer.parseInt(reader.readLine()); String [][] arr = new String[3][n]; HashMap<String, Integer> map = new HashMap<>(); for (int i = 0; i < 3; i++) { StringTokenizer st = new StringTokenizer(reader.readLine()); for (int j = 0; j < n; j++) { String current = st.nextToken(); arr[i][j] = current; map.putIfAbsent(current, 0); map.put(current, map.get(current) + 1); } } for (int i = 0; i < 3; i++) { int point = 0; for (int j = 0; j < n; j++) { if(map.get(arr[i][j]) == 1) { point += 3; continue; } if(map.get(arr[i][j]) == 2) { point += 1; continue; } } System.out.print(point + " "); } System.out.println(); } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
490a044a97d77698462e5c30bc63a507
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.*; public class Main { public static void main(String []args) { Scanner scan = new Scanner(System.in); int testCases = scan.nextInt(); for(int q = 0; q < testCases; q++) { int n = scan.nextInt(); String [][] input = new String[3][n]; Map<String, Integer> map = new Hashtable<>(); for(int i = 0; i < 3; i++) { for(int j = 0; j < n; j++) { input[i][j] = scan.next(); if(map.containsKey(input[i][j])) { map.put(input[i][j], map.get(input[i][j]) + 1); } else { map.put(input[i][j], 1); } } } int []ans = new int[3]; for(int i = 0; i < 3; i++) { for(int j = 0; j < n; j++) { if(i == 0) { if(map.get(input[i][j]) == 1) ans[0] += 3; else if(map.get(input[i][j]) == 2) ans[0] += 1; } else if(i == 1) { if(map.get(input[i][j]) == 1) ans[1] += 3; else if(map.get(input[i][j]) == 2) ans[1] += 1; } else { if(map.get(input[i][j]) == 1) ans[2] += 3; else if(map.get(input[i][j]) == 2) ans[2] += 1; } } } for(int item : ans) System.out.print(item + " "); System.out.println(); } } // end of main method } // end of Main class
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
096f2e9766b3d8d6366f93fc293dfc17
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.InputStreamReader; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.stream.Collectors; public class App { public static void main(String[] args) throws Exception { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); //BufferedReader reader = new BufferedReader(new FileReader(new File("C:\\Development\\MyProjects\\EducationProject\\src\\main\\java\\ru\\ilbagmanov\\randomcode\\inp.txt"))); int n = Integer.parseInt(reader.readLine()); for (int i = 0; i < n; i++) { int s = Integer.parseInt(reader.readLine()); String[] a = reader.readLine().split(" "); String[] b = reader.readLine().split(" "); String[] c = reader.readLine().split(" "); Set<String> hashA = new HashSet<>(Arrays.asList(a)); Set<String> hashB = new HashSet<>(Arrays.asList(b)); Set<String> hashC = new HashSet<>(Arrays.asList(c)); int sumA = 0; for (int j = 0; j < a.length; j++) { boolean flag1 = hashB.contains(a[j]); boolean flag2 = hashC.contains(a[j]); if (flag1 == flag2 && !flag1) sumA += 3; else if (flag1 != flag2) sumA += 1; } int sumB = 0; for (int j = 0; j < b.length; j++) { boolean flag1 = hashA.contains(b[j]); boolean flag2 = hashC.contains(b[j]); if (flag1 == flag2 && !flag1) sumB += 3; else if (flag1 != flag2) sumB += 1; } int sumC = 0; for (int j = 0; j < c.length; j++) { boolean flag1 = hashB.contains(c[j]); boolean flag2 = hashA.contains(c[j]); if (flag1 == flag2 && !flag1) sumC += 3; else if (flag1 != flag2) sumC += 1; } System.out.printf("%d %d %d\n", sumA, sumB, sumC); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
3d16f7df623500bc687517dd27d50765
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.*; public class Word { 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(); Set<String> s1 = new HashSet<>(); Set<String> s2 = new HashSet<>(); Set<String> s3 = new HashSet<>(); Set<String> h1 = new HashSet<>(); Set<String> h2 = new HashSet<>(); Set<String> h3 = new HashSet<>(); Set<String> merge12 = new HashSet<>(); Set<String> merge13 = new HashSet<>(); Set<String> merge23 = new HashSet<>(); for (int i = 0; i < n; i++) { String s = sc.next(); merge12.add(s); merge13.add(s); s1.add(s); h1.add(s); } for (int i = 0; i < n; i++) { String s = sc.next(); merge12.add(s); merge23.add(s); s2.add(s); h2.add(s); } for (int i = 0; i < n; i++) { String s = sc.next(); merge13.add(s); merge23.add(s); s3.add(s); h3.add(s); } s3.removeAll(h2); s3.removeAll(h1); s1.removeAll(h2); s1.removeAll(h3); s2.removeAll(h1); s2.removeAll(h3); merge13.removeAll(h2); merge13.removeAll(s1); merge13.removeAll(s3); merge12.removeAll(h3); merge12.removeAll(s1); merge12.removeAll(s2); merge23.removeAll(h1); merge23.removeAll(s3); merge23.removeAll(s2); int comon12 = merge12.size(); int comon13 = merge13.size(); int comon23 = merge23.size(); int score1 = comon12 + comon13 + (s1.size()) * 3; int score2 = comon12 + comon23 + (s2.size()) * 3; int score3 = comon23 + comon13 + (s3.size()) * 3; System.out.println(score1 + " " + score2 + " " + score3); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
4e2ec282c69fd71d7d1d4ac08002511a
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
//package com.company; import com.sun.source.tree.Tree; import java.io.*; import java.util.*; public class Q1 { public static void main(String[] args) throws Exception{ Reader1.init(System.in); BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out)); int t = Reader1.nextInt(); while (t-- > 0) { int n = Reader1.nextInt(); HashMap<String,Integer> map = new HashMap<>(); String[][] mat = new String[3][n]; for (int i=0;i<3;i++) { //System.out.println(i); String[] arr = Reader1.nextLine().split(" "); //System.out.println(arr.length + " " + arr[0]); for (int j=0;j<arr.length;j++) { //System.out.println(i + " " + j); mat[i][j] = arr[j]; //System.out.println(i + " " + j); if (map.containsKey(arr[j])) map.replace(arr[j],map.get(arr[j]),map.get(arr[j])+1); else map.put(arr[j],1); } //mat[i] = arr; } //System.out.println(map); int[] scores = new int[3]; for (int i=0;i<3;i++) { for (int j=0;j<n;j++) { if (map.get(mat[i][j])==1) scores[i]+=3; if (map.get(mat[i][j])==2) scores[i]+=1; } } System.out.println(scores[0] + " " + scores[1] + " " + scores[2]); } } static void sieveOfEratosthenes(int N,int s[]) { boolean[] prime = new boolean[N + 1]; // for all the even numbers for (int i = 2; i <= N; i += 2) s[i] = 2; // For odd numbers less // then equal to n for (int i = 3; i <= N; i += 2) { if (prime[i] == false) { // s(i) for a prime is // the number itself s[i] = i; // For all multiples of // current prime number for (int j = i; j * i <= N; j += 2) { if (prime[i * j] == false) { prime[i * j] = true; // i is the smallest prime // factor for number "i*j". s[i * j] = i; } } } } } public static TreeMap<Integer,Integer> generatePrimeFactors(int N) { TreeMap<Integer,Integer> m = new TreeMap<>(); // s[i] is going to store // smallest prime factor of i. int[] s = new int[N + 1]; // Filling values in s[] using sieve sieveOfEratosthenes(N, s); int curr = s[N]; // Current prime factor of N int cnt = 1; // Power of current prime factor while (N > 1) { N /= s[N]; if (curr == s[N]) { cnt++; continue; } m.put(curr,cnt); curr = s[N]; cnt = 1; } return m; } static long modFact(int n,int p) { if (n >= p) return 0; long result = 1; for (int i = 1; i <= n; i++) result = (result * i) % p; return result; } } class Reader1 { static BufferedReader reader; static StringTokenizer tokenizer; /** call this method to initialize reader for InputStream */ static void init(InputStream input) { reader = new BufferedReader( new InputStreamReader(input) ); tokenizer = new StringTokenizer(""); } /** get next word */ static String next() throws IOException { while ( ! tokenizer.hasMoreTokens() ) { //TODO add check for eof if necessary tokenizer = new StringTokenizer( reader.readLine() ); } return tokenizer.nextToken(); } static String nextLine() throws IOException { return reader.readLine(); } static int nextInt() throws IOException { return Integer.parseInt( next() ); } static long nextLong() throws IOException{ return Long.parseLong(next() ); } static double nextDouble() throws IOException { return Double.parseDouble( next() ); } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
ceee1065ee20455152deb0cf47c31de6
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.io.*; import java.util.*; public class MyOwn { static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer st; public static int[] arr = new int[5]; public static String s, s1; public static void main(String args[]) throws IOException{ int t = readInt(); int n, score1=0, score2=0, score3=0; String temp; for(int q = 0; q < t; q++) { HashMap<String, Integer> p1 = new HashMap<String, Integer>(); HashMap<String, Integer> p2 = new HashMap<String, Integer>(); HashMap<String, Integer> p3 = new HashMap<String, Integer>(); n=readInt(); score1=n*3; score2=n*3; score3=n*3; for(int i = 0; i < n; i++) { temp=next(); p1.put(temp, 1); } for(int i = 0;i < n; i++) { temp=next(); p2.put(temp, 1); if(p1.containsKey(temp)) { score1-=2; score2-=2; } } for(int i = 0; i < n; i++) { temp=next(); p3.put(temp, 1); if(p1.containsKey(temp) && p2.containsKey(temp)) { score1-=1; score2-=1; score3-=3; }else if(p1.containsKey(temp)) { score1-=2; score3-=2; }else if(p2.containsKey(temp)) { score2-=2; score3-=2; } } System.out.println(score1 + " " + score2 + " " + score3); } } 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 String readLine() throws IOException { return br.readLine().trim(); } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
76e574c20c782b7ea99a6aec4225f530
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.*; import java.io.*; public class IO{ 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){ // write code here int n = in.nextInt(); String arr[][] = new String[3][n]; HashMap<String , Integer> map = new HashMap<>(); for(int i = 0 ; i < 3 ; i++) { for(int j = 0 ; j < n ; j++) { arr[i][j]=in.next(); map.put(arr[i][j], map.getOrDefault(arr[i][j],0)+1); } } for(int i = 0 ; i < 3 ; i++) { int ans = 0; for(int j = 0 ; j < n ; j++) { if(map.get(arr[i][j])==1) ans+=3; else if(map.get(arr[i][j])==2) ans++; } out.print(ans+" "); } out.println(" "); } out.close(); } catch (Exception e) { return; } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
8fbd89facf9061caa7b6426dcdd2108d
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
// JAI SHREE RAM, HAR HAR MAHADEV, HARE KRISHNA import java.util.*; import java.util.Map.Entry; import java.util.stream.*; import java.lang.*; import java.math.BigInteger; import java.text.DecimalFormat; import java.io.*; public class CodeForces { static private final String INPUT = "input.txt"; static private final String OUTPUT = "output.txt"; static BufferedReader BR = new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer ST; static PrintWriter out = new PrintWriter(System.out); static DecimalFormat df = new DecimalFormat("0.00"); final static int MAX = Integer.MAX_VALUE, MIN = Integer.MIN_VALUE, mod = (int) (1e9 + 7); final static long LMAX = Long.MAX_VALUE, LMIN = Long.MIN_VALUE; final static long INF = (long) 1e18, Neg_INF = (long) -1e18; static Random rand = new Random(); // ======================= MAIN ================================== public static void main(String[] args) throws IOException { long time = System.currentTimeMillis(); boolean oj = System.getProperty("ONLINE_JUDGE") != null; // ==== start ==== input(); preprocess(); int t = 1; t = readInt(); while (t-- > 0) { solve(); } out.flush(); // ==== end ==== if (!oj) System.out.println(Arrays.deepToString(new Object[] { System.currentTimeMillis() - time + " ms" })); } private static void solve() throws IOException { int n = readInt(); Set<String> s1 = new HashSet<>(), s2 = new HashSet<>(), s3 = new HashSet<>(); Map<String, Integer> map = new HashMap<>(); for (int j = 0; j < n; j++) { String s = readString(); map.put(s, map.getOrDefault(s, 0) + 1); s1.add(s); } for (int j = 0; j < n; j++) { String s = readString(); map.put(s, map.getOrDefault(s, 0) + 1); s2.add(s); } for (int j = 0; j < n; j++) { String s = readString(); map.put(s, map.getOrDefault(s, 0) + 1); s3.add(s); } int a1 = 0, a2 = 0, a3 = 0; for (String s : s1) { if (map.get(s) == 1) a1 += 3; else if (map.get(s) == 2) a1++; } for (String s : s2) { if (map.get(s) == 1) a2 += 3; else if (map.get(s) == 2) a2++; } for (String s : s3) { if (map.get(s) == 1) a3 += 3; else if (map.get(s) == 2) a3++; } out.println(a1 + " " + a2 + " " + a3); } private static void preprocess() throws IOException { } // cd C:\Users\Eshan Bhatt\Visual Studio Code\Competitive Programming\CodeForces // javac CodeForces.java && java CodeForces // change Stack size -> java -Xss16M CodeForces.java // ==================== CUSTOM CLASSES ================================ static class Pair implements Comparable<Pair> { int first, second; Pair(int f, int s) { first = f; second = s; } public int compareTo(Pair o) { if (this.first == o.first) return this.second - o.second; return this.first - o.first; } @Override public boolean equals(Object obj) { if (obj == this) return true; if (obj == null) return false; if (this.getClass() != obj.getClass()) return false; Pair other = (Pair) (obj); if (this.first != other.first) return false; if (this.second != other.second) return false; return true; } @Override public int hashCode() { return this.first ^ this.second; } @Override public String toString() { return this.first + " " + this.second; } } static class DequeNode { DequeNode prev, next; int val; DequeNode(int val) { this.val = val; } DequeNode(int val, DequeNode prev, DequeNode next) { this.val = val; this.prev = prev; this.next = next; } } // ======================= FOR INPUT ================================== private static void input() { FileInputStream instream = null; PrintStream outstream = null; try { instream = new FileInputStream(INPUT); outstream = new PrintStream(new FileOutputStream(OUTPUT)); System.setIn(instream); System.setOut(outstream); } catch (Exception e) { System.err.println("Error Occurred."); } BR = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); } static String next() throws IOException { while (ST == null || !ST.hasMoreTokens()) ST = new StringTokenizer(readLine()); return ST.nextToken(); } static long readLong() throws IOException { return Long.parseLong(next()); } static int readInt() throws IOException { return Integer.parseInt(next()); } static double readDouble() throws IOException { return Double.parseDouble(next()); } static char readCharacter() throws IOException { return next().charAt(0); } static String readString() throws IOException { return next(); } static String readLine() throws IOException { return BR.readLine().trim(); } static int[] readIntArray(int n) throws IOException { int[] arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = readInt(); return arr; } static int[][] read2DIntArray(int n, int m) throws IOException { int[][] arr = new int[n][m]; for (int i = 0; i < n; i++) arr[i] = readIntArray(m); return arr; } static List<Integer> readIntList(int n) throws IOException { List<Integer> list = new ArrayList<>(n); for (int i = 0; i < n; i++) list.add(readInt()); return list; } static long[] readLongArray(int n) throws IOException { long[] arr = new long[n]; for (int i = 0; i < n; i++) arr[i] = readLong(); return arr; } static long[][] read2DLongArray(int n, int m) throws IOException { long[][] arr = new long[n][m]; for (int i = 0; i < n; i++) arr[i] = readLongArray(m); return arr; } static List<Long> readLongList(int n) throws IOException { List<Long> list = new ArrayList<>(n); for (int i = 0; i < n; i++) list.add(readLong()); return list; } static char[] readCharArray() throws IOException { return readString().toCharArray(); } static char[][] readMatrix(int n, int m) throws IOException { char[][] mat = new char[n][m]; for (int i = 0; i < n; i++) mat[i] = readCharArray(); return mat; } // ========================= FOR OUTPUT ================================== private static void printIList(List<Integer> list) { for (int i = 0; i < list.size(); i++) out.print(list.get(i) + " "); out.println(" "); } private static void printLList(List<Long> list) { for (int i = 0; i < list.size(); i++) out.print(list.get(i) + " "); out.println(" "); } private static void printIArray(int[] arr) { for (int i = 0; i < arr.length; i++) out.print(arr[i] + " "); out.println(" "); } private static void print2DIArray(int[][] arr) { for (int i = 0; i < arr.length; i++) printIArray(arr[i]); } private static void printLArray(long[] arr) { for (int i = 0; i < arr.length; i++) out.print(arr[i] + " "); out.println(" "); } private static void print2DLArray(long[][] arr) { for (int i = 0; i < arr.length; i++) printLArray(arr[i]); } private static void yes() { out.println("YES"); } private static void no() { out.println("NO"); } // ====================== TO CHECK IF STRING IS NUMBER ======================== private static boolean isInteger(String s) { try { Integer.parseInt(s); } catch (NumberFormatException e) { return false; } catch (NullPointerException e) { return false; } return true; } private static boolean isLong(String s) { try { Long.parseLong(s); } catch (NumberFormatException e) { return false; } catch (NullPointerException e) { return false; } return true; } // ==================== FASTER SORT ================================ private static void sort(int[] arr) { int n = arr.length; List<Integer> list = new ArrayList<>(n); for (int i = 0; i < n; i++) list.add(arr[i]); Collections.sort(list); for (int i = 0; i < n; i++) arr[i] = list.get(i); } private static void reverseSort(int[] arr) { int n = arr.length; List<Integer> list = new ArrayList<>(n); for (int i = 0; i < n; i++) list.add(arr[i]); Collections.sort(list, Collections.reverseOrder()); for (int i = 0; i < n; i++) arr[i] = list.get(i); } private static void sort(long[] arr) { int n = arr.length; List<Long> list = new ArrayList<>(n); for (int i = 0; i < n; i++) list.add(arr[i]); Collections.sort(list); for (int i = 0; i < n; i++) arr[i] = list.get(i); } private static void reverseSort(long[] arr) { int n = arr.length; List<Long> list = new ArrayList<>(n); for (int i = 0; i < n; i++) list.add(arr[i]); Collections.sort(list, Collections.reverseOrder()); for (int i = 0; i < n; i++) arr[i] = list.get(i); } // ==================== MATHEMATICAL FUNCTIONS =========================== private static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } private static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } private static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } private static long lcm(long a, long b) { return (a / gcd(a, b)) * b; } private static int mod_pow(long a, long b, int mod) { if (b == 0) return 1; int temp = mod_pow(a, b >> 1, mod); temp %= mod; temp = (int) ((1L * temp * temp) % mod); if ((b & 1) == 1) temp = (int) ((1L * temp * a) % mod); return temp; } private static long multiply(long a, long b) { return (((a % mod) * (b % mod)) % mod); } private static long divide(long a, long b) { return multiply(a, mod_pow(b, mod - 2, mod)); } private static boolean isPrime(long n) { for (long i = 2; i * i <= n; i++) if (n % i == 0) return false; return true; } private static long nCr(long n, long r) { if (n - r > r) r = n - r; long ans = 1L; for (long i = r + 1; i <= n; i++) ans *= i; for (long i = 2; i <= n - r; i++) ans /= i; return ans; } private static List<Integer> factors(int n) { List<Integer> list = new ArrayList<>(); for (int i = 1; 1L * i * i <= n; i++) if (n % i == 0) { list.add(i); if (i != n / i) list.add(n / i); } return list; } private static List<Long> factors(long n) { List<Long> list = new ArrayList<>(); for (long i = 1; i * i <= n; i++) if (n % i == 0) { list.add(i); if (i != n / i) list.add(n / i); } return list; } // ==================== Primes using Seive ===================== private static List<Integer> getPrimes(int n) { boolean[] prime = new boolean[n + 1]; Arrays.fill(prime, true); for (int i = 2; 1L * i * i <= n; i++) if (prime[i]) for (int j = i * i; j <= n; j += i) prime[j] = false; // return prime; List<Integer> list = new ArrayList<>(); for (int i = 2; i <= n; i++) if (prime[i]) list.add(i); return list; } private static int[] SeivePrime(int n) { int[] primes = new int[n]; for (int i = 0; i < n; i++) primes[i] = i; for (int i = 2; 1L * i * i < n; i++) { if (primes[i] != i) continue; for (int j = i * i; j < n; j += i) if (primes[j] == j) primes[j] = i; } return primes; } // ==================== STRING FUNCTIONS ================================ private static boolean isPalindrome(String str) { int i = 0, j = str.length() - 1; while (i < j) if (str.charAt(i++) != str.charAt(j--)) return false; return true; } // check if a is subsequence of b private static boolean isSubsequence(String a, String b) { int idx = 0; for (int i = 0; i < b.length() && idx < a.length(); i++) if (a.charAt(idx) == b.charAt(i)) idx++; return idx == a.length(); } private static String reverseString(String str) { StringBuilder sb = new StringBuilder(str); return sb.reverse().toString(); } private static String sortString(String str) { int[] arr = new int[256]; for (char ch : str.toCharArray()) arr[ch]++; StringBuilder sb = new StringBuilder(); for (int i = 0; i < 256; i++) while (arr[i]-- > 0) sb.append((char) i); return sb.toString(); } // ==================== LIS & LNDS ================================ private static int LIS(int arr[], int n) { List<Integer> list = new ArrayList<>(); for (int i = 0; i < n; i++) { int idx = find1(list, arr[i]); if (idx < list.size()) list.set(idx, arr[i]); else list.add(arr[i]); } return list.size(); } private static int find1(List<Integer> list, int val) { int ret = list.size(), i = 0, j = list.size() - 1; while (i <= j) { int mid = (i + j) / 2; if (list.get(mid) >= val) { ret = mid; j = mid - 1; } else { i = mid + 1; } } return ret; } private static int LNDS(int[] arr, int n) { List<Integer> list = new ArrayList<>(); for (int i = 0; i < n; i++) { int idx = find2(list, arr[i]); if (idx < list.size()) list.set(idx, arr[i]); else list.add(arr[i]); } return list.size(); } private static int find2(List<Integer> list, int val) { int ret = list.size(), i = 0, j = list.size() - 1; while (i <= j) { int mid = (i + j) / 2; if (list.get(mid) <= val) { i = mid + 1; } else { ret = mid; j = mid - 1; } } return ret; } // =============== Lower Bound & Upper Bound =========== // less than or equal private static int lower_bound(List<Integer> list, int val) { int ans = -1, lo = 0, hi = list.size() - 1; while (lo <= hi) { int mid = (lo + hi) / 2; if (list.get(mid) <= val) { ans = mid; lo = mid + 1; } else { hi = mid - 1; } } return ans; } private static int lower_bound(List<Long> list, long val) { int ans = -1, lo = 0, hi = list.size() - 1; while (lo <= hi) { int mid = (lo + hi) / 2; if (list.get(mid) <= val) { ans = mid; lo = mid + 1; } else { hi = mid - 1; } } return ans; } private static int lower_bound(int[] arr, int val) { int ans = -1, lo = 0, hi = arr.length - 1; while (lo <= hi) { int mid = (lo + hi) / 2; if (arr[mid] <= val) { ans = mid; lo = mid + 1; } else { hi = mid - 1; } } return ans; } private static int lower_bound(long[] arr, long val) { int ans = -1, lo = 0, hi = arr.length - 1; while (lo <= hi) { int mid = (lo + hi) / 2; if (arr[mid] <= val) { ans = mid; lo = mid + 1; } else { hi = mid - 1; } } return ans; } // greater than or equal private static int upper_bound(List<Integer> list, int val) { int ans = list.size(), lo = 0, hi = ans - 1; while (lo <= hi) { int mid = (lo + hi) / 2; if (list.get(mid) >= val) { ans = mid; hi = mid - 1; } else { lo = mid + 1; } } return ans; } private static int upper_bound(List<Long> list, long val) { int ans = list.size(), lo = 0, hi = ans - 1; while (lo <= hi) { int mid = (lo + hi) / 2; if (list.get(mid) >= val) { ans = mid; hi = mid - 1; } else { lo = mid + 1; } } return ans; } private static int upper_bound(int[] arr, int val) { int ans = arr.length, lo = 0, hi = ans - 1; while (lo <= hi) { int mid = (lo + hi) / 2; if (arr[mid] >= val) { ans = mid; hi = mid - 1; } else { lo = mid + 1; } } return ans; } private static int upper_bound(long[] arr, long val) { int ans = arr.length, lo = 0, hi = ans - 1; while (lo <= hi) { int mid = (lo + hi) / 2; if (arr[mid] >= val) { ans = mid; hi = mid - 1; } else { lo = mid + 1; } } return ans; } // ==================== UNION FIND ===================== private static int find(int x, int[] parent) { if (parent[x] == x) return x; return parent[x] = find(parent[x], parent); } private static boolean union(int x, int y, int[] parent, int[] rank) { int lx = find(x, parent), ly = find(y, parent); if (lx == ly) return false; if (rank[lx] > rank[ly]) parent[ly] = lx; else if (rank[lx] < rank[ly]) parent[lx] = ly; else { parent[lx] = ly; rank[ly]++; } return true; } // ==================== TRIE ================================ static class Trie { class Node { Node[] children; boolean isEnd; Node() { children = new Node[26]; } } Node root; Trie() { root = new Node(); } boolean insert(String word) { Node curr = root; boolean ans = true; for (char ch : word.toCharArray()) { if (curr.children[ch - 'a'] == null) curr.children[ch - 'a'] = new Node(); curr = curr.children[ch - 'a']; if (curr.isEnd) ans = false; } curr.isEnd = true; return ans; } boolean find(String word) { Node curr = root; for (char ch : word.toCharArray()) { if (curr.children[ch - 'a'] == null) return false; curr = curr.children[ch - 'a']; } return curr.isEnd; } } // ================== SEGMENT TREE (RANGE SUM & RANGE UPDATE) ================== public static class SegmentTree { int n; long[] arr, tree, lazy; SegmentTree(long arr[]) { this.arr = arr; this.n = arr.length; this.tree = new long[(n << 2)]; this.lazy = new long[(n << 2)]; build(1, 0, n - 1); } void build(int id, int start, int end) { if (start == end) tree[id] = arr[start]; else { int mid = (start + end) / 2, left = (id << 1), right = left + 1; build(left, start, mid); build(right, mid + 1, end); tree[id] = tree[left] + tree[right]; } } void update(int l, int r, long val) { update(1, 0, n - 1, l, r, val); } void update(int id, int start, int end, int l, int r, long val) { distribute(id, start, end); if (end < l || r < start) return; if (start == end) tree[id] += val; else if (l <= start && end <= r) { lazy[id] += val; distribute(id, start, end); } else { int mid = (start + end) / 2, left = (id << 1), right = left + 1; update(left, start, mid, l, r, val); update(right, mid + 1, end, l, r, val); tree[id] = tree[left] + tree[right]; } } long query(int l, int r) { return query(1, 0, n - 1, l, r); } long query(int id, int start, int end, int l, int r) { if (end < l || r < start) return 0L; distribute(id, start, end); if (start == end) return tree[id]; else if (l <= start && end <= r) return tree[id]; else { int mid = (start + end) / 2, left = (id << 1), right = left + 1; return query(left, start, mid, l, r) + query(right, mid + 1, end, l, r); } } void distribute(int id, int start, int end) { if (start == end) tree[id] += lazy[id]; else { tree[id] += lazy[id] * (end - start + 1); lazy[(id << 1)] += lazy[id]; lazy[(id << 1) + 1] += lazy[id]; } lazy[id] = 0; } } // ==================== FENWICK TREE ================================ static class FT { int n; int[] arr; int[] tree; FT(int[] arr, int n) { this.arr = arr; this.n = n; this.tree = new int[n + 1]; for (int i = 1; i <= n; i++) { update(i, arr[i - 1]); } } FT(int n) { this.n = n; this.tree = new int[n + 1]; } // 1 based indexing void update(int idx, int val) { while (idx <= n) { tree[idx] += val; idx += idx & -idx; } } // 1 based indexing int query(int l, int r) { return getSum(r) - getSum(l - 1); } int getSum(int idx) { int ans = 0; while (idx > 0) { ans += tree[idx]; idx -= idx & -idx; } return ans; } } // ==================== BINARY INDEX TREE ================================ static class BIT { long[][] tree; int n, m; BIT(int[][] mat, int n, int m) { this.n = n; this.m = m; tree = new long[n + 1][m + 1]; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { update(i, j, mat[i - 1][j - 1]); } } } void update(int x, int y, int val) { while (x <= n) { int t = y; while (t <= m) { tree[x][t] += val; t += t & -t; } x += x & -x; } } long query(int x1, int y1, int x2, int y2) { return getSum(x2, y2) - getSum(x1 - 1, y2) - getSum(x2, y1 - 1) + getSum(x1 - 1, y1 - 1); } long getSum(int x, int y) { long ans = 0L; while (x > 0) { int t = y; while (t > 0) { ans += tree[x][t]; t -= t & -t; } x -= x & -x; } return ans; } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
c446c1c655adb366dbc0bd43359a299f
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class CodeForces { static HashMap<String,Integer> m = new HashMap<>(); static void pushIntoMap(String s[]) { for (int i = 0; i < s.length; i++) { if (m.containsKey(s[i])) m.put(s[i], m.get(s[i]) + 1); else m.put(s[i], 1); } } static int getPoints(String s[]) { int ans = 0; for (int i = 0; i < s.length; i++) { if (m.get(s[i]) == 1) ans += 3; else if (m.get(s[i]) == 2) ans += 1; } return ans; } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); while (t-- > 0) { int n = Integer.parseInt(br.readLine()); String a[] = br.readLine().split(" "); String b[] = br.readLine().split(" "); String c[] = br.readLine().split(" "); m.clear(); pushIntoMap(a); pushIntoMap(b); pushIntoMap(c); int p1 = getPoints(a); int p2 = getPoints(b); int p3 = getPoints(c); System.out.print(p1 + " " + p2 + " " + p3); System.out.println(); } br.close(); } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
d29716b8480aa973e8b5ceb8fa0d1405
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.HashMap; import java.util.StringTokenizer; public class CF1722C { public static void main(String[] args) throws IOException { InputReader in = new InputReader(); int t = in.readInt(); for(; t>0; t--) { int n = in.readInt(); HashMap<String, ArrayList<Integer>> map = new HashMap<>(); int a=0, b=0, c=0; String[] s = in.readStringArray(n); for(int i=0; i<n; i++) { map.put(s[i], new ArrayList<Integer>()); map.get(s[i]).add(1); } s = in.readStringArray(n); for(int i=0; i<n; i++) { if(map.containsKey(s[i])) { map.get(s[i]).add(2); } else { map.put(s[i], new ArrayList<Integer>()); map.get(s[i]).add(2); } } s = in.readStringArray(n); for(int i=0; i<n; i++) { if(map.containsKey(s[i])) { map.get(s[i]).add(3); } else { map.put(s[i], new ArrayList<Integer>()); map.get(s[i]).add(3); } } for(String k: map.keySet()) { ArrayList<Integer> list = map.get(k); // System.out.println(k + " " + list); if(list.size() == 3) continue; else if(list.size() == 2) { if(list.get(0)==1 || list.get(1)==1) a++; if(list.get(0)==2 || list.get(1)==2) b++; if(list.get(0)==3 || list.get(1)==3) c++; } else { if(list.get(0)==1) a+=3; else if(list.get(0)==2) b+=3; else c+=3; } } System.out.println(a + " " + b + " " + c); } } public static class InputReader { static BufferedReader br; static StringTokenizer st; InputReader() { br = new BufferedReader(new InputStreamReader(System.in)); } public String read() throws IOException { return br.readLine().trim(); } public int readInt() throws IOException { return Integer.parseInt(br.readLine().trim()); } public long readLong() throws IOException { return Long.parseLong(br.readLine().trim()); } public int[] readArray(int len) throws IOException { int[] a = new int[len]; st = new StringTokenizer(br.readLine().trim()); int pos = 0; for(;st.hasMoreTokens();) { a[pos++] = Integer.parseInt(st.nextToken()); } return a; } public long[] readLongArray(int len) throws IOException { long[] a = new long[len]; st = new StringTokenizer(br.readLine().trim()); int pos = 0; for(;st.hasMoreTokens();) { a[pos++] = Long.parseLong(st.nextToken()); } return a; } public String[] readStringArray(int len) throws IOException { return br.readLine().trim().split(" "); } public long[][] readLongIndexArray(int len) throws IOException { long[][] a = new long[len][2]; st = new StringTokenizer(br.readLine().trim()); int pos = 0; for(;st.hasMoreTokens();) { a[pos][1] = pos; a[pos++][0] = Long.parseLong(st.nextToken()); } return a; } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
d6b31f6bbf3b3444364620fa8c34a8f4
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.*; public class Main{ public static void main(String[] args){ Scanner scan = new Scanner(System.in); int t = scan.nextInt(); Map<String, Integer> a = new HashMap<>(); Map<String, Integer> b = new HashMap<>(); Map<String, Integer> c = new HashMap<>(); while(t > 0){ int n = scan.nextInt(); --t; for(int i = 0; i < n; i++) a.put(scan.next(), 1); for(int i = 0; i < n; i++){ String str = scan.next(); if(a.containsKey(str)){ a.put(str, a.get(str) + 1); b.put(str, a.get(str)); }else b.put(str, 1); } for(int i = 0; i < n; i++){ String str = scan.next(); if(a.containsKey(str) && !b.containsKey(str)){ a.put(str, a.get(str) + 1); c.put(str, a.get(str)); }else if(!a.containsKey(str) && b.containsKey(str)){ b.put(str, b.get(str) + 1); c.put(str, b.get(str)); }else if(a.containsKey(str) && b.containsKey(str)){ a.put(str, a.get(str) + 1); b.put(str, a.get(str)); c.put(str, a.get(str)); }else c.put(str, 1); } System.out.println(getScore(a) + " " + getScore(b) + " " + getScore(c)); a.clear(); b.clear(); c.clear(); } } public static int getScore(Map<String, Integer> map){ Set<String> set = map.keySet(); Iterator<String> it = set.iterator(); int score = 0; while(it.hasNext()){ String s = it.next(); if(map.get(s) == 1) score += 3; else if(map.get(s) == 2) score += 1; } return score; } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
9a18b634de34ac836717a0f78343ec9f
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.io.*; import java.util.*; public class SpellCheck { public static void main(String[] args) throws IOException { //Scanner sc= new Scanner(System.in); BufferedReader sc=new BufferedReader(new InputStreamReader(System.in)); int t=Integer.parseInt(sc.readLine()); for(int i=0;i<t;i++) { int n=Integer.parseInt(sc.readLine()); String pt1=sc.readLine(); String pt2=sc.readLine(); String pt3=sc.readLine(); String[] p1=pt1.split(" "); String[] p2=pt2.split(" "); String[] p3=pt3.split(" "); int c1=3*n,c2=3*n,c3=3*n; HashSet<String> hs1=new HashSet<String>(); HashSet<String> hs2=new HashSet<String>(); HashSet<String> hs3=new HashSet<String>(); for(int j=0;j<n;j++) { hs1.add(p1[j]); hs2.add(p2[j]); hs3.add(p3[j]); } for(int j=0;j<n;j++) { if(hs2.contains(p1[j])) { if(hs3.contains(p1[j])) { c1=c1-3; c2=c2-3; c3=c3-3; } else { c1=c1-2; c2=c2-2; } } else if(hs3.contains(p1[j])) { c1=c1-2; c3=c3-2; } if(hs3.contains(p2[j]) && !(hs1.contains(p2[j]))) { c2=c2-2; c3=c3-2; } } System.out.println(c1+" "+c2+" "+c3); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
4b26efb5e490388f8d6e4bed871d448e
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class Solution { 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 static final class Pair<T1, T2> { public T1 first; public T2 second; public Pair() { first = null; second = null; } public Pair(T1 firstValue, T2 secondValue) { first = firstValue; second = secondValue; } public Pair(Pair<T1, T2> pair) { first = pair.first; second = pair.second; } } public static void main(String[] args) { RealScanner sc = new RealScanner(); PrintWriter out = new PrintWriter(System.out); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); String[][] s = new String[3][n]; Map<String, Integer> map = new HashMap<>(); for (int i = 0; i < 3; i++) { for (int j = 0; j < n; j++) { s[i][j] = sc.next(); map.put(s[i][j], map.getOrDefault(s[i][j], 0) + 1); } } for (int i = 0; i < 3; i++) { int count = 0; for (int j = 0; j < n; j++) { String check = s[i][j]; int val = map.get(check); if (val == 1) { count += 3; } else if (val == 2) { count += 1; } } out.print(count + " "); } out.println(); } out.flush(); out.close(); } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
0936e444833e75eadb62f92619227385
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.security.spec.ECField; import java.util.HashMap; import java.util.Scanner; public class hello { public static void main(String[] args) { Scanner scn = new Scanner(System.in); try { int T = scn.nextInt(); while (T-- > 0) { int n = scn.nextInt(); scn.nextLine(); int p = 3; HashMap<String, Integer> hm = new HashMap<>(); HashMap<String, Integer> hm1 = new HashMap<>(); HashMap<String, Integer> hm2 = new HashMap<>(); HashMap<String, Integer> hm3 = new HashMap<>(); while (p > 0) { String m = scn.nextLine(); String[] arr = m.split(" "); for (int i = 0; i < arr.length; i++) { int nf = hm.getOrDefault(arr[i], 0) + 1; hm.put(arr[i], nf); } if (p == 3) { for (int i = 0; i < arr.length; i++) { int nf = hm1.getOrDefault(arr[i], 0) + 1; hm1.put(arr[i], nf); } } else if (p == 2) { for (int i = 0; i < arr.length; i++) { int nf = hm2.getOrDefault(arr[i], 0) + 1; hm2.put(arr[i], nf); } } else { for (int i = 0; i < arr.length; i++) { int nf = hm3.getOrDefault(arr[i], 0) + 1; hm3.put(arr[i], nf); } } p--; } long pt1 = 0; for (String str1 : hm1.keySet()) { if (hm.get(str1) == 1) { pt1 += 3; } else if (hm.get(str1) == 2) { pt1 += 1; } } long pt2 = 0; for (String str2 : hm2.keySet()) { if (hm.get(str2) == 1) { pt2 += 3; } else if (hm.get(str2) == 2) { pt2 += 1; } } long pt3 = 0; for (String str3 : hm3.keySet()) { if (hm.get(str3) == 1) { pt3 += 3; } else if (hm.get(str3) == 2) { pt3 += 1; } } System.out.println(pt1 + " " + pt2 + " " + pt3); } } catch (Exception e){ return; } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
52dd6455814edc3ff7c7b89b9c93fa5e
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.io.*; 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 (); HashMap < String, Integer > map = new HashMap <> (); String[] s1 = new String[n]; for (int i = 0; i < n; i++) { s1[i] = in.next (); map.put (s1[i], map.getOrDefault (s1[i], 0) + 1); } String[] s2 = new String[n]; for (int i = 0; i < n; i++) { s2[i] = in.next (); map.put (s2[i], map.getOrDefault (s2[i], 0) + 1); } String[]s3 = new String[n]; for (int i = 0; i < n; i++) { s3[i] = in.next (); map.put (s3[i], map.getOrDefault (s3[i], 0) + 1); } int a1 = 0, a2 = 0, a3 = 0; for (int i = 0; i < s1.length; i++) { int freq = map.get (s1[i]); if (freq == 1) a1 += 3; else if (freq == 2) a1 += 1; } for (int i = 0; i < s2.length; i++) { int freq = map.get (s2[i]); if (freq == 1) a2 += 3; else if (freq == 2) a2 += 1; } for (int i = 0; i < s3.length; i++) { int freq = map.get (s3[i]); if (freq == 1) a3 += 3; else if (freq == 2) a3 += 1; } System.out.print (a1 + " "); System.out.print (a2 + " "); System.out.print (a3); System.out.println(); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
2a6849c8d5c440a422e5b2a84ed86447
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.*; public class Sample { public static void main(String args[]) { Scanner in = new Scanner(System.in); int t = in.nextInt(); while(t-->0) { int n=in.nextInt(); HashSet<String> q = new HashSet<>(); HashSet<String> r = new HashSet<>(); HashSet<String> s = new HashSet<>(); for(int i=0;i<n;i++) q.add(in.next()); for(int i=0;i<n;i++) r.add(in.next()); for(int i=0;i<n;i++) s.add(in.next()); int scoreq=0,scorer=0,scores=0; for(String ele :q) { if(r.contains(ele) && s.contains(ele)) scoreq+=0; else if(r.contains(ele)||s.contains(ele)) scoreq++; else scoreq+=3; } for(String ele :r) { if(q.contains(ele) && s.contains(ele)) scorer+=0; else if(q.contains(ele)||s.contains(ele)) scorer++; else scorer+=3; } for(String ele :s) { if(r.contains(ele) && q.contains(ele)) scores+=0; else if(q.contains(ele)||r.contains(ele)) scores++; else scores+=3; } System.out.println(scoreq+" "+scorer+" "+scores); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
e8a013aa8636ca6064873f8e193c8f4f
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.*; import java.io.*; public class practice1{ public static void main(String[] args) throws IOException, InterruptedException { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int t = sc.nextInt(); while (t-->0) { int n = sc.nextInt(); HashSet<String>k1 = new HashSet<>(); HashSet<String>k2 = new HashSet<>(); HashSet<String>k3 = new HashSet<>(); int a1=0; int a2=0; int a3=0; for (int i=0;i<n;i++) { k1.add(sc.next()); } for (int i=0;i<n;i++) { k2.add(sc.next()); } for (int i=0;i<n;i++) { k3.add(sc.next()); } Iterator<String> iterator = k1.iterator(); while (iterator.hasNext()) { String m = iterator.next(); if (k2.contains(m)&&k3.contains(m)) { a1-=3; a2-=3; a3-=3; iterator.remove(); k2.remove(m); k3.remove(m); } else if (k2.contains(m)) { a1-=2; a2-=2; iterator.remove(); k2.remove(m); } else if (k3.contains(m)) { a1-=2; a3-=2; iterator.remove(); k3.remove(m); } } Iterator<String> iterator2 = k2.iterator(); while (iterator2.hasNext()) { String m = iterator2.next(); if (k1.contains(m)&&k3.contains(m)) { a1-=3; a2-=3; a3-=3; k1.remove(m); iterator2.remove(); k3.remove(m); } else if (k1.contains(m)) { a1-=2; a2-=2; k1.remove(m); iterator2.remove(); } else if (k3.contains(m)) { a2-=2; a3-=2; iterator2.remove(); k3.remove(m); } } Iterator<String> iterator3 = k3.iterator(); while (iterator3.hasNext()) { String m = iterator3.next(); if (k1.contains(m)&&k2.contains(m)) { a1-=3; a2-=3; a3-=3; k1.remove(m); k2.remove(m); iterator3.remove(); } else if (k1.contains(m)) { a1-=2; a3-=2; k1.remove(m); iterator3.remove(); } else if (k2.contains(m)) { a2-=2; a3-=2; k2.remove(m); iterator3.remove(); } } pw.println((a1+(3*n))+" "+(a2+(3*n))+" "+(a3+(3*n))); } pw.flush(); } } class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public boolean ready() throws IOException { return br.ready(); } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
a25ec09cf9b53f7a6b141d775e4aa1a8
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.*; import java.io.*; public class practice1{ public static void main(String[] args) throws IOException, InterruptedException { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int t = sc.nextInt(); while (t-->0) { int n = sc.nextInt(); HashSet<String>k1 = new HashSet<>(); HashSet<String>k2 = new HashSet<>(); HashSet<String>k3 = new HashSet<>(); int a1=0; int a2=0; int a3=0; for (int i=0;i<n;i++) { k1.add(sc.next()); } for (int i=0;i<n;i++) { k2.add(sc.next()); } for (int i=0;i<n;i++) { k3.add(sc.next()); } Iterator<String> iterator = k1.iterator(); while (iterator.hasNext()) { String m = iterator.next(); if (k2.contains(m)&&k3.contains(m)) { a1-=3; a2-=3; a3-=3; iterator.remove(); k2.remove(m); k3.remove(m); } else if (k2.contains(m)) { a1-=2; a2-=2; iterator.remove(); k2.remove(m); } else if (k3.contains(m)) { a1-=2; a3-=2; iterator.remove(); k3.remove(m); } } Iterator<String> iterator2 = k2.iterator(); while (iterator2.hasNext()) { String m = iterator2.next(); if (k1.contains(m)&&k3.contains(m)) { a1-=3; a2-=3; a3-=3; k1.remove(m); iterator2.remove(); k3.remove(m); } else if (k1.contains(m)) { a1-=2; a2-=2; k1.remove(m); iterator2.remove(); } else if (k3.contains(m)) { a2-=2; a3-=2; iterator2.remove(); k3.remove(m); } } Iterator<String> iterator3 = k3.iterator(); while (iterator3.hasNext()) { String m = iterator3.next(); if (k1.contains(m)&&k2.contains(m)) { a1-=3; a2-=3; a3-=3; k1.remove(m); k2.remove(m); iterator3.remove(); } else if (k1.contains(m)) { a1-=2; a3-=2; k1.remove(m); iterator3.remove(); } else if (k2.contains(m)) { a2-=2; a3-=2; k2.remove(m); iterator3.remove(); } } pw.println((a1+(3*n))+" "+(a2+(3*n))+" "+(a3+(3*n))); } pw.flush(); } } class point { int key; String value; public point (int k, String v ) { key=k; value=v; } } class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public boolean ready() throws IOException { return br.ready(); } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
20e053da358f92adfa1180e91fd6f245
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.io.*; import java.util.StringTokenizer; import java.util.*; import java.io.*; 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.math.*; public class Word_Game_CF { 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 boolean check_one(int a) { if(a==1) { return true; } return false; } static boolean check_two(int a) { if(a==2) { return true; } return false; } public static String sortString(String inputString) { char tempArray[] = inputString.toCharArray(); Arrays.sort(tempArray); return new String(tempArray); } public static void main(String r[]) { try { FastReader in =new FastReader(); FastWriter out=new FastWriter(); int test=in.nextInt(); int t=0; while(test>0) { int len=in.nextInt(); String str[][]=new String[3][len]; ArrayList<Integer>result=new ArrayList<>(); for(int i=0;i<3;i++) { for(int j=0;j<len;j++) { str[i][j]=in.next(); } } Map<String,Integer>map=new HashMap<>(); for(int i=0;i<3;i++) { for(int j=0;j<len;j++) { map.put(str[i][j],map.getOrDefault(str[i][j],0)+1); } } int temp=0; for(int i=0;i<3;i++) { temp=0; for(int j=0;j<len;j++) { int x=map.get(str[i][j]); if(check_one(x)) { temp+=3; } else if(check_two(x)) { temp++; } } result.add(temp); } for(int i=0;i<result.size();i++) { System.out.print(result.get(i)+" "); } System.out.println(); test--; } out.close(); } catch(Exception ex) { System.err.println("Error"); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
398da9bc28618fec00ddcfc3cf39a355
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
//package codeforces; import java.util.List; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.Scanner; public class C { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); int n,k = 0; String dump, str; List<String>[] a = new ArrayList[3]; int b[] = new int[3]; while(t-- > 0) { HashMap<String, Integer> map = new HashMap(); n = sc.nextInt(); dump = sc.nextLine(); for(int i = 0; i < 3; i++) { str = sc.nextLine(); a[i] = new ArrayList<>(Arrays.asList(str.split(" "))); b[i] = 0; } for(int i = 0; i < 3; i++) { for(String s: a[i]) { map.put(s, map.containsKey(s)?map.get(s)+1:1); } } for(int i=0; i<3; i++) { for(String s: a[i]) { k = map.get(s); //System.out.printf(s+": %d\n",k); b[i] += k==3? 0: (k==2? 1: 3); } System.out.print(b[i]+" "); } System.out.println(); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
5ff979e22d077db3c57c12d9ed54fe33
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.Scanner; import java.util.HashMap; public class Solution{ public static void main(String args[]) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-- > 0) { HashMap<String,Integer> map = new HashMap<>(); int p = 0; int x = sc.nextInt(); String s[][] = new String[3][x]; for(int i=0;i<3;i++) { for(int j=0;j<x;j++) { s[i][j] = sc.next(); map.put(s[i][j],map.getOrDefault(s[i][j],0)+1); } } int p1 = 0, p2 = 0, p3 = 0; // int k = 0; for(int i=0;i<x;i++){ if(map.get(s[0][i])==1){ p1+=3; } else if(map.get(s[0][i])==2){ p1+=1; } else{ continue; } } for(int i=0;i<x;i++){ if(map.get(s[1][i])==1){ p2+=3; } else if(map.get(s[1][i])==2){ p2+=1; } else{ continue; } } for(int i=0;i<x;i++){ if(map.get(s[2][i])==1){ p3+=3; } else if(map.get(s[2][i])==2){ p3+=1; } else{ continue; } } System.out.println(p1+" "+p2+" "+p3); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
bcdc10d553bd3838c1119f54cb8db484
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.*; import java.io.*; public class Main { static FastReader sc = new FastReader(); static PrintWriter out = new PrintWriter(System.out); public static void main(String[] args) { int T = sc.nextInt(); while (T-- > 0) { solve(); } out.close(); } static void solve() { int n = sc.nextInt(); int a = 0, b = 0, c= 0; HashMap<String, Integer> map = new HashMap<>(); ArrayList<String> A = new ArrayList<>(); for(int i=0; i<n; i++){ String x = sc.next(); map.put(x, map.getOrDefault(x, 0)+1); A.add(x); } ArrayList<String> B = new ArrayList<>(); for(int i=0; i<n; i++){ String x = sc.next(); map.put(x, map.getOrDefault(x, 0)+1); B.add(x); } ArrayList<String> C = new ArrayList<>(); for(int i=0; i<n; i++){ String x = sc.next(); map.put(x, map.getOrDefault(x, 0)+1); C.add(x); } for(String i: A){ if(map.get(i)==2) a++; else if(map.get(i)==1) a+=3; } for(String i: B){ if(map.get(i)==2) b++; else if(map.get(i)==1) b+=3; } for(String i: C){ if(map.get(i)==2) c++; else if(map.get(i)==1) c+=3; } out.println(a+" "+b+" "+c); } 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()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
c259fe58c8108b3f115a78fe1b6060a3
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int x=0;x<t;x++){ int n=sc.nextInt(); String [][]s=new String[3][n]; HashMap<String,Integer>h=new HashMap<>(); for(int i=0;i<3;i++){ for(int j=0;j<n;j++){ s[i][j]=sc.next(); if(h.containsKey(s[i][j])){ h.put(s[i][j],h.get(s[i][j])+1); } else{ h.put(s[i][j],1); } } } for(int i=0;i<3;i++){ int c=0; for(int j=0;j<n;j++){ if(h.get(s[i][j])==3){ c=c+0; } else if(h.get(s[i][j])==2){ c=c+1; } else if(h.get(s[i][j])==1){ c=c+3; } } System.out.print(c+" "); } System.out.println(""); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
9ca41854881a81232e79fa176926d88d
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.*; public class Main { public static int value(Set<String>s,HashMap<String,Integer>map,int one){ for(String p:s){ if(map.get(p)==1) one+=3; else if(map.get(p)==2) one+=1; } return one; } public static void main(String[] args) { // write your code here Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); sc.nextLine(); Set<String> a=new HashSet<>(); Set<String> b=new HashSet<>(); Set<String> c=new HashSet<>(); String[][] arr = new String[3][n]; for (int i = 0; i < 3; i++) { for (int j = 0; j < n; j++) { arr[i][j] = sc.next(); if(i==0) a.add(arr[i][j]); else if(i==1) b.add(arr[i][j]); else c.add(arr[i][j]); } sc.nextLine(); } HashMap<String,Integer> map=new HashMap<>(); int one=0;int two=0;int three=0; for (int i = 0; i < 3; i++) { for (int j = 0; j < n; j++) { map.put(arr[i][j],map.getOrDefault(arr[i][j],0)+1); } } one=value(a,map,one); two=value(b,map,two); three=value(c,map,three); System.out.println(one+" "+two+" "+three); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
b4ff327bb4246f7fc1d744d3714f2c79
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.*; public class C { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int t = Integer.parseInt(sc.next().trim()); String sol = ""; for (int i = 0; i<t; ++i) { sol = ""; int n = Integer.parseInt(sc.next().trim()); String a[] = new String[n]; int aa = 0; String b[] = new String[n]; int bb = 0; String c[] = new String[n]; int cc = 0; int x[][][] = new int[26][26][26]; for (int j = 0; j<n ; ++j) { a[j] = sc.next().trim(); x[a[j].charAt(0)-'a'][a[j].charAt(1)-'a'][a[j].charAt(2)-'a']+=1; } for (int j = 0; j<n ; ++j) { b[j] = sc.next().trim(); x[b[j].charAt(0)-'a'][b[j].charAt(1)-'a'][b[j].charAt(2)-'a']+=7; } for (int j = 0; j<n ; ++j) { c[j] = sc.next().trim(); x[c[j].charAt(0)-'a'][c[j].charAt(1)-'a'][c[j].charAt(2)-'a']+=777; } for (int j = 0; j<n; ++j) { if (x[a[j].charAt(0)-'a'][a[j].charAt(1)-'a'][a[j].charAt(2)-'a'] == 1) aa+=3; else if (x[a[j].charAt(0)-'a'][a[j].charAt(1)-'a'][a[j].charAt(2)-'a'] == 8 || x[a[j].charAt(0)-'a'][a[j].charAt(1)-'a'][a[j].charAt(2)-'a'] == 778) aa+=1; if (x[b[j].charAt(0)-'a'][b[j].charAt(1)-'a'][b[j].charAt(2)-'a'] == 7) bb+=3; else if (x[b[j].charAt(0)-'a'][b[j].charAt(1)-'a'][b[j].charAt(2)-'a'] == 8 || x[b[j].charAt(0)-'a'][b[j].charAt(1)-'a'][b[j].charAt(2)-'a'] == 784) bb+=1; if (x[c[j].charAt(0)-'a'][c[j].charAt(1)-'a'][c[j].charAt(2)-'a'] == 777) cc+=3; else if (x[c[j].charAt(0)-'a'][c[j].charAt(1)-'a'][c[j].charAt(2)-'a'] == 778 || x[c[j].charAt(0)-'a'][c[j].charAt(1)-'a'][c[j].charAt(2)-'a'] == 784) cc+=1; } /*for (int j = 0; j<n ; ++j) { boolean ba = b1.contains(a[j]); boolean ca = c1.contains(a[j]); boolean ab = a1.contains(b[j]); boolean cb = c1.contains(b[j]); boolean ac = a1.contains(c[j]); boolean bc = b1.contains(c[j]); if (ba&&ca) { aa+=0; } else if (ba||ca) { aa+=1; } else { aa+=3; } ; if (ab&&cb) { bb+=0; } else if (ab||cb) { bb+=1; } else { bb+=3; } ; if (bc&&ac) { cc+=0; } else if (bc||ac) { cc+=1; } else { cc+=3; } }*/ sol = aa+" "+bb+" "+cc; sol = sol.trim(); System.out.println(sol); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
d447f4bd46b25a43d76163a0d1040b0d
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int N = in.nextInt(); while(N-- != 0) { Map<String,Integer> map = new HashMap<>(); int n = in.nextInt(); String[][] name = new String[3][n]; for(int i = 0;i < 3;i++) { for(int j = 0;j < n;j++){ name[i][j] = in.next(); int value = map.getOrDefault(name[i][j],0) + 1; map.put(name[i][j],value); } } for(int i = 0;i < 3;i++) { int t =0 ; for(int j = 0;j <n;j++) { int cnt = map.getOrDefault(name[i][j],0); if(cnt == 2) t += 1; else if(cnt == 1) t += 3; } System.out.print(t + " "); } System.out.println(); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
ea65adfa7e495d5d676332df0cfd7e30
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashMap; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws NumberFormatException, IOException { // TODO Auto-generated method stub BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int T=Integer.parseInt(br.readLine()); StringBuilder sb=new StringBuilder(); for(int t=0; t<T;t++) { int N=Integer.parseInt(br.readLine()); HashMap<String, Integer> map =new HashMap<>(); String[][] arr = new String[3][N]; for(int i=0; i<3 ;i++) { StringTokenizer stk=new StringTokenizer(br.readLine()); for(int j=0; j<N; j++) { String s=stk.nextToken(); arr[i][j]=s; if(map.containsKey(s)) { map.put(s, map.get(s)+1); }else { map.put(s, 1); } } } for(int i=0; i<3 ;i++) { int result=0; for(int j=0; j<N; j++) { if(map.containsKey(arr[i][j])) { int p = map.get(arr[i][j]); if(p==1) { result=result+3; }else if(p==2) { result=result+1; } }else { } } sb.append(result); if(i!=2) sb.append(' '); } if(t!=T-1) sb.append('\n'); } System.out.println(sb.toString()); } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
2b26c2f30fe7ed43cda3ef20ceb6ac0b
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.*; import java.io.*; public class C { 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(); ArrayList<String> arrli1=new ArrayList<>(); ArrayList<String> arrli2=new ArrayList<>(); ArrayList<String> arrli3=new ArrayList<>(); HashSet<String> hs1=new HashSet<>(); HashSet<String> hs2=new HashSet<>(); HashSet<String> hs3=new HashSet<>(); for(int i=0;i<n;i++) { arrli1.add(input.scanString()); hs1.add(arrli1.get(i)); } for(int i=0;i<n;i++) { arrli2.add(input.scanString()); hs2.add(arrli2.get(i)); } for(int i=0;i<n;i++) { arrli3.add(input.scanString()); hs3.add(arrli3.get(i)); } int cnt=0; for(int i=0;i<n;i++) { int cc=0; if(hs2.contains(arrli1.get(i))) { cc++; } if(hs3.contains(arrli1.get(i))) { cc++; } // System.out.println(cc); if(cc==0) { cnt+=3; } if(cc==1) { cnt++; } } ans.append(cnt+" "); cnt=0; for(int i=0;i<n;i++) { int cc=0; if(hs1.contains(arrli2.get(i))) { cc++; } if(hs3.contains(arrli2.get(i))) { cc++; } if(cc==0) { cnt+=3; } if(cc==1) { cnt++; } } ans.append(cnt+" "); cnt=0; for(int i=0;i<n;i++) { int cc=0; if(hs1.contains(arrli3.get(i))) { cc++; } if(hs2.contains(arrli3.get(i))) { cc++; } if(cc==0) { cnt+=3; } if(cc==1) { cnt++; } } ans.append(cnt+"\n"); } System.out.print(ans); } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
25fdaaf5dfb6afcca9fc0eb4f919c6c3
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.*; public class Solution { static Scanner sc = new Scanner(System.in); static class word{ String data; Boolean a = false; Boolean b = false; Boolean c = false; } public static void main(String[] args) { int t = sc.nextInt(); while (t>0){t--; int n = sc.nextInt(); SortedMap<String,word> sm = new TreeMap<>(); for(int i=0; i<n; i++){ String s = sc.next(); word w = new word(); w.data = s; w.a = true; sm.put(s,w); } for(int i=0; i<n; i++){ String s = sc.next(); if(sm.containsKey(s)){ sm.get(s).b = true; }else { word w = new word(); w.data = s; w.b = true; sm.put(s,w); } } for(int i=0; i<n; i++){ String s = sc.next(); if(sm.containsKey(s)){ sm.get(s).c = true; }else { word w = new word(); w.data = s; w.c = true; sm.put(s,w); } } int a_score = 0; int b_score = 0; int c_score = 0; for(Map.Entry<String,word> wa : sm.entrySet()){ word w = wa.getValue(); if(w.a == true){ if(w.b == true){ if(w.c == true){ ; }else{ a_score++; b_score++; } }else{ if(w.c == true){ a_score++;c_score++; }else { a_score += 3; } } }else{ if(w.b == true){ if(w.c == true){ c_score++; b_score++; }else { b_score += 3; } }else{ if(w.c == true){ c_score += 3; } } } } System.out.println(a_score+" "+b_score+" "+c_score); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
956bdf37c683ea11278baabe6c5350e5
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.*; import java.io.*; import java.lang.*; import java.math.*; import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; public class x { static FastInput scn; static PrintWriter out; final static int MOD = (int) (1e9 + 7); final static int MAX = Integer.MAX_VALUE; final static int MIN = Integer.MIN_VALUE; // MAIN public static void main(String[] args) throws IOException { scn = new FastInput(); out = new PrintWriter(System.out); int t = 1; t = scn.nextInt(); while (t-- > 0) { solve(); } out.flush(); } private static void solve() throws IOException { int n = scn.nextInt(); List<List<String>> s = new ArrayList<>(); for(int i = 0;i<3;i++){ s.add(new ArrayList<>()); } HashMap<String,Integer> map = new HashMap<>(); int[] ans = new int[3]; for(int i = 0;i<3;i++){ for(int j = 0;j<n;j++){ String temp = scn.next(); s.get(i).add(temp); if(map.containsKey(temp)) map.put(temp,map.get(temp)+1); else map.put(temp,1); } } for(int i = 0;i<3;i++){ for(int j = 0;j<n;j++){ String t = s.get(i).get(j); if(map.get(t) == 1){ ans[i]+=3; } else if(map.get(t) == 2){ ans[i]++; } } } printIntArray(ans); } // CLASSES static class Pair implements Comparable<Pair> { int first, second; Pair(int first, int second) { this.first = first; this.second = second; } Pair(Pair o) { this.first = o.first; this.second = o.second; } public int compareTo(Pair o) { return this.first - o.first; } } // CHECK IF STRING IS NUMBER private static boolean isInteger(String s) { try { Integer.parseInt(s); } catch (NumberFormatException e) { return false; } catch (NullPointerException e) { return false; } return true; } private static boolean isLong(String s) { try { Long.parseLong(s); } catch (NumberFormatException e) { return false; } catch (NullPointerException e) { return false; } return true; } // FASTER SORT private static void fastSort(int[] arr) { int n = arr.length; List<Integer> list = new ArrayList<>(); for (int i = 0; i < n; i++) list.add(arr[i]); Collections.sort(list); for (int i = 0; i < n; i++) arr[i] = list.get(i); } private static void fastSort(char[] arr) { int n = arr.length; List<Character> list = new ArrayList<>(); for (int i = 0; i < n; i++) list.add(arr[i]); Collections.sort(list); for (int i = 0; i < n; i++) arr[i] = list.get(i); } private static void fastSortReverse(int[] arr) { int n = arr.length; List<Integer> list = new ArrayList<>(); for (int i = 0; i < n; i++) list.add(arr[i]); Collections.sort(list, Collections.reverseOrder()); for (int i = 0; i < n; i++) arr[i] = list.get(i); } private static void fastSort(long[] arr) { int n = arr.length; List<Long> list = new ArrayList<>(); for (int i = 0; i < n; i++) list.add(arr[i]); Collections.sort(list); for (int i = 0; i < n; i++) arr[i] = list.get(i); } private static void fastSortReverse(long[] arr) { int n = arr.length; List<Long> list = new ArrayList<>(); for (int i = 0; i < n; i++) list.add(arr[i]); Collections.sort(list, Collections.reverseOrder()); for (int i = 0; i < n; i++) arr[i] = list.get(i); } // QUICK MATHS private static void swap(int[] a,int i,int j){ int t = a[i]; a[i] = a[j]; a[j] = t; } private static void swap(long[] a,int i,int j){ long t = a[i]; a[i] = a[j]; a[j] = t; } private static void swap(char[] a,int i,int j){ char t = a[i]; a[i] = a[j]; a[j] = t; } private static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } private static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } private static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } private static long lcm(long a, long b) { return (a / gcd(a, b)) * b; } private static long power(long a, long b) { if (b == 0) return 1L; long ans = power(a, b / 2); ans *= ans; if ((b & 1) == 1) ans *= a; return ans; } private static int mod_power(int a, int b) { if (b == 0) return 1; int temp = mod_power(a, b / 2); temp %= MOD; temp = (int) ((1L * temp * temp) % MOD); if ((b & 1) == 1) temp = (int) ((1L * temp * a) % MOD); return temp; } private static int multiply(int a, int b) { return (int) ((((1L * a) % MOD) * ((1L * b) % MOD)) % MOD); } private static boolean isPrime(int n) { for (int i = 2; i * i <= n; i++) if (n % i == 0) return false; return true; } private static boolean isPrime(long n) { for (long i = 2; i * i <= n; i++) if (n % i == 0) return false; return true; } // STRING FUNCTIONS private static boolean isPalindrome(String str) { int i = 0, j = str.length() - 1; while (i < j) if (str.charAt(i++) != str.charAt(j--)) return false; return true; } private static String reverseString(String str) { StringBuilder sb = new StringBuilder(str); return sb.reverse().toString(); } private static String sortString(String str) { int[] arr = new int[256]; for (char ch : str.toCharArray()) arr[ch]++; StringBuilder sb = new StringBuilder(); for (int i = 0; i < 256; i++) while (arr[i]-- > 0) sb.append((char) i); return sb.toString(); } // LONGEST INCREASING AND NON-DECREASING SUBSEQUENCE private static int LIS(int arr[]) { int n = arr.length; List<Integer> list = new ArrayList<>(); for (int i = 0; i < n; i++) { int idx = find1(list, arr[i]); if (idx < list.size()) { list.set(idx, arr[i]); } else { list.add(arr[i]); } } return list.size(); } private static int find1(List<Integer> list, int val) { int ret = list.size(), i = 0, j = list.size() - 1; while (i <= j) { int mid = (i + j) / 2; if (list.get(mid) >= val) { ret = mid; j = mid - 1; } else { i = mid + 1; } } return ret; } private static int LNDS(int[] arr) { int n = arr.length; List<Integer> list = new ArrayList<>(); for (int i = 0; i < n; i++) { int idx = find2(list, arr[i]); if (idx < list.size()) { list.set(idx, arr[i]); } else { list.add(arr[i]); } } return list.size(); } private static int find2(List<Integer> list, int val) { int ret = list.size(), i = 0, j = list.size() - 1; while (i <= j) { int mid = (i + j) / 2; if (list.get(mid) <= val) { i = mid + 1; } else { ret = mid; j = mid - 1; } } return ret; } // DISJOINT SET UNION private static int find(int x, int[] parent) { if (parent[x] == x) { return x; } parent[x] = find(parent[x], parent); return parent[x]; } private static boolean union(int x, int y, int[] parent, int[] rank) { int lx = find(x, parent), ly = find(y, parent); if (lx == ly) { return true; } else if (rank[lx] > rank[ly]) { parent[ly] = lx; } else if (rank[lx] < rank[ly]) { parent[lx] = ly; } else { parent[lx] = ly; rank[ly]++; } return false; } // TRIE static class Trie { class Node { Node[] children; boolean isEnd; Node() { children = new Node[26]; } } Node root; Trie() { root = new Node(); } public void insert(String word) { Node curr = root; for (char ch : word.toCharArray()) { if (curr.children[ch - 'a'] == null) { curr.children[ch - 'a'] = new Node(); } curr = curr.children[ch - 'a']; } curr.isEnd = true; } public boolean find(String word) { Node curr = root; for (char ch : word.toCharArray()) { if (curr.children[ch - 'a'] == null) { return false; } curr = curr.children[ch - 'a']; } return curr.isEnd; } } // INPUT static class FastInput { BufferedReader br; StringTokenizer st; FastInput() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(nextLine()); return st.nextToken(); } long nextLong() throws IOException { return Long.parseLong(next()); } int nextInt() throws IOException { return Integer.parseInt(next()); } double nextDouble() throws IOException { return Double.parseDouble(next()); } char nextCharacter() throws IOException { return next().charAt(0); } String nextLine() throws IOException { return br.readLine().trim(); } int[] nextIntArray(int n) throws IOException { int[] arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = nextInt(); return arr; } int[][] next2DIntArray(int n, int m) throws IOException { int[][] arr = new int[n][m]; for (int i = 0; i < n; i++) arr[i] = nextIntArray(m); return arr; } long[] nextLongArray(int n) throws IOException { long[] arr = new long[n]; for (int i = 0; i < n; i++) arr[i] = nextLong(); return arr; } long[][] next2DLongArray(int n, int m) throws IOException { long[][] arr = new long[n][m]; for (int i = 0; i < n; i++) arr[i] = nextLongArray(m); return arr; } List<Integer> nextIntList(int n) throws IOException { List<Integer> list = new ArrayList<>(); for (int i = 0; i < n; i++) list.add(nextInt()); return list; } List<Long> nextLongList(int n) throws IOException { List<Long> list = new ArrayList<>(); for (int i = 0; i < n; i++) list.add(nextLong()); return list; } char[] nextCharArray(int n) throws IOException { return next().toCharArray(); } char[][] next2DCharArray(int n, int m) throws IOException { char[][] mat = new char[n][m]; for (int i = 0; i < n; i++) mat[i] = nextCharArray(m); return mat; } } // OUTPUT private static void printIntList(List<Integer> list) { for (int i = 0; i < list.size(); i++) out.print(list.get(i) + " "); out.println(" "); } private static void printLongList(List<Long> list) { for (int i = 0; i < list.size(); i++) out.print(list.get(i) + " "); out.println(" "); } private static void printIntArray(int[] arr) { for (int i = 0; i < arr.length; i++) out.print(arr[i] + " "); out.println(" "); } private static void print2DIntArray(int[][] arr) { for (int i = 0; i < arr.length; i++) printIntArray(arr[i]); } private static void printLongArray(long[] arr) { for (int i = 0; i < arr.length; i++) out.print(arr[i] + " "); out.println(" "); } private static void print2DLongArray(long[][] arr) { for (int i = 0; i < arr.length; i++) printLongArray(arr[i]); } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
6b14ac9dd98698d8c10e7dea199a1d99
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.*; public class fire extends PrintWriter { fire() { super(System.out); } public static void main(String[] $) throws IOException { fire o = new fire(); o.main(); o.flush(); } void main() throws IOException { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0) { int n = sc.nextInt(); Map<String,boolean[]> map = new HashMap<>(); for(int i=0;i<n;i++) { String str = sc.next(); if(map.containsKey(str)) map.get(str)[0] = true; else { boolean[] shit = {false,false,false}; map.put(str, shit); map.get(str)[0] = true; } } for(int i=0;i<n;i++) { String str = sc.next(); if(map.containsKey(str)) map.get(str)[1] = true; else { boolean[] shit = {false,false,false}; map.put(str, shit); map.get(str)[1] = true; } } for(int i=0;i<n;i++) { String str = sc.next(); if(map.containsKey(str)) map.get(str)[2] = true; else { boolean[] shit = {false,false,false}; map.put(str, shit); map.get(str)[2] = true; } } int[] p = {0,0,0}; for (Map.Entry<String, boolean[]> entry : map.entrySet()) { if(entry.getValue()[0] && entry.getValue()[1] && entry.getValue()[2]==false) {p[0]++;p[1]++;} else if (entry.getValue()[0] && entry.getValue()[1]==false && entry.getValue()[2]) {p[0]++;p[2]++;} else if (entry.getValue()[0]==false && entry.getValue()[1] && entry.getValue()[2]) {p[2]++;p[1]++;} else if (entry.getValue()[0] && entry.getValue()[1]==false && entry.getValue()[2]==false) p[0]+=3; else if (entry.getValue()[0]==false && entry.getValue()[1] && entry.getValue()[2]==false) p[1]+=3; else if (entry.getValue()[0]==false && entry.getValue()[1]==false && entry.getValue()[2]) p[2]+=3; } println(p[0]+" "+p[1]+" "+p[2]); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
541ffe75b49cf2d0c772e70d9a350214
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.*; public class C_Word_Game { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t-- != 0) { int n = sc.nextInt(); String arr1[] = new String[n]; String arr2[] = new String[n]; String arr3[] = new String[n]; Map<String, Integer> mp = new HashMap<>(); for (int i = 0; i < n; i++) { arr1[i] = sc.next(); mp.put(arr1[i], mp.getOrDefault(arr1[i], 0) + 1); } for (int i = 0; i < n; i++) { arr2[i] = sc.next(); mp.put(arr2[i], mp.getOrDefault(arr2[i], 0) + 1); } for (int i = 0; i < n; i++) { arr3[i] = sc.next(); mp.put(arr3[i], mp.getOrDefault(arr3[i], 0) + 1); } int a1 = 0, a2 = 0, a3 = 0; for (int i = 0; i < n; i++) { if (mp.get(arr1[i]) == 2) { a1++; } else if (mp.get(arr1[i]) == 1) { a1 += 3; } if (mp.get(arr2[i]) == 2) { a2++; } else if (mp.get(arr2[i]) == 1) { a2 += 3; } if (mp.get(arr3[i]) == 2) { a3++; } else if (mp.get(arr3[i]) == 1) { a3 += 3; } } System.out.println(a1 + " " + a2 + " " + a3); } sc.close(); } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
072b33f3da02470a278ee36f99d08dd7
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
//package com.company.Array; import java.util.*; import java.lang.*; import java.io.*; public class Codechef { // static Scanner sc = new Scanner(System.in); static FastReader in =new FastReader(); static final Random random=new Random(); static long mod=1000000007L; static HashMap<String,Integer>mp=new HashMap<>(); 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 [] readIntArray(int n) { int res [] = new int [n]; for(int i = 0; i<n; i++) res[i] = nextInt(); return res; } long [] readLongArray(int n) { long res [] = new long [n]; for(int i = 0; i<n; i++)res[i] = nextLong(); return res; } } public static void main (String[] args) throws java.lang.Exception { int test = in.nextInt(); while (test-->0){ int n = in.nextInt(); String s1 = in.nextLine(); String s2= in.nextLine(); String s3 = in.nextLine(); HashMap<String,Integer>mp1=new HashMap<>(); HashMap<String,Integer>mp2=new HashMap<>(); HashMap<String,Integer>mp3=new HashMap<>(); for(String str : s1.split(" ")){ if (mp1.containsKey(str)) { mp1.put(str,mp1.getOrDefault(str,0)+1); }else{ mp1.put(str,1); } } for(String str : s2.split(" ")){ if (mp2.containsKey(str)) { mp2.put(str,mp2.getOrDefault(str,0)+1); }else{ mp2.put(str,1); } } for(String str : s3.split(" ")){ if (mp3.containsKey(str)) { mp3.put(str,mp3.getOrDefault(str,0)+1); }else{ mp3.put(str,1); } } int a =0,b=0,c=0; for(Map.Entry<String,Integer>mp: mp1.entrySet()){ String s = mp.getKey(); if(mp2.containsKey(s) && mp3.containsKey(s)){ } else if(mp2.containsKey(s) || mp3.containsKey(s)){ a+=1; }else if((!mp2.containsKey(s)) && (!mp2.containsKey(s))){ a+=3; } } for(Map.Entry<String,Integer>mp: mp2.entrySet()){ String s = mp.getKey(); if(mp1.containsKey(s) && mp3.containsKey(s)){ } else if(mp1.containsKey(s) || mp3.containsKey(s)){ b+=1; }else if((!mp1.containsKey(s)) && (!mp3.containsKey(s))){ b+=3; } } for(Map.Entry<String,Integer>mp: mp3.entrySet()){ String s = mp.getKey(); if(mp2.containsKey(s) && mp1.containsKey(s)){ } else if(mp1.containsKey(s) || mp2.containsKey(s)){ c+=1; }else if((!mp1.containsKey(s)) && (!mp2.containsKey(s))){ c+=3; } } System.out.println(a+" "+b+" "+c); } } static int max(int a, int b) { if(a<b) return b; return a; } static int abs(int a) { if(a<0) return -1*a; return a; } static < E > void print(E res) { System.out.println(res); } static void count(String str1, String str2) { int c = 0, j = 0; for (int i = 0; i < str1.length(); i++) { if (str2.indexOf(str1.charAt(i)) >= 0) { c += 1; } } System.out.println("No. of matching characters are: " + c); } static int findGCD(int a, int b) { if (b == 0) return a; return findGCD(b, a % b); } static int findLcm(int x, int y) { return (x / findGCD(x, y)) * y; } static Long factorial(Long n) { if (n == 0) return (long)1; return n * factorial(n - 1); } static void LargestSum(int [] arr){ int max =0; int sum =0; for(int i =0;i<arr.length;i++){ sum =sum+arr[i]; max = Math.max(max,sum); if(sum<0){ sum=0; } } System.out.println(max); } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
35d863195aff18ebf725f05b9e29ce5c
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.*; public class Main{ 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 s1=0; int s2=0; int s3=0; HashMap<String,Integer> a1=new HashMap<>(); String []q1=new String[n]; String []q2=new String[n]; String []q3=new String[n]; for (int j = 0; j < n; j++) { String s= sc.next(); if (a1.get(s)==null) a1.put(s,1); else a1.put(s,a1.get(s)+1); q1[j]=s; } for (int j = 0; j < n; j++) { String s= sc.next(); if (a1.get(s)==null) a1.put(s,1); else a1.put(s,a1.get(s)+1); q2[j]=s; } for (int j = 0; j < n; j++) { String s= sc.next(); if (a1.get(s)==null) a1.put(s,1); else a1.put(s,a1.get(s)+1); q3[j]=s; } for (int j = 0; j < n; j++) { if (a1.get(q1[j])==1) s1+=3; else if (a1.get(q1[j])==2) s1+=1; } for (int j = 0; j < n; j++) { if (a1.get(q2[j])==1) s2+=3; else if (a1.get(q2[j])==2) s2+=1; } for (int j = 0; j < n; j++) { if (a1.get(q3[j])==1) s3+=3; else if (a1.get(q3[j])==2) s3+=1; } System.out.println(s1+" "+s2+" "+s3); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
ab1ee78960a284f0ace5d8c6621aac96
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.*; import java.io.*; public class CC { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int t = sc.nextInt(); for (int i = 1; i <= t; i++) { int n = sc.nextInt(); HashSet<String> al1 = new HashSet<>(); HashSet<String> al2 = new HashSet<>(); HashSet<String> al3 = new HashSet<>(); int ans1=0; int ans2=0; int ans3=0; for(int j=0;j<n;j++){ String s = sc.next(); al1.add(s); ans1+=3; } for(int j=0;j<n;j++){ String s = sc.next(); al2.add(s); ans2+=3; if(al1.contains(s)){ ans1-=2; ans2-=2; } } for(int j=0;j<n;j++){ String s = sc.next(); al3.add(s); ans3+=3; if(al1.contains(s) && al2.contains(s)){ ans1-=1; ans2-=1; ans3-=3; } else if(al1.contains(s)){ ans1-=2; ans3-=2; } else if(al2.contains(s)){ ans3-=2; ans2-=2; } } pw.println(ans1+ " " + ans2 + " " + ans3); } pw.flush(); pw.close(); } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
4d900792f17cb4ea7e11bf608afd5f43
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import com.sun.security.jgss.GSSUtil; import java.awt.*; import java.io.*; import java.util.*; import java.util.List; public class MainClass { static FastScanner fs; static FastWriter fw; static boolean checkOnlineJudge = System.getProperty("ONLINE_JUDGE") == null; private static final int[][] kdir = new int[][]{{-1, 2}, {-2, 1}, {-2, -1}, {-1, -2}, {1, -2}, {2, -1}, {2, 1}, {1, 2}}; private static final int[][] dir = new int[][]{{-1, 0}, {1, 0}, {0, 1}, {0, -1}}; private static final int iMax = (int) (1e9 + 100), iMin = (int) (-1e9 - 100); private static final long lMax = (long) (1e18 + 100), lMin = (long) (-1e18 - 100); private static final int mod1 = (int) (1e9 + 7); private static final int mod2 = 998244353; public static void main(String[] args) throws IOException { fs = new FastScanner(); fw = new FastWriter(); int t = 1; t = fs.nextInt(); while (t-- > 0) { solve(); } fw.out.close(); } private static void solve() { int n = fs.nextInt(); HashSet<String> hs1 = new HashSet<>(); HashSet<String> hs2 = new HashSet<>(); HashSet<String> hs3 = new HashSet<>(); HashSet<String> hs = new HashSet<>(); int aa=0, bb=0, cc=0; for(int i=0; i<n; i++) { String s = fs.next(); hs1.add(s); hs.add(s); } for(int i=0; i<n; i++) { String s = fs.next(); hs2.add(s); hs.add(s); }for(int i=0; i<n; i++) { String s = fs.next(); hs3.add(s); hs.add(s); } for(String s: hs) { if(hs1.contains(s) && !hs2.contains(s) && !hs3.contains(s)) aa+=3; else if(!hs1.contains(s) && hs2.contains(s) && !hs3.contains(s)) bb+=3; else if(!hs1.contains(s) && !hs2.contains(s) && hs3.contains(s)) cc+=3; else if(hs1.contains(s) && hs2.contains(s) && !hs3.contains(s)) { aa++; bb++; } else if(hs2.contains(s) && hs3.contains(s) && !hs1.contains(s)) { bb++; cc++; } else if(hs1.contains(s) && hs3.contains(s) && !hs2.contains(s)) { aa++; cc++; } else { continue; } } fw.out.println(aa+" " +bb+" " +cc); } private static class UnionFind { private final int[] parent; private final int[] rank; UnionFind(int n) { parent = new int[n + 5]; rank = new int[n + 5]; for (int i = 0; i <= n; i++) { parent[i] = i; rank[i] = 0; } } private int find(int i) { if (parent[i] == i) return i; return parent[i] = find(parent[i]); } private void union(int a, int b) { a = find(a); b = find(b); if (a != b) { if (rank[a] < rank[b]) { int temp = a; a = b; b = temp; } parent[b] = a; if (rank[a] == rank[b]) rank[a]++; } } } private static class Calc_nCr { private final long[] fact; private final long[] invfact; private final int p; Calc_nCr(int n, int prime) { fact = new long[n + 5]; invfact = new long[n + 5]; p = prime; fact[0] = 1; for (int i = 1; i <= n; i++) { fact[i] = (i * fact[i - 1]) % p; } invfact[n] = pow(fact[n], p - 2, p); for (int i = n - 1; i >= 0; i--) { invfact[i] = (invfact[i + 1] * (i + 1)) % p; } } private long nCr(int n, int r) { if (r > n || n < 0 || r < 0) return 0; return (((fact[n] * invfact[r]) % p) * invfact[n - r]) % p; } } private static long gcd(long a, long b) { return (b == 0 ? a : gcd(b, a % b)); } private static long lcm(long a, long b) { return ((a * b) / gcd(a, b)); } private static long pow(long a, long b, int mod) { long result = 1; while (b > 0) { if ((b & 1L) == 1) { result = (result * a) % mod; } a = (a * a) % mod; b >>= 1; } return result; } private static long ceilDiv(long a, long b) { return ((a + b - 1) / b); } private static long getMin(long... args) { long min = lMax; for (long arg : args) min = Math.min(min, arg); return min; } private static long getMax(long... args) { long max = lMin; for (long arg : args) max = Math.max(max, arg); return max; } private static boolean isPalindrome(String s, int l, int r) { int i = l, j = r; while (j - i >= 1) { if (s.charAt(i) != s.charAt(j)) return false; i++; j--; } return true; } private static List<Integer> primes(int n) { boolean[] primeArr = new boolean[n + 5]; Arrays.fill(primeArr, true); for (int i = 2; (i * i) <= n; i++) { if (primeArr[i]) { for (int j = i * i; j <= n; j += i) { primeArr[j] = false; } } } List<Integer> primeList = new ArrayList<>(); for (int i = 2; i <= n; i++) { if (primeArr[i]) primeList.add(i); } return primeList; } private static int noOfSetBits(long x) { int cnt = 0; while (x != 0) { x = x & (x - 1); cnt++; } return cnt; } private static boolean isPerfectSquare(long num) { long sqrt = (long) Math.sqrt(num); return ((sqrt * sqrt) == num); } private static class Pair<U, V> { private final U first; private final V second; @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Pair<?, ?> pair = (Pair<?, ?>) o; return first.equals(pair.first) && second.equals(pair.second); } @Override public int hashCode() { return Objects.hash(first, second); } @Override public String toString() { return "(" + first + ", " + second + ")"; } private Pair(U ff, V ss) { this.first = ff; this.second = ss; } } private static void randomizeIntArr(int[] arr, int n) { Random r = new Random(); for (int i = (n - 1); i > 0; i--) { int j = r.nextInt(i + 1); swapInIntArr(arr, i, j); } } private static void randomizeLongArr(long[] arr, int n) { Random r = new Random(); for (int i = (n - 1); i > 0; i--) { int j = r.nextInt(i + 1); swapInLongArr(arr, i, j); } } private static void swapInIntArr(int[] arr, int a, int b) { int temp = arr[a]; arr[a] = arr[b]; arr[b] = temp; } private static void swapInLongArr(long[] arr, int a, int b) { long temp = arr[a]; arr[a] = arr[b]; arr[b] = temp; } private static int[] readIntArray(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = fs.nextInt(); return arr; } private static long[] readLongArray(int n) { long[] arr = new long[n]; for (int i = 0; i < n; i++) arr[i] = fs.nextLong(); return arr; } private static List<Integer> readIntList(int n) { List<Integer> list = new ArrayList<>(); for (int i = 0; i < n; i++) list.add(fs.nextInt()); return list; } private static List<Long> readLongList(int n) { List<Long> list = new ArrayList<>(); for (int i = 0; i < n; i++) list.add(fs.nextLong()); return list; } private static class FastScanner { BufferedReader br; StringTokenizer st; FastScanner() throws IOException { if (checkOnlineJudge) this.br = new BufferedReader(new FileReader("src/input.txt")); else this.br = new BufferedReader(new InputStreamReader(System.in)); this.st = new StringTokenizer(""); } public String next() { while (!st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException err) { err.printStackTrace(); } } return st.nextToken(); } public String nextLine() { if (st.hasMoreTokens()) { return st.nextToken("").trim(); } try { return br.readLine().trim(); } catch (IOException err) { err.printStackTrace(); } return ""; } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } } private static class FastWriter { PrintWriter out; FastWriter() throws IOException { if (checkOnlineJudge) out = new PrintWriter(new FileWriter("src/output.txt")); else out = new PrintWriter(System.out); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
a75b2ac8104bf7168469d05b2b184a15
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashMap; import java.util.StringTokenizer; public class Main { static long ans = 0; public static void main(String[] args) throws IOException{ // TODO Auto-generated method stub BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb = new StringBuilder(); //StringTokenizer st = new StringTokenizer(br.readLine(), " "); int T = Integer.parseInt(br.readLine()); while(T --> 0) { ans = 0; HashMap<String, Integer> hashmap = new HashMap<>(); int n = Integer.parseInt(br.readLine()); String[][] strarr = new String[3][n]; for(int i = 0; i < 3; i++) { StringTokenizer st = new StringTokenizer(br.readLine(), " "); for(int j = 0; j < n; j++) { String str = st.nextToken(); strarr[i][j] = str; hashmap.put(str, hashmap.getOrDefault(str, 0) + 1); } } int[] arr = new int[3]; for(int i = 0; i < 3; i++) { int sum = 0; for(int j = 0; j < n; j++) { String str = strarr[i][j]; int a = hashmap.get(str); if(a == 1) sum += 3; else if(a == 2) sum += 1; } arr[i] = sum; } sb.append(arr[0]+" "+arr[1]+" "+arr[2]).append('\n'); /*if(result) sb.append("NO").append('\n'); else sb.append("YES").append('\n'); */ //sb.append(ans).append('\n'); } System.out.println(sb); } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
71a2f01eee72cb3f5197f6e030f94316
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintStream; import java.math.BigInteger; import java.util.*; import java.io.UncheckedIOException; import java.io.Closeable; import java.io.Writer; import java.io.OutputStreamWriter; /* @author : sanskarXrawat @date : 4/18/2022 @time : 4:49 PM */ @SuppressWarnings("ALL") public class Demo { public static void main(String[] args) throws Throwable { Thread thread = new Thread (null, new TaskAdapter (), "", 1 << 29); thread.start (); thread.join (); } static class TaskAdapter implements Runnable { @Override public void run() { InputStream inputStream = System.in; OutputStream outputStream = System.out; FastInput in = new FastInput (inputStream); FastOutput out = new FastOutput (outputStream); Solution solver = new Solution (); try { solver.solve (1, in, out); } catch (Exception e) { e.printStackTrace (); } in.close (); out.close (); } } @SuppressWarnings("unused") static class Solution { static final Debug debug = new Debug (true); static int ans=0; public void solve(int testNumber, FastInput in, FastOutput out) throws Exception { int test=in.ri (); while(test-->0){ int n=in.ri (); HashSet<String> one=new HashSet<> (); HashSet<String> two=new HashSet<> (); HashSet<String> three=new HashSet<> (); for(int i=0;i<3;i++){ for(int j=0;j<n;j++){ if(i==0){ one.add(in.readString ()); }else if(i==1){ two.add (in.readString ()); }else{ three.add (in.readString ()); } } } int o=0,t=0,th=0; for(String e:one){ if((two.contains (e) && !three.contains (e)) || (!two.contains (e) && three.contains (e))){ o++; }else if(!two.contains (e) && !three.contains (e)){ o+=3; } } for(String e:two){ if((one.contains (e) && !three.contains (e)) || (!one.contains (e) && three.contains (e))){ t++; }else if(!one.contains (e) && !three.contains (e)){ t+=3; } } for(String e:three){ if((two.contains (e) && !one.contains (e)) || (!two.contains (e) && one.contains (e))){ th++; }else if(!two.contains (e) && !one.contains (e)){ th+=3; } } out.prt (o); out.prt (t); out.prt (th); out.println (); } } } static class FastOutput implements AutoCloseable, Closeable, Appendable { private final StringBuilder cache = new StringBuilder (THRESHOLD * 2); private static final int THRESHOLD = 32 << 10; private final Writer os; public FastOutput append(CharSequence csq) { cache.append (csq); return this; } public FastOutput append(CharSequence csq, int start, int end) { cache.append (csq, start, end); return this; } private void afterWrite() { if (cache.length () < THRESHOLD) { return; } flush (); } public FastOutput(Writer os) { this.os = os; } public FastOutput(OutputStream os) { this (new OutputStreamWriter (os)); } public FastOutput append(char c) { cache.append (c); afterWrite (); return this; } public FastOutput append(String c) { cache.append (c); afterWrite (); return this; } public FastOutput println(String c) { return append (c).println (); } public FastOutput println() { return append ('\n'); } final <T> void prt(T a) { append (a + " "); } final <T> void prtl(T a) { append (a + "\n"); } public FastOutput flush() { try { os.append (cache); os.flush (); cache.setLength (0); } catch (IOException e) { throw new UncheckedIOException (e); } return this; } public void close() { flush (); try { os.close (); } catch (IOException e) { throw new UncheckedIOException (e); } } public String toString() { return cache.toString (); } public FastOutput printf(String format, Object... args) { return append (String.format (format, args)); } private static int countDigits(long l) { if (l >= 1000000000000000000L) return 19; if (l >= 100000000000000000L) return 18; if (l >= 10000000000000000L) return 17; if (l >= 1000000000000000L) return 16; if (l >= 100000000000000L) return 15; if (l >= 10000000000000L) return 14; if (l >= 1000000000000L) return 13; if (l >= 100000000000L) return 12; if (l >= 10000000000L) return 11; if (l >= 1000000000L) return 10; if (l >= 100000000L) return 9; if (l >= 10000000L) return 8; if (l >= 1000000L) return 7; if (l >= 100000L) return 6; if (l >= 10000L) return 5; if (l >= 1000L) return 4; if (l >= 100L) return 3; if (l >= 10L) return 2; return 1; } private static int countDigits(int l) { if (l >= 1000000000) return 10; if (l >= 100000000) return 9; if (l >= 10000000) return 8; if (l >= 1000000) return 7; if (l >= 100000) return 6; if (l >= 10000) return 5; if (l >= 1000) return 4; if (l >= 100) return 3; if (l >= 10) return 2; return 1; } } static class FastInput { private final StringBuilder defaultStringBuf = new StringBuilder (1 << 13); private final ByteBuffer tokenBuf = new ByteBuffer (); private final byte[] buf = new byte[1 << 13]; private SpaceCharFilter filter; private final InputStream is; private int bufOffset; private int bufLen; private int next; private int ptr; public FastInput(InputStream is) { this.is = is; } private int read() { while (bufLen == bufOffset) { bufOffset = 0; try { bufLen = is.read (buf); } catch (IOException e) { bufLen = -1; } if (bufLen == -1) { return -1; } } return buf[bufOffset++]; } public void skipBlank() { while (next >= 0 && next <= 32) { next = read (); } } public String next() { return readString (); } public int ri() { return readInt (); } public int readInt() { boolean rev = false; skipBlank (); if (next == '+' || next == '-') { rev = next == '-'; next = read (); } int val = 0; while (next >= '0' && next <= '9') { val = val * 10 - next + '0'; next = read (); } return rev ? val : -val; } public long readLong() { boolean rev = false; skipBlank (); if (next == '+' || next == '-') { rev = next == '-'; next = read (); } long val = 0L; while (next >= '0' && next <= '9') { val = val * 10 - next + '0'; next = read (); } return rev ? val : -val; } public long rl() { return readLong (); } public String readString(StringBuilder builder) { skipBlank (); while (next > 32) { builder.append ((char) next); next = read (); } return builder.toString (); } public String readString() { defaultStringBuf.setLength (0); return readString (defaultStringBuf); } public int rs(char[] data, int offset) { return readString (data, offset); } public char[] rsc() { return readString ().toCharArray (); } public int rs(char[] data) { return rs (data, 0); } public int readString(char[] data, int offset) { skipBlank (); int originalOffset = offset; while (next > 32) { data[offset++] = (char) next; next = read (); } return offset - originalOffset; } public char rc() { return readChar (); } public char readChar() { skipBlank (); char c = (char) next; next = read (); return c; } public double rd() { return nextDouble (); } 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, readInt ()); 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, readInt ()); if (c < '0' || c > '9') throw new InputMismatchException (); m /= 10; res += (c - '0') * m; c = read (); } } return res * sgn; } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar (c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } public final int readByteUnsafe() { if (ptr < bufLen) return buf[ptr++]; ptr = 0; try { bufLen = is.read (buf); if (bufLen > 0) { return buf[ptr++]; } else { return -1; } } catch (IOException e) { throw new UncheckedIOException (e); } } public final int readByte() { if (ptr < bufLen) return buf[ptr++]; ptr = 0; try { bufLen = is.read (buf); if (bufLen > 0) { return buf[ptr++]; } else { throw new java.io.EOFException (); } } catch (IOException e) { throw new UncheckedIOException (e); } } public final String nextLine() { tokenBuf.clear (); for (int b = readByte (); b != '\n'; b = readByteUnsafe ()) { if (b == -1) break; tokenBuf.append (b); } return new String (tokenBuf.getRawBuf (), 0, tokenBuf.size ()); } public final String nl() { return nextLine (); } public final boolean hasNext() { for (int b = readByteUnsafe (); b <= 32 || b >= 127; b = readByteUnsafe ()) { if (b == -1) return false; } --ptr; return true; } public void readArray(Object T) { if (T instanceof int[]) { int[] arr = (int[]) T; for (int i = 0; i < arr.length; i++) { arr[i] = ri (); } } if (T instanceof long[]) { long[] arr = (long[]) T; for (int i = 0; i < arr.length; i++) { arr[i] = rl (); } } if (T instanceof double[]) { double[] arr = (double[]) T; for (int i = 0; i < arr.length; i++) { arr[i] = rd (); } } if (T instanceof char[]) { char[] arr = (char[]) T; for (int i = 0; i < arr.length; i++) { arr[i] = readChar (); } } if (T instanceof String[]) { String[] arr = (String[]) T; for (int i = 0; i < arr.length; i++) { arr[i] = next (); } } if (T instanceof int[][]) { int[][] arr = (int[][]) T; for (int i = 0; i < arr.length; i++) { for (int j = 0; j < arr[0].length; j++) { arr[i][j] = ri (); } } } if (T instanceof char[][]) { char[][] arr = (char[][]) T; for (int i = 0; i < arr.length; i++) { for (int j = 0; j < arr[0].length; j++) { arr[i][j] = readChar (); } } } if (T instanceof long[][]) { long[][] arr = (long[][]) T; for (int i = 0; i < arr.length; i++) { for (int j = 0; j < arr[0].length; j++) { arr[i][j] = rl (); } } } } public final void close() { try { is.close (); } catch (IOException e) { throw new UncheckedIOException (e); } } private static final class ByteBuffer { private static final int DEFAULT_BUF_SIZE = 1 << 12; private byte[] buf; private int ptr = 0; private ByteBuffer(int capacity) { this.buf = new byte[capacity]; } private ByteBuffer() { this (DEFAULT_BUF_SIZE); } private ByteBuffer append(int b) { if (ptr == buf.length) { int newLength = buf.length << 1; byte[] newBuf = new byte[newLength]; System.arraycopy (buf, 0, newBuf, 0, buf.length); buf = newBuf; } buf[ptr++] = (byte) b; return this; } private char[] toCharArray() { char[] chs = new char[ptr]; for (int i = 0; i < ptr; i++) { chs[i] = (char) buf[i]; } return chs; } private byte[] getRawBuf() { return buf; } private int size() { return ptr; } private void clear() { ptr = 0; } } } static class Debug { private final boolean offline; private final PrintStream out = System.err; static int[] empty = new int[0]; public Debug(boolean enable) { offline = enable && System.getSecurityManager () == null; } public Debug debug(String name, Object x) { return debug (name, x, empty); } public Debug debug(String name, long x) { if (offline) { debug (name, "" + x); } return this; } public Debug debug(String name, String x) { if (offline) { out.printf ("%s=%s", name, x); out.println (); } return this; } public Debug debug(String name, Object x, int... indexes) { if (offline) { if (x == null || !x.getClass ().isArray ()) { out.append (name); for (int i : indexes) { out.printf ("[%d]", i); } out.append ("=").append ("" + x); out.println (); } else { indexes = Arrays.copyOf (indexes, indexes.length + 1); if (x instanceof byte[]) { byte[] arr = (byte[]) x; for (int i = 0; i < arr.length; i++) { indexes[indexes.length - 1] = i; debug (name, arr[i], indexes); } } else if (x instanceof short[]) { short[] arr = (short[]) x; for (int i = 0; i < arr.length; i++) { indexes[indexes.length - 1] = i; debug (name, arr[i], indexes); } } else if (x instanceof boolean[]) { boolean[] arr = (boolean[]) x; for (int i = 0; i < arr.length; i++) { indexes[indexes.length - 1] = i; debug (name, arr[i], indexes); } } else if (x instanceof char[]) { char[] arr = (char[]) x; for (int i = 0; i < arr.length; i++) { indexes[indexes.length - 1] = i; debug (name, arr[i], indexes); } } else if (x instanceof int[]) { int[] arr = (int[]) x; for (int i = 0; i < arr.length; i++) { indexes[indexes.length - 1] = i; debug (name, arr[i], indexes); } } else if (x instanceof float[]) { float[] arr = (float[]) x; for (int i = 0; i < arr.length; i++) { indexes[indexes.length - 1] = i; debug (name, arr[i], indexes); } } else if (x instanceof double[]) { double[] arr = (double[]) x; for (int i = 0; i < arr.length; i++) { indexes[indexes.length - 1] = i; debug (name, arr[i], indexes); } } else if (x instanceof long[]) { long[] arr = (long[]) x; for (int i = 0; i < arr.length; i++) { indexes[indexes.length - 1] = i; debug (name, arr[i], indexes); } } else { Object[] arr = (Object[]) x; for (int i = 0; i < arr.length; i++) { indexes[indexes.length - 1] = i; debug (name, arr[i], indexes); } } } } return this; } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
18ee5dfa42e2faa7ac82af873f453cb9
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
/* package codeChef; // don't place package name! */ // algo_messiah23 , NIT RKL ... import java.util.*; import java.lang.*; import java.io.*; import java.math.*; import static java.lang.System.*; import java.util.stream.IntStream; import java.util.Map.Entry; /* Name of the class has to be "Main" only if the class is public. */ public class CodeForces { static PrintWriter out = new PrintWriter((System.out)); static FastReader in = new FastReader(); static int INF = Integer.MAX_VALUE; static int NINF = Integer.MIN_VALUE; public static void main(String[] args) throws java.lang.Exception { // your code goes here int t = i(); while (t-- > 0) algo_messiah23(); out.close(); } public static void algo_messiah23() { int n = i(); String a = isl(); String b = isl(); String c = isl(); HashMap<String, Integer> map = new HashMap<>(); String p[] = a.split(" "); String q[] = b.split(" "); String r[] = c.split(" "); for (int i = 0; i < p.length; i++) { if (map.containsKey(p[i])) map.put(p[i], map.get(p[i]) + 1); else map.put(p[i], 1); } for (int i = 0; i < q.length; i++) { if (map.containsKey(q[i])) map.put(q[i], map.get(q[i]) + 1); else map.put(q[i], 1); } for (int i = 0; i < r.length; i++) { if (map.containsKey(r[i])) map.put(r[i], map.get(r[i]) + 1); else map.put(r[i], 1); } int ans[] = new int[3]; ans[0] = cost(map, p); ans[1] = cost(map, q); ans[2] = cost(map, r); out.println(ans[0] + " " + ans[1] + " " + ans[2]); } static int cost(HashMap<String, Integer> map, String[] s) { int cost = 0; int n = s.length; for (int i = 0; i < n; i++) { String k = s[i]; if (map.containsKey(k)) { int p = map.get(k); if (p == 1) cost += 3; else if (p == 2) cost += 1; else { cost += 0; } } } return cost; } static String rev(String s) { StringBuilder st = new StringBuilder(s); st.reverse(); String ans = st.toString(); return ans; } static int[] input(int N) { int[] A = new int[N]; for (int i = 0; i < N; i++) A[i] = in.nextInt(); return A; } public static void print(int[] arr) { int n = arr.length; for (int i = 0; i < n; i++) { out.print(arr[i] + " "); } out.println(); } public static void sort(int[] arr) { ArrayList<Integer> ls = new ArrayList<>(); 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 void reverse(int[] arr) { int n = arr.length; for (int i = 0; i < n / 2; i++) { int temp = arr[i]; arr[i] = arr[n - 1 - i]; arr[n - 1 - i] = temp; } } public static void reverse(long[] arr) { int n = arr.length; for (int i = 0; i < n / 2; i++) { long temp = arr[i]; arr[i] = arr[n - 1 - i]; arr[n - 1 - i] = temp; } } public static void print(ArrayList<Integer> arr) { int n = arr.size(); for (int i = 0; i < n; i++) { out.print(arr.get(i) + " "); } out.println(); } static int i() { return in.nextInt(); } static long l() { return in.nextLong(); } static char ich() { return in.next().charAt(0); } static String is() { return in.next(); } static String isl() { return in.nextLine(); } public static int max(int[] arr) { int max = -1; int n = arr.length; for (int i = 0; i < n; i++) max = Math.max(max, arr[i]); return max; } public static int min(int[] arr) { int min = INF; int n = arr.length; for (int i = 0; i < n; i++) min = Math.min(min, arr[i]); return min; } public static int gcd(int x, int y) { if (y == 0) { return x; } return gcd(y, x % y); } } 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\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
1510fad67b48db4a4ea0e84eb801219b
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class Main { static long mod = (int)1e9+7; static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); public static void main (String[] args) throws java.lang.Exception { FastReader sc =new FastReader(); int t=sc.nextInt(); // int t=1; while(t-->0) { int n = sc.nextInt(); String[][] arr = new String[3][n]; for(int i=0;i<3;i++) { for(int j=0;j<n;j++) { String st = sc.next(); arr[i][j] = st; } } HashMap<String , Integer> map = new HashMap<>(); for(int i=0;i<n;i++) { for(int j=0;j<3;j++) { map.put(arr[j][i] , map.getOrDefault(arr[j][i] , 0) + 1); } } for(int i=0;i<3;i++) { int sum = 0; for(int j=0;j<n;j++) { if(map.get(arr[i][j]) == 1) { sum += 3; } else if(map.get(arr[i][j]) == 2) { sum += 1; } else if(map.get(arr[i][j]) == 3) { sum += 0; } } out.print(sum+" "); } out.println(); } out.flush(); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } float nextFloat() { return Float.parseFloat(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long[] readArrayLong(int n) { long[] a=new long[n]; for (int i=0; i<n; i++) a[i]=nextLong(); return a; } } static 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); } } public static int[] radixSort2(int[] a) { int n = a.length; int[] c0 = new int[0x101]; int[] c1 = new int[0x101]; int[] c2 = new int[0x101]; int[] c3 = new int[0x101]; for(int v : a) { c0[(v&0xff)+1]++; c1[(v>>>8&0xff)+1]++; c2[(v>>>16&0xff)+1]++; c3[(v>>>24^0x80)+1]++; } for(int i = 0;i < 0xff;i++) { c0[i+1] += c0[i]; c1[i+1] += c1[i]; c2[i+1] += c2[i]; c3[i+1] += c3[i]; } int[] t = new int[n]; for(int v : a)t[c0[v&0xff]++] = v; for(int v : t)a[c1[v>>>8&0xff]++] = v; for(int v : a)t[c2[v>>>16&0xff]++] = v; for(int v : t)a[c3[v>>>24^0x80]++] = v; return a; } private static long mergeAndCount(int[] arr, int l, int m, int r) { // Left subarray int[] left = Arrays.copyOfRange(arr, l, m + 1); // Right subarray int[] right = Arrays.copyOfRange(arr, m + 1, r + 1); int i = 0, j = 0, k = l;long swaps = 0; while (i < left.length && j < right.length) { if (left[i] < right[j]) arr[k++] = left[i++]; else { arr[k++] = right[j++]; swaps += (m + 1) - (l + i); } } while (i < left.length) arr[k++] = left[i++]; while (j < right.length) arr[k++] = right[j++]; return swaps; } // Merge sort function private static long mergeSortAndCount(int[] arr, int l, int r) { // Keeps track of the inversion count at a // particular node of the recursion tree long count = 0; if (l < r) { int m = (l + r) / 2; // Total inversion count = left subarray count // + right subarray count + merge count // Left subarray count count += mergeSortAndCount(arr, l, m); // Right subarray count count += mergeSortAndCount(arr, m + 1, r); // Merge count count += mergeAndCount(arr, l, m, r); } return count; } static void my_sort(long[] arr) { ArrayList<Long> 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); } } static void reverse_sorted(int[] arr) { ArrayList<Integer> list = new ArrayList<>(); for(int i=0;i<arr.length;i++) { list.add(arr[i]); } Collections.sort(list , Collections.reverseOrder()); for(int i=0;i<arr.length;i++) { arr[i] = list.get(i); } } static int LowerBound(int a[], int x) { // x is the target value or key int l=-1,r=a.length; while(l+1<r) { int m=(l+r)>>>1; if(a[m]>=x) r=m; else l=m; } return r; } static int UpperBound(ArrayList<Integer> list, int x) {// x is the key or target value int l=-1,r=list.size(); while(l+1<r) { int m=(l+r)>>>1; if(list.get(m)<=x) l=m; else r=m; } return l+1; } public static HashMap<Integer, Integer> sortByValue(HashMap<Integer, Integer> hm) { // Create a list from elements of HashMap List<Map.Entry<Integer, Integer> > list = new LinkedList<Map.Entry<Integer, Integer> >(hm.entrySet()); // Sort the list Collections.sort(list, new Comparator<Map.Entry<Integer, Integer> >() { public int compare(Map.Entry<Integer, Integer> o1, Map.Entry<Integer, Integer> o2) { return (o1.getValue()).compareTo(o2.getValue()); } }); // put data from sorted list to hashmap HashMap<Integer, Integer> temp = new LinkedHashMap<Integer, Integer>(); for (Map.Entry<Integer, Integer> aa : list) { temp.put(aa.getKey(), aa.getValue()); } return temp; } static class Queue_Pair implements Comparable<Queue_Pair> { int first , second; public Queue_Pair(int first, int second) { this.first=first; this.second=second; } public int compareTo(Queue_Pair o) { return Integer.compare(o.first, first); } } static void leftRotate(int arr[], int d, int n) { for (int i = 0; i < d; i++) leftRotatebyOne(arr, n); } static void leftRotatebyOne(int arr[], int n) { int i, temp; temp = arr[0]; for (i = 0; i < n - 1; i++) arr[i] = arr[i + 1]; arr[n-1] = temp; } static boolean isPalindrome(String str) { // Pointers pointing to the beginning // and the end of the string int i = 0, j = str.length() - 1; // While there are characters to compare while (i < j) { // If there is a mismatch if (str.charAt(i) != str.charAt(j)) return false; // Increment first pointer and // decrement the other i++; j--; } // Given string is a palindrome return true; } static boolean palindrome_array(char arr[], int n) { // Initialise flag to zero. int flag = 0; // Loop till array size n/2. for (int i = 0; i <= n / 2 && n != 0; i++) { // Check if first and last element are different // Then set flag to 1. if (arr[i] != arr[n - i - 1]) { flag = 1; break; } } // If flag is set then print Not Palindrome // else print Palindrome. if (flag == 1) return false; else return true; } static boolean allElementsEqual(int[] arr,int n) { int z=0; for(int i=0;i<n-1;i++) { if(arr[i]==arr[i+1]) { z++; } } if(z==n-1) { return true; } else { return false; } } static boolean allElementsDistinct(int[] arr,int n) { int z=0; for(int i=0;i<n-1;i++) { if(arr[i]!=arr[i+1]) { z++; } } if(z==n-1) { return true; } else { return false; } } public static void reverse(int[] array) { // Length of the array int n = array.length; // Swaping the first half elements with last half // elements for (int i = 0; i < n / 2; i++) { // Storing the first half elements temporarily int temp = array[i]; // Assigning the first half to the last half array[i] = array[n - i - 1]; // Assigning the last half to the first half array[n - i - 1] = temp; } } public static void reverse_Long(long[] array) { // Length of the array int n = array.length; // Swaping the first half elements with last half // elements for (int i = 0; i < n / 2; i++) { // Storing the first half elements temporarily long temp = array[i]; // Assigning the first half to the last half array[i] = array[n - i - 1]; // Assigning the last half to the first half array[n - i - 1] = temp; } } static boolean isSorted(int[] a) { for (int i = 0; i < a.length - 1; i++) { if (a[i] > a[i + 1]) { return false; } } return true; } static boolean isReverseSorted(int[] a) { for (int i = 0; i < a.length - 1; i++) { if (a[i] < a[i + 1]) { return false; } } return true; } static int[] rearrangeEvenAndOdd(int arr[], int n) { ArrayList<Integer> list = new ArrayList<>(); for(int i=0;i<n;i++) { if(arr[i]%2==0) { list.add(arr[i]); } } for(int i=0;i<n;i++) { if(arr[i]%2!=0) { list.add(arr[i]); } } int len = list.size(); int[] array = list.stream().mapToInt(i->i).toArray(); return array; } static long[] rearrangeEvenAndOddLong(long arr[], int n) { ArrayList<Long> list = new ArrayList<>(); for(int i=0;i<n;i++) { if(arr[i]%2==0) { list.add(arr[i]); } } for(int i=0;i<n;i++) { if(arr[i]%2!=0) { list.add(arr[i]); } } int len = list.size(); long[] array = list.stream().mapToLong(i->i).toArray(); return array; } static boolean isPrime(long n) { // Check if number is less than // equal to 1 if (n <= 1) return false; // Check if number is 2 else if (n == 2) return true; // Check if n is a multiple of 2 else if (n % 2 == 0) return false; // If not, then just check the odds for (long i = 3; i <= Math.sqrt(n); i += 2) { if (n % i == 0) return false; } return true; } static long getSum(long n) { long sum = 0; while (n != 0) { sum = sum + n % 10; n = n/10; } return sum; } static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } static long gcdLong(long a, long b) { if (b == 0) return a; return gcdLong(b, a % b); } static void swap(int i, int j) { int temp = i; i = j; j = temp; } static int countDigit(int n) { return (int)Math.floor(Math.log10(n) + 1); } } class Pair { int first; int second; Pair(int first , int second) { this.first = first; this.second = second; } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
0dc6b3e93c5e184c474d0a310dcfcc12
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Scanner; public class pb3 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t-->0){ int n = sc.nextInt(); ArrayList<String> a = new ArrayList<>(); ArrayList<String> b = new ArrayList<>(); ArrayList<String> c = new ArrayList<>(); HashSet<String > aSet = new HashSet<>(); HashSet<String > bSet = new HashSet<>(); HashSet<String > cSet = new HashSet<>(); for (int i = 0 ; i< n ; i++){ String str = sc.next(); a.add(str); aSet.add(str); } for (int i = 0 ; i< n ; i++){ String str = sc.next(); b.add(str); bSet.add(str); } for (int i = 0 ; i< n ; i++){ String str = sc.next(); c.add(str); cSet.add(str); } int aNet = 0 , bNet = 0 , cNet = 0; for (String str : a){ int cnt = 0; if (bSet.contains(str)) cnt++; if (cSet.contains(str)) cnt++; if (cnt == 0) aNet += 3; if (cnt == 1){ aNet += 1; } } for (String str : b){ int cnt = 0; if (aSet.contains(str)) cnt++; if (cSet.contains(str)) cnt++; if (cnt == 0) bNet += 3; if (cnt == 1){ bNet += 1; } } for (String str : c){ int cnt = 0; if (bSet.contains(str)) cnt++; if (aSet.contains(str)) cnt++; if (cnt == 0) cNet += 3; if (cnt == 1){ cNet += 1; } } System.out.println(aNet + " " + bNet + " " + cNet); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
fcef4e25c31213312d91beaca764177d
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
/* package codechef; // don't place package name! */ import java.math.*; import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public final class Main { FastReader s; public static void main (String[] args) throws java.lang.Exception { new Main().run(); } void run() { s = new FastReader(); solve(); } StringBuffer sb; void solve() { sb = new StringBuffer(); for(int T = s.nextInt();T > 0;T--) start(); System.out.println(sb); } void start() { int n = s.nextInt(); String [] x = s.nextLine().trim().split(" "); String [] y = s.nextLine().trim().split(" "); String [] z = s.nextLine().trim().split(" "); HashMap<String,Integer> xa = new HashMap<>(); for(int i = 0; i<n; i++) { xa.put(x[i],xa.getOrDefault(x[i],0)+1); xa.put(y[i],xa.getOrDefault(y[i],0)+1); xa.put(z[i],xa.getOrDefault(z[i],0)+1); } int a1 = 0; int b1 = 0; int c1 = 0; for(String a : x) { int val = xa.get(a); if(val == 1) a1+=3; else if(val == 2) { a1++; } } for(String a : y) { int val = xa.get(a); if(val == 1) b1+=3; else if(val == 2) { b1++; } } for(String a : z) { int val = xa.get(a); if(val == 1) c1+=3; else if(val == 2) { c1++; } } sb.append(a1+" "+b1+" "+c1+"\n"); } int lower_bound(int [] arr , int key) { int i = 0; int j = arr.length-1; if(arr[j] < key)return -1; while(i<j) { int mid = (i+j)/2; if(arr[mid] == key) { j = mid; } else if(arr[mid] < key) { i = mid+1; } else j = mid-1; } return i; } int upper_bound(int [] arr , int key) { int i = 0; int j = arr.length-1; if(arr[j] <= key)return -1; while(i<j) { int mid = (i+j)/2; if(arr[mid] <= key) { i = mid+1; } else j = mid; } return i; } // pair static class Pair implements Comparable<Pair> { long x; long y; Pair(long x,long y){ this.x=x; this.y=y; } @Override public int compareTo(Pair o) { if(this.x>o.x) return 1; else if(this.x<o.x) return -1; else { if(this.y>o.y) return 1; else if(this.y<o.y) return -1; else return 0; } } /* FOR TREE MAP PAIR USE */ // public int compareTo(Pair o) { // if (x > o.x) { // return 1; // } // if (x < o.x) { // return -1; // } // if (y > o.y) { // return 1; // } // if (y < o.y) { // return -1; // } // return 0; // } // public int hashCode() // { // final int temp = 14; // int ans = 1; // ans =x*31+y*13; // return ans; // } // // // Equal objects must produce the same // // hash code as long as they are equal // @Override // public boolean equals(Object o) // { // if (this == o) { // return true; // } // if (o == null) { // return false; // } // if (this.getClass() != o.getClass()) { // return false; // } // Pair other = (Pair)o; // if (this.x != other.x || this.y!=other.y) { // return false; // } // return true; // } } //end //sorting static void sort(int[] A){ int n = A.length; Random rnd = new Random(); for(int i=0; i<n; ++i){ int tmp = A[i]; int randomPos = i + rnd.nextInt(n-i); A[i] = A[randomPos]; A[randomPos] = tmp; } Arrays.sort(A); } static void sort(long[] A){ int n = A.length; Random rnd = new Random(); for(int i=0; i<n; ++i){ long tmp = A[i]; int randomPos = i + rnd.nextInt(n-i); A[i] = A[randomPos]; A[randomPos] = tmp; } Arrays.sort(A); } static String sort(String s) { Character ch[]=new Character[s.length()]; for(int i=0;i<s.length();i++) { ch[i]=s.charAt(i); } Arrays.sort(ch); StringBuffer st=new StringBuffer(""); for(int i=0;i<s.length();i++) { st.append(ch[i]); } return st.toString(); } //end //long array input public long [] longArr(int len) { // long arr input long [] arr = new long[len]; String [] strs = s.nextLine().trim().split("\\s+"); for(int i =0; i<len; i++) { arr[i] = Long.parseLong(strs[i]); } return arr; } // int arr input public int [] intArr(int len) { // long arr input int [] arr = new int[len]; String [] strs = s.nextLine().trim().split("\\s+"); for(int i =0; i<len; i++) { arr[i] = Integer.parseInt(strs[i]); } return arr; } // FastReader 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\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
5e6f8e569b47085b4aa40a4e8e509ac9
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.io.*; import java.lang.reflect.Array; import java.util.*; import static java.lang.Math.min; public class Main { public static void main(String[] args) { Reader reader = new Reader(); PrintWriter out = new PrintWriter(System.out); int T = reader.nextInt(); for (int tt = 0; tt < T; ++tt) { int n = reader.nextInt(); List<Integer> first, second, third = new ArrayList<>(n); List<Integer> answer = new ArrayList<>(Arrays.asList(0, 0, 0)); Map<String, List<Boolean>> dict = new HashMap<>(); for(int i = 0; i < 3; ++i) { for(int j = 0; j < n; ++j) { String word = reader.next(); if(dict.containsKey(word)) { List<Boolean> updated = dict.get(word); updated.set(i, true); dict.put(word, updated); } else { List<Boolean> initial = new ArrayList<>(Arrays.asList(false, false, false)); initial.set(i, true); dict.put(word, initial); } } } for(var curr : dict.entrySet()) { if(curr.getValue().get(0) && !curr.getValue().get(1) && !curr.getValue().get(2)) { answer.set(0, 3 + answer.get(0)); } else if(curr.getValue().get(0) && curr.getValue().get(1) && !curr.getValue().get(2)) { answer.set(0, 1 + answer.get(0)); answer.set(1, 1 + answer.get(1)); } else if(curr.getValue().get(0) && !curr.getValue().get(1) && curr.getValue().get(2)) { answer.set(0, 1 + answer.get(0)); answer.set(2, 1 + answer.get(2)); } else if(curr.getValue().get(1) && !curr.getValue().get(0) && !curr.getValue().get(2)) { answer.set(1, 3 + answer.get(1)); } else if(curr.getValue().get(1) && !curr.getValue().get(0) && curr.getValue().get(2)) { answer.set(1, 1 + answer.get(1)); answer.set(2, 1 + answer.get(2)); } else if(curr.getValue().get(2) && !curr.getValue().get(0) && !curr.getValue().get(1)) { answer.set(2, 3 + answer.get(2)); } } System.out.println(answer.get(0) + " " + answer.get(1) + " " + answer.get(2)); } out.close(); } 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 class Reader { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
bcf72f194f38d74b88e6f09da72e1b4e
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
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 SolutionC { public static void main(String[] args) throws Exception { out = new PrintWriter(new BufferedOutputStream(System.out)); sc = new FastReader(); int test = sc.nextInt(); for (int t = 1; t <= test; t++) { solve(t); } out.close(); } private static void solve(int t) { int n = sc.nextInt(); Set<String> personA = new HashSet<>(); Set<String> personB = new HashSet<>(); Set<String> personC = new HashSet<>(); update(personA, n); update(personB, n); update(personC, n); getScore(personA, personB, personC); getScore(personB, personA, personC); getScore(personC, personA, personB); out.println(); } private static void getScore(Set<String> personA, Set<String> personB, Set<String> personC) { int score = 0; for (String s : personA) { int points = 3; if (personB.contains(s) && personC.contains(s)) { points = 0; }else if (personB.contains(s) || personC.contains(s)) { points = 1; } score += points; } out.print(score + " "); } private static void update(Set<String> person, int n) { for (int i = 0; i < n; i++) { String s = sc.next(); person.add(s); } } 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\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
0ec1951beb70c322caed674726f2dea5
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
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.HashMap; import java.util.List; import java.util.StringTokenizer; public class cf1722C { public static void main(String[] args) { FastReader sc = new FastReader(); int t = sc.nextInt(); while(t-->0) { int n = sc.nextInt(); HashMap<String, ArrayList<Integer>> wordToUser = new HashMap<>(); int[] c = new int[3]; for(int i=0; i<3; i++) { for(int j=0; j<n; j++) { String s = sc.next(); if(!wordToUser.containsKey(s)) { wordToUser.put(s, new ArrayList<>(Arrays.asList(i))); } else { ArrayList<Integer> list = wordToUser.get(s); list.add(i); wordToUser.put(s, list); } } } for(var entry : wordToUser.entrySet()) { List<Integer> val = entry.getValue(); if (val.size() == 1) { c[val.get(0)] += 3; } else if (val.size() == 2) { c[val.get(0)] += 1; c[val.get(1)] += 1; } } System.out.println(c[0] + " " + c[1] + " " + c[2]); } } 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\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
e5f68ec55836fcd8bf0c1201d4c3cba2
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
// "static void main" must be defined in a public class. import java.util.*; public class Main { public static void main(String[] args) { Scanner scn = new Scanner(System.in); int shh = scn.nextInt(); for(int h = 0 ; h < shh ; h++){ int n = scn.nextInt(); scn.nextLine(); String s1 = scn.nextLine(); String s2 = scn.nextLine(); String s3 = scn.nextLine(); String[] arr1 = s1.split(" "); String[] arr2 = s2.split(" "); String[] arr3 = s3.split(" "); boolean ans = true; HashMap<String, Integer> map = new HashMap<>(); int a = 0; int b= 0; int c = 1; for(int i = 0 ; i < n ; i++){ if(map.containsKey(arr1[i])){ int val = map.get(arr1[i]); map.put(arr1[i] , val+1); }else{ map.put(arr1[i] ,1); } if(map.containsKey(arr2[i])){ int val = map.get(arr2[i]); map.put(arr2[i] , val+1); }else{ map.put(arr2[i] ,1); } if(map.containsKey(arr3[i])){ int val = map.get(arr3[i]); map.put(arr3[i] , val+1); }else{ map.put(arr3[i] ,1); } } for(int i = 0 ; i< n ; i++){ int val1 = map.get(arr1[i]); int val2 = map.get(arr2[i]); int val3 = map.get(arr3[i]); if(val1 == 1){ a += 3; }else if(val1 == 2){ a += 1; } if(val2 == 1){ b += 3; }else if(val2 == 2){ b += 1; } if(val3 == 1){ c += 3; }else if(val3 == 2){ c += 1; } } System.out.println(a + " " + b + " " + (c-1)); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
bb1f65220b91230dd9be2e1030986c0b
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
// "static void main" must be defined in a public class. import java.util.*; public class Main { public static void main(String[] args) { Scanner scn = new Scanner(System.in); int shh = scn.nextInt(); for(int h = 0 ; h < shh ; h++){ int n = scn.nextInt(); scn.nextLine(); String s1 = scn.nextLine(); String s2 = scn.nextLine(); String s3 = scn.nextLine(); String[] arr1 = s1.split(" "); String[] arr2 = s2.split(" "); String[] arr3 = s3.split(" "); boolean ans = true; HashMap<String, Integer> map = new HashMap<>(); int a = 0; int b= 0; int c = 1; for(int i = 0 ; i < n ; i++){ if(map.containsKey(arr1[i])){ int val = map.get(arr1[i]); map.put(arr1[i] , val+1); }else{ map.put(arr1[i] ,1); } if(map.containsKey(arr2[i])){ int val = map.get(arr2[i]); map.put(arr2[i] , val+1); }else{ map.put(arr2[i] ,1); } if(map.containsKey(arr3[i])){ int val = map.get(arr3[i]); map.put(arr3[i] , val+1); }else{ map.put(arr3[i] ,1); } } for(int i = 0 ; i< n ; i++){ int val1 = map.get(arr1[i]); int val2 = map.get(arr2[i]); int val3 = map.get(arr3[i]); if(val1 == 1){ a += 3; }else if(val1 == 2){ a += 1; } if(val2 == 1){ b += 3; }else if(val2 == 2){ b += 1; } if(val3 == 1){ c += 3; }else if(val3 == 2){ c += 1; } } System.out.println(a + " " + b + " " + (c-1)); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
baadba236c82cf73af4a7b1a375b6ef3
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); for (int z = 0; z < t; z++) { int n = in.nextInt(); HashMap<String, Integer> first = new HashMap<>(); HashMap<String, Integer> third = new HashMap<>(); HashMap<String, Integer> second = new HashMap<>(); for(int i = 0; i < n; i++){ first.put(in.next(), 1); } for(int i = 0; i < n; i++){ second.put(in.next(), 1); } for(int i = 0; i < n; i++){ third.put(in.next(), 1); } int amo1 = 0; for(Map.Entry<String, Integer> entry: first.entrySet()){ if(second.containsKey(entry.getKey()) && third.containsKey(entry.getKey())) continue; if(second.containsKey(entry.getKey()) || third.containsKey(entry.getKey())) amo1++; else if(!second.containsKey(entry.getKey()) && !third.containsKey(entry.getKey())) amo1 += 3; } int amo2 = 0; for(Map.Entry<String, Integer> entry: second.entrySet()){ if(first.containsKey(entry.getKey()) && third.containsKey(entry.getKey())) continue; if(first.containsKey(entry.getKey()) || third.containsKey(entry.getKey())) amo2++; else if(!first.containsKey(entry.getKey()) && !third.containsKey(entry.getKey())) amo2 += 3; } int amo3 = 0; for(Map.Entry<String, Integer> entry: third.entrySet()){ if(second.containsKey(entry.getKey()) && first.containsKey(entry.getKey())) continue; if(second.containsKey(entry.getKey()) || first.containsKey(entry.getKey())) amo3++; else if(!second.containsKey(entry.getKey()) && !first.containsKey(entry.getKey())) amo3 += 3; } System.out.printf("%d %d %d\n", amo1, amo2, amo3); } } private static boolean isEqual(char c1, char c2){ if(c1 == c2) return true; if((c1 == 'B' || c1 == 'G') && (c2 == 'B' || c2 == 'G')) return true; return false; } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
0b461530063f1353cd731090673a5563
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.HashMap; import java.util.HashSet; import java.util.Scanner; public class WordGame { public static void main(String[] args) { Scanner in = new Scanner(System.in); int t= in.nextInt(); for(int T=1; T<=t; T++) { int n = in.nextInt(); HashMap<String, Integer> hm = new HashMap<>(); String s[][]= new String[3][n]; for(int i=0; i<3; i++) { for(int j=0; j<n; j++) { s[i][j] = in.next(); } } for(int i=0; i<3; i++) { for(int j=0; j<n; j++) { hm.put(s[i][j], hm.getOrDefault(s[i][j],0)+1); } } for(int i=0;i<3; i++ ) { int pts=0; for(int j=0; j<n; j++) { if(hm.get(s[i][j])==1) pts+=3; else if(hm.get(s[i][j])==2) pts+=1; else pts+=0; } System.out.print(pts+" "); } System.out.println(); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
490c31795e753ae89903da60809d73dd
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.*; public class MyClass { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int tc=sc.nextInt(); while(tc>0) { int n=sc.nextInt(); String arr[][]=new String[3][n]; for(int i=0;i<3;i++) { for(int j=0;j<n;j++) arr[i][j]=sc.next(); } HashMap<String,Integer> map=new HashMap<>(); for(int i=0;i<3;i++) { for(int j=0;j<n;j++) { String s=arr[i][j]; if(map.containsKey(s)) map.put(s,map.get(s)+1); else map.put(s,1); } } for(int i=0;i<3;i++) { int sco=0; for(int j=0;j<n;j++) { String s=arr[i][j]; int f=map.get(s); if(f==1) sco+=3; else if(f==2) sco+=1; } System.out.print(sco+" "); } System.out.println(); --tc; } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
118b2b093ccd661b487d961a0d007ade
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.Arrays; import java.util.HashSet; import java.util.Scanner; import java.util.Stack; public class aaaaaa { static HashSet<Character> set; static Scanner sc; public static void solve() { HashSet<String> a = new HashSet<>(); HashSet<String> b = new HashSet<>(); HashSet<String> c = new HashSet<>(); int words = sc.nextInt(); for(int i=0; i<words; i++){ a.add(sc.next()); } for(int i=0; i<words; i++){ b.add(sc.next()); } for(int i=0; i<words; i++){ c.add(sc.next()); } int aScore = 0; int bScore = 0; int cScore = 0; for(String word : a){ if(b.contains(word) && c.contains(word)) continue; if(b.contains(word)){ aScore++; bScore++; b.remove(word); } else if(c.contains(word)){ aScore++; cScore++; c.remove(word); } else aScore += 3; } for(String word : b){ if(a.contains(word) && c.contains(word)) continue; if(c.contains(word)){ bScore++; cScore++; c.remove(word); } else bScore += 3; } for(String word : c){ if(a.contains(word) && b.contains(word)) continue; cScore += 3; } System.out.println(aScore + " " + bScore + " " + cScore); } public static void main(String[] args) { sc = new Scanner(System.in); int t = sc.nextInt(); while (t-->0){ set = new HashSet<>(); set.add('T'); set.add('i'); set.add('m'); set.add('u'); set.add('r'); solve(); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
0f7da496c1abd1acdf73c45bebfb5d88
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.HashMap; import java.util.Scanner; public class wordgame { public static void main(String[] args) { Scanner s = new Scanner(System.in); int t = s.nextInt(); while (t-- > 0) { HashMap<String, Integer> app = new HashMap<String, Integer>(); int n = s.nextInt(); s.nextLine(); String[] p1 = s.nextLine().split(" "); String[] p2 = s.nextLine().split(" "); String[] p3 = s.nextLine().split(" "); for (int i = 0; i < n; i++) { if (!app.containsKey(p1[i])) app.put(p1[i], 1); else app.put(p1[i], app.get(p1[i]) + 1); if (!app.containsKey(p2[i])) app.put(p2[i], 1); else app.put(p2[i], app.get(p2[i]) + 1); if (!app.containsKey(p3[i])) app.put(p3[i], 1); else app.put(p3[i], app.get(p3[i]) + 1); } int s1 = getScore(p1, app); int s2 = getScore(p2, app); int s3 = getScore(p3, app); System.out.println(s1 + " " + s2 + " " + s3); } } static int getScore(String[] arr, HashMap<String, Integer> app) { int score = 0; for (int i = 0; i < arr.length; i++) { int count = app.get(arr[i]); if (count == 1) score += 3; else if (count == 2) score++; } return score; } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
56c96846c49450e54ddf552871fe8820
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class sol { public static void main(String args[]) { Scanner sc=new Scanner(System.in); for(int t=sc.nextInt();t>0;t--){ int n=sc.nextInt(); HashMap<String,Integer> s=new HashMap<String,Integer>(); String a[][]=new String[3][n]; for(int i=0;i<3;i++){ for(int j=0;j<n;j++){ String check=sc.next(); a[i][j]=check; if(s.containsKey(check)){ s.put(check,s.get(check)+1); }else s.put(check,1); } } for(int i=0;i<3;i++){ int ans=0; for(int j=0;j<n;j++){ int time=s.get(a[i][j]); if(time==1) ans+=3; else if(time==2) ans+=1; } System.out.print(ans+" "); } System.out.println(); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
0044545e1e0733db107725cc0f955d6f
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
//Code By KB. import java.beans.Visibility; import java.io.*; import java.lang.annotation.Target; import java.lang.reflect.Array; import java.nio.channels.AsynchronousCloseException; import java.security.KeyStore.Entry; import java.util.*; import java.util.logging.*; import java.io.*; import java.util.logging.*; import java.util.regex.*; import javax.management.ValueExp; import javax.print.DocFlavor.INPUT_STREAM; import javax.swing.plaf.basic.BasicBorders.SplitPaneBorder; import javax.swing.text.AbstractDocument.LeafElement; import javax.xml.validation.Validator; public class Codeforces { public static void main(String[] args) { FlashFastReader in = new FlashFastReader(System.in); try(PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));) { new Codeforces().solution(in, out); } catch (Exception e) { System.out.println(e.getStackTrace()); } } public void solution(FlashFastReader in, PrintWriter out) { try { int t = in.nextInt(); while (t-->0) { int n = in.nextInt(); String s1[] = new String[n]; String s2[] = new String[n]; String s3[] = new String[n]; HashMap<String , Integer> map = new HashMap<>(); int n1 = 0 , n2 = 0 , n3 =0; for (int i = 0; i < n; i++) { s1[i] = in.nextString(); map.put(s1[i],map.getOrDefault(s1[i], 0)+1); } for (int i = 0; i < n; i++) { s2[i] = in.nextString(); map.put(s2[i],map.getOrDefault(s2[i], 0)+1); } for (int i = 0; i < n; i++) { s3[i] = in.nextString(); map.put(s3[i],map.getOrDefault(s3[i], 0)+1); } for (int i = 0; i < s3.length; i++) { if (map.get(s1[i])==1) { n1+=3; } else if (map.get(s1[i])==2) { n1+=1; } } for (int i = 0; i < s3.length; i++) { if (map.get(s2[i])==1) { n2+=3; } else if (map.get(s2[i])==2) { n2+=1; } } for (int i = 0; i < s3.length; i++) { if (map.get(s3[i])==1) { n3+=3; } else if (map.get(s3[i])==2) { n3+=1; } } out.println(n1+" "+n2+" "+n3); } } catch (Exception exception) { out.println(exception); } } public int countSquares(int[][] matrix) { int dp [][] = new int [matrix.length+1][matrix[0].length+1]; for (int i = 1; i <=matrix.length; i++) { for (int j = 1; j <=matrix[0].length; j++) { if (matrix[i][j]==1) { if (i>=1&&j>=1) { dp[i][j] =1+ Math.min(dp[i-1][j], Math.min(dp[i-1][j-1], dp[i][j-1]) ); } } x+=dp[i][j]; } } return x; } HashMap<Integer, Integer> map = new HashMap<>(); public int totalNQueens(int n) { if (n==1) { return 1; } if (n==2||n==3) { return 0; } dfsNqueens( map , 0 , n ); return x; } public void dfsNqueens( HashMap<Integer, Integer>map , int col , int n ) { if (col == n) { x++; return; } for (int i = 0; i < n; i++) { map.put(col, i); boolean f = true; for (int j = 0; j < n; j++) { if (map.containsKey(j)) { if (map.get(j)==i||Math.abs(col - j)==Math.abs(map.get(j)-i) ) { f = false; } } } if (f) { dfsNqueens(map, col+1, n); } } } public int[] minOperations(String boxes) { int a [] = new int[boxes.length()]; for (int i = 0; i < boxes.length(); i++) { StringBuilder sb = new StringBuilder(boxes); int x = 0; for (int j = 0; j < sb.length(); j++) { if (sb.indexOf("1")<0) { break; } x+=Math.abs(i - sb.indexOf("1")); sb.setCharAt(sb.indexOf("1"), '0'); } a[i] = x; } return a; } public List<List<Integer>> subsets(int[] nums) { List<Integer> curr = new ArrayList<>(); subsetsGen(0, nums , curr); return list; } public void subsetsGen(int j ,int[] n , List<Integer>curr) { list.add(curr); for (int i = j; i < n.length; i++) { curr.add(n[i]); subsetsGen(j+1, n, curr); curr.remove(curr.size()-1); } } boolean visited[]= new boolean[1000]; public int findCircleNum(int[][] isConnected) { for (int i = 0; i < isConnected.length; i++) { if (visited[i]!=true) { x++; dfsFindProvinces( i , isConnected ); } } return x; } public void dfsFindProvinces( int i ,int [][]isConnected ) { visited[i]=true; for (int j = 0; j < isConnected.length; j++) { if (isConnected[i][j]==1&&visited[j]!=true) { dfsFindProvinces(j, isConnected); } } } public int[] canSeePersonsCount(int[] heights) { int ans [] = new int[heights.length]; Stack<Integer> stck = new Stack<>(); for (int i = 0; i < heights.length; i++) { while(!stck.isEmpty()&&heights[stck.peek()]<heights[i]) { ans[stck.pop()]++; } if (!stck.isEmpty()) { ans[stck.peek()]++; } stck.push(i); } return ans; } public int pathSum(TreeNode root, int targetSum) { List<Integer> path = new ArrayList<>(); dsfPathSum(root, targetSum , 0 ,path); pathSum(root.left, targetSum); pathSum(root.right, targetSum); for (List<Integer> p : list) { for (int i = 0; i < p.size() ; i++) { System.out.print(p.get(i)+" "); } System.out.println(); } return list.size(); } public void dsfPathSum(TreeNode root , int t , long sum , List<Integer>path ) { if (root==null) { return; } sum+=root.val ; path.add(root.val); if (sum==t) { list.add(path); } dsfPathSum(root.left, t, sum , path); dsfPathSum(root.right, t, sum , path); } public ListNode addTwoNumbers(ListNode l1, ListNode l2) { ListNode l = new ListNode(); int a = 0; int b =0; l1 = reverseList(l1); l2 = reverseList(l2); while (l1!=null) { a=a*10+l1.val; l1=l1.next; } while (l2!=null) { b=b*10+l2.val; l2=l2.next; } a=a+b; ListNode head = null; while (a!=0) { int r = a%10; if(l==null) { head= new ListNode(r); l=head; }else { l.next = new ListNode(r); l= l.next; } a/=10; } return head; } public ListNode reverseList(ListNode head) { if(head==null || head.next==null) return head; ListNode nextNode=head.next; ListNode newHead=reverseList(nextNode); nextNode.next=head; head.next=null; return newHead; } int x=0; public int uniquePathsIII(int[][] grid) { int zeros = 0; int sx=0; int sy =0; for (int i = 0; i < grid.length; i++) { for (int j = 0; j < grid[0].length; j++) { if (grid[i][j]==0) { zeros++; } else if (grid[i][j]==1) { sx=i; sy=j; } } } dfsUniquePaths(zeros , sx , sy , grid); return x; } public void dfsUniquePaths(int zeros ,int i ,int j , int g[][]) { if (i<0||i>=g.length||j>=g[0].length||j<0||g[i][j]<0) { System.out.println(i+" "+j); return; } if (g[i][j]==2) { if(zeros==0) x++; return; } g[i][j]=-2; zeros--; dfsUniquePaths(zeros, i+1, j, g); dfsUniquePaths(zeros, i-1, j, g); dfsUniquePaths(zeros, i, j+1, g); dfsUniquePaths(zeros, i, j-1, g); g[i][j]=0; zeros++; } public TreeNode addOneRow(TreeNode root, int val, int depth) { if (depth==1) { TreeNode t = new TreeNode(val); t.left=root; return t; } dfsAddOneRow(root , 1 , val , depth); return root; } public void dfsAddOneRow(TreeNode root , int currD , int val , int depth) { if (root==null) { return ; } if (currD==depth) { TreeNode l = root.left; root.left = new TreeNode(val); root.left.left = l; TreeNode r = root.right; root.right = new TreeNode(val); root.right.right = r; } currD++; dfsAddOneRow(root.left, currD, val, depth); dfsAddOneRow(root.right, currD, val, depth); } public List<List<Integer>> threeSum(int[] nums) { int n = nums.length; int sum =0; HashSet<List<Integer>> h = new HashSet<List<Integer>>(); for (int i = 0; i < nums.length; i++) { sum=nums[i]; for (int j = i+1; j < nums.length; j++) { sum+=nums[j]; int k =j; n = nums.length; while (k<n) { int mid = (k+n)/2; if ((sum+nums[mid])==0) { HashSet<Integer> m = new HashSet<>(); m.add(nums[i]); m.add(nums[j]); m.add(nums[mid]); if (m.size()==3) { List<Integer>x = new ArrayList<>(); x.add(nums[i]); x.add(nums[j]); x.add( nums[mid]); h.add(x); } } else if ((sum+nums[mid])>0) { n=mid; } else { k=mid; } } } } return list; } public int uniquePaths(int m, int n) { int dp[][]= new int [m][n]; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { if(i==0&&j==0) { dp[i][j]=1; } else if (i==0) { dp[i][j]=dp[i][j]+dp[i][j-1]; } else if (j==0) { dp[i][j]=dp[i][j]+dp[i-1][j]; } else { dp[i][j]+=dp[i][j-1]+dp[i-1][j]; } } } return dp[m-1][n-1]; } public int maxProfit(int[] prices) { int p = -1; return p ; } public int trap(int[] height) { int n = height.length; int left[] = new int [n]; int right[] = new int [n]; left[0] = height[0]; for (int i = 1; i <n; i++) { left[i] = Math.max(height[i], left[i-1]); } right[n-1]=height[n-1]; for (int i = n-2; i>=0 ; i--) { right[i] = Math.max(height[i], right[i+1]); } for (int i = 1; i < right.length-1; i++) { int s =Math.min(left[i] , right[i])-height[i]; if (s>0) { x+=s; } } return x; } public int maxProduct(int[] nums) { int maxSoFar = Integer.MIN_VALUE; int maxTillEnd = 0; for (int i = 0; i < nums.length; i++) { maxTillEnd*=nums[i]; if (maxSoFar<maxTillEnd) { maxSoFar=maxTillEnd; } if (maxTillEnd<=0) { maxTillEnd=1; } } return maxSoFar; } public int maximumScore(int[] nums, int[] multipliers) { int n = multipliers.length; int dp[] = new int[n+1]; for (int i = 1; i < multipliers.length; i++) { for (int j = 1; j < nums.length; j++) { dp[i] = Math.max(dp[j-1], multipliers[i-1]*nums[i-1]); } } return dp[n]; } public int islandPerimeter(int[][] grid) { for (int i = 0; i < grid.length; i++) { for (int j = 0; j < grid[0].length; j++) { if(grid[i][j]==1){ dfsIslandPerimeter(i , j , grid); } } } return x; } public void dfsIslandPerimeter(int i , int j , int[][] grid) { if(i<0||i>=grid.length||j<0||j>grid[0].length) { x++; return; } if(grid[i][j]==0) { x++; return; } if(grid[i][j]==1) { return; } dfsIslandPerimeter(i+1, j, grid); dfsIslandPerimeter(i-1, j, grid); dfsIslandPerimeter(i, j+1, grid); dfsIslandPerimeter(i, j-1, grid); } public int[] findOriginalArray(int[] changed) { int n =changed.length; int m = n/2; int a[] = new int[m]; if (n<2) { return new int[]{}; } if (n%2!=0) { return new int[]{}; } TreeMap<Integer , Integer> map = new TreeMap<>(); for (int i = 0; i < changed.length; i++) { map.put(changed[i], map.getOrDefault(changed[i] ,0)+1); } int j =0; for (Map.Entry<Integer , Integer> e : map.entrySet()) { if (map.containsKey(e.getKey()*2)&&map.get(e.getKey()*2)>=1&&map.get(e.getKey())>=1) { map.put(e.getKey(), map.get(e.getKey()) -1); if(j==n-1) break; a[j++] = e.getKey(); } } return a; } public int jump(int[] nums) { int n =nums.length; int jumps =1; int i =0; int j =0; while (i<n) { int max =0; for (j=i+1 ;j<=i+nums[i];j++) { max = Math.max(max , nums[j]+j); } jumps++; i=max; } return jumps; } static void sort(int[] arr) { if (arr.length < 2) return; int mid = arr.length / 2; int[] left_half = new int[mid]; int[] right_half = new int[arr.length - mid]; // copying the elements of array into left_half for (int i = 0; i < mid; i++) { left_half[i] = arr[i]; } // copying the elements of array into right_half for (int i = mid; i < arr.length; i++) { right_half[i - mid] = arr[i]; } sort(left_half); sort(right_half); merge(arr, left_half, right_half); } static void merge(int[] arr, int[] left_half, int[] right_half) { int i = 0, j = 0, k = 0; while (i < left_half.length && j < right_half.length) { if (left_half[i] < right_half[j]) { arr[k++] = left_half[i++]; } else { arr[k++] = right_half[j++]; } } while (i < left_half.length) { arr[k++] = left_half[i++]; } while (j < right_half.length) { arr[k++] = right_half[j++]; } } public int minCostClimbingStairs(int[] cost) { int n = cost.length; int dp[] = new int[n+1]; dp[1] = cost[0]; dp[2] = cost[1]; for (int i = 3; i <=n; i++) { dp[i]=cost[i-1]+Math.min(dp[i-1], dp[i-2]); } return dp[n]; } TreeNode newAns =null; public TreeNode removeLeafNodes(TreeNode root, int target) { newAns = root; dfsRemoveNode(newAns , target); return newAns; } public void dfsRemoveNode(TreeNode root , int t) { if (root==null) { return; } if (root.val==t) { if (root.left!=null) { root=root.left; }else if (root.right!=null){ root=root.right; } else { root=null; } } dfsRemoveNode(root.left, t); dfsRemoveNode(root.right, t); } public int maxProfit(int k, int[] prices) { int n = prices.length; if (n <= 1) return 0; if (k >= n/2) { return stocks(prices, n); } int[][] dp = new int[k+1][n]; for (int i = 1; i <=k; i++) { int c= dp[i-1][0] - prices[0]; for (int j = 1; j < n; j++) { dp[i][j] = Math.max(dp[i][j-1], prices[j] + c); c = Math.max(c, dp[i-1][j] - prices[j]); } } return dp[k][n-1]; } public int stocks(int [] prices , int n ) { int maxPro = 0; for (int i = 1; i < n; i++) { if (prices[i] > prices[i-1]) maxPro += prices[i] - prices[i-1]; } return maxPro; } public List<List<Integer>> combine(int n, int k) { List<Integer> x = new ArrayList<>(); combinations( n , k , 1 ,x); return list; } public void combinations(int n , int k ,int startPos , List<Integer> x) { if (k==x.size()) { list.add(new ArrayList<>(x)); //x=new ArrayList<>(); return; } for (int i = startPos; i <=n; i++) { x.add(i); combinations(n, k, i+1, x); x.remove(x.size()-1); } } List<List<Integer>> list = new ArrayList<>(); public List<List<Integer>> permute(int[] a) { List<Integer> x = new ArrayList<>(); permutations(a , 0 ,a.length ,x ); return list ; } public void permutations(int a[] , int startPos , int l , List<Integer>x) { if (l==x.size()) { list.add(new ArrayList<>(x)); //x=new ArrayList<>(); } for (int i = 0; i <=l; i++) { if (!x.contains(a[i])) { x.add(a[i]); permutations(a, i, l, x); x.remove(x.size()-1); } } } List<String> str = new ArrayList<>(); public List<String> letterCasePermutation(String s) { casePermutations(s , 0 , s.length() , "" ); return str; } public void casePermutations(String s ,int i , int l , String curr) { if (curr.length()==l) { str.add(curr); return; } char b = s.charAt(i); curr+=b; casePermutations(s, i+1, l, curr); curr = new StringBuilder(curr).deleteCharAt(curr.length()-1).toString(); if (Character.isAlphabetic(b)&&Character.isLowerCase(b)) { curr+=Character.toUpperCase(b); casePermutations(s, i+1, l, curr); curr = new StringBuilder(curr).deleteCharAt(curr.length()-1).toString(); } else if (Character.isAlphabetic(b)) { curr+=Character.toLowerCase(b); casePermutations(s, i+1, l, curr); curr = new StringBuilder(curr).deleteCharAt(curr.length()-1).toString(); } } TreeNode ans= null; public TreeNode lcaDeepestLeaves(TreeNode root) { dfslcaDeepestLeaves(root , 0 ); return ans; } public void dfslcaDeepestLeaves(TreeNode root , int level) { if (root==null) { return; } if (depth(root.left)==depth(root.right)) { ans= root; return; } else if (depth(root.left)>depth(root.right)){ dfslcaDeepestLeaves(root.left, level+1); } else { dfslcaDeepestLeaves(root.right, level+1); } } public int depth(TreeNode root) { if (root==null) { return 0; } return 1+Math.max(depth(root.left), depth(root.right)); } TreeMap<Integer , Integer> m = new TreeMap<>(); public int maxLevelSum(TreeNode root) { int maxlevel =0; int mx = Integer.MIN_VALUE; dfsMaxLevelSum(root , 0); for (Map.Entry<Integer,Integer> e : m.entrySet()) { if (e.getValue()>mx) { mx=e.getValue(); maxlevel=e.getKey()+1; } } return maxlevel; } public void dfsMaxLevelSum(TreeNode root , int currLevel) { if (root==null) { return; } if (!m.containsKey(currLevel)) { m.put(currLevel, root.val); } else { m.put(currLevel, m.get(currLevel)+root.val); } dfsMaxLevelSum(root.left, currLevel+1); dfsMaxLevelSum(root.right, currLevel+1); } int teampPerf = 0; int teampSpeed = 0; public int maxPerformance(int n, int[] speed, int[] efficiency, int k) { int [][] map = new int[efficiency.length][2]; for (int i = 0; i < efficiency.length; i++) { map[i][0] = efficiency[i]; map[i][1] = speed[i]; } Arrays.sort(map , (e1 , e2 )-> (e2[0] - e1[0])); PriorityQueue<Integer> pq = new PriorityQueue<>(); calmax(map , speed , efficiency , pq , k); return teampPerf ; } public void calmax(int [][]map , int s[] , int e[] , PriorityQueue<Integer>pq , int k) { for (int i = 0 ; i<n ; i++) { if (pq.size()==k) { int lowestSpeed =pq.remove(); teampSpeed-=lowestSpeed; } pq.add(map[i][1]); teampSpeed+=map[i][1]; teampPerf=Math.max(teampPerf, teampSpeed*map[i][1]); } } int maxRob = 0; public int rob(int[] nums) { int one = 0; int two = 0; for (int i = 0; i < nums.length; i++) { if (i%2==0) { one+=nums[i]; } else { two+=nums[i]; } } return Math.max(one, two); } public int numberOfWeakCharacters(int[][] properties) { int c =0; Arrays.sort(properties, (a, b) -> (b[0] == a[0]) ? (a[1] - b[1]) : b[0] - a[0]); PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder()); pq.offer(0); for (int i = 0; i < properties.length; i++) { if (properties[i][1]<pq.peek()) { c++; } pq.offer(properties[i][1]); } return c; } public boolean canFinish(int numCourses, int[][] prerequisites) { boolean f = true ; TreeMap <Integer,Integer> map = new TreeMap<>(); for (int i = 0; i < prerequisites.length; i++) { if (map.get(prerequisites[i][1])!=null) { return false; } map.put(prerequisites[i][0], prerequisites[i][1]); } return f; } int n =0; char res[][] = new char [1000][1000]; public int countBattleships(char[][] board) { for (int i = 0; i < board.length; i++) { for (int j = 0; j < board[0].length; j++) { res[i][j]= board[i][j]; } } for (int i = 0; i < board.length; i++) { for (int j = 0; j < board[0].length; j++) { if (res[i][j]=='X') { int x = dfsB( i , j ,board , res); n++; } } } return n ; } public int dfsB(int i , int j , char [][]b , char [][]res) { if (i<0||i>=b.length|j<0||j>=b[0].length||res[i][j]=='.') { return 0; } if (res[i][j]=='X') { return 1+dfsB(i+1, j, b, res)+dfsB(i, j+1, b, res); } return 0; } List<Integer> l = new ArrayList<>(); public List<Integer> rightSideView(TreeNode root) { return dfsRightSideView(root); } public List<Integer> dfsRightSideView(TreeNode root) { if (root!=null) { l.add(root.val); } if (root==null) { return l; } if (root.right==null) { l.add(root.right.val); } dfsRightSideView(root.right); return l; } public void dfsSumNumber(TreeNode root ,int sum , int l ) { l=l*10 +root.val; if (root.left!=null) { dfsSumNumber(root.left,sum , l); } if (root.right!=null) { dfsSumNumber(root.right , sum, l); } if (root.left==null && root.right==null) { sum+=l; } // r=l*10+root.val; l-=root.val; l/=10; } //BFS SOLN public int[][] updateMatrix(int[][] mat) { int m =mat.length; int n = mat[0].length; Queue<int[]> q = new LinkedList<>(); for (int i = 0; i < mat.length; i++) { for (int j = 0; j < mat[0].length; j++) { if (mat[i][j]==0) { q.offer(new int[] { i , j}); } else { mat[i][j] = Integer.MAX_VALUE; } } } int dir[][] = {{1 , 0} , {-1 , 0} , {0 , 1} , { 0 , -1}}; while (!q.isEmpty()) { int zeroPos[] = q.poll(); for (int[] d : dir) { int r = zeroPos[0]+d[0]; int c = zeroPos[1]+d[1]; if (r<0||r>=mat.length || c<0||c>=mat[0].length||mat[r][c]<=mat[zeroPos[0]][zeroPos[1]]+1) { continue; } q.add(new int[]{r,c}); mat[r][c] = mat[zeroPos[0]][zeroPos[1]]+1; } } return mat; } // DFS SOLN // public int[][] updateMatrix(int[][] mat) { // int res [][] = new int[mat.length][mat[0].length]; // for (int i = 0; i < mat.length; i++) { // for (int j = 0; j < mat.length; j++) { // if (mat[i][j]==0) { // Dis0(i, j, mat , res, 0); // } // } // } // return res; // } // public void Dis0(int i , int j , int [][]mat, int res[][] , int dist) { // if (i<0||i>=mat.length||j>=mat[0].length||j<0) { // return ; // } // if (dist==0 ||mat[i][j]==1&&(res[i][j]==0||res[i][j]>dist)) { // res[i][j]= dist; // Dis0(i+1, j, mat, res, dist+1); // Dis0(i-1, j, mat, res, dist+1); // Dis0(i, j+1, mat, res, dist+1); // Dis0(i, j-1, mat, res, dist+1); // } // // return dist; // } public int maxDepth(TreeNode root) { if (root==null) { return 0; } return maxD(root , 0); } public int maxD(TreeNode root , int d ) { if (root==null) { return d; } return Math.max(maxD(root.left, d+1), maxD(root.right, d+1)); } public int reverse(int x) { int sign=x>0?1:-1; //x=Math.abs(x); long s= 0; int r= 0; int n=x; while (n!=0) { r=n%10; s=s*10+r; n/=10; if (s>Integer.MAX_VALUE||s<Integer.MIN_VALUE) { return 0; } } return (int)s*sign; } public boolean checkInclusion(String s1, String s2) { boolean f = false ; if (s1.length()>s2.length()) { return false; } for (int i = 0; i < s2.length(); i++) { HashMap<Character ,Integer> c1 = new HashMap<>(); HashMap<Character ,Integer> c2 = new HashMap<>(); for (int j = 0; j < s1.length(); j++) { char ch2 = s2.charAt(i+j); char ch1 = s1.charAt(j); // if (c1.get(key)) { // } } } return f; } public class ListNode { int val; ListNode next; ListNode() {} ListNode(int val) { this.val = val; } ListNode(int val, ListNode next) { this.val = val; this.next = next; } } public ListNode middleNode(ListNode head) { ListNode mid = head; ListNode last = head; int k =0; while (last.next!=null&&last.next.next!=null) { k++; mid= mid.next; last = last.next.next; } if (getLen(head)%2==0) { return mid.next; } return mid; } public int getLen(ListNode mid) { int l = 0; ListNode p = mid; while (p!=null) { l++; p=p.next; } return l; } public class TreeNode { int val; TreeNode left; TreeNode right; TreeNode() {} TreeNode(int val) { this.val = val; } TreeNode(int val, TreeNode left, TreeNode right) { this.val = val; this.left = left; this.right = right; } } public List<List<Integer>> verticalTraversal(TreeNode root) { TreeMap<Integer, TreeMap<Integer, PriorityQueue<Integer>>> map = new TreeMap<>(); dfs(root, 0, 0, map); List<List<Integer>> list = new ArrayList<>(); for (TreeMap<Integer, PriorityQueue<Integer>> ys : map.values()) { list.add(new ArrayList<>()); for (PriorityQueue<Integer> nodes : ys.values()) { while (!nodes.isEmpty()) { // list.get(list.size() - 1).add(nodes.poll()); } } } return list; } private void dfs(TreeNode root, int x, int y, TreeMap<Integer, TreeMap<Integer, PriorityQueue<Integer>>> map) { if (root == null) { return; } if (!map.containsKey(x)) { map.put(x, new TreeMap<>()); } if (!map.get(x).containsKey(y)) { map.get(x).put(y, new PriorityQueue<>()); } map.get(x).get(y).offer(root.val); dfs(root.left, x - 1, y + 1, map); dfs(root.right, x + 1, y + 1, map); } public long pow (int x ,int n ) { long y = 1; if (n==0) { return y; } while (n>0) { if (n%2!=0) { y=y*x; } x*=x; n/=2; } return y; } public long powrec (int x ,int n ) { long y = 1; if (n==0) { return y; } y = powrec(x, n/2); if (n%2==0) { return y*y; } return y*y*x; } public int fib(int n) { if (n==0||n==11) { return n; } return fib(n-1)+fib(n-2); } public long gcd(long a , long b) { if (b%a==0) { return a; } return gcd(b%a,a); } public int maximumElement(int a[]) { int x = Integer.MIN_VALUE; for (int i = 0; i < a.length; i++) { if (a[i]>x) { x=a[i]; } } return x; } public int minimumElement(int a[]) { int x = Integer.MAX_VALUE; for (int i = 0; i < a.length; i++) { if (a[i]<x) { x=a[i]; } } return x; } public 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]) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } return prime; } // GFG arraylist function for referral public ArrayList create2DArrayList(int n ,int k) { // Creating a 2D ArrayList of Integer type ArrayList<ArrayList<Integer> > x = new ArrayList<ArrayList<Integer> >(); // One space allocated for R0 // Adding 3 to R0 created above x(R0, C0) //x.get(0).add(0, 3); int xr = 0; for (int i = 1; i <= n; i+=2) { if ((i+k)*(i+1)%4==0) { x.add(new ArrayList<Integer>()); x.get(xr).addAll(Arrays.asList(i , i+1)); } else { x.add(new ArrayList<Integer>()); x.get(xr).addAll(Arrays.asList(i+1 , i)); } xr++; } // Creating R1 and adding values // Note: Another way for adding values in 2D // collections // x.add( // new ArrayList<Integer>(Arrays.asList(3, 4, 6))); // // Adding 366 to x(R1, C0) // x.get(1).add(0, 366); // // Adding 576 to x(R1, C4) // x.get(1).add(4, 576); // // Now, adding values to R2 // x.add(2, new ArrayList<>(Arrays.asList(3, 84))); // // Adding values to R3 // x.add(new ArrayList<Integer>( // Arrays.asList(83, 6684, 776))); // // Adding values to R4 // x.add(new ArrayList<>(Arrays.asList(8))); // // Appending values to R4 // x.get(4).addAll(Arrays.asList(9, 10, 11)); // // Appending values to R1, but start appending from // // C3 // x.get(1).addAll(3, Arrays.asList(22, 1000)); // This method will return 2D array return x; } } class FlashFastReader { BufferedReader in; StringTokenizer token; public FlashFastReader(InputStream ins) { in=new BufferedReader(new InputStreamReader(ins)); token=new StringTokenizer(""); } public boolean hasNext() { while (!token.hasMoreTokens()) { try { String s = in.readLine(); if (s == null) return false; token = new StringTokenizer(s); } catch (IOException e) { throw new InputMismatchException(); } } return true; } public String next() { hasNext(); return token.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public int[] nextIntsInputAsArray(int n) { int[] res = new int[n]; for (int i = 0; i < n; i++) res[i] = nextInt(); return res; } public long nextLong() { return Long.parseLong(next()); } public long[] nextLongsInputAsArray(int n) { long [] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public String nextString() { return String.valueOf(next()); } public String[] nextStringsInputAsArray(int n) { String [] a = new String[n]; for (int i = 0; i < n; i++) a[i] = nextString(); return a; } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 11
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
b94b339e3d3deee0daf9fb72316579b7
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int casos = scan.nextInt(); while (casos > 0 && casos <= 100){ String pal; int numeropalabras = scan.nextInt(); Map<String,Integer> valores = new HashMap<>(); String [] num = new String[numeropalabras * 3]; int [] pntos = new int[3]; for (int i = 0; i < numeropalabras*3; i++){ pal = scan.next(); //cargar valores if (valores.containsKey(pal)) { if (valores.get(pal).equals(3)){ valores.put(pal,1); }else valores.put(pal,0); }else { valores.put(pal,3); } //cargar array num [i] = pal; } for (int numeroA = 0; numeroA < numeropalabras;numeroA++){ if (valores.containsKey(num[numeroA])){ pntos[0] = pntos[0] + valores.get(num[numeroA]); if (valores.containsKey(num[numeroA+numeropalabras])){ pntos[1] = pntos[1] + valores.get(num[numeroA+numeropalabras]); } if (valores.containsKey(num[numeroA+numeropalabras*2])){ pntos[2] = pntos[2] + valores.get(num[numeroA+numeropalabras*2]); } } } System.out.println(pntos[0] + " " + pntos[1] + " " + pntos[2]); casos--; } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 8
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
23790280235ac814e23378eea78441f3
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.io.*; import java.util.*; public class wordGame { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); int testNumber = sc.nextInt(); while(testNumber>0){ int wordNumber = sc.nextInt(); int[] answer = new int[3]; Map<String, List<Integer>> map = new HashMap<>(); for(int i = 0; i < 3; i++){ List<String> list = new ArrayList<>(); for(int j = 0; j < wordNumber; j++) list.add(sc.next()); for(int j = 0; j < wordNumber; j++){ if(!map.containsKey(list.get(j))){ map.put(list.get(j), new ArrayList<>()); map.get(list.get(j)).add(i); } else map.get(list.get(j)).add(i); } } for(Map.Entry<String, List<Integer>> entry : map.entrySet()) { List<Integer> index = entry.getValue(); int length = index.size(); if(length <3){ if(length == 2){ for(int i : index) answer[i]++; } else { for(int i : index) answer[i]+=3; } } } for(int i : answer){ System.out.print(i + " "); } System.out.println(); testNumber--; } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 8
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
933b0674760cf4c6c1d3dcf891a428da
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.HashMap; import java.util.Scanner; public class C1722_WordGame { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); byte t = scanner.nextByte(); while (t-- > 0) { short n = scanner.nextShort(), p1Score = (short) (3*n), p2Score = (short) (3*n), p3Score = (short) (3*n); HashMap<String, Integer> map = new HashMap<String, Integer>(); // null = not used / 1 = used by one / 2 = used by 2 / 3 = used by 1 &nd 2 for (int i = 0; i < 3 * n; i++) { if(i < n) map.put(scanner.next(), 1); else if(i < 2 * n) { String s = scanner.next(); if (map.get(s) == null) map.put(s, 2); else { map.put(s, 3); p1Score -= 2; p2Score -= 2; } } else { String s = scanner.next(); int mapS = map.get(s) == null ? -1 : map.get(s); if(mapS == -1) continue; switch (mapS) { case 1 : p1Score -= 2; p3Score -= 2; break; case 2 : p2Score -= 2; p3Score -= 2; break; case 3 : p1Score -= 1; p2Score -= 1; p3Score -= 3; } }; } System.out.println(p1Score + " "+ p2Score + " " + p3Score); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 8
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
de98cc00429464b05941108bae70a4c6
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.*; public class Main { private static Map<String,Integer> different; public static void main(String[] args) { Scanner cin = new Scanner(System.in); int test = cin.nextInt(); while (test -- > 0){ solve(cin); } } private static void solve(Scanner cin) { int n = cin.nextInt(); List<List<String>> str = new ArrayList<List<String>>(); List<Map<String,Integer>> map = new ArrayList<>(); for(int i = 0 ; i < 3 ;i ++) { String s; str.add(new ArrayList<>()); List<String> temp = str.get(i); map.add(new HashMap<>()); for(int j = 0 ; j < n ;j ++){ s = cin.next(); temp.add(s); map.get(i).put(s,i); } } calculate(str.get(0),map.get(1),map.get(2)); calculate(str.get(1),map.get(0),map.get(2)); calculate(str.get(2),map.get(0),map.get(1)); System.out.println(); } private static void calculate(List<String> first, Map<String,Integer> secondmap, Map<String,Integer> thirdmap) { int answer = 0; for(int i = 0; i < first.size() ;i ++){ if(secondmap.get(first.get(i)) == null && thirdmap.get(first.get(i)) == null){ answer += 3; } else if(secondmap.get(first.get(i)) != null && thirdmap.get(first.get(i)) != null){ continue; }else{ answer += 1; } } System.out.print(answer + " "); } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 8
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
69e8dc608193ffe990aea99ca8509863
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.*; public class Main { private static Map<String,Integer> different; public static void main(String[] args) { Scanner cin = new Scanner(System.in); int test = cin.nextInt(); while (test -- > 0){ solve(cin); } } private static void solve(Scanner cin) { int n = cin.nextInt(); different = new HashMap<>(); List<String> first = new ArrayList<String>(); List<String> second = new ArrayList<String>(); List<String> third = new ArrayList<String>(); List<Integer> answer = new ArrayList<>(); for(int i = 1 ; i <= 3 ;i ++) { String s; for(int j = 0 ; j < n ;j ++){ s = cin.next(); if(Objects.nonNull(different.get(s))){ different.put(s,different.get(s) + i); }else different.putIfAbsent(s,i); if(i == 1) first.add(s); if(i == 2) second.add(s); if(i == 3) third.add(s); } } int summa = 0; for(String i : first){ summa += different.get(i) == 1 ? 3 : (different.get(i) == 3 || different.get(i) == 4) ? 1 : 0; } answer.add(summa); summa = 0; for(String i : second){ summa += different.get(i) == 2 ? 3 : (different.get(i) == 3 || different.get(i) == 5) ? 1 : 0; } answer.add(summa); summa = 0; for(String i : third){ summa += different.get(i) == 3 ? 3 : (different.get(i) == 4 || different.get(i) == 5) ? 1 : 0; } answer.add(summa); for (Integer integer : answer) { System.out.print(integer + " "); } System.out.println(); } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 8
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
81a695ead715f05ad5f6f4bc3439286f
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.*; public class Solution{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int i=0;i<t;i++){ sc.nextLine(); int n=sc.nextInt(); List<String> lst=new ArrayList<>(); HashMap<String,Integer> map=new HashMap<>(); for(int j=0;j<3;j++){ for(int k=0;k<n;k++){ String temp=sc.next(); map.put(temp,map.getOrDefault(temp,0)+1); lst.add(temp); } } for(int j=0;j<lst.size();j+=n){ int sum=0; for(int k=j;k<j+n;k++){ int count=map.get(lst.get(k)); if(count==1) sum+=3; else if(count==2) sum+=1; else if(count==3) sum+=0; } System.out.print(sum+" "); } System.out.println(); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 8
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
b1437afb1bc7e9249a254f2d7d3c5552
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.*; public class Main{ public static void main(String[] args){ Scanner in = new Scanner(System.in); int cont = in.nextInt(); in.nextLine(); for(int k=0; k<cont; k++){ int words = in.nextInt(); in.nextLine(); Set<String> set_1 = new HashSet<>(); Set<String> set_2 = new HashSet<>(); Set<String> set_3 = new HashSet<>(); Set<String> setPalabras = new HashSet<>(); String[] line_1 = in.nextLine().split(" "); String[] line_2 = in.nextLine().split(" "); String[] line_3 = in.nextLine().split(" "); int cont_1 = 0; int cont_2 = 0; int cont_3 = 0; boolean a = false; boolean b = false; boolean c = false; for(int i=0; i<words; i++){ set_1.add(line_1[i]); set_2.add(line_2[i]); set_3.add(line_3[i]); setPalabras.add(line_1[i]); setPalabras.add(line_2[i]); setPalabras.add(line_3[i]); } for(String word: setPalabras){ a = !set_1.add(word); b = !set_2.add(word); c = !set_3.add(word); if( a && b && !c){ cont_1++; cont_2++; } if( a && !b && c){ cont_1++; cont_3++; } if( !a && b && c){ cont_3++; cont_2++; } if( a && !b && !c){ cont_1 += 3; } if( !a && b && !c){ cont_2 += 3; } if( !a && !b && c){ cont_3 += 3; } } System.out.println(cont_1 + " " + cont_2 + " " + cont_3); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 8
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
d58d2093de2816398eff751b9d9561e5
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.ArrayList; import java.util.Scanner; import java.util.Map; import java.util.HashMap; public class Main { public static void main(String []args){ Scanner sc = new Scanner(System.in); int c = sc.nextInt(); for(int i = 0; i < c; i++){ Map<String, ArrayList<Integer>> grafo = new HashMap<String, ArrayList<Integer>>(); int[]jugadores = new int[3]; int nNode = sc.nextInt(); for(int k = 0; k < 3; k++){ for(int j = 0; j < nNode; j++){ String newWord = sc.next(); if(grafo.containsKey(newWord)){ grafo.get(newWord).add(k); } else { ArrayList <Integer> auxEdge = new ArrayList<Integer>(); auxEdge.add(k); grafo.put(newWord, auxEdge); } } } print(grafo, jugadores); } } private static void print(Map<String, ArrayList<Integer>> g, int[]j){ for (Map.Entry<String, ArrayList<Integer>> entry : g.entrySet()) { if(entry.getValue().size() == 1){ j[entry.getValue().get(0)] += 3; } if(entry.getValue().size() == 2){ j[entry.getValue().get(0)] += 1; j[entry.getValue().get(1)] += 1; } } System.out.println(j[0]+" "+j[1]+" "+j[2]); } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 8
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
18ce149d0b8a20688a012fb92ad07f9a
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class Codeforces { public static void main (String[] args) throws IOException { PrintWriter pt=new PrintWriter(System.out); Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int xyz=0; xyz<t; xyz++) { int n=sc.nextInt(); String [][] ss = new String[3][n]; HashMap<String, Integer> hm = new HashMap<>(); for(int i = 0 ; i < 3 ; i ++){ for(int j = 0; j < n; j++){ String s = ss[i][j] = sc.next(); hm.put(s, hm.getOrDefault(s, 0) + 1); } } for(int i = 0; i < 3; i++){ int ans = 0; for(int j = 0; j < n; j++){ int k = hm.get(ss[i][j]); ans += k == 1? 3 : k == 2? 1: 0; } System.out.print(ans + " "); } System.out.println(); } pt.close(); } public static void recurPermut(String S, List<String> ls, int index) { if(index == S.length()) { String s = ""; for(int i = 0; i < S.length(); ++i) { s = s + S.charAt(i); } ls.add(s.trim()); } if(index < S.length()) { for(int i = 0; i < S.length(); ++i) { S = swap(i, index, S); recurPermut(S, ls, index + 1); S = swap(i, index, S); } } } public static String swap(int i, int j, String a) { char temp; char[] charArray = a.toCharArray(); temp = charArray[i] ; charArray[i] = charArray[j]; charArray[j] = temp; return String.valueOf(charArray); } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 8
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
237834dd2bc5f826b61659f796c0b8fc
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.*; public class Solution { public static void wordGame(String [][]a,int n) { Map<String,Integer> map=new HashMap<>(); for(int i=0;i<3;i++) { for(int j=0;j<n;j++) { map.put(a[i][j],map.getOrDefault(a[i][j], 0)+1); } } for(int i=0;i<3;i++) { int tot=0; for(int j=0;j<n;j++) { if(map.get(a[i][j])==1) tot+=3; else if(map.get(a[i][j])==2) tot+=1; else tot+=0; } System.out.print(tot+ " "); } System.out.println(); } public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); String [][]a=new String[3][n]; for(int i=0;i<3;i++) { for(int j=0;j<n;j++) { a[i][j]=sc.next(); } } wordGame(a,n); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 8
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
713b7fde9348da6008432a332e6d6451
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.*; public class Solution { public static void wordGame(String [][]a,int n) { Map<String,Integer> map=new HashMap<>(); for(int i=0;i<3;i++) { for(int j=0;j<n;j++) { map.put(a[i][j],map.getOrDefault(a[i][j], 0)+1); } } for(int i=0;i<3;i++) { int tot=0; for(int j=0;j<n;j++) { if(map.get(a[i][j])==1) tot+=3; else if(map.get(a[i][j])==2) tot+=1; else tot+=0; } System.out.print(tot+ " "); } System.out.println(); } public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); String [][]a=new String[3][n]; for(int i=0;i<3;i++) { for(int j=0;j<n;j++) { a[i][j]=sc.next(); } } wordGame(a,n); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 8
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
c18f126fa65943880016fd483e92ea9b
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.*; import java.lang.*; public class tes { public static void main (String[] args)throws java.lang.Exception { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(),i,x=0,y=0,z=0; HashMap <String,Integer> m=new HashMap<>(); String a[]=new String[n]; String b[]=new String[n]; String c[]=new String[n]; for(i=0;i<n;i++) { a[i]=sc.next(); m.put(a[i],1); } for(i=0;i<n;i++) { b[i]=sc.next(); if(m.containsKey(b[i])) m.replace(b[i],m.get(b[i])+1); else m.put(b[i],1); } for(i=0;i<n;i++) { c[i]=sc.next(); if(m.containsKey(c[i])) m.replace(c[i],m.get(c[i])+1); else m.put(c[i],1); } for(i=0;i<n;i++) { if(m.get(a[i])==2)x++; else if(m.get(a[i])==1)x=x+3; if(m.get(b[i])==2)y++; else if(m.get(b[i])==1)y=y+3; if(m.get(c[i])==2)z++; else if(m.get(c[i])==1)z=z+3; } System.out.println(x+" "+y+" "+z); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 8
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
cf4f53c81ab053d75f89338671f7cd09
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.*; public class Word_Game { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-- > 0) { int n=sc.nextInt(); int person=3; HashMap<String,Integer> map=new HashMap<>(); String [][] word=new String[person][n]; int []p=new int[person]; for(int i=0;i<person;i++) { p[i]=0; for(int j=0;j<n;j++) { word[i][j]=sc.next(); if(!map.containsKey(word[i][j])) { map.put(word[i][j],1); } else { map.put(word[i][j],map.get(word[i][j])+1); } } } for(int i=0;i<person;i++) { for(int j=0;j<n;j++) { if(map.get(word[i][j])==2) { p[i]+=1; } else if(map.get(word[i][j])==1) { p[i]+=3; } } } //printing for(int i=0;i<person;i++) { System.out.print(p[i] + " "); } System.out.println(); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 8
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
e658ed40ea4abc45b346e8693525fcc0
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.io.*; import java.math.*; import java.util.*; public class Main{ static final int INF = 0x3f3f3f3f; static final long LNF = 0x3f3f3f3f3f3f3f3fL; public static void main(String[] args) throws IOException { initReader(); int t=nextInt(); while (t--!=0){ int n=nextInt(); Map<String,Boolean>ma1=new HashMap<String, Boolean>(); Map<String,Boolean>ma2=new HashMap<String, Boolean>(); Map<String,Boolean>ma3=new HashMap<String, Boolean>(); int cnt1=0,cnt2=0,cnt3=0; Set<String>set=new HashSet<String>(); for(int i=1;i<=n;i++){ String s=next(); ma1.put(s,true); set.add(s); } for(int i=1;i<=n;i++){ String s=next(); ma2.put(s,true); set.add(s); } for(int i=1;i<=n;i++){ String s=next(); ma3.put(s,true); set.add(s); } for(String a:set){ if(ma1.get(a)!=null&&ma2.get(a)!=null&&ma3.get(a)!=null){ continue; } else if(ma1.get(a)==null&&ma2.get(a)!=null&&ma3.get(a)!=null){ cnt2++; cnt3++; } else if(ma1.get(a)!=null&&ma2.get(a)==null&&ma3.get(a)!=null){ cnt1++; cnt3++; } else if(ma1.get(a)!=null&&ma2.get(a)!=null&&ma3.get(a)==null){ cnt1++; cnt2++; } else if(ma1.get(a)!=null){ cnt1+=3; } else if(ma2.get(a)!=null){ cnt2+=3; } else if(ma3.get(a)!=null){ cnt3+=3; } } pw.println(cnt1+" "+cnt2+" "+cnt3); } pw.close(); } /***************************************************************************************/ static BufferedReader reader; static StringTokenizer tokenizer; static PrintWriter pw; public static void initReader() throws IOException { reader = new BufferedReader(new InputStreamReader(System.in)); tokenizer = new StringTokenizer(""); pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); // 从文件读写 // reader = new BufferedReader(new FileReader("test.in")); // tokenizer = new StringTokenizer(""); // pw = new PrintWriter(new BufferedWriter(new FileWriter("test1.out"))); } public static boolean hasNext() { try { while (!tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } } catch (Exception e) { return false; } return true; } public static String next() throws IOException { while (!tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } return tokenizer.nextToken(); } public static String nextLine() { try { return reader.readLine(); } catch (Exception e) { return null; } } public static int nextInt() throws IOException { return Integer.parseInt(next()); } public static long nextLong() throws IOException { return Long.parseLong(next()); } public static double nextDouble() throws IOException { return Double.parseDouble(next()); } public static char nextChar() throws IOException { return next().charAt(0); } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 8
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
c94464220ac76f374f83ab95b3cd8333
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
/****************************************************************************** Practice,Practice and Practice....!! *******************************************************************************/ 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.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(); HashMap<String,Integer> hm=new HashMap<>(); HashSet<String> one=new HashSet<>(); HashSet<String> two=new HashSet<>(); HashSet<String> three=new HashSet<>(); int pt1=0,pt2=0,pt3=0; for(int i=0;i<3;i++){ for(int j=0;j<n;j++){ String str=in.next(); if(i==0) one.add(str); if(i==1) two.add(str); else three.add(str); hm.put(str,hm.getOrDefault(str,0)+1); } } for(Map.Entry<String,Integer> e:hm.entrySet()){ if(e.getValue()==1){ if(one.contains(e.getKey())) pt1+=3; else if(two.contains(e.getKey())) pt2+=3; else pt3+=3; } else if(e.getValue()==2){ if(one.contains(e.getKey()) && two.contains(e.getKey())){ pt1=pt1+1; pt2+=1; } else if(two.contains(e.getKey()) && three.contains(e.getKey())){ pt2=pt2+1; pt3=pt3+1; } else{ pt1+=1; pt3+=1; } } } System.out.println(pt1+" "+pt2+" "+pt3); } out.close(); } catch (Exception e) { return; } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 8
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
a2aa826681074960ebdc45cdc13948a2
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.*; public class Codeforces { public static void main(String[] args) { Scanner kali = new Scanner(System.in); int dannyi = kali.nextInt(); for(int i = 0; i < dannyi; i++){ int num = kali.nextInt(); String[] arr1 = new String[num]; String[] arr2 = new String[num]; String[] arr3 = new String[num]; Set<String> set1 = new HashSet<>(); Set<String> set2 = new HashSet<>(); Set<String> set3 = new HashSet<>(); for(int j = 0; j < num; j++){ arr1[j] = kali.next(); set1.add(arr1[j]); } for(int j = 0; j < num; j++){ arr2[j] = kali.next(); set2.add(arr2[j]); } for(int j = 0; j < num; j++){ arr3[j] = kali.next(); set3.add(arr3[j]); } int count1 = 0; int count2 = 0; int count3 = 0; for(int j = 0; j < num; j++){ if(set2.contains(arr1[j]) && !set3.contains(arr1[j])){ count1++; count2++; } else if(!set2.contains(arr1[j]) && set3.contains(arr1[j])){ count1++; count3++; } else if(!set2.contains(arr1[j]) && !set3.contains(arr1[j])){ count1 += 3; } } for(int j = 0; j < num; j++){ if(!set1.contains(arr2[j]) && set3.contains(arr2[j])){ count2++; count3++; } else if(!set1.contains(arr2[j]) && !set3.contains(arr2[j])){ count2 += 3; } } for(int j = 0; j < num; j++){ if(!set2.contains(arr3[j]) && !set1.contains(arr3[j])){ count3 += 3; } } System.out.println(count1 + " " + count2 + " " + count3); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 8
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
416ab0993b8a95ef0c85b4115d17c773
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.*; public class Rough { public static void main(String[] args) { HashMap<String,Long> map = new HashMap<>(); Scanner sc = new Scanner(System.in); long t = sc.nextLong(); while(t-->0) { long n = sc.nextLong(); String arr[][] = new String[3][(int) n]; for(int i=0; i<3; i++) { for(int j=0; j<n; j++) { arr[i][j] = sc.next(); if(map.containsKey(arr[i][j])) { map.put(arr[i][j], map.get(arr[i][j])+1); }else { map.put(arr[i][j], (long) 1); } } } // for(Map.Entry<String,Integer> e : map.entrySet()) { // System.out.println(e.getKey()+" "+e.getValue()); //// System.out.println(e.getValue()); // } long vk[] = new long[3]; long sum = 0; for(int i=0; i<3; i++) { for(int j=0; j<n; j++) { if(map.get(arr[i][j])==1) { sum = sum+3; } if(map.get(arr[i][j])==2) { sum = sum+1; } } vk[i] = sum; sum = 0; } for(int i=0; i<3; i++) { System.out.print(vk[i]+" "); } System.out.println(); map.clear(); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 8
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
54ac6b0277fa3f5a26a43f3be26b2dad
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.*; import java.io.*; public class WordGame { public static void main(String[] args)throws Exception{ FastReader f=new FastReader(System.in); int t=f.nextInt(); while (t-->0){ int n=f.nextInt(); HashMap<String, List<Integer>> wordMap=new HashMap<String, List<Integer>>(); for (int i=0;i<n*3;i++){ String s=f.nextString(); if (wordMap.containsKey(s)) wordMap.get(s).add(i/n); else wordMap.put(s, new ArrayList<Integer>(Arrays.asList(i/n))); } //System.out.println(wordMap); int[] points=new int[3]; for (String s:wordMap.keySet()){ List<Integer> l=wordMap.get(s); if (l.size()==1) points[l.get(0)]+=3; if (l.size()==2){ points[l.get(0)]+=1; points[l.get(1)]+=1; } } System.out.println(points[0]+" "+points[1]+" "+points[2]); } } } class FastReader { private InputStream stream; private byte[] buf = new byte[8192]; private int curChar; private int pnumChars; private FastReader.SpaceCharFilter filter; public FastReader(InputStream stream) { this.stream = stream; } public int read() { if (pnumChars == -1) { throw new InputMismatchException(); } if (curChar >= pnumChars) { curChar = 0; try { pnumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (pnumChars <= 0) { return -1; } } return buf[curChar++]; } public String next() { return nextString(); } 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 == ',') { c = read(); } 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; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String nextString() { 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 String nextLine() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); } public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } 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\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 8
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
bd9b5145188d3a0ea6bb005016b59181
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws IOException { Fast f = new Fast(System.in); int t = f.nextInt(); while (t--!=0) { int n = f.nextInt(); int [] ans = new int[3]; HashSet<String> s1 = new HashSet<>(); HashSet<String> s2 = new HashSet<>(); HashSet<String> s3 = new HashSet<>(); for (int i = 0 ; i < n ; i++) s1.add(f.next()); for (int i = 0 ; i < n ; i++) s2.add(f.next()); for (int i = 0 ; i < n ; i++) s3.add(f.next()); for (String s : s1) { if(s2.contains(s) && s3.contains(s)) { s3.remove(s); s2.remove(s); continue; } if(!s2.contains(s) && !s3.contains(s)) ans[0]+=3; else if (s2.contains(s) && !s3.contains(s)) { ans[0]++; ans[1]++; s2.remove(s); } else if (!s2.contains(s) && s3.contains(s)) { ans[0]++; ans[2]++; s3.remove(s); } } for (String s : s2) { if(s1.contains(s) && s3.contains(s)) { s3.remove(s); continue; } if(!s1.contains(s) && !s3.contains(s)) ans[1]+=3; else if (!s1.contains(s) && s3.contains(s)) { ans[1]++; ans[2]++; s3.remove(s); } else if (s1.contains(s) && !s3.contains(s)) { ans[0]++; ans[1]++; } } System.out.println(ans[0] + " " + ans[1] + " "+(ans[2]+(s3.size()*3))); } System.out.flush(); System.out.close(); } } class Fast { StringTokenizer st; BufferedReader br; public Fast(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Fast(String file) throws IOException { br = new BufferedReader(new FileReader(file)); } public Fast(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 String readAllLines(BufferedReader reader) throws IOException { StringBuilder content = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { content.append(line); content.append(System.lineSeparator()); } return content.toString(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } 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 boolean ready() throws IOException { return br.ready(); } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 8
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
9e838e9d9e2f3ca52636b5bbcf6647d8
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws IOException { Fast f = new Fast(System.in); int t = f.nextInt(); while (t--!=0) { int n = f.nextInt(); int [] ans = new int[3]; Arrays.fill(ans,0); HashSet<String> s1 = new HashSet<>(); HashSet<String> s2 = new HashSet<>(); HashSet<String> s3 = new HashSet<>(); for (int i = 0 ; i < n ; i++) s1.add(f.next()); for (int i = 0 ; i < n ; i++) s2.add(f.next()); for (int i = 0 ; i < n ; i++) s3.add(f.next()); for (String s : s1) { if(s2.contains(s) && s3.contains(s)) { s3.remove(s); s2.remove(s); continue; } if(!s2.contains(s) && !s3.contains(s)) ans[0]+=3; else if (s2.contains(s) && !s3.contains(s)) { ans[0]++; ans[1]++; s2.remove(s); } else if (!s2.contains(s) && s3.contains(s)) { ans[0]++; ans[2]++; s3.remove(s); } } for (String s : s2) { if(s1.contains(s) && s3.contains(s)) { s3.remove(s); continue; } if(!s1.contains(s) && !s3.contains(s)) ans[1]+=3; else if (!s1.contains(s) && s3.contains(s)) { ans[1]++; ans[2]++; s3.remove(s); } else if (s1.contains(s) && !s3.contains(s)) { ans[0]++; ans[1]++; } } System.out.println(ans[0] + " " + ans[1] + " "+(ans[2]+(s3.size()*3))); } System.out.flush(); System.out.close(); } } class Fast { StringTokenizer st; BufferedReader br; public Fast(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Fast(String file) throws IOException { br = new BufferedReader(new FileReader(file)); } public Fast(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 String readAllLines(BufferedReader reader) throws IOException { StringBuilder content = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { content.append(line); content.append(System.lineSeparator()); } return content.toString(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } 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 boolean ready() throws IOException { return br.ready(); } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 8
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
70b3f18df71694e92b7682cabf8b2e4a
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
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) throws NumberFormatException, 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()); int[] scores=new int[3]; Map<String,Integer> map=new HashMap<>(); String[][] str=new String[3][N]; for(int i=0;i<3;i++) { StringTokenizer token=new StringTokenizer(br.readLine()); for(int j=0;j<N;j++) { str[i][j]=token.nextToken(); map.put(str[i][j], map.getOrDefault(str[i][j], 0)+1); } } for(int i=0;i<3;i++) { for(int j=0;j<N;j++) { switch(map.get(str[i][j])) { case 1: scores[i]+=2; case 2: scores[i]+=1; } } } sb.append(scores[0]).append(" ").append(scores[1]).append(" ").append(scores[2]).append("\n"); t--; } System.out.print(sb.toString()); } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 8
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
211f0eed676ca8f3b71147b614107dcb
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.HashMap; import java.util.Scanner; public class Practice { 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(); String arr[][]=new String[3][n]; HashMap<String,Integer>mp=new HashMap<>(); for(int i=0;i<3;i++) { for(int j=0;j<n;j++){ arr[i][j]=sc.next(); String res=arr[i][j]; mp.put(res,mp.getOrDefault(res,0)+1); } } for(int i=0;i<3;i++) { int ans=0; for(int j=0;j<n;j++) { String res=arr[i][j]; int fre=mp.get(res); if(fre==1) ans+=3; else if(fre==2) ans+=1; } System.out.print(ans+" "); } System.out.println(); --t; } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 8
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
1061ab0802e7e1c37fa567e5e33a29f7
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.HashMap; import java.util.Scanner; public class Practice { 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(); String arr[][]=new String[3][n]; HashMap<String,Integer>mp=new HashMap<>(); for(int i=0;i<3;i++) { for(int j=0;j<n;j++){ arr[i][j]=sc.next(); String res=arr[i][j]; mp.put(res,mp.getOrDefault(res,0)+1); } } for(int i=0;i<3;i++) { int ans=0; for(int j=0;j<n;j++) { String res=arr[i][j]; int fre=mp.get(res); if(fre==1) ans+=3; else if(fre==2) ans+=1; } System.out.print(ans+" "); } System.out.println(); --t; } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 8
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
2c74cc4e6eaab6b53f446dbbca0dae93
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.HashSet; import java.util.Scanner; public class C { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int num = scan.nextInt(); for(int i=0;i<num;i++){ int size=scan.nextInt(); int[] ans = new int[3]; HashSet<String> arr1 = new HashSet<>(); HashSet<String> arr2 = new HashSet<>(); HashSet<String> arr3 = new HashSet<>(); for(int j=0;j<size;j++){ arr1.add(scan.next()); } for(int j=0;j<size;j++){ arr2.add(scan.next()); } for(int j=0;j<size;j++){ arr3.add(scan.next()); } int j=0; for(String s:arr1){ if(!arr2.contains(s)&&!arr3.contains(s)){ ans[j]+=3; } else if(arr2.contains(s)&&arr3.contains(s)){ ans[j]+=0; } else{ ans[j]+=1; } } j++; for(String s:arr2){ if(!arr1.contains(s)&&!arr3.contains(s)){ ans[j]+=3; } else if(arr1.contains(s)&&arr3.contains(s)){ ans[j]+=0; } else{ ans[j]+=1; } } j++; for(String s:arr3){ if(!arr1.contains(s)&&!arr2.contains(s)){ ans[j]+=3; } else if(arr1.contains(s)&&arr2.contains(s)){ ans[j]+=0; } else{ ans[j]+=1; } } for(int k=0;k<3;k++){ System.out.println(ans[k]); } } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 8
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
228ab65adc3ee688ed938c7458a73962
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.*; public class acmp { public static void main(String[] args) { Scanner css = new Scanner(System.in); int t = css.nextInt(); for (int i = 0; i < t; i++) { Map<String, Integer> map = new HashMap<>(); int n = css.nextInt(); String[] s1 = new String[n]; String[] s2 = new String[n]; String[] s3 = new String[n]; for (int j = 0; j < n; j++) { s1[j] = css.next(); if(!(map.containsKey(s1[j]))){ map.put(s1[j], 3); }else if(map.get(s1[j]) == 3){ map.put(s1[j], 1); }else if(map.get(s1[j]) == 1) { map.put(s1[j], 0); } }for (int j = 0; j < n; j++) { s2[j] = css.next(); if(!(map.containsKey(s2[j]))){ map.put(s2[j], 3); }else if(map.get(s2[j]) == 3){ map.put(s2[j], 1); }else if(map.get(s2[j]) == 1) { map.put(s2[j], 0); } }for (int j = 0; j < n; j++) { s3[j] = css.next(); if(!(map.containsKey(s3[j]))){ map.put(s3[j], 3); }else if(map.get(s3[j]) == 3){ map.put(s3[j], 1); }else if(map.get(s3[j]) == 1) { map.put(s3[j], 0); } } int c1 = 0, c2 = 0, c3 = 0; for (int j = 0; j < n; j++) { c1 += map.get(s1[j]); c2 += map.get(s2[j]); c3 += map.get(s3[j]); } System.out.println(c1 + " " + c2 + " " + c3); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 8
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
e2de00a318e4c087d6ac9fc69428a6b2
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.io.*; import java.math.BigInteger; import java.net.InetAddress; import java.net.ServerSocket; import java.net.Socket; import java.util.*; import static java.lang.System.out; public class app { public static long m; static int mod = 998244353; static int inf = (int) 1e9; public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); //int t=1; while (t-- > 0) { int n = sc.nextInt(); int a[] = new int[3]; String[][] x = new String[3][n]; for(int i = 0;i < 3;i++) x[i] = sc.nextLine().split(" "); Map<String, Integer> map = new HashMap<>(); Map<String, List<Integer>> map1 = new HashMap<>(); for(int i = 0; i< 3;i++){ for(int j = 0;j < n;j++) { String s = x[i][j]; map.put(x[i][j], map.getOrDefault(x[i][j], 0) + 1); List<Integer> list = map1.getOrDefault(s,new ArrayList<>()); list.add(i); map1.put(s,list); } } for(String s : map.keySet()){ if(map.get(s) == 2){ a[map1.get(s).get(0)]++; a[map1.get(s).get(1)]++; }else if(map.get(s) == 1){ a[map1.get(s).get(0)]+=3; } } out.println(Arrays.toString(a).replace(",","").replace("]","").replace("[","")); } } //out.println(Arrays.toString(d).replace(",","").replace("]","").replace("[","")); static long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); } static long lcm(long a, long b) { return a * b / gcd(a, b); } static void sort(int[] a) { int n = a.length; Integer[] b = new Integer[n]; for (int i = 0; i < n; i++) b[i] = a[i]; Arrays.sort(b); for (int i = 0; i < n; i++) a[i] = b[i]; } static void sort(long[] a) { int n = a.length; Long[] b = new Long[n]; for (int i = 0; i < n; i++) b[i] = a[i]; Arrays.sort(b); for (int i = 0; i < n; i++) a[i] = b[i]; } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream system) { br = new BufferedReader(new InputStreamReader(system)); } public Scanner(String file) throws Exception { br = new BufferedReader(new FileReader(file)); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public String nextLine() throws IOException { return br.readLine(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public char nextChar() throws IOException { return next().charAt(0); } public Long nextLong() throws IOException { return Long.parseLong(next()); } public int[] nextArrInt(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public long[] nextArrLong(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public int[] nextArrIntSorted(int n) throws IOException { int[] a = new int[n]; Integer[] a1 = new Integer[n]; for (int i = 0; i < n; i++) a1[i] = nextInt(); Arrays.sort(a1); for (int i = 0; i < n; i++) a[i] = a1[i].intValue(); return a; } public long[] nextArrLongSorted(int n) throws IOException { long[] a = new long[n]; Long[] a1 = new Long[n]; for (int i = 0; i < n; i++) a1[i] = nextLong(); Arrays.sort(a1); for (int i = 0; i < n; i++) a[i] = a1[i].longValue(); return a; } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 8
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
5949f87ba076b04633fb1e850e67f05d
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.lang.*; import java.util.*; import java.io.*; 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(); String [][] s=new String[3][n]; for(int i=0;i<3;i++){ for(int j=0;j<n;j++){ s[i][j]=sc.next(); } } HashMap<String,Integer>h=new HashMap<>(); for(int i=0;i<3;i++){ for(int j=0;j<n;j++){ if(h.containsKey(s[i][j])) h.put(s[i][j],h.get(s[i][j])+1); else h.put(s[i][j],1); } } for(int i=0;i<3;i++){ int c=0; for(int j=0;j<n;j++){ if(h.get(s[i][j])==3){ c=c+0; }else if(h.get(s[i][j])==2){ c=c+1; } else if(h.get(s[i][j])==1){ c=c+3; } } System.out.print(c+" "); } System.out.println(); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 8
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
61034333856d04f31675e25e89be76be
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int test = in.nextInt(); for(int t =1;t<=test;t++) { int n = in.nextInt(); String s1[] = new String[n]; String s2[] = new String[n]; String s3[] = new String[n]; Map<String ,Integer> m1 = new HashMap<>(); Map<String ,Integer> m2 = new HashMap<>(); Map<String ,Integer> m3 = new HashMap<>(); for(int i = 0;i<n;i++){ s1[i] = in.next(); m1.put(s1[i],0); } for(int i = 0;i<n;i++){ s2[i] = in.next(); m2.put(s2[i],0); } for(int i = 0;i<n;i++){ s3[i] = in.next(); m3.put(s3[i],0); } int sum1 = 0,sum2 = 0,sum3 =0; for(int i = 0;i<n;i++){ if(m2.containsKey(s1[i]) || m3.containsKey(s1[i])){ if(m2.containsKey(s1[i]) && m3.containsKey(s1[i])){ sum1+=0; } else{ sum1++; } } else{ sum1+=3; } if(m1.containsKey(s2[i]) || m3.containsKey(s2[i])){ if(m1.containsKey(s2[i]) && m3.containsKey(s2[i])){ sum2+=0; } else{ sum2++; } } else{ sum2+=3; } if(m1.containsKey(s3[i]) || m2.containsKey(s3[i])){ if(m1.containsKey(s3[i]) && m2.containsKey(s3[i])){ sum3+=0; } else{ sum3++; } } else{ sum3+=3; } } pw.println(sum1+" "+sum2+" "+sum3); } pw.close(); } static void debug(Object... obj) { System.err.println(Arrays.deepToString(obj)); } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 8
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
f3bd769fbcf2d2a16c60e4408566ed3c
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.io.*; import java.util.*; public class ProblemB { static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static PrintWriter pw = new PrintWriter(System.out); public static void main(String[] args) throws IOException { int t = Integer.parseInt(br.readLine()); while(t-- > 0) { int n = Integer.parseInt(br.readLine()); String[] a = br.readLine().split(" "); String[] b = br.readLine().split(" "); String[] c = br.readLine().split(" "); HashSet<String> am = new HashSet<>(); HashSet<String> bm = new HashSet<>(); HashSet<String> cm = new HashSet<>(); for (int i = 0; i < c.length; i++) { am.add(a[i]); bm.add(b[i]); cm.add(c[i]); } int[] ans = new int[3]; for(int i = 0; i < n; i++) { if(bm.contains(a[i]) && cm.contains(a[i])) { } else if(bm.contains(a[i])) { ans[0] += 1; } else if(cm.contains(a[i])) { ans[0] += 1; } else { ans[0] += 3; } if(am.contains(b[i]) && cm.contains(b[i])) { } else if(am.contains(b[i])) { ans[1] += 1; } else if(cm.contains(b[i])) { ans[1] += 1; } else { ans[1] += 3; } if(bm.contains(c[i]) && am.contains(c[i])) { } else if(bm.contains(c[i])) { ans[2] += 1; } else if(am.contains(c[i])) { ans[2] += 1; } else { ans[2] += 3; } } System.out.println(ans[0] + " " + ans[1] + " " + ans[2]); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 8
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
b1733f5ba251f187adfeaa53ac13c4ea
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.io.*; import java.util.*; import java.math.*; public class A { public static long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); } public static void print(int[] a) { for (int i = 0; i < a.length; i++) { System.out.print(a[i] + " "); } System.out.println(); } public static String concat(String s1, String s2) { return new StringBuilder(s1).append(s2).toString(); } static long lcm(long a, long b) { return (a / gcd(a, b)) * b; } public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int t1 = sc.nextInt(); outer:while (t1-- > 0) { int n = sc.nextInt(); String a1 [] = new String [n]; String b1 [] = new String [n]; String c1 [] = new String [n]; for (int i = 0;i<n;i++) { a1[i] = sc.next(); } for (int i = 0;i<n;i++) { b1[i] = sc.next(); } for (int i = 0;i<n;i++) { c1[i] = sc.next(); } long a = 0,b = 0,c = 0; TreeSet<String> aa = new TreeSet<>(); TreeSet<String> bb = new TreeSet<>(); TreeSet<String> cc = new TreeSet<>(); for (int i = 0;i<n;i++) { aa.add(a1[i]); } for (int i = 0;i<n;i++) { bb.add(b1[i]); } for (int i = 0;i<n;i++) { cc.add(c1[i]); } for (int i = 0;i<n;i++) { if (bb.contains(a1[i]) && cc.contains(a1[i])) { continue; }else if (bb.contains(a1[i]) || cc.contains(a1[i])) { a+=1; }else { a+=3; } } for (int i = 0;i<n;i++) { if (aa.contains(c1[i]) && bb.contains(c1[i])) { continue; }else if (aa.contains(c1[i]) || bb.contains(c1[i])) { c+=1; }else { c+=3; } } for (int i = 0;i<n;i++) { if (aa.contains(b1[i]) && cc.contains(b1[i])) { continue; }else if (aa.contains(b1[i]) || cc.contains(b1[i])) { b+=1; }else { b+=3; } } out.println(a + " "+ b + " "+c); } out.close(); } static class Pair implements Comparable<Pair> { long first; long second; public Pair(long first, long second) { this.first = first; this.second = second; } public int compareTo(Pair p) { if (first != p.first) return Long.compare(first, p.first); else if (second != p.second) return Long.compare(second, p.second); else return 0; } } static class Tuple implements Comparable<Tuple> { long first; long second; long third; public Tuple(long a, long b, long c) { first = a; second = b; third = c; } public int compareTo(Tuple t) { if (first != t.first) return Long.compare(first, t.first); else if (second != t.second) return Long.compare(second, t.second); else if (third != t.third) return Long.compare(third, t.third); else return 0; } } static final Random random = new Random(); static void shuffleSort(int[] a) { int n = a.length; for (int i = 0; i < n; i++) { int r = random.nextInt(n), temp = a[r]; a[r] = a[i]; a[i] = temp; } Arrays.sort(a); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public boolean ready() throws IOException { return br.ready(); } int[] readArray(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 8
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
747589e108f3a9bb6fc6f5346bb887ee
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner scn = new Scanner(System.in); int t = scn.nextInt(); while(t-- > 0){ int n = scn.nextInt(); HashMap<String, Integer> map = new HashMap<>(); String arr[][] = new String[3][n]; for(int i = 0; i < 3; i++){ for(int j = 0; j < n; j++){ String str = scn.next(); arr[i][j] = str; map.put(str,map.getOrDefault(str,0) +1); } } int ans[] = new int[3]; for(int i = 0; i < 3; i++){ for(int j = 0; j < n; j++){ String str = arr[i][j]; int freq = map.get(str); if(freq == 1){ ans[i]+=3; } else if(freq == 2){ ans[i]+= 1; } else{ continue; } } } for(int i = 0; i < 3; i++){ System.out.print(ans[i] + " "); } System.out.println(); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 8
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
e3902bf7b713b68a22709c653c4636a9
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.io.*; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.Scanner; public final class Main { public static void main(String[] args) throws IOException { 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()); int[] ans = new int[3]; String[] inp = br.readLine().split(" "); HashSet<String> A = new HashSet<>(Arrays.asList(inp).subList(0, N)); inp = br.readLine().split(" "); HashSet<String> B = new HashSet<>(Arrays.asList(inp).subList(0, N)); inp = br.readLine().split(" "); HashSet<String> C = new HashSet<>(Arrays.asList(inp).subList(0, N)); for (String str : A) if (B.contains(str) && C.contains(str)) ans[0] += 0; else if (B.contains(str) || C.contains(str)) ans[0] += 1; else ans[0] += 3; for (String str : B) if (A.contains(str) && C.contains(str)) ans[1] += 0; else if (A.contains(str) || C.contains(str)) ans[1] += 1; else ans[1] += 3; for (String str : C) if (B.contains(str) && A.contains(str)) ans[2] += 0; else if (B.contains(str) || A.contains(str)) ans[2] += 1; else ans[2] += 3; for (int i : ans) bw.write(i + " "); bw.write("\n"); } bw.close(); } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 8
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
1c624e6eeeef507b270b7cad00ff2b46
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.Arrays; import java.util.HashSet; import java.util.Scanner; import java.util.Set; public class Main { static Scanner sc = new Scanner(System.in); static int n; static String s1, s2, s3; public static void main(String[] args) { int _t = sc.nextInt(); while (_t -- > 0){ n = sc.nextInt(); sc.nextLine(); s1 = sc.nextLine(); s2 = sc.nextLine(); s3 = sc.nextLine(); String[] a1 = s1.split(" "); String[] a2 = s2.split(" "); String[] a3 = s3.split(" "); StringBuilder sb = new StringBuilder(); Set<String> set1 = new HashSet<>(Arrays.asList(a1)); Set<String> set2 = new HashSet<>(Arrays.asList(a2)); Set<String> set3 = new HashSet<>(Arrays.asList(a3)); int point = 0; for (String s : a1) { point += con(s, set2, set3); } sb.append(point + " "); point = 0; for (String s : a2) { point += con(s, set1, set3); } sb.append(point + " "); point = 0; for (String s : a3) { point += con(s, set2, set1); } sb.append(point); System.out.println(sb); sb = new StringBuilder(); } } public static int con(String s, Set<String> a, Set<String> b){ int res = 0; if (a.contains(s)) res ++; if (b.contains(s)){ res ++; } if (res == 0)return 3; if (res == 1)return 1; return 0; } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 8
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output
PASSED
1d3bfbed8749e7932e6605467ec5574a
train_109.jsonl
1661871000
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
256 megabytes
import java.util.HashSet; import java.util.Scanner; public class codefoword { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); for(int i=0;i<n;i++){ int m = sc.nextInt(); HashSet<String> hm1 = new HashSet<>(); HashSet<String> hm2 = new HashSet<>(); HashSet<String> hm3 = new HashSet<>(); String[][] arr = new String[3][m]; int[] nums = new int[3]; for(int j=0;j<3;j++){ nums[j]=0; } for(int j=0;j<3;j++){ for(int k=0;k<m;k++){ arr[j][k]=sc.next(); } } for(int j=0;j<m;j++){ hm1.add(arr[0][j]); } for(int j=0;j<m;j++){ hm2.add(arr[1][j]); } for(int j=0;j<m;j++){ hm3.add(arr[2][j]); } for(int j=0;j<m;j++) { if (hm2.contains(arr[0][j])){ if(!(hm3.contains(arr[0][j]))){ nums[0]+=1; } } else if (hm3.contains(arr[0][j])) { nums[0]+=1; } else{ nums[0]+=3; } } for(int j=0;j<m;j++) { if (hm1.contains(arr[1][j])){ if(!(hm3.contains(arr[1][j]))){ nums[1]+=1; } } else if (hm3.contains(arr[1][j])) { nums[1]+=1; } else{ nums[1]+=3; } } for(int j=0;j<m;j++) { if (hm1.contains(arr[2][j])){ if(!(hm2.contains(arr[2][j]))){ nums[2]+=1; } } else if (hm2.contains(arr[2][j])) { nums[2]+=1; } else{ nums[2]+=3; } } for(int k=0;k<3;k++){ System.out.print(nums[k]+" "); } System.out.println(); } } }
Java
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
1 second
["1 3 1 \n2 2 6 \n9 11 5"]
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
Java 8
standard input
[ "data structures", "implementation" ]
f8a89510fefbbc8e5698efe8a0c30927
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
800
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
standard output