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
|
2fd49b30a14ae783110b057bd210b28b
|
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.BufferedInputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class C {
public static int[] solve(String[][] players) {
int[] res = new int[3];
Map<String, Integer> hash = new HashMap<>();
for (String[] ws: players) {
for (String w: ws) {
hash.put(w, hash.getOrDefault(w, 0) + 1);
}
}
for (int i = 0; i < 3; i++) {
int ans = 0;
for (String w: players[i]) {
int v = hash.get(w);
ans += (v == 1) ? 3 : ((v == 2) ? 1 : 0);
}
res[i] = ans;
}
return res;
}
public static void main(String[] args) {
Scanner sc = new Scanner(new BufferedInputStream(System.in));
int kase = sc.nextInt();
while (kase-- > 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();
}
}
int[] res = solve(arr);
System.out.printf("%d %d %d\n", res[0], res[1], res[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 17
|
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
|
147f118dc5dccfd9d424c41867ac0d22
|
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 WordGame {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int T = input.nextInt();
HashMap<String, int[]> freq = new HashMap<>();
int[] points;
while (T-- > 0) {
points = new int[3];
freq.clear();
int N = input.nextInt();
for (int i = 0; i < 3; i++) {
for (int j = 0; j < N; j++) {
String str = input.next();
if (freq.containsKey(str)) {
int[] arr = freq.get(str);
arr[i] = 1;
} else {
freq.put(str, new int[3]);
freq.get(str)[i] = 1;
}
}
}
for (String keys : freq.keySet()) {
int[] arr = freq.get(keys);
int cnt = 0;
for (int i : arr) {
if (i != 0) {
cnt++;
}
}
if (cnt == 1) {
for (int i = 0; i < 3; i++) {
if (arr[i] != 0) {
points[i] += 3;
break;
}
}
} else if (cnt == 2) {
for (int i = 0; i < 3; i++) {
if (arr[i] != 0) {
points[i] += 1;
}
}
} else {
}
}
for (int i = 0; i < 3; i++) {
System.out.print(points[i] + " ");
}
System.out.println();
}
input.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 17
|
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
|
6bf3a1212081b9314bc5114b8baebb55
|
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 = 1;
t = in.nextInt();
while (t-->0)
{
int n=in.nextInt();
HashMap<String,Integer> mp=new HashMap<String,Integer>();
String X[][]=new String[3][n];
for (int i=0; i<3; i++)
{
for (int j=0; j<n; j++)
{
X[i][j]=in.next();
mp.put(X[i][j],mp.containsKey(X[i][j])?mp.get(X[i][j])+1:1);
}
}
for (int i=0; i<3; i++)
{
int c=0;
for (int j=0; j<n; j++)
{
int xx= mp.get(X[i][j]);
if(xx==1)
c+=3;
else if(xx==2)
c++;
}
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 17
|
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
|
7555597ee861c1ed180da71eb4122105
|
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 ProblemC {
static HashMap<String,Integer> addToMap(HashMap<String,Integer> map,String word){
if(map.containsKey(word)){
int temp = map.get(word);
map.put(word,++temp);
}
else{
map.put(word,1);
}
return map;
}
static int getScore(HashMap<String,Integer> map,String word){
int temp = map.get(word);
if(temp == 3){return 0;}
if(temp == 2){return 1;}
return 3;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int i=0;i<t;i++){
int len = sc.nextInt();
int[] scores = new int[3];
ArrayList<String> A = new ArrayList<String>();
ArrayList<String> B = new ArrayList<String>();
ArrayList<String> C = new ArrayList<String>();
HashMap<String,Integer> map = new HashMap<String,Integer>();
//Adding the scores
for(int j=0;j<len;j++){
A.add(sc.next());
map = addToMap(map,A.get(j));
}
for(int j=0;j<len;j++){
B.add(sc.next());
map = addToMap(map,B.get(j));
}
for(int j=0;j<len;j++){
C.add(sc.next());
map = addToMap(map,C.get(j));
}
//checking the words
for(int j=0;j<len;j++){
scores[0]+=getScore(map,A.get(j));
scores[1]+=getScore(map,B.get(j));
scores[2]+=getScore(map,C.get(j));
}
System.out.println(scores[0]+ " "+scores[1]+" "+scores[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 17
|
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
|
8f6ce3566c20fd14b6eaaf9015401719
|
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 static java.util.Map.entry;
import java.io.*;
import java.util.*;
import java.util.stream.Collectors;
import java.math.*;
public class Solution {
private static final Map<Integer, Integer> NO_FO_WORDS = Map.ofEntries(entry(1, 3), entry(2, 1), entry(3, 0));
public static void main(String[] args) throws Exception {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
// Task solver = new Task();
int testCases = in.nextInt();
for (int test = 1; test <= testCases; test += 1) {
int n = in.nextInt();
String[][] words = new String[3][n];
for (int i = 0; i < words.length; i++) {
for (int j = 0; j < words[i].length; j++) {
words[i][j] = in.next();
}
}
System.out.println(Task.solve(words));
}
out.close();
}
static class Task {
static final int MOD = (int) (1e9 + 7);
static String solve(String[][] words) {
Map<String, Integer> wordCount = new HashMap<>();
for (int i = 0; i < words.length; i++) {
for (int j = 0; j < words[i].length; j++) {
wordCount.put(words[i][j], wordCount.getOrDefault(words[i][j], 0) + 1);
}
}
return Arrays.stream(words)
.mapToInt(
p -> Arrays.stream(p).mapToInt(word -> NO_FO_WORDS.get(wordCount.get(word))).sum())
.mapToObj(String::valueOf)
.collect(Collectors.joining(" "));
}
}
static class InputReader {
public BufferedReader take;
public StringTokenizer split;
public InputReader(InputStream stream) {
take = new BufferedReader(new InputStreamReader(stream), 10000000);
split = null;
}
public String next() {
while (split == null || !split.hasMoreTokens()) {
try {
split = new StringTokenizer(take.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return split.nextToken();
}
public int nextInt() {
return Integer.parseInt(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 17
|
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
|
36044aa51b93b413f61ab2f2621f35ba
|
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.Arrays;
import java.util.HashSet;
import java.util.Set;
public class Main817C {
public static void main(String[] args) throws IOException {
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
int numberOfCases = Integer.parseInt(input.readLine());
for (int i = 0; i < numberOfCases; i++) {
input.readLine();
Set<String> set1 = new HashSet<>(Arrays.asList(input.readLine().split(" ")));
Set<String> set2 = new HashSet<>(Arrays.asList(input.readLine().split(" ")));
Set<String> set3 = new HashSet<>(Arrays.asList(input.readLine().split(" ")));
System.out.println(getCount(set1, set2, set3) + " " + getCount(set2, set1, set3) + " " + getCount(set3, set2, set1));
}
}
public static int getCount(Set<String> set1, Set<String> set2, Set<String> set3) {
int count = 0;
for (String s : set1) {
if (!set2.contains(s) && !set3.contains(s))
count += 3;
else if (set2.contains(s) ^ set3.contains(s))
count++;
}
return count;
}
}
|
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 17
|
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
|
706d7ea2275a8f6efb4a7a4cf8321237
|
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 _1722C_WordGame {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int t = input.nextInt();
while (t-- > 0) {
solve(input);
}
}
static void solve(Scanner input) {
int len = input.nextInt();
HashSet<String> s1 = new HashSet<>();
HashSet<String> s2 = new HashSet<>();
HashSet<String> s3 = new HashSet<>();
for (int i = 0; i < len; i++) {
s1.add(input.next());
}
for (int i = 0; i < len; i++) {
s2.add(input.next());
}
for (int i = 0; i < len; i++) {
s3.add(input.next());
}
int first = 0;
int second = 0;
int third = 0;
for (String s : s1) {
int num = 0;
num += s2.contains(s) ? 1: 0;
num += s3.contains(s) ? 1: 0;
if (num == 0) {
first += 3;
} else if (num == 1) {
first++;
}
}
for (String s : s2) {
int num = 0;
num += s1.contains(s) ? 1:0;
num += s3.contains(s) ? 1:0;
if (num == 0) {
second += 3;
} else if (num == 1) {
second++;
}
}
for (String s : s3) {
int num = 0;
num += s1.contains(s) ? 1 : 0;
num += s2.contains(s) ? 1 : 0;
if (num == 0) {
third += 3;
} else if (num == 1) {
third++;
}
}
System.out.println(String.format("%d %d %d", first, second, third));
}
}
|
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 17
|
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
|
bc028e97f6d7066ee0b92244c13cec9d
|
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 ProblemC {
private static final Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
int n = sc.nextInt();
for (int i = 0; i < n; i++) {
solve();
}
}
private static void solve() {
int wordsNum = sc.nextInt();
List<List<String>> words = new ArrayList<>();
Map<String, Integer> freq = new HashMap<>();
for (int i = 0; i < 3; i++) {
List<String> currList = new ArrayList<>();
for (int j = 0; j < wordsNum; j++) {
String str = sc.next();
currList.add(str);
freq.put(str, freq.getOrDefault(str, 0) + 1);
}
words.add(currList);
}
for (int i = 0; i < 3; i++) {
int pts = 0;
for (String str : words.get(i)) {
int freqNum = freq.get(str);
if (freqNum == 1) pts += 3;
else if (freqNum == 2) pts += 1;
}
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 17
|
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
|
7cac72bfaf0480c7e9de9349d6025200
|
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.BufferedWriter;
import java.io.Flushable;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;
public class Submit {
public static void main(String... strings) throws IOException {
try (InputReader reader = new InputReader();
OutputWriter writer = new OutputWriter(true)) {
Set<String> s1;
Set<String> s2;
Set<String> s3;
Set<String> allWords;
int t = reader.nextInt();
while (t-- > 0) {
int words = reader.nextInt();
allWords = new HashSet<>();
s1 = new HashSet<>(Arrays.asList(reader.nextLine().split(" ")));
s2 = new HashSet<>(Arrays.asList(reader.nextLine().split(" ")));
s3 = new HashSet<>(Arrays.asList(reader.nextLine().split(" ")));
allWords.addAll(s1);
allWords.addAll(s2);
allWords.addAll(s3);
int p1 = 0;
int p2 = 0;
int p3 = 0;
boolean s1HasIt;
boolean s2HasIt;
boolean s3HasIt;
for (String word : allWords) {
s1HasIt = s1.contains(word);
s2HasIt = s2.contains(word);
s3HasIt = s3.contains(word);
// urcite to niekto ma a urcite mam pici ked to maju seci
if (s1HasIt && s2HasIt && s3HasIt) {
// jebat
} else if (s1HasIt && s2HasIt && !s3HasIt) {
p1++;
p2++;
} else if (s1HasIt && !s2HasIt && s3HasIt) {
p1++;
p3++;
} else if (!s1HasIt && s2HasIt && s3HasIt) {
p2++;
p3++;
} else if (s1HasIt) {
p1 += 3;
} else if (s2HasIt) {
p2 += 3;
} else if (s3HasIt) {
p3 += 3;
}
}
writer.println(p1 + " " + p2 + " " + p3);
}
}
}
}
class InputReader implements AutoCloseable {
private BufferedReader bufferedReader;
private StringTokenizer tokenizer;
public InputReader() {
bufferedReader = new BufferedReader(new InputStreamReader(System.in));
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreElements()) {
try {
tokenizer = new StringTokenizer(bufferedReader.readLine());
} catch (IOException ex) {
ex.printStackTrace();
}
}
return tokenizer.nextToken();
}
public char nextChar() {
char character = ' ';
try {
character = (char) bufferedReader.read();
} catch (IOException e) {
e.printStackTrace();
}
return character;
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String nextLine() {
String line = "";
try {
line = bufferedReader.readLine();
} catch (IOException ex) {
ex.printStackTrace();
}
return line;
}
@Override
public void close() {
try {
this.bufferedReader.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
class OutputWriter implements AutoCloseable, Flushable {
private final BufferedWriter writer;
private boolean autoFlush;
public OutputWriter() {
this.writer = new BufferedWriter(new OutputStreamWriter(System.out));
}
public OutputWriter(boolean autoFlush) {
this();
this.autoFlush = autoFlush;
}
public void printWithSpace(int input) {
try {
writer.append(input + " ");
} catch (IOException e) {
e.printStackTrace();
}
if (autoFlush) {
flush();
}
}
public void print(int input) {
try {
writer.append(input + "");
} catch (IOException e) {
e.printStackTrace();
}
if (autoFlush) {
flush();
}
}
public void println(int input) {
try {
writer.append(input + System.lineSeparator());
} catch (IOException e) {
e.printStackTrace();
}
if (autoFlush) {
flush();
}
}
public void printWithSpace(String input) {
try {
writer.append(input + " ");
} catch (IOException e) {
e.printStackTrace();
}
if (autoFlush) {
flush();
}
}
public void print(String input) {
try {
writer.append(input);
} catch (IOException e) {
e.printStackTrace();
}
if (autoFlush) {
flush();
}
}
public void println(CharSequence input) {
try {
writer.append(input);
writer.append(System.lineSeparator());
} catch (IOException e) {
e.printStackTrace();
}
if (autoFlush) {
flush();
}
}
public void printArray() {
// implement
if (autoFlush) {
flush();
}
}
@Override
public void flush() {
try {
this.writer.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void close() {
try {
writer.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
|
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 17
|
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
|
b4c7c8c54354f46514ec654c1fb46e3a
|
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 S = new Scanner(System.in);
int T = S.nextInt();
while(T-- > 0)
{
HashMap<String,Integer>Mp = new HashMap<String,Integer>();
ArrayList<ArrayList<String>>Arr = new ArrayList<ArrayList<String>>();
int N = S.nextInt();
for(int i=0;i<3;i++)
{
Arr.add(new ArrayList<String>());
for(int j=1;j<=N;j++)
{
String Curr = S.next();
Arr.get(i).add(Curr);
Mp.put(Curr , Mp.getOrDefault(Curr , 0) + 1);
}
}
int Ans[] = new int[3];
for(int i=0;i<3;i++)
{
for(String X : Arr.get(i))
{
if(Mp.get(X) == 1)Ans[i]+=3;
else if(Mp.get(X) == 2)Ans[i]++;
}
}
for(int X : Ans)System.out.print(X + " ");
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 17
|
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
|
44ba904422874da3a176da4af3134b21
|
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{
static Scanner s = new Scanner(System.in);
public static void main(String[] args) {
int t = s.nextInt();
while(t-->0){
HashMap<String,Integer> mp = new HashMap<>();
int n = s.nextInt();
String ar[][] = new String[3][n];
for(int i=0;i<3;i++){
for(int j=0;j<n;j++){
ar[i][j] = s.next();
if(mp.containsKey(ar[i][j])){
mp.put(ar[i][j], mp.get(ar[i][j])+1);
}else{
mp.put(ar[i][j], 1);
}
}
}
for(int i=0;i<3;i++){
int total =0;
for(int j=0;j<n;j++){
if(mp.get(ar[i][j]) == 1){
total+=3;
}else if(mp.get(ar[i][j])==2){
total++;
}
}
System.out.print(total+" ");
}
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 17
|
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
|
02813cf1926e9fe068a94682cf375152
|
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 static java.lang.Math.*;
import static java.lang.System.*;
public class Main implements Runnable {
private final void process() throws IOException {
// InputReader input = new InputReader(new FileReader(System.getenv("INPUT")));
// PrintWriter output = new PrintWriter(new BufferedOutputStream(new FileOutputStream(System.getenv("OUTPUT"))));
InputReader input = new InputReader(in);
PrintWriter output = new PrintWriter(new BufferedOutputStream(out));
byte test = input.nextByte();
while (test-- > 0) {
int n = input.nextInt();
String[][] words = new String[3][n];
for (int i = 0; i < 3; i++) {
words[i] = input.readStringArray();
}
HashMap<String, ArrayList<Integer>> hmap = new HashMap<>();
for (int i = 1; i <= 3; i++) {
for (String word : words[i - 1]) {
if (!hmap.containsKey(word))
hmap.put(word, new ArrayList<>());
hmap.get(word).add(i);
}
}
int A = 0, B = 0, C = 0;
for (String key : hmap.keySet()) {
var lst = hmap.get(key);
if (lst.size() == 2) {
for (int idx : lst) {
if (idx == 1) A++;
else if (idx == 2) B++;
else if (idx == 3) C++;
}
} else if (lst.size() == 1) {
if (lst.get(0) == 1) A += 3;
else if (lst.get(0) == 2) B += 3;
else C += 3;
}
}
output.println(A + " " + B + " " + C);
}
output.close();
input.close();
}
@Override
public void run() {
try {
process();
} catch (IOException ignored) {}
}
public static void main(String... args) throws IOException {
new Thread(null, new Main(), "Main", 1 << 26).start();
}
private final void printArr(PrintWriter output, short...arr) {
output.println(Arrays.toString(arr).replaceAll("\\[|]|, ", " ").trim());
}
private final void printArr(PrintWriter output, int...arr) {
output.println(Arrays.toString(arr).replaceAll("\\[|]|, ", " ").trim());
}
private final void printArr(PrintWriter output, double...arr) {
output.println(Arrays.toString(arr).replaceAll("\\[|]|, ", " ").trim());
}
private final void printArr(PrintWriter output, long...arr) {
output.println(Arrays.toString(arr).replaceAll("\\[|]|, ", " ").trim());
}
private final void printArr(PrintWriter output, char...arr) {
output.println(Arrays.toString(arr).replaceAll("\\[|]|, ", " ").trim());
}
private final void printArr(PrintWriter output, String...arr) {
output.println(Arrays.toString(arr).replaceAll("\\[|]|, ", " ").trim());
}
}
class InputReader {
private StringTokenizer token;
private BufferedReader buffer;
public InputReader(InputStream stream) {
buffer = new BufferedReader(new InputStreamReader(stream));
}
public InputReader(FileReader reader) throws FileNotFoundException {
buffer = new BufferedReader(reader);
}
public final String next() throws IOException {
while (token == null || !token.hasMoreTokens())
token = new StringTokenizer(buffer.readLine());
return token.nextToken();
}
public final String nextLine() throws IOException {
return buffer.readLine();
}
public final byte nextByte() throws IOException {
return Byte.parseByte(next());
}
public final short nextShort() throws IOException {
return Short.parseShort(next());
}
public final int nextInt() throws IOException {
return Integer.parseInt(next());
}
public final long nextLong() throws IOException {
return Long.parseLong(next());
}
public final double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public final char nextChar() throws IOException {
return next().charAt(0);
}
public final boolean nextBoolean() throws IOException {
return Boolean.parseBoolean(next());
// return Boolean.getBoolean(next());
// return Boolean.valueOf(next());
}
public int[] readIntArray(int n) throws IOException {
int[] arr = new int[n];
for (int i = 0; i < n; i++)
arr[i] = nextInt();
return arr;
}
public int[] readIntArray() throws IOException {
return java.util.Arrays.stream(nextLine().split("\\s+")).
mapToInt(Integer::parseInt).toArray();
}
public long[] readLongArray(int n) throws IOException {
long[] arr = new long[n];
for (int i = 0; i < n; i++)
arr[i] = nextLong();
return arr;
}
public long[] readLongArray() throws IOException {
return java.util.Arrays.stream(nextLine().split("\\s+")).
mapToLong(Long::parseLong).toArray();
}
public double[] readDoubleArray(int n) throws IOException {
double[] arr = new double[n];
for (int i = 0; i < n; i++)
arr[i] = nextDouble();
return arr;
}
public double[] readDoubleArray() throws IOException {
return java.util.Arrays.stream(nextLine().split("\\s+")).
mapToDouble(Double::parseDouble).toArray();
}
public char[] readCharArray() throws IOException {
return nextLine().toCharArray();
}
public String[] readStringArray(int n) throws IOException {
String[] arr = new String[n];
for (int i = 0; i < n; i++)
arr[i] = next();
return arr;
}
public String[] readStringArray() throws IOException {
return nextLine().split("\\s+");
}
public boolean ready() throws IOException {
return buffer.ready();
}
public void close() throws IOException {
buffer.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 17
|
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
|
299c68f3395df48914a4a0092e626f94
|
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.LinkedList;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
public class MyClass {
static Scanner in = new Scanner(System.in);
public static void printArray(int[] arr) {
for(int i=0; i<arr.length; i++) {
System.out.print(arr[i] + " ");
}
}
public static void printArray(String[] arr) {
for(int i=0; i<arr.length; i++) {
System.out.println(arr[i]);
}
}
public static void minimumVariedNumber() {
int t = in.nextInt();
int[] cases = new int[t];
for(int i=0; i<t; i++) {
cases[i] = in.nextInt();
}
int[] res = new int[t];
for(int i=0; i<t; i++) {
int num = cases[i];
int k = 1;
if(num/10 == 0) {
res[i] = num;
continue;
}
int temp = num;
for(int j=9; j>0; j--) {
if(temp>=j) {
temp = temp - j;
res[i] = res[i] + j*k;
k*=10;
}
}
}
printArray(res);
}
public static boolean allOpen(int x, int[] doors) {
int t = x -1;
int count = 1;
while(doors[t]!=0) {
t = doors[t] - 1;
count++;
}
if(count != 3)
return false;
else
return true;
}
public static void threeDoors() {
int t = in.nextInt();
String[] res = new String[t];
int[] doors = new int[3];
for(int i=0; i<t; i++) {
int x = in.nextInt();
for(int j=0; j<3; j++) {
doors[j] = in.nextInt();
}
if(allOpen(x,doors)) {
res[i] = "YES";
}
else {
res[i] = "NO";
}
}
printArray(res);
}
public static void swap(int[] arr, int i, int j) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
public static void sortAsc(int[] arr) {
int n = arr.length;
for(int i=0; i<n-1; i++) {
for(int j=i+1; j<n; j++) {
if(arr[i] > arr[j]) {
swap(arr, i, j);
}
}
}
}
public static PriorityQueue<Integer> generateNew(PriorityQueue<Integer> pq) {
PriorityQueue<Integer> new_pq = new PriorityQueue<Integer>();
int a = 0;
int b = 0;
while(pq.size()!=new_pq.size() || (pq.size() != 1 && new_pq.size() != 1)) {
if(pq.size() == 1) {
pq.clear();
PriorityQueue<Integer> tmp = pq;
pq = new_pq;
new_pq = tmp;
}
a = pq.poll();
b = pq.peek();
new_pq.add(b-a);
}
return new_pq;
}
public static void differenceArray() {
int t = 1;
//int t = in.nextInt();
int res[] = new int[t];
for(int i=0; i<t; i++) {
int n = 100000;
//int n = in.nextInt();
PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
for(int j=0; j<n; j++) {
//pq.add(in.nextInt());
pq.add(0);
}
pq = generateNew(pq);
res[i] = pq.poll();
}
printArray(res);
}
public static void wordGame() {
int t = in.nextInt();
HashMap<String, Par> mapa = new HashMap<String, Par>();
for(int test = 0; test < t; test++) {
int n = in.nextInt();
for(int i=0; i<3; i++) {
for(int j=0; j<n; j++) {
String rijec = in.next();
if(mapa.containsKey(rijec)) {
mapa.get(rijec).dodajIgraca(i);
}
else {
Par p = new Par(i);
mapa.put(rijec, p);
}
}
}
int ukupni_bodovi[] = new int[3];
for(Map.Entry<String, Par> entry: mapa.entrySet()) {
for(int i=0; i<3; i++) {
ukupni_bodovi[i] += entry.getValue().getBodovi()[i];
}
}
printArray(ukupni_bodovi);
System.out.println();
mapa.clear();
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
//minimumVariedNumber();
//threeDoors();
wordGame();
}
}
class Par {
private int bodovi[] = new int[3]; //bodovi za svaku rijec
private int ucestalost = 0;
public Par(int igrac) {
bodovi[igrac] = 3;
ucestalost++;
}
public Par(Par p) {
bodovi = p.bodovi;
ucestalost = p.ucestalost;
}
public void dodajIgraca(int igrac) {
ucestalost++;
if(ucestalost == 2) {
for(int i=0; i<3; i++) {
if(bodovi[i]>0) {
bodovi[i] = 1;
break;
}
}
bodovi[igrac] = 1;
}
else {
for(int i=0; i<3; i++) {
bodovi[i] = 0;
}
}
}
public int[] getBodovi() {
return bodovi;
}
public int getUcestalost() {
return ucestalost;
}
public void setUcestalost(int ucestalost) {
this.ucestalost = ucestalost;
}
}
|
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 17
|
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
|
9a5b7f402ebf38e30548e20316adb1ce
|
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.Map;
import java.util.Scanner;
import java.util.TreeMap;
public class guess {
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[n];
String [] ss = new String[n];
String [] sss = new String[n];
TreeMap<String , Integer> tree = new TreeMap<String , Integer>();
int x=0;
for(int i =0;i<3*n;i++){
if(i<n) {
s[i] = sc.next();
tree.put(s[i],1);
}
else if(i<2*n&&i>=n) {
ss[i-n] = sc.next();
if(tree.containsKey(ss[i-n])) {
x = tree.remove(ss[i - n]);
tree.put(ss[i - n], ++x);
}
else
tree.put(ss[i-n],1);
}
else {
sss[i-2*n] = sc.next();
if(tree.containsKey(sss[i-2*n])) {
x = tree.remove(sss[i - 2 * n]);
tree.put(sss[i - 2 * n], ++x);
}
else
tree.put(sss[i-2*n],1);
}
}
int a=0,b=0,c=0;
for(int i=0;i<n;i++){
x = tree.remove(s[i]);
if(x==2)
a+=1;
if(x==1)
a+=3;
tree.put(s[i],x);
}
for(int i=0;i<n;i++){
x = tree.remove(ss[i]);
if(x==2)
b+=1;
if(x==1)
b+=3;
tree.put(ss[i],x);
}
for(int i=0;i<n;i++){
x = tree.remove(sss[i]);
if(x==2)
c+=1;
if(x==1)
c+=3;
tree.put(sss[i],x);
}
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 17
|
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
|
18a78cb45ec93324959fe2cc23436edd
|
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.Arrays;
import java.util.HashSet;
import java.util.Scanner;
public class WordGame {
public static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
int cases = sc.nextInt();
for(int i = 0 ; i<cases;i++){
int countA = 0 ,countB = 0 ,countC = 0;
int size = sc.nextInt();
HashSet<String> a = new HashSet<>();
HashSet<String> b = new HashSet<>();
HashSet<String> c = new HashSet<>();
//String[] arr = new String[3*size];
ArrayList<String> list = new ArrayList<>();
for(int j = 0 ;j<size;j++){
String elem = sc.next();
a.add(elem);
list.add(elem);
}
for(int k = 0 ;k<size;k++){
String elem = sc.next();
b.add(elem);
if(!a.contains(elem))
list.add(elem);
}
for(int l = 0 ;l<size;l++){
String elem = sc.next();
c.add(elem);
if(!a.contains(elem) && !b.contains(elem))
list.add(elem);
}
for(int x = 0; x<list.size();x++){
String comp = list.get(x);
if(a.contains(comp) && !b.contains(comp) && !c.contains(comp)){
countA+=3;
}else if(!a.contains(comp) && b.contains(comp) && !c.contains(comp)){
countB+=3;
}else if(!a.contains(comp) && !b.contains(comp) && c.contains(comp)){
countC+=3;
} else if (a.contains(comp) && b.contains(comp) && !c.contains(comp)) {
countA++;
countB++;
}else if (a.contains(comp) && !b.contains(comp) && c.contains(comp)) {
countA++;
countC++;
}else if (!a.contains(comp) && b.contains(comp) && c.contains(comp)) {
countC++;
countB++;
}
}
System.out.println(countA+" "+ countB+" "+countC);
}
}
// public static int[] 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 17
|
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
|
86da10926290146fb2b3a581fa294513
|
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 BrInput {
public static class Pair {
int x;
int y;
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
}
private static final int modulo = 1000000007;
public static Scanner scan = new Scanner(System.in);
public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) throws IOException {
int testCase = Integer.parseInt(br.readLine());
for (int vedant = 0; vedant < testCase; vedant++) {
solve();
}
// out.println(5);
}
private static void solve() throws IOException {
// ******************** S O L V E M E T H O D *****************
// ************* M A I N L O G I C G O E S H E R E **********
int size = Integer.parseInt(br.readLine());
ArrayList<Set<String>> arr = new ArrayList<>();
for (int i = 0; i < 3; i++) {
arr.add(new HashSet<>());
}
String[] firstPerson = br.readLine().split(" ");
String[] secondPerson = br.readLine().split(" ");
String[] thirdPerson = br.readLine().split(" ");
for (int i = 0; i < size; i++) {
arr.get(0).add(firstPerson[i]);
arr.get(1).add(secondPerson[i]);
arr.get(2).add(thirdPerson[i]);
}
int firstPersonPoints = 0;
int secondPersonPoints = 0;
int thirdPersonPoints = 0;
for (int i = 0; i < size; i++) {
// 1st Person points
if (!arr.get(1).contains(firstPerson[i])
&& !arr.get(2).contains(firstPerson[i])) {
firstPersonPoints += 3;
} else if (!arr.get(1).contains(firstPerson[i])
|| !arr.get(2).contains(firstPerson[i])) {
firstPersonPoints += 1;
}
// 2nd Person points
if (!arr.get(0).contains(secondPerson[i])
&& !arr.get(2).contains(secondPerson[i])) {
secondPersonPoints += 3;
} else if (!arr.get(0).contains(secondPerson[i])
|| !arr.get(2).contains(secondPerson[i])) {
secondPersonPoints += 1;
}
// 3rd Person Points
if (!arr.get(1).contains(thirdPerson[i])
&& !arr.get(0).contains(thirdPerson[i])) {
thirdPersonPoints += 3;
} else if (!arr.get(1).contains(thirdPerson[i])
|| !arr.get(0).contains(thirdPerson[i])) {
thirdPersonPoints += 1;
}
}
System.out.println(firstPersonPoints + " " + secondPersonPoints + " " + thirdPersonPoints);
// **************************** S O L U T I O N E N D S H E R E ****************************
}
private static void printArray(int[] arr) {
StringBuilder output = new StringBuilder();
for (int j : arr) {
output.append(j).append(" ");
}
System.out.println(output);
}
private static void printYES() {
System.out.println("YES");
}
private static void printNO() {
System.out.println("NO");
}
private static long getMaximumFromList(List<Long> arr) {
long max = Long.MIN_VALUE;
for (Long aLong : arr) {
max = Math.max(max, aLong);
}
return max;
}
public static int binarySearch(int[] arr, int target) {
int starting = 0;
int ending = arr.length - 1;
while (starting < ending) {
int mid = starting + (ending - starting) / 2;
if (arr[mid] == target) {
return mid;
}
if (arr[mid] > target) {
ending = mid - 1;
} else {
starting = mid + 1;
}
}
return -1;
}
public static int binarySearch(long[] arr, long target) {
int starting = 0;
int ending = arr.length - 1;
while (starting < ending) {
int mid = starting + (ending - starting) / 2;
if (arr[mid] == target) {
return mid;
}
if (arr[mid] > target) {
ending = mid - 1;
} else {
starting = mid + 1;
}
}
return -1;
}
public static int gcd(int a, int b) {
// Everything divides 0
if (a == 0)
return b;
if (b == 0)
return a;
// base case
if (a == b)
return a;
// a is greater
if (a > b)
return gcd(a-b, b);
return gcd(a, b-a);
}
public static long gcd(long a, long b) {
// Everything divides 0
if (a == 0)
return b;
if (b == 0)
return a;
// base case
if (a == b)
return a;
// a is greater
if (a > b)
return gcd(a-b, b);
return gcd(a, b-a);
}
private static int[] readIntArray(int size) {
int[] arr = new int[size];
for (int i = 0; i < size; i++) {
arr[i] = scan.nextInt();
}
return arr;
}
private static long[] readLongArray(int size) {
long[] arr = new long[size];
for (int i = 0; i < size; i++) {
arr[i] = scan.nextLong();
}
return arr;
}
private static boolean isVowel(char charAt) {
charAt = Character.toLowerCase(charAt);
return charAt == 'a' ||
charAt == 'e' ||
charAt == 'i' ||
charAt == 'o' ||
charAt == 'u';
}
}
|
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 17
|
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
|
ea47fd0c04ca0032a3c042aae2a7fe56
|
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 Solution {
public static void main(String[] args) {
try (Scanner sc = new Scanner(System.in)) {
int t = sc.nextInt();
Outer: while (t-- > 0) {
int n = sc.nextInt();
int one = n*3, two = n*3, three = n*3;
Set<String> s1 = new HashSet<>();
for (int i = 0; i < n; ++i)
s1.add(sc.next());
Set<String> s2 = new HashSet<>();
for (int i = 0; i < n; ++i)
s2.add(sc.next());
Set<String> s3 = new HashSet<>();
for (int i = 0; i < n; ++i)
s3.add(sc.next());
for(var s : s1){
if(s2.contains(s) && s3.contains(s)){
one -= 3;
two -= 3;
three -= 3;
s2.remove(s);
s3.remove(s);
}else if(s2.contains(s)){
one -= 2;
two -= 2;
s2.remove(s);
}else if(s3.contains(s)){
one -= 2;
three -= 2;
s3.remove(s);
}
}
for(var s : s2){
if(s1.contains(s)){
one -= 2;
two -= 2;
// s1.remove(s);
}else if(s3.contains(s)){
two -= 2;
three -= 2;
s3.remove(s);
}
}
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 17
|
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
|
4463a9398f1b697b8455a13b782cbbd4
|
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 sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
HashMap<String,Integer> hm=new HashMap<>();
String[][] str=new String[3][n];
int[] b=new int[3];
for(int i=0;i<3;i++){
for(int j=0;j<n;j++){
str[i][j]=sc.next();
if(hm.containsKey(str[i][j])) hm.put(str[i][j],hm.get(str[i][j])+1);
else hm.put(str[i][j],1);
}
}
for(int i=0;i<3;i++){
for(int j=0;j<n;j++){
if(hm.get(str[i][j])==1) b[i]=b[i]+3;
else if(hm.get(str[i][j])==2) b[i]=b[i]+1;
}
}
for(int i=0;i<3;i++) System.out.print(b[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 17
|
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
|
92fb95ef46f068c990c31c0369cd7aea
|
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 {
private static final int INT_MAX = 999999999;
/*public static int power(int x,int n) {
if(n==0)
return 1;
return x*power(x,n-1);
}*/
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int test=0;test<t;test++) {
int n=sc.nextInt();
HashSet<String> s1=new HashSet<>();
HashSet<String> s2=new HashSet<>();
HashSet<String> s3=new HashSet<>();
String[] a1=new String[n];
String[] a2=new String[n];
String[] a3=new String[n];
for(int i=0;i<n;i++) {
a1[i]=sc.next();
s1.add(a1[i]);
}
for(int i=0;i<n;i++) {
a2[i]=sc.next();
s2.add(a2[i]);
}
for(int i=0;i<n;i++) {
a3[i]=sc.next();
s3.add(a3[i]);
}
int[] ans=new int[3];
for(int i=0;i<n;i++) {
if(s2.contains(a1[i])&&s3.contains(a1[i]))
ans[0]+=0;
else if(!s2.contains(a1[i])&&s3.contains(a1[i]))
ans[0]+=1;
else if(s2.contains(a1[i])&&!s3.contains(a1[i]))
ans[0]+=1;
else
ans[0]+=3;
}
for(int i=0;i<n;i++) {
if(s1.contains(a2[i])&&s3.contains(a2[i]))
ans[1]+=0;
else if(!s1.contains(a2[i])&&s3.contains(a2[i]))
ans[1]+=1;
else if(s1.contains(a2[i])&&!s3.contains(a2[i]))
ans[1]+=1;
else
ans[1]+=3;
}
for(int i=0;i<n;i++) {
if(s2.contains(a3[i])&&s1.contains(a3[i]))
ans[2]+=0;
else if(!s2.contains(a3[i])&&s1.contains(a3[i]))
ans[2]+=1;
else if(s2.contains(a3[i])&&!s1.contains(a3[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 17
|
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
|
f31c6254e34a87d5fd5b687290f84154
|
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 Solve {
private static void solve(Scanner sc) {
int n = sc.nextInt();
HashMap<String, Integer> map = new HashMap<>();
List<String> list = new ArrayList<>();
for (int i = 0; i < 3; i++) {
for (int j = 0; j < n; j++) {
String s = sc.next();
list.add(s);
if (map.get(s) != null) {
map.put(s, map.get(s) + 1);
} else {
map.put(s, 1);
}
}
}
int idx = 0;
for (int i = 0; i < 3; i++) {
int answer = 0;
for (int j = idx; j < idx + n; j++) {
if (map.get(list.get(j)) == 1) {
answer += 3;
}
if (map.get(list.get(j)) == 2) {
answer++;
}
}
idx += n;
System.out.print(answer + " ");
}
System.out.print('\n');
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int tt = scanner.nextInt();
while (tt-- > 0) {
solve(scanner);
}
}
}
|
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 17
|
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
|
b6e01129a57192d89265ef4bc56799a9
|
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 CF1722C {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
PrintWriter pr = new PrintWriter(new OutputStreamWriter(System.out));
int t = sc.nextInt();
HashMap<String, List<Integer>> mp = new HashMap<>();
while (t-- > 0)
{
int[] ans = new int[3];
mp.clear();
int n = sc.nextInt();
for (int i = 0; i < 3; i++)
for (int j =0; j < n; j++) {
String s = sc.next();
List<Integer> l = new ArrayList<>();
if (mp.get(s) == null) {
l.add(i);
mp.put(s, l);
ans[i] += 3;
}
else {
l = mp.get(s);
if (l.size() == 1) {
ans[l.get(0)] -= 2;
ans[i] += 1;
}
else if (l.size() == 2) {
ans[l.get(0)] -= 1;
ans[l.get(1)] -= 1;
}
l.add(i);
mp.replace(s, l);
}
}
pr.println(ans[0] + " " + ans[1] + " " + ans[2]);
pr.flush();
}
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 17
|
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
|
1fa8cae46dde18be183d5a0307ce2507
|
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 input = new Scanner(System.in);
int t = input.nextInt();
HashMap<String, List<Integer>> map = new HashMap<>();
while (t > 0) {
map.clear();
int n = input.nextInt();
int[] points = new int[3];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < n; j++) {
String s = input.next();
List<Integer> list = new ArrayList<>();
if (map.get(s) == null) {
list.add(i);
map.put(s, list);
} else {
list = map.get(s);
list.add(i);
map.replace(s, list);
}
}
}
Collection<List<Integer>> scores = map.values();
for (List<Integer> col : scores) {
if (col.size() == 1) {
points[col.get(0)] += 3;
}
if (col.size() == 2) {
points[col.get(0)]++;
points[col.get(1)]++;
}
}
System.out.println(points[0] + " " + points[1] + " " + points[2]);
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 17
|
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
|
33deb857b43282ae3a2af5d86cce3030
|
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.math.*;
public class C1722 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int l=0;l<t;l++) {
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();
}
}
int[] A = new int[3];
Hashtable<String,Integer> ht = new Hashtable<String,Integer>();
for(int i=0;i<3;i++) {
for(int j=0;j<n;j++) {
if(ht.get(s[i][j])==null) {
ht.put(s[i][j],1);
}
else {
int temp = ht.get(s[i][j]);
ht.replace(s[i][j], temp+1);
}
}
}
for(int i=0;i<3;i++) {
for(int j=0;j<n;j++) {
if(ht.get(s[i][j])==1) {
A[i]+=3;
}
else if(ht.get(s[i][j])==2) {
A[i]+=1;
}
}
}
System.out.println(A[0]+" "+A[1]+" "+A[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 17
|
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
|
3564b81033d05a0ba7cef3afe4414bff
|
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.*;
public class main{
static Scanner sc = new Scanner(System.in);
static String[][] s = new String[4][1005];
public static void Solve(){
int n = sc.nextInt();
Map<String, Integer> M = new HashMap<String, Integer>();
for(int i = 1; i <= 3; ++ i){
for(int j = 1; j <= n; ++ j) {
s[i][j] = sc.next();
if(M.containsKey(s[i][j])){
int cnt = M.get(s[i][j]);
M.put(s[i][j], cnt + 1);
}
else {
M.put(s[i][j], 1);
}
}
}
for(int i = 1; i <= 3; ++ i){
int ans = 0;
for(int j = 1; j <= n; ++ j){
int cnt = M.get(s[i][j]);
if(cnt == 1) {
ans += 3;
}
else {
if(cnt < 3) {
ans += 1;
}
}
}
System.out.print(ans + " ");
}
System.out.println();
}
public static void main(String[] argv){
int t = sc.nextInt();
while(t -- > 0){
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 17
|
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
|
21f15d301c7870e74d6d39b540a70aa2
|
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.Map;
import java.util.StringTokenizer;
public class C {
public static void main(String[] args) {
FastScanner fs = new FastScanner();
int tt = 1;
tt = fs.nextInt();
while (tt-- > 0) {
int n = fs.nextInt();
int[] scores = new int[3];
String[][] a = new String[n][3];
Map<String, Integer> mp = new HashMap<>();
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < n; ++j) {
a[j][i] = fs.next();
mp.put(a[j][i], mp.getOrDefault(a[j][i], 0) + 1);
}
}
for (int i = 0; i < n; ++i) {
String[] cur = a[i];
for (int j = 0; j < 3; ++j) {
int count = mp.get(cur[j]);
if (count == 1) scores[j] += 3;
else if (count == 2) scores[j] += 1;
}
}
System.out.printf("%d %d %d \n", scores[0], scores[1], scores[2]);
}
}
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
}
|
Java
|
["3\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 17
|
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
|
fe3afe7cb7ee22e37052671d8d65bc3f
|
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 Solution {
public static Scanner scan = new Scanner(System.in);
public static void main(String[] args) {
int testCase = scan.nextInt();
for(int i = 0; i < testCase; i++) {
solve();
}
}
public static void solve() {
int n = scan.nextInt();
Map<String, Integer> map = new HashMap<String, Integer>();
String[][] a = new String[3][n];
for(int i = 0; i < 3; i++) {
for(int j = 0; j < n; j++) {
a[i][j] = scan.next();
if(map.containsKey(a[i][j])) {
map.put(a[i][j], map.get(a[i][j]) + 1);
}
else {
map.put(a[i][j], 1);
}
}
}
for(int i = 0; i < 3; i++) {
int point = 0;
for(int j = 0; j < n; j++) {
int check = map.get(a[i][j]);
if(check == 1) {
point += 3;
}
else if(check == 2) {
point += 1;
}
}
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 17
|
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
|
ccd5e8d9e1f898296bb08eae3bb14dc1
|
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 practice {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
while (t-->0){
int n = in.nextInt();
HashMap<Integer,List<String>> m1 = new HashMap<>();
HashMap<String,Integer> m2 = new HashMap<>();
for(int i = 1; i<=3;i++) {
for (int j = 0; j < n;j++) {
String s = in.next();
if (!m1.containsKey(i)) {
m1.put(i, new ArrayList<>());
m1.get(i).add(s);
} else m1.get(i).add(s);
if (!m2.containsKey(s)) m2.put(s, 1);
else m2.put(s, m2.get(s) + 1);
}
}
int []arr = new int[3];
for(int key : m1.keySet()){
for(String s : m1.get(key)){
if(m2.get(s)==1) arr[key-1]+=3;
if(m2.get(s)==2) arr[key-1]++;
}
}
for(int e : arr) System.out.print(e+" ");
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 17
|
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
|
d8adcf0d08ca11f07d708fea28b458c7
|
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.*;
import static java.lang.Math.*;
public class Main {
StreamTokenizer in;
BufferedReader inb;
PrintWriter out;
StringTokenizer tok;
Scanner sc;
boolean console = true;
final double eps = 1e-9;
final boolean DEBUG = false;
public static void main(String[] args) throws Exception {
new Main().run();
}
public void run() throws Exception {
if (!DEBUG) {
inb = new BufferedReader(console ? new InputStreamReader(System.in)
: new FileReader("bisector.in"));
in = new StreamTokenizer(inb);
out = new PrintWriter(console ? new OutputStreamWriter(System.out)
: new FileWriter("bisector.out"));
sc = new Scanner(System.in);
tok = new StringTokenizer("");
Locale.setDefault(Locale.US);
solve();
out.flush();
out.close();
} else {
long begMem = Runtime.getRuntime().totalMemory()
- Runtime.getRuntime().freeMemory();
long t1 = System.currentTimeMillis();
inb = new BufferedReader(new FileReader("input.txt"));
in = new StreamTokenizer(inb);
out = new PrintWriter(new FileWriter("output.txt"));
tok = new StringTokenizer("");
solve();
long endMem = Runtime.getRuntime().totalMemory()
- Runtime.getRuntime().freeMemory();
out.flush();
long t2 = System.currentTimeMillis();
System.out.println("Time:" + (t2 - t1));
System.out.println("Memory:" + (endMem - begMem));
System.out.println("Total memory: "
+ (Runtime.getRuntime().totalMemory() - Runtime
.getRuntime().freeMemory()));
}
}
public int nextInt() throws Exception {
in.nextToken();
return (int) in.nval;
}
public String next() throws Exception {
in.nextToken();
return in.sval;
}
public String nextLine() throws Exception {
return inb.readLine();
}
public String nextString() throws Exception {
while (!tok.hasMoreTokens())
tok = new StringTokenizer(inb.readLine());
return tok.nextToken();
}
public long nextLong() throws Exception {
return Long.parseLong(nextString());
}
public double nextDouble() throws Exception {
in.nextToken();
return in.nval;
}
public int gcd(int a, int b) {
if (a == 0 || b == 0)
return 1;
if (a < b) {
int c = b;
b = a;
a = c;
}
while (a % b != 0) {
a = a % b;
if (a < b) {
int c = b;
b = a;
a = c;
}
}
return b;
}
public BigInteger pow(BigInteger a, long n) {
if (n == 0)
return BigInteger.ONE;
BigInteger k = BigInteger.valueOf(n), b = BigInteger.ONE, c = a;
while (!k.equals(BigInteger.ZERO)) {
if (k.mod(BigInteger.valueOf(2)).equals(BigInteger.ZERO)) {
k = k.divide(BigInteger.valueOf(2));
c = c.multiply(c);
} else {
k = c.subtract(BigInteger.ONE);
b = b.multiply(c);
}
}
return b;
}
public int lcm(int a, int b) {
return a * b / gcd(a, b);
}
public int[] findPrimes(int x) {
boolean[] erat = new boolean[x - 1];
List<Integer> t = new ArrayList<Integer>();
int l = 0, j = 0;
for (int i = 2; i < x; i++) {
if (erat[i - 2])
continue;
t.add(i);
l++;
j = i * 2;
while (j < x) {
erat[j - 2] = true;
j += i;
}
}
int[] primes = new int[l];
Iterator<Integer> iterator = t.iterator();
for (int i = 0; iterator.hasNext(); i++) {
primes[i] = iterator.next().intValue();
}
return primes;
}
public int[] prefix(String s) {
int n = s.length();
int a[] = new int[n];
for (int i = 1; i < n; ++i) {
int j = a[i - 1];
while (j > 0 && s.charAt(i) != s.charAt(j)) {
j = a[j - 1];
}
if (s.charAt(i) == s.charAt(j))
++j;
a[i] = j;
}
return a;
}
long a[];
long sum;
public void gen_perm(int n, int pos, int mask) {
if (pos == n) {
return;
}
if (pos == n - 1) {
a[pos] = sum;
return;
}
for (int i = 1; i <= n; i++) {
if ((mask & (1 << i)) == 0) {
a[pos] = i;
sum -= i;
gen_perm(n, pos + 1, (mask | (1 << i)));
sum += i;
}
}
}
public void solve() throws Exception {
int n = nextInt();
for (int i=0; i<n; i++) {
int j = nextInt();
Set<String> s1 = new HashSet<>();
Set<String> s2 = new HashSet<>();
Set<String> s3 = new HashSet<>();
for (int k=0; k<j;k++) {
s1.add(nextString());
}
for (int k=0; k<j;k++) {
s2.add(nextString());
}
for (int k=0; k<j;k++) {
s3.add(nextString());
}
int count1 = 0;
for (String s: s1) {
if (!s2.contains(s) && !s3.contains(s)) {
count1+=3;
} else if (s2.contains(s) && s3.contains(s)) {
} else {
count1++;
}
}
int count2 = 0;
for (String s: s2) {
if (!s1.contains(s) && !s3.contains(s)) {
count2+=3;
} else if (s1.contains(s) && s3.contains(s)) {
} else {
count2++;
}
}
int count3 = 0;
for (String s: s3) {
if (!s2.contains(s) && !s1.contains(s)) {
count3+=3;
} else if (s2.contains(s) && s1.contains(s)) {
} else {
count3++;
}
}
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 17
|
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
|
6ec019ed54acba79a818d2c2a62fb93d
|
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_Word_Game {
final int mod = 1000000007;
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void swap(long[] a, int i, int j) {
long temp = a[i];
a[i] = a[j];
a[j] = temp;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
FastReader t = new FastReader();
PrintWriter o = new PrintWriter(System.out);
int test = t.nextInt();
while (test-- > 0) {
long min = Integer.MIN_VALUE, max = Integer.MAX_VALUE;
long ans =0 ;
int n = t.nextInt();
HashMap<String, int[]> map = new HashMap<>();
for (int k=0; k<3; k++) {
for (int i = 0; i < n; ++i) {
String s = t.next();
if (map.containsKey(s)) {
int[] p = map.get(s);
p[k] = 1;
map.put(s, p);
}
else {
int[] p = new int[3];
p[k] = 1;
map.put(s, p);
}
}
}
long a=0, b=0, c=0;
for (int[] p : map.values()) {
int sc = p[0]+p[1]+p[2];
if (sc == 1) {
a += p[0]*3;
b += p[1]*3;
c += p[2]*3;
}
if (sc == 2) {
a += p[0];
b += p[1];
c += p[2];
}
}
o.println(a+" "+b+" "+c);
// long m = t.nextLong();
// ArrayList<Integer> al = new ArrayList<>();
// HashSet<Integer> set = new HashSet<>();
// HashMap<Integer, Integer> map = new HashMap<>();
// TreeMap<Integer, Integer> map = new TreeMap<>();
// for (int i = 0; i < n; ++i) {
// for (int j = 0; j < n; ++j) {
// }
// }
}
o.flush();
o.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 17
|
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
|
8768185adf3d1e4f339d2af33d44c8e5
|
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 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static int tcs, n;
static StringTokenizer st;
static Map<String, Integer> map = new HashMap<>();
static int p1, p2, p3;
static String[][] table;
static void solved() throws IOException {
st = new StringTokenizer(br.readLine());
n = Integer.parseInt(st.nextToken());
map.clear();
p1 = p2 = p3 = 0;
String key;
table = new String[3][n];
for (int i = 0; i < 3; i++) {
st = new StringTokenizer(br.readLine());
for (int j = 0; j < n; j++) {
key = st.nextToken();
map.put(key, map.getOrDefault(key, 0) + 1);
table[i][j] = key;
}
}
p1 = getPoint(0);
p2 = getPoint(1);
p3 = getPoint(2);
System.out.println(p1 + " " + p2 + " " + p3);
}
static int getPoint(int i) {
String key;
int p;
int result = 0;
for (int j = 0; j < n; j++) {
key = table[i][j];
p = map.get(key);
if (p == 1) {
result += 3;
} else if (p == 2) {
result += 1;
}
}
return result;
}
public static void main(String[] args) throws IOException {
tcs = Integer.parseInt(br.readLine());
while (tcs-- > 0) {
solved();
}
}
}
|
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 17
|
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
|
ea1853e9333d479bb236c9c21d418943
|
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 sc = new Scanner(System.in);
int t = sc.nextInt();
for (int tt = 0; tt < t; tt++) {
int n = sc.nextInt();
String [][] s = new String[3][n];
Map<String,Integer> hm = new HashMap<>();
for (int i = 0; i < 3; i++) {
for (int j = 0; j < n; j++) {
s[i][j] = sc.next();
hm.put(s[i][j],hm.getOrDefault(s[i][j],0) + 1);
}
}
for (int i = 0; i < 3; i++) {
int score = 0;
for (int j = 0; j < n; j++) {
if (hm.get(s[i][j]) == 1) score += 3;
else if (hm.get(s[i][j]) == 2) score++;
}
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 17
|
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
|
42d02f3cec40fa7f82825a72fdd32cfb
|
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();
while(t > 0){
HashMap<String, Integer> map = new HashMap<>();
int n = sc.nextInt();
int p1 = n*3, p2 = n*3, p3 = n*3;
sc.nextLine();
for(int i = 0; i < n; i++){
String s = sc.next();
map.put(s, 1);
}
for(int i = 0; i < n; i++){
String s = sc.next();
if(!map.containsKey(s)){
map.put(s, 2);
}
else{
map.put(s, map.get(s) + 2);
}
}
for(int i = 0; i < n; i++){
String s = sc.next();
if(!map.containsKey(s)){
map.put(s, 0);
}
else{
map.put(s, map.get(s) + 3);
}
}
for(Map.Entry<String, Integer> i : map.entrySet()){
if(i.getValue() == 6){
p1 -= 3;
p2 -= 3;
p3 -= 3;
}
else if(i.getValue() == 3){
p1 -= 2;
p2 -= 2;
}
else if(i.getValue() == 4){
p1 -= 2;
p3 -= 2;
}
else if(i.getValue() == 5){
p2 -= 2;
p3 -= 2;
}
}
System.out.println(p1 + " " + p2 + " " + p3);
t --;
}
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 17
|
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
|
af25dcc393687e420dbc03a31501a769
|
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.util.Map.Entry;
import java.io.*;
import java.lang.*;
public class main1{
FastScanner in;
PrintWriter out;
public static void main(String[] arg) {
new main1().run();
}
//////////////SOLVE QUESTIONS HERE/////////////
public class ji{
HashMap<String,Integer> mp=new HashMap<>();
void add(String s)
{
mp.put(s,1);
}
void print()
{
mp.entrySet().forEach(entry -> {
System.out.println(entry.getKey() + " " + entry.getValue());
});
}
}
public void solve() throws IOException {
int testcase=1;
testcase=in.nextInt();
while(testcase-- > 0)
{
ji[] arr=new ji[3];
ArrayList<String> s1=new ArrayList<>();
ArrayList<String> s2=new ArrayList<>();
ArrayList<String> s3=new ArrayList<>();
HashSet<String> s=new HashSet<>();
int n=in.nextInt();
for(int j=0;j<3;j++)
{
arr[j]=new ji();
for(int i=0;i<n;i++)
{
var temp=in.next();
s.add(temp);
if(j==0)
s1.add(temp);
else if(j==1)
s2.add(temp);
else
s3.add(temp);
arr[j].add(temp);
}
}
int a=0,b=0,c=0;
for(String temp:s)
{
if(arr[0].mp.get(temp)!=null && arr[1].mp.get(temp)!=null && arr[2].mp.get(temp)!=null )
{
continue;
}
else if(arr[0].mp.get(temp)!=null && arr[1].mp.get(temp)!=null)
{
a++;
b++;
}
else if(arr[0].mp.get(temp)!=null && arr[2].mp.get(temp)!=null)
{
a++;
c++;
}
else if(arr[1].mp.get(temp)!=null && arr[2].mp.get(temp)!=null)
{
b++;
c++;
}
else if(arr[0].mp.get(temp)!=null)
{
a+=3;
}
else if(arr[1].mp.get(temp)!=null)
{
b+=3;
}
else if(arr[2].mp.get(temp)!=null)
{
c+=3;
}
}
out.println(a+" "+b+" "+c);
}
}
public void run() {
try {
in = new FastScanner(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(Reader f) {
br = new BufferedReader(f);
}
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;
}
}
}
|
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 17
|
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
|
1eb42e215bc3c0ed4561f4ba7bf3ba14
|
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 {
private final static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
int testCases = sc.nextInt();
for (int testCase = 0; testCase < testCases; testCase++) {
Set<String> person1 = new HashSet<>();
Set<String> person2 = new HashSet<>();
Set<String> person3 = new HashSet<>();
int n = sc.nextInt();
for (int word = 0; word < n; word++) {
person1.add(sc.next());
}
for (int word = 0; word < n; word++) {
person2.add(sc.next());
}
for (int word = 0; word < n; word++) {
person3.add(sc.next());
}
int person1Score = 0;
int person2Score = 0;
int person3Score = 0;
person1Score = getPersonScore(person1, person2, person3, person1Score);
person2Score = getPersonScore(person2, person1, person3, person2Score);
person3Score = getPersonScore(person3, person1, person2, person3Score);
System.out.println(person1Score + " " + person2Score + " " + person3Score);
}
}
private static int getPersonScore(Set<String> person1, Set<String> person2, Set<String> person3, int personScore) {
for (String word:
person1) {
if (person2.contains(word) && !person3.contains(word)) {
personScore++;
}
if (!person2.contains(word) && person3.contains(word)) {
personScore++;
}
if (!person2.contains(word) && !person3.contains(word)) {
personScore += 3;
}
}
return personScore;
}
}
|
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 17
|
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
|
55453a6d07cea7a0a6e8d6df4ad049e2
|
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 {
static Scanner sc = new Scanner(System.in);
static void input(String arr[], Map<String, Integer> mp) {
for (int i = 0; i < arr.length; i++) {
arr[i] = sc.next();
mp.put(arr[i], mp.getOrDefault(arr[i], 0) + 1);
}
}
static int increment(String arr[], Map<String, Integer> mp) {
int val = 0;
for (String s : arr) {
if (mp.get(s) == 2)
val++;
else if (mp.get(s) == 1)
val += 3;
}
return val;
}
public static void main(String args[]) {
int t = sc.nextInt();
while (t-- != 0) {
int n = sc.nextInt();
String s1[] = new String[n], s2[] = new String[n], s3[] = new String[n];
Map<String, Integer> mp = new HashMap<>();
input(s1, mp);
input(s2, mp);
input(s3, mp);
int val1 = increment(s1, mp), val2 = increment(s2, mp), val3 = increment(s3, mp);
System.out.println(val1 + " " + val2 + " " + val3);
}
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 17
|
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
|
262ddd7c20b44682acbf1c15ad0a0283
|
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.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
public class C {
final private static FastReader reader = new FastReader();
final private static PrintWriter writer = new PrintWriter(System.out);
public static void main(String[] args) {
//solveTestCase();
runTestCases(false);
writer.flush();
}
public static void solveTestCase() {
int n = reader.nextInt();
String[][] words = new String[3][n];
Map<String, Integer> counter = new HashMap<>();
for(int i = 0; i < 3; i++) {
for(int j = 0; j < n; j++) {
words[i][j] = reader.next();
if(counter.containsKey(words[i][j])) {
counter.put(words[i][j], counter.get(words[i][j]) + 1);
} else {
counter.put(words[i][j], 1);
}
}
}
for (int i = 0; i < 3; i++) {
int total = 0;
for (int j = 0; j < n; j++) {
switch (counter.get(words[i][j])) {
case 1 -> total += 3;
case 2 -> total += 1;
}
}
writer.print(total);
writer.print(' ');
}
writer.println();
}
private static void runTestCases(boolean forGoogle) {
int T = reader.nextInt();
final String cases = "Case #", colon = ": ";
for (int _t = 0; _t < T; _t++){
if(forGoogle) {
writer.print(cases);
writer.print(_t);
writer.print(colon);
}
solveTestCase();
}
}
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 {
if(st.hasMoreTokens()){
str = st.nextToken("\n");
} else {
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 17
|
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
|
776f30f3bbbfa0c080c42f5b30646967
|
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.PrintWriter;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
public class C_Word_Game {
public static void main(String[] args) throws IOException {
InputStream inputStream = System.in;
InputReader sc = new InputReader(inputStream);
int t = sc.nextInt();
while (--t >= 0) {
int size = sc.nextInt();
String[][] al = new String[3][size];
for (int i = 0; i < 3; i++) {
// for(int j = 0; j < size; j++) {
String g = sc.nextLine();
String[] split = g.split(" ");
for(int j = 0; j < size; j++) {
al[i][j] = split[j];
}
// }
}
Map<String, List<Integer>> hm = new HashMap<>();
for(int i = 0 ; i < 3 ; i++){
for(int j = 0;j < size ; j++){
String str = al[i][j];
if(hm.containsKey(str)){
hm.get(str).add(i);
}else{
List<Integer> temp= new ArrayList<>();
temp.add(i);
hm.put(str,temp);
}
}
}
int[] points = new int[3];
for(Map.Entry<String, List<Integer>> e : hm.entrySet()){
List<Integer> com = e.getValue();
if(com.size() ==3){
continue;
}else if(com.size() == 2){
points[com.get(0)] += 1;
points[com.get(1)] += 1;
}else{
points[com.get(0)] += 3;
}
}
System.out.println(points[0]+" "+points[1]+" "+points[2]);
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public char nextChar() {
return next().charAt(0);
}
public String nextLine() throws IOException {
return reader.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 17
|
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
|
c2c7c4b674a607314db89d987b67f004
|
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 WordGame {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int numTestCase = sc.nextInt();
int arr[][] = new int[numTestCase][3];
for (int i = 0; i < numTestCase; i++) {
int numWords = sc.nextInt();
String p1[] = new String[numWords];
String p2[] = new String[numWords];
String p3[] = new String[numWords];
int a = 0, b = 0, c = 0;
for (int j = 0; j < numWords; j++) {
p1[j] = sc.next();
}
for (int j = 0; j < numWords; j++) {
p2[j] = sc.next();
}
for (int j = 0; j < numWords; j++) {
p3[j] = sc.next();
}
Map<String, Integer> m = new HashMap<>();
for (int j = 0; j < numWords; j++) {
if (m.containsKey(p1[j])) {
m.put(p1[j], m.get(p1[j]) + 1);
} else {
m.put(p1[j], 1);
}
if (m.containsKey(p2[j])) {
m.put(p2[j], m.get(p2[j]) + 1);
} else {
m.put(p2[j], 1);
}
if (m.containsKey(p3[j])) {
m.put(p3[j], m.get(p3[j]) + 1);
} else {
m.put(p3[j], 1);
}
}
for (int j = 0; j < numWords; j++) {
if (m.get(p1[j]) == 2) {
a++;
}
if (m.get(p1[j]) == 1) {
a = a + 3;
}
if (m.get(p2[j]) == 2) {
b++;
}
if (m.get(p2[j]) == 1) {
b = b + 3;
}
if (m.get(p3[j]) == 2) {
c++;
}
if (m.get(p3[j]) == 1) {
c = c + 3;
}
}
arr[i][0] = a;
arr[i][1] = b;
arr[i][2] = c;
}
for (int i = 0; i < numTestCase; i++) {
for (int j = 0; j < 3; j++) {
System.out.print(arr[i][j] + " ");
}
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 17
|
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
|
e33a679a988a8f22099c7d64faeb3971
|
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 {
private void solve(InputReader in, PrintWriter pw) {
int t = in.nextInt();
outer:while (t-- > 0) {
int n = in.nextInt();
String[][] s = new String[3][n];
HashMap<String, Integer> map = new HashMap<>();
for (int i = 0; i < 3; i++) {
for (int j = 0; j < n; j++) {
s[i][j] = in.next();
map.put(s[i][j], map.getOrDefault(s[i][j], 0) + 1);
}
}
int[] ans = new int[3];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < n; j++) {
int cnt = map.get(s[i][j]);
if (cnt == 1) {
ans[i] += 3;
} else if (cnt == 2) {
ans[i] += 1;
}
}
}
for (int x : ans) {
pw.print(x + " ");
}
pw.println();
}
pw.close();
}
public static void main(String[] args) {
new Main().solve(new InputReader(System.in), new PrintWriter(System.out));
}
}
class InputReader {
private final BufferedReader reader;
private StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public String nextLine() {
String str;
try {
str = reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
return str;
}
public boolean hasNext() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
String nextLine;
try {
nextLine = reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
if (nextLine == null) {
return false;
}
tokenizer = new StringTokenizer(nextLine);
}
return true;
}
public int nextInt() {
return Integer.parseInt(next());
}
public 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 17
|
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
|
6f59408a4ffe01b6812d22d86e0b8906
|
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 static java.util.Map.entry;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.Collectors;
public class Main {
static final Map<Integer, Integer> COUNT_TO_POINT =
Map.ofEntries(entry(1, 3), entry(2, 1), entry(3, 0));
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int tc = 0; tc < t; ++tc) {
int n = sc.nextInt();
String[][] words = new String[3][n];
for (int i = 0; i < words.length; ++i) {
for (int j = 0; j < words[i].length; ++j) {
words[i][j] = sc.next();
}
}
System.out.println(solve(words));
}
sc.close();
}
static String solve(String[][] words) {
Map<String, Integer> wordToCount = new HashMap<>();
for (int i = 0; i < words.length; ++i) {
for (int j = 0; j < words[i].length; ++j) {
wordToCount.put(words[i][j], wordToCount.getOrDefault(words[i][j], 0) + 1);
}
}
return Arrays.stream(words)
.mapToInt(
p -> Arrays.stream(p).mapToInt(word -> COUNT_TO_POINT.get(wordToCount.get(word))).sum())
.mapToObj(String::valueOf)
.collect(Collectors.joining(" "));
}
}
|
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 17
|
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
|
0ff9120a31d9bc91cb08dffc2e608798
|
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.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
public class D {
public static void main(String[] args) {
FastReader scanner = new FastReader();
int numberOfCases = scanner.nextInt();
while (numberOfCases -- > 0) {
int numberOfCul= scanner.nextInt();
String[][] arr = new String[3][numberOfCul];
Map<String, Integer> map = new HashMap<>();
int c = 1;
int[] res = new int[3];
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
arr[i][j] = scanner.next();
if (map.containsKey(arr[i][j])) {
map.replace(arr[i][j], map.get(arr[i][j]) + 1);
continue;
}
map.put(arr[i][j], c);
}
}
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
if (map.get(arr[i][j]) == 1)
res[i] += 3;
else if (map.get(arr[i][j]) == 2)
res[i] += 1;
}
}
for (var r : res)
System.out.print(r + " ");
System.out.println();
}
}
}
class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public FastReader(String file) throws FileNotFoundException {
br = new BufferedReader(new FileReader(file));
}
void close() throws IOException {
br.close();
}
String next() {
while (st == null || !st.hasMoreElements()) { // null = The First time
//!st.hasNoElements = After the st finish the first time
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
long nextLong() {
return Long.parseLong(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
boolean hasNext() {
String s = null;
try {
s = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
if (s == null) return false;
st = new StringTokenizer(s);
return true;
}
}
|
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 17
|
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
|
5c69d0293e3c1d9e8ea6eb303dc15df0
|
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.HashMap;
import java.util.Map;
import java.util.Scanner;
public class MainCode {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
while(n-- > 0) {
int k = sc.nextInt();
sc.nextLine();
Map<String, Integer> map = new HashMap<>();
String[][] arr = new String[3][k];
for(int i=0; i < 3; i++) {
for(int j=0; j < k; j++) {
String str = sc.next();
if(map.containsKey(str)) map.put(str, map.get(str)+1);
else map.put(str, 1);
arr[i][j] = str;
}
}
int[] players = new int[3];
for(int j=0; j < 3; j++) {
for(int i=0; i < k; i++) {
if(map.containsKey(arr[0][i])) {
if(map.get(arr[j][i]) == 3) {
players[j] += 0;
} else if(map.get(arr[j][i]) == 2) {
players[j] += 1;
} else {
players[j] += 3;
}
}
}
}
System.out.println(players[0] + " " + players[1] + " " + players[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 17
|
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
|
6944aad183cb9db06c1ea3c1e906dbd7
|
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 in=new Scanner(System.in);
int T=in.nextInt();
while(T-->0)
{
int n=in.nextInt();
HashSet<String> h1=new HashSet<>();
HashSet<String> h2=new HashSet<>();
HashSet<String> h3=new HashSet<>();
for(int i=0;i<n;i++)
h1.add(in.next());
for(int i=0;i<n;i++)
h2.add(in.next());
for(int i=0;i<n;i++)
h3.add(in.next());
int ans1=0,ans2=0,ans3=0;
for(String k:h1)
{
if(h2.contains(k)&&h3.contains(k))
ans1+=0;
else if(h2.contains(k)||h3.contains(k))
ans1+=1;
else
ans1+=3;
}
for(String k:h2)
{
if(h1.contains(k)&&h3.contains(k))
ans2+=0;
else if(h1.contains(k)||h3.contains(k))
ans2+=1;
else
ans2+=3;
}
for(String k:h3)
{
if(h2.contains(k)&&h1.contains(k))
ans3+=0;
else if(h2.contains(k)||h1.contains(k))
ans3+=1;
else
ans3+=3;
}
System.out.println(ans1+" "+ans2+" "+ans3);
}
}
}
|
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 17
|
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
|
00643dc021b4338355c49dfa7eaf6408
|
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 Exception {
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
// sc.nextInt();
// sc.Integer.parseInt()nextLine();
int T = Integer.parseInt(input.readLine());
while(T-->0){
int k = Integer.parseInt(input.readLine());
HashSet<String> map1 = new HashSet<>();
HashSet<String> map2 = new HashSet<>();
HashSet<String> map3 = new HashSet<>();
String[] p1 = input.readLine().split(" ");
String[] p2 = input.readLine().split(" ");
String[] p3 = input.readLine().split(" ");
for(int z =0;z<k;z++){
map1.add(p1[z]);
map2.add(p2[z]);
map3.add(p3[z]);
}
// System.out.println(map1);
int val1=0,val2=0,val3=0;
for(String h:map1){
if(map2.contains(h) && map3.contains(h)){
val1+=0;
}
else if(!map2.contains(h) && !map3.contains(h)){
val1+=3;
}
else val1+=1;
}
for(String h:map2){
if(map1.contains(h) && map3.contains(h)){
val2+=0;
}
else if(!map1.contains(h) && !map3.contains(h)){
val2+=3;
}
else val2+=1;
}
for(String h:map3){
if(map2.contains(h) && map1.contains(h)){
val3+=0;
}
else if(!map2.contains(h) && !map1.contains(h)){
val3+=3;
}
else val3+=1;
}
System.out.println(val1 + " " + val2 + " " + val3);
}
}
}
|
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 17
|
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
|
cce9a09f41df8e59b0f7f7af7ed83050
|
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 wordGame {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
while(T-->0)
{
int n = sc.nextInt();
String[][] s1 = new String[3][n];
int[] ar = new int[3];
Map<String,Integer> hm = new HashMap<>();
for(int i=0;i<3;i++) {
for (int j = 0; j < n; j++) {
s1[i][j] = sc.next();
hm.put(s1[i][j], hm.getOrDefault(s1[i][j], 0) + 1);
}
}
for(int i=0;i<3;i++)
{
int count=0;
for(int j=0;j<n;j++)
{
if(hm.get(s1[i][j])==1)
{
count=count+3;
}
else if(hm.get(s1[i][j])==2)
{
count=count+1;
}
}
ar[i] =count;
}
for (int i=0;i<3;i++)
{
System.out.print(ar[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 17
|
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
|
11b5f9c633bab8f137b5fca925904457
|
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.*;
public class Problem_17 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int test = sc.nextInt();
while (test-- > 0) {
int n = sc.nextInt();
Set<String> set1 = new HashSet<>();
Set<String> set2 = new HashSet<>();
Set<String> set3 = new HashSet<>();
String[] can1 = new String[n];
String[] can2 = new String[n];
String[] can3 = new String[n];
int point1 = 0;
int point2 = 0;
int point3 = 0;
for(int i =0;i<n;i++) {
String s = sc.next();
can1[i] = s;
set1.add(s);
}
for(int i =0;i<n;i++) {
String s = sc.next();
can2[i] = s;
set2.add(s);
}
for(int i =0;i<n;i++) {
String s = sc.next();
can3[i] = s;
set3.add(s);
}
for(int i =0;i<can3.length;i++) {
if(!set1.contains(can3[i]) && !set2.contains(can3[i])) {
point3 += 3;
}
if(set1.contains(can3[i]) && !set2.contains(can3[i])) {
point3 += 1;
// point1 += 1;
}
if(!set1.contains(can3[i]) && set2.contains(can3[i])) {
point3 += 1;
// point2 += 1;
}
}
for(int i =0;i<can2.length;i++) {
if(!set1.contains(can2[i]) && !set3.contains(can2[i])) {
point2 += 3;
}
if(set1.contains(can2[i]) && !set3.contains(can2[i])) {
point2 += 1;
// point1 += 1;
}
if(!set1.contains(can2[i]) && set3.contains(can2[i])) {
point2 += 1;
// point3 += 1;
}
}
for(int i =0;i<can1.length;i++) {
if(!set2.contains(can1[i]) && !set3.contains(can1[i])) {
point1 += 3;
}
if(set2.contains(can1[i]) && !set3.contains(can1[i])) {
point1 += 1;
// point2 += 1;
}
if(!set2.contains(can1[i]) && set3.contains(can1[i])) {
// point3 += 1;
point1 += 1;
}
}
System.out.println(point1 + " " + point2 + " " + point3);
}
}
}
|
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 17
|
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
|
6eca6aa451db6fff867d65f7a30d066c
|
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 Exception{
// Your code goes here
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
while(t-->0){
HashSet<String> set1 = new HashSet<>();
HashSet<String> set2 = new HashSet<>();
HashSet<String> set3 = new HashSet<>();
int n = Integer.parseInt(br.readLine());
String[] s1 = br.readLine().split(" ");
String[] s2 = br.readLine().split(" ");
String[] s3 = br.readLine().split(" ");
for(int i=0;i<n;i++){
set1.add(s1[i]);
set2.add(s2[i]);
set3.add(s3[i]);
}
int count1 = 0,count2 =0,count3 =0;
for(String s : set1){
// if(!set2.contains(s) && !set3.contains(s)){
// count1 +=3;
// }
if(set2.contains(s) && set3.contains(s)){
count1 +=0;
}
else if(!set2.contains(s) && !set3.contains(s)){
count1 +=3;
}
else{
count1 +=1;
}
}
for(String s : set2){
if(set1.contains(s) && set3.contains(s)){
count2 +=0;
}
else if(!set1.contains(s) && !set3.contains(s)){
count2 +=3;
}
else{
count2 +=1;
}
}
for(String s : set3){
if(set2.contains(s) && set1.contains(s)){
count3 +=0;
}
else if(!set2.contains(s) && !set1.contains(s)){
count3 +=3;
}
else {
count3 +=1;
}
}
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 17
|
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
|
04fae7b8fc88159ac2e2bf26170f389a
|
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.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
public class Solution {
public static void main(String[] args) throws IOException {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
int count=1;
String s[]=new String[n];
String s2[]=new String[n];
String s3[]=new String[n];
Map<String ,Integer>map=new HashMap<>();
for(int i=0; i<n; i++)
{
s[i]=sc.next();
if(!map.containsKey(s[i]))
{
map.put(s[i],count);
}
else
{
map.put(s[i],map.get(s[i])+1);
}
}
for(int i=0; i<n; i++)
{
s2[i]=sc.next();
if(!map.containsKey(s2[i]))
{
map.put(s2[i],count);
}
else
{
map.put(s2[i],map.get(s2[i])+1);
}
}
for(int i=0; i<n; i++)
{
s3[i]=sc.next();
if(!map.containsKey(s3[i]))
{
map.put(s3[i],count);
}
else
{
map.put(s3[i],map.get(s3[i])+1);
}
}
int sum=0;
for(int i=0; i<n; i++)
{
if(map.get(s[i])==1)
{
sum=sum+3;
}
else if(map.get(s[i])==2)
{
sum=sum+1;
}
}
System.out.print(sum+" ");
sum=0;
for(int i=0; i<n; i++)
{
if(map.get(s2[i])==1)
{
sum=sum+3;
}
else if(map.get(s2[i])==2)
{
sum=sum+1;
}
}
System.out.print(sum+" ");
sum=0;
for(int i=0; i<n; i++)
{
if(map.get(s3[i])==1)
{
sum=sum+3;
}
else if(map.get(s3[i])==2)
{
sum=sum+1;
}
}
System.out.println(sum);
}
}
}
|
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 17
|
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
|
cca06d6356d4cbbd1650f5ec857bda69
|
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 B {
static InputReader in;
static OutputWriter out;
public static void main(String[] args) throws FileNotFoundException {
in = new InputReader(System.in);
out = new OutputWriter(System.out);
if (System.getProperty("ONLINE_JUDGE") == null) {
try {
in = new InputReader(new FileInputStream("input.txt"));
out = new OutputWriter(new FileOutputStream("output.txt"));
} catch (Exception e) {
}
}
int t = in.readInt();
for (int o = 1; o <= t; o++) {
int n = in.readInt();
String[] a = IOUtils.readStringArray(in, n);
String[] b = IOUtils.readStringArray(in, n);
String[] c = IOUtils.readStringArray(in, n);
solve(n, a, b, c);
}
out.flush();
out.close();
}
public static void solve(int n, String[] a, String[] b, String[] c) {
HashMap<String, Integer> map = new HashMap<>();
for (int i = 0; i < n; i++) {
if (map.containsKey(a[i])) {
map.put(a[i], map.get(a[i]) + 1);
} else {
map.put(a[i], 1);
}
if (map.containsKey(b[i])) {
map.put(b[i], map.get(b[i]) + 1);
} else {
map.put(b[i], 1);
}
if (map.containsKey(c[i])) {
map.put(c[i], map.get(c[i]) + 1);
} else {
map.put(c[i], 1);
}
}
int x = 0, y = 0, z = 0;
for (int i = 0; i < n; i++) {
x += 3 - (map.get(a[i]) == 1 ? 0 : map.get(a[i]));
y += 3 - (map.get(b[i]) == 1 ? 0 : map.get(b[i]));
z += 3 - (map.get(c[i]) == 1 ? 0 : map.get(c[i]));
}
out.printLine(x + " " + y + " " + z);
}
}
class CPHandler{
public static boolean binarySearch(int[] nums, int target) {
int low = 0;
int high = nums.length - 1;
while (low <= high) {
int mid = low + (high - low) / 2;
if (nums[mid] == target) {
return true;
} else if (target < nums[mid]) {
high = mid - 1;
} else {
low = mid + 1;
}
}
return false;
}
public static int gcd(int a, int b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
}
class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int readInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public long readLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public String readString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next() {
return readString();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
public void printLine(Object... objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
public void flush() {
writer.flush();
}
}
class IOUtils {
public static int[] readIntArray(InputReader in, int size) {
int[] array = new int[size];
for (int i = 0; i < size; i++)
array[i] = in.readInt();
return array;
}
public static long[] readLongArray(InputReader in, int size) {
long[] array = new long[size];
for (int i = 0; i < size; i++)
array[i] = in.readLong();
return array;
}
public static String[] readStringArray(InputReader in, int size) {
String[] array = new String[size];
for (int i = 0; i < size; i++)
array[i] = in.readString();
return array;
}
}
|
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 17
|
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
|
3662f4fb4b48b5dd45fb38376d464865
|
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 String str="Timur";
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int h=0;h<t;h++) {
int n = sc.nextInt();
String a []=new String[n];
String b []=new String[n];
String c []=new String[n];
HashMap<String,Integer> uwu=new HashMap<>();
for(int i=0;i<n;i++)
{
String val=sc.next();
a[i]=val;
uwu.put(val,uwu.getOrDefault(val,0)+1);
}
for(int i=0;i<n;i++)
{
String val=sc.next();
b[i]=val;
uwu.put(val,uwu.getOrDefault(val,0)+1);
}
for(int i=0;i<n;i++)
{
String val=sc.next();
c[i]=val;
uwu.put(val,uwu.getOrDefault(val,0)+1);
}
int sa=0,sb=0,scc=0;
for(int i=0;i<n;i++)
{
if(uwu.get(a[i])==1)
sa+=3;
else
if(uwu.get(a[i])==2)
sa++;
}
for(int i=0;i<n;i++)
{
if(uwu.get(b[i])==1)
sb+=3;
else
if(uwu.get(b[i])==2)
sb++;
}
for(int i=0;i<n;i++)
{
if(uwu.get(c[i])==1)
scc+=3;
else
if(uwu.get(c[i])==2)
scc++;
}
System.out.println(sa+" "+sb+" "+scc);
}
}
}
|
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 17
|
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
|
a488041396d23242c76c937b26248d08
|
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 n = sc.nextInt();
for(int m = 1; m <= n; m++){
int l = sc.nextInt();
int[] ans = new int[3];
String ar1[] = new String[l];
HashMap<String,String> map1 = new HashMap<>();
String ar2[] = new String[l];
HashMap<String,String> map2 = new HashMap<>();
String ar3[] = new String[l];
HashMap<String,String> map3 = new HashMap<>();
for(int j = 0; j < l; j++){
ar1[j] = sc.next();
map1.put(ar1[j],"");
}
for(int j = 0; j < l; j++){
ar2[j] = sc.next();
map2.put(ar2[j],"");
}
for(int j = 0; j < l; j++){
ar3[j] = sc.next();
map3.put(ar3[j],"");
}
for(int i = 0; i < ar1.length; i++){
String k = ar1[i];
if(map2.containsKey(k)){
if(!map3.containsKey(k)){
ans[0] += 1;
}
}else if(map3.containsKey(k)){
ans[0] += 1;
}else{
ans[0] += 3;
}
}
for(int i = 0; i < ar2.length; i++){
String k = ar2[i];
if(map1.containsKey(k)){
if(!map3.containsKey(k)){
ans[1] += 1;
}
}else if(map3.containsKey(k)){
ans[1] += 1;
}else{
ans[1] += 3;
}
}
for(int i = 0; i < ar3.length; i++){
String k = ar3[i];
if(map1.containsKey(k)){
if(!map2.containsKey(k)){
ans[2] += 1;
}
}else if(map2.containsKey(k)){
ans[2] += 1;
}else{
ans[2] += 3;
}
}
System.out.println(ans[0] + " " + ans[1] + " " + ans[2]);
}
// String b = sc.next();
// boolean breaked = false;
// for(int j = 0; j < l; j++){
// if(a.charAt(j) == 'R'){
// if(b.charAt(j) != 'R'){
// System.out.println("NO");
// breaked = true;
// break;
// }
// }else if(b.charAt(j) == 'R'){
// System.out.println("NO");
// breaked = true;
// break;
// }
// }
// if(!breaked) System.out.println("YES");
// if(l != 5){
// System.out.println("NO");
// continue;
// }
// int[] arr = new int[256];
// for(int k = 0; k < s.length(); k++){
// arr[s.charAt(k)] = 1;
// }
// boolean valid = true;
// String str = "Timur";
// for(int k = 0; k < str.length(); k++){
// if(arr[str.charAt(k)] != 1){
// valid = false;
// break;
// }
// }
// if(valid) System.out.println("YES");
// else System.out.println("No");
// }
}
}
|
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 17
|
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
|
6f960804c714ed2af68e08a1033dfc09
|
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.Map;
import java.util.Scanner;
public class problemC {
public static void main(String[] args) {
Scanner sh = new Scanner(System.in);
int t = sh.nextInt();
while(t>0){
int n = sh.nextInt();
sh.nextLine();
Map<String,Integer> m = new HashMap<>();
Map<String,Integer> a = new HashMap<>();
Map<String,Integer> b = new HashMap<>();
Map<String,Integer> c = new HashMap<>();
for(int i = 1; i<=3*n; i++){
String s = sh.next();
if(i<n+1){
a.put(s,1);
}else if(i>n && i<2*n + 1){
b.put(s,1);
}else{
c.put(s,1);
}
if(m.containsKey(s)){
m.replace(s,m.get(s) +1);
}else{
m.put(s,1);
}
} int p1 = 0; int p2 = 0; int p3 = 0;
for(String x : a.keySet()){
if(m.get(x) == 1){
p1 = p1+3;
}else if(m.get(x) == 2){
p1++;
}
}
for(String x : b.keySet()){
if(m.get(x) == 1){
p2 = p2+3;
}else if(m.get(x) == 2){
p2++;
}
}
for(String x : c.keySet()){
if(m.get(x) == 1){
p3 = p3+3;
}else if(m.get(x) == 2){
p3++;
}
}
System.out.println(p1 + " " + p2 + " " + p3);
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 17
|
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
|
c7f20d13b344cb815a5b3314cf8aabbf
|
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();
while(t>0){
int n= sc.nextInt();
int p=0,q=0,r=0;
String l[] = new String[3*n];
Map<String,Integer> m = new HashMap<String,Integer>();
for( int i=0;i<3*n;i++){
String s= sc.next();
l[i]=s;
m.merge(s,1,Integer::sum);
}
for(int i=0;i<n;i++){
if (m.get(l[i])==1)
p+=3;
else if(m.get(l[i])==2)
p+=1;
else
p+=0;
}
for(int i=n;i<2*n;i++){
if (m.get(l[i])==1)
q+=3;
else if(m.get(l[i])==2)
q+=1;
else
q+=0;
}
for(int i=2*n;i<3*n;i++){
if (m.get(l[i])==1)
r+=3;
else if(m.get(l[i])==2)
r+=1;
else
r+=0;
}
System.out.println(p+" "+ q+" "+r);
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 17
|
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
|
7d631eb42fa55fa6dcf84e8c413befc9
|
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.Scanner;
public class Codeforces2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int tc = sc.nextInt();
while (tc-- > 0) {
int n = sc.nextInt();
ArrayList<String> first = new ArrayList<>();
ArrayList<String> second = new ArrayList<>();
ArrayList<String> third = new ArrayList<>();
HashMap<String, Integer> freq = new HashMap<>();
for (int j = 0; j < n; j++) {
String s = sc.next();
first.add(s);
freq.put(s, freq.getOrDefault(s, 0) + 1);
}
for (int j = 0; j < n; j++) {
String s = sc.next();
second.add(s);
freq.put(s, freq.getOrDefault(s, 0) + 1);
}
for (int j = 0; j < n; j++) {
String s = sc.next();
third.add(s);
freq.put(s, freq.getOrDefault(s, 0) + 1);
}
int m1 = 0, m2 = 0, m3 = 0;
for (String s : first) {
if (freq.containsKey(s)) {
if (freq.get(s) == 2) m1 += 1;
else if (freq.get(s) == 1) m1 += 3;
}
}
for (String s : second) {
if (freq.containsKey(s)) {
if (freq.get(s) == 2) m2 += 1;
else if (freq.get(s) == 1) m2 += 3;
}
}
for (String s : third) {
if (freq.containsKey(s)) {
if (freq.get(s) == 2) m3 += 1;
else if (freq.get(s) == 1) m3 += 3;
}
}
System.out.println(m1 + " " + m2 + " " + m3);
}
}
}
|
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 17
|
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
|
a460e599c3e43b78e3b1c5e2d7cb6e29
|
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.util.Map.Entry;
import java.io.*;
import java.lang.*;
public class main1{
FastScanner in;
PrintWriter out;
public static void main(String[] arg) {
new main1().run();
}
//////////////SOLVE QUESTIONS HERE/////////////
public class ji{
HashMap<String,Integer> mp=new HashMap<>();
void add(String s)
{
mp.put(s,1);
}
void print()
{
mp.entrySet().forEach(entry -> {
System.out.println(entry.getKey() + " " + entry.getValue());
});
}
}
public void solve() throws IOException {
int testcase=1;
testcase=in.nextInt();
while(testcase-- > 0)
{
ji[] arr=new ji[3];
ArrayList<String> s1=new ArrayList<>();
ArrayList<String> s2=new ArrayList<>();
ArrayList<String> s3=new ArrayList<>();
HashSet<String> s=new HashSet<>();
int n=in.nextInt();
for(int j=0;j<3;j++)
{
arr[j]=new ji();
for(int i=0;i<n;i++)
{
var temp=in.next();
s.add(temp);
if(j==0)
s1.add(temp);
else if(j==1)
s2.add(temp);
else
s3.add(temp);
arr[j].add(temp);
}
}
int a=0,b=0,c=0;
for(String temp:s)
{
if(arr[0].mp.get(temp)!=null && arr[1].mp.get(temp)!=null && arr[2].mp.get(temp)!=null )
{
continue;
}
else if(arr[0].mp.get(temp)!=null && arr[1].mp.get(temp)!=null)
{
a++;
b++;
}
else if(arr[0].mp.get(temp)!=null && arr[2].mp.get(temp)!=null)
{
a++;
c++;
}
else if(arr[1].mp.get(temp)!=null && arr[2].mp.get(temp)!=null)
{
b++;
c++;
}
else if(arr[0].mp.get(temp)!=null)
{
a+=3;
}
else if(arr[1].mp.get(temp)!=null)
{
b+=3;
}
else if(arr[2].mp.get(temp)!=null)
{
c+=3;
}
}
out.println(a+" "+b+" "+c);
}
}
public void run() {
try {
in = new FastScanner(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(Reader f) {
br = new BufferedReader(f);
}
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;
}
}
}
|
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 17
|
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
|
3a5340ba58481e1ca9a442c53a647ffa
|
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 sc = new Scanner(System.in);
int t = sc.nextInt();
for(int it = 0 ; it < t ; it++){
int n = sc.nextInt();
HashSet<String> aSet = new HashSet<>();
HashSet<String> bSet = new HashSet<>();
HashSet<String> cSet = new HashSet<>();
for(int i = 0 ; i < n ; i++){
aSet.add(sc.next());
}
for(int i = 0 ; i < n ; i++){
bSet.add(sc.next());
}
for(int i = 0 ; i < n ; i++){
cSet.add(sc.next());
}
int a = 0;
int b = 0;
int c = 0;
for(String s : aSet){
if(bSet.contains(s) && cSet.contains(s)){
continue;
}else if(bSet.contains(s) || cSet.contains(s)){
a++;
}else{
a += 3;
}
}
for(String s : bSet){
if(aSet.contains(s) && cSet.contains(s)){
continue;
}else if(aSet.contains(s) || cSet.contains(s)){
b++;
}else{
b += 3;
}
}
for(String s : cSet){
if(bSet.contains(s) && aSet.contains(s)){
continue;
}else if(bSet.contains(s) || aSet.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 17
|
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
|
35c0645ae6cbd94d2ec3a82ec1dadba8
|
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.HashSet;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
int t = Integer.parseInt(br.readLine());
while(t-->0) {
br.readLine();
HashSet<String> hs = new HashSet<>();
HashSet<String> hs1 = new HashSet<>();
HashSet<String> hs2 = new HashSet<>();
HashSet<String> hs3 = new HashSet<>();
String[] s1 = br.readLine().split(" ");
String[] s2 = br.readLine().split(" ");
String[] s3 = br.readLine().split(" ");
for(String s : s1) {
hs.add(s);
hs1.add(s);
}
for(String s : s2) {
hs.add(s);
hs2.add(s);
}
for(String s : s3) {
hs.add(s);
hs3.add(s);
}
int c1 = 0;
int c2 = 0;
int c3 = 0;
for(String str : hs) {
if(hs1.contains(str) && hs2.contains(str) && !hs3.contains(str)) {
c1++;
c2++;
}
else if(!hs1.contains(str) && hs2.contains(str) && hs3.contains(str)) {
c2++;
c3++;
}
else if(hs1.contains(str) && !hs2.contains(str) && hs3.contains(str)) {
c1++;
c3++;
}
else if(hs1.contains(str) && !hs2.contains(str) && !hs3.contains(str))
c1+=3;
else if(!hs1.contains(str) && hs2.contains(str) && !hs3.contains(str))
c2+=3;
else if(!hs1.contains(str) && !hs2.contains(str) && hs3.contains(str))
c3+=3;
}
pw.println(c1+" " + c2 + " " + c3);
}
br.close();
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 17
|
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
|
6e533f43c893e52f9d114128e7adda5b
|
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 input = new Scanner(System.in);
int t = input.nextInt();
while(t-- > 0) {
int n = input.nextInt();
String[][] arr = new String[3][n];
HashSet<String>[] set = new HashSet[3];
for (int i = 0; i < 3; i++){
set[i] = new HashSet<>();
for (int j = 0; j < n; j++){
arr[i][j] = input.next();
set[i].add(arr[i][j]);
}
}
long[] ans = new long[3];
for (int i = 0; i < n; i++){
if (set[1].contains(arr[0][i]) && set[2].contains(arr[0][i]))
continue;
else if (set[1].contains(arr[0][i]) || set[2].contains(arr[0][i])){
ans[0]++;
}
else {
ans[0] += 3;
}
}
for (int i = 0; i < n; i++){
if (set[0].contains(arr[1][i]) && set[2].contains(arr[1][i]))
continue;
else if (set[0].contains(arr[1][i]) || set[2].contains(arr[1][i])){
ans[1]++;
}
else {
ans[1] += 3;
}
}
for (int i = 0; i < n; i++){
if (set[1].contains(arr[2][i]) && set[0].contains(arr[2][i]))
continue;
else if (set[1].contains(arr[2][i]) || set[0].contains(arr[2][i])){
ans[2]++;
}
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 17
|
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
|
2462cb3d9ac394ff766fe197c7992e00
|
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 ProblemC {
public static void main(String[] args) {
var scanner = new Scanner(System.in);
var cases = scanner.nextInt();
for (int tc = 0; tc < cases; tc++) {
var words = new HashSet<>();
var repeatedWords = new HashSet<>();
var repeatedAllWords = new HashSet<>();
var wordCount = scanner.nextInt();
var input = new String[3][wordCount];
for (int x = 0; x < 3; x++) {
for (int i = 0; i < wordCount; i++) {
input[x][i] = scanner.next();
}
}
for (int p = 0; p < 3; p++) {
for (int i = 0; i < wordCount; i++) {
var word = input[p][i];
if (!words.add(word)) {
if (!repeatedWords.add(word))
repeatedAllWords.add(word);
}
}
}
for (int p = 0; p < 3; p++) {
var score = 0;
for (int i = 0; i < wordCount; i++) {
var word = input[p][i];
if (repeatedAllWords.contains(word)) continue;
if (repeatedWords.contains(word)) score += 1;
else 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 17
|
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
|
02050c303337325e5be5af647f39d4cf
|
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
|
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
//package Codeforces;
import java.util.HashSet;
import java.util.Scanner;
/**
*
* @author Vinay Jain
*/
public class cf_817_c {
static class Solution {
public void solve(Scanner sc){
int n = sc.nextInt();
HashSet<String> a = new HashSet<>();
HashSet<String> b = new HashSet<>();
HashSet<String> c = new HashSet<>();
int p_a = 0 , p_b = 0, p_c = 0;
for(int i = 0 ; i < n ; i++)
a.add(sc.next());
for(int i = 0 ; i < n ; i++)
b.add(sc.next());
for(int i = 0 ; i < n ; i++)
c.add(sc.next());
for(String ele : a){
if(b.contains(ele) && c.contains(ele)){
continue;
}
if(!b.contains(ele) && !c.contains(ele))
p_a += 3;
else
p_a += 1;
}
for(String ele : b){
if(a.contains(ele) && c.contains(ele)){
continue;
}
if(!a.contains(ele) && !c.contains(ele))
p_b += 3;
else
p_b += 1;
}
for(String ele : c){
if(a.contains(ele) && b.contains(ele)){
continue;
}
if(!a.contains(ele) && !b.contains(ele))
p_c += 3;
else
p_c += 1;
}
System.out.println(p_a+" "+p_b+" "+p_c);
}
}
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
while (n-- > 0){
new Solution().solve(sc);
}
}
}
|
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 17
|
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
|
217089bbf8b131254cd0227520df5431
|
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 Sol
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
int t=s.nextInt();
for(int i=0;i<t;i++)
{
int n=s.nextInt();
String na[][]=new String[3][n];
for(int j=0;j<3;j++)
{
for(int k=0;k<n;k++)
na[j][k]=s.next();
}
for(int j=0;j<3;j++)
{
Arrays.sort(na[j]);
}
int c=0;
for(int k=0;k<n;k++)
{
if(Arrays.binarySearch(na[1],na[0][k])<0&&Arrays.binarySearch(na[2],na[0][k])<0)
c+=3;
else if(Arrays.binarySearch(na[1],na[0][k])>0&&Arrays.binarySearch(na[2],na[0][k])>0)
c+=0;
else if(Arrays.binarySearch(na[1],na[0][k])<0||Arrays.binarySearch(na[2],na[0][k])<0)
c+=1;
}
System.out.print(c+" ");
c=0;
for(int k=0;k<n;k++)
{
if(Arrays.binarySearch(na[0],na[1][k])<0&&Arrays.binarySearch(na[2],na[1][k])<0)
c+=3;
else if(Arrays.binarySearch(na[0],na[1][k])>0&&Arrays.binarySearch(na[2],na[1][k])>0)
c+=0;
else if(Arrays.binarySearch(na[0],na[1][k])<0||Arrays.binarySearch(na[2],na[1][k])<0)
c+=1;
}
System.out.print(c+" ");
c=0;
for(int k=0;k<n;k++)
{
if(Arrays.binarySearch(na[0],na[2][k])<0&&Arrays.binarySearch(na[1],na[2][k])<0)
c+=3;
else if(Arrays.binarySearch(na[0],na[2][k])>0&&Arrays.binarySearch(na[1],na[2][k])>0)
c+=0;
else if(Arrays.binarySearch(na[0],na[2][k])<0||Arrays.binarySearch(na[1],na[2][k])<0)
c+=1;
}
System.out.println(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 17
|
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
|
a72c7f500eaa4addc1f1de1c71289b46
|
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 WordGame {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int T = input.nextInt();
HashMap<String, int[]> freq = new HashMap<>();
int[] points;
while (T-- > 0) {
points = new int[3];
freq.clear();
int N = input.nextInt();
for (int i = 0; i < 3; i++) {
for (int j = 0; j < N; j++) {
String str = input.next();
if (freq.containsKey(str)) {
int[] arr = freq.get(str);
arr[i] = 1;
} else {
freq.put(str, new int[3]);
freq.get(str)[i] = 1;
}
}
}
for (String keys : freq.keySet()) {
int[] arr = freq.get(keys);
int cnt = 0;
for (int i : arr) {
if (i != 0) {
cnt++;
}
}
if (cnt == 1) {
for (int i = 0; i < 3; i++) {
if (arr[i] != 0) {
points[i] += 3;
break;
}
}
} else if (cnt == 2) {
for (int i = 0; i < 3; i++) {
if (arr[i] != 0) {
points[i] += 1;
}
}
} else {
}
}
for (int i = 0; i < 3; i++) {
System.out.print(points[i] + " ");
}
System.out.println();
}
input.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
|
b9afb85ebf285b4a7b85898bc7ed4ccb
|
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.HashSet;
import java.util.Set;
public class Word_Game {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
int t = scan.nextInt();
while (t-- > 0) {
int n = scan.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 = scan.next();
merge12.add(s);
merge13.add(s);
s1.add(s);
h1.add(s);
}
for (int i = 0; i < n; i++) {
String s = scan.next();
merge12.add(s);
merge23.add(s);
s2.add(s);
h2.add(s);
}
for (int i = 0; i < n; i++) {
String s = scan.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 common12 = merge12.size();
int common13 = merge13.size();
int common23 = merge23.size();
int score1 = common12 + common13 + (s1.size()) * 3;
int score2 = common12 + common23 + (s2.size()) * 3;
int score3 = common23 + common13 + (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
|
90bf33dc4596051738d618ae9fa1dd80
|
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.StringTokenizer;
import java.util.HashSet;
import java.util.TreeMap;
import java.util.PriorityQueue;
import java.util.Arrays;
public class Main {
public static void main(String[] args) throws IOException{
FastReader s = new FastReader();
int t = s.nextInt();
while(t-->0){
int n = s.nextInt();
HashSet<String> set1 = new HashSet<>();
HashSet<String> set2 = new HashSet<>();
int p1 = 0;
int p2 = 0;
int p3 = 0;
for(int i = 0; i < n; i++){
set1.add(s.next());
p1 += 3;
}
for(int i = 0; i < n; i++){
String str = s.next();
set2.add(str);
if(set1.contains(str)){
p1 -= 2;
p2 += 1;
}
else{
p2 += 3;
}
}
for(int i = 0; i < n; i++){
String str = s.next();
if(set1.contains(str) && set2.contains(str)){
p1--;
p2--;
}
else if(set1.contains(str)){
p1 -= 2;
p3++;
}
else if(set2.contains(str)){
p2 -= 2;
p3++;
}
else{
p3 += 3;
}
}
System.out.println(p1 + " " + p2 + " " + p3);
}
}
public static boolean isVowel(char ch){
if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'u' || ch == 'o'){
return true;
}
return false;
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader(){
br = new BufferedReader(new InputStreamReader(System.in));
}
public String next() throws IOException{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() throws IOException{ return Integer.parseInt(next()); }
long nextLong() throws IOException{ return Long.parseLong(next()); }
double nextDouble() throws IOException{return Double.parseDouble(next());}
String nextLine() throws IOException{
String str = "";
if(st.hasMoreTokens()){
str = st.nextToken("\n");
}
else{
str = br.readLine();
}
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
|
e921a7d2d4c992742345630646d553bf
|
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 Words {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
int numberOfSets = Integer.parseInt(br.readLine());
for (int nos = 0; nos < numberOfSets; nos ++) {
int size = Integer.parseInt(br.readLine());
String [] s1 = br.readLine().split(" ");
String [] s2 = br.readLine().split(" ");
String [] s3 = br.readLine().split(" ");
int sum1, sum2, sum3;
sum1=sum2=sum3=0;
int count;
Map<String, Integer> map = new HashMap<>();
for (int i = 0; i<size; i++) {
if (map.get(s1[i]) == null) {
map.put(s1[i], 3);
} else {
count = map.get(s1[i]);
map.put(s1[i], count/2);
}
}
for (int i = 0; i<size; i++) {
if (map.get(s2[i]) == null) {
map.put(s2[i], 3);
} else {
count = map.get(s2[i]);
map.put(s2[i], count/2);
}
}
for (int i = 0; i<size; i++) {
if (map.get(s3[i]) == null) {
map.put(s3[i], 3);
} else {
count = map.get(s3[i]);
map.put(s3[i], count/2);
}
}
for (int i = 0; i < size; i++) {
if(map.containsKey(s1[i])) {
sum1+= map.get(s1[i]);
}
}
for (int i = 0; i < size; i++) {
if(map.containsKey(s2[i])) {
sum2+= map.get(s2[i]);
}
}
for (int i = 0; i < size; i++) {
if(map.containsKey(s3[i])) {
sum3+= map.get(s3[i]);
}
}
System.out.println(sum1 + " " + sum2 + " " + sum3);
}
}
}
|
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
|
6f5bdd96954818971c6380e44cdfccf7
|
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 WordGame {
public static void main(String[] args) {
final Scanner sc = new Scanner(System.in);
int t = Integer.parseInt(sc.nextLine());
String[] resultados =new String[t];
for(int i=0;i<t;i++){
int n=Integer.parseInt(sc.nextLine());
int puntaje1=0;
int puntaje2=0;
int puntaje3=0;
String[] jugador1 = sc.nextLine().split(" ");
String[] jugador2 = sc.nextLine().split(" ");
String[] jugador3 = sc.nextLine().split(" ");
//System.out.println(jugador1.length);
Map<String, Integer> map = new HashMap<String, Integer>();
for (int j=0;j<n;j++){
map.put(jugador1[j],0);
map.put(jugador2[j],0);
map.put(jugador3[j],0);
}
for (int j=0;j<n;j++){
map.put(jugador1[j],map.get(jugador1[j])+1);
map.put(jugador2[j],map.get(jugador2[j])+1);
map.put(jugador3[j],map.get(jugador3[j])+1);
}
for (int z=0;z<n;z++){
if (map.get(jugador1[z])==1){
puntaje1+=3;
}else if (map.get(jugador1[z])==2){
puntaje1+=1;
}
}
for (int z=0;z<n;z++){
if (map.get(jugador2[z])==1){
puntaje2+=3;
}else if (map.get(jugador2[z])==2){
puntaje2+=1;
}
}
for (int z=0;z<n;z++){
if (map.get(jugador3[z])==1){
puntaje3+=3;
}else if (map.get(jugador3[z])==2){
puntaje3+=1;
}
}
resultados[i]= (puntaje1+" "+puntaje2+" "+puntaje3);
}
for (int k=0;k<t;k++){
System.out.println(resultados[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 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
|
91c761271709f0e1ebf82474da1eee44
|
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.Map;
import java.util.Set;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class C817 {
static AReader scan = new AReader();
static void solve() {
Map<String,Integer> hash = new HashMap<>();
int n = scan.nextInt();
String[][] strs = new String[4][n+10];
for(int i = 1;i<=3;i++){
Set<String> st = new HashSet<>();
for(int j = 1;j<=n;j++){
String s = scan.next();
strs[i][j] = s;
if(st.contains(s)) continue;
st.add(s);
int t = hash.getOrDefault(s,0);
hash.put(s,++t);
}
}
for(int i = 1;i<=3;i++){
int p = 0;
for(int j = 1;j<=n;j++){
String s = strs[i][j];
if(hash.get(s) == 1) p +=3;
else if(hash.get(s) == 2) p +=1;
}
System.out.print(p+" ");
}
System.out.println();
}
public static void main(String[] args) {
int T = scan.nextInt();
while (T-- > 0) {
solve();
}
}
}
class AReader {
private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
private StringTokenizer tokenizer = new StringTokenizer("");
private String innerNextLine() {
try {
return reader.readLine();
} catch (IOException ex) {
return null;
}
}
public boolean hasNext() {
while (!tokenizer.hasMoreTokens()) {
String nextLine = innerNextLine();
if (nextLine == null) {
return false;
}
tokenizer = new StringTokenizer(nextLine);
}
return true;
}
public String nextLine() {
tokenizer = new StringTokenizer("");
return innerNextLine();
}
public String next() {
hasNext();
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
|
Java
|
["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
|
c982e4a387739519284c716a55f90b79
|
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 _1722C {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int i=1;i<=t;i++) {
int n = sc.nextInt();
// String trsah = sc.nextLine();
// HashMap<String,Integer> words = new HashMap<String,Integer>();
// ArrayList<String> p1 = new ArrayList<String>();
// ArrayList<String> p2 = new ArrayList<String>();
// ArrayList<String> p3 = new ArrayList<String>();
// String l1[]=sc.nextLine().split(" ");
// String l2[]=sc.nextLine().split(" ");
// String l3[]=sc.nextLine().split(" ");
// for(int j=0;j<n;j++) {
// String temp=l1[j];
// if(!p1.contains(temp)) {
// int val=words.getOrDefault(temp, 0);
// val++;
// words.put(temp, val);
// }
// p1.add(temp);
// }
// for(int j=0;j<n;j++) {
// String temp=l2[j];
// if(!p2.contains(temp)) {
// int val=words.getOrDefault(temp, 0);
// val++;
// words.put(temp, val);
// }
// p2.add(temp);
// }
// for(int j=0;j<n;j++) {
// String temp=l3[j];
// if(!p3.contains(temp)) {
// int val=words.getOrDefault(temp, 0);
// val++;
// words.put(temp, val);
// }
// p3.add(temp);
// }
// for(String h:p1) {
// if(p2.contains(h)) {
// if(p3.contains(h)) {
// continue;
// }else {
// a1++;
// }
// }else if(p3.contains(h)) {
// if(p2.contains(h)) {
// continue;
// }else {
// a1++;
// }
// }else {
// a1+=3;
// }
// }
// for(String h:p2) {
// if(p1.contains(h)) {
// if(p3.contains(h)) {
// continue;
// }else {
// a2++;
// }
// }else if(p3.contains(h)) {
// if(p2.contains(h)) {
// continue;
// }else {
// a2++;
// }
// }else {
// a2+=3;
// }
// }
// for(String h:p3) {
// if(p1.contains(h)) {
// if(p2.contains(h)) {
// continue;
// }else {
// a3++;
// }
// }else if(p2.contains(h)) {
// if(p1.contains(h)) {
// continue;
// }else {
// a3++;
// }
// }else {
// a3+=3;
// }
// }
// for(String h:words) {
// if(p1.contains(h) && p2.contains(h) && p3.contains(h)) {
// continue;
// }else if(p1.contains(h)) {
// if(p2.contains(h)) {
// a1++;a2++;
// }else if(p3.contains(h)) {
// a1++;a3++;
// }else {
// a1+=3;
// }
// }else if(p2.contains(h)) {
// if(p1.contains(h)) {
// a1++;a2++;
// }else if(p3.contains(h)) {
// a2++;a3++;
// }else {
// a2+=3;
// }
// }else if(p3.contains(h)) {
// if(p1.contains(h)) {
// a1++;a3++;
// }else if(p2.contains(h)) {
// a2++;a3++;
// }else {
// a3+=3;
// }
// }
// }
// for(String h:words.keySet()) {
// int val=words.get(h);
// if(val==3) {
// continue;
// }else if(val==2) {
// if(p1.contains(h)) {
// if(p2.contains(h)) {
// a1++;a2++;
// }else if(p3.contains(h)) {
// a1++;a3++;
// }
// }else if(p2.contains(h)) {
// if(p1.contains(h)) {
// a1++;a2++;
// }else if(p3.contains(h)) {
// a2++;a3++;
// }
// }else if(p3.contains(h)) {
// if(p1.contains(h)) {
// a1++;a3++;
// }else if(p2.contains(h)) {
// a2++;a3++;
// }
// }
// }else if(val==1) {
// if(p1.contains(h)) {
// a1+=3;
// }else if(p2.contains(h)) {
// a2+=3;
// }else if(p3.contains(h)) {
// a3+=3;
// }
// }
// }
int a1=0;
int a2=0;
int a3=0;
HashMap<String,Integer> words = new HashMap<String,Integer>();
for(int j=0;j<n;j++) {
String temp = sc.next();
words.put(temp, 1);
a1+=3;
}
for(int j=0;j<n;j++) {
String temp=sc.next();
if(words.keySet().contains(temp)) {
a1++;a1-=3;a2++;
words.put(temp, 2);
}else {
words.put(temp,-1);
a2+=3;
}
}
for(int j=0;j<n;j++) {
String temp=sc.next();
if(words.keySet().contains(temp)) {
if(words.get(temp)==2) {
words.put(temp, 3);
a1--;a2--;
}else if(words.get(temp)==-1){
a2++;a3++;a2-=3;
}else if(words.get(temp)==1) {
a1++;a3++;a1-=3;
}
}else {
words.put(temp, 1);
a3+=3;
}
}
System.out.println(a1+" "+a2+" "+a3);
}
}
}
|
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
|
9605130d71952fcfa2d6fde9490c5aa6
|
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.BigInteger;
import java.util.stream.Collectors;
public class Main {
InputStream is;
PrintWriter out;
String INPUT = "";
void run() throws Exception {
is = System.in; out = new PrintWriter(System.out);
solve(); out.flush(); out.close();
}
public static void main(String[] args) throws Exception {
new Main().run();
}
public byte[] inbuf = new byte[1 << 16];
public int lenbuf = 0, ptrbuf = 0;
public int readByte() {
if (lenbuf == -1) {
throw new InputMismatchException();
}
if (ptrbuf >= lenbuf) {
ptrbuf = 0;
try {
lenbuf = is.read(inbuf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0)
return -1;
}
return inbuf[ptrbuf++];
}
public boolean isSpaceChar(int c) {
return !(c >= 33 && c <= 126);
}
public int skip() {
int b;
while ((b = readByte()) != -1 && isSpaceChar(b))
;
return b;
}
public double nd() {
return Double.parseDouble(ns());
}
public char nc() {
return (char) skip();
}
private String ns() {
int b = skip();
StringBuilder sb = new StringBuilder();
while (!(isSpaceChar(b))) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private int ni() {
return (int) nl();
}
private long nl() {
long num = 0;
int b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
class Pair {
int first;
int second;
Pair(int a, int b) {
first = a;
second = b;
}
}
long[] nal(int n) {
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = nl();
}
return arr;
}
void solve() {
int test_case = 1;
test_case = ni();
while (test_case-- > 0) {
go();
}
}
// WRITE CODE FROM HERE :-
void go() {
int n = ni();
Map<String, Integer> map = new HashMap<>();
String[][] ch = new String[3][n];
String s = "";
for(int i=0; i<3; i++) {
for(int j=0; j<n; j++) {
s = ns();
ch[i][j] = s;
map.put(s, map.getOrDefault(s, 0) + 1);
}
}
long ans = 0;
for(int i=0; i<3; i++) {
ans = 0;
for(int j=0; j<n; j++) {
if(map.get(ch[i][j]) == 2) ans += 1;
else if(map.get(ch[i][j]) == 1) ans += 3;
else ans += 0;
}
out.print(ans + " ");
}
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
|
4d66fab65d5a00da53d03f2f5a5d4217
|
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 s=new Scanner(System.in);
int t=s.nextInt();
while(t-->0)
{
int n=s.nextInt();
String[] q1=new String[n];
String[] q2=new String[n];
String[] q3=new String[n];
HashSet<String> l1=new HashSet();
HashSet<String> l2=new HashSet();
HashSet<String> l3=new HashSet();
int c1=0,c2=0,c3=0;
for(int i=0;i<n;i++)
{
q1[i]=s.next();
l1.add(q1[i]);
}
for(int i=0;i<n;i++)
{
q2[i]=s.next();
l2.add(q2[i]);
}
for(int i=0;i<n;i++)
{
q3[i]=s.next();
l3.add(q3[i]);
}
for(String i:l1)
{
if(l2.contains(i) && l3.contains(i))
c1=c1+0;
else if(l2.contains(i) && !l3.contains(i) || !l2.contains(i) && l3.contains(i))
c1=c1+1;
else
c1=c1+3;
}
for(String i:l2)
{
if(l1.contains(i) && l3.contains(i))
c2=c2+0;
else if(l1.contains(i) && !l3.contains(i) || !l1.contains(i) && l3.contains(i))
c2=c2+1;
else
c2=c2+3;
}
for(String i:l3)
{
if(l2.contains(i) && l1.contains(i))
c3=c3+0;
else if(l2.contains(i) && !l1.contains(i) || !l2.contains(i) && l1.contains(i))
c3=c3+1;
else
c3=c3+3;
}
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
|
b77400c1e4aa802bdac1cc9f1b76c99e
|
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.util.regex.Pattern;
public class Robot4 {
public static void main(String[] args) {
Scanner x = new Scanner(System.in);
int s = x.nextInt();
for (int i = 0; i < s; i++) {
int count1=0;
int count2=0;
int count3=0;
String[]aa ;
String[]bb ;
String[]cc ;
// ArrayList<String>a = new ArrayList<>();
// ArrayList<String>b = new ArrayList<>();
// ArrayList<String>c = new ArrayList<>();
int leng = x.nextInt();
x.nextLine();
aa=x.nextLine().split(" ");
bb=x.nextLine().split(" ");
cc=x.nextLine().split(" ");
HashMap<String,Integer>a1 = new HashMap<>();
HashMap<String,Integer>b1 = new HashMap<>();
HashMap<String,Integer>c1 = new HashMap<>();
for (int j = 0; j < leng; j++) {a1.put(aa[j],0);b1.put(bb[j],0);c1.put(cc[j],0);}
for (Map.Entry<String, Integer> pair : a1.entrySet()) {
if ((b1.containsKey(pair.getKey())&&!c1.containsKey(pair.getKey()))){
count1++;
count2++;
}
}
for (Map.Entry<String, Integer> pair : c1.entrySet()) {
if ((b1.containsKey(pair.getKey())&&!a1.containsKey(pair.getKey()))){
count2++;
count3++;
}
}
for (Map.Entry<String, Integer> pair : c1.entrySet()) {
if ((a1.containsKey(pair.getKey())&&!b1.containsKey(pair.getKey()))){
count1++;
count3++;
}
}
for (Map.Entry<String, Integer> pair : c1.entrySet()) {
if ((!a1.containsKey(pair.getKey())&&!b1.containsKey(pair.getKey()))){
count3++;
count3++;
count3++;
}
} for (Map.Entry<String, Integer> pair : a1.entrySet()) {
if ((!b1.containsKey(pair.getKey())&&!c1.containsKey(pair.getKey()))){
count1++;
count1++;
count1++;
}
}
for (Map.Entry<String, Integer> pair : b1.entrySet()) {
if ((!a1.containsKey(pair.getKey())&&!c1.containsKey(pair.getKey()))){
count2++;
count2++;
count2++;
}
}
// if (b.contains(c.get(j))&&!a.contains(c.get(j))){
//
// cminus2++;
// cminus3++;
//
// count2++;
// count3++;
// }
//
// if (a.contains(c.get(j))&&!b.contains(c.get(j))){
// cminus1++;
// cminus3++;
//
// count1++;
// count3++;
// }
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 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
|
21c7a4fc1c6baf01a032f5279ee85784
|
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) {
try {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-->0) {
int n = sc.nextInt();
String[] a = new String[n];
String[] b = new String[n];
String[] c = new String[n];
HashMap<String,Integer>m = new HashMap<>();
for(int i=0;i<n;i++){
a[i] = sc.next();
m.put(a[i],m.getOrDefault(a[i],0)+1);
}
for(int i=0;i<n;i++){
b[i] = sc.next();
m.put(b[i],m.getOrDefault(b[i],0)+1);
}
for(int i=0;i<n;i++){
c[i] = sc.next();
m.put(c[i],m.getOrDefault(c[i],0)+1);
}
int ca = 0,cb=0,cc=0;
for(int i=0;i<n;i++){
if(m.get(a[i]) == 2)
ca+=1;
else if(m.get(a[i]) == 1)
ca+=3;
if(m.get(b[i]) == 2)
cb+=1;
else if(m.get(b[i]) == 1)
cb+=3;
if(m.get(c[i]) == 2)
cc+=1;
else if(m.get(c[i]) == 1)
cc+=3;
}
System.out.println(ca+" "+cb+" "+cc);
}
}
catch (Exception e){
System.out.println(e);
}
}
}
|
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
|
44e4568a4c20ff87d8e69f822fe22442
|
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.HashSet;
import java.util.StringTokenizer;
public class ProblemA {
public static void main(String[] args) throws IOException
{
BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(f.readLine());
int t = Integer.parseInt(st.nextToken());
for(int x = 0; x < t; x++)
{
st = new StringTokenizer(f.readLine());
int n = Integer.parseInt(st.nextToken());
HashSet<String> a = new HashSet<String>();
HashSet<String> a1 = new HashSet<String>();
HashSet<String> a2 = new HashSet<String>();
String[] b = new String[n];
String[] b1 = new String[n];
String[] b2 = new String[n];
st = new StringTokenizer(f.readLine());
for(int i = 0; i < n; i++)
{
b[i] = st.nextToken();
a.add(b[i]);
}
st = new StringTokenizer(f.readLine());
for(int i = 0; i < n; i++)
{
b1[i] = st.nextToken();
a1.add(b1[i]);
}
st = new StringTokenizer(f.readLine());
for(int i = 0; i < n; i++)
{
b2[i] = st.nextToken();
a2.add(b2[i]);
}
int sum = 0;
for(int i = 0; i < n; i++)
{
if(a2.contains(b[i]) && a1.contains(b[i]))
{
sum+=0;
}
else if(a2.contains(b[i]) && !a1.contains(b[i]))
{
sum+=1;
}
else if(a1.contains(b[i]) && !a2.contains(b[i]))
{
sum+=1;
}
else
{
sum+=3;
}
}
System.out.print(sum+" ");
sum = 0;
for(int i = 0; i < n; i++)
{
if(a2.contains(b1[i]) && a.contains(b1[i]))
{
sum+=0;
}
else if(a2.contains(b1[i]) && !a.contains(b1[i]))
{
sum+=1;
}
else if(a.contains(b1[i]) && !a2.contains(b1[i]))
{
sum+=1;
}
else
{
sum+=3;
}
}
System.out.print(sum+" ");
sum = 0;
for(int i = 0; i < n; i++)
{
if(a1.contains(b2[i]) && a.contains(b2[i]))
{
sum+=0;
}
else if(a.contains(b2[i]) && !a1.contains(b2[i]))
{
sum+=1;
}
else if(a1.contains(b2[i]) && !a.contains(b2[i]))
{
sum+=1;
}
else
{
sum+=3;
}
}
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 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
|
9b6cb3e9f1b594f1a712161ce0c2e9a7
|
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 OurThirdProblem {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
for (int t = in.nextInt(); t>0; t--){
int n = in.nextInt();
HashMap<String, LinkedList<Integer>> map = new HashMap<>();
for (int i = 0; i<n; i++){
String current = in.next();
if (!map.containsKey(current)) map.put(current,new LinkedList<>());
map.get(current).add(1);
}
for (int i = 0; i<n; i++){
String current = in.next();
if (!map.containsKey(current)) map.put(current,new LinkedList<>());
map.get(current).add(2);
}
for (int i = 0; i<n; i++){
String current = in.next();
if (!map.containsKey(current)) map.put(current,new LinkedList<>());
map.get(current).add(3);
}
int p1 = 0,p2 = 0,p3 = 0;
for (String word : map.keySet()){
LinkedList<Integer> l = map.get(word);
int size = l.size();
if (size == 1) {
if (l.get(0) == 1) p1+=3;
if (l.get(0) == 2) p2+=3;
if (l.get(0) == 3) p3+=3;
}
else if (size == 2) {
if (l.get(0) == 1 || l.get(1) == 1) p1++;
if (l.get(0) == 2 || l.get(1) == 2) p2++;
if (l.get(0) == 3 || l.get(1) == 3) p3++;
}
}
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
|
9ba4ecb3d5baa937774bd8ae10d8db96
|
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 _1722C {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
StringBuilder sb = new StringBuilder();
for (int t = in.nextInt(); t>0; t--){
int n = in.nextInt();
HashSet<String> M1 = add(in, n), M2 = add(in, n), M3 = add(in, n);
int m1 = counter(M1, M2, M3), m2 = counter(M2, M1, M3), m3 = counter(M3, M1, M2);
sb.append(m1).append(" ").append(m2).append(" ").append(m3).append("\n");
}
System.out.println(sb);
}
public static int counter(HashSet<String> current,HashSet<String> s1, HashSet<String> s2){
int c1 = 0;
for (String s : current){
boolean one = s1.contains(s), two = s2.contains(s);
if ((one && !two) || (!one && two))
c1++;
else if (!one)
c1+=3;
}
return c1;
}
public static HashSet<String> add(Scanner in, int n){
HashSet<String> current = new HashSet<>();
for (int j = 1; j<= n; j++) current.add(in.next());
return current;
}
}
|
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
|
f9c014a9a7f2d7ccc38b9f0cac8a3af2
|
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 _1722C {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
for (int t = in.nextInt(); t>0; t--){
int n = in.nextInt();
HashSet<String> M1 = add(in, n);
HashSet<String> M2 = add(in, n);
HashSet<String> M3 = add(in, n);
int m1 = counter(M1, M2, M3);
int m2 = counter(M2, M1, M3);
int m3 = counter(M3, M1, M2);
System.out.println(m1 + " " + m2 + " " + m3);
}
}
public static int counter(HashSet<String> current,HashSet<String> s1, HashSet<String> s2){
int c1 = 0;
for (String s : current){
boolean one = s1.contains(s), two = s2.contains(s);
if ((one && !two) || (!one && two))
c1++;
else if (!one)
c1+=3;
}
return c1;
}
public static HashSet<String> add(Scanner in, int n){
HashSet<String> current = new HashSet<>();
for (int j = 1; j<= n; j++) current.add(in.next());
return current;
}
}
|
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
|
3a5ee0ebfdc39e285f7766961c55d238
|
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();
while(t-- > 0){
int n= sc.nextInt();
HashMap<String,Integer>hm = new HashMap<>();
String a[][] = new String[3][n];
int i,j = 0;
for(i=0;i<3;i++){
for(j=0;j<n;j++){
a[i][j] = sc.next();
if(hm.containsKey(a[i][j])){
hm.put(a[i][j],hm.get(a[i][j])-2);
}
else{
hm.put(a[i][j],3);
}
}
}
int r[] = new int[3];
for(i=0;i<3;i++){
for(j=0;j<n;j++){
if(hm.get(a[i][j])>0){
r[i] = r[i] + hm.get(a[i][j]);
}
}
}
System.out.println(r[0]+" "+r[1]+" "+r[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
|
b87e780aa5d5f3ecbc9fb19a224dde2c
|
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();
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] = scn.next();
if(map.containsKey(arr[i][j]))
map.put(arr[i][j],map.get(arr[i][j])-2);
else
map.put(arr[i][j],3);
}
}
int[] points = new int[3];
for(int i=0; i<3; i++){
for(int j=0; j<n; j++){
if(map.get(arr[i][j])!=-1)
points[i] += map.get(arr[i][j]);
}
}
System.out.println(points[0] + " " + points[1] + " " + points[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
|
a8163caa8916b24751974755065072bc
|
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 WordGameSet {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for ( int p = 0; p < t; p++){
int n = in.nextInt();
HashSet <String> set1 = new HashSet<>();
HashSet <String> set2 = new HashSet<>();
HashSet <String> set3 = new HashSet<>();
HashSet <String> set4 = new HashSet<>();
for ( int i = 0; i < n; i++) {
String x = in.next();
set1.add(x);
set4.add(x);
}
for ( int i = 0; i < n; i++) set2.add(in.next());
for ( int i = 0; i < n; i++) set3.add(in.next());
int num1 = set1.size();
int num2 = set2.size();
int num3 = set3.size();
set1.retainAll(set2);
set2.retainAll(set3);
set4.retainAll(set3);
int num12 = set1.size();
int num23 = set2.size();
int num13 = set4.size();
set1.retainAll(set2);
int num123 = set1.size();
num12-= num123;
num13-= num123;
num23-= num123;
num1 -= num12 + num13 + num123;
num2 -= num23 + num12 + num123;
num3 -= num13 + num23 + num123;
System.out.println(((3*num1)+num12+num13) + " " + ((3*num2)+num12+num23) + " " + ((3*num3)+num13+num23));
}
}
}
|
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
|
3d88a09a779d6bea707f3c329e48a358
|
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.*;
public class Q3 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner key=new Scanner(System.in);
int t=key.nextInt();
for(int i=0;i<t;i++) {
int n=key.nextInt();
key.nextLine();
String str1=key.nextLine();
String str2=key.nextLine();
String str3=key.nextLine();
HashSet<String>s=new HashSet<>();
int one=0,two=0,three=0,ac=0,ab=0,bc=0,abc=0,qabc=0;
String temp="";
for(int j=0;j<4*n-1;j++) {
if(str1.charAt(j)==' ') {
s.add(temp);
temp="";
}else {
temp=temp+str1.charAt(j);
}
}
s.add(temp);
temp="";
for(int k=0;k<4*n-1;k++) {
if(str2.charAt(k)==' ') {
if(s.contains(temp)) {
ab++;
}
temp="";
}else {
temp=temp+str2.charAt(k);
}
}
if(s.contains(temp)) {
ab++;
}
temp="";
for(int l=0;l<4*n-1;l++) {
if(str3.charAt(l)==' ') {
if(s.contains(temp)) {
ac++;
}
temp="";
}else {
temp=temp+str3.charAt(l);
}
}
if(s.contains(temp)) {
ac++;
}
temp="";
for(int r=0;r<4*n-1;r++) {
if(str3.charAt(r)==' ') {
s.add(temp);
temp="";
}else {
temp=temp+str3.charAt(r);
}
}
s.add(temp);
temp="";
for(int q=0;q<4*n-1;q++) {
if(str2.charAt(q)==' ') {
s.add(temp);
temp="";
}else {
temp=temp+str2.charAt(q);
}
}
s.add(temp);
temp="";
abc=s.size();
s.clear();
for(int e=0;e<4*n-1;e++) {
if(str3.charAt(e)==' ') {
s.add(temp);
temp="";
}else {
temp=temp+str3.charAt(e);
}
}
s.add(temp);
temp="";
for(int w=0;w<4*n-1;w++) {
if(str2.charAt(w)==' ') {
if(s.contains(temp)) {
bc++;
}
temp="";
}else {
temp=temp+str2.charAt(w);
}
}
if(s.contains(temp)) {
bc++;
}
qabc=abc+ab+ac+bc-3*n;
one=1*(ab+ac-2*qabc)+3*(n-ab-ac+qabc);
two=1*(ab+bc-2*qabc)+3*(n-ab-bc+qabc);
three=1*(bc+ac-2*qabc)+3*(n-bc-ac+qabc);
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
|
8af19132adf7b67a4abac370d2e51c77
|
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
|
c19535144ac1569cc0708ce8fe01fccf
|
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.lang.reflect.Array;
import java.math.BigInteger;
import java.rmi.Remote;
import java.text.Collator;
// import java.util.Scanner;
import java.util.*;
import javax.management.Query;
import javax.xml.transform.Source;
public class second {
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 {
if (st.hasMoreTokens()) {
str = st.nextToken("\n");
} else {
str = br.readLine();
}
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args) {
FastReader s = new FastReader();
int test_case=s.nextInt();
while(test_case-->0){
int n=s.nextInt();
String [][] aa=new String[3][n];
HashMap<String,Integer> ans=new HashMap<>();
for(int i=0;i<n;i++){
aa[0][i]=s.next();
ans.put(aa[0][i],ans.getOrDefault(aa[0][i],0)+1);
}
for(int i=0;i<n;i++){
aa[1][i]=s.next();
ans.put(aa[1][i],ans.getOrDefault(aa[1][i],0)+1);
}
for(int i=0;i<n;i++){
aa[2][i]=s.next();
ans.put(aa[2][i],ans.getOrDefault(aa[2][i],0)+1);
}
int points=0;
for(int i=0;i<n;i++){
if(ans.get(aa[0][i])==1) points+=3;
else if(ans.get(aa[0][i])==2) points++;
}
System.out.print(points+" ");
points=0;
for(int i=0;i<n;i++){
if(ans.get(aa[1][i])==1) points+=3;
else if(ans.get(aa[1][i])==2) points++;
}
System.out.print(points+" ");
points=0;
for(int i=0;i<n;i++){
if(ans.get(aa[2][i])==1) points+=3;
else if(ans.get(aa[2][i])==2) points++;
}
System.out.print(points+"\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
|
3e68709347b8b92adb84859f2792f3a0
|
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();
while (t-- > 0) {
HashMap<String, Integer> map = new HashMap<>();
int n = sc.nextInt();
sc.nextLine();
String[] str1 = sc.nextLine().split(" ");
String[] str2 = sc.nextLine().split(" ");
String[] str3 = sc.nextLine().split(" ");
for (int i = 0; i < n; i++) {
map.put(str1[i], map.getOrDefault(str1[i], 0) + 1);
map.put(str2[i], map.getOrDefault(str2[i], 0) + 1);
map.put(str3[i], map.getOrDefault(str3[i], 0) + 1);
}
int sum1 = 0, sum2 = 0, sum3 = 0;
for (int i = 0; i < n; i++) {
if (map.get(str1[i]) == 1) {
sum1 += 3;
}else if(map.get(str1[i]) == 2) {
sum1 += 1;
}
if(map.get(str2[i]) == 1) {
sum2 += 3;
}else if(map.get(str2[i]) == 2) {
sum2 += 1;
}
if(map.get(str3[i]) == 1) {
sum3 += 3;
}else if(map.get(str3[i]) == 2) {
sum3 += 1;
}
}
System.out.println(sum1 + " " + sum2 + " " + sum3);
}
}
}
|
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
|
b6c1e3b63448cfc9179231da2fa75fbd
|
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 Solve {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int count = Integer.parseInt(sc.nextLine());
for(int i = 0; i < count; i++){
System.out.println(howPoints(Integer.parseInt(sc.nextLine()), sc.nextLine(), sc.nextLine(), sc.nextLine()));
}
}
public static String howPoints(int len, String first, String second, String third){
String[] firstLine = first.split(" ");
String[] secondLine = second.split(" ");
String[] thirdLine = third.split(" ");
int[] points = new int[4];
HashMap<String, Integer> dict = new HashMap<>();
for(String i: firstLine){
dict.put("1" + i, 1);
}
for(String i: secondLine){
String fromFirst = "1" + i;
if(dict.containsKey(fromFirst)) {
dict.put("12" + i, dict.get(fromFirst) + 1);
dict.remove(fromFirst);
}else
dict.put("2" + i, 1);
}
for(String i: thirdLine){
String fromFirst = "1" + i;
String fromSecond = "2" + i;
String fromBoth = "12" + i;
if(dict.containsKey(fromFirst)) {
dict.put("13" + i, dict.get(fromFirst) + 1);
dict.remove(fromFirst);
}
else if(dict.containsKey(fromSecond)) {
dict.put("23" + i, dict.get(fromSecond) + 1);
dict.remove(fromSecond);
}else if(dict.containsKey(fromBoth)){
dict.remove(fromBoth);
}else
dict.put("3" + i, 1);
}
for (Map.Entry<String, Integer> entry : dict.entrySet()) {
if(entry.getValue() == 1)
points[Integer.parseInt(entry.getKey().substring(0, 1))]+= 3;
else{
points[Integer.parseInt(entry.getKey().substring(0,1))]++;
points[Integer.parseInt(entry.getKey().substring(1, 2))]++;
}
}
return "" + points[1] + " " + points[2] + " " + points[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 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
|
14f607d95c5b328e1ffa12ac5a18f596
|
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.*;
public class distict {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t>0) {
int n=sc.nextInt();
HashSet<String> valid1 =new HashSet<>();
HashSet<String> valid2 =new HashSet<>();
HashSet<String> valid3 =new HashSet<>();
for(int i=0;i<n;i++) {
valid1.add(sc.next());
}
for(int i=0;i<n;i++) {
String s2=sc.next();
valid2.add(s2);
}
for(int i=0;i<n;i++) {
String s3=sc.next();
valid3.add(s3);
}
int ans1=0,ans2=0,ans3=0;
for(String x : valid1) {
if(valid3.contains(x) && valid2.contains(x) ) {
}
else if(valid2.contains(x) || valid3.contains(x)) {
ans1+=1;
}
else if(!valid2.contains(x) && !valid3.contains(x)) {
ans1+=3;
}
}
for(String y : valid2) {
if(valid1.contains(y) && valid3.contains(y) ) {
}
else if(valid1.contains(y) || valid3.contains(y)) {
ans2+=1;
}
else if(!valid1.contains(y) && !valid3.contains(y)) {
ans2+=3;
}
}
for(String z : valid3) {
if(valid1.contains(z) && valid2.contains(z) ) {
}
else if(valid1.contains(z) || valid2.contains(z)) {
ans3+=1;
}
else if(!valid1.contains(z) && !valid2.contains(z)) {
ans3+=3;
}
}
System.out.print(ans1+" "+ans2+" "+ans3);
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 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
|
8824d93b8b7deb5ede706472088acd76
|
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.util.Map;
/**
*
* @author Vattikuti Rajesh
*/
public class SolutionA {
public static void main(String r[]){
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
String[] str1=new String[n];
String[] str2=new String[n];
String[] str3=new String[n];
for(int i=0;i<n;i++)
str1[i]=sc.next();
for(int i=0;i<n;i++)
str2[i]=sc.next();
for(int i=0;i<n;i++)
str3[i]=sc.next();
HashMap<String,Integer> map=new HashMap<>();
for(int i=0;i<n;i++){
if(map.containsKey(str1[i]))
map.put(str1[i],map.get(str1[i])+1);
else
map.put(str1[i],1);
}
for(int i=0;i<n;i++){
if(map.containsKey(str2[i]))
map.put(str2[i],map.get(str2[i])+1);
else
map.put(str2[i],1);
}for(int i=0;i<n;i++){
if(map.containsKey(str3[i]))
map.put(str3[i],map.get(str3[i])+1);
else
map.put(str3[i],1);
}
int cnt1=0,cnt2=0,cnt3=0;
for(int i=0;i<n;i++){
int x=map.get(str1[i]);
if(x==1)
cnt1+=3;
if(x==2)
cnt1+=1;
}
for(int i=0;i<n;i++){
int x=map.get(str2[i]);
if(x==1)
cnt2+=3;
if(x==2)
cnt2+=1;
}
for(int i=0;i<n;i++){
int x=map.get(str3[i]);
if(x==1)
cnt3+=3;
if(x==2)
cnt3+=1;
}
System.out.println(cnt1+" "+cnt2+" "+cnt3);
}
}
}
|
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
|
00a046fed502c4d14d23a104b17f7958
|
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 ProbC_2 {
public static void main(String[] args) {
FastScanner fs = new FastScanner(System.in);
int t = fs.nextInt();
while(t-- > 0){
int n = fs.nextInt();
String[][] arr = new String[3][n];
for(int i=0;i<3;i++){
arr[i] = fs.nextArray(n);
};
int[] abc = new int[3];
HashMap<String,Integer> hm = new HashMap<>();
for(String[] i: arr){
for(String j: i){
hm.putIfAbsent(j,0);
hm.put(j,hm.get(j)+1);
}
}
// System.out.println(hm);
for(int i=0;i<3;i++){
for(int j=0;j<n;j++){
if(hm.get(arr[i][j]) == 1){
abc[i] += 3;
}
else if(hm.get(arr[i][j]) == 2){
abc[i] += 1;
}
}
}
System.out.println(abc[0]+" "+abc[1]+" "+abc[2]);
}
}
static class FastScanner {
private BufferedReader reader = null;
private StringTokenizer tokenizer = null;
public FastScanner(InputStream in) {
reader = new BufferedReader(new InputStreamReader(in));
tokenizer = null;
}
public String next() {
if (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public String nextLine() {
if (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
return reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken("\n");
}
public long nextLong() {
return Long.parseLong(next());
}
public int nextInt() {
return Integer.parseInt(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public int[] nextIntArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public long[] nextLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public ArrayList<Integer> nextIntArrayList(int n) {
ArrayList<Integer> a = new ArrayList<>();
for (int i = 0; i < n; i++)
a.add(nextInt());
return a;
}
public String[] nextArray(int n) {
String[] a = new String[n];
for (int i = 0; i < n; i++)
a[i] = next();
return a;
}
public ArrayList<String> nextArrayList(int n) {
ArrayList<String> a = new ArrayList<>();
for (int i = 0; i < n; i++)
a.add(next());
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
|
dd050caef3354f11cd412c5d067912f9
|
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 C_Word_Game {
public static void main(String args[]) throws IOException {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0)
{
int n=sc.nextInt();
String a[][]=new String[3][n];
HashMap<String,Integer> hmap = new HashMap<>();
int aa[]=new int[3];
for(int i=0;i<3;i++)
{
for(int j=0;j<n;j++)
{
a[i][j]=sc.next();
// int val = hmap.get(a[i][j]);
// hmap.put(a[i][j],val+1 );
if(hmap.containsKey(a[i][j]))
{
hmap.put(a[i][j], hmap.get(a[i][j]) + 1);
}
else
{
hmap.put(a[i][j], 1);
}
}
}
for(int i=0;i<3;i++)
{
for(int j=0;j<n;j++)
{
if(hmap.get(a[i][j])==1)
{
aa[i]+=3;
}
else if(hmap.get(a[i][j])==2)
{
aa[i]+=1;
}
}
}
// String b[]=new String[n];
// String c[]=new String[n];
// ArrayList<String> aa=new ArrayList<>();
// ArrayList<String> bb=new ArrayList<>();
// ArrayList<String> cc=new ArrayList<>();
// int an=3*n;
// int bn=3*n;
// int cn=0;
// for(int j=0;j<n;j++)
// {
// a[j]=sc.next();
// aa.add(a[j]);
// }
// for(int j=0;j<n;j++)
// {
// b[j]=sc.next();
// bb.add(b[j]);
// }
// for(int j=0;j<n;j++)
// {
// c[j]=sc.next();
// cc.add(c[j]);
// }
// if(aa.contains(c[j])==false && bb.contains(c[j])==false)
// {
// cn=cn+3;
// if(aa.contains(b[j])==true)
// {
// an=an-2;
// bn=bn-2;
// }
// }
// else if(aa.contains(c[j])==true && bb.contains(c[j])==true){
// an=an-3;
// bn=bn-3;
// }
// else{
// if(aa.contains(c[j])==true && bb.contains(c[j])==false)
// {
// an=an-2;
// cn=cn+1;
// }
// else if(aa.contains(c[j])==false && bb.contains(c[j])==true)
// {
// bn=bn-2;
// cn=cn+1;
// }
// // else
// for(int j=0;j<n;j++)
// {
// if(bb.contains(a[j])==false && cc.contains(a[j])==false)
// {
// an=an+3;
// }
// else if(bb.contains(a[j])==true && cc.contains(a[j])==true)
// {
// an=an+0;
// }
// // else{
// // if(bb.contains(a[j])==false && cc.contains(a[j])==true)
// // {
// // bn=bn+1;
// // }
// }
// }
System.out.println(aa[0]+" "+aa[1]+" "+aa[2]);
}
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
|
01534d6725fa1cfd99d8517959eaa250
|
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.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.StringTokenizer;
import java.util.function.Supplier;
import java.util.stream.Collectors;
public class codeforces {
//-----------PrintWriter for faster output---------------------------------
public static PrintWriter out;
public static int cnt;
//-----------MyScanner class for faster input----------
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
static boolean isPrime(int n)
{
// Corner cases
if (n <= 1)
return false;
if (n <= 3)
return true;
// This is checked so that we can skip
// middle five numbers in below loop
if (n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
public static int reverseBits(int n)
{
int rev = 0;
// traversing bits of 'n'
// from the right
while (n > 0)
{
// bitwise left shift
// 'rev' by 1
rev <<= 1;
// if current bit is '1'
if ((int)(n & 1) == 1)
rev ^= 1;
// bitwise right shift
//'n' by 1
n >>= 1;
}
// required number
return rev;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
MyScanner sc = new MyScanner();
out = new PrintWriter(new BufferedOutputStream(System.out));
StringBuilder sb = new StringBuilder();
int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
String arr[]=new String[n];
String brr[]=new String[n];
String crr[]=new String[n];
int ans1=0,ans2=0,ans3=0;
HashMap<String,Integer> x=new HashMap<String,Integer>();
for(int i=0;i<n;i++)
{
arr[i]=sc.next();
if(!x.containsKey(arr[i]))
{
x.put(arr[i],1);
}
else
{
x.put(arr[i], x.get(arr[i])+1);
}
}
for(int i=0;i<n;i++)
{
brr[i]=sc.next();
if(!x.containsKey(brr[i]))
{
x.put(brr[i],1);
}
else
{
x.put(brr[i], x.get(brr[i])+1);
}
}
for(int i=0;i<n;i++)
{
crr[i]=sc.next();
if(!x.containsKey(crr[i]))
{
x.put(crr[i],1);
}
else
{
x.put(crr[i], x.get(crr[i])+1);
}
}
for(int i=0;i<n;i++)
{
if(x.get(arr[i])==1)
{
ans1=ans1+3;
}
if(x.get(arr[i])==2)
{
ans1++;
}
}
for(int i=0;i<n;i++)
{
if(x.get(brr[i])==1)
{
ans2=ans2+3;
}
if(x.get(brr[i])==2)
{
ans2++;
}
}
for(int i=0;i<n;i++)
{
if(x.get(crr[i])==1)
{
ans3=ans3+3;
}
if(x.get(crr[i])==2)
{
ans3++;
}
}
out.println(ans1+" "+ans2+" "+ans3);
}
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
|
12e839f17dbfe1e81ecbb8c672d86c60
|
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 Rough {
static ArrayList<Long> ar=new ArrayList<>();
static long an=998244353;
//static long an2=(long)1E18;
public static void main(String[] args) throws Exception {
Scanner s = new Scanner(System.in);
PrintWriter pw = new PrintWriter(System.out);
int tc = s.nextInt();
for (int t = 1; t <= tc; t++) {
int n=s.nextInt();
s.nextLine();
ArrayList<String> ar=new ArrayList<>();
ArrayList<String> ar1=new ArrayList<>();
ArrayList<String> ar2=new ArrayList<>();
HashMap<String,Integer> hm=new HashMap<>();
for(int i=0;i<n;i++) {
String in=s.next();
ar.add(in);
maping(in,1,hm);
}
for(int i=0;i<n;i++) {
String in=s.next();
ar1.add(in);
maping(in,1,hm);
}
for(int i=0;i<n;i++) {
String in=s.next();
ar2.add(in);
maping(in,1,hm);
}
int cnt=0;
int cnt1=0;
int cnt2=0;
for(int i=0;i<n;i++) {
String in=ar.get(i);
if(hm.get(in)==2)cnt++;
else if(hm.get(in)==1)cnt+=3;
}
for(int i=0;i<n;i++) {
String in=ar1.get(i);
if(hm.get(in)==2)cnt1++;
else if(hm.get(in)==1)cnt1+=3;
}for(int i=0;i<n;i++) {
String in=ar2.get(i);
if(hm.get(in)==2)cnt2++;
else if(hm.get(in)==1)cnt2+=3;
}
pw.println(cnt+" "+cnt1+" "+cnt2);
}
pw.close();
}
static boolean ispalin(String in) {
StringBuilder sb = new StringBuilder(in);
if (sb.reverse().toString().equals(in))
return true;
else
return false;
}
static void maping(String key, int val, HashMap<String, Integer> hm) {
if (hm.containsKey(key)) {
int valu = hm.get(key) + 1;
hm.put(key, valu);
} else
hm.put(key, val);
}
static final Random ran = new Random();
static void sort(int[] ar) {
int n = ar.length;
for (int i = 0; i < n; i++) {
int doer = ran.nextInt(n), temp = ar[doer];
ar[doer] = ar[i];
ar[i] = temp;
}
Arrays.sort(ar);
}
static void sort(long[] ar) {
int n = ar.length;
for (int i = 0; i < n; i++) {
int doer = ran.nextInt(n);
long temp = ar[doer];
ar[doer] = ar[i];
ar[i] = temp;
}
Arrays.sort(ar);
}
}
|
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
|
782e2c614fbf672129078e70b5dd731b
|
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 input=new Scanner(System.in);
int testCase=input.nextInt();
for(int i=0;i<testCase;i++){
int wordsNumber=input.nextInt();
Set<String> player1=new HashSet();
Set<String>player2=new HashSet();
Set<String>player3=new HashSet();
int first=0,second=0,third=0;
for(int w=0;w<3;w++){
for(int g=0;g<wordsNumber;g++){
if(w==0){
player1.add(input.next());
}
else if(w==1){
player2.add(input.next());
}
else {
player3.add(input.next());
}
}
}
for(String word:player1){
if(player2.contains(word) && player3.contains(word)){
player2.remove(word);
player3.remove(word);
}
else if(player2.contains(word)){
player2.remove(word);
first++;
second++;
}
else if(player3.contains(word)){
first++;
third++;
player3.remove(word);
}
else first+=3;
}
for(String word:player2){
if(player3.contains(word)){
second++;
third++;
player3.remove(word);
}
else second+=3;
}
third+=player3.size()*3;
System.out.println(first+" "+second+" "+third);
}
}
}
|
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
|
28583809e736a025dbca898aab094955
|
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 threeQ {
static class Pair{
int index;
int count;
Pair(int index, int count){
this.index=index;
this.count=count;
}
}
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
int t=sc.nextInt();
while(t--!=0) {
int n=sc.nextInt();
sc.nextLine();
HashMap<String, Pair>map= new HashMap<>();
String s1=sc.nextLine();
String s2=sc.nextLine();
String s3=sc.nextLine();
String[] a1=s1.split(" ");
String[] a2=s2.split(" ");
String[] a3=s3.split(" ");
for(int i=0;i<a1.length;i++) {
if(map.containsKey(a1[i])) {
int l=map.get(a1[i]).index ;
int r=map.get(a1[i]).count;
map.put(a1[i] , new Pair(l+3,r+1));
}else {
map.put(a1[i], new Pair(3,1));
}
if(map.containsKey(a2[i])) {
int l=map.get(a2[i]).index ;
int r=map.get(a2[i]).count;
map.put(a2[i], new Pair(l+5,r+1));
}else {
map.put(a2[i], new Pair(5,1));
}
if(map.containsKey(a3[i])) {
int l=map.get(a3[i]).index ;
int r=map.get(a3[i]).count;
map.put(a3[i], new Pair(l+7,r+1));
}else {
map.put(a3[i], new Pair(7,1));
}
}
int[] ans= new int[3];
for(Map.Entry<String, Pair> entry:map.entrySet()) {
if(entry.getValue().count==1) {
int m=entry.getValue().index;
if(m==3) {
ans[0]+=3;
}else if(m==5) {
ans[1]+=3;
}else {
ans[2]+=3;
}
}
else if(entry.getValue().count==2) {
int m=entry.getValue().index;
if(m==8) {
ans[0]+=1;
ans[1]+=1;
}else if(m==12) {
ans[1]+=1;
ans[2]+=1;
}else if(m==10){
ans[2]+=1;
ans[0]+=1;
}
}
}
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 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
|
7db3a489a87d37f01bc3827d884c9a59
|
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.lang.reflect.Array;
import java.util.*;
public class Main
{
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
if(st.hasMoreTokens()){
str = st.nextToken("\n");
}
else{
str = br.readLine();
}
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args)
{
FastReader sc=new FastReader();
int tc=sc.nextInt();
while(tc-->0)
{
int n=sc.nextInt();
HashSet<String> s1=new HashSet<>();
HashSet<String> s2=new HashSet<>();
HashSet<String> s3=new HashSet<>();
for(int i=0;i<n;i++)
{
s1.add(sc.next());
}
for(int i=0;i<n;i++)
{
s2.add(sc.next());
}
for(int i=0;i<n;i++)
{
s3.add(sc.next());
}
int p1=0,p2=0,p3=0;
for(String s:s1)
{
if(s2.contains(s)&&s3.contains(s))
{}
else if(!s2.contains(s)&& !s3.contains(s))
{
p1+=3;
}
else
{
p1+=1;
}
}
for(String s:s2)
{
if(s1.contains(s)&&s3.contains(s))
{}
else if(!s1.contains(s)&& !s3.contains(s))
{
p2+=3;
}
else
{
p2+=1;
}
}
for(String s:s3)
{
if(s2.contains(s)&&s1.contains(s))
{}
else if(!s2.contains(s)&& !s1.contains(s))
{
p3+=3;
}
else
{
p3+=1;
}
}
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
|
cba79b71e2252ed6fabcebeead82022c
|
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();
HashMap<String,ArrayList<Integer>> hm=new HashMap<>();
String arr[][]=new String[3][n];
for(int j=0;j<3;j++)
{
for(int k=0;k<n;k++)
{
arr[j][k]=sc.next();
if(hm.containsKey(arr[j][k]))
{
ArrayList<Integer> temp=hm.get(arr[j][k]);
temp.add(j);
hm.put(arr[j][k],temp);
}
else{
ArrayList<Integer> temp=new ArrayList<>();
temp.add(j);
hm.put(arr[j][k],temp);
}
}
}
int counta=0;
int countb=0;
int countc=0;
for(String str : hm.keySet())
{
if(hm.get(str).size()==2)
{
for(int num: hm.get(str))
{
if(num==0)
{
counta++;
}
if(num==1)
{
countb++;
}
if(num==2)
{
countc++;
}
}
}
else if(hm.get(str).size()==1)
{
int num=hm.get(str).get(0);
if(num==0)
{
counta+=3;
}
if(num==1)
{
countb+=3;
}
if(num==2)
{
countc+=3;
}
}
}
System.out.println(counta+ " "+countb + " "+countc);
}
}
}
|
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
|
0b0b689548cb090e48ea0d115c9a4e68
|
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.sql.SQLOutput;
import java.util.*;
public class Algorithms {
static FastScanner scan = new FastScanner();
static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
int t = scan.nextInt();
for (int i = 1; i <= t; i++) {
solve();
}
}
static void solve() {
int[] ans = new int[4];
int n = scan.nextInt();
String[] a = new String[n];
String[] b = new String[n];
String[] c = new String[n];
Map<String, Integer> map = new HashMap<>();
for (int i = 0; i < n; i++) {
a[i] = scan.next();
map.put(a[i], map.getOrDefault(a[i], 0) + 1);
}
for (int i = 0; i < n; i++) {
b[i]= scan.next();
map.put(b[i], map.getOrDefault(b[i], 0) + 1);
}
for (int i = 0; i < n; i++) {
c[i]= scan.next();
map.put(c[i], map.getOrDefault(c[i], 0) + 1);
}
for (int i = 0; i < n; i++) {
if (map.get(a[i]) == 1)
{
ans[1] += 3;
}
else if (map.get(a[i]) == 2) {
ans[1]++;
}
if (map.get(b[i]) == 1){
ans[2] += 3;
}
else if (map.get(b[i]) == 2) { ans[2]++;
}
if (map.get(c[i]) == 1) {
ans[3] += 3;
}
else if (map.get(c[i]) == 2){
ans[3]++;
}
}
System.out.println(ans[1] + " "+ans[2]+ " "+ ans[3]);
}
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;
}
static boolean isSorted(int[] arr) {
for (int i = 1; i < arr.length; i++) {
if (arr[i - 1] > arr[i])
return false;
}
return true;
}
static long gcd(long A, long B) {
if (B == 0) return A;
return gcd(B, A % B);
}
static boolean isInteger(int n) {
return Math.sqrt(n) % 1 == 0;
}
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens()) try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = nextInt();
return a;
}
String[] readStringArray(int n) {
String[] arr = new String[n];
for (int i = 0; i < n; i++) arr[i] = next();
return arr;
}
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
|
1c798a69be09205bf9e24d32a5eb8010
|
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 Reader r = new Reader();
static StringBuilder sb = new StringBuilder();
public static void main(String args[]) throws IOException {
int t = r.readInt();
while(t-->0){
solve();
}
System.out.println(sb);
}
static void solve() throws IOException{
int n = r.readInt();
String[] s1 = r.readLine().split(" ");
String[] s2 = r.readLine().split(" ");
String[] s3 = r.readLine().split(" ");
int[][][] cnt = new int[26][26][26];
int[] score = new int[3];
for(String s: s1)
cnt[s.charAt(0)-'a'][s.charAt(1)-'a'][s.charAt(2)-'a']++;
for(String s: s2)
cnt[s.charAt(0)-'a'][s.charAt(1)-'a'][s.charAt(2)-'a']++;
for(String s: s3)
cnt[s.charAt(0)-'a'][s.charAt(1)-'a'][s.charAt(2)-'a']++;
for(String s: s1){
if(cnt[s.charAt(0)-'a'][s.charAt(1)-'a'][s.charAt(2)-'a']==1)
score[0]+=3;
else if(cnt[s.charAt(0)-'a'][s.charAt(1)-'a'][s.charAt(2)-'a']==2)
score[0]+=1;
}
for(String s: s2){
if(cnt[s.charAt(0)-'a'][s.charAt(1)-'a'][s.charAt(2)-'a']==1)
score[1]+=3;
else if(cnt[s.charAt(0)-'a'][s.charAt(1)-'a'][s.charAt(2)-'a']==2)
score[1]+=1;
}
for(String s: s3){
if(cnt[s.charAt(0)-'a'][s.charAt(1)-'a'][s.charAt(2)-'a']==1)
score[2]+=3;
else if(cnt[s.charAt(0)-'a'][s.charAt(1)-'a'][s.charAt(2)-'a']==2)
score[2]+=1;
}
sb.append(score[0]).append(" ").append(score[1]).append(" ").append(score[2]).append("\n");
}
}
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 String readLine() throws IOException {
byte[] buf = new byte[5000]; // 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 readInt() throws IOException {
int ret = 0;
byte c = read();
while(c <= ' '){ c = read();}
boolean neg = (c == '-');
if(neg) c = read();
do{
ret = (ret<<3) + (ret<<1) + c - '0';
} while ((c = read()) >= '0' && c <= '9');
return neg ? -ret : ret;
}
public long readLong() throws IOException {
long ret = 0;
byte c = read();
while(c <= ' '){ c = read();}
boolean neg = (c == '-');
if(neg) c = read();
do{
ret = (ret<<3) + (ret<<1) + c - '0';
} while ((c = read()) >= '0' && c <= '9');
return neg ? -ret : ret;
}
private void fillBuffer() throws IOException {
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if(bytesRead == -1) buffer[0] = -1;
}
private byte read() throws IOException {
if(bufferPointer == bytesRead) fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException {
if(din==null) return;
din.close();
}
}
|
Java
|
["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
|
2fbe5ea00d5f12cc9be0883d48d65512
|
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.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException{
BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out));
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
List<String> list1=new ArrayList<>();
List<String> list2=new ArrayList<>();
List<String> list3=new ArrayList<>();
Map<String,Integer> map=new HashMap<>();
int n=sc.nextInt();
for(int i=0;i<n;i++){
String temp= sc.next();
list1.add(temp);
map.put(temp,map.getOrDefault(temp,0)+1);
}
for(int i=0;i<n;i++){
String temp= sc.next();
list2.add(temp);
map.put(temp,map.getOrDefault(temp,0)+1);
}
for(int i=0;i<n;i++){
String temp= sc.next();
list3.add(temp);
map.put(temp,map.getOrDefault(temp,0)+1);
}
int ans1=0;
int ans2=0;
int ans3=0;
for(int i=0;i<n;i++){
String temp=list1.get(i);
int count=map.get(temp);
// if(list1.contains(temp)){
// count++;
// }
// if(list2.contains(temp)){
// count++;
// }
// if(list3.contains(temp)){
// count++;
// }
if(count==2){
ans1+=1;
}
else if(count==1){
ans1+=3;
}
}
for(int i=0;i<n;i++){
String temp=list2.get(i);
int count=map.get(temp);
// if(list1.contains(temp)){
// count++;
// }
// if(list2.contains(temp)){
// count++;
// }
// if(list3.contains(temp)){
// count++;
// }
if(count==2){
ans2+=1;
}
else if(count==1){
ans2+=3;
}
}
for(int i=0;i<n;i++){
String temp=list3.get(i);
int count=map.get(temp);
// if(list1.contains(temp)){
// count++;
// }
// if(list2.contains(temp)){
// count++;
// }
// if(list3.contains(temp)){
// count++;
// }
if(count==2){
ans3+=1;
}
else if(count==1){
ans3+=3;
}
}
System.out.println(ans1+" "+ans2+" "+ans3);
}
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
|
218a2e5773060a2a0541fcea1732b812
|
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 R817C {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int t = scan.nextInt();
while(t-->0){
int n = scan.nextInt();
scan.nextLine();
HashMap<String, Integer> map = new HashMap<>();
String[] a = scan.nextLine().split(" ");
String[] b = scan.nextLine().split(" ");
String[] c = scan.nextLine().split(" ");
for(int i = 0;i<n;i++){
map.put(a[i],map.getOrDefault(a[i],0)+1);
map.put(b[i],map.getOrDefault(b[i],0)+1);
map.put(c[i],map.getOrDefault(c[i],0)+1);
}
int[] points = new int[3];
int[] vals = {0,3,1,0};
for(int i = 0;i<n;i++){
points[0] += vals[map.get(a[i])];
points[1] += vals[map.get(b[i])];
points[2] += vals[map.get(c[i])];
}
System.out.println(points[0]+" "+points[1]+" "+points[2]);
}
}
static class JS {
public int BS = 1 << 16;
public char NC = (char) 0;
byte[] buf = new byte[BS];
int bId = 0, size = 0;
char c = NC;
double num = 1;
BufferedInputStream in;
public JS() {
in = new BufferedInputStream(System.in, BS);
}
public JS(String s) throws FileNotFoundException {
in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
}
public char nextChar() {
while (bId == size) {
try {
size = in.read(buf);
} catch (Exception e) {
return NC;
}
if (size == -1) return NC;
bId = 0;
}
return (char) buf[bId++];
}
public int nextInt() {
return (int) nextLong();
}
public long nextLong() {
num = 1;
boolean neg = false;
if (c == NC) c = nextChar();
for (; (c < '0' || c > '9'); c = nextChar()) {
if (c == '-') neg = true;
}
long res = 0;
for (; c >= '0' && c <= '9'; c = nextChar()) {
res = (res << 3) + (res << 1) + c - '0';
num *= 10;
}
return neg ? -res : res;
}
public double nextDouble() {
double cur = nextLong();
return c != '.' ? cur : cur + nextLong() / num;
}
public String next() {
StringBuilder res = new StringBuilder();
while (c <= 32) c = nextChar();
while (c > 32) {
res.append(c);
c = nextChar();
}
return res.toString();
}
public String nextLine() {
StringBuilder res = new StringBuilder();
while (c <= 32) c = nextChar();
while (c != '\n') {
res.append(c);
c = nextChar();
}
return res.toString();
}
public boolean hasNext() {
if (c > 32) return true;
while (true) {
c = nextChar();
if (c == NC) return false;
else if (c > 32) return true;
}
}
}
}
|
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
|
d7e1912a68eb37fbbddd3b2ef3f39548
|
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 p=1;p<=t;p++)
{
int n = in.nextInt();
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();
}
}
int x=0,y=0,z=0;
HashMap<String,Integer> map1 = new HashMap<>();
HashMap<String,Integer> map2 = new HashMap<>();
HashMap<String,Integer> map3 = new HashMap<>();
for(int i=0;i<n;i++)
map1.put(s[0][i],1);
for(int i=0;i<n;i++)
map2.put(s[1][i],1);
for(int i=0;i<n;i++)
map3.put(s[2][i],1);
for(int i=0;i<n;i++)
{
if(map1.containsKey(s[0][i]) && map2.containsKey(s[0][i]) && (map3.containsKey(s[0][i])))
{}
else if(map1.containsKey(s[0][i]) && map2.containsKey(s[0][i]) && (!map3.containsKey(s[0][i])))
{
x++;
}
else if(map1.containsKey(s[0][i]) && !map2.containsKey(s[0][i]) && (map3.containsKey(s[0][i])))
{
x++;
}
else if(map1.containsKey(s[0][i]))
x+=3;
}
for(int i=0;i<n;i++)
{
if(map1.containsKey(s[1][i]) && map2.containsKey(s[1][i]) && (map3.containsKey(s[1][i])))
{}
else if(map1.containsKey(s[1][i]) && map2.containsKey(s[1][i]) && (!map3.containsKey(s[1][i])))
{
y++;
}
else if(!map1.containsKey(s[1][i]) && map2.containsKey(s[1][i]) && (map3.containsKey(s[1][i])))
{
y++;
}
else if(map2.containsKey(s[1][i]))
y+=3;
}
for(int i=0;i<n;i++)
{
if(map1.containsKey(s[2][i]) && map2.containsKey(s[2][i]) && (map3.containsKey(s[2][i])))
{}
else if(!map1.containsKey(s[2][i]) && map2.containsKey(s[2][i]) && (map3.containsKey(s[2][i])))
{
z++;
}
else if(map1.containsKey(s[2][i]) && !map2.containsKey(s[2][i]) && (map3.containsKey(s[2][i])))
{
z++;
}
else if(map3.containsKey(s[2][i]))
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 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
|
15d7877467aaf1c34d7c6136381142a3
|
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.HashSet;
import java.util.StringTokenizer;
// https://codeforces.com/contest/1722/problem/C
public class CF1722C {
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 {
if (st.hasMoreTokens()) {
str = st.nextToken("\n");
} else {
str = br.readLine();
}
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args) {
FastReader sc = new FastReader();
int t = sc.nextInt();
while(t-->0) {
int n = sc.nextInt();
HashSet<String> player1 = new HashSet<>();
HashSet<String> player2 = new HashSet<>();
HashSet<String> player3 = new HashSet<>();
for (int i = 0; i < n; i++) player1.add(sc.next());
for (int i = 0; i < n; i++) player2.add(sc.next());
for (int i = 0; i < n; i++) player3.add(sc.next());
int Points1 = 0;
int Points2 = 0;
int Points3 = 0;
for (String str : player1) {
if(player2.contains(str) && player3.contains(str));
else if(player2.contains(str) || player3.contains(str)) Points1++;
else Points1 += 3;
}
for (String str : player2) {
if(player1.contains(str) && player3.contains(str));
else if(player1.contains(str) || player3.contains(str)) Points2++;
else Points2 += 3;
}
for (String str : player3) {
if(player1.contains(str) && player2.contains(str));
else if(player1.contains(str) || player2.contains(str)) Points3++;
else Points3 +=3;
}
System.out.printf("%d %d %d \n", Points1, Points2, Points3);
}
}
}
|
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
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.