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
|
210a2dc3a00fb516ccbfbfc4585fab1d
|
train_109.jsonl
|
1661871000
|
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
|
256 megabytes
|
import java.util.HashSet;
import java.util.Scanner;
public class codefoword {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for(int i=0;i<n;i++){
int m = sc.nextInt();
HashSet<String> hm1 = new HashSet<>();
HashSet<String> hm2 = new HashSet<>();
HashSet<String> hm3 = new HashSet<>();
String[][] arr = new String[3][m];
int[] nums = new int[3];
for(int j=0;j<3;j++){
nums[j]=0;
}
for(int j=0;j<3;j++){
for(int k=0;k<m;k++){
arr[j][k]=sc.next();
}
}
for(int j=0;j<m;j++){
hm1.add(arr[0][j]);
}
for(int j=0;j<m;j++){
hm2.add(arr[1][j]);
}
for(int j=0;j<m;j++){
hm3.add(arr[2][j]);
}
for(int j=0;j<m;j++) {
if (hm2.contains(arr[0][j])){
if(!(hm3.contains(arr[0][j]))){
nums[0]+=1;
}
} else if (hm3.contains(arr[0][j])) {
nums[0]+=1;
} else{
nums[0]+=3;
}
}
for(int j=0;j<m;j++) {
if (hm1.contains(arr[1][j])){
if(!(hm3.contains(arr[1][j]))){
nums[1]+=1;
}
} else if (hm3.contains(arr[1][j])) {
nums[1]+=1;
} else{
nums[1]+=3;
}
}
for(int j=0;j<m;j++) {
if (hm1.contains(arr[2][j])){
if(!(hm2.contains(arr[2][j]))){
nums[2]+=1;
}
} else if (hm2.contains(arr[2][j])) {
nums[2]+=1;
} else{
nums[2]+=3;
}
}
System.out.println("");
for(int k=0;k<3;k++){
System.out.print(nums[k]+" ");
}
}
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
a69debff52f902900306161ea940241c
|
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 AAAPractice {
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,ArrayList<Integer>>hm = new HashMap<>();
for(int k =1;k<=3;k++)
{
for(int i =0;i<n;i++)
{
String s =sc.next();
if(hm.containsKey(s))
{
ArrayList<Integer>al = hm.get(s);
al.add(k);
hm.put(s, al);
}
else
{
ArrayList<Integer>al = new ArrayList<>();
al.add(k);
hm.put(s, al);
}
}
}
int first =0;
int second =0;
int third =0;
for(Map.Entry<String, ArrayList<Integer>>e : hm.entrySet())
{
ArrayList<Integer> al = e.getValue();
if(al.size()==1)
{
int ele = al.get(0);
if(ele==1)
first+=3;
else if(ele==2)
second+=3;
else
third+=3;
}
else if(al.size()==2)
{
int f = al.get(0);
int s = al.get(1);
if(f==1||s==1)
{
first+=1;
}
if(f==2||s==2)
{
second+=1;
}
if(f==3||s==3)
{
third+=1;
}
}
}
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 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
34cd832c70a5a86acd9aa547afdcd169
|
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.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.PrintWriter;
import java.util.HashMap;
public class MyClass {
public static void main(String[] args) {
InputReader scanner = new InputReader(System.in);
PrintWriter output = new PrintWriter(System.out);
int T = scanner.nextInt();
while (T-- > 0) {
int f = 0;
int s = 0;
int th = 0;
int n = scanner.nextInt();
String[] s1 = new String[n];
String[] s2 = new String[n];
String[] s3 = new String[n];
HashMap<String, Integer> map = new HashMap<>();
for (int i = 0; i < n; i++) {
s1[i] = scanner.next();
map.put(s1[i], 0);
}
for (int i = 0; i < n; i++) {
s2[i] = scanner.next();
if (map.containsKey(s2[i])) {
map.put(s2[i], 1);
} else {
map.put(s2[i], 0);
}
}
for (int i = 0; i < n; i++) {
s3[i] = scanner.next();
if (map.containsKey(s3[i])) {
if (map.get(s3[i]) == 0) {
map.put(s3[i], 1);
} else {
map.put(s3[i], 2);
}
} else {
map.put(s3[i], 0);
}
}
for (int i = 0; i < n; i++) {
if (map.get(s1[i]) == 0) {
f += 3;
} else if (map.get(s1[i]) == 1) {
f++;
}
}
for (int i = 0; i < n; i++) {
if (map.get(s2[i]) == 0) {
s += 3;
} else if (map.get(s2[i]) == 1) {
s++;
}
}
for (int i = 0; i < n; i++) {
if (map.get(s3[i]) == 0) {
th += 3;
} else if (map.get(s3[i]) == 1) {
th++;
}
}
output.println(f + " " + s + " " + th);
}
output.close();
}
static class InputReader {
BufferedReader reader;
StringTokenizer tokenizer;
InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.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 = reader.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 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
20a668f3220283d11b891e6132d4b56d
|
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 MyClass {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();
while (t-- > 0) {
int f = 0;
int s = 0;
int th = 0;
int n = scanner.nextInt();
String[] s1 = new String[n];
String[] s2 = new String[n];
String[] s3 = new String[n];
HashMap<String, Integer> map = new HashMap<>();
for (int i = 0; i < n; i++) {
s1[i] = scanner.next();
map.put(s1[i], 0);
}
for (int i = 0; i < n; i++) {
s2[i] = scanner.next();
if (map.containsKey(s2[i])) {
map.put(s2[i], 1);
} else {
map.put(s2[i], 0);
}
}
for (int i = 0; i < n; i++) {
s3[i] = scanner.next();
if (map.containsKey(s3[i])) {
if (map.get(s3[i]) == 0) {
map.put(s3[i], 1);
} else {
map.put(s3[i], 2);
}
} else {
map.put(s3[i], 0);
}
}
for (int i = 0; i < n; i++) {
if (map.get(s1[i]) == 0) {
f += 3;
} else if (map.get(s1[i]) == 1) {
f++;
}
}
for (int i = 0; i < n; i++) {
if (map.get(s2[i]) == 0) {
s += 3;
} else if (map.get(s2[i]) == 1) {
s++;
}
}
for (int i = 0; i < n; i++) {
if (map.get(s3[i]) == 0) {
th += 3;
} else if (map.get(s3[i]) == 1) {
th++;
}
}
System.out.println(f + " " + s + " " + th);
}
scanner.close();
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
f7d2affc8290b7e7bb7b7de2de6e6895
|
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 Main{
static Scanner scn;
public static void main(String[] args){
scn = new Scanner(System.in);
int t = scn.nextInt();
while(t-- > 0){
int wordLen = scn.nextInt();
scn.nextLine();
String str1 = scn.nextLine();
String str2 = scn.nextLine();
String str3 = scn.nextLine();
String[] strArr1 = str1.split(" ");
String[] strArr2 = str2.split(" ");
String[] strArr3 = str3.split(" ");
HashSet<String> hs1 = new HashSet<>();
for(String str : strArr1) hs1.add(str);
HashSet<String> hs2 = new HashSet<>();
for(String str : strArr2) hs2.add(str);
HashSet<String> hs3 = new HashSet<>();
for(String str : strArr3) hs3.add(str);
int score1 = 0, score2 = 0, score3 = 0;
for(String str : hs1){
boolean contain2 = false;
boolean contain3 = false;
if(hs2.contains(str)){
contain2 = true;
hs2.remove(str);
}
if(hs3.contains(str)){
contain3 = true;
hs3.remove(str);
}
if(contain2 && !contain3){
score1++;
score2++;
}
else if(!contain2 && contain3){
score1++;
score3++;
}
else if(!contain2 && !contain3){
score1 += 3;
}
}
hs1 = new HashSet<>();
for(String str : hs2){
boolean contain3 = false;
if(hs3.contains(str)){
contain3 = true;
hs3.remove(str);
}
if(contain3){
score3++;
score2++;
}
else if(!contain3){
score2 += 3;
}
}
hs2 = new HashSet<>();
for(String str : hs3){
score3 += 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 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
ae7712a9a0240c82fd8814f0cedbdcd7
|
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;
import java.util.Set;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for (int i = 0; i < t; ++i) {
int ttt = in.nextInt();
in.nextLine();
String temp1 = in.nextLine();
String[] player1 = temp1.split(" ");
String temp2 = in.nextLine();
String[] player2 = temp2.split(" ");
String temp3 = in.nextLine();
String[] player3 = temp3.split(" ");
HashMap<String, Integer> countOfString = new HashMap<>();
for (String j : player1) {
if (countOfString.containsKey(j))
countOfString.put(j, countOfString.get(j) + 1);
else
countOfString.put(j, 1);
}
for (String j : player2) {
if (countOfString.containsKey(j))
countOfString.put(j, countOfString.get(j) + 1);
else
countOfString.put(j, 1);
}
for (String j : player3) {
if (countOfString.containsKey(j))
countOfString.put(j, countOfString.get(j) + 1);
else
countOfString.put(j, 1);
}
Set<String> keys = countOfString.keySet();
int count = 0;
for (String j : player1) {
if (countOfString.get(j) == 1) {
count += 3;
} else if (countOfString.get(j) == 2) {
count++;
}
}
System.out.print(count + " ");
count = 0;
for (String j : player2) {
if (countOfString.get(j) == 1) {
count += 3;
} else if (countOfString.get(j) == 2) {
count++;
}
}
System.out.print(count + " ");
count = 0;
for (String j : player3) {
if (countOfString.get(j) == 1) {
count += 3;
} else if (countOfString.get(j) == 2) {
count++;
}
}
System.out.println(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 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
abb00f9e116f5daef6b16e35f39e308f
|
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;
/**
* Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools
*
* To modify the template, go to Preferences -> Editor -> File and Code Templates -> Other
*/
public class Main {
public static void main(String[] args) {
// Write your solution here
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while (t>0){
int n=sc.nextInt();
String[][] arr=new String[3][n];
Map<String,Integer> map=new HashMap<>();
for(int i=0;i<3;i++){
for(int j=0;j<n;j++){
arr[i][j]=sc.next();
if(map.containsKey(arr[i][j])){
int c=map.get(arr[i][j]);
c++;
map.put(arr[i][j],c);
}else{
map.put(arr[i][j],1);
}
}
}
// System.out.println(map);
int[][] ansArray=new int[1][3];
for(int i=0;i<3;i++){
int c=0;
for(int j=0;j<n;j++) {
if(map.containsKey(arr[i][j])){
int ans=map.get(arr[i][j]);
//System.out.println(arr[i][j]);
if(ans==1){
c=c+3;
}else if(ans==2){
c=c+1;
}
}
//System.out.println();
}
ansArray[0][i]=c;
}
for(int i=0;i<1;i++){
for(int j=0;j<3;j++){
System.out.print(ansArray[i][j]+" ");
}
System.out.println();
}
t--;
// System.out.println(map1);
// System.out.println(map2);
// System.out.println(map3);
}
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
dac3c5691cdc901ca1197219b57bae6a
|
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();
Map<String, List<Integer>> map = new HashMap<>();
int[] points = new int[3];
for(int i=1 ;i<=3 ;i++) {
for(int j=1 ;j<=n ;j++) {
String str = sc.next();
if(!map.containsKey(str))
map.put(str, new ArrayList<>());
map.get(str).add(i);
}
}
for(String key : map.keySet()) {
List<Integer> list = map.get(key);
if(list.size() == 3) continue;
else if(list.size() == 2) {
for(int i : list)
points[i - 1]++;
}
else points[list.get(0) - 1] += 3;
}
for(int i=0 ;i<3 ;i++) System.out.print(points[i] + " ");
System.out.println();
}
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
d246080b7e906852de38326a811408eb
|
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.HashSet;
import java.util.Scanner;
public class wordGame {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
int tests = sc.nextInt();
while(tests-->0) {
int firstPoints = 0;
int secondPoints = 0;
int thirdPoints = 0;
HashSet<String> first = new HashSet<>();
HashSet<String> second = new HashSet<>();
HashSet<String> third = new HashSet<>();
int words = sc.nextInt();
for(int i=0 ;i<words; i++)
first.add(sc.next());
for(int i=0 ;i<words; i++)
second.add(sc.next());
for(int i=0 ;i<words; i++)
third.add(sc.next());
for(String word : first) {
if(second.contains(word) && third.contains(word) ) {
second.remove(word);
third.remove(word);
}
else if (second.contains(word)) {
firstPoints+=1;
secondPoints+=1;
second.remove(word);
}
else if(third.contains(word)) {
firstPoints+=1;
thirdPoints+=1;
third.remove(word);
}
else firstPoints +=3 ;
}
for(String word : second)
{
if(first.contains(word) && third.contains(word)) {
first.remove(word);
third.remove(word);
}
else if(third.contains(word)) {
thirdPoints+=1;
secondPoints+=1;
third.remove(word);
}
// else if(first.contains(word)) //redundant i guess
// {
// firstPoints+=1;
// secondPoints+=1;
// first.remove(word);
// }
else secondPoints+=3;
}
thirdPoints += third.size() *3;
System.out.println(firstPoints +" "+ secondPoints +" "+ thirdPoints);
}
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 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
8c98fd6313d77f9adcc31f629ff2f19c
|
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 GameTask {
private static final int PLAYER_COUNT = 3;
private static final String INPUT = "3\n" +
"1\n" +
"abc\n" +
"def\n" +
"abc\n" +
"3\n" +
"orz for qaq\n" +
"qaq orz for\n" +
"cod for ces\n" +
"5\n" +
"iat roc hem ica lly\n" +
"bac ter iol ogi sts\n" +
"bac roc lly iol iat";
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int roundCount = sc.nextInt();
StringBuilder answer = new StringBuilder();
for (int i = 0; i < roundCount; i++) {
int count = sc.nextInt();
sc.nextLine();
ArrayList<String>[] words = new ArrayList[PLAYER_COUNT];
for (int j = 0; j < words.length; j++) words[j] = new ArrayList<>(count);
HashMap<String, Integer> costs = new HashMap<>();
for (int j = 0; j < count * PLAYER_COUNT; j++) {
String key = sc.next();
words[j / count].add(key);
if (!costs.containsKey(key)) costs.put(key, 3);
else if (costs.get(key) == 3) costs.put(key, 1);
else costs.put(key, 0);
}
for (ArrayList<String> keys : words)
answer.append(getPlayerScore(keys, costs)).append(' ');
answer.setCharAt(answer.length() - 1, '\n');
}
System.out.println(answer);
}
private static int getPlayerScore(ArrayList<String> keys, HashMap<String, Integer> costs) {
int score = 0;
for (String key : keys)
score += costs.get(key);
return score;
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
b17f856c8847b381695e7063ce3eefbd
|
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 scan = new Scanner(System.in);
int tt = scan.nextInt();
for(int t = 1; t <= tt; t++) {
int n = scan.nextInt();
String[][] words = new String[3][n];
HashMap<String, Integer> frequency = new HashMap<>();
for(int i = 0; i < 3; i++) {
for(int j = 0; j < n; j++) {
words[i][j] = scan.next();
int currentFreq = frequency.getOrDefault(words[i][j], 0);
currentFreq++;
frequency.put(words[i][j], currentFreq);
}
}
for(int i = 0; i < 3; i++) {
int currScore = 0;
for(String word : words[i]) {
int freqWord = frequency.get(word);
if(freqWord == 1) currScore += 3;
else if(freqWord == 2) currScore += 1;
}
System.out.print(currScore + " ");
}
System.out.println();
}
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
fdb56c4500eab1ae4b4dc12bc821d9dc
|
train_109.jsonl
|
1661871000
|
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
|
256 megabytes
|
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int tCases = scan.nextInt();
for(int i=0; i < tCases ; i++) {
int n_words = scan.nextInt();
int [] person_score = new int [3];
HashMap<String, Integer> words_occures = new HashMap<>();
HashMap<String, List<Integer>> word_people = new HashMap<>();
for(int p=0; p < 3; p++) {
for(int w =0 ; w< n_words; w++) {
String word = scan.next();
person_score[p]+=3;
if(!words_occures.keySet().contains(word)) {
words_occures.put(word, 1);
List<Integer> prsn = new ArrayList<>();
prsn.add(p);
word_people.put(word, prsn);
}
else {
words_occures.put(word, words_occures.get(word)+1);
word_people.get(word).add(p);
int current_num_of_people = word_people.get(word).size();
for(Integer prn : word_people.get(word)) {
if(current_num_of_people == 2) {
person_score[prn]-=2;
}
else {
person_score[prn]-=1; //occurs 3 times
}
}
if(current_num_of_people==3) {
person_score[2]-=2;
}
}
}
}
System.out.println(person_score[0] + " " + person_score[1] + " " +person_score[2]);
}
scan.close();
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
51c9860d79f7530199230625bdc302e4
|
train_109.jsonl
|
1661871000
|
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
|
256 megabytes
|
import java.io.*;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.StringTokenizer;
/**
* @ClassName : Main
* @Description :
* @Author : KID
* @Date: 2022/8/14
*/
public class Main
{
public static void main(String[] args) throws IOException
{
Reader sc = new Reader();
PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
int tt = sc.nextInt();
while (tt-- != 0)
{
int n = sc.nextInt();
String[] a = sc.nextLine().split(" ");
String[] b = sc.nextLine().split(" ");
String[] c = sc.nextLine().split(" ");
HashSet<String> s1 = new HashSet<>();
HashSet<String> s2 = new HashSet<>();
HashSet<String> s3 = new HashSet<>();
for (String word : a) s1.add(word);
for (String word : b) s2.add(word);
for (String word : c) s3.add(word);
int cnta = 0, cntb = 0, cntc = 0;
for (String word : a)
{
if(s2.contains(word) && s3.contains(word)) continue;
else if(s2.contains(word) || s3.contains(word)) cnta += 1;
else cnta += 3;
}
for (String word : b)
{
if(s1.contains(word) && s3.contains(word)) continue;
else if(s1.contains(word) || s3.contains(word)) cntb += 1;
else cntb += 3;
}
for (String word : c)
{
if(s1.contains(word) && s2.contains(word)) continue;
else if(s2.contains(word) || s1.contains(word)) cntc += 1;
else cntc += 3;
}
out.printf("%d %d %d\n", cnta, cntb, cntc);
}
out.flush();
out.close();
}
static class Reader
{
private BufferedReader bf;
private StringTokenizer st;
public Reader()
{
bf = new BufferedReader(new InputStreamReader(System.in));
st = new StringTokenizer("");
}
public String nextLine() throws IOException
{
return bf.readLine();
}
public String next() throws IOException
{
while (!st.hasMoreTokens())
{
st = new StringTokenizer(bf.readLine());
}
return st.nextToken();
}
public int nextInt() throws IOException
{
return Integer.parseInt(next());
}
public long nextLong() throws IOException
{
return Long.parseLong(next());
}
public double nextDouble() throws IOException
{
return Double.parseDouble(next());
}
public BigInteger nextBigInteger() throws IOException
{
return new BigInteger(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 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
14dd034cecd234e66c1ab6536ac18788
|
train_109.jsonl
|
1661871000
|
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
|
256 megabytes
|
import java.io.*;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.StringTokenizer;
/**
* @ClassName : Main
* @Description :
* @Author : KID
* @Date: 2022/8/14
*/
public class Main
{
public static void main(String[] args) throws IOException
{
Reader sc = new Reader();
PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
int tt = sc.nextInt();
while (tt-- != 0)
{
int n = sc.nextInt();
String[] a = sc.nextLine().split(" ");
String[] b = sc.nextLine().split(" ");
String[] c = sc.nextLine().split(" ");
HashSet<String> s1 = new HashSet<>();
HashSet<String> s2 = new HashSet<>();
HashSet<String> s3 = new HashSet<>();
for (String word : a) s1.add(word);
for (String word : b) s2.add(word);
for (String word : c) s3.add(word);
int cnta = 0, cntb = 0, cntc = 0;
for (String word : a)
{
if(s2.contains(word) && s3.contains(word)) continue;
else if(s2.contains(word) || s3.contains(word)) cnta += 1;
else cnta += 3;
}
for (String word : b)
{
if(s1.contains(word) && s3.contains(word)) continue;
else if(s1.contains(word) || s3.contains(word)) cntb += 1;
else cntb += 3;
}
for (String word : c)
{
if(s1.contains(word) && s2.contains(word)) continue;
else if(s2.contains(word) || s1.contains(word)) cntc += 1;
else cntc += 3;
}
out.printf("%d %d %d\n", cnta, cntb, cntc);
}
out.flush();
out.close();
}
static class Reader
{
private BufferedReader bf;
private StringTokenizer st;
public Reader()
{
bf = new BufferedReader(new InputStreamReader(System.in));
st = new StringTokenizer("");
}
public String nextLine() throws IOException
{
return bf.readLine();
}
public String next() throws IOException
{
while (!st.hasMoreTokens())
{
st = new StringTokenizer(bf.readLine());
}
return st.nextToken();
}
public int nextInt() throws IOException
{
return Integer.parseInt(next());
}
public long nextLong() throws IOException
{
return Long.parseLong(next());
}
public double nextDouble() throws IOException
{
return Double.parseDouble(next());
}
public BigInteger nextBigInteger() throws IOException
{
return new BigInteger(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 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
8f34b3f08135d58d46fffc9540977eeb
|
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 C {
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();
while(t-->0){
Map<String, Integer> set = new HashMap<>();
int cnta = 0, cntb = 0, cntc = 0;
int n = scanner.nextInt();
n*=3;
for(int i=1;i<=n;i++){
String str = scanner.next();
if(i<=n/3){
set.put(str, 3);
continue;
}
else if(i<=(n*2)/3 && i>n/3){
if(set.get(str) != null){
set.put(str, 1);
cnta +=2;
cntb +=2;
}
else set.put(str, 2);
}
else if(set.get(str) == null)
set.put(str, 3);
else{
if(set.get(str) == 1){
set.put(str, 0);
cnta++; cntb++; cntc+=3;
}
else{
if(set.get(str)==2){
cntb+=2; cntc+=2;
}
else{
cnta+=2; cntc+=2;
}
}
}
}
System.out.printf("%d %d %d \n", n-cnta, n-cntb, n-cntc);
}
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
8ebb0e20629cec842dcdc70636a4cf4b
|
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 A {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args) throws IOException
{
FastReader ob =new FastReader();
try
{
int t=ob.nextInt();
while(t--!=0)
{
int n=ob.nextInt();
HashMap<String,List<Integer>> map =new HashMap<>();
for(int i=0;i<3;i++)
{
for(int z=1;z<=n;z++)
{
String str =ob.next();
if(map.containsKey(str))
{
map.get(str).add(i);
}
else
{
map.put(str,new ArrayList<>());
map.get(str).add(i);
}
}
}
int[] score =new int[3];
for(String a:map.keySet())
{
List<Integer> temp =map.get(a);
if(temp.size()==1)
{
score[temp.get(0)]+=3;
}
else if(temp.size()==2)
{
score[temp.get(0)]+=1;
score[temp.get(1)]+=1;
}
}
for(int a:score)
System.out.print(a+" ");
System.out.println();
}
}
catch (Exception e)
{
return;
}
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
6b7689cb446ba91996a7330febca54b8
|
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 scn = new Scanner(System.in);
int t = scn.nextInt();
while (t-- > 0) {
int n = scn.nextInt();
String[][] array = new String[3][n];
HashMap<String, Integer> words = new HashMap<String, Integer>();
int[] points = new int[3];
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array[i].length; j++) {
array[i][j] = scn.next();
if(words.containsKey(array[i][j]))
words.put(array[i][j],words.get(array[i][j])+1);
else
words.put(array[i][j],1);
}
}
for(int i = 0 ; i< array.length ; i++)
{
for(int j = 0 ; j<array[i].length ; j++)
{
int repeating = words.get(array[i][j]);
if(repeating==1)
points[i]+=3;
else if(repeating==2)
points[i]+=1;
}
}
for(int i = 0 ; i<3 ; i++)
System.out.print(points[i] +" ");
System.out.println();
}
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
0afefee4188229712c7adb3864425f6d
|
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 word {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer st;
public static void main(String args[]) throws IOException{
int t = readInt();
for(int i=0; i<t; i++) {
int n = readInt();
int s1 = 0;
int s2 = 0;
int s3 = 0;
HashSet<String>word1 = new HashSet<String>();
HashSet<String>word2 = new HashSet<String>();
HashSet<String>word3 = new HashSet<String>();
for(int j=0; j<n; j++) {
word1.add(next());
}
for(int j=0; j<n; j++) {
word2.add(next());
}
for(int j=0; j<n; j++) {
word3.add(next());
}
for(String s: word1) {
if(word2.contains(s)&&word3.contains(s)) {
word2.remove(s);
word3.remove(s);
} else if(word2.contains(s)) {
s1+=1;
s2+=1;
word2.remove(s);
} else if(word3.contains(s)) {
s1+=1;
s3+=1;
word3.remove(s);
} else {
s1+=3;
}
}
for(String s:word2) {
if(word3.contains(s)){
word3.remove(s);
s2+=1;
s3+=1;
} else {
s2+=3;
}
}
s3+= word3.size()*3;
System.out.println(s1+" "+s2+" "+s3);
}
}
static String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine().trim());
return st.nextToken();
}
static long readLong() throws IOException {
return Long.parseLong(next());
}
static int readInt() throws IOException {
return Integer.parseInt(next());
}
static double readDouble() throws IOException {
return Double.parseDouble(next());
}
static String readLine() throws IOException {
return br.readLine().trim();
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
2e996b253b7166e6ef166e22621bd70a
|
train_109.jsonl
|
1661871000
|
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
|
256 megabytes
|
import java.util.*;
public class C_Word_Game{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int i=0; i<t; i++){
int n=sc.nextInt();
String arr[]=new String[n];
String arr1[]=new String[n];
String arr2[]=new String[n];
Map<String, Integer> map=new HashMap<String, Integer>();
for (int j = 0; j < n; j++) {
arr[j]=sc.next();
map.put(arr[j], 1);
}
for (int j = 0; j < n; j++) {
arr1[j]=sc.next();
if(map.containsKey(arr1[j])){
map.put(arr1[j], map.get(arr1[j])+1);
}else{
map.put(arr1[j], 1);
}
}
for (int j = 0; j < n; j++) {
arr2[j]=sc.next();
if(map.containsKey(arr2[j])){
map.put(arr2[j], map.get(arr2[j])+1);
}else{
map.put(arr2[j], 1);
}
}
int first=n*3;
int second=n*3;
int third=n*3;
for(Map.Entry m: map.entrySet()){
boolean check1=false;
boolean check2=false;
boolean check3=true;
if((Integer)m.getValue() == 3){
first-=3;
second-=3;
third-=3;
}else if((Integer)m.getValue() == 2){
for(int k=0; k<n; k++){
if(((String) m.getKey()).compareTo(arr[k]) == 0 ){
check1=true;
break;
}
}
for(int k=0; k<n; k++){
if(((String) m.getKey()).compareTo(arr1[k]) == 0 ){
check2=true;
break;
}
}
if(check1 && check2){
first-=2;
second-=2;
}else if(check1 && check3){
first-=2;
third-=2;
}else{
second-=2;
third-=2;
}
}
}
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 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
a6ac7d4c73e90b253427003fa940677d
|
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.Math;
public class CrossMarket
{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int test = sc.nextInt();
while(test > 0){
int n = sc.nextInt();
int point1 = 0;
int point2 = 0;
int point3 = 0;
ArrayList<String> arr1 = new ArrayList<>();
ArrayList<String> arr2 = new ArrayList<>();
ArrayList<String> arr3 = new ArrayList<>();
for(int i=0;i<n;i++) arr1.add(sc.next());
for(int i=0;i<n;i++) arr2.add(sc.next());
for(int i=0;i<n;i++) arr3.add(sc.next());
HashSet<String> hash1 = new HashSet<>();
HashSet<String> hash2 = new HashSet<>();
HashSet<String> hash3 = new HashSet<>();
for(int i=0;i<n;i++) hash1.add(arr1.get(i));
for(int i=0;i<n;i++) hash2.add(arr2.get(i));
for(int i=0;i<n;i++) hash3.add(arr3.get(i));
for(int i=0;i<n;i++){
if(hash2.contains(arr1.get(i)) && hash3.contains(arr1.get(i))) continue;
else if(hash2.contains(arr1.get(i)) || hash3.contains(arr1.get(i))) point1++;
else if(!hash2.contains(arr1.get(i)) && !hash3.contains(arr1.get(i))) point1 += 3;
}
for(int i=0;i<n;i++){
if(hash1.contains(arr2.get(i)) && hash3.contains(arr2.get(i))) continue;
else if(hash1.contains(arr2.get(i)) || hash3.contains(arr2.get(i))) point2++;
else if(!hash1.contains(arr2.get(i)) && !hash3.contains(arr2.get(i))) point2 += 3;
}
for(int i=0;i<n;i++){
if(hash2.contains(arr3.get(i)) && hash1.contains(arr3.get(i))) continue;
else if(hash2.contains(arr3.get(i)) || hash1.contains(arr3.get(i))) point3++;
else if(!hash2.contains(arr3.get(i)) && !hash1.contains(arr3.get(i))) point3 += 3;
}
System.out.println(point1+" "+point2+" "+point3);
test--;
}
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
1d58a4bbd4d0ffdd08cfa2698079494a
|
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.*;
/**
* @author freya
* @date 2022/8/31
**/
public class Main {
public static Reader in;
public static PrintWriter out;
public static void main(String[] args) {
out = new PrintWriter(new BufferedOutputStream(System.out));
in = new Reader();
solve();
out.close();
}
static void solve(){
int t = in.nextInt();
Set<String>[] sets = new HashSet[3];
Arrays.setAll(sets, a->new HashSet<>());
while (t-->0){
int n = in.nextInt();
String[][] strs = new String[3][n];
Map<String, Integer> cnt = new HashMap<>();
for(int i = 0;i<3;i++){
for(int j = 0;j<n;j++){
String str = in.next();
strs[i][j] = str;
cnt.put(str, cnt.getOrDefault(str, 0)+1);
}
}
int[] re = new int[3];
for(int i = 0;i<3;i++){
for(int j = 0;j<n;j++){
String str = strs[i][j];
if (cnt.get(str) == 1)re[i] += 3;
if (cnt.get(str) == 2)re[i] += 1;
}
}
out.println(re[0] + " " + re[1] + " " + re[2]);
}
}
static class Reader {
private BufferedReader br;
private StringTokenizer st;
Reader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
try {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] nextIntArray(int n) {
int[] arr = new int[n];
for (int i = 0; i < n; i++)
arr[i] = nextInt();
return arr;
}
long nextLong() {
return Long.parseLong(next());
}
String nextLine() {
String s = "";
try {
s = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return s;
}
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
30b5cc1432759af86cdfc77b78f970be
|
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 Word1 {
public static void main(String[] args) {
Scanner o = new Scanner(System.in);
int t = o.nextInt();
while( t-- > 0){
int n = o.nextInt();
String[] arr3 = new String[n];
HashMap<String, Integer> hm1 = new HashMap();
HashMap<String, Integer> hm2 = new HashMap();
HashMap<String, Integer> hm3 = new HashMap();
int c1 = 0, c2 = 0, c3 = 0;
String tem;
for(int i = 0; i < n; i ++){
hm1.put(o.next(), 3);
}
for(int i = 0; i < n; i ++){
tem = o.next();
if( hm1.containsKey(tem)){
hm1.put(tem, 1);
hm2.put(tem, 1);
continue;
}
hm2.put(tem, 3);
}
for(int i = 0; i < n; i ++){
tem = o.next();
if(hm1.containsKey(tem)){
if(hm2.containsKey(tem)){
hm1.put(tem, 0);
hm2.put(tem, 0);
continue;
}
hm1.put(tem, 1);
c3 += 1;
continue;
}
if(hm2.containsKey(tem)){
hm2.put(tem, 1);
c3 += 1;
}
else{
c3 += 3;
}
}
for (int val : hm1.values())
c1 += val;
for (int val : hm2.values())
c2 += val;
System.out.println(c1 + " " + c2 + " " + c3);
}
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
9355911b6f1aefa267774cd7bc2bbf74
|
train_109.jsonl
|
1661871000
|
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class Main {
public static void main(String [] args) {
FastScanner fs=new FastScanner();
PrintWriter out=new PrintWriter(System.out);
StringBuilder res = new StringBuilder();
int t = fs.nextInt();
while(t-- > 0) {
int n = fs.nextInt();
String [][] s = new String[3][n];
HashMap<String , Integer> map = new LinkedHashMap<>();
int [] ans = new int[3];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < n; j++) {
s[i][j] = fs.next();
String m = s[i][j];
if(map.containsKey(m)) {
int count = map.get(m);
map.put(m, (count + 1));
}
else {
map.put(m, 1);
}
}
}
for (int i = 0; i < 3; i++) {
for (int j = 0; j < n; j++) {
if(map.containsKey(s[i][j])) {
if(map.get(s[i][j]) == 1) ans[i]+=3;
if(map.get(s[i][j]) == 2) ans[i]+=1;
}
}
}
for (int i = 0; i < 3; i++) {
res.append(ans[i] + " ");
}
res.append("\n");
}
out.print(res);
out.close();
}
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 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
8ca5768643759226fac2af3c2c069fe7
|
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.Set;
import java.util.LinkedHashSet;
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();
Set<String> m = new LinkedHashSet<String>();
for(int j=0;j<n;j++){
m.add(sc.next());
}
//System.out.println(m);
Set<String> m1 = new LinkedHashSet<String>();
for(int j=0;j<n;j++){
m1.add(sc.next());
}
Set<String> m2 = new LinkedHashSet<String>();
for(int j=0;j<n;j++){
m2.add(sc.next());
}
int sum=0;
for(String s1: m){
sum +=check(s1,m1,m2);
}
System.out.print(sum+" ");
sum=0;
for(String s1: m1){
sum +=check(s1,m,m2);
}
System.out.print(sum+" ");
sum=0;
for(String s1: m2){
sum +=check(s1,m,m1);
}
System.out.print(sum+" ");
System.out.println();
}
}
static int check(String s,Set<String> m1,Set<String> m2){
if(m1.contains(s) && m2.contains(s)){
return 0;
}
if(m1.contains(s) || m2.contains(s)){
return 1;
}
return 3;
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
62170141759cdfb19b5c7b0a34bfe217
|
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.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
public class Main {
static File file;
static BufferedReader br;
/* ------------------- Solve Area ------------------------------- */
private static void solve() {
try {
int t=Integer.parseInt(br.readLine());
while(t-->0) {
int n=Integer.parseInt(br.readLine());
String person1[]=br.readLine().split(" ");
String person2[]=br.readLine().split(" ");
String person3[]=br.readLine().split(" ");
// System.out.println("0");
HashMap<String,Integer> map = new HashMap<>();
for(int i=0;i<person1.length;i++) {
if(map.containsKey(person1[i])) {
map.put(person1[i],map.get(person1[i])+1);
}
else {
map.put(person1[i],1);
}
}
// System.out.println("0");
for(int i=0;i<n;i++) {
if(map.containsKey(person2[i])) {
map.put(person2[i],map.get(person2[i])+1);
}
else {
map.put(person2[i],1);
}
}
for(int i=0;i<n;i++) {
if(map.containsKey(person3[i])) {
map.put(person3[i],map.get(person3[i])+1);
}
else {
map.put(person3[i],1);
}
}
int a=0,b=0,c=0;
for(int i=0;i<n;i++) {
if(map.get(person1[i])==2) a=a+1;
else if(map.get(person1[i])==1) a=a+3;
}
for(int i=0;i<n;i++) {
if(map.get(person2[i])==2) b=b+1;
else if(map.get(person2[i])==1) b=b+3;
}
for(int i=0;i<n;i++) {
if(map.get(person3[i])==2) c=c+1;
else if(map.get(person3[i])==1) c=c+3;
}
System.out.println(a+" "+b+" "+c);
}
}catch(Exception e) {
}
}
private static int[] countdigit(int n) {
int arr[]=new int[10];
while(n>0) {
arr[n%10]++;
n/=10;
}
return arr;
}
/* ------------------- Main Method ------------------------------- */
public static void main(String[] args) throws IOException {
// file = new File("/home/deependra/CODE/JAVA/Practise/Test/src/temp.txt");
// br = new BufferedReader(new FileReader(file));
br=new BufferedReader(new InputStreamReader(System.in));
solve();
}
/* ------------------- GCD ------------------------------- */
static long gcd(long a, long b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
/* --------------- fast power ----------------------------- */
static long fastPow(long base, long exp, long m) {
if (exp == 0)
return 1;
long half = fastPow(base, exp / 2, m);
if (exp % 2 == 0)
return mul(half, half, m);
return mul(half, mul(half, base, m), m);
}
static long mul(long a, long b, long m) {
return a * b % m;
}
/* --------------- sort ----------------------------- */
static void swap(int[] arr, int i, int j) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
static int partition(int[] arr, int low, int high) {
int pivot = arr[high];
int i = (low - 1);
for (int j = low; j <= high - 1; j++) {
if (arr[j] < pivot) {
i++;
swap(arr, i, j);
}
}
swap(arr, i + 1, high);
return (i + 1);
}
static void sort(int[] arr, int low, int high) {
if (low < high) {
int pi = partition(arr, low, high);
sort(arr, low, pi - 1);
sort(arr, pi + 1, high);
}
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
74a9f90d047a5f513f7b9dc4e010c6fd
|
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 points {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
while (t-- > 0) {
int n = in.nextInt();
ArrayList<String> s1 = new ArrayList<>();
ArrayList<String> s2 = new ArrayList<>();
ArrayList<String> s3 = new ArrayList<>();
for (int i = 0; i < 3; i++) {
for (int j = 0; j < n; j++) {
if (i == 0) {
String s = in.next();
s1.add(s);
}
if (i == 1) {
String s = in.next();
s2.add(s);
}
if (i == 2) {
String s = in.next();
s3.add(s);
}
}
}
s1.addAll(s2);
s1.addAll(s3);
int c1 = 0, c2 = 0, c3 = 0;
Map<String, Integer> hm = new HashMap<String, Integer>();
for (String i : s1) {
Integer j = hm.get(i);
hm.put(i, (j == null) ? 1 : j + 1);
}
for (int i = 0; i < 3; i++) {
for (int j = 0; j < n; j++) {
if (i == 0) {
if (hm.containsKey(s1.get(j))) {
int k = hm.get(s1.get(j));
if (k == 1) {
c1 = c1 + 3;
}
if (k == 2) {
c1 = c1+1;
}
}
}
if (i == 1) {
if (hm.containsKey(s2.get(j))) {
int k = hm.get(s2.get(j));
if (k == 1) {
c2 = c2 + 3;
}
if (k == 2) {
c2 = c2 + 1;
}
}
}
if (i == 2) {
if (hm.containsKey(s3.get(j))) {
int k = hm.get(s3.get(j));
if (k == 1) {
c3 = c3 + 3;
}
if (k == 2) {
c3 = c3 + 1;
}
}
}
}
}
System.out.println(c1+" "+c2+" "+c3);
}
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
a2d0b3399e27d1f3c3b7e947dc482e27
|
train_109.jsonl
|
1661871000
|
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class Main{
static class FastReader{
BufferedReader br;
StringTokenizer st;
public FastReader(){
br=new BufferedReader(new InputStreamReader(System.in));
}
String next(){
while(st==null || !st.hasMoreTokens()){
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt(){
return Integer.parseInt(next());
}
long nextLong(){
return Long.parseLong(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
String nextLine(){
String str="";
try {
str=br.readLine().trim();
} catch (Exception e) {
e.printStackTrace();
}
return str;
}
}
static class FastWriter {
private final BufferedWriter bw;
public FastWriter() {
this.bw = new BufferedWriter(new OutputStreamWriter(System.out));
}
public void print(Object object) throws IOException {
bw.append("" + object);
}
public void println(Object object) throws IOException {
print(object);
bw.append("\n");
}
public void close() throws IOException {
bw.close();
}
}
public static void main(String[] args) {
try {
FastReader in = new FastReader();
FastWriter out = new FastWriter();
int testCases = in.nextInt();
while(testCases --> 0){
// write code here
int n = in.nextInt();
int p1 = n * 3, p2 = n * 3, p3 = n * 3;
HashSet<String> set1 = new HashSet<String>();
HashSet<String> set2 = new HashSet<String>();
HashSet<String> set3 = new HashSet<String>();
String[] s1 = new String[n];
String[] s2 = new String[n];
String[] s3 = new String[n];
for (int i = 0; i < n; i++) {
s1[i] = in.next();
set1.add(s1[i]);
}
for (int i = 0; i < n; i++) {
s2[i] = in.next();
set2.add(s2[i]);
}
for (int i = 0; i < n; i++) {
s3[i] = in.next();
set3.add(s3[i]);
}
// List<String> l1 = new ArrayList<>(Arrays.asList(s1));
// List<String> l2 = new ArrayList<>(Arrays.asList(s2));
// List<String> l3 = new ArrayList<>(Arrays.asList(s3));
// for (int i = 0; i < n; i++) {
// int temp = 2;
// if (l2.contains(s1[i])) {
// temp--;
// }
// if (l3.contains(s1[i])) {
// temp--;
// }
// if (temp != 2)
// p1 += temp;
// else
// p1+= 3;
// }
// for (int i = 0; i < n; i++) {
// int temp = 2;
// if (l1.contains(s2[i])) {
// temp--;
// }
// if (l3.contains(s2[i])) {
// temp--;
// }
// if (temp != 2)
// p2 += temp;
// else
// p2+= 3;
// }
// for (int i = 0; i < n; i++) {
// int temp = 2;
// if (l2.contains(s3[i])) {
// temp--;
// }
// if (l1.contains(s3[i])) {
// temp--;
// }
// if (temp != 2)
// p3 += temp;
// else
// p3+= 3;
// }
HashSet<String> s1dup = new HashSet<String>(set1);
s1dup.retainAll(set2);
p1 -= (2 * s1dup.size());
HashSet<String> s1dup2 = new HashSet<String>(set1);
s1dup2.retainAll(set3);
p1 -= (2 * s1dup2.size());
s1dup.retainAll(s1dup2);
p1 += s1dup.size();
HashSet<String> s2dup = new HashSet<String>(set2);
s2dup.retainAll(set1);
p2 -= (2 * s2dup.size());
HashSet<String> s2dup2 = new HashSet<String>(set2);
s2dup2.retainAll(set3);
p2 -= (2 * s2dup2.size());
s2dup.retainAll(s2dup2);
p2 += s2dup.size();
HashSet<String> s3dup = new HashSet<String>(set3);
s3dup.retainAll(set2);
p3 -= (2 * s3dup.size());
HashSet<String> s3dup2 = new HashSet<String>(set3);
s3dup2.retainAll(set1);
p3 -= (2 * s3dup2.size());
s3dup.retainAll(s3dup2);
p3 += s3dup.size();
System.out.println(p1 + " " + p2 + " " + p3);
}
out.close();
} catch (Exception e) {
return;
}
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
7856681bd155bfdb74ae154ed645046d
|
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);
while (in.hasNext()) {
int T = in.nextInt();
while (T -- > 0) {
int n = in.nextInt();
HashSet<String> aa = new HashSet<>();
HashSet<String> bb = new HashSet<>();
HashSet<String> cc = new HashSet<>();
String [] a = new String[n];
String [] b = new String[n];
String [] c = new String[n];
for (int i = 0; i < n; i++) {
a[i] = in.next();
aa.add(a[i]);
}
for (int i = 0; i < n; i++) {
b[i] = in.next();
bb.add(b[i]);
}
for (int i = 0; i < n; i++) {
c[i] = in.next();
cc.add(c[i]);
}
int s1 = 0, s2 = 0,s3 = 0;
for (int i = 0; i < n; i++) {
if(bb.contains(a[i]) && cc.contains(a[i]))
s1 += 0;
else if(bb.contains(a[i]) || cc.contains(a[i]))
s1 += 1;
else
s1 += 3;
if(cc.contains(b[i]) && aa.contains(b[i]))
s2 += 0;
else if(cc.contains(b[i]) || aa.contains(b[i]))
s2 += 1;
else
s2 += 3;
if(bb.contains(c[i]) && aa.contains(c[i]))
s3 += 0;
else if(bb.contains(c[i]) || aa.contains(c[i]))
s3 += 1;
else
s3 += 3;
}
System.out.println(s1 + " " + s2 + " " + s3);
}
}
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
ce1c7332ef781f2cae3a39a5808a3b88
|
train_109.jsonl
|
1661871000
|
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
|
256 megabytes
|
import java.util.*;
import java.lang.*;
import java.io.*;
public class main
//class pp
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int n = sc.nextInt();
List<String> s1 = new ArrayList<>();
List<String> s2 = new ArrayList<>();
List<String> s3 = new ArrayList<>();
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());
}
Map<String,Integer> map1 = new HashMap<>();
Map<String,Integer> map2 = new HashMap<>();
Map<String,Integer> map3 = new HashMap<>();
for(int i =0;i<n;i++){
map1.put(s1.get(i), 1);
}
for(int i =0;i<n;i++){
map2.put(s2.get(i), 1);
}
for(int i =0;i<n;i++){
map3.put(s3.get(i), 1);
}
int p1=0,p2=0,p3=0;
for(int i =0;i<n;i++){
if(map2.containsKey(s1.get(i)) || map3.containsKey(s1.get(i))){
if(map2.containsKey(s1.get(i)) && map3.containsKey(s1.get(i)))
p1=p1+0;
else
p1=p1+1;
}
else
p1=p1+3;
}
for(int i =0;i<n;i++){
if(map1.containsKey(s2.get(i)) || map3.containsKey(s2.get(i))){
if(map1.containsKey(s2.get(i)) && map3.containsKey(s2.get(i)))
p2=p2+0;
else
p2=p2+1;
}
else
p2=p2+3;
}
for(int i =0;i<n;i++){
if(map2.containsKey(s3.get(i)) || map1.containsKey(s3.get(i))){
if(map2.containsKey(s3.get(i)) && map1.containsKey(s3.get(i)))
p3=p3+0;
else
p3=p3+1;
}
else
p3=p3+3;
}
System.out.print(p1+" ");
System.out.print(p2+" ");
System.out.println(p3);
}
}
//method to check prime
static boolean isPrime(long n)
{
// Corner cases
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
// method to return gcd of two numbers
static long gcd(long a, long b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
// method to return LCM of two numbers
static long lcm(long a, long b)
{
return (a / gcd(a, b)) * b;
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
11e61c4c9ee9948789f87eede6a6e9bf
|
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 kflip
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
ArrayList<String> list1=new ArrayList<>();
ArrayList<String> list2=new ArrayList<>();
ArrayList<String> list3=new ArrayList<>();
HashMap<String, Integer> map = new HashMap<>();
for(int i=0;i<n;i++)
{
String inp=sc.next();
list1.add(inp);
map.put(inp,map.getOrDefault(inp,0)+1);
}
for(int i=0;i<n;i++)
{
String inp=sc.next();
list2.add(inp);
map.put(inp,map.getOrDefault(inp,0)+1);
}
for(int i=0;i<n;i++)
{
String inp=sc.next();
list3.add(inp);
map.put(inp,map.getOrDefault(inp,0)+1);
}
int p1=0,p2=0,p3=0;
for(int i=0;i<list1.size();i++)
{
String s=list1.get(i);
if(map.containsKey(s))
{
if(map.get(s)==2){
p1+=1;}
else if(map.get(s)==1){
p1+=3;}
}
}
for(int i=0;i<list2.size();i++)
{
String s=list2.get(i);
if(map.containsKey(s))
{
if(map.get(s)==2){
p2+=1;}
else if(map.get(s)==1){
p2+=3;}
}
}
for(int i=0;i<list3.size();i++)
{
String s=list3.get(i);
if(map.containsKey(s))
{
if(map.get(s)==2){
p3+=1;}
else if(map.get(s)==1){
p3+=3;}
}
}
System.out.println(p1+" "+p2+" "+p3);
}
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 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
783c1e6b913b01f5769987eebea0506b
|
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 WordGame {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
while (t-- > 0) {
int n = Integer.parseInt(br.readLine());
Set<String> s1 = new HashSet<>(Arrays.asList(br.readLine().split(" ")));
Set<String> s2 = new HashSet<>(Arrays.asList(br.readLine().split(" ")));
Set<String> s3 = new HashSet<>(Arrays.asList(br.readLine().split(" ")));
Set<String> s = new HashSet<>();
s.addAll(s1);
s.addAll(s2);
s.addAll(s3);
int p1 = 0;
int p2 = 0;
int p3 = 0;
for (String word: s) {
if (s1.contains(word)) {
if (s2.contains(word)) {
if (!s3.contains(word)) {
p1++;
p2++;
}
} else if (s3.contains(word)) {
p1++;
p3++;
} else
p1 += 3;
}
else if (s2.contains(word)) {
if (!s3.contains(word))
p2 += 3;
else {
p2 += 1;
p3 += 1;
}
}
else {
p3 += 3;
}
}
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 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
b6b7ef0101a6d8ea026352afab94f602
|
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 whatever //do not write package name here */
import java.util.*;
public final class GFG {
public static void fun(HashSet<String> set[], String s[][], int n) {
int result[] = new int[3];
boolean first, second, third;
for(int j = 0; j < n; j++) {
String hold = s[0][j];
second = set[1].contains(hold);
third = set[2].contains(hold);
if(second && third) {
set[1].remove(hold);
set[2].remove(hold);
}
else if(second) {
result[0] += 1;
result[1] += 1;
set[1].remove(hold);
}
else if(third) {
result[0] += 1;
result[2] += 1;
set[2].remove(hold);
}
else {
result[0] += 3;
}
}
for(int j = 0; j < n; j++) {
String hold = s[1][j];
second = set[1].contains(hold);
third = set[2].contains(hold);
if(second && third) {
result[1] += 1;
result[2] += 1;
set[2].remove(hold);
}
else if(second) {
result[1] += 3;
}
}
for(int j = 0; j < n; j++) {
String hold = s[2][j];
third = set[2].contains(hold);
if(third){
result[2] += 3;
}
}
System.out.println(result[0] + " " + result[1] + " " + result[2]);
}
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> set[] = new HashSet[3];
for(int i = 0; i < 3; i++) {
set[i] = new HashSet();
}
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();
set[i].add(s[i][j]);
}
}
fun(set, s, n);
}
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
1898a6656bcce3739d0bdcf79f6b303d
|
train_109.jsonl
|
1661871000
|
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
|
256 megabytes
|
import java.io.*;
import java.util.*;
import java.math.*;
public class C_1722 {
public static void main(String[] args)
{
FastReader sc = new FastReader();
int t=sc.nextInt();
while(t-->0) {
int n=sc.nextInt();
ArrayList<String> al1=new ArrayList<String>();
HashMap<String, Integer> hm1=new HashMap<String, Integer>();
StringTokenizer s1=new StringTokenizer(sc.nextLine());
while(s1.hasMoreTokens()) {
String s=s1.nextToken();
hm1.putIfAbsent(s, 0);
al1.add(s);
}
ArrayList<String> al2=new ArrayList<String>();
HashMap<String, Integer> hm2=new HashMap<String, Integer>();
StringTokenizer s2=new StringTokenizer(sc.nextLine());
while(s2.hasMoreTokens()) {
String s=s2.nextToken();
hm2.putIfAbsent(s, 0);
al2.add(s);
}
ArrayList<String> al3=new ArrayList<String>();
HashMap<String, Integer> hm3=new HashMap<String, Integer>();
StringTokenizer s3=new StringTokenizer(sc.nextLine());
while(s3.hasMoreTokens()) {
String s=s3.nextToken();
hm3.putIfAbsent(s, 0);
al3.add(s);
}
int n1=0, n2=0, n3=0;
for(int i=0;i<n;i++) {
String s=al1.get(i);
if(!hm2.containsKey(s) && !hm3.containsKey(s)) n1+=3;
else if(hm2.containsKey(s) && hm3.containsKey(s)) n1=n1;
else n1++;
}
for(int i=0;i<n;i++) {
String s=al2.get(i);
if(!hm1.containsKey(s) && !hm3.containsKey(s)) n2+=3;
else if(hm1.containsKey(s) && hm3.containsKey(s)) n2=n2;
else n2++;
}for(int i=0;i<n;i++) {
String s=al3.get(i);
if(!hm2.containsKey(s) && !hm1.containsKey(s)) n3+=3;
else if(hm2.containsKey(s) && hm1.containsKey(s)) n1=n1;
else n3++;
}
System.out.println(n1+" "+n2+" "+n3);
}
}
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return (str);
}
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
8dc28454e371dfca76eba24f6c7f977c
|
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.*;
/**
* @author Dozen Lee<br/>
* 2022/8/30 22:21
*/
public class C {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int testCases = scan.nextInt();
for (int i = 0; i < testCases; i++) {
int n = scan.nextInt();
Map<String, List<Integer>> strByIdx = new HashMap<>();
// first person = 0
for (int j = 0; j < n; j++) {
String s = scan.next();
List<Integer> lst = new ArrayList<>();
lst.add(0);
strByIdx.put(s, lst);
}
// second person = 1
for (int j = 0; j < n; j++) {
String s = scan.next();
if (strByIdx.containsKey(s)) {
strByIdx.get(s).add(1);
} else {
List<Integer> lst = new ArrayList<>();
lst.add(1);
strByIdx.put(s, lst);
}
}
// third person = 2
for (int j = 0; j < n; j++) {
String s = scan.next();
if (strByIdx.containsKey(s)) {
strByIdx.get(s).add(2);
} else {
List<Integer> lst = new ArrayList<>();
lst.add(2);
strByIdx.put(s, lst);
}
}
int[] ans = new int[3];
for (List<Integer> idxes : strByIdx.values()) {
if (idxes.size() == 1) {
ans[idxes.get(0)] += 3;
} else if (idxes.size() == 2) {
ans[idxes.get(0)] += 1;
ans[idxes.get(1)] += 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 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
902ea13909c02a378e238de76490d2bd
|
train_109.jsonl
|
1661871000
|
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
|
256 megabytes
|
//package com.contest.codeforce;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class WordGame {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
while (t-- > 0) {
HashMap<String, Integer> myMap = new HashMap<>();
List<Integer> result = new ArrayList<>();
int n = Integer.parseInt(br.readLine());
String[] listString1 = br.readLine().split(" ");
String[] listString2 = br.readLine().split(" ");
String[] listString3 = br.readLine().split(" ");
for (String s : listString1) {
myMap.put(s, myMap.getOrDefault(s, 0) + 1);
}
for (String s : listString2) {
myMap.put(s, myMap.getOrDefault(s, 0) + 1);
}
for (String s : listString3) {
myMap.put(s, myMap.getOrDefault(s, 0) + 1);
}
int sum = 0;
for (String s : listString1) {
int val = myMap.get(s);
if (val == 1) {
sum = sum+3;
}else if (val==2){
sum+=1;
}
}
result.add(sum);sum=0;
for (String s : listString2) {
int val = myMap.get(s);
if (val == 1) {
sum = sum+3;
}else if (val==2){
sum+=1;
}
}
result.add(sum);sum=0;
for (String s : listString3) {
int val = myMap.get(s);
if (val == 1) {
sum = sum+3;
}else if (val==2){
sum+=1;
}
}
result.add(sum);sum=0;
for (int i: result) {
System.out.print(i+" ");
}
System.out.println();
}
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
667fd3e18c5cfb620b28bdcb03aa478d
|
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.*;
/**
*
*
* @author adnan
**/
@SuppressWarnings("unchecked")
public class CodeForces {
final static String no = "NO";
final static String yes = "YES";
final static int maxV = Integer.MAX_VALUE;
final static int minV = Integer.MIN_VALUE;
final static int mod = (int) (1e9 + 7);
static public PrintWriter pw = new PrintWriter(System.out);
static public IO sc = new IO();
static Scanner fc = new Scanner(System.in);
public static void main(String[] args) {
solve();
pw.flush();
}
//////////////////////////////////////////////////////////////////////////
private static void solve() {
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
Set<String> a = new HashSet<>();
Set<String> b = new HashSet<>();
Set<String> c = new HashSet<>();
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());
Set<String> du = new HashSet<>();
for(String s : a) {
if(b.contains(s)&&c.contains(s)) {
du.add(s);
}
}
for(String d : du) {
a.remove(d);
b.remove(d);
c.remove(d);
}
du.clear();
int x = 0;
int y = 0;
int z = 0;
int ab = 0;
int bc = 0;
int ca = 0;
for(String s : a) {
if(b.contains(s)) {
du.add(s);
x++;
y++;
z+=3;
ab++;
}
}
for(String s : du) {
a.remove(s);
b.remove(s);
}
du.clear();
for(String s : b) {
if(c.contains(s)) {
du.add(s);
x+=3;
y++;
z++;
bc++;
}
}
for(String s : du) {
b.remove(s);
c.remove(s);
}
du.clear();
for(String s : a) {
if(c.contains(s)) {
du.add(s);
x++;
y+=3;
z++;
ca++;
}
}
for(String s : du) {
a.remove(s);
c.remove(s);
}
// pw.println(x+" "+y+" "+z);
// pw.println(a);
// pw.println(b);
// pw.println(c);
x+=3*a.size() - 3*bc;
y+=3*b.size() - 3*ca;
z+=3*c.size() - 3*ab;
pw.println(x+" "+y+" "+z);
}
}
///////////////////////////////////////////////////////////////////////////
static class Three {
int x, y, z;
public Three(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
}
static int floorPowerOf2(int n) {
int p = (int) (Math.log(n) / Math.log(2));
return (int) Math.pow(2, p);
}
static int ceilPowerOf2(int n) {
int p = (int) (Math.log(n) / Math.log(2));
return (int) Math.pow(2, p + 1);
}
static List<Integer> printDivisors(int n) {
// Note that this loop runs till square root
List<Integer> sl = new ArrayList<>();
for (int i = 1; i <= Math.sqrt(n); i++) {
if (n % i == 0) {
// If divisors are equal, print only one
if (n / i == i)
sl.add(i);
else // Otherwise print both
{
sl.add(i);
sl.add(n / i);
}
}
}
return sl;
}
static int max(int... val) {
int res = Integer.MIN_VALUE;
for (int i : val) {
res = Math.max(i, res);
}
return res;
}
static class Pair {
int x, y, z;
Pair(int x, int y) {
this.x = x;
this.y = y;
}
Pair(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
}
static int gcd(int a, int b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
static long gcd(long a, long b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
static long lcm(long a, long b) {
return (a / gcd(a, b)) * b;
}
static void sort(int[] arr) {
Random rand = new Random();
int n = arr.length;
for (int i = 0; i < n; i++) {
int idx = rand.nextInt(n);
if (idx == i)
continue;
arr[i] ^= arr[idx];
arr[idx] ^= arr[i];
arr[i] ^= arr[idx];
}
Arrays.sort(arr);
}
static void sort(long[] arr) {
Random rand = new Random();
int n = arr.length;
for (int i = 0; i < n; i++) {
int idx = rand.nextInt(n);
if (idx == i)
continue;
arr[i] ^= arr[idx];
arr[idx] ^= arr[i];
arr[i] ^= arr[idx];
}
Arrays.sort(arr);
}
static void sortDec(int[] arr) {
Random rand = new Random();
int n = arr.length;
for (int i = 0; i < n; i++) {
int idx = rand.nextInt(n);
if (idx == i)
continue;
arr[i] ^= arr[idx];
arr[idx] ^= arr[i];
arr[i] ^= arr[idx];
}
Arrays.sort(arr);
int l = 0;
int r = n - 1;
while (l < r) {
arr[l] ^= arr[r];
arr[r] ^= arr[l];
arr[l] ^= arr[r];
l++;
r--;
}
}
static void sortDec(long[] arr) {
Random rand = new Random();
int n = arr.length;
for (int i = 0; i < n; i++) {
int idx = rand.nextInt(n);
if (idx == i)
continue;
arr[i] ^= arr[idx];
arr[idx] ^= arr[i];
arr[i] ^= arr[idx];
}
Arrays.sort(arr);
int l = 0;
int r = n - 1;
while (l < r) {
arr[l] ^= arr[r];
arr[r] ^= arr[l];
arr[l] ^= arr[r];
l++;
r--;
}
}
static class IO {
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());
}
long[] longArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
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 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
5bbfb5a94f9e75008217d49290a3c052
|
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
|
//KENAA
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.HashMap;
import java.util.StringTokenizer;
public class C {
public static void main(String[] args) {
FastReader fr = new FastReader();
PrintWriter out = new PrintWriter(System.out);
StringBuilder st = new StringBuilder();
int tt = fr.nextInt();
while (tt-- > 0) {
int n = fr.nextInt();
ArrayList<String> arr1 = new ArrayList<>(n);
ArrayList<String> arr2 = new ArrayList<>(n);
ArrayList<String> arr3 = new ArrayList<>(n);
HashMap<String, Integer>mapy=new HashMap<>();
for (int i = 0; i < n; i++) {
arr1.add(fr.next());
if (!mapy.containsKey(arr1.get(i))) {
mapy.put(arr1.get(i), 1);
}else {
mapy.put(arr1.get(i), mapy.get(arr1.get(i))+1);
}
}
for (int i = 0; i < n; i++) {
arr2.add(fr.next());
if (!mapy.containsKey(arr2.get(i))) {
mapy.put(arr2.get(i), 1);
}else {
mapy.put(arr2.get(i), mapy.get(arr2.get(i))+1);
}
}
for (int i = 0; i < n; i++) {
arr3.add(fr.next());
if (!mapy.containsKey(arr3.get(i))) {
mapy.put(arr3.get(i), 1);
}else {
mapy.put(arr3.get(i), mapy.get(arr3.get(i))+1);
}
}
int to1=0;
int to2=0;
int to3=0;
for (int i = 0; i < n; i++) {
int x =mapy.get(arr1.get(i));
int y =mapy.get(arr2.get(i));
int z =mapy.get(arr3.get(i));
if (x==1) {
to1+=3;
}else if(x==2) {
to1+=1;
}else {
}
if (y==1) {
to2+=3;
}else if(y==2) {
to2+=1;
}else {
}
if (z==1) {
to3+=3;
}else if(z==2) {
to3+=1;
}else {
}
}
st.append(to1+" "+to2+" "+to3+"\n");
}
out.print(st);
out.close();
}
static class FastReader {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
}
return st.nextToken();
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
}
public static long lcm(long a, long b) {
return a * b / gcd(a, b);
}
public static long gcd(long a, long b) {
while (b != 0) {
long m = a % b;
a = b;
b = m;
}
return a;
}
public static long factorial(int n) {
if (n == 0)
return 1;
long res = 1;
for (int i = 2; i <= n; i++)
res = res * i;
return res;
}
public static long nCr(int n, int r) {
return factorial(n) / (factorial(r) * factorial(n - r));
}
public static ArrayList<Integer> factors(long n) {
ArrayList<Integer> list = new ArrayList<>();
for (int i = 2; i < n / i; i++) {
while (n % i == 0) {
if (!list.contains(i)) {
list.add(i);
n /= i;
}
}
}
if (n > 2) {
if (!list.contains((int) n)) {
list.add((int) n);
}
}
return list;
}
public static int numOfPrimes(int n) {
if (n < 2) {
return 0;
}
boolean[] bool = new boolean[n + 1];
outer: for (int i = 2; i < bool.length / i; i++) {
if (bool[i]) {
continue outer;
}
for (int j = 2 * i; j < bool.length; j += i) {
bool[j] = true;
}
}
int counter = 0;
for (int i = 0; i < bool.length; i++) {
if (!bool[i]) {
counter++;
}
}
return counter;
}
public static void sort2DGivenArray(Object[][] arr, int colNum) {
Arrays.sort(arr, (val1, val2) -> {
if (val1[colNum] == val2[colNum]) {
return 0;
} else if (((Integer) (val1[colNum])).compareTo(((Integer) (val2[colNum]))) < 0) {
return 1;
} else {
return -1;
}
});
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
e5134ef3b79dbdb34c02d6d34ac5bacc
|
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.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
import java.util.Stack;
import javax.swing.tree.TreeNode;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
List<String>list=new ArrayList<String>();
for (int i = 0; i < t; i++) {
int n=sc.nextInt();
List<String>aList=new ArrayList<String>();
List<String>bList=new ArrayList<String>();
List<String>cList=new ArrayList<String>();
Set<String>set=new HashSet<String>();
for (int j = 0; j < n; j++) {
aList.add(sc.next());
}
for (int j = 0; j < n; j++) {
bList.add(sc.next());
}
for (int j = 0; j < n; j++) {
cList.add(sc.next());
}
set.addAll(aList);set.addAll(bList);set.addAll(cList);
Map<String, Integer>map=new HashMap<String, Integer>();
for (String string : set) {
map.put(string, 0);
}
for (String string : aList) {
map.put(string, map.get(string)+1);
}
for (String string : bList) {
map.put(string, map.get(string)+1);
}
for (String string : cList) {
map.put(string, map.get(string)+1);
}
String aString="";
int a1=0;
for (String string : aList) {
if (map.get(string)==1) {
a1+=3;
}else if (map.get(string)==2) {
a1+=1;
}
}
int b1=0;
for (String string : bList) {
if (map.get(string)==1) {
b1+=3;
}else if (map.get(string)==2) {
b1+=1;
}
}
int c1=0;
for (String string : cList) {
if (map.get(string)==1) {
c1+=3;
}else if (map.get(string)==2) {
c1+=1;
}
}
aString+=a1+" "+b1+" "+c1;
list.add(aString);
}
for (String string : list) {
System.out.println(string);
}
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
6d500a0b5c11d866bd9b0da6c504dc38
|
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 javax.lang.model.util.ElementScanner14;
public class testing {
public static int solve(int n,int m,int sx,int sy,int d)
{
return 0;
}
public static void main(String[] args)
{
Scanner scn=new Scanner(System.in);
int t=Integer.parseInt(scn.nextLine());
String[] ans=new String[t];
for(int itr=0;itr<t;itr++)
{
int num=Integer.parseInt(scn.nextLine());
String a=scn.nextLine();
String b=scn.nextLine();
String c=scn.nextLine();
Set<String> as=new HashSet<>();
Set<String> bs=new HashSet<>();
Set<String> cs=new HashSet<>();
//Set<String> ts=new HashSet<>();
as.addAll(Arrays.asList(a.split(" ")));
bs.addAll(Arrays.asList(b.split(" ")));
cs.addAll(Arrays.asList(c.split(" ")));
int scorea=0;
int scoreb=0;
int scorec=0;
for(String temp:as)
{
boolean v1=bs.contains(temp);
boolean v2=cs.contains(temp);
if(v1&&v2)
{
}
else if(v1||v2)
{
scorea++;
}
else
{
scorea+=3;
}
}
for(String temp:bs)
{
boolean v1=as.contains(temp);
boolean v2=cs.contains(temp);
if(v1&&v2)
{
}
else if(v1||v2)
{
scoreb++;
}
else
{
scoreb+=3;
}
}
for(String temp:cs)
{
boolean v1=bs.contains(temp);
boolean v2=as.contains(temp);
if(v1&&v2)
{
}
else if(v1||v2)
{
scorec++;
}
else
{
scorec+=3;
}
}
String ta=scorea+" "+scoreb+" "+scorec;
ans[itr]=ta;
}
for(int itr=0;itr<ans.length;itr++)
{
System.out.println(ans[itr]);
}
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
b9a8037ac009fba01f5a2078f7d7c1cf
|
train_109.jsonl
|
1661871000
|
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
|
256 megabytes
|
import java.util.*;
import java.lang.*;
import java.io.*;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
public class C
{
public static void main (String[] args) throws java.lang.Exception
{
MyScanner sc = new MyScanner();
out = new PrintWriter(new BufferedOutputStream(System.out));
int t = sc.nextInt();
while (t-- != 0)
{
int n = sc.nextInt();
HashMap<Integer, ArrayList<String>> w = new HashMap<>();
HashMap<String, Integer> c = new HashMap<>();
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < n; j++)
{
String ws1 = sc.next();
c.put(ws1, c.getOrDefault(ws1, 0) + 1);
if (!w.containsKey(i))
{
w.put(i, new ArrayList<>());
}
w.get(i).add(ws1);
}
}
for (int i = 0; i < 3; i++)
{
int p = 0;
for (String ws : w.get(i))
{
p += c.get(ws) == 1 ? 3 : c.get(ws) == 2 ? 1 : 0;
}
out.print(p + " ");
}
out.println("");
}
out.close();
}
public static PrintWriter out;
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
6f22e74e94007fbee2939c26e5fab36e
|
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.math.*;
import java.io.*;
import java.util.*;
//sort(String);
//isPrime(
public class A
{
static PrintWriter out = new PrintWriter(System.out);
static FastReader in=new FastReader();
static ArrayList<Integer> A=new ArrayList<>();
public static void main(String args[])throws IOException
{
int t =i();
outer:while(t-->0) {
int n=i();
ArrayList<String> list1=new ArrayList<>();
ArrayList<String> list2=new ArrayList<>();
ArrayList<String> list3=new ArrayList<>();
HashSet<String> h1=new HashSet<>();
HashSet<String> h2=new HashSet<>();
HashSet<String> h3=new HashSet<>();
for(int i=0;i<n;i++) {
list1.add(S());
h1.add(list1.get(i));
}
for(int i=0;i<n;i++) {
list2.add(S());h2.add(list2.get(i));
}
for(int i=0;i<n;i++) {
list3.add(S());h3.add(list3.get(i));
}
long ans1=0;long ans2=0; long ans3=0;
for(int i=0;i<n;i++) {
String s=list1.get(i);
if(h2.contains(s) && h3.contains(s)) {
continue;
}
else if(h2.contains(s) ||h3.contains(s)){
ans1+=1;
}
else {
ans1+=3;
}
}
for(int i=0;i<n;i++) {
String s=list2.get(i);
if(h1.contains(s) && h3.contains(s)) {
continue;
}
else if(h1.contains(s) || h3.contains(s)){
ans2+=1;
}
else {
ans2+=3;
}
}
for(int i=0;i<n;i++) {
String s=list3.get(i);
if(h2.contains(s) && h1.contains(s)) {
continue;
}
else if(h2.contains(s) || h1.contains(s)){
ans3+=1;
}
else {
ans3+=3;
}
}
out.println(ans1+" "+ans2+" "+ans3);
}
out.close();
}
static void print(char[][] x,int r,int c) {
for(int i=0;i<r;i++) {
for(int j=0;j<c;j++) {
out.print(x[i][j]);
}
out.println();
}
}
public static boolean set(int i,int j,char[][] mat,int r,int c,char[][] x) {
x[i][j]='^';
if(i-1<0 && i+1<r) {
if(j-1<0 && j+1<c) {
x[i+1][j]='^';
x[i+1][j+1]='^';
x[i][j+1]='^';
return true;
}
else {
x[i+1][j]='^';
x[i+1][j-1]='^';
x[i][j-1]='^';
return true;
}
}
else if(i-1>0 && i+1>=r) {
if(j-1<0 && j+1<c) {
x[i-1][j]='^';
x[i-1][j+1]='^';
x[i][j+1]='^';
return true;
}
else {
x[i-1][j]='^';
x[i-1][j-1]='^';
x[i][j-1]='^';
return true;
}
}
else if(i-1>=0 && i+1<r) {
if(j-1<0 && j+1<c) {
x[i-1][j]='^';
x[i-1][j+1]='^';
x[i][j+1]='^';
return true;
}
else {
x[i-1][j]='^';
x[i-1][j-1]='^';
x[i][j-1]='^';
return true;
}
}
return false;
}
public static void reverse(int[] array)
{
int n = array.length;
for (int i = 0; i < n / 2; i++) {
int temp = array[i];
array[i] = array[n - i - 1];
array[n - i - 1] = temp;
}
}
static boolean isitSorted(long A[])
{
for(int i=1; i<A.length; i++) {
if(A[i]<A[i-1])return false;
}
return true;
}
static void print(int A[])
{
for(long i:A)System.out.print(i+ " ");
System.out.println();
}
static void print(long A[])
{
for(long i:A)System.out.print(i+ " ");
System.out.println();
}
static void print(ArrayList<Integer> A)
{
for(long a:A)System.out.print(a);
System.out.println();
}
static int i()
{
return in.nextInt();
}
static long l()
{
return in.nextLong();
}
static String S() {
return in.next();
}
static int[] input(int N){
int A[]=new int[N];
for(int i=0; i<N; i++)
{
A[i]=in.nextInt();
}
return A;
}
static long[] inputL(int N) {
long A[]=new long[N];
for(int i=0; i<A.length; i++) {
A[i]=in.nextLong();
}
return A;
}
}
class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br=new BufferedReader(new InputStreamReader(System.in));
}
String next()
{
while(st==null || !st.hasMoreElements())
{
try
{
st=new StringTokenizer(br.readLine());
}
catch(IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str="";
try
{
str=br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
d74d515581676a57fb2291aea9876d58
|
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 static java.lang.Math.*;
public class Main {
static Scanner scn = new Scanner(System.in);
static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) {
int t = 1;
t = scn.nextInt();
for(int tests = 0; tests < t; tests++) solve();
out.close();
}
/*
Case 1:
a. if contained by all
*/
public static void solve() {
int n = scn.nextInt();
String[] str1 = new String[n], str2 = new String[n], str3 = new String[n];
for(int i = 0; i < n; i++) str1[i] = scn.next();
for(int i = 0; i < n; i++) str2[i] = scn.next();
for(int i = 0; i < n; i++) str3[i] = scn.next();
HashMap<String, Integer> m1 = new HashMap<>(), m2 = new HashMap<>(), m3 = new HashMap<>();
for(String s1 : str1) m1.put(s1, m1.getOrDefault(s1, 0) + 1);
for(String s1 : str2) m2.put(s1, m2.getOrDefault(s1, 0) + 1);
for(String s1 : str3) m3.put(s1, m3.getOrDefault(s1, 0) + 1);
int[] f = new int[3];
for(int i = 0; i < n; i++) {
String s1 = str1[i];
int g = m1.get(s1);
if(m2.containsKey(s1) && m3.containsKey(s1)) {
}else if(m2.containsKey(s1) || m3.containsKey(s1)) {
if(m2.containsKey(s1)) {
f[1]++;
}else {
f[2]++;
}
}else {
f[0] += 3;
}
}
for(int i = 0; i < n; i++) {
String s1 = str2[i];
int g = m2.get(s1);
if(m1.containsKey(s1) && m3.containsKey(s1)) {
}else if(m1.containsKey(s1) || m3.containsKey(s1)) {
if(m1.containsKey(s1)) {
f[0]++;
}else {
f[2]++;
}
}else {
f[1] += 3;
}
}
for(int i = 0; i < n; i++) {
String s1 = str3[i];
int g = m3.get(s1);
if(m1.containsKey(s1) && m2.containsKey(s1)) {
}else if(m1.containsKey(s1) || m2.containsKey(s1)) {
if(m1.containsKey(s1)) {
f[0]++;
}else {
f[1]++;
}
}else {
f[2] += 3;
}
}
out.println(f[0] + " " + f[1] + " " + f[2]);
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
99a6b8ad001d3b5e9b5655eca3182586
|
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.lang.Math.*;
// import java.util.Scanner;
import java.util.*;
import java.io.*;
public class Main {
static Scanner sc = new Scanner(System.in);
static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) {
int t = 1;
t = sc.nextInt();
for(int tests = 0; tests < t; tests++) solve();
out.close();
}
public static void solve(){
int n=sc.nextInt();
HashSet<String> set1=new HashSet<>();
HashSet<String> set2=new HashSet<>();
HashSet<String> set3=new HashSet<>();
for(int i=0;i<n;i++){
set1.add(sc.next());
}
for(int i=0;i<n;i++){
set2.add(sc.next());
}
for(int i=0;i<n;i++){
set3.add(sc.next());
}
int sc1=0;
int sc2=0;
int sc3=0;
for(String s:set1){
boolean f1=false;
boolean f2=false;
if(set2.contains(s)){
f1=true;
}
if(set3.contains(s)){
f2=true;
}
if(f1==true && f2==false){
sc1++;
}
else if(f2==true && f1==false){
sc1++;
}
else if(f1==false && f2==false){
sc1=sc1+3;
}
}
for(String s:set2){
boolean f1=false;
boolean f2=false;
if(set1.contains(s)){
f1=true;
}
if(set3.contains(s)){
f2=true;
}
if(f1==true && f2==false){
sc2++;
}
else if(f2==true && f1==false){
sc2++;
}
else if(f1==false && f2==false){
sc2=sc2+3;
}
}
for(String s:set3){
boolean f1=false;
boolean f2=false;
if(set1.contains(s)){
f1=true;
}
if(set2.contains(s)){
f2=true;
}
if(f1==true && f2==false){
sc3++;
}
else if(f2==true && f1==false){
sc3++;
}
else if(f1==false && f2==false){
sc3=sc3+3;
}
}
out.println(sc1+" "+sc2+" "+sc3);
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
7f103d936c301e480ac74a12f79177ea
|
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
|
/*############################################################################################################
########################################## >>>> Diaa12360 <<<< ###############################################
########################################### Just Nothing #################################################
#################################### If You Need it, Fight For IT; #########################################
###############################################.-. 1 5 9 2 .-.################################################
############################################################################################################*/
import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Solution {
static final int maxN = 1000000000;
static int dx[] = {1, 0, 0, -1};
static int dy[] = {0, -1, 1, 0};
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
// in = new BufferedReader(new FileReader("in.text"));
StringBuilder out = new StringBuilder();
StringTokenizer tk;
int t = anInt(in.readLine());
while (t-- > 0) {
int n = anInt(in.readLine());
String[][] arr = new String[3][n];
Map<String, Integer> mp = new HashMap<>();
for (int i = 0; i < 3; i++) {
tk = new StringTokenizer(in.readLine());
for (int j = 0; j < n; j++) {
arr[i][j] = tk.nextToken();
if(mp.containsKey(arr[i][j]) && mp.get(arr[i][j]) > 1){
mp.put(arr[i][j], 1);
}
else if(!mp.containsKey(arr[i][j])){
mp.put(arr[i][j], 3);
}
else {
mp.put(arr[i][j], 0);
}
}
}
for (String[] a: arr) {
int count = 0;
for (String s: a) {
count += mp.get(s);
}
out.append(count).append(' ');
}
out.append('\n');
}
System.out.println(out);
}
static boolean v[][];
static int solve(int cuX, int cuY, int sx, int sy, int n, int m, int d, int count) {
if (cuX == n && cuY == m) {
return count;
}
v[cuX][cuY] = true;
int c = 0;
for (int i = 0; i < 4; i++) {
int nextX = cuX + dx[i];
int nextY = cuY + dy[i];
if (nextX > n || nextY > m || nextX < 1 || nextY < 1 || v[nextX][nextY])
continue;
if (Math.abs(nextY - sy) + Math.abs(nextX - sx) <= d)
continue;
c++;
return solve(nextX, nextY, sx, sy, n, m, d, count + 1);
}
if (c == 0) {
return -1;
}
return -1;
}
/*
3
2 3 1 3 0
2 3 1 3 1
5 5 3 4 2
*/
static int lcm(int a, int b) {
return a / gcd(a, b) * b;
}
static int gcd(int a, int b) {
if (a == 0) {
return b;
}
return gcd(b % a, a);
}
//all primes
static ArrayList<Integer> primes;
static boolean[] primesB;
//sieve algorithm
static void sieve(int n) {
primes = new ArrayList<>();
primesB = new boolean[n + 1];
for (int i = 2; i <= n; i++) {
primesB[i] = true;
}
for (int i = 2; i * i <= n; i++) {
if (primesB[i]) {
for (int j = i * i; j <= n; j += i) {
primesB[j] = false;
}
}
}
for (int i = 0; i <= n; i++) {
if (primesB[i]) {
primes.add(i);
}
}
}
// Function to find gcd of array of
// numbers
static int findGCD(int[] arr, int n) {
int result = arr[0];
for (int element : arr) {
result = gcd(result, element);
if (result == 1) {
return 1;
}
}
return result;
}
private static int anInt(String s) {
return Integer.parseInt(s);
}
}
class Pair<K, V> implements Comparable<Pair<K, V>> {
K first;
V second;
Pair(K f, V s) {
first = f;
second = s;
}
@Override
public int compareTo(Pair<K, V> o) {
return 0;
}
}
class PairInt implements Comparable<PairInt> {
int first;
int second;
PairInt(int f, int s) {
first = f;
second = s;
}
@Override
public int compareTo(PairInt o) {
if (this.first > o.first) {
return 1;
} else if (this.first < o.first)
return -1;
else {
if (this.second < o.second)
return 1;
else if (this.second == o.second)
return -1;
return 0;
}
}
@Override
public String toString() {
return "<" + first + ", " + second + ">";
}
}
/*
5 1
5 4 3 2 1
1 4
5 3
1 2 3 5 4
1 3
4 5
3 5
5 3
1 2 2 2 1
1 4
2 5
1 5
5 2
1 1 1 2 1
2 3
4 5
10
1 3 1 5 2 3 5 7 4 3
5
1 1 1 1 2
1
4
2 4 1 2
4
1 3 1 3
3
3 3 2
5
4 1 5 3 2
1
1
5
1 2
3 3
5 3
3 6
8 4
*/
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
924adaa9c6266214f0a1a3bc067f26cf
|
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 Task_1722C {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for (int i = 0; i < t; i++) {
solve(in);
}
}
private static void solve(Scanner in) {
Set<String> s1 = new HashSet<>();
Set<String> s2 = new HashSet<>();
Set<String> s3 = new HashSet<>();
long n = in.nextInt();
for (int i = 0; i < n; ++i) {
s1.add(in.next());
}
for (int i = 0; i < n; ++i) {
s2.add(in.next());
}
for (int i = 0; i < n; ++i) {
s3.add(in.next());
}
long r1 = 0, r2 = 0, r3 = 0;
for (String s : s1) {
if(!s2.contains(s) && !s3.contains(s)) {
r1 += 3;
} else if (!s2.contains(s) || !s3.contains(s)) {
r1 += 1;
}
}
for (String s : s2) {
if(!s1.contains(s) && !s3.contains(s)) {
r2 += 3;
} else if (!s1.contains(s) || !s3.contains(s)) {
r2 += 1;
}
}
for (String s : s3) {
if(!s2.contains(s) && !s1.contains(s)) {
r3 += 3;
} else if (!s2.contains(s) || !s1.contains(s)) {
r3 += 1;
}
}
System.out.println(r1 + " " + r2 + " " + r3);
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
63aba5f11155316af65951952175fcf5
|
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
|
/*
*
* * *
* * * * *
* P A U L A *
* * * * * * * * * *
* * * * * * * * * * * *
* * * * * * * * * * * * * *
*/
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import static java.lang.Double.*;
import static java.lang.Float.*;
public class Main {
static final BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
static final InputStream inputStream = System.in;
static final FastReader in = new FastReader(inputStream);
public static void main(String[] args) throws IOException {
int numOfTestCase = 1;//in.nextInt() ;
while (numOfTestCase-- > 0) Task.solve(in, out);
finish();
}
static class Task {
public static void solve(FastReader input, BufferedWriter out) throws IOException {
/*
----------------------------------------------------------------------------------------------------------
كود بيتاكد ان كل الحروف الابجدية موجودة ف الاسترنج
distinct() ميثود بتحذف تكرار الحروف يعني مثلا
aabbcc
هتكون
abc
int n=input.nextInt();
System.out.println(input.next().toLowerCase().chars().distinct().count()>=26?"YES":"NO");
----------------------------------------------------------------------------------------------------------
>>>>>>>>> soooooort String <<<<<<<<<<<<
String s = in.next(); //cba
char[] Arr = s.toCharArray();
Arrays.sort(Arr);
String x = new String(Arr);
System.out.println(x);
----------------------------------------------------------------------------------------------------------
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>MMMMMMAAAAAAAAPPPPPPPP<<<<<<<<<<<<<<<<<<<<<<<
int n = in.nextInt();
HashMap<String,Integer> mp = new HashMap<>();
for (int i = 1 ; i<=n ; i++)
{
String s = in.next();
if (!mp.containsKey(s))
{
mp.put(s,0);
System.out.println("OK");
}
else
{
mp.put(s,mp.get(s)+1);
System.out.println(s+mp.get(s));
}
}
----------------------------------------------------------------------------------------------------------
>>>>>>>>>>>>>>>مودلس للاسترنج>>>>>>>>>>>>>>>>>
String s= input.next();
BigInteger b =new BigInteger(s);
if (b.mod(new BigInteger("9")).equals(new BigInteger("0")))
System.out.println("YES");
else
System.out.println("NO");
**********************************************
String s= input.next();
int i=0;
for (int j = 0; j <s.length() ; j++) {
i=(i+(s.charAt(s.length()-1-j) -'0')%9) % 9;
}
System.out.println(i==0?"YES" : "NO");
------------------------------------------------------------------------------------------------------------
<<<<<<<<<<<<<<<<<<<< PREFEX SUM<<<<<<<<<<<<<<<<<<<<<<<
int size=input.nextInt();
int range=input.nextInt();
long arr[]=new long [size];
for (int i = 0; i <size ; i++) {
arr[i]=input.nextInt();
if (i==0)
continue;
arr[i]+=arr[i-1];
}
for (int i = 0; i <range ; i++) {
int ind1=input.nextInt();
int ind2=input.nextInt();
System.out.print(ind1 -1 ==0?arr[--ind2] +"\n" : arr[--ind2] - arr[ind1-2]+"\n");
}
-----------------------------------------------------------------------------------------------------------------
GCD قانون
BigInteger b1=BigInteger.valueOf(input.nextInt());
BigInteger b2=BigInteger.valueOf(input.nextInt());
BigInteger b3=b1.gcd(b2);
System.out.println(b3);
-------------------------------------------------------------------------------------------------------------------
قانونLCM
BigInteger b1=BigInteger.valueOf(input.nextInt());
BigInteger b2=BigInteger.valueOf(input.nextInt());
BigInteger b3=b1.gcd(b2);
System.out.println((b1.multiply(b2)) .divide(b3));
--------------------------------------------------------------------------------------------------------------------
*/
//---------------------------------------------------------------------------------------------------------//
int t=input.nextInt();
while (t-->0) {
int num = input.nextInt();
Map<String, Integer> map = new HashMap<>();
ArrayList<String> arr1 = new ArrayList<>();
ArrayList<String> arr2 = new ArrayList<>();
ArrayList<String> arr3 = new ArrayList<>();
for (int i = 0; i < num; i++) {
String str = input.next();
arr1.add(str);
if (map.containsKey(str))
map.replace(str, map.get(str) + 1);
else map.put(str, 1);
}
for (int i = 0; i < num; i++) {
String str = input.next();
arr2.add(str);
if (map.containsKey(str))
map.replace(str, map.get(str) + 1);
else map.put(str, 1);
}
for (int i = 0; i < num; i++) {
String str = input.next();
arr3.add(str);
if (map.containsKey(str))
map.replace(str, map.get(str) + 1);
else map.put(str, 1);
}
int n1 = 0, n2 = 0, n3 = 0;
for (int i = 0; i < num; i++) {
if (map.get(arr1.get(i)) == 1) n1 += 3;
else if (map.get(arr1.get(i)) == 2) n1 += 1;
if (map.get(arr2.get(i)) == 1) n2 += 3;
else if (map.get(arr2.get(i)) == 2) n2 += 1;
if (map.get(arr3.get(i)) == 1) n3 += 3;
else if (map.get(arr3.get(i)) == 2) n3 += 1;
}
out.write(n1 + " " + n2 + " " + n3 + "\n");
}
//---------------------------------------------------------------------------------------------------------//
}
}
static int[] readArray1d(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = in.nextInt();
return a;
}
static int[][] readArray2d(int row, int col) throws IOException {
int[][] a = new int[row][col];
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
a[i][j] = in.nextInt();
}
}
return a;
}
static long[][] readArray2d(long row, long col) throws IOException {
long[][] a = new long[(int) row][(int) col];
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
a[i][j] = in.nextLong();
}
}
return a;
}
private static void printArray(int[] numbers) throws IOException {
for (int number : numbers) {
out.write(number + " ");
}
}
private static void printArray(long[] numbers) throws IOException {
for (long number : numbers) {
out.write(number + " ");
}
}
static class FastReader {
private static byte[] buf = new byte[1024];
private static int index;
private static InputStream in;
private static int total;
public FastReader(InputStream in) {
FastReader.in = in;
}
public static int scan() throws IOException {
if (total < 0) throw new InputMismatchException();
if (index >= total) {
index = 0;
total = in.read(buf);
if (total <= 0) return -1;
}
return buf[index++];
}
public int nextInt() throws IOException {
int integer = 0;
int n = scan();
while (isWhiteSpace(n)) n = scan();
int neg = 1;
if (n == '-') {
neg = -1;
n = scan();
}
while (!isWhiteSpace(n)) {
if (n >= '0' && n <= '9') {
integer *= 10;
integer += n - '0';
n = scan();
} else {
throw new InputMismatchException();
}
}
return neg * integer;
}
public double nextDouble() throws IOException {
return parseDouble(next());
}
public double nextFloat() throws IOException {
return parseFloat(next());
}
public long nextLong() throws IOException {
long integer = 0;
long n = scan();
while (isWhiteSpace(n)) n = scan();
long neg = 1;
if (n == '-') {
neg = -1;
n = scan();
}
while (!isWhiteSpace(n)) {
if (n >= '0' && n <= '9') {
integer *= 10;
integer += n - '0';
n = scan();
} else {
throw new InputMismatchException();
}
}
return neg * integer;
}
public String next() throws IOException {
StringBuilder sb = new StringBuilder();
int n = scan();
while (isWhiteSpace(n)) n = scan();
while (!isWhiteSpace(n)) {
sb.append((char) n);
n = scan();
}
return sb.toString();
}
public String nextLine() throws IOException {
StringBuilder sb = new StringBuilder();
int n = scan();
while (isWhiteSpace(n)) n = scan();
while (!newLine(n)) {
sb.append((char) n);
n = scan();
}
return sb.toString();
}
private static boolean isWhiteSpace(long n) {
return n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1;
}
private boolean newLine(long n) {
return n == '\n' || n == -1;
}
}
static void finish() throws IOException {
out.flush();
out.close();
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
790f806271cc7c039e8fa22e1df59ff2
|
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 Test62 {
public static void main (String[] args) throws java.lang.Exception {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
int i;
for (i = 0; i < t; i++) {
int n = sc.nextInt();
sc.nextLine();
String[] str = new String[n*3];
int count = 0;
Map<String, Integer> map = new HashMap<>();
int j;
for(j=0; j<n*3; j++) {
count++;
str[j] = sc.next();
if(!map.containsKey(str[j])) {
map.put(str[j], 1);
} else {
map.put(str[j], map.get(str[j]) + 1);
}
if(count == n) {
count = 0;
}
}
int number = 0;
int m = 1;
for(j=0; j<str.length; j++) {
if(map.get(str[j]) == 1) {
number = number + 3;
} else if(map.get(str[j]) == 2) {
number = number + 1;
}
if(j == m*n -1) {
System.out.print(number + " ");
m++;
number = 0;
}
}
System.out.print("\n");
}
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
b2df6edca5a313fe4ed259ae2d9830da
|
train_109.jsonl
|
1661871000
|
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
|
256 megabytes
|
import java.util.*;
import java.io.*;
import java.math.*;
/**
* @author Naitik
*
*/
public class Main
{
static FastReader sc=new FastReader();
static int dp[][];
// static boolean v[][][];
// static int mod=998244353;;
static int mod=1000000007;
static long max;
static int bit[];
static PrintWriter out=new PrintWriter(System.out);
public static void main(String[] args)
{
// StringBuffer sb=new StringBuffer("");
int ttt=1;
ttt =i();
outer :while (ttt-- > 0)
{
int n=i();
String A[]=inputS(n);
String B[]=inputS(n);
String C[]=inputS(n);
HashSet<String> set1=new HashSet<String>(),set2=new HashSet<String>(),set3=new HashSet<String>();
for(int i=0;i<n;i++) {
set1.add(A[i]);
set2.add(B[i]);
set3.add(C[i]);
}
int a=0,b=0,c=0;
for(int i=0;i<n;i++) {
String s=A[i];
if(set2.contains(s) && set3.contains(s)) {
}
else if(set2.contains(s) || set3.contains(s)) {
a++;
}
else {
a+=3;
}
s=B[i];
if(set1.contains(s) && set3.contains(s)) {
}
else if(set1.contains(s) || set3.contains(s)) {
b++;
}
else {
b+=3;
}
s=C[i];
if(set1.contains(s) && set2.contains(s)) {
}
else if(set1.contains(s) || set2.contains(s)) {
c++;
}
else {
c+=3;
}
}
System.out.println(a+" "+b+" "+c);
}
//System.out.println(sb.toString());
out.close();
//CHECK FOR N=1 //CHECK FOR M=0
//CHECK FOR N=1 //CHECK FOR M=0
//CHECK FOR N=1
}
// public static void main(String args[]) {
// Scanner sc=new Scanner(System.in);
//
// }
static class Pair implements Comparable<Pair>
{
int x;
int y;
int z;
Pair(int x,int y){
this.x=x;
this.y=y;
// this.z=z;
}
@Override
public int compareTo(Pair o) {
if(this.x>o.x)
return 1;
else if(this.x<o.x)
return -1;
else {
if(this.y>o.y)
return 1;
else if(this.y<o.y)
return -1;
else
return 0;
}
}
public int hashCode()
{
final int temp = 14;
long ans = 1;
ans =x*31+y*13;
return (int)ans;
}
// @Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null) {
return false;
}
if (this.getClass() != o.getClass()) {
return false;
}
Pair other = (Pair)o;
if (this.x != other.x || this.y!=other.y) {
return false;
}
return true;
}
//
/* FOR TREE MAP PAIR USE */
// public int compareTo(Pair o) {
// if (x > o.x) {
// return 1;
// }
// if (x < o.x) {
// return -1;
// }
// if (y > o.y) {
// return 1;
// }
// if (y < o.y) {
// return -1;
// }
// return 0;
// }
}
//static int find(int A[],int a) {
// if(A[a]==a)
// return a;
// return A[a]=find(A, A[a]);
//}
//FENWICK TREE
static void update(int i, int x){
for(; i < bit.length; i += (i&-i))
bit[i] += x;
}
static int sum(int i){
int ans = 0;
for(; i > 0; i -= (i&-i))
ans += bit[i];
return ans;
}
//END
static void add(HashMap<Long,Integer> map,long v) {
if(!map.containsKey(v)) {
map.put(v, 1);
}
else {
map.put(v, map.get(v)+1);
}
}
static void remove(HashMap<Long,Integer> map,long v) {
if(map.containsKey(v)) {
map.put(v, map.get(v)-1);
if(map.get(v)==0)
map.remove(v);
}
}
static void add(HashMap<Integer,Integer> map,int v) {
if(!map.containsKey(v)) {
map.put(v, 1);
}
else {
map.put(v, map.get(v)+1);
}
}
static void remove(HashMap<Integer,Integer> map,int v) {
if(map.containsKey(v)) {
map.put(v, map.get(v)-1);
if(map.get(v)==0)
map.remove(v);
}
}
static void add(TreeMap<Integer,Integer> map,int v) {
if(!map.containsKey(v)) {
map.put(v, 1);
}
else {
map.put(v, map.get(v)+1);
}
}
static void add(TreeMap<Long,Integer> map,long v) {
if(!map.containsKey(v)) {
map.put(v, 1);
}
else {
map.put(v, map.get(v)+1);
}
}
static void remove(TreeMap<Integer,Integer> map,int v) {
if(map.containsKey(v)) {
map.put(v, map.get(v)-1);
if(map.get(v)==0)
map.remove(v);
}
}
static void remove(TreeMap<Long,Integer> map,long v) {
if(map.containsKey(v)) {
map.put(v, map.get(v)-1);
if(map.get(v)==0)
map.remove(v);
}
}
static long modInverse(long n, int p)
{
return power(n, p - 2, p);
}
static int[] copy(int A[]) {
int B[]=new int[A.length];
for(int i=0;i<A.length;i++) {
B[i]=A[i];
}
return B;
}
static long[] copy(long A[]) {
long B[]=new long[A.length];
for(int i=0;i<A.length;i++) {
B[i]=A[i];
}
return B;
}
static int[] input(int n) {
int A[]=new int[n];
for(int i=0;i<n;i++) {
A[i]=sc.nextInt();
}
return A;
}
static long[] inputL(int n) {
long A[]=new long[n];
for(int i=0;i<n;i++) {
A[i]=sc.nextLong();
}
return A;
}
static String[] inputS(int n) {
String A[]=new String[n];
for(int i=0;i<n;i++) {
A[i]=sc.next();
}
return A;
}
static long sum(int A[]) {
long sum=0;
for(int i : A) {
sum+=i;
}
return sum;
}
static long sum(long A[]) {
long sum=0;
for(long i : A) {
sum+=i;
}
return sum;
}
static void reverse(long A[]) {
int n=A.length;
long B[]=new long[n];
for(int i=0;i<n;i++) {
B[i]=A[n-i-1];
}
for(int i=0;i<n;i++)
A[i]=B[i];
}
static void reverse(int A[]) {
int n=A.length;
int B[]=new int[n];
for(int i=0;i<n;i++) {
B[i]=A[n-i-1];
}
for(int i=0;i<n;i++)
A[i]=B[i];
}
static void input(int A[],int B[]) {
for(int i=0;i<A.length;i++) {
A[i]=sc.nextInt();
B[i]=sc.nextInt();
}
}
static int[][] input(int n,int m){
int A[][]=new int[n][m];
for(int i=0;i<n;i++) {
for(int j=0;j<m;j++) {
A[i][j]=i();
}
}
return A;
}
static char[][] charinput(int n,int m){
char A[][]=new char[n][m];
for(int i=0;i<n;i++) {
String s=s();
for(int j=0;j<m;j++) {
A[i][j]=s.charAt(j);
}
}
return A;
}
static int nextPowerOf2(int n)
{
if(n==0)
return 1;
n--;
n |= n >> 1;
n |= n >> 2;
n |= n >> 4;
n |= n >> 8;
n |= n >> 16;
n++;
return n;
}
static int highestPowerof2(int x)
{
x |= x >> 1;
x |= x >> 2;
x |= x >> 4;
x |= x >> 8;
x |= x >> 16;
return x ^ (x >> 1);
}
static long highestPowerof2(long x)
{
x |= x >> 1;
x |= x >> 2;
x |= x >> 4;
x |= x >> 8;
x |= x >> 16;
return x ^ (x >> 1);
}
static int max(int A[]) {
int max=Integer.MIN_VALUE;
for(int i=0;i<A.length;i++) {
max=Math.max(max, A[i]);
}
return max;
}
static int min(int A[]) {
int min=Integer.MAX_VALUE;
for(int i=0;i<A.length;i++) {
min=Math.min(min, A[i]);
}
return min;
}
static long max(long A[]) {
long max=Long.MIN_VALUE;
for(int i=0;i<A.length;i++) {
max=Math.max(max, A[i]);
}
return max;
}
static long min(long A[]) {
long min=Long.MAX_VALUE;
for(int i=0;i<A.length;i++) {
min=Math.min(min, A[i]);
}
return min;
}
static long [] prefix(long A[]) {
long p[]=new long[A.length];
p[0]=A[0];
for(int i=1;i<A.length;i++)
p[i]=p[i-1]+A[i];
return p;
}
static long [] prefix(int A[]) {
long p[]=new long[A.length];
p[0]=A[0];
for(int i=1;i<A.length;i++)
p[i]=p[i-1]+A[i];
return p;
}
static long [] suffix(long A[]) {
long p[]=new long[A.length];
p[A.length-1]=A[A.length-1];
for(int i=A.length-2;i>=0;i--)
p[i]=p[i+1]+A[i];
return p;
}
static long [] suffix(int A[]) {
long p[]=new long[A.length];
p[A.length-1]=A[A.length-1];
for(int i=A.length-2;i>=0;i--)
p[i]=p[i+1]+A[i];
return p;
}
static void fill(int dp[]) {
Arrays.fill(dp, -1);
}
static void fill(int dp[][]) {
for(int i=0;i<dp.length;i++)
Arrays.fill(dp[i], -1);
}
static void fill(int dp[][][]) {
for(int i=0;i<dp.length;i++) {
for(int j=0;j<dp[0].length;j++) {
Arrays.fill(dp[i][j],-1);
}
}
}
static void fill(int dp[][][][]) {
for(int i=0;i<dp.length;i++) {
for(int j=0;j<dp[0].length;j++) {
for(int k=0;k<dp[0][0].length;k++) {
Arrays.fill(dp[i][j][k],-1);
}
}
}
}
static void fill(long dp[]) {
Arrays.fill(dp, -1);
}
static void fill(long dp[][]) {
for(int i=0;i<dp.length;i++)
Arrays.fill(dp[i], -1);
}
static void fill(long dp[][][]) {
for(int i=0;i<dp.length;i++) {
for(int j=0;j<dp[0].length;j++) {
Arrays.fill(dp[i][j],-1);
}
}
}
static void fill(long dp[][][][]) {
for(int i=0;i<dp.length;i++) {
for(int j=0;j<dp[0].length;j++) {
for(int k=0;k<dp[0][0].length;k++) {
Arrays.fill(dp[i][j][k],-1);
}
}
}
}
static int min(int a,int b) {
return Math.min(a, b);
}
static int min(int a,int b,int c) {
return Math.min(a, Math.min(b, c));
}
static int min(int a,int b,int c,int d) {
return Math.min(a, Math.min(b, Math.min(c, d)));
}
static int max(int a,int b) {
return Math.max(a, b);
}
static int max(int a,int b,int c) {
return Math.max(a, Math.max(b, c));
}
static int max(int a,int b,int c,int d) {
return Math.max(a, Math.max(b, Math.max(c, d)));
}
static long min(long a,long b) {
return Math.min(a, b);
}
static long min(long a,long b,long c) {
return Math.min(a, Math.min(b, c));
}
static long min(long a,long b,long c,long d) {
return Math.min(a, Math.min(b, Math.min(c, d)));
}
static long max(long a,long b) {
return Math.max(a, b);
}
static long max(long a,long b,long c) {
return Math.max(a, Math.max(b, c));
}
static long max(long a,long b,long c,long d) {
return Math.max(a, Math.max(b, Math.max(c, d)));
}
static long power(long x, long y, long p)
{
if(y==0)
return 1;
if(x==0)
return 0;
long res = 1;
x = x % p;
while (y > 0) {
if (y % 2 == 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
static long power(long x, long y)
{
if(y==0)
return 1;
if(x==0)
return 0;
long res = 1;
while (y > 0) {
if (y % 2 == 1)
res = (res * x);
y = y >> 1;
x = (x * x);
}
return res;
}
static void print(int A[]) {
for(int i : A) {
out.print(i+" ");
}
out.println();
}
static void print(long A[]) {
for(long i : A) {
System.out.print(i+" ");
}
System.out.println();
}
static long mod(long x) {
return ((x%mod + mod)%mod);
}
static String reverse(String s) {
StringBuffer p=new StringBuffer(s);
p.reverse();
return p.toString();
}
static int i() {
return sc.nextInt();
}
static String s() {
return sc.next();
}
static long l() {
return sc.nextLong();
}
static void sort(int[] A){
int n = A.length;
Random rnd = new Random();
for(int i=0; i<n; ++i){
int tmp = A[i];
int randomPos = i + rnd.nextInt(n-i);
A[i] = A[randomPos];
A[randomPos] = tmp;
}
Arrays.sort(A);
}
static void sort(long[] A){
int n = A.length;
Random rnd = new Random();
for(int i=0; i<n; ++i){
long tmp = A[i];
int randomPos = i + rnd.nextInt(n-i);
A[i] = A[randomPos];
A[randomPos] = tmp;
}
Arrays.sort(A);
}
static String sort(String s) {
Character ch[]=new Character[s.length()];
for(int i=0;i<s.length();i++) {
ch[i]=s.charAt(i);
}
Arrays.sort(ch);
StringBuffer st=new StringBuffer("");
for(int i=0;i<s.length();i++) {
st.append(ch[i]);
}
return st.toString();
}
static HashMap<Integer,Integer> hash(int A[]){
HashMap<Integer,Integer> map=new HashMap<Integer, Integer>();
for(int i : A) {
if(map.containsKey(i)) {
map.put(i, map.get(i)+1);
}
else {
map.put(i, 1);
}
}
return map;
}
static HashMap<Long,Integer> hash(long A[]){
HashMap<Long,Integer> map=new HashMap<Long, Integer>();
for(long i : A) {
if(map.containsKey(i)) {
map.put(i, map.get(i)+1);
}
else {
map.put(i, 1);
}
}
return map;
}
static TreeMap<Integer,Integer> tree(int A[]){
TreeMap<Integer,Integer> map=new TreeMap<Integer, Integer>();
for(int i : A) {
if(map.containsKey(i)) {
map.put(i, map.get(i)+1);
}
else {
map.put(i, 1);
}
}
return map;
}
static TreeMap<Long,Integer> tree(long A[]){
TreeMap<Long,Integer> map=new TreeMap<Long, Integer>();
for(long i : A) {
if(map.containsKey(i)) {
map.put(i, map.get(i)+1);
}
else {
map.put(i, 1);
}
}
return map;
}
static boolean prime(int n)
{
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
double sq=Math.sqrt(n);
for (int i = 5; i <= sq; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
static boolean prime(long n)
{
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
double sq=Math.sqrt(n);
for (int i = 5; i <= sq; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
static int gcd(int a, int b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
static long gcd(long a, long b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
0bf3e601a2c051e66dff3ec4316f8917
|
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();
while (t-- > 0){
int n = sc.nextInt();
sc.nextLine();
String[] p1 = sc.nextLine().split("\\s+");
String[] p2 = sc.nextLine().split("\\s+");
String[] p3 = sc.nextLine().split("\\s+");
HashMap<String, Integer> words = new HashMap<>();
for (int i=0; i<n; i++){
if (words.containsKey(p1[i])){
words.put(p1[i], words.get(p1[i])+1);
} else words.put(p1[i], 1);
if (words.containsKey(p2[i])){
words.put(p2[i], words.get(p2[i])+1);
} else words.put(p2[i], 1);
if (words.containsKey(p3[i])){
words.put(p3[i], words.get(p3[i])+1);
} else words.put(p3[i], 1);
}
int point1 = 0, point2 = 0, point3 = 0;
for (int i=0; i<n; i++){
int occurs = words.get(p1[i]);
if (occurs == 1){
point1 += 3;
} else if (occurs == 2) {
point1 += 1;
}
occurs = words.get(p2[i]);
if (occurs == 1){
point2 += 3;
} else if (occurs == 2) {
point2 += 1;
}
occurs = words.get(p3[i]);
if (occurs == 1){
point3 += 3;
} else if (occurs == 2) {
point3 += 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 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
926657ebd8b67fdd6572d4150040084b
|
train_109.jsonl
|
1661871000
|
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
|
256 megabytes
|
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
public class abhinandan6065_Test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
StringBuilder sb = new StringBuilder();
int quary = sc.nextInt();
while (quary-- > 0) {
int n = sc.nextInt();
Map<String, Integer> hm = new TreeMap<>();
List<ArrayList<String>> al = new ArrayList<>();
for (int i = 0; i < 3; i++) {
ArrayList<String> al2 = new ArrayList<>();
for (int j = 0; j < n; j++) {
String val = sc.next();
al2.add(val);
if (!hm.containsKey(val)) {
hm.put(val, 1);
} else {
hm.replace(val, hm.get(val) + 1);
}
}
al.add(al2);
}
int ans[] = new int[3];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < n; j++) {
int val = hm.get(al.get(i).get(j));
if (val == 1) {
ans[i] = ans[i] + 3;
} else if (val == 2) {
ans[i] = ans[i] + 1;
} else {
ans[i] = ans[i] + 0;
}
}
}
for (Integer el : ans) {
sb.append(el + " ");
}
sb.append("\n");
}
System.out.print(sb);
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
df1bac3a8c88445440278a564258cfd9
|
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.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.*;
public class Cf_0 {
public static void main(String[] args) throws IOException {
// Reader r= new Reader();
Scanner sc= new Scanner(System.in);
int t= sc.nextInt();
for(int i=0;i<t;i++){
int n=sc.nextInt();
String[][]strs= new String[3][n];
// int []arr= new int[n];
for(int it=0;it<3;it++){
for(int jt=0;jt<n;jt++){
strs[it][jt]=sc.next();
}
}
solveA(strs);
}
}
//
public static void solveA(String[][]grid){
long count=0;
HashMap<String,Integer>occ= new HashMap<>();
HashSet<String>temp= new HashSet<>();
for(int i=0;i<3;i++){
temp= new HashSet<>();
for(int j=0;j<grid[i].length;j++){
if(!temp.contains(grid[i][j])){
temp.add(grid[i][j]);
}
}
for(String it:temp){
occ.put(it,occ.getOrDefault(it,0)+1);
}
}
for(int i=0;i<3;i++){
int sum=0;
for(int j=0;j<grid[i].length;j++){
if(occ.get(grid[i][j])==1){
sum+=3;
}
else if(occ.get(grid[i][j])==2){
sum+=1;
}
}
System.out.print(sum+" ");
}
System.out.println();
//System.out.println(list);
}
public static void print(int []a){
for(int t:a){
if(t!=0)
System.out.print(t+" ");
}
System.out.println();
}
}
class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(
new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n') {
if (cnt != 0) {
break;
}
else {
continue;
}
}
buf[cnt++] = (byte)c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ') {
c = read();
}
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0,
BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
66661cc8133ab1d3b76263bd308025d9
|
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 {
public static void main(String[] args) throws IOException {
FastReader in = new FastReader(System.in);
PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
int t = in.nextInt();
for (int tt = 0; tt < t; tt++) {
int n = in.nextInt();
HashMap<String, Integer> mp1 = new HashMap<>();
HashMap<String, Integer> mp2 = new HashMap<>();
HashMap<String, Integer> mp3 = new HashMap<>();
for (int i = 0; i < n; i++) {
mp1.put(in.next(), -1);
}
for (int i = 0; i < n; i++) {
mp2.put(in.next(), -1);
}
for (int i = 0; i < n; i++) {
mp3.put(in.next(), -1);
}
int one = 0, two = 0, three = 0;
for (Map.Entry<String, Integer> i : mp1.entrySet()) {
String x = i.getKey();
if (!mp2.containsKey(x) && !mp3.containsKey(x)) one += 3;
if ((mp2.containsKey(x) && !mp3.containsKey(x)) || (!mp2.containsKey(x) && mp3.containsKey(x))) one++;
}
for (Map.Entry<String, Integer> i : mp2.entrySet()) {
String x = i.getKey();
if (!mp1.containsKey(x) && !mp3.containsKey(x)) two += 3;
if ((mp1.containsKey(x) && !mp3.containsKey(x)) || (!mp1.containsKey(x) && mp3.containsKey(x))) two++;
}
for (Map.Entry<String, Integer> i : mp3.entrySet()) {
String x = i.getKey();
if (!mp1.containsKey(x) && !mp2.containsKey(x)) three += 3;
if ((mp1.containsKey(x) && !mp2.containsKey(x)) || (!mp1.containsKey(x) && mp2.containsKey(x))) three++;
}
pw.println(one + " " + two + " " + three);
}
pw.close();
}
public static void Sort(int[] a) {
ArrayList<Integer> lst = new ArrayList<>();
for (int i : a) lst.add(i);
Collections.sort(lst);
for (int i = 0; i < lst.size(); i++) a[i] = lst.get(i);
}
static void debug(Object... obj) {
System.err.println(Arrays.deepToString(obj));
}
static class FastReader {
InputStream is;
private byte[] inbuf = new byte[1024];
private int lenbuf = 0, ptrbuf = 0;
public FastReader(InputStream is) {
this.is = is;
}
public int readByte() {
if (lenbuf == -1) throw new InputMismatchException();
if (ptrbuf >= lenbuf) {
ptrbuf = 0;
try {
lenbuf = is.read(inbuf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0) return -1;
}
return inbuf[ptrbuf++];
}
public boolean isSpaceChar(int c) {
return !(c >= 33 && c <= 126);
}
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
public int skip() {
int b;
while ((b = readByte()) != -1 && isSpaceChar(b)) ;
return b;
}
public String next() {
int b = skip();
StringBuilder sb = new StringBuilder();
while (!(isSpaceChar(b))) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public String nextLine() {
int c = skip();
StringBuilder sb = new StringBuilder();
while (!isEndOfLine(c)) {
sb.appendCodePoint(c);
c = readByte();
}
return sb.toString();
}
public int nextInt() {
int num = 0, b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = (num << 3) + (num << 1) + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
public long nextLong() {
long num = 0;
int b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = (num << 3) + (num << 1) + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
public double nextDouble() {
return Double.parseDouble(next());
}
public char[] next(int n) {
char[] buf = new char[n];
int b = skip(), p = 0;
while (p < n && !(isSpaceChar(b))) {
buf[p++] = (char) b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
public char readChar() {
return (char) skip();
}
public long[] readArrayL(int n) {
long[] arr = new long[n];
for (int i = 0; i < n; i++) arr[i] = nextLong();
return arr;
}
public int[] readArray(int n) {
int[] arr = new int[n];
for (int i = 0; i < n; i++) arr[i] = nextInt();
return arr;
}
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
e20311d21a46247e16d237177c259c0b
|
train_109.jsonl
|
1661871000
|
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
|
256 megabytes
|
import java.util.Scanner;
import java.util.HashMap;
public class WordGame {
public static void main(String arg[])
{
Scanner scan=new Scanner(System.in);
int t=scan.nextInt();
for(int i=0;i<t;i++)
{
int n=scan.nextInt();
String str[][]=new String[3][n];
HashMap<String,Integer> hs=new HashMap<String,Integer>();
for(int j=0;j<3;j++)
{
for(int k=0;k<n;k++)
{
str[j][k]=scan.next();
hs.put(str[j][k],hs.getOrDefault(str[j][k], 0)+1);
}
}
int s=0;
for(int j=0;j<3;j++)
{
s=0;
for(int k=0;k<n;k++)
{
if(hs.get(str[j][k])==1)
s+=3;
else if(hs.get(str[j][k])==2)
s+=1;
}
System.out.print(s+" ");
}
System.out.println("");
}
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
43054fb7e075ffae791f6f4fe0255058
|
train_109.jsonl
|
1661871000
|
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
|
256 megabytes
|
//package com.company;
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.stream.IntStream;
import java.math.*;
import java.util.stream.Stream;
public class Scanner {
static boolean[] x;
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public Scanner(FileReader r) {
br = new BufferedReader(r);
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public String nextLine() throws IOException {
return br.readLine();
}
public double nextDouble() throws IOException {
String x = next();
StringBuilder sb = new StringBuilder("0");
double res = 0, f = 1;
boolean dec = false, neg = false;
int start = 0;
if (x.charAt(0) == '-') {
neg = true;
start++;
}
for (int i = start; i < x.length(); i++)
if (x.charAt(i) == '.') {
res = Long.parseLong(sb.toString());
sb = new StringBuilder("0");
dec = true;
} else {
sb.append(x.charAt(i));
if (dec)
f *= 10;
}
res += Long.parseLong(sb.toString()) / f;
return res * (neg ? -1 : 1);
}
public long[] nextlongArray(int n) throws IOException {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public Long[] nextLongArray(int n) throws IOException {
Long[] a = new Long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public int[] nextIntArray(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public Integer[] nextIntegerArray(int n) throws IOException {
Integer[] a = new Integer[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public boolean ready() throws IOException {
return br.ready();
}
/*public static void luckyNumbers(int a, int b, ArrayList x) {
if(a>Math.pow(10,9) || b>Math.pow(10,9))
return;
x.add(a);
x.add(b);
luckyNumbers((a*10)+4,(b*10)+4,x);
luckyNumbers((a*10)+7,(b*10)+7,x);
} */
public static void prefixSum(long[] prefix, long[] steps) { // prefix Sum for the cost Array
prefix[0] = steps[0];
for(int i=1;i<steps.length;i++)
prefix[i] = prefix[i-1] + steps[i];
}
public static void prefixSumSorted(Integer[] costSorted, long[] prefixSum) { // prefix Sum for the sorted cost Array
prefixSum[0] = costSorted[0];
for(int i=1;i<costSorted.length;i++)
prefixSum[i] = prefixSum[i-1] + costSorted[i];
}
/* public static boolean isOperator(char c) {
return c == '^' || c == '/' || c == '*' || c == '+' || c == '-';
}
public static int getPrecedence(char c) {
case '+', '-' -> 1;
case '*', '/' -> 3;
default -> 5;
};
} */
public static boolean isPrime (int a) {
for(int i=2;i<a;i++) {
if(a%i == 0)
return false;
}
return true;
}
/*public static int getP(int y) {
int p = 0;
for(int i=2;i<=y;i++) {
if(y%i == 0 && x.contains(y))
p++;
}
return p;
} */
public static void luckyNumbers(long a, ArrayList x) {
if(a>Math.pow(10,15))
return;
if(a!=0)
x.add(a);
luckyNumbers(a*10+4,x);
luckyNumbers(a*10+7,x);
}
public static boolean isFullCol(char[][] x, int j , char c) {
boolean flag = false;
for(int i=0;i<8;i++) {
if(x[i][j] != c) {
flag = true;
break;
}
}
return !flag;
}
public static boolean isFullRow(char[][] x, int j , char c) {
boolean flag = false;
for(int i=0;i<8;i++) {
if(x[j][i] != c) {
flag = true;
break;
}
}
return !flag;
}
// CODE STARTS HERE
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
char[] alphabet = "abcdefghijklmnopqrstuvwxyz".toCharArray();
int t = sc.nextInt();
for(int i=0;i<t;i++) {
int n = sc.nextInt();
String[] a = new String[n];
String[] b = new String[n];
String[] c = new String[n];
String a1 = sc.nextLine();
String b1 = sc.nextLine();
String c1 = sc.nextLine();
a = a1.split(" ");
b = b1.split(" ");
c = c1.split(" ");
String[] d = new String[3*n];
int k =0;
int ptsA = 0;
int ptsB = 0;
int ptsC = 0;
for(int j=0;j<n;j++) {
d[k] = a[j];
k++;
d[k] = b[j];
k++;
d[k] = c[j];
k++;
}
HashMap<String,Integer> map = new HashMap<>();
for(int j=0;j<(3*n);j++) {
if(map.containsKey(d[j])) {
int temp = map.get(d[j]);
map.replace(d[j] , temp+1);
}
else
map.put(d[j], 1);
}
for(int j=0;j<n;j++) {
if(map.get(a[j]) == 1)
ptsA += 3;
else if(map.get(a[j]) == 2)
ptsA += 1;
if(map.get(b[j]) == 1)
ptsB += 3;
else if(map.get(b[j]) == 2)
ptsB += 1;
if(map.get(c[j]) == 1)
ptsC += 3;
else if(map.get(c[j]) == 2)
ptsC += 1;
}
System.out.println(ptsA + " " + ptsB + " " + ptsC);
}
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
55b5ffaa86a23f3aeffc33a056ddcded
|
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.*;
/**
* @Author: yuluo
* @CreateTime: 2022-10-14 15:48
* @Description: TODO
*/
public class Demo4 {
public static void main(String[] args) {
int score = 0;
List<String> list = new ArrayList<>();
Scanner scanner = new Scanner(System.in);
Map<String, Integer> map = new HashMap<>();
int total = scanner.nextInt();
for (int i = 0; i < total; i++) {
int dataTotal = scanner.nextInt();
for (int j = 0; j < 3 * dataTotal; j++) {
String next = scanner.next();
list.add(next);
}
// 统计各个元素出现的次数
Integer occurrences;
for (String s : list) {
occurrences = map.get(s);
map.put(s, (occurrences == null) ? 1 : occurrences + 1);
}
// System.out.println(map);
int start = 0;
for (int x = 1; x <= 3; x++) {
// 将每个人输入的数据放进去一个list中
int end = x * dataTotal;
for (; start < end; start ++) {
int appear = map.get(list.get(start));
if (appear == 1) {
score += 3;
} else if (appear == 2){
score += 1;
}
}
System.out.print(score + " ");
score = 0;
}
System.out.println();
list.clear();
map.clear();
}
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
0e9ab502c91b1ede01b8a552a14de116
|
train_109.jsonl
|
1661871000
|
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class WordGame {
public static void main(String[] args) {
try {
FastReader in = new FastReader();
PrintWriter out = new PrintWriter(System.out);
int testcases = in.nextInt();
while (testcases-- > 0) {
int n = in.nextInt();
HashMap<String, Integer> map = new HashMap<>();
String[][] a = new String[3][n];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < n; j++) {
a[i][j] = in.next();
map.put(a[i][j], map.getOrDefault(a[i][j], 0) + 1);
}
}
int[] ans = new int[3];
for (int i = 0; i < 3; i++) {
int curr = 0;
for (int j = 0; j < n; j++) {
if (map.get(a[i][j]) == 1)
curr += 3;
else if (map.get(a[i][j]) == 2)
curr += 1;
else
curr += 0;
}
ans[i] = curr;
}
for (int i : ans) {
out.print(i + " ");
}
out.println();
}
out.close();
} catch (Exception e) {
// TODO: handle exception
return;
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
long[] readLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
String nextLine() {
String str = "";
try {
str = br.readLine().trim();
} catch (Exception e) {
e.printStackTrace();
}
return str;
}
}
static boolean LOCAL = System.getProperty("ONLINE_JUDGE") == null;
static void dbg(Object... o) {
if (LOCAL)
System.err.println(Arrays.deepToString(o));
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
72e1d949e6a0f61f3a997462c6378a88
|
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;
public class R817C {
public static void main(String[] args) throws IOException{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(in.readLine());
while(n-- > 0){
Map<String,Integer> map=new HashMap<>();
int l=Integer.parseInt(in.readLine());
String[] s1=in.readLine().split(" ");
String[] s2=in.readLine().split(" ");
String[] s3=in.readLine().split(" ");
int a1=0,a2=0,a3=0;
for(String s:s1){
map.put(s, map.getOrDefault(s, 0)+1);
}
for(String s:s2){
map.put(s, map.getOrDefault(s, 0)+1);
}
for(String s:s3){
map.put(s, map.getOrDefault(s, 0)+1);
}
for(String s:s1){
int t=map.get(s);
if(t==1){
a1+=3;
}else if(t==2){
a1++;
}
}
for(String s:s2){
int t=map.get(s);
if(t==1){
a2+=3;
}else if(t==2){
a2++;
}
}
for(String s:s3){
int t=map.get(s);
if(t==1){
a3+=3;
}else if(t==2){
a3++;
}
}
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 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
57bf648d7f3555169db192b80858ab2b
|
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 {
private static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
String[][] a = new String[3][n];
Map<String, Integer> map = new HashMap<>();
for (int i = 0; i < 3; i++) {
for (int j = 0; j < n; j++) {
a[i][j] = sc.next();
map.put(a[i][j], map.getOrDefault(a[i][j], 0) + 1);
}
}
int[] res = new int[3];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < n; j++) {
int cnt = map.get(a[i][j]);
if (cnt == 1) res[i] += 3;
if (cnt == 2) res[i] += 1;
}
}
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 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
3b6160b25fe1a7123ddba10c2abab2ea
|
train_109.jsonl
|
1661871000
|
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.StringTokenizer;
public class CodeForce_1722_C {
public static void main(String[] args) throws IOException {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer tokens = new StringTokenizer(read.readLine());
int T = Integer.parseInt(tokens.nextToken());
for (int test = 0; test < T; test++) {
int N = Integer.parseInt(read.readLine());
ArrayList<String> A = new ArrayList<>();
ArrayList<String> B = new ArrayList<>();
ArrayList<String> C = new ArrayList<>();
HashMap<String, Integer> Dict = new HashMap<>();
int ar = 0;
int br = 0;
int cr = 0;
tokens = new StringTokenizer(read.readLine());
StringTokenizer tokens2 = new StringTokenizer(read.readLine());
StringTokenizer tokens3 = new StringTokenizer(read.readLine());
for (int i = 0; i < N; i++) {
String a = tokens.nextToken();
String b = tokens2.nextToken();
String c = tokens3.nextToken();
A.add(a);
B.add(b);
C.add(c);
if (!Dict.containsKey(a)) {
Dict.put(a, 3);
} else {
int r = Dict.get(a);
if (r == 3) {
Dict.replace(a, 1);
} else if (r == 1) {
Dict.replace(a, 0);
}
}
if (!Dict.containsKey(b)) {
Dict.put(b, 3);
} else {
int r = Dict.get(b);
if (r == 3) {
Dict.replace(b, 1);
} else if (r == 1) {
Dict.replace(b, 0);
}
}
if (!Dict.containsKey(c)) {
Dict.put(c, 3);
} else {
int r = Dict.get(c);
if (r == 3) {
Dict.replace(c, 1);
} else if (r == 1) {
Dict.replace(c, 0);
}
}
}
for (int i = 0; i < N; i++) {
ar += Dict.get(A.get(i));
br += Dict.get(B.get(i));
cr += Dict.get(C.get(i));
}
System.out.printf("%d %d %d\n", ar, br, cr);;
}
}
private static int makeInteger(String temp) {
int result = 0;
for (int i = 0; i < 3; i++) {
result += temp.charAt(i) - 'a';
}
return result;
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
b2d23dd406ff7f4489e0509568fd5a54
|
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.StringTokenizer;
public class Main{
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();
}
String nextLine() throws IOException {return br.readLine();}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
static FastScanner in = new FastScanner();
static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) throws IOException {
int t = in.nextInt();
HashMap<String,String> map = new HashMap<>();
while(t-- != 0) {
map.clear();
in.nextInt();
for (int i = 0; i < 3; i++) {
String s = in.nextLine();
StringTokenizer tk = new StringTokenizer(s);
String temp;
while(tk.hasMoreTokens()){
temp = tk.nextToken();
map.put(temp, map.getOrDefault(temp,"")+i);
}
}
int[]arr = new int[3];
for(String h: map.values()){
if(h.length() == 3) continue;
else if(h.length() == 2) {
arr[Integer.parseInt(h.charAt(0) + "")] += 1;
arr[Integer.parseInt(h.charAt(1) + "")] += 1;
}
else arr[Integer.parseInt(h.charAt(0) + "")] += 3;
}
out.println(arr[0] + " " + arr[1] + " " + arr[2]);
}
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 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
b364e36c2f5eccb663d6eea5e585e3bc
|
train_109.jsonl
|
1661871000
|
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
|
256 megabytes
|
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;
public class WordGame {
public static void main(String[] args) {
Scanner 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];
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++) {
int count=0;
for (int j = 0; j < n; j++) {
int x = hm.get(str[i][j]);
if(x==1){
count+=3;
}
else if(x==2){
count+=1;
}
}
System.out.print(count+" ");
}
System.out.println();
}
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
621ee024e517caf0066e6cbd7c3de472
|
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 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
b5c41ca5769c030647bd62288166e6ca
|
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();
sc.nextLine();
String x=sc.nextLine();
String y=sc.nextLine();
String z=sc.nextLine();
String[] xarr=x.split(" ");
String[] yarr=y.split(" ");
String[] zarr=z.split(" ");
HashSet<String> st1=new HashSet<>();
HashSet<String> st2=new HashSet<>();
HashSet<String> st3=new HashSet<>();
for(int i=0;i<n;i++){
st1.add(xarr[i]);
st2.add(yarr[i]);
st3.add(zarr[i]);
}
Iterator<String> it1=st1.iterator();
int sum1=0;
while(it1.hasNext()){
String cap=it1.next();
if((st2.contains(cap) && !st3.contains(cap)) || (st3.contains(cap) && !st2.contains(cap))){
sum1+=1;
}else if(!(st2.contains(cap)) && !(st3.contains(cap))){
sum1+=3;
}
}
Iterator<String> it2=st2.iterator();
int sum2=0;
while(it2.hasNext()){
String cap=it2.next();
if((st1.contains(cap) && !st3.contains(cap)) || (st3.contains(cap) && !st1.contains(cap))){
sum2+=1;
}else if(!(st1.contains(cap)) && !(st3.contains(cap))){
sum2+=3;
}
}
Iterator<String> it3=st3.iterator();
int sum3=0;
while(it3.hasNext()){
String cap=it3.next();
if((st2.contains(cap) && !st1.contains(cap)) || (st1.contains(cap) && !st2.contains(cap))){
sum3+=1;
}else if(!(st2.contains(cap)) && !(st1.contains(cap))){
sum3+=3;
}
}
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 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
ba03c77ab2aeaa21a84093fe3c8b871f
|
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 cp {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
List<String> res = new ArrayList<>();
while (t-- > 0) {
int numWords = in.nextInt();
String[][] arr = new String[3][numWords];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < numWords; j++) {
arr[i][j] = in.next();
}
}
solution(arr);
}
}
public static void solution(String[][] arr) {
Map<String, List<Integer>> map = new HashMap<>();
int[] pScore = new int[3];
for (int i = 0; i < 3; i++) {
for (String word : arr[i]) {
if (!map.containsKey(word)) map.put(word, new ArrayList<>());
if (map.get(word).size() == 1) {
pScore[map.get(word).get(0)] -= 2;
pScore[i] += 1;
} else if (map.get(word).size() == 2) {
pScore[0] -= 1;
pScore[1] -= 1;
} else {
pScore[i] += 3;
}
map.get(word).add(i);
}
}
System.out.println(pScore[0] + " " + pScore[1] + " " + pScore[2]);
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
5a970a11e2ea250b44c170f8af701218
|
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 B {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int nroCasos=in.nextInt();
in.nextLine();
int nroPalabras;
String linea;
HashMap<String,String> dicPalabras;
int[]puntajes;
do{
nroPalabras=in.nextInt();
in.nextLine();
puntajes=new int[3];
dicPalabras=new HashMap<>();
for(int i=0;i<3;i++){
linea=in.nextLine();
String [] palabras=linea.split(" ");
String apariciones="";
for(int j=0;j<palabras.length;j++){
String palabra=palabras[j];
if(!dicPalabras.containsKey(palabra))
dicPalabras.put(palabra,"");
apariciones=dicPalabras.get(palabra)+i;
dicPalabras.put(palabra,apariciones);
}
}
for(String key: dicPalabras.keySet()){
String repetido=dicPalabras.get(key);
int index; int puntos;
switch (repetido.length()){
case 1: puntos=3; break;
case 2: puntos=1; break;
default: puntos=0;break;
}
for(int l=0;l<repetido.length();l++){
index=Character.getNumericValue(repetido.charAt(l));
puntajes[index]+=puntos;
}
}
System.out.println(puntajes[0]+" "+puntajes[1]+" "+puntajes[2]);
nroCasos--;
}while (nroCasos>0);
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
21371f218cd39d17a403fe2a177a9460
|
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 {
public static void main(String args[]) throws IOException {
PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
int t = nextInt();
while (t-->0) {
int n = nextInt(); int[] point = {0, 0, 0};
HashMap<String, Boolean[]> words = new HashMap<>();
for (int p = 0; p < 3; p++) {
for (int i = 0; i < n; i++) {
String w = next();
if (words.putIfAbsent(w, new Boolean[]{p==0, p==1, p==2}) != null) {
Boolean[] tr = words.get(w); tr[p] = true;
if (p==1) {point[0] -= 2; point[p] += 1;}
else if (p==2 && tr[0] && tr[1]) {point[0] -= 1; point[1] -= 1;}
else if (p==2 && tr[0]) {point[0] -= 2; point[p] += 1;}
else {point[1] -= 2; point[p] += 1;}
words.put(w, tr);
//out.println(point[0] + " " + point[1] + " " + point[2] + " w " + p);
}
else{point[p] += 3;}
}
}
out.println(point[0] + " " + point[1] + " " + point[2]);
}
out.close();
}
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer st = new StringTokenizer("");
static String next() throws IOException {
while (!st.hasMoreElements()) {st = new StringTokenizer(br.readLine());}
return st.nextToken();
}
static int nextInt() throws IOException {return Integer.parseInt(next());}
static long nextLong() throws IOException {return Long.parseLong(next());}
static double nextDouble() throws IOException {return Double.parseDouble(next());}
static String nextLine() {
String str = "";
try {str = br.readLine();}
catch (IOException e) {e.printStackTrace();}
return str;
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
f9e27d67e6edb02bf2e174425fc5f747
|
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 abc{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
String [][]s=new String[3][n];
for(int i=0;i<3;i++){
for(int j=0;j<n;j++){
s[i][j]=sc.next();
}
}
wordGame(s,n);
}
}
public static void wordGame(String[][]str,int n){
HashMap<String,Integer>hm=new HashMap<>();
for(int i=0;i<3;i++){
for(int j=0;j<n;j++){
hm.put(str[i][j],hm.getOrDefault(str[i][j],0)+1);
}
}
for(int i=0;i<3;i++){
int total=0;
for(int j=0;j<n;j++){
if(hm.get(str[i][j])==1){
total+=3;
}
else if(hm.get(str[i][j])==2){
total+=1;
}
else{
total+=0;
}
}
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 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
b2dd000eb55a0c29c728db3027c70685
|
train_109.jsonl
|
1661871000
|
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
|
256 megabytes
|
import java.util.*;
import java.lang.*;
import java.io.*;
public class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
try{
FastReader read=new FastReader();
StringBuilder sb = new StringBuilder();
int t=read.nextInt();
for(int k=1;k<=t;k++)
{
//sb.append("Case #"+k+": ");
int n = read.nextInt();
String s[][] = new String[3][n];
Hashtable<String,Integer> ht = new Hashtable<String,Integer>();
int a[] = new int[50];
for(int i=0;i<3;i++)
{
for(int j=0;j<n;j++)
{
s[i][j]=read.next();
//System.out.println(s[i][j]);
if(ht.containsKey(s[i][j]))
{
//System.out.println(ht.get(s[i][j]));
a[ht.get(s[i][j])]--;
ht.put(s[i][j],ht.get(s[i][j])*(i+2));
// System.out.println(ht.get(s[i][j]));
a[ht.get(s[i][j])]++;
}
else
{
ht.put(s[i][j],(i+2));
a[i+2]++;
}
}
}
//System.out.println("g");
int x=0,y=0,z=0;
x+=3*a[2];
y+=3*a[3];
z+=3*a[4];
x+=a[6]+a[8];
y+=a[6]+a[12];
z+=a[12]+a[8];
//System.out.println("g");
sb.append(x+" "+y+" "+z);
sb.append('\n');
}
System.out.println(sb);
}
catch(Exception e)
{return;
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
static void sort(int[] A) {
int n = A.length;
Random rnd = new Random();
for (int i = 0; i < n; ++i) {
int tmp = A[i];
int randomPos = i + rnd.nextInt(n - i);
A[i] = A[randomPos];
A[randomPos] = tmp;
}
Arrays.sort(A);
}
static void sort(long[] A) {
int n = A.length;
Random rnd = new Random();
for (int i = 0; i < n; ++i) {
long tmp = A[i];
int randomPos = i + rnd.nextInt(n - i);
A[i] = A[randomPos];
A[randomPos] = tmp;
}
Arrays.sort(A);
}
static void sort(ArrayList<Long> A,char ch) {
int n = A.size();
Random rnd = new Random();
for (int i = 0; i < n; ++i) {
long tmp = A.get(i);
int randomPos = i + rnd.nextInt(n - i);
A.set(i,A.get(randomPos));
A.set(randomPos,tmp);
}
Collections.sort(A);
}
static void sort(ArrayList<Integer> A) {
int n = A.size();
Random rnd = new Random();
for (int i = 0; i < n; ++i) {
int tmp = A.get(i);
int randomPos = i + rnd.nextInt(n - i);
A.set(i,A.get(randomPos));
A.set(randomPos,tmp);
}
Collections.sort(A);
}
static String sort(String s) {
Character ch[] = new Character[s.length()];
for (int i = 0; i < s.length(); i++) {
ch[i] = s.charAt(i);
}
Arrays.sort(ch);
StringBuffer st = new StringBuffer("");
for (int i = 0; i < s.length(); i++) {
st.append(ch[i]);
}
return st.toString();
}
}
class pair implements Comparable<pair>
{
int X,Y,C;
pair(int s,int e,int c)
{
X=s;
Y=e;
C=c;
}
public int compareTo(pair p )
{
return this.C-p.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 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
c657ca8bbd0883be3ef50e995fcb1fa3
|
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 E {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int T = in.nextInt();
for(int tt = 0; tt<T; tt++) {
int n = in.nextInt();
HashSet<String> first = new HashSet<>();
HashSet<String> second = new HashSet<>();
HashSet<String> third = new HashSet<>();
int cnt1 = 0;
int cnt2 = 0;
int cnt3 = 0;
for(int i = 0; i<n; i++) {
first.add(in.next());
}
for(int i = 0; i<n; i++) {
second.add(in.next());
}
for(int i = 0; i<n; i++) {
third.add(in.next());
}
cnt1 = check(first, second, third);
cnt2 = check(second, first, third);
cnt3 = check(third, first, second);
System.out.println(cnt1+" "+cnt2+" "+cnt3);
}
}
private static int check(HashSet<String> first, HashSet<String> second, HashSet<String> third) {
int cnt = 0;
for(String s: first) {
if(second.contains(s) && third.contains(s)) {
cnt += 0;
}
else if(second.contains(s) || third.contains(s)) {
cnt += 1;
}
else {
cnt +=3;
}
}
return cnt;
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
252c52bc4682b39ab42a4b7fb676e0a6
|
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 HelloWorld {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
while(n>0){
int x=sc.nextInt();
Map<String, Integer> hm=new HashMap<>();
String arr[][]=new String[3][x];
for(int i=0;i<3;i++){
for(int j=0;j<x;j++){
String s=sc.next();
arr[i][j]=s;
if(hm.containsKey(s)){
hm.put(s, hm.get(s)+1);
}else{
hm.put(s, 1);
}
}
}
for(int i=0;i<3;i++){
int val=0;
for(int j=0;j<x;j++){
if(hm.get(arr[i][j])==1){
val+=3;
}else if(hm.get(arr[i][j])==2){
val+=1;
}
}
System.out.print(val+" ");
}
System.out.println();
n--;
}
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
5f24da43f0d3e20c7fae7eb6f8906cfe
|
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.*;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scn=new Scanner(System.in);
int n=scn.nextInt();
while (n>0){
int a=scn.nextInt();
HashMap<String,Integer>map=new HashMap <>();
String [][]arr=new String[3][a];
for(int i=0;i<3;i++){
for (int j=0;j<a;j++){
String str=scn.next();
arr[i][j]=str;
map.put(str,map.getOrDefault(str,0)+1);
}
}
for (int i=0;i<3;i++){
int c=0;
for (int j=0;j<a;j++){
if(map.get(arr[i][j])==1){
c+=3;
}else if(map.get(arr[i][j])==2){
c+=1;
}
}
System.out.print(c+" ");
}
System.out.println();
n--;
}
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
2f438f9d533da132a949229824a45b6e
|
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 Codeforce6 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int x=0;x<t;x++)
{
HashMap<String,Integer> h=new HashMap<>();
ArrayList<ArrayList<String>> res=new ArrayList<>();
int n=sc.nextInt();
for(int i=0;i<3;i++)
{
ArrayList<String> arr1=new ArrayList<>();
for(int j=0;j<n;j++)
{
String temp=sc.next();
arr1.add(temp);
h.put(temp,h.getOrDefault(temp,0)+1);
}
res.add(arr1);
}
for(int i=0;i<3;i++)
{
int count=0;
for(int j=0;j<res.get(i).size();j++)
{
if(h.get(res.get(i).get(j))==1)
count+=3;
else if(h.get(res.get(i).get(j))==2)
count+=1;
}
System.out.print(count+" ");
}
System.out.println();
}
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
ef782f1f54673b80491d07773e49a940
|
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 codeforce;
import java.io.*;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
public class C817 {
public static void main(String[] args) {
InputReader in = new InputReader(System.in);
PrintWriter out = new PrintWriter(System.out);
Task solver = new Task();
solver.solve(in.nextInt(), in, out);
out.close();
}
static class Task {
public void solve(int testNumber, InputReader in, PrintWriter out) {
for (int t = 0; t < testNumber; t++) {
int n = in.nextInt();
String[][] list = new String[3][n];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < n; j++) {
list[i][j] = in.next();
}
}
out.println(resolve(list));
}
}
public String resolve(String[][] list) {
Map<String, Integer> map = new HashMap<>();
for (String[] strings : list) {
for (String str : strings) {
map.put(str, map.getOrDefault(str, 0) + 1);
}
}
int[] res = new int[3];
for (int i = 0; i < 3; i++) {
for (String s : list[i]) {
switch (map.get(s)) {
case 1:
res[i] += 3;
break;
case 2:
res[i] += 1;
}
}
}
return res[0] + " " + res[1] + " " + res[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 long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public int[] nextArray(int n) {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = nextInt();
}
return arr;
}
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
85889efd188e36b19ef9308949c674be
|
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();
while (t-- > 0) {
int n = in.nextInt();
Map<String, Integer> map = new HashMap<>();
String arr1[] = new String[n];
String arr2[] = new String[n];
String arr3[] = new String[n];
for (int i = 0; i < n; i++) {
arr1[i] = in.next();
map.put(arr1[i], map.getOrDefault(arr1[i], 0) + 1);
}
for (int i = 0; i < n; i++) {
arr2[i] = in.next();
map.put(arr2[i], map.getOrDefault(arr2[i], 0) + 1);
}
for (int i = 0; i < n; i++) {
arr3[i] = in.next();
map.put(arr3[i], map.getOrDefault(arr3[i], 0) + 1);
}
int sum1 = 0;
int sum2 = 0;
int sum3 = 0;
for (int i = 0; i < n; i++) {
if (map.get(arr1[i]) == 1) {
sum1 += 3;
} else if (map.get(arr1[i]) == 2) {
sum1 += 1;
}
}
for (int i = 0; i < n; i++) {
if (map.get(arr2[i]) == 1) {
sum2 += 3;
} else if (map.get(arr2[i]) == 2) {
sum2 += 1;
}
}
for (int i = 0; i < n; i++) {
if (map.get(arr3[i]) == 1) {
sum3 += 3;
} else if (map.get(arr3[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 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
b86e9a7061ba81309a348422abf9a487
|
train_109.jsonl
|
1661871000
|
Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows: if a word was written by one person — that person gets 3 points, if a word was written by two people — each of the two gets 1 point, if a word was written by all — nobody gets any points. In the end, how many points does each player have?
|
256 megabytes
|
import java.util.*;
public class Main {
public static void main ( String[] args ) {
Scanner scan = new Scanner (System.in);
int t= scan.nextInt ();
while(t>0){
Map <String, Integer> map = new HashMap<> ();
int n= scan.nextInt ();
Vector < Vector < String> > vec = new Vector< Vector <String>> ();
for(int i=0;i<3;i++){
Vector <String> tv= new Vector<String> ();
for(int j=0;j<n;j++){
String s= scan.next ();
tv.add (s);
if(map.containsKey (s)){
int times= map.get(s);
times++;
map.put (s,times);
}
else{
map.put (s,1);
}
}
vec.add (tv);
}
for(int i=0;i<3;i++){
int ans=0;
for(int j=0;j<n;j++){
int times= map.get ((vec.get (i)).get (j));
if(times==1){
ans+=3;
}
else if(times==2){
ans+=1;
}
}
System.out.print (ans+" ");
}
System.out.println ();
t--;
}
}
}
|
Java
|
["3\n\n1\n\nabc\n\ndef\n\nabc\n\n3\n\norz for qaq\n\nqaq orz for\n\ncod for ces\n\n5\n\niat roc hem ica lly\n\nbac ter iol ogi sts\n\nbac roc lly iol iat"]
|
1 second
|
["1 3 1 \n2 2 6 \n9 11 5"]
|
NoteIn the first test case: The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point. The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.
|
Java 8
|
standard input
|
[
"data structures",
"implementation"
] |
f8a89510fefbbc8e5698efe8a0c30927
|
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.
| 800
|
For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.
|
standard output
| |
PASSED
|
09ec8b990c6d8657b741de5596992df8
|
train_109.jsonl
|
1661871000
|
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class Main {
// static int[] prime = new int[100001];
final static long mod = 1000000007;
static boolean[] vis;
static int[] val;
public static void main(String[] args) {
// sieve();
InputReader in = new InputReader(System.in);
PrintWriter out = new PrintWriter(System.out);
int t = in.nextInt();
while(t-- > 0){
int n = in.nextInt();
int k = (1<<29) ^ (1 << 30);
for(int i = 1; i <= n-3; i++){
out.print(i + " ");
k = k ^ i;
}
out.println((1 << 29) + " " + (1 << 30) + " " + k);
}
out.flush();
}
private static int left(int n) {
int i = 0;
while(n != 0){
if(n == 1){
return i;
}
i++;
n = n >> 1;
}
return 0;
}
static long gcd(long a, long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
static Integer[] intInput(int n, InputReader in) {
Integer[] a = new Integer[n];
for (int i = 0; i < a.length; i++)
a[i] = in.nextInt();
return a;
}
static Long[] longInput(int n, InputReader in) {
Long[] a = new Long[n];
for (int i = 0; i < a.length; i++)
a[i] = in.nextLong();
return a;
}
static String[] strInput(int n, InputReader in) {
String[] a = new String[n];
for (int i = 0; i < a.length; i++)
a[i] = in.next();
return a;
}
// static void sieve() {
// for (int i = 2; i * i < prime.length; i++) {
// if (prime[i])
// continue;
// for (int j = i * i; j < prime.length; j += i) {
// prime[j] = true;
// }
// }
// }
}
class Segment {
int[] a;
final int n;
Segment(int n){
this.n = n;
a = new int[4*n];
Arrays.fill(a, Integer.MIN_VALUE);
}
void set(int index, int val){
set(0, n-1, 0, index, val);
}
private void set(int s, int e, int ind, int index, int val) {
if(s == e){
a[ind] = val;
return;
}
int mid = (s+e)/2;
if(mid <= index){
set(s, mid, 2*ind+1, index, val);
}else{
set(mid+1, e, 2*ind+2, index, val);
}
a[ind] = Math.max(a[2*ind+1], a[2*ind+2]);
}
int get(int l, int h){
return get(0, n-1, l, h, 0);
}
private int get(int s, int e, int l, int h, int ind) {
if(s >= l && e <= h){
return a[ind];
}
if(s > h || e < l){
return Integer.MIN_VALUE;
}
int mid = (s+e)/2;
return Math.max(get(s, mid, l, h, 2*ind+1), get(mid+1, e, l, h, 2*ind+2));
}
}
class Data{
int i, j;
long val;
public Data(int i, int j, long val) {
this.i = i;
this.j = j;
this.val = val;
}
}
// class compareVal implements Comparator<Data> {
// @Override
// public int compare(Data o1, Data o2) {
// return (o1.val - o2.val);
// }
// }
// class compareInd implements Comparator<Data> {
// @Override
// public int compare(Data o1, Data o2) {
// return o1.ind - o2.ind == 0 ? o1.val - o2.val : o1.ind - o2.ind;
// }
// }
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());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = reader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
|
Java
|
["7\n8\n3\n4\n5\n6\n7\n9"]
|
1 second
|
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
|
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
|
Java 17
|
standard input
|
[
"bitmasks",
"constructive algorithms",
"greedy"
] |
52bd5dc6b92b2af5aebd387553ef4076
|
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
| 1,500
|
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
|
standard output
| |
PASSED
|
ff2932b07036343e05e71e062d335044
|
train_109.jsonl
|
1661871000
|
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
|
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 void solve() throws IOException {
int tc=in.nextInt();
while(tc-->0)
{
int n=in.nextInt();
int case1=0,case2=0;
long ans=((long)1<<31)-1;
for(int i=0;i<n-2;i++)
{
case1^=i;
case2^=(i+1);
}
if(case1!=0)
{
for(int i=0;i<n-2;i++)
System.out.print(i+" ");
case1^=ans;
System.out.println(ans + " " + case1);
}
else
{
for(int i=1;i<=n-2;i++)
System.out.print(i+" ");
case2^=ans;
System.out.println(ans + " " + case2);
}
}
}
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
|
["7\n8\n3\n4\n5\n6\n7\n9"]
|
1 second
|
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
|
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
|
Java 17
|
standard input
|
[
"bitmasks",
"constructive algorithms",
"greedy"
] |
52bd5dc6b92b2af5aebd387553ef4076
|
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
| 1,500
|
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
|
standard output
| |
PASSED
|
66c8554e876f0c9c882ee1fc334a058a
|
train_109.jsonl
|
1661871000
|
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
|
256 megabytes
|
import java.util.*;
import java.io.*;
// import java.util.Random;
// import java.util.stream.Collectors;
public class EvenOddXor {
public static void main(String[] args) throws IOException {
// Scanner s = new Scanner(new File("input.txt"));
Scanner s = new Scanner(System.in);
// System.setOut(new PrIntegerStream(new File("output.txt")));
Integer t = s.nextInt();
// s.nextLine();
for(Integer i = 0; i < t; i++){
// List<Integer> arr = Arrays.asList(s.nextLine().trim().split(" ")).parallelStream().map((String k) -> Integer.parseInteger(k)).collect(Collectors.toList());
Integer n = s.nextInt();
// System.out.prIntegerln(n);
HashSet<Integer> ls = new HashSet<Integer>();
for(Integer j = 0; j <= n-3; j++){
ls.add(j);
}
// boolean ans_got = false;
Integer xor_till_now = xors(ls);
Integer init_j = n-1;
Integer last_one;
// System.out.println(n);
// System.out.println(ls);
Iterator<Integer> m = ls.iterator();
while(true){
last_one = xor_till_now ^ init_j;
if(last_one.equals(init_j)){
ls.remove(m.next());
// initial++;
init_j++;
ls.add(init_j);
xor_till_now = xors(ls);
init_j++;
}
else if(ls.contains(last_one)){
init_j++;
}
else{
break;
}
}
// System.out.printf("%d %d\n", init_j, last_one);
ls.add(init_j);
ls.add(last_one);
Iterator<Integer> j = ls.iterator();
while(j.hasNext()){
Integer tmp = j.next();
System.out.print(tmp + " ");
}
System.out.println();
// System.out.println("Xor:: " + xors(ls));
// System.out.println("Ans:: " + verify(ls));
}
s.close();
}
private static Integer xors(HashSet<Integer> arr){
Iterator<Integer> i = arr.iterator();
Integer ans = 0;
while(i.hasNext()){
Integer k = i.next();
ans = ans ^ k;
}
return ans;
}
private static Integer verify(HashSet<Integer> arr){
Iterator<Integer> j = arr.iterator();
Integer ans = 0;
while(j.hasNext()){
ans = ans ^ j.next();
}
// System.out.prIntegerln(ans);
return ans;
}
}
|
Java
|
["7\n8\n3\n4\n5\n6\n7\n9"]
|
1 second
|
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
|
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
|
Java 17
|
standard input
|
[
"bitmasks",
"constructive algorithms",
"greedy"
] |
52bd5dc6b92b2af5aebd387553ef4076
|
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
| 1,500
|
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
|
standard output
| |
PASSED
|
34d610042510b6c673d980c194b51f8c
|
train_109.jsonl
|
1661871000
|
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
|
256 megabytes
|
import java.util.Scanner;
public class EvenOddXOR {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int numTestCase = sc.nextInt();
for (int i = 0; i < numTestCase; i++) {
int n = sc.nextInt();
if (n % 4 == 0) {
for (int j = 0; j < n; j++) {
System.out.print(j + " ");
}
System.out.println();
} else if (n % 4 == 1) {
System.out.print("0 ");
for (int j = 0; j < n - 1; j++) {
System.out.print((j + 2) + " ");
}
System.out.println();
} else if (n % 4 == 2) {
System.out.print("2 3 1 4 12 8 ");
for (int j = 0; j < n - 6; j++) {
System.out.print((14 + j) + " ");
}
System.out.println();
} else if (n % 4 == 3) {
System.out.print("2 1 3 ");
for (int j = 0; j < n - 3; j++) {
System.out.print((j + 4) + " ");
}
System.out.println();
}
}
}
}
|
Java
|
["7\n8\n3\n4\n5\n6\n7\n9"]
|
1 second
|
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
|
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
|
Java 17
|
standard input
|
[
"bitmasks",
"constructive algorithms",
"greedy"
] |
52bd5dc6b92b2af5aebd387553ef4076
|
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
| 1,500
|
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
|
standard output
| |
PASSED
|
2a3d49728176dbe9b66c43267f481829
|
train_109.jsonl
|
1661871000
|
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
|
256 megabytes
|
import java.io.*;
import java.util.*;
import java.awt.*;
public class Main {
public static void main(String[] args) throws IOException {
var in=new FastInput();
StringBuffer res=new StringBuffer();
var t=in.getIntArray(1)[0];
int[] pow=new int[31];
pow[0]=1;
for (int i = 1; i < pow.length; i++) {
pow[i]=pow[i-1]<<1;
}
int a=1<<29;
int[][] last={{},{0},{},{1,2,3},{4,5,6,7},{0,4,5,6,7},{a+(4<<24),a+(1<<24),a+(2<<24),a+(12<<24),a+(3<<24),a+(8<<24)},{1,2,3,4,5,6,7}};
for (int i = 0; i < t; i++) {
var n=in.getAutoIntArray()[0];
int[] r=new int[n];
int index=0;
int wait=n%8;
if(wait==2){
for (int j = pow.length-1; j >=3 ; j--) {
if(n==pow[j]+2){
for (int j2 = 0; j2 < last[6].length; j2++) {
r[index]=last[6][j2];
index++;
n-=6;
}
for (int j2 = j-1; j2 >= 2; j2--) {
for (int k = 0; k < pow[j2]; k++) {
r[index]=pow[j2]+k;
index++;
}
}
break;
}else if(n>pow[j]){
for (int j2 = 0; j2 < pow[j]; j2++) {
r[index]=pow[j]+j2;
index++;
}
n-=pow[j];
}
}
}else{
for (int j = pow.length-1; j >=3 ; j--) {
if(n>=pow[j]){
for (int j2 = 0; j2 < pow[j]; j2++) {
r[index]=pow[j]+j2;
index++;
}
n-=pow[j];
}
}
for (int j = 0; j < last[wait].length; j++) {
r[index]=last[wait][j];
index++;
}
}
res.append(in.getArrayString(r));
res.append("\n");
}
System.out.println(res.toString().substring(0,res.length()-1));
}
}
class FastInput {
BufferedReader in = null;
public FastInput() {
in = new BufferedReader(new InputStreamReader(System.in));
}
public int[] getAutoIntArray() throws IOException {
String[] data=in.readLine().split(" ");
int[] res=new int[data.length];
for (int i = 0; i < res.length; i++) {
res[i]=Integer.valueOf(data[i]);
}
return res;
}
public int[] getIntArray(int len) throws IOException {
int[] res = new int[len];
String[] data = in.readLine().split(" ");
for (int i = 0; i < res.length; i++) {
res[i] = Integer.valueOf(data[i]);
}
return res;
}
public ArrayList<Integer> getIntArrayList(int len) throws IOException {
ArrayList<Integer> res = new ArrayList<>();
String[] data = in.readLine().split(" ");
for (int i = 0; i < len; i++) {
res.add(Integer.valueOf(data[i]));
}
return res;
}
public Integer[] getIntegerArray(int len) throws IOException {
Integer[] res = new Integer[len];
String[] data = in.readLine().split(" ");
for (int i = 0; i < res.length; i++) {
res[i] = Integer.valueOf(data[i]);
}
return res;
}
public long[] getLongArray(int len) throws IOException {
long[] res = new long[len];
String[] data = in.readLine().split(" ");
for (int i = 0; i < res.length; i++) {
res[i] = Long.valueOf(data[i]);
}
return res;
}
public ArrayList<Long> getLongArrayList(int len) throws IOException {
ArrayList<Long> res = new ArrayList<>();
String[] data = in.readLine().split(" ");
for (int i = 0; i < len; i++) {
res.add(Long.valueOf(data[i]));
}
return res;
}
public double[] getDoubleArray(int len) throws IOException {
double[] res = new double[len];
String[] data = in.readLine().split(" ");
for (int i = 0; i < res.length; i++) {
res[i] = Double.valueOf(data[i]);
}
return res;
}
public int[] getStringToIntArray(int len) throws IOException {
int[] res=new int[len];
String s=in.readLine();
for (int i = 0; i < res.length; i++) {
if(s.charAt(i)=='0'){
res[i]=0;
}else{
res[i]=1;
}
}
return res;
}
public static void printArray(int[] x){
StringBuffer res=new StringBuffer();
for (int i = 0; i < x.length; i++) {
res.append(x[i]);
if(i+1!=x.length)
res.append(" ");
}
System.out.println(res);
}
public static void printArray(long[] x){
if(x==null) {
System.out.println("null");
return ;
}
StringBuffer res=new StringBuffer();
for (int i = 0; i < x.length; i++) {
res.append(x[i]);
if(i+1!=x.length)
res.append(" ");
}
System.out.println(res);
}
public static String getArrayString(long[] x){
if(x==null) {
return "null";
}
StringBuffer res=new StringBuffer();
for (int i = 0; i < x.length; i++) {
res.append(x[i]);
if(i+1!=x.length)
res.append(" ");
}
return res.toString();
}
public static String getArrayString(int[] x){
if(x==null) {
return "null";
}
StringBuffer res=new StringBuffer();
for (int i = 0; i < x.length; i++) {
res.append(x[i]);
if(i+1!=x.length)
res.append(" ");
}
return res.toString();
}
}
|
Java
|
["7\n8\n3\n4\n5\n6\n7\n9"]
|
1 second
|
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
|
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
|
Java 17
|
standard input
|
[
"bitmasks",
"constructive algorithms",
"greedy"
] |
52bd5dc6b92b2af5aebd387553ef4076
|
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
| 1,500
|
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
|
standard output
| |
PASSED
|
97f1e156290046f02693850629d993b3
|
train_109.jsonl
|
1661871000
|
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
|
256 megabytes
|
import java.util.Scanner;
public class Solution{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();
while(t-- > 0){
int n = scanner.nextInt();
int case1 = 0;
int case2 = 0;
for(int i = 0 ; i < n - 2 ; i++) {
case1 ^= i;
case2 ^= (i + 1);
}
if(case1 != 0){
long last = (1L << 30);
StringBuilder ans = new StringBuilder();
for(int i = 0 ; i < n - 2 ; i++)
ans.append(i).append(" ");
ans.append(last).append(" ");
ans.append(last ^ case1);
System.out.println(ans);
}else{
long last = (1L << 30);
StringBuilder ans = new StringBuilder();
for(int i = 1 ; i <= n - 2 ; i++)
ans.append(i).append(" ");
ans.append(last).append(" ");
ans.append(last ^ case2);
System.out.println(ans);
}
}
}
}
|
Java
|
["7\n8\n3\n4\n5\n6\n7\n9"]
|
1 second
|
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
|
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
|
Java 17
|
standard input
|
[
"bitmasks",
"constructive algorithms",
"greedy"
] |
52bd5dc6b92b2af5aebd387553ef4076
|
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
| 1,500
|
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
|
standard output
| |
PASSED
|
cdf29dd306290423fcd19b40b8bd5aed
|
train_109.jsonl
|
1661871000
|
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
|
256 megabytes
|
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.abs;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
import java.io.*;
import java.math.*;
/**
*
* @Har_Har_Mahadev
*/
public class F {
public static void process() throws IOException {
int n = sc.nextInt();
int cur = 0;
for(int i=1;i<=n;++i) {
if(i == n) {
System.out.println(cur);
}
else {
cur ^= i;
if(i == 2) {
System.out.print((i ^ (1 << 30))+" ");
cur ^= (1 << 30);
}
else {
System.out.print(i+" ");
}
}
}
}
//=============================================================================
//--------------------------The End---------------------------------
//=============================================================================
private static long INF = 2000000000000000000L, M = 1000000007, MM = 998244353;
private static int N = 0;
private static void google(int tt) {
System.out.print("Case #" + (tt) + ": ");
}
static FastScanner sc;
static FastWriter out;
public static void main(String[] args) throws IOException {
boolean oj = true;
if (oj) {
sc = new FastScanner();
out = new FastWriter(System.out);
} else {
sc = new FastScanner("input.txt");
out = new FastWriter("output.txt");
}
long s = System.currentTimeMillis();
int t = 1;
t = sc.nextInt();
int TTT = 1;
while (t-- > 0) {
// google(TTT++);
process();
}
out.flush();
// tr(System.currentTimeMillis()-s+"ms");
}
private static boolean oj = System.getProperty("ONLINE_JUDGE") != null;
private static void tr(Object... o) {
if (!oj)
System.err.println(Arrays.deepToString(o));
}
static class Pair implements Comparable<Pair> {
int x, y;
Pair(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public int compareTo(Pair o) {
return Integer.compare(this.x, o.x);
}
/*
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Pair)) return false;
Pair key = (Pair) o;
return x == key.x && y == key.y;
}
@Override
public int hashCode() {
int result = x;
result = 31 * result + y;
return result;
}
*/
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
static int ceil(int x, int y) {
return (x % y == 0 ? x / y : (x / y + 1));
}
static long ceil(long x, long y) {
return (x % y == 0 ? x / y : (x / y + 1));
}
static long sqrt(long z) {
long sqz = (long) Math.sqrt(z);
while (sqz * 1L * sqz < z) {
sqz++;
}
while (sqz * 1L * sqz > z) {
sqz--;
}
return sqz;
}
static int log2(int N) {
int result = (int) (Math.log(N) / Math.log(2));
return result;
}
public static long gcd(long a, long b) {
if (a > b)
a = (a + b) - (b = a);
if (a == 0L)
return b;
return gcd(b % a, a);
}
public static long lcm(long a, long b) {
return (a * b) / gcd(a, b);
}
public static int lower_bound(int[] arr, int x) {
int low = 0, high = arr.length - 1, mid = -1;
int ans = -1;
while (low <= high) {
mid = (low + high) / 2;
if (arr[mid] > x) {
high = mid - 1;
} else {
ans = mid;
low = mid + 1;
}
}
return ans;
}
public static int upper_bound(int[] arr, int x) {
int low = 0, high = arr.length - 1, mid = -1;
int ans = arr.length;
while (low < high) {
mid = (low + high) / 2;
if (arr[mid] >= x) {
ans = mid;
high = mid - 1;
} else {
low = mid + 1;
}
}
return ans;
}
static void ruffleSort(int[] a) {
Random get = new Random();
for (int i = 0; i < a.length; i++) {
int r = get.nextInt(a.length);
int temp = a[i];
a[i] = a[r];
a[r] = temp;
}
Arrays.sort(a);
}
static void ruffleSort(long[] a) {
Random get = new Random();
for (int i = 0; i < a.length; i++) {
int r = get.nextInt(a.length);
long temp = a[i];
a[i] = a[r];
a[r] = temp;
}
Arrays.sort(a);
}
static void reverseArray(int[] a) {
int n = a.length;
int arr[] = new int[n];
for (int i = 0; i < n; i++)
arr[i] = a[n - i - 1];
for (int i = 0; i < n; i++)
a[i] = arr[i];
}
static void reverseArray(long[] a) {
int n = a.length;
long arr[] = new long[n];
for (int i = 0; i < n; i++)
arr[i] = a[n - i - 1];
for (int i = 0; i < n; i++)
a[i] = arr[i];
}
//custom multiset (replace with HashMap if needed)
public static void push(TreeMap<Integer, Integer> map, int k, int v) {
//map[k] += v;
if (!map.containsKey(k))
map.put(k, v);
else
map.put(k, map.get(k) + v);
}
public static void pull(TreeMap<Integer, Integer> map, int k, int v) {
//assumes map[k] >= v
//map[k] -= v
int lol = map.get(k);
if (lol == v)
map.remove(k);
else
map.put(k, lol - v);
}
// compress Big value to Time Limit
public static int[] compress(int[] arr) {
ArrayList<Integer> ls = new ArrayList<Integer>();
for (int x : arr)
ls.add(x);
Collections.sort(ls);
HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
int boof = 1; //min value
for (int x : ls)
if (!map.containsKey(x))
map.put(x, boof++);
int[] brr = new int[arr.length];
for (int i = 0; i < arr.length; i++)
brr[i] = map.get(arr[i]);
return brr;
}
// Fast Writer
public static class FastWriter {
private static final int BUF_SIZE = 1 << 13;
private final byte[] buf = new byte[BUF_SIZE];
private final OutputStream out;
private int ptr = 0;
private FastWriter() {
out = null;
}
public FastWriter(OutputStream os) {
this.out = os;
}
public FastWriter(String path) {
try {
this.out = new FileOutputStream(path);
} catch (FileNotFoundException e) {
throw new RuntimeException("FastWriter");
}
}
public FastWriter write(byte b) {
buf[ptr++] = b;
if (ptr == BUF_SIZE)
innerflush();
return this;
}
public FastWriter write(char c) {
return write((byte) c);
}
public FastWriter write(char[] s) {
for (char c : s) {
buf[ptr++] = (byte) c;
if (ptr == BUF_SIZE)
innerflush();
}
return this;
}
public FastWriter write(String s) {
s.chars().forEach(c -> {
buf[ptr++] = (byte) c;
if (ptr == BUF_SIZE)
innerflush();
});
return this;
}
private static int countDigits(int l) {
if (l >= 1000000000)
return 10;
if (l >= 100000000)
return 9;
if (l >= 10000000)
return 8;
if (l >= 1000000)
return 7;
if (l >= 100000)
return 6;
if (l >= 10000)
return 5;
if (l >= 1000)
return 4;
if (l >= 100)
return 3;
if (l >= 10)
return 2;
return 1;
}
public FastWriter write(int x) {
if (x == Integer.MIN_VALUE) {
return write((long) x);
}
if (ptr + 12 >= BUF_SIZE)
innerflush();
if (x < 0) {
write((byte) '-');
x = -x;
}
int d = countDigits(x);
for (int i = ptr + d - 1; i >= ptr; i--) {
buf[i] = (byte) ('0' + x % 10);
x /= 10;
}
ptr += d;
return this;
}
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;
}
public FastWriter write(long x) {
if (x == Long.MIN_VALUE) {
return write("" + x);
}
if (ptr + 21 >= BUF_SIZE)
innerflush();
if (x < 0) {
write((byte) '-');
x = -x;
}
int d = countDigits(x);
for (int i = ptr + d - 1; i >= ptr; i--) {
buf[i] = (byte) ('0' + x % 10);
x /= 10;
}
ptr += d;
return this;
}
public FastWriter write(double x, int precision) {
if (x < 0) {
write('-');
x = -x;
}
x += Math.pow(10, -precision) / 2;
// if(x < 0){ x = 0; }
write((long) x).write(".");
x -= (long) x;
for (int i = 0; i < precision; i++) {
x *= 10;
write((char) ('0' + (int) x));
x -= (int) x;
}
return this;
}
public FastWriter writeln(char c) {
return write(c).writeln();
}
public FastWriter writeln(int x) {
return write(x).writeln();
}
public FastWriter writeln(long x) {
return write(x).writeln();
}
public FastWriter writeln(double x, int precision) {
return write(x, precision).writeln();
}
public FastWriter write(int... xs) {
boolean first = true;
for (int x : xs) {
if (!first)
write(' ');
first = false;
write(x);
}
return this;
}
public FastWriter write(long... xs) {
boolean first = true;
for (long x : xs) {
if (!first)
write(' ');
first = false;
write(x);
}
return this;
}
public FastWriter writeln() {
return write((byte) '\n');
}
public FastWriter writeln(int... xs) {
return write(xs).writeln();
}
public FastWriter writeln(long... xs) {
return write(xs).writeln();
}
public FastWriter writeln(char[] line) {
return write(line).writeln();
}
public FastWriter writeln(char[]... map) {
for (char[] line : map)
write(line).writeln();
return this;
}
public FastWriter writeln(String s) {
return write(s).writeln();
}
private void innerflush() {
try {
out.write(buf, 0, ptr);
ptr = 0;
} catch (IOException e) {
throw new RuntimeException("innerflush");
}
}
public void flush() {
innerflush();
try {
out.flush();
} catch (IOException e) {
throw new RuntimeException("flush");
}
}
public FastWriter print(byte b) {
return write(b);
}
public FastWriter print(char c) {
return write(c);
}
public FastWriter print(char[] s) {
return write(s);
}
public FastWriter print(String s) {
return write(s);
}
public FastWriter print(int x) {
return write(x);
}
public FastWriter print(long x) {
return write(x);
}
public FastWriter print(double x, int precision) {
return write(x, precision);
}
public FastWriter println(char c) {
return writeln(c);
}
public FastWriter println(int x) {
return writeln(x);
}
public FastWriter println(long x) {
return writeln(x);
}
public FastWriter println(double x, int precision) {
return writeln(x, precision);
}
public FastWriter print(int... xs) {
return write(xs);
}
public FastWriter print(long... xs) {
return write(xs);
}
public FastWriter println(int... xs) {
return writeln(xs);
}
public FastWriter println(long... xs) {
return writeln(xs);
}
public FastWriter println(char[] line) {
return writeln(line);
}
public FastWriter println(char[]... map) {
return writeln(map);
}
public FastWriter println(String s) {
return writeln(s);
}
public FastWriter println() {
return writeln();
}
}
// Fast Inputs
static class FastScanner {
//I don't understand how this works lmao
private int BS = 1 << 16;
private char NC = (char) 0;
private byte[] buf = new byte[BS];
private int bId = 0, size = 0;
private char c = NC;
private double cnt = 1;
private BufferedInputStream in;
public FastScanner() {
in = new BufferedInputStream(System.in, BS);
}
public FastScanner(String s) {
try {
in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
} catch (Exception e) {
in = new BufferedInputStream(System.in, BS);
}
}
private char getChar() {
while (bId == size) {
try {
size = in.read(buf);
} catch (Exception e) {
return NC;
}
if (size == -1)
return NC;
bId = 0;
}
return (char) buf[bId++];
}
public int nextInt() {
return (int) nextLong();
}
public int[] readArray(int N) {
int[] res = new int[N];
for (int i = 0; i < N; i++) {
res[i] = (int) nextLong();
}
return res;
}
public long[] readArrayLong(int N) {
long[] res = new long[N];
for (int i = 0; i < N; i++) {
res[i] = nextLong();
}
return res;
}
public int[][] readArrayMatrix(int N, int M, int Index) {
if (Index == 0) {
int[][] res = new int[N][M];
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++)
res[i][j] = (int) nextLong();
}
return res;
}
int[][] res = new int[N][M];
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= M; j++)
res[i][j] = (int) nextLong();
}
return res;
}
public long[][] readArrayMatrixLong(int N, int M, int Index) {
if (Index == 0) {
long[][] res = new long[N][M];
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++)
res[i][j] = nextLong();
}
return res;
}
long[][] res = new long[N][M];
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= M; j++)
res[i][j] = nextLong();
}
return res;
}
public long nextLong() {
cnt = 1;
boolean neg = false;
if (c == NC)
c = getChar();
for (; (c < '0' || c > '9'); c = getChar()) {
if (c == '-')
neg = true;
}
long res = 0;
for (; c >= '0' && c <= '9'; c = getChar()) {
res = (res << 3) + (res << 1) + c - '0';
cnt *= 10;
}
return neg ? -res : res;
}
public double nextDouble() {
double cur = nextLong();
return c != '.' ? cur : cur + nextLong() / cnt;
}
public double[] readArrayDouble(int N) {
double[] res = new double[N];
for (int i = 0; i < N; i++) {
res[i] = nextDouble();
}
return res;
}
public String next() {
StringBuilder res = new StringBuilder();
while (c <= 32)
c = getChar();
while (c > 32) {
res.append(c);
c = getChar();
}
return res.toString();
}
public String nextLine() {
StringBuilder res = new StringBuilder();
while (c <= 32)
c = getChar();
while (c != '\n') {
res.append(c);
c = getChar();
}
return res.toString();
}
public boolean hasNext() {
if (c > 32)
return true;
while (true) {
c = getChar();
if (c == NC)
return false;
else if (c > 32)
return true;
}
}
}
}
|
Java
|
["7\n8\n3\n4\n5\n6\n7\n9"]
|
1 second
|
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
|
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
|
Java 17
|
standard input
|
[
"bitmasks",
"constructive algorithms",
"greedy"
] |
52bd5dc6b92b2af5aebd387553ef4076
|
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
| 1,500
|
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
|
standard output
| |
PASSED
|
468dfcad0ed332656863a273bf85423d
|
train_109.jsonl
|
1661871000
|
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
|
256 megabytes
|
import java.util.*;
public class Test1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int tc = sc.nextInt();
while(tc-->0) {
int n = sc.nextInt();
StringBuilder sb = new StringBuilder();
int q = n / 4, r = n % 4;
if(r == 2) q -= 1;
int num = 14;
while(q-->0) {
for(int i=0;i<4;i++) sb.append(num++).append(' ');
}
if(r == 1) sb.append(0);
else if(r == 2) sb.append("1 2 3 4 8 12");
else if(r == 3) sb.append("1 2 3");
System.out.println(sb.toString());
}
// ####################
}
// ####################
}
|
Java
|
["7\n8\n3\n4\n5\n6\n7\n9"]
|
1 second
|
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
|
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
|
Java 17
|
standard input
|
[
"bitmasks",
"constructive algorithms",
"greedy"
] |
52bd5dc6b92b2af5aebd387553ef4076
|
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
| 1,500
|
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
|
standard output
| |
PASSED
|
31b9ee07608cfd3bfa3d23b6d995e302
|
train_109.jsonl
|
1661871000
|
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
|
256 megabytes
|
import java.util.Scanner;
public class Program {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int t=in.nextInt();
for (int i=0;i<t;i++){
int n=in.nextInt();
long l=0;
for (int j=0;j<n-3;j++){
System.out.print(j+" ");
l^=j;
}
System.out.print((1<<29)+" ");
l^=(1<<29);
System.out.print((1<<30)+" ");
l^=(1<<30);
System.out.println(l+" ");
}
}
}
|
Java
|
["7\n8\n3\n4\n5\n6\n7\n9"]
|
1 second
|
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
|
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
|
Java 17
|
standard input
|
[
"bitmasks",
"constructive algorithms",
"greedy"
] |
52bd5dc6b92b2af5aebd387553ef4076
|
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
| 1,500
|
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
|
standard output
| |
PASSED
|
106ffe1559760891777fdeaf1ad75288
|
train_109.jsonl
|
1661871000
|
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class G {
final static boolean multipleTests = true;
Input in;
PrintWriter out;
public G() {
in = new Input(System.in);
out = new PrintWriter(System.out);
}
public static void main(String[] args) {
G solution = new G();
int t = 1;
if (multipleTests) t = solution.in.nextInt();
for (; t > 0; t--) {
solution.solve();
}
solution.out.close();
}
void solve() {
int n = in.nextInt();
int[] ans = new int[n];
int curr = Integer.MAX_VALUE;
int xor = 0;
Set<Integer> set = new HashSet<>();
for (int i=0; i<n; i++) {
ans[i] = curr;
curr -= (i % 2 == 0) ? 997 : 547;
xor ^= ans[i];
set.add(ans[i]);
}
if (xor != 0) {
for (int i=0; i<n; i++) {
if (!set.contains(ans[i] ^ xor)) {
ans[i] ^= xor;
xor = 0;
break;
}
}
}
if (xor != 0) throw new RuntimeException("dammit");
for (int i=0; i<n; i++) {
out.print(ans[i]);
out.print(' ');
}
out.println();
}
static class Input {
BufferedReader br;
StringTokenizer st;
public Input(InputStream in) {
br = new BufferedReader(new InputStreamReader(in));
st = new StringTokenizer("");
}
String nextString() {
while (!st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(nextString());
}
long nextLong() {
return Long.parseLong(nextString());
}
double nextDouble() {
return Double.parseDouble(nextString());
}
int[] nextIntArray(int size) {
int[] ans = new int[size];
for (int i = 0; i < size; i++) {
ans[i] = nextInt();
}
return ans;
}
}
}
|
Java
|
["7\n8\n3\n4\n5\n6\n7\n9"]
|
1 second
|
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
|
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
|
Java 17
|
standard input
|
[
"bitmasks",
"constructive algorithms",
"greedy"
] |
52bd5dc6b92b2af5aebd387553ef4076
|
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
| 1,500
|
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
|
standard output
| |
PASSED
|
808d1464e60b0eaae84251b7adc23408
|
train_109.jsonl
|
1661871000
|
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
|
256 megabytes
|
import java.io.BufferedInputStream;
import java.util.*;
public class G {
public static int[] solve(int n) {
if (n % 4 == 0) {
int[] res = new int[n];
for (int i = 0; i < n; i+=4) {
res[i] = i;
res[i + 2] = i + 3;
res[i + 1] = i + 1;
res[i + 3] = i + 2;
}
return res;
} else if (n % 4 == 1) {
int[] res = new int[n];
for (int i = 0; i < n - 1; i+=4) {
res[i] = i + 4;
res[i + 2] = i + 3 + 4;
res[i + 1] = i + 1 + 4;
res[i + 3] = i + 2 + 4;
}
res[n - 1] = 0;
return res;
} else if (n % 4 == 2) {
int[] res = new int[n];
for (int i = 0; i < n - 6; i+=4) {
res[i] = i + 200;
res[i + 2] = i + 3 + 200;
res[i + 1] = i + 1 + 200;
res[i + 3] = i + 2 + 200;
}
// res[n - 1] = 0;
// 4 1 2 12 3 8
res[n - 6] = 4;
res[n - 5] = 1;
res[n - 4] = 2;
res[n - 3] = 12;
res[n - 2] = 3;
res[n - 1] = 8;
return res;
} else {
int[] res = new int[n];
for (int i = 0; i < n - 3; i+=4) {
res[i] = i + 4;
res[i + 2] = i + 3 + 4;
res[i + 1] = i + 1 + 4;
res[i + 3] = i + 2 + 4;
}
res[n - 3] = 1;
res[n - 2] = 2;
res[n - 1] = 3;
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();
int[] res = solve(n);
StringBuffer sb = new StringBuffer();
for (int i = 0; i < res.length; i++) {
if (i != 0) sb.append(" ");
sb.append(res[i]);
}
System.out.println(sb.toString());
}
}
}
|
Java
|
["7\n8\n3\n4\n5\n6\n7\n9"]
|
1 second
|
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
|
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
|
Java 17
|
standard input
|
[
"bitmasks",
"constructive algorithms",
"greedy"
] |
52bd5dc6b92b2af5aebd387553ef4076
|
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
| 1,500
|
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
|
standard output
| |
PASSED
|
b7f88edad6b3bc22fa544138554beb23
|
train_109.jsonl
|
1661871000
|
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
|
256 megabytes
|
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int numberOfCases = sc.nextInt();
StringBuilder out = new StringBuilder();
for(int i = 0; i< numberOfCases; i++) {
int n = sc.nextInt();
executeCase(n, out);
}
System.out.print(out);
}
public static void mainM(String[] args) {
StringBuilder out = new StringBuilder();
executeCase(5, out);
System.out.print(out);
}
private static void executeCase(int size, StringBuilder out) {
if (size == 1) {
out.append(0);
return;
}
if (size == 2) {
return;
}
StringBuilder local = new StringBuilder();
int sum = 0;
for(int i = 0; i< size - 2; i++) {
sum = sum ^ i;
local.append(i);
local.append(" ");
}
if (sum == 0) {
local = new StringBuilder();
for(int i = 1; i < size - 1; i++) {
sum = sum ^ i;
local.append(i);
local.append(" ");
}
}
int topBit = 1;
int remainder = size;
while ( remainder > 0) {
topBit = topBit << 1;
remainder = remainder >> 1;
}
local.append(topBit);
local.append(" ");
int latest = topBit ^ sum;
local.append(latest);
out.append(local);
out.append("\n");
}
private static int[] readArray(Scanner sc, int n) {
int[] result = new int[n];
for(int j = 0; j< n; j++) {
result[j] = sc.nextInt();
}
return result;
}
private static boolean[][] readSquare(Scanner sc, int n) {
boolean[][] result = new boolean[n][n];
for(int i = 0; i<n; i++) {
String line = sc.next();
for(int j=0; j<n; j++) {
result[i][j] = line.charAt(j) == '1';
}
}
return result;
}
public static class Node {
public Node(int id) {
this.id = id;
}
public void addChild(Node node) {
children.add(node);
}
public enum Color {
BLACK,
WHITE
}
private final int id;
private Color color;
private List<Node> children = new ArrayList();
public void setColor(Color color) {
this.color = color;
}
public int count(Counter counter) {
Counter ownCounter = new Counter();
for (Node child : children) {
child.count(ownCounter);
}
if (color == Color.BLACK) {
ownCounter.incrementBlack();
} else {
ownCounter.incrementWhite();
}
counter.update(ownCounter);
return counter.getBalanced();
}
}
public static class Counter {
private int black = 0;
private int white = 0;
private int balanced = 0;
public void incrementBlack() {
black++;
checkBalanced();
}
public void incrementWhite() {
white++;
checkBalanced();
}
private void checkBalanced() {
if (black == white) {
balanced++;
}
}
public int getBalanced() {
return balanced;
}
public void update(Counter anotherCounter) {
black += anotherCounter.black;
white += anotherCounter.white;
balanced += anotherCounter.balanced;
}
}
}
|
Java
|
["7\n8\n3\n4\n5\n6\n7\n9"]
|
1 second
|
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
|
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
|
Java 17
|
standard input
|
[
"bitmasks",
"constructive algorithms",
"greedy"
] |
52bd5dc6b92b2af5aebd387553ef4076
|
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
| 1,500
|
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
|
standard output
| |
PASSED
|
8026d8aa78eba4272f149de29110b3fa
|
train_109.jsonl
|
1661871000
|
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
|
256 megabytes
|
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class EvenOddXor {
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 ignored) {
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
}
public static void main(String[] args) {
FastScanner sc = new FastScanner();
int t = sc.nextInt();
while (t-- > 0) {
int n=sc.nextInt();
int[] arr =new int[n];
if(n%2==0) {
for(int i=0,j=1;i<n;i+=2,j++) arr[i]=j;
for(int i=1,j=1;i<n;i+=2,j++) arr[i]=j;
}else {
for(int i=2,j=1;i<n;i+=2,j++) arr[i]=j;
for(int i=1,j=1;i<n;i+=2,j++) arr[i]=j;
}
if(((n+1)/2)%2==0) {
for(int i=0;i<n;i+=2) {
arr[i]|=(1<<30);
}
}else {
for(int i=0;i+2<n;i+=2) {
arr[i]|=(1<<30);
}
for(int i=2;i<n;i+=2) {
arr[i]|=(1<<29);
}
}
for(int i:arr) System.out.print(i+" ");
System.out.println();
}
}
}
|
Java
|
["7\n8\n3\n4\n5\n6\n7\n9"]
|
1 second
|
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
|
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
|
Java 17
|
standard input
|
[
"bitmasks",
"constructive algorithms",
"greedy"
] |
52bd5dc6b92b2af5aebd387553ef4076
|
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
| 1,500
|
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
|
standard output
| |
PASSED
|
a3ea799606dde95019d7562e91f8899d
|
train_109.jsonl
|
1661871000
|
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
|
256 megabytes
|
import java.util.*;
public class Main {
public static int n,m;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- > 0){
n = sc.nextInt();
int [] ans = new int[n];
ans[n - 3] = 1 << 29;
ans[n - 2] = 1 << 30;
int xor = ans[n - 3] ^ ans[n - 2];
for (int i = 0; i < n - 3; i++) {
ans[i] = i;
xor ^= i;
}
ans[n - 1] = xor;
for (int i = 0; i < n; i++) {
System.out.print(ans[i] + " ");
}
System.out.println();
}
}
}
|
Java
|
["7\n8\n3\n4\n5\n6\n7\n9"]
|
1 second
|
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
|
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
|
Java 17
|
standard input
|
[
"bitmasks",
"constructive algorithms",
"greedy"
] |
52bd5dc6b92b2af5aebd387553ef4076
|
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
| 1,500
|
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
|
standard output
| |
PASSED
|
eb387c4c36a22e21d92f19c98d6e1fd8
|
train_109.jsonl
|
1661871000
|
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
|
256 megabytes
|
import java.util.*;
import java.util.stream.Collectors;
/**
* @Author Create by jiaxiaozheng
* @Date 2022/9/1
*/
public class Main {
static List<Integer> slv(int n){
List<Integer> list = new ArrayList<>();
int last=0;
if (n%4==1){
list.addAll(Arrays.asList(2,0,4,5,3));
last=6;
}
if (n%4==2){
list.addAll(Arrays.asList(4,1,2,12,3,8));
last=13;
}
if (n%4==3){
list.addAll(Arrays.asList(2,1,3));
last=4;
}
if (last%2==1){
last++;
}
while (list.size()<n){
list.add(last);
list.add(last+2);
list.add(last+1);
list.add(last+3);
last+=4;
}
return list;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int l = scanner.nextInt();
for (int i = 0; i < l; i++) {
int n=scanner.nextInt();
List<Integer> list = slv(n);
int odd=list.get(1);
int even=list.get(0);
for (int j = 2; j < list.size(); j++) {
if (j%2==0){
even^=list.get(j);
}else {
odd^=list.get(j);
}
}
if (odd!=even){
System.out.println("ERR");
}
System.out.println(list.stream().map(x->x+"").collect(Collectors.joining(" ")));
}
}
}
|
Java
|
["7\n8\n3\n4\n5\n6\n7\n9"]
|
1 second
|
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
|
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
|
Java 17
|
standard input
|
[
"bitmasks",
"constructive algorithms",
"greedy"
] |
52bd5dc6b92b2af5aebd387553ef4076
|
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
| 1,500
|
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
|
standard output
| |
PASSED
|
ef597c39f94b078776740aeb51fc0c29
|
train_109.jsonl
|
1661871000
|
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
|
256 megabytes
|
import java.io.*;
import java.util.*;
import javax.swing.Painter;
public class sneh{
static PrintWriter out;
static Kioken sc;
public static void main(String[] args) throws FileNotFoundException {
boolean t = true;
boolean f = false;
if (f) {
out = new PrintWriter("output.txt");
sc = new Kioken("input.txt");
} else {
out = new PrintWriter((System.out));
sc = new Kioken();
}
int tt = 1;
tt = sc.nextInt();
while (tt-- > 0) {
solve();
}
out.flush();
out.close();
}
public static void solve() {
int n=sc.nextInt();
if(n==3){
System.out.println(2 + " "+ 1+ " "+ 3);
return;
}
int x=1;
while(x<=(n/2)){
x*=2;
}
int tmp=1;
int m=n/2;
if(m%2==0){
Vector<Integer>v = new Vector<Integer>();
for(int i=0;i<m;i++){
v.add(i+1);
}
for(int i=0;i<m;i++){
v.add(v.get(i)+ x);
}
for(int i=0;i<m;i++){
System.out.print(v.get(i) + " "+ v.get(i+m) + " ");
}
if(n%2==1){
System.out.print(0);
}
}
else{
Vector<Integer>v = new Vector<Integer>();
for(int i=0;i<m;i++){
v.add(i+1);
}
for(int i=0;i<m-2;i++){
v.add(v.get(i)+ x);
}
v.add(v.get(m-2)+ x+ 2*x);
v.add(v.get(m-1)+ 2*x);
for(int i=0;i<m;i++){
System.out.print(v.get(i) + " "+ v.get(i+m) + " ");
}
if(n%2==1){
System.out.print(0);
}
}
System.out.println();
}
public static long gcd(long a, long b) {
while (b != 0) {
long rem = a % b;
a = b;
b = rem;
}
return a;
}
static long MOD = 1000000007;
static void reverseSort(int[] arr){List<Integer> list = new ArrayList<>();for (int i=0; i<arr.length; i++){list.add(arr[i]);}Collections.sort(list, Collections.reverseOrder());for (int i = 0; i < arr.length; i++){arr[i] = list.get(i);}}
static void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static void sort(long[] a){
ArrayList<Long> l=new ArrayList<>();
for (long i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static class Kioken {
// FileInputStream br = new FileInputStream("input.txt");
BufferedReader br;
StringTokenizer st;
Kioken(String filename) {
try {
FileReader fr = new FileReader(filename);
br = new BufferedReader(fr);
st = new StringTokenizer("");
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
Kioken() {
try {
br = new BufferedReader(new InputStreamReader(System.in));
st = new StringTokenizer("");
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
public String next() {
while (!st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String nextLine() {
try {
return br.readLine();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public boolean hasNext() {
String next = null;
try {
next = br.readLine();
} catch (Exception e) {
}
if (next == null || next.length() == 0) {
return false;
}
st = new StringTokenizer(next);
return true;
}
}
}
|
Java
|
["7\n8\n3\n4\n5\n6\n7\n9"]
|
1 second
|
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
|
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
|
Java 17
|
standard input
|
[
"bitmasks",
"constructive algorithms",
"greedy"
] |
52bd5dc6b92b2af5aebd387553ef4076
|
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
| 1,500
|
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
|
standard output
| |
PASSED
|
e0d67d475d5f2fa7ddf69e06f8da455a
|
train_109.jsonl
|
1661871000
|
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
|
256 megabytes
|
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.lang.reflect.Array;
import java.util.*;
import java.util.function.IntFunction;
import java.util.function.IntUnaryOperator;
import java.util.function.ToIntFunction;
import java.util.stream.IntStream;
import java.util.stream.Stream;
public class Codeforces {
static void solve(int tc) {
int n = i32();
int r = n % 4;
if (r == 3) {
print(IntStream.rangeClosed(1, n).toArray());
} else if (r == 0) {
print(IntStream.range(0, n).toArray());
} else if (r == 1) {
int k = Integer.highestOneBit(n);
int[] a = new int[n];
for (int i = 0, p = Integer.numberOfTrailingZeros(k); i <= p; i++, k /= 2) {
for (int j = 0; j < n - 1 && j + k <= n; j += 2 * k) {
for (int l = 0; l < k; l++) {
a[j + l] |= (1 << i);
}
}
}
print(a);
} else {
int k = Integer.highestOneBit(n);
int[] a = new int[n];
for (int i = 0, p = Integer.numberOfTrailingZeros(k); i <= p; i++, k /= 2) {
for (int j = 0; j < n - 2 && j + k <= n; j += 2 * k) {
for (int l = 0; l < k; l++) {
a[j + l] |= (1 << i);
}
}
}
k = Integer.highestOneBit(n);
a[0] |= (k << 1);
a[n -1] |= (k << 1);
print(a);
}
}
//####################################################################################################################
private static final Scanner _IN_ = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
private static final PrintStream _OUT_ = new PrintStream(new BufferedOutputStream(System.out));
public static void main(String[] args) {
try (_IN_; _OUT_) {
for (int t = 1, T = i32(); t <= T; t++) solve(t);
// solve(1);
}
}
// ARRAY #############################################################################################################
private static <T> T[] array(int n, Class<T> type, IntFunction<T> fun) {
@SuppressWarnings("unchecked") T[] array = (T[]) Array.newInstance(type, n);
for (int i = 0; i < n; i++) array[i] = fun.apply(i); return array;
}
private static int[] array(int n, int d) { int[] array = new int[n]; Arrays.fill(array, d); return array; }
private static int fst(int[] arr) { return arr[0]; }
private static int last(int[] arr) { return arr[arr.length - 1]; }
private static void swap(int[] arr, int i, int j) { int x = arr[i]; arr[i] = arr[j]; arr[j] = x; }
private static void shuffle(int[] arr) { for (int i = 0; i < arr.length; i++) swap(arr, (int) (Math.random() * arr.length), i); }
private static Stream<pair> pairs(int[] as) {
int n = as.length;
if (n < 2) return Stream.empty();
return Stream.iterate(new pair(0, 1), it -> it.fst < n - 1,
it -> it.snd + 1 == n ? new pair(it.fst + 1, it.fst + 2) : new pair(it.fst, it.snd + 1));
}
private static Stream<pair> cartesian(int m, int n) {
return Stream.iterate(new pair(0, 0), it -> it.fst < m,
it -> it.snd + 1 == n ? new pair(it.fst + 1, 0) : new pair(it.fst, it.snd + 1));
}
// DS ################################################################################################################
private static class pair {
final int fst, snd;
pair(int fst, int snd) { this.fst = fst; this.snd = snd; }
public String toString() { return fst + " " + snd; }
boolean neq(pair p) { return fst != p.fst || snd != p.snd; }
}
private static class triple {
final int fst, snd, thd;
triple(int fst, int snd, int thd) { this.fst = fst; this.snd = snd; this.thd = thd; }
public String toString() { return fst + " " + snd + " " + thd; }
}
// GEOMETRY ##########################################################################################################
private static double dist(int x1, int y1, int x2, int y2) { return Math.sqrt(Math.pow(x1-x2, 2) + Math.pow(y1-y2, 2)); }
// INPUT #############################################################################################################
private static int i32() { return _IN_.nextInt(); }
private static int[] i32(int n) { return IntStream.generate(Codeforces::i32).limit(n).toArray(); }
private static String str() { return _IN_.next(); }
private static String[] str(int n) { return Stream.generate(Codeforces::str).limit(n).toArray(String[]::new); }
// ITERATION #########################################################################################################
private static IntStream iter(int[] arr) { return Arrays.stream(arr); }
private static IntStream iter(int l, int r) { return IntStream.range(l, r); }
private static IntStream iter(int l, IntUnaryOperator next) { return IntStream.iterate(l, next); }
private static class Window<T> {
T[] arr; int i, sz;
Window(T[] arr, int sz) { this.arr = arr; this.sz = sz; }
T get(int j) { return arr[i + j]; }
T fst() { return arr[i]; }
T snd() { return arr[i + 1]; }
boolean hasNext() { return i + sz <= arr.length; }
public Window<T> next() { i++; return this; }
}
private static class IntWindow {
int[] arr; int i, sz;
IntWindow(int[] arr, int sz) { this.arr = arr; this.sz = sz; }
int get(int j) { return arr[i + j]; }
int fst() { return arr[i]; }
int snd() { return arr[i + 1]; }
boolean hasNext() { return i + sz <= arr.length; }
public IntWindow next() { i++; return this; }
}
private static <T> Stream<Window<T>> windows(T[] arr, int sz) {
if (sz > arr.length) return Stream.empty();
return Stream.iterate(new Window<>(arr, sz), Window::hasNext, Window::next);
}
private static Stream<IntWindow> windows(int[] arr, int sz) {
if (sz > arr.length) return Stream.empty();
return Stream.iterate(new IntWindow(arr, sz), IntWindow::hasNext, IntWindow::next);
}
// NUMBER ############################################################################################################
private static final int INF = Integer.MAX_VALUE;
private static int sum(int[] xs) { return iter(xs).sum(); }
private static int sum(int[] xs, int l) { return Arrays.stream(xs).skip(l).sum(); }
private static int min(int a, int b) { return Math.min(a, b); }
private static int abs(int x) { return Math.abs(x); }
// OUTPUT ############################################################################################################
private static void print(Object o) { _OUT_.println(o); }
private static void print(int[] xs) { for (int x : xs) _OUT_.print(x + " "); _OUT_.println(); }
private static void print(long[] xs) { for (long x : xs) _OUT_.print(x + " "); _OUT_.println(); }
// SORT ##############################################################################################################
private static <T> void sort(T[] arr, ToIntFunction<T> comp) { Arrays.sort(arr, Comparator.comparingInt(comp)); }
private static void sort(int[] arr) { shuffle(arr); Arrays.sort(arr); }
// STRING ############################################################################################################
private static class Str {
final String s; final int l, r;
Str(String s, int l, int r) { this.s = s; this.l = l; this.r = r; }
int len() { return r - l; }
boolean eq(Str that) {
if (that.len() != this.len()) return false;
for (int i = 0, len = len(); i < len; i++) if (s.charAt(l + i) != that.s.charAt(that.l + i)) return false;
return true;
}
}
private static String reverse(String s) { return new StringBuilder(s).reverse().toString(); }
}
|
Java
|
["7\n8\n3\n4\n5\n6\n7\n9"]
|
1 second
|
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
|
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
|
Java 17
|
standard input
|
[
"bitmasks",
"constructive algorithms",
"greedy"
] |
52bd5dc6b92b2af5aebd387553ef4076
|
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
| 1,500
|
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
|
standard output
| |
PASSED
|
1cb9054e50af9bf73c9e83569674ae35
|
train_109.jsonl
|
1661871000
|
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
|
256 megabytes
|
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class CF1722G {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in, StandardCharsets.UTF_8);
int t = scanner.nextInt();
for (int i = 0; i < t; i++) {
int n = scanner.nextInt();
System.out.println(solve(n));
}
}
private static String solve(int n) {
int case1 = 0;
int case2 = 0;
for (int i = 0; i < n - 2; i++) {
case1 ^= i;
case2 ^= (i + 1);
}
long addLast = (1L << 31) - 1;
List<String> resList = new ArrayList<>();
if (case1 != 0) {
for (int i = 0; i < n - 2; i++) {
resList.add(String.valueOf(i));
}
case1 ^= addLast;
resList.add(String.valueOf(addLast));
resList.add(String.valueOf(case1));
} else {
for (int i = 1; i <= n - 2; i++) {
resList.add(String.valueOf(i));
}
case2 ^= addLast;
resList.add(String.valueOf(addLast));
resList.add(String.valueOf(case2));
}
return String.join(" ", resList);
}
}
|
Java
|
["7\n8\n3\n4\n5\n6\n7\n9"]
|
1 second
|
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
|
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
|
Java 17
|
standard input
|
[
"bitmasks",
"constructive algorithms",
"greedy"
] |
52bd5dc6b92b2af5aebd387553ef4076
|
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
| 1,500
|
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
|
standard output
| |
PASSED
|
c5ec498f38ebdb01abba752da60133ed
|
train_109.jsonl
|
1661871000
|
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
|
256 megabytes
|
import java.math.BigInteger;
import java.util.*;
import java.io.*;
public class Vaibhav{
static long bit[];
static boolean prime[];
public static long lcm(long x, long y) {return (x * y) / gcd(x, y);}
static class Pair {//implements Comparable<Pair> {
int x;
int y;
Pair(int x,int y) {
this.x = x;
this.y=y;
}
/* //public int compareTo(Pair o){
return this.cqm-o.cqm;
}*/
}
//BIT
public static void update(long bit[], int i, int x) {for (; i < bit.length; i += (i & (-i))) {bit[i] += x;}}
public static long sum(int i) {long sum = 0;for (; i > 0; i -= (i & (-i))) {sum += bit[i];}return sum;}
static long power(long x, long y, long p) {if (y == 0) return 1;if (x == 0) return 0;long res = 1l;x = x % p;while (y > 0) {if (y % 2 == 1) res = (res * x) % p;y = y >> 1;x = (x * x) % p;}return res;}
static long power(long x, long y) {if (y == 0) return 1;if (x == 0) return 0;long res = 1;while (y > 0) {if (y % 2 == 1) res = (res * x);y = y >> 1;x = (x * x);}return res;}
static void sort(long[] a) {ArrayList<Long> l = new ArrayList<>();for (long i : a) l.add(i);Collections.sort(l);for (int i = 0; i < a.length; i++) a[i] = l.get(i);}
static class FastScanner {BufferedReader br = new BufferedReader(new InputStreamReader(System.in));StringTokenizer st = new StringTokenizer("");String next() {while (!st.hasMoreTokens()) try {st = new StringTokenizer(br.readLine());}catch (IOException e) {e.printStackTrace();}return st.nextToken();}int nextInt() {return Integer.parseInt(next());}int[] readArray(int n) {int[] a = new int[n];for (int i = 0; i < n; i++) a[i] = nextInt();return a;}long[] readlongArray(int n) {long[] a = new long[n];for (int i = 0; i < n; i++) a[i] = nextLong();return a;}long nextLong() {return Long.parseLong(next());}}
static void sieveOfEratosthenes(int n) {prime = new boolean[n + 1];for (int i = 0; i <= n; i++) prime[i] = true;for (int p = 2; p * p <= n; p++){ if (prime[p] == true) {for (int i = p * p; i <= n; i += p) prime[i] = false;}}}
public static int log2(int x) {
return (int) (Math.log(x) / Math.log(2));
}
public static long gcd(long a, long b) {if (b == 0) {return a;}return gcd(b, a % b);}
static long nCk(int n, int k) {long res = 1;for (int i = n - k + 1; i <= n; ++i) res *= i;for (int i = 2; i <= k; ++i) res /= i;return res;}
static BigInteger bi(String str) {
return new BigInteger(str);
}
// Author - vaibhav_1710
static FastScanner fs = null;
static long ans;
static long mod = 1_000_000_007;
static ArrayList<Integer> al[];
public static void main(String[] args) {
fs = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int t =fs.nextInt();
outer: while (t-- > 0) {
int n = fs.nextInt();
long a[] = new long[n];
long b[] = new long[32];
long c[] = new long[32];
for(int i=0;i<n;i++){
a[i]=i;
if(i%2!=0){
for(int j = 31;j>=0;j--) {
long val = i>>j;
if ((val & 1) > 0) b[31 - j]++;
}
}else{
for(int j=31;j>=0;j--){
long val = i>>j;
if((val&1)>0) c[31-j]++;
}
}
}
StringBuilder sb = new StringBuilder();
//long val = 0l;
for(int i=0;i<32;i++){
if((b[i]%2)!=(c[i]%2)){
sb.append('1');
}else{
sb.append('0');
}
}
a[2] = ((1<<30) | a[2]);
long val = 0l;
for(int i=0;i<sb.length();i++){
if(sb.toString().charAt(i) == '1'){
val += (1<<i);
}
}
a[0] = convertBinStrToInt(sb.toString());
a[0] = ((1l<<30) | a[0]);
for(long v:a){
out.print(v+" ");
}
out.println();
}
out.close();
}
public static int convertBinStrToInt(String binStr) {
int dec = 0, count = 0;
for (int i = binStr.length()-1; i >=0; i--) {
dec += (binStr.charAt(i) - '0') * (1 << count++);
}
return dec;
}
}
|
Java
|
["7\n8\n3\n4\n5\n6\n7\n9"]
|
1 second
|
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
|
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
|
Java 17
|
standard input
|
[
"bitmasks",
"constructive algorithms",
"greedy"
] |
52bd5dc6b92b2af5aebd387553ef4076
|
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
| 1,500
|
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
|
standard output
| |
PASSED
|
767105f0172f12d79423b463322d8bf0
|
train_109.jsonl
|
1661871000
|
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class CF1722G extends PrintWriter {
CF1722G() { super(System.out); }
Scanner sc = new Scanner(System.in);
public static void main(String[] $) {
CF1722G o = new CF1722G(); o.main(); o.flush();
}
void main() {
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
if (n == 3) {
println("1 2 3 ");
continue;
}
if (n % 2 == 1) {
print("0 ");
n--;
}
if (n % 4 == 2) {
print("1 4 2 8 3 12 ");
n -= 6;
}
for (int i = 0; i < n; i += 2)
if (i % 4 == 0)
print((i + 14) + " " + (i + 15) + " ");
else
print((i + 15) + " " + (i + 14) + " ");
println();
}
}
}
|
Java
|
["7\n8\n3\n4\n5\n6\n7\n9"]
|
1 second
|
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
|
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
|
Java 17
|
standard input
|
[
"bitmasks",
"constructive algorithms",
"greedy"
] |
52bd5dc6b92b2af5aebd387553ef4076
|
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
| 1,500
|
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
|
standard output
| |
PASSED
|
20832c8be203b60c2aa9e26b0b3a0b68
|
train_109.jsonl
|
1661871000
|
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class Template {
FastScanner in;
PrintWriter out;
Random rnd = new Random();
final int MAX_VAL = (1<<31) - 1;
int rndInt() {
return rnd.nextInt(MAX_VAL);
}
public void solve() throws IOException {
int t = in.nextInt();
for (int cs = 0; cs < t; cs++) {
int n = in.nextInt();
int[] a = new int[n];
boolean found = false;
while (!found) {
int xr0 = 0, xr1 = 0;
Set<Integer> s = new HashSet<>();
for (int i = 0; i < n - 1; i++) {
int x = rndInt();
while (s.contains(x)) {
x = rndInt();
}
s.add(x);
a[i] = x;
if (i % 2 == 0)
xr0 ^= x;
else
xr1 ^= x;
}
if (!s.contains(xr0 ^ xr1)) {
a[n - 1] = xr0 ^ xr1;
found = true;
}
}
for (int i = 0; i < n; i++)
out.print(a[i] + " ");
out.println();
}
}
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;
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());
}
}
public static void main(String[] arg) {
new Template().run();
}
}
|
Java
|
["7\n8\n3\n4\n5\n6\n7\n9"]
|
1 second
|
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
|
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
|
Java 17
|
standard input
|
[
"bitmasks",
"constructive algorithms",
"greedy"
] |
52bd5dc6b92b2af5aebd387553ef4076
|
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
| 1,500
|
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
|
standard output
| |
PASSED
|
58d15e5055109839addc4c0444886317
|
train_109.jsonl
|
1661871000
|
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
|
256 megabytes
|
import java.io.*;
import java.math.BigInteger;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.*;
import static java.lang.System.out;
public class app {
public static long m;
static int mod = 998244353;
static int inf = (int) 1e9;
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
//int t=1;
while (t-- > 0) {
int s=sc.nextInt();
long[]a =new long[s];
int a1=0;
int a2=0;
long ii=2147483647;
if(s==3){
out.println(1+" "+2+" "+3);
}else {
for (int i = 0; i < s - 3; i++) {
if (i % 2 == 0) {
a1 = a1 ^ (i+1);
} else {
a2 = a2 ^ (i+1);
}
a[i]=i+1;
}
if(a1>a2){
a[s-3]=0;
a[s-2]=ii-a1+(a1-a2);
a[s-1]=ii-a1;
}else if(a1<a2){
a[s-3]=0;
a[s-2]=ii-a2;
a[s-1]=ii-a2+(a2-a1);
}else{
a[s-3]=(((ii+1)/2)-3);
a[s-2]=((ii+1)/2)+2;
a[s-1]=ii;
}
out.println(Arrays.toString(a).replace(",","").replace("]","").replace("[",""));
}
}
}
//out.println(Arrays.toString(d).replace(",","").replace("]","").replace("[",""));
static long gcd(long a, long b) {
return b == 0 ? a : gcd(b, a % b);
}
static long lcm(long a, long b) {
return a * b / gcd(a, b);
}
static void sort(int[] a) {
int n = a.length;
Integer[] b = new Integer[n];
for (int i = 0; i < n; i++)
b[i] = a[i];
Arrays.sort(b);
for (int i = 0; i < n; i++)
a[i] = b[i];
}
static void sort(long[] a) {
int n = a.length;
Long[] b = new Long[n];
for (int i = 0; i < n; i++)
b[i] = a[i];
Arrays.sort(b);
for (int i = 0; i < n; i++)
a[i] = b[i];
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream system) {
br = new BufferedReader(new InputStreamReader(system));
}
public Scanner(String file) throws Exception {
br = new BufferedReader(new FileReader(file));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public String nextLine() throws IOException {
return br.readLine();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public char nextChar() throws IOException {
return next().charAt(0);
}
public Long nextLong() throws IOException {
return Long.parseLong(next());
}
public int[] nextArrInt(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public long[] nextArrLong(int n) throws IOException {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public int[] nextArrIntSorted(int n) throws IOException {
int[] a = new int[n];
Integer[] a1 = new Integer[n];
for (int i = 0; i < n; i++)
a1[i] = nextInt();
Arrays.sort(a1);
for (int i = 0; i < n; i++)
a[i] = a1[i].intValue();
return a;
}
public long[] nextArrLongSorted(int n) throws IOException {
long[] a = new long[n];
Long[] a1 = new Long[n];
for (int i = 0; i < n; i++)
a1[i] = nextLong();
Arrays.sort(a1);
for (int i = 0; i < n; i++)
a[i] = a1[i].longValue();
return a;
}
}
}
|
Java
|
["7\n8\n3\n4\n5\n6\n7\n9"]
|
1 second
|
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
|
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
|
Java 8
|
standard input
|
[
"bitmasks",
"constructive algorithms",
"greedy"
] |
52bd5dc6b92b2af5aebd387553ef4076
|
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
| 1,500
|
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
|
standard output
| |
PASSED
|
d34f4af047643ca2564cab21d73ea5ba
|
train_109.jsonl
|
1661871000
|
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
|
256 megabytes
|
/*
Goal: Become better in CP!
Key: Consistency and Discipline
Desire: SDE @ Google USA
Motto: Do what i Love <=> Love what i do
If you don't use your brain 100%, it deteriorates gradually
*/
import java.util.*;
import java.io.*;
import java.math.*;
public class Code {
static StringBuffer str=new StringBuffer();
static BufferedReader bf;
static PrintWriter pw;
static int n;
static void solve(int te) throws Exception{
int xor=0;
for(int i=0;i<n-3;i++){
xor^=i;
str.append(i).append(" ");
}
str.append(1<<29).append(" ");
xor^=(1<<29);
str.append(1<<30).append(" ");
xor^=(1<<30);
str.append(xor).append("\n");
}
public static void main(String[] args) throws java.lang.Exception {
boolean lenv=false;
if(lenv){
bf = new BufferedReader(
new FileReader("input.txt"));
pw=new PrintWriter(new
BufferedWriter(new FileWriter("output.txt")));
}else{
bf = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(new OutputStreamWriter(System.out));
}
int q1 = Integer.parseInt(bf.readLine().trim());
for(int te=1;te<=q1;te++) {
n=Integer.parseInt(bf.readLine().trim());
solve(te);
}
pw.print(str);
pw.flush();
// System.out.println(str);
}
}
|
Java
|
["7\n8\n3\n4\n5\n6\n7\n9"]
|
1 second
|
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
|
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
|
Java 8
|
standard input
|
[
"bitmasks",
"constructive algorithms",
"greedy"
] |
52bd5dc6b92b2af5aebd387553ef4076
|
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
| 1,500
|
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
|
standard output
| |
PASSED
|
0f4a37466672b0d142ead2bc500ad3fc
|
train_109.jsonl
|
1661871000
|
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
|
256 megabytes
|
/*
Goal: Become better in CP!
Key: Consistency and Discipline
Desire: SDE @ Google USA
Motto: Do what i Love <=> Love what i do
If you don't use your brain 100%, it deteriorates gradually
*/
import java.util.*;
import java.io.*;
import java.math.*;
public class Code {
static StringBuffer str=new StringBuffer();
static BufferedReader bf;
static PrintWriter pw;
static int n;
static void solve(int te) throws Exception{
int a[]=new int[n];
if(n%2!=0){
int start=2;
if(((n-1)/2)%2==1) a[1]=1;
else a[1]=0;
for(int i=3;i<n;i+=2){
a[i]=start++;
}
for(int i=0;i<n;i+=2){
a[i]=start++;
}
}else{
if(n%4==0){
int start=0;
for(int i=0;i<n;i+=2) a[i]=start++;
for(int i=1;i<n;i+=2) a[i]=start++;
}else{
int xor=0;
for(int i=1;i<=n-2;i++) xor^=i;
if(xor==0){
xor^=1;
int nextPow=1<<30;
xor^=nextPow;
int start=0;
for(int i=0;i<n-2;i+=2) a[i]=start++;
for(int i=1;i<n-2;i+=2) a[i]=start++;
a[n-2]=nextPow;
a[n-1]=xor;
}else{
int idx=1<<(int)(Math.ceil(Math.log(n-1)/Math.log(2)));
int nextPow=1<<30;
xor^=nextPow;
int start=1;
for(int i=0;i<n-2;i+=2) a[i]=start++;
for(int i=1;i<n-2;i+=2) a[i]=start++;
a[n-2]=nextPow;
a[n-1]=xor;
}
}
}
for(int i=0;i<n;i++) str.append(a[i]).append(" ");
str.append("\n");
}
public static void main(String[] args) throws java.lang.Exception {
boolean lenv=false;
if(lenv){
bf = new BufferedReader(
new FileReader("input.txt"));
pw=new PrintWriter(new
BufferedWriter(new FileWriter("output.txt")));
}else{
bf = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(new OutputStreamWriter(System.out));
}
int q1 = Integer.parseInt(bf.readLine().trim());
for(int te=1;te<=q1;te++) {
n=Integer.parseInt(bf.readLine().trim());
solve(te);
}
pw.print(str);
pw.flush();
// System.out.println(str);
}
}
|
Java
|
["7\n8\n3\n4\n5\n6\n7\n9"]
|
1 second
|
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
|
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
|
Java 8
|
standard input
|
[
"bitmasks",
"constructive algorithms",
"greedy"
] |
52bd5dc6b92b2af5aebd387553ef4076
|
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
| 1,500
|
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
|
standard output
| |
PASSED
|
d37fb9dea55246e2d9d5a23e8284cd7c
|
train_109.jsonl
|
1661871000
|
Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.
|
256 megabytes
|
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
private static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
StringBuilder sb = new StringBuilder();
List<Integer> list = new ArrayList<>();
for (int i = 1; i <= n / 2; i++) {
list.add(3 << 20 | i);
list.add(i);
}
if (n % 2 != 0) list.add(3 << 20);
if ((n + 1) / 2 % 2 == 1) {
list.set(n - 1, 1 << 20 ^ list.get(n - 1));
list.set(n - 3, 2 << 20 ^ list.get(n - 3));
}
for (Integer num : list) {
sb.append(num).append(" ");
}
System.out.println(sb.toString().trim());
}
}
}
|
Java
|
["7\n8\n3\n4\n5\n6\n7\n9"]
|
1 second
|
["4 2 1 5 0 6 7 3\n2 1 3\n2 1 3 0\n2 0 4 5 3\n4 1 2 12 3 8\n1 2 3 4 5 6 7\n8 2 3 7 4 0 5 6 9"]
|
NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.
|
Java 8
|
standard input
|
[
"bitmasks",
"constructive algorithms",
"greedy"
] |
52bd5dc6b92b2af5aebd387553ef4076
|
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
| 1,500
|
For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.
|
standard output
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.