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
03d9a80d593fdb926014618fcb9d612c
train_002.jsonl
1474119900
ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed disappear! More formally, if you typed a word at second a and then the next word at second b, then if b - a ≀ c, just the new word is appended to other words on the screen. If b - a > c, then everything on the screen disappears and after that the word you have typed appears on the screen.For example, if c = 5 and you typed words at seconds 1, 3, 8, 14, 19, 20 then at the second 8 there will be 3 words on the screen. After that, everything disappears at the second 13 because nothing was typed. At the seconds 14 and 19 another two words are typed, and finally, at the second 20, one more word is typed, and a total of 3 words remain on the screen.You're given the times when ZS the Coder typed the words. Determine how many words remain on the screen after he finished typing everything.
256 megabytes
import java.util.Scanner; public class NewMain5 { public static void main(String[] args) { // TODO code application logic here Scanner s = new Scanner(System.in); int n = s.nextInt(); long c = s.nextLong(); long[] sec = new long[n]; for (int i = 0; i < n; i++) { sec[i] = s.nextLong(); } int answer = 1; for (int i = 0; i < n - 1; i++) { if (sec[i + 1] - sec[i] <= c) { answer++; } else { answer = 1; } } System.out.println(answer); } }
Java
["6 5\n1 3 8 14 19 20", "6 1\n1 3 5 7 9 10"]
2 seconds
["3", "2"]
NoteThe first sample is already explained in the problem statement.For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 &gt; 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be two words on the screen, as the old word won't disappear because 10 - 9 ≀ 1.
Java 8
standard input
[ "implementation" ]
fb58bc3be4a7a78bdc001298d35c6b21
The first line contains two integers n and c (1 ≀ n ≀ 100 000, 1 ≀ c ≀ 109)Β β€” the number of words ZS the Coder typed and the crazy computer delay respectively. The next line contains n integers t1, t2, ..., tn (1 ≀ t1 &lt; t2 &lt; ... &lt; tn ≀ 109), where ti denotes the second when ZS the Coder typed the i-th word.
800
Print a single positive integer, the number of words that remain on the screen after all n words was typed, in other words, at the second tn.
standard output
PASSED
162e7de556f76efbac7ae2e4eea4eff6
train_002.jsonl
1474119900
ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed disappear! More formally, if you typed a word at second a and then the next word at second b, then if b - a ≀ c, just the new word is appended to other words on the screen. If b - a &gt; c, then everything on the screen disappears and after that the word you have typed appears on the screen.For example, if c = 5 and you typed words at seconds 1, 3, 8, 14, 19, 20 then at the second 8 there will be 3 words on the screen. After that, everything disappears at the second 13 because nothing was typed. At the seconds 14 and 19 another two words are typed, and finally, at the second 20, one more word is typed, and a total of 3 words remain on the screen.You're given the times when ZS the Coder typed the words. Determine how many words remain on the screen after he finished typing everything.
256 megabytes
import java.util.Scanner;; public class CrazyComputer_716A { public static void main(String... args) { Scanner input = new Scanner(System.in); int n = input.nextInt(); int c = input.nextInt(); int total = 0; int prev = 0; for (int i = 0; i < n; i++) { int curr = input.nextInt(); if (curr - prev > c) total = 1; else total++; prev = curr; } System.out.println(total); input.close(); } }
Java
["6 5\n1 3 8 14 19 20", "6 1\n1 3 5 7 9 10"]
2 seconds
["3", "2"]
NoteThe first sample is already explained in the problem statement.For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 &gt; 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be two words on the screen, as the old word won't disappear because 10 - 9 ≀ 1.
Java 8
standard input
[ "implementation" ]
fb58bc3be4a7a78bdc001298d35c6b21
The first line contains two integers n and c (1 ≀ n ≀ 100 000, 1 ≀ c ≀ 109)Β β€” the number of words ZS the Coder typed and the crazy computer delay respectively. The next line contains n integers t1, t2, ..., tn (1 ≀ t1 &lt; t2 &lt; ... &lt; tn ≀ 109), where ti denotes the second when ZS the Coder typed the i-th word.
800
Print a single positive integer, the number of words that remain on the screen after all n words was typed, in other words, at the second tn.
standard output
PASSED
ff84859aabd89e43134597f6a171ad60
train_002.jsonl
1474119900
ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed disappear! More formally, if you typed a word at second a and then the next word at second b, then if b - a ≀ c, just the new word is appended to other words on the screen. If b - a &gt; c, then everything on the screen disappears and after that the word you have typed appears on the screen.For example, if c = 5 and you typed words at seconds 1, 3, 8, 14, 19, 20 then at the second 8 there will be 3 words on the screen. After that, everything disappears at the second 13 because nothing was typed. At the seconds 14 and 19 another two words are typed, and finally, at the second 20, one more word is typed, and a total of 3 words remain on the screen.You're given the times when ZS the Coder typed the words. Determine how many words remain on the screen after he finished typing everything.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class C372 { public static void main(String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); Integer n = Integer.parseInt(st.nextToken()); Integer c = Integer.parseInt(st.nextToken()); int last = 0; int count = 0; st = new StringTokenizer(br.readLine()); for (int i = 0 ; i < n; i++) { int cur = Integer.parseInt(st.nextToken()); if (cur - last <= c) count++; else count = 1; last = cur; } System.out.println(count); } }
Java
["6 5\n1 3 8 14 19 20", "6 1\n1 3 5 7 9 10"]
2 seconds
["3", "2"]
NoteThe first sample is already explained in the problem statement.For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 &gt; 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be two words on the screen, as the old word won't disappear because 10 - 9 ≀ 1.
Java 8
standard input
[ "implementation" ]
fb58bc3be4a7a78bdc001298d35c6b21
The first line contains two integers n and c (1 ≀ n ≀ 100 000, 1 ≀ c ≀ 109)Β β€” the number of words ZS the Coder typed and the crazy computer delay respectively. The next line contains n integers t1, t2, ..., tn (1 ≀ t1 &lt; t2 &lt; ... &lt; tn ≀ 109), where ti denotes the second when ZS the Coder typed the i-th word.
800
Print a single positive integer, the number of words that remain on the screen after all n words was typed, in other words, at the second tn.
standard output
PASSED
1118c9a148e42180fe5b2d07cd46ddd1
train_002.jsonl
1474119900
ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed disappear! More formally, if you typed a word at second a and then the next word at second b, then if b - a ≀ c, just the new word is appended to other words on the screen. If b - a &gt; c, then everything on the screen disappears and after that the word you have typed appears on the screen.For example, if c = 5 and you typed words at seconds 1, 3, 8, 14, 19, 20 then at the second 8 there will be 3 words on the screen. After that, everything disappears at the second 13 because nothing was typed. At the seconds 14 and 19 another two words are typed, and finally, at the second 20, one more word is typed, and a total of 3 words remain on the screen.You're given the times when ZS the Coder typed the words. Determine how many words remain on the screen after he finished typing everything.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskA solver = new TaskA(); solver.solve(1, in, out); out.close(); } static class TaskA { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); int c = in.nextInt(); int cnt = 1; int prev = in.nextInt(); for (int i = 0; i < n - 1; i++) { int cur = in.nextInt(); if (cur - prev <= c) cnt++; else cnt = 1; prev = cur; } out.println(cnt); } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
Java
["6 5\n1 3 8 14 19 20", "6 1\n1 3 5 7 9 10"]
2 seconds
["3", "2"]
NoteThe first sample is already explained in the problem statement.For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 &gt; 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be two words on the screen, as the old word won't disappear because 10 - 9 ≀ 1.
Java 8
standard input
[ "implementation" ]
fb58bc3be4a7a78bdc001298d35c6b21
The first line contains two integers n and c (1 ≀ n ≀ 100 000, 1 ≀ c ≀ 109)Β β€” the number of words ZS the Coder typed and the crazy computer delay respectively. The next line contains n integers t1, t2, ..., tn (1 ≀ t1 &lt; t2 &lt; ... &lt; tn ≀ 109), where ti denotes the second when ZS the Coder typed the i-th word.
800
Print a single positive integer, the number of words that remain on the screen after all n words was typed, in other words, at the second tn.
standard output
PASSED
8e0f2414b218b1e12de4405e79ed25fa
train_002.jsonl
1474119900
ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed disappear! More formally, if you typed a word at second a and then the next word at second b, then if b - a ≀ c, just the new word is appended to other words on the screen. If b - a &gt; c, then everything on the screen disappears and after that the word you have typed appears on the screen.For example, if c = 5 and you typed words at seconds 1, 3, 8, 14, 19, 20 then at the second 8 there will be 3 words on the screen. After that, everything disappears at the second 13 because nothing was typed. At the seconds 14 and 19 another two words are typed, and finally, at the second 20, one more word is typed, and a total of 3 words remain on the screen.You're given the times when ZS the Coder typed the words. Determine how many words remain on the screen after he finished typing everything.
256 megabytes
import java.util.Scanner; public class kk { public static void main(String args[]) { int n,c; Scanner sc=new Scanner(System.in); n=sc.nextInt(); c=sc.nextInt(); // System.out.println(n+" "+c); int arr[]=new int[n]; int words=1; for(int k=0;k<n;k++) arr[k]=sc.nextInt(); for(int i=0;i<n-1;i++) { if(arr[i+1]-arr[i]<=c) { words++; } else words=1; //System.out.println(words); } System.out.println(words); } }
Java
["6 5\n1 3 8 14 19 20", "6 1\n1 3 5 7 9 10"]
2 seconds
["3", "2"]
NoteThe first sample is already explained in the problem statement.For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 &gt; 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be two words on the screen, as the old word won't disappear because 10 - 9 ≀ 1.
Java 8
standard input
[ "implementation" ]
fb58bc3be4a7a78bdc001298d35c6b21
The first line contains two integers n and c (1 ≀ n ≀ 100 000, 1 ≀ c ≀ 109)Β β€” the number of words ZS the Coder typed and the crazy computer delay respectively. The next line contains n integers t1, t2, ..., tn (1 ≀ t1 &lt; t2 &lt; ... &lt; tn ≀ 109), where ti denotes the second when ZS the Coder typed the i-th word.
800
Print a single positive integer, the number of words that remain on the screen after all n words was typed, in other words, at the second tn.
standard output
PASSED
4211f4085cf5f58c50e0053607085f60
train_002.jsonl
1474119900
ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed disappear! More formally, if you typed a word at second a and then the next word at second b, then if b - a ≀ c, just the new word is appended to other words on the screen. If b - a &gt; c, then everything on the screen disappears and after that the word you have typed appears on the screen.For example, if c = 5 and you typed words at seconds 1, 3, 8, 14, 19, 20 then at the second 8 there will be 3 words on the screen. After that, everything disappears at the second 13 because nothing was typed. At the seconds 14 and 19 another two words are typed, and finally, at the second 20, one more word is typed, and a total of 3 words remain on the screen.You're given the times when ZS the Coder typed the words. Determine how many words remain on the screen after he finished typing everything.
256 megabytes
import java.util.Scanner; public class Test { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int c = in.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = in.nextInt(); } int count = 1; for (int i = 1; i < n; i++) { if (arr[i] - arr[i - 1] <= c) { count++; } else { count = 1; } } System.out.println(count); } }
Java
["6 5\n1 3 8 14 19 20", "6 1\n1 3 5 7 9 10"]
2 seconds
["3", "2"]
NoteThe first sample is already explained in the problem statement.For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 &gt; 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be two words on the screen, as the old word won't disappear because 10 - 9 ≀ 1.
Java 8
standard input
[ "implementation" ]
fb58bc3be4a7a78bdc001298d35c6b21
The first line contains two integers n and c (1 ≀ n ≀ 100 000, 1 ≀ c ≀ 109)Β β€” the number of words ZS the Coder typed and the crazy computer delay respectively. The next line contains n integers t1, t2, ..., tn (1 ≀ t1 &lt; t2 &lt; ... &lt; tn ≀ 109), where ti denotes the second when ZS the Coder typed the i-th word.
800
Print a single positive integer, the number of words that remain on the screen after all n words was typed, in other words, at the second tn.
standard output
PASSED
e7123ade342e644a36f3b8efb2507a27
train_002.jsonl
1474119900
ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed disappear! More formally, if you typed a word at second a and then the next word at second b, then if b - a ≀ c, just the new word is appended to other words on the screen. If b - a &gt; c, then everything on the screen disappears and after that the word you have typed appears on the screen.For example, if c = 5 and you typed words at seconds 1, 3, 8, 14, 19, 20 then at the second 8 there will be 3 words on the screen. After that, everything disappears at the second 13 because nothing was typed. At the seconds 14 and 19 another two words are typed, and finally, at the second 20, one more word is typed, and a total of 3 words remain on the screen.You're given the times when ZS the Coder typed the words. Determine how many words remain on the screen after he finished typing everything.
256 megabytes
import java.util.Scanner; public class Game{ public static void main(String arg[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int c=sc.nextInt(); int[] arr=new int[n]; arr[0]=sc.nextInt(); int count=1; for(int i=1;i<n;i++){ arr[i]=sc.nextInt(); int temp=arr[i]-arr[i-1]; count++; if(temp>c)count=1; } System.out.println(count); } }
Java
["6 5\n1 3 8 14 19 20", "6 1\n1 3 5 7 9 10"]
2 seconds
["3", "2"]
NoteThe first sample is already explained in the problem statement.For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 &gt; 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be two words on the screen, as the old word won't disappear because 10 - 9 ≀ 1.
Java 8
standard input
[ "implementation" ]
fb58bc3be4a7a78bdc001298d35c6b21
The first line contains two integers n and c (1 ≀ n ≀ 100 000, 1 ≀ c ≀ 109)Β β€” the number of words ZS the Coder typed and the crazy computer delay respectively. The next line contains n integers t1, t2, ..., tn (1 ≀ t1 &lt; t2 &lt; ... &lt; tn ≀ 109), where ti denotes the second when ZS the Coder typed the i-th word.
800
Print a single positive integer, the number of words that remain on the screen after all n words was typed, in other words, at the second tn.
standard output
PASSED
94cf9de35891b31dc535e3b28893e071
train_002.jsonl
1474119900
ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed disappear! More formally, if you typed a word at second a and then the next word at second b, then if b - a ≀ c, just the new word is appended to other words on the screen. If b - a &gt; c, then everything on the screen disappears and after that the word you have typed appears on the screen.For example, if c = 5 and you typed words at seconds 1, 3, 8, 14, 19, 20 then at the second 8 there will be 3 words on the screen. After that, everything disappears at the second 13 because nothing was typed. At the seconds 14 and 19 another two words are typed, and finally, at the second 20, one more word is typed, and a total of 3 words remain on the screen.You're given the times when ZS the Coder typed the words. Determine how many words remain on the screen after he finished typing everything.
256 megabytes
import java.util.*; import java.lang.*; public class JavaApplication4 { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int a= sc.nextInt(); int b=sc.nextInt(); int[] c= new int[a]; for(int i=0;i<a;i++){ c[i]=sc.nextInt(); } int d=1; if(a==1)System.out.print(1); else{ for(int i=1;i<a;i++){ if(c[i]-c[i-1]>b)d=0; d+=1; } System.out.print(d); } } }
Java
["6 5\n1 3 8 14 19 20", "6 1\n1 3 5 7 9 10"]
2 seconds
["3", "2"]
NoteThe first sample is already explained in the problem statement.For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 &gt; 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be two words on the screen, as the old word won't disappear because 10 - 9 ≀ 1.
Java 8
standard input
[ "implementation" ]
fb58bc3be4a7a78bdc001298d35c6b21
The first line contains two integers n and c (1 ≀ n ≀ 100 000, 1 ≀ c ≀ 109)Β β€” the number of words ZS the Coder typed and the crazy computer delay respectively. The next line contains n integers t1, t2, ..., tn (1 ≀ t1 &lt; t2 &lt; ... &lt; tn ≀ 109), where ti denotes the second when ZS the Coder typed the i-th word.
800
Print a single positive integer, the number of words that remain on the screen after all n words was typed, in other words, at the second tn.
standard output
PASSED
29028c15c9c67e4bfb0ce1f8726af811
train_002.jsonl
1474119900
ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed disappear! More formally, if you typed a word at second a and then the next word at second b, then if b - a ≀ c, just the new word is appended to other words on the screen. If b - a &gt; c, then everything on the screen disappears and after that the word you have typed appears on the screen.For example, if c = 5 and you typed words at seconds 1, 3, 8, 14, 19, 20 then at the second 8 there will be 3 words on the screen. After that, everything disappears at the second 13 because nothing was typed. At the seconds 14 and 19 another two words are typed, and finally, at the second 20, one more word is typed, and a total of 3 words remain on the screen.You're given the times when ZS the Coder typed the words. Determine how many words remain on the screen after he finished typing everything.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int a=sc.nextInt(); int b=sc.nextInt(); int A[]=new int[a]; int count=1; for (int i = 0; i < a; i++) { int c=sc.nextInt(); A[i]=c; } for (int i = 0; i < a-1; i++) { { if((A[i+1]-A[i])<=b){ count++; } else{ count=1; } } } System.out.println(count); } }
Java
["6 5\n1 3 8 14 19 20", "6 1\n1 3 5 7 9 10"]
2 seconds
["3", "2"]
NoteThe first sample is already explained in the problem statement.For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 &gt; 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be two words on the screen, as the old word won't disappear because 10 - 9 ≀ 1.
Java 8
standard input
[ "implementation" ]
fb58bc3be4a7a78bdc001298d35c6b21
The first line contains two integers n and c (1 ≀ n ≀ 100 000, 1 ≀ c ≀ 109)Β β€” the number of words ZS the Coder typed and the crazy computer delay respectively. The next line contains n integers t1, t2, ..., tn (1 ≀ t1 &lt; t2 &lt; ... &lt; tn ≀ 109), where ti denotes the second when ZS the Coder typed the i-th word.
800
Print a single positive integer, the number of words that remain on the screen after all n words was typed, in other words, at the second tn.
standard output
PASSED
0a15011c8564d6c58c8ec7e4ff51135c
train_002.jsonl
1474119900
ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed disappear! More formally, if you typed a word at second a and then the next word at second b, then if b - a ≀ c, just the new word is appended to other words on the screen. If b - a &gt; c, then everything on the screen disappears and after that the word you have typed appears on the screen.For example, if c = 5 and you typed words at seconds 1, 3, 8, 14, 19, 20 then at the second 8 there will be 3 words on the screen. After that, everything disappears at the second 13 because nothing was typed. At the seconds 14 and 19 another two words are typed, and finally, at the second 20, one more word is typed, and a total of 3 words remain on the screen.You're given the times when ZS the Coder typed the words. Determine how many words remain on the screen after he finished typing everything.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int a=sc.nextInt(); int b=sc.nextInt(); int A[]=new int[a]; int count=1; for (int i = 0; i < a; i++) { int c=sc.nextInt(); A[i]=c; } for (int i = 0; i < a-1; i++) { { if((A[i+1]-A[i])<=b){ count++; } else{ count=1; } } } System.out.println(count); } }
Java
["6 5\n1 3 8 14 19 20", "6 1\n1 3 5 7 9 10"]
2 seconds
["3", "2"]
NoteThe first sample is already explained in the problem statement.For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 &gt; 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be two words on the screen, as the old word won't disappear because 10 - 9 ≀ 1.
Java 8
standard input
[ "implementation" ]
fb58bc3be4a7a78bdc001298d35c6b21
The first line contains two integers n and c (1 ≀ n ≀ 100 000, 1 ≀ c ≀ 109)Β β€” the number of words ZS the Coder typed and the crazy computer delay respectively. The next line contains n integers t1, t2, ..., tn (1 ≀ t1 &lt; t2 &lt; ... &lt; tn ≀ 109), where ti denotes the second when ZS the Coder typed the i-th word.
800
Print a single positive integer, the number of words that remain on the screen after all n words was typed, in other words, at the second tn.
standard output
PASSED
485a7a5be071859d3e228c44ef7337fd
train_002.jsonl
1474119900
ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed disappear! More formally, if you typed a word at second a and then the next word at second b, then if b - a ≀ c, just the new word is appended to other words on the screen. If b - a &gt; c, then everything on the screen disappears and after that the word you have typed appears on the screen.For example, if c = 5 and you typed words at seconds 1, 3, 8, 14, 19, 20 then at the second 8 there will be 3 words on the screen. After that, everything disappears at the second 13 because nothing was typed. At the seconds 14 and 19 another two words are typed, and finally, at the second 20, one more word is typed, and a total of 3 words remain on the screen.You're given the times when ZS the Coder typed the words. Determine how many words remain on the screen after he finished typing everything.
256 megabytes
import java.util.Scanner; public class R372A { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int x = scan.nextInt(), k = scan.nextInt(); int[] nums = new int[x]; for (int i = 0; i < nums.length; ++i) { nums[i] = scan.nextInt(); } int count = 0; for (int i = 0; i < nums.length; ++i) { if (i < nums.length - 1) { if (nums[i + 1] - nums[i] <= k) count++; else count = 0; } } ++count; System.out.println(count); } }
Java
["6 5\n1 3 8 14 19 20", "6 1\n1 3 5 7 9 10"]
2 seconds
["3", "2"]
NoteThe first sample is already explained in the problem statement.For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 &gt; 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be two words on the screen, as the old word won't disappear because 10 - 9 ≀ 1.
Java 8
standard input
[ "implementation" ]
fb58bc3be4a7a78bdc001298d35c6b21
The first line contains two integers n and c (1 ≀ n ≀ 100 000, 1 ≀ c ≀ 109)Β β€” the number of words ZS the Coder typed and the crazy computer delay respectively. The next line contains n integers t1, t2, ..., tn (1 ≀ t1 &lt; t2 &lt; ... &lt; tn ≀ 109), where ti denotes the second when ZS the Coder typed the i-th word.
800
Print a single positive integer, the number of words that remain on the screen after all n words was typed, in other words, at the second tn.
standard output
PASSED
ae8bd22a93302666da376e1923e80171
train_002.jsonl
1474119900
ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed disappear! More formally, if you typed a word at second a and then the next word at second b, then if b - a ≀ c, just the new word is appended to other words on the screen. If b - a &gt; c, then everything on the screen disappears and after that the word you have typed appears on the screen.For example, if c = 5 and you typed words at seconds 1, 3, 8, 14, 19, 20 then at the second 8 there will be 3 words on the screen. After that, everything disappears at the second 13 because nothing was typed. At the seconds 14 and 19 another two words are typed, and finally, at the second 20, one more word is typed, and a total of 3 words remain on the screen.You're given the times when ZS the Coder typed the words. Determine how many words remain on the screen after he finished typing everything.
256 megabytes
import java.io.*; import java.util.StringTokenizer; public class CrazyComputer { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()); int c = Integer.parseInt(st.nextToken()); int[]a = new int[n]; st = new StringTokenizer(br.readLine()); int count=1; for (int i = 0; i < n; i++) { a[i] = Integer.parseInt(st.nextToken()); } for (int i = 1; i < n; i++) { if(a[i]- a[i-1] <= c) { count++; } else { count=1; } } System.out.println(count); } }
Java
["6 5\n1 3 8 14 19 20", "6 1\n1 3 5 7 9 10"]
2 seconds
["3", "2"]
NoteThe first sample is already explained in the problem statement.For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 &gt; 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be two words on the screen, as the old word won't disappear because 10 - 9 ≀ 1.
Java 8
standard input
[ "implementation" ]
fb58bc3be4a7a78bdc001298d35c6b21
The first line contains two integers n and c (1 ≀ n ≀ 100 000, 1 ≀ c ≀ 109)Β β€” the number of words ZS the Coder typed and the crazy computer delay respectively. The next line contains n integers t1, t2, ..., tn (1 ≀ t1 &lt; t2 &lt; ... &lt; tn ≀ 109), where ti denotes the second when ZS the Coder typed the i-th word.
800
Print a single positive integer, the number of words that remain on the screen after all n words was typed, in other words, at the second tn.
standard output
PASSED
94133779472d960643cbf422c93d6167
train_002.jsonl
1474119900
ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed disappear! More formally, if you typed a word at second a and then the next word at second b, then if b - a ≀ c, just the new word is appended to other words on the screen. If b - a &gt; c, then everything on the screen disappears and after that the word you have typed appears on the screen.For example, if c = 5 and you typed words at seconds 1, 3, 8, 14, 19, 20 then at the second 8 there will be 3 words on the screen. After that, everything disappears at the second 13 because nothing was typed. At the seconds 14 and 19 another two words are typed, and finally, at the second 20, one more word is typed, and a total of 3 words remain on the screen.You're given the times when ZS the Coder typed the words. Determine how many words remain on the screen after he finished typing everything.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); int c = s.nextInt(); int se = s.nextInt(); int coun = 1; int[] a = new int[c]; for (int i = 0; i < c; i++) { a[i] = s.nextInt(); } for (int i = 1; i < c; i++) { coun++; if (a[i] - a[i - 1] > se) { coun = 1; } } System.out.println(coun); } }
Java
["6 5\n1 3 8 14 19 20", "6 1\n1 3 5 7 9 10"]
2 seconds
["3", "2"]
NoteThe first sample is already explained in the problem statement.For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 &gt; 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be two words on the screen, as the old word won't disappear because 10 - 9 ≀ 1.
Java 8
standard input
[ "implementation" ]
fb58bc3be4a7a78bdc001298d35c6b21
The first line contains two integers n and c (1 ≀ n ≀ 100 000, 1 ≀ c ≀ 109)Β β€” the number of words ZS the Coder typed and the crazy computer delay respectively. The next line contains n integers t1, t2, ..., tn (1 ≀ t1 &lt; t2 &lt; ... &lt; tn ≀ 109), where ti denotes the second when ZS the Coder typed the i-th word.
800
Print a single positive integer, the number of words that remain on the screen after all n words was typed, in other words, at the second tn.
standard output
PASSED
032b6d678f33621d2cdd3f31b0286540
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.io.*; import java.math.BigInteger; import java.util.*; public class Main implements Runnable { int maxn = (int)1e2+111; int n,m,k; int a[][] = new int[maxn][maxn]; int row[] = new int[maxn]; int col[] = new int[maxn]; void solve() throws Exception { n = in.nextInt(); m = in.nextInt(); for (int i=1; i<=n; i++) { row[i] = in.nextInt(); a[i][m] = row[i]; } for (int i=1; i<=m; i++) { col[i] = in.nextInt(); a[n][i] = col[i]; } for (int i=1; i<=n-1; i++) { for (int j=1; j<=m-1; j++) { a[i][j] = 0; } } a[n][m] = 0; int lastCol = 0; for (int i=1; i<=n-1; i++) { lastCol ^= a[i][m]; } int lastRow = 0; for (int i=1; i<=m-1; i++) { lastRow ^= a[n][i]; } int left = lastRow^row[n]; a[n][m] = left; int right = lastCol^a[n][m]; if (right==col[m]) { out.println("YES"); for (int i=1; i<=n; i++) { for (int j=1; j<=m; j++) { out.print(a[i][j] + " "); } out.println(); } } else { out.println("NO"); } } /* 2 2 1000000000 1000000000 1000000000 1000000000 */ class Pair { int x, y; public Pair(int x, int y) { this.x = x; this.y = y; } } String fileInName = ""; boolean file = false; boolean isAcmp = false; static Throwable throwable; public static void main (String [] args) throws Throwable { Thread thread = new Thread(null, new Main(), "", (1 << 26)); thread.start(); thread.join(); thread.run(); if (throwable != null) throw throwable; } FastReader in; PrintWriter out; public void run() { String fileIn = "absum.in"; String fileOut = "absum.out"; try { if (isAcmp) { if (file) { in = new FastReader(new BufferedReader(new FileReader(fileIn))); out = new PrintWriter (fileOut); } else { in = new FastReader(new BufferedReader(new InputStreamReader(System.in))); out = new PrintWriter(System.out); } } else if (file) { in = new FastReader(new BufferedReader(new FileReader(fileInName+".in"))); out = new PrintWriter (fileInName + ".out"); } else { in = new FastReader(new BufferedReader(new InputStreamReader(System.in))); out = new PrintWriter(System.out); } solve(); } catch(Exception e) { throwable = e; } finally { out.close(); } } } class FastReader { BufferedReader bf; StringTokenizer tk = null; public FastReader(BufferedReader bf) { this.bf = bf; } public String nextToken () throws Exception { if (tk==null || !tk.hasMoreTokens()) { tk = new StringTokenizer(bf.readLine()); } if (!tk.hasMoreTokens()) return nextToken(); else return tk.nextToken(); } public int nextInt() throws Exception { return Integer.parseInt(nextToken()); } public long nextLong() throws Exception { return Long.parseLong(nextToken()); } public double nextDouble() throws Exception { return Double.parseDouble(nextToken()); } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
5ab7e736edc9a2e59ec3f2c1501c0cfe
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author DY */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); DVasyaAndTheMatrix solver = new DVasyaAndTheMatrix(); solver.solve(1, in, out); out.close(); } static class DVasyaAndTheMatrix { public void solve(int testNumber, InputReader in, OutputWriter out) { int n = in.readInt(); int m = in.readInt(); int[] a = new int[n]; int[] b = new int[m]; for (int i = 0; i < n; ++i) a[i] = in.readInt(); for (int i = 0; i < m; ++i) b[i] = in.readInt(); int[][] ans = new int[n][m]; int last1 = a[n - 1], last2 = b[m - 1]; for (int i = 0; i < n - 1; ++i) { ans[i][m - 1] = a[i]; last2 ^= a[i]; } for (int i = 0; i < m - 1; ++i) { ans[n - 1][i] = b[i]; last1 ^= b[i]; } if (last1 != last2) { out.printLine("NO"); } else { ans[n - 1][m - 1] = last1; out.printLine("YES"); for (int i = 0; i < n; ++i) out.printLine(ans[i]); } } } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private InputReader.SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public int readInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) { writer.print(' '); } writer.print(objects[i]); } } public void print(int[] array) { for (int i = 0; i < array.length; i++) { if (i != 0) { writer.print(' '); } writer.print(array[i]); } } public void printLine(int[] array) { print(array); writer.println(); } public void printLine(Object... objects) { print(objects); writer.println(); } public void close() { writer.close(); } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
111e9adbb3cbe28cbabf47f2a5f8c568
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); StringTokenizer st = new StringTokenizer(in.readLine()); int n = Integer.parseInt(st.nextToken()); int m = Integer.parseInt(st.nextToken()); int[] a = new int[n]; int[] b = new int[m]; st = new StringTokenizer(in.readLine()); for (int i = 0; i < n; i++) a[i] = Integer.parseInt(st.nextToken()); st = new StringTokenizer(in.readLine()); for (int i = 0; i < m; i++) b[i] = Integer.parseInt(st.nextToken()); int ta = 0; for (int i = 0; i < n; i++) ta ^= a[i]; int tb = 0; for (int i = 0; i < m; i++) tb ^= b[i]; if (ta != tb) { out.println("NO"); out.close(); return; } out.println("YES"); int s = a[0]; for (int i = 1; i < m; i++) s ^= b[i]; out.print(s + " "); for (int i = 1; i < m; i++) out.print(b[i] + " "); out.print('\n'); for (int i = 1; i < n; i++) { out.print(a[i] + " "); for (int j = 1; j < m; j++) { out.print("0 "); } out.print('\n'); } out.close(); } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
f066a532a67bdcb04e8485487943645a
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.util.*; import java.io.*; import java.lang.*; import java.math.*; import static java.lang.Math.*; import java.util.concurrent.ThreadLocalRandom; public class Sol implements Runnable { long mod = (long)1e9 + 7; void solve(InputReader in, PrintWriter w) { int n = in.nextInt(); int m = in.nextInt(); int a[] = new int[n]; int b[] = new int[m]; int xorA = 0, xorB = 0; int res[][] = new int[n][m]; for(int i=0;i<n;i++) { a[i] = in.nextInt(); xorA ^= a[i]; } for(int i=0;i<m;i++) { b[i] = in.nextInt(); xorB ^= b[i]; } if(xorA != xorB) w.println("NO"); else { w.println("YES"); res[0][0] = a[0] ^ xorB ^ b[0]; for(int i=1;i<m;i++) res[0][i] = b[i]; for(int i=1;i<n;i++) res[i][0] = a[i]; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) w.print(res[i][j]+" "); w.println(); } } } // ************* Code ends here *************** void init() throws Exception { //Scanner in; InputReader in; PrintWriter w; boolean online = false; String common_in_fileName = "\\in"; String common_out_fileName = "\\out"; int test_files = 0; for (int file_no = 0; file_no <= test_files; file_no++) { String x = "" + file_no; if (x.length() == 1) x = "0" + x; String in_fileName = common_in_fileName + "" + x; String out_fileName = common_out_fileName + "" + x; if (online) { //in = new Scanner(new File(in_fileName + ".txt")); in = new InputReader(new FileInputStream(new File(in_fileName + ".txt"))); w = new PrintWriter(new FileWriter(out_fileName + ".txt")); } else { //in = new Scanner(System.in); in = new InputReader(System.in); w = new PrintWriter(System.out); } solve(in, w); w.close(); } } public void run() { try { init(); } catch (Exception e) { System.out.println(e); e.printStackTrace(); } } public static void main(String args[]) throws Exception { new Thread(null, new Sol(), "Sol", 1 << 28).start(); } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public String nextLine() { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public double nextDouble() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') { return res * Math.pow(10, nextInt()); } if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') { return res * Math.pow(10, nextInt()); } if (c < '0' || c > '9') { throw new InputMismatchException(); } m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
659b422cce3b2f04a7ac0457fa471af1
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.io.*; import java.math.*; import java.util.*; import static java.util.Arrays.fill; import static java.lang.Math.*; import static java.util.Arrays.sort; import static java.util.Collections.sort; public class D { public static int mod = 1000000007; public static long INF = (1L << 60); static FastScanner2 in = new FastScanner2(); static OutputWriter out = new OutputWriter(System.out); public static void main(String[] args) { int n=in.nextInt(); int m=in.nextInt(); int[] a=new int[n+1]; int[] b=new int[m+1]; int x1=0,x2=0; for(int i=1;i<=n;i++) { a[i]=in.nextInt(); x1^=a[i]; } for(int i=1;i<=m;i++) { b[i]=in.nextInt(); x2^=b[i]; } if(x1!=x2) { System.out.println("NO"); return; } int[][] ans=new int[n+1][m+1]; for(int i=1;i<n;i++) { ans[i][m]=a[i]; } int x=0; for(int i=1;i<m;i++) { ans[n][i]=b[i]; x^=b[i]; } ans[n][m]=a[n]^x; out.println("YES"); for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { out.print(ans[i][j]+" "); } out.println(); } out.close(); } static class FastScanner2 { private byte[] buf = new byte[1024]; private int curChar; private int snumChars; public int read() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = System.in.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); } public String nextString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = nextInt(); } return arr; } public long[] nextLongArray(int n) { long[] arr = new long[n]; for (int i = 0; i < n; i++) { arr[i] = nextLong(); } return arr; } private boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream inputstream) { reader = new BufferedReader(new InputStreamReader(inputstream)); tokenizer = null; } public String nextLine() { String fullLine = null; while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { fullLine = reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } return fullLine; } return fullLine; } 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 long nextLong() { return Long.parseLong(next()); } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } public long[] nextLongArray(int n) { long a[] = new long[n]; for (int i = 0; i < n; i++) { a[i] = nextLong(); } return a; } public int nextInt() { return Integer.parseInt(next()); } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) writer.print(' '); writer.print(objects[i]); } } public void println(Object... objects) { print(objects); writer.println(); } public void close() { writer.close(); } public void flush() { writer.flush(); } } private static boolean oj = System.getProperty("ONLINE_JUDGE") != null; private static void debug(Object... o) { if (!oj) System.out.println(Arrays.deepToString(o)); } private static void tr(Object... o) { if (!oj) System.out.println(Arrays.deepToString(o)); } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
ab1a297feb028e50767fae054df498fa
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.util.*; public class myClass{ public static void main(String[] args) { // Use the Scanner class Scanner sc = new Scanner(System.in); /* int n = sc.nextInt(); // read input as integer long k = sc.nextLong(); // read input as long double d = sc.nextDouble(); // read input as double String str = sc.next(); // read input as String String s = sc.nextLine(); // read whole line as String */ long n,m; n = sc.nextLong(); m = sc.nextLong(); long[] a = new long[(int)n]; long[] b = new long[(int)m]; long pcur=0; for(int i=0;i<n;i++) { a[i] = sc.nextLong(); pcur^=a[i]; } long cur = 0; for(int i=0;i<m;i++) { b[i] = sc.nextLong(); cur^=b[i]; } if(cur == pcur){ System.out.print("YES\n"); cur^=b[0]; System.out.print(a[0]^cur); System.out.print(" "); for(int i=1;i<m;i++) { System.out.print(b[i]); System.out.print(" "); } System.out.println(""); for(int i=1;i<n;i++) { System.out.print(a[i]); System.out.print(" "); for(int j=1;j<m;j++) { System.out.print(0); System.out.print(" "); } System.out.println(""); } } else{ System.out.print("NO\n"); } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
07fdd94ed1d1e299e3e577ca5913d710
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.io.*; import java.util.*; public class Main { static InputReader in = new InputReader(System.in); static PrintWriter out = new PrintWriter(System.out); static long oo = (long)1e15; public static void main(String[] args) throws IOException { int n = in.nextInt(); int m = in.nextInt(); int[] a = in.nextIntArray(n); int[] b = in.nextIntArray(m); int aa = 0, bb = 0; for(int i = 0; i < n; ++i) aa ^= a[i]; for(int i = 0; i < m; ++i) bb ^= b[i]; if(aa != bb) { System.out.println("NO"); return; } int[][] ans = new int[n][m]; ans[0][0] = bb ^ b[0] ^ a[0]; for(int i = 1; i < m; ++i) ans[0][i] = b[i]; for(int i = 1; i < n; ++i) ans[i][0] = a[i]; System.out.println("YES"); for(int i = 0; i < n; ++i) { for(int j = 0; j < m; ++j) System.out.print(ans[i][j] + " "); System.out.println(); } out.close(); } static int[] getPi(char[] a) { int m = a.length; int j = 0; int[] pi = new int[m]; for(int i = 1; i < m; ++i) { while(j > 0 && a[i] != a[j]) j = pi[j-1]; if(a[i] == a[j]) { pi[i] = j + 1; j++; } } return pi; } static long lcm(long a, long b) { return a * b / gcd(a, b); } static boolean nextPermutation(int[] a) { for(int i = a.length - 2; i >= 0; --i) { if(a[i] < a[i+1]) { for(int j = a.length - 1; ; --j) { if(a[i] < a[j]) { int t = a[i]; a[i] = a[j]; a[j] = t; for(i++, j = a.length - 1; i < j; ++i, --j) { t = a[i]; a[i] = a[j]; a[j] = t; } return true; } } } } return false; } static void shuffle(int[] a) { Random r = new Random(); for(int i = a.length - 1; i > 0; --i) { int si = r.nextInt(i); int t = a[si]; a[si] = a[i]; a[i] = t; } } static void shuffle(long[] a) { Random r = new Random(); for(int i = a.length - 1; i > 0; --i) { int si = r.nextInt(i); long t = a[si]; a[si] = a[i]; a[i] = t; } } static int lower_bound(int[] a, int n, int k) { int s = 0; int e = n; int m; while (e - s > 0) { m = (s + e) / 2; if (a[m] < k) s = m + 1; else e = m; } return e; } static int lower_bound(long[] a, int n, long k) { int s = 0; int e = n; int m; while (e - s > 0) { m = (s + e) / 2; if (a[m] < k) s = m + 1; else e = m; } return e; } static int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } static long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); } static class Pair implements Comparable<Pair> { int first, second; public Pair(int first, int second) { super(); this.first = first; this.second = second; } @Override public int compareTo(Pair o) { return this.first != o.first ? this.first - o.first : this.second - o.second; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + first; result = prime * result + second; return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Pair other = (Pair) obj; if (first != other.first) return false; if (second != other.second) return false; return true; } } } class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; public InputReader(InputStream st) { this.stream = st; } public int read() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } public String readString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); } public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
98391adcb3d261512596cf65da6018e5
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.util.*; import java.io.*; public class A { public static void main(String ar[]) throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String s1[]=br.readLine().split(" "); int n=Integer.parseInt(s1[0]); int m=Integer.parseInt(s1[1]); String s2[]=br.readLine().split(" "); String s3[]=br.readLine().split(" "); long a[]=new long[n]; long b[]=new long[m]; long x=0,y=0; for(int i=0;i<n;i++) { a[i]=Long.parseLong(s2[i]); x=x^a[i]; } for(int i=0;i<m;i++) { b[i]=Long.parseLong(s3[i]); y=y^b[i]; } long c[][]=new long[n][m]; if(x!=y) System.out.println("NO"); else { c[0][0]=x^a[0]^b[0]; for(int i=1;i<m;i++) c[0][i]=b[i]; for(int i=1;i<n;i++) c[i][0]=a[i]; StringBuffer sb=new StringBuffer(); for(int i=0;i<n;i++) { for(int j=0;j<m;j++) sb.append(c[i][j]).append(" "); sb.append("\n"); } System.out.println("YES"); System.out.println(sb); } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
8646e96c238d04b444d2b2fc9e23d15d
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.lang.*; import java.util.*; import java.io.*; import java.math.*; public class Main { private static FastReader sc = new FastReader(System.in); private static OutputWriter out = new OutputWriter(System.out); public static void main(String[] args) { int r = sc.nextInt(); int c = sc.nextInt(); int[] a = new int[r]; int[] b = new int[c]; for (int i = 0; i < r; i++) a[i] = sc.nextInt(); for (int i = 0; i < c; i++) b[i] = sc.nextInt(); int[][][] arr = new int[r][c][32]; for (int k = 0; k < 32; k++) { int[] rows = new int[r]; int[] cols = new int[c]; int rowOnes = 0, colOnes = 0; for (int i = 0; i < r; i++) { // if (k == 1) System.out.println(a[i] + " " + (1 << k)); rows[i] = (a[i] & (1 << k)) == 0 ? 0 : 1; if (rows[i] == 1) rowOnes++; } for (int i = 0; i < c; i++) { cols[i] = (b[i] & (1 << k)) == 0 ? 0 : 1; if (cols[i] == 1) colOnes++; } // System.out.println(k + " " + rowOnes + " " + colOnes); if (Math.abs(rowOnes - colOnes) % 2 != 0) { // System.out.println(k + " " + rowOnes + " " + colOnes); System.out.println("NO"); System.exit(0); } ArrayList<Integer> remRows = new ArrayList<>(); ArrayList<Integer> remCols = new ArrayList<>(); for (int i = 0; i < r; i++) if (rows[i] == 1) remRows.add(i); for (int i = 0; i < c; i++) if (cols[i] == 1) remCols.add(i); int l = 0, m = 0; for (int i = 0; i < Math.min(rowOnes, colOnes); i++) { while (rows[l] != 1) l++; while (cols[m] != 1) m++; arr[l][m][k] = 1; remRows.remove((Integer) l); remCols.remove((Integer) m); l++; m++; } if (remRows.size() > 0) { for (int i : remRows) arr[i][0][k] = 1; } else { for (int j : remCols) arr[0][j][k] = 1; } } System.out.println("YES"); for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { int val = 0; // System.out.println(Arrays.toString(arr[i][j])); for (int k = 0; k < 32; k++) { val += arr[i][j][k] * (1 << k); } System.out.print(val + " "); } System.out.println(); } } } class FastReader { private boolean finished = false; private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public FastReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public int peek() { if (numChars == -1) { return -1; } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { return -1; } if (numChars <= 0) { return -1; } } return buf[curChar]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c == ',') { c = read(); } if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String nextString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private String readLine0() { StringBuilder buf = new StringBuilder(); int c = read(); while (c != '\n' && c != -1) { if (c != '\r') { buf.appendCodePoint(c); } c = read(); } return buf.toString(); } public String nextLine() { String s = readLine0(); while (s.trim().length() == 0) s = readLine0(); return s; } public String nextLine(boolean ignoreEmptyLines) { if (ignoreEmptyLines) { return nextLine(); } else { return readLine0(); } } public BigInteger nextBigInteger() { try { return new BigInteger(nextString()); } catch (NumberFormatException e) { throw new InputMismatchException(); } } public char nextCharacter() { int c = read(); while (isSpaceChar(c)) c = read(); return (char) c; } public double nextDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') { return res * Math.pow(10, nextInt()); } if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') { return res * Math.pow(10, nextInt()); } if (c < '0' || c > '9') { throw new InputMismatchException(); } m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public boolean isExhausted() { int value; while (isSpaceChar(value = peek()) && value != -1) read(); return value == -1; } public String next() { return nextString(); } public SpaceCharFilter getFilter() { return filter; } public void setFilter(SpaceCharFilter filter) { this.filter = filter; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) writer.print(' '); writer.print(objects[i]); } } public void printLine(Object... objects) { print(objects); writer.println(); } public void close() { writer.close(); } public void flush() { writer.flush(); } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
82340ba846c20a60c12fb901a138574b
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.util.*; public class D { public Object solve() { int N = sc.nextInt(), M = sc.nextInt(); long [] R = sc.nextLongs(), C = sc.nextLongs(); long [][] res = new long [N][M]; for (int b : rep(50)) { int [] r = new int [N], c = new int[M]; for (int i : rep(N)) r[i] = has(R[i], b) ? 1 : 0; for (int j : rep(M)) c[j] = has(C[j], b) ? 1 : 0; int [][] q = solve(r, c); if (q == null) exit("NO"); for (int i : rep(N)) for (int j : rep(M)) res[i][j] += q[i][j] * bit(b); } print("YES"); for (int i : rep(N)) print(res[i]); return null; } int [][] solve(int [] R, int [] C) { int N = R.length, M = C.length; int X = 0, Y = 0; for (int i : rep(N)) X ^= R[i]; for (int j : rep(M)) Y ^= C[j]; if (X != Y) return null; int [][] res = new int [N][M]; for (int i : rep(1, N)) res[i][0] = R[i]; for (int j : rep(1, M)) res[0][j] = C[j]; int Z = 0; for (int i : rep(N)) for (int j : rep(M)) Z ^= res[i][j]; if (Z != X) res[0][0] = 1; return res; } private static final boolean ONE_TEST_CASE = true; private static void init() { } private static long and (long x, int i) { return (x & bit(i)); } private static long bit (int i) { return (1L << i); } private static boolean has (long x, int i) { return and(x, i) != 0; } private static Iterable<Integer> rep (int N) { return rep(0, N); } private static Iterable<Integer> rep (final int S, final int T) { return new Iterable<Integer>() { public Iterator<Integer> iterator() { return S < T ? java.util.stream.IntStream.range(S, T).iterator() : Collections.emptyIterator(); } }; } //////////////////////////////////////////////////////////////////////////////////// private static IOUtils.MyScanner sc = new IOUtils.MyScanner(); private static Object print (Object o, Object ... A) { IOUtils.print(o, A); return null; } private static Object exit (Object o, Object ... A) { print(o, A); IOUtils.exit(); return null; } private static class IOUtils { public static class MyScanner { public String next() { newLine(); return line[index++]; } public int nextInt() { return Integer.parseInt(next()); } public String nextLine() { line = null; return readLine(); } public String [] nextStrings() { return split(nextLine()); } public long[] nextLongs() { return nextStream().mapToLong(Long::parseLong).toArray(); } ////////////////////////////////////////////// private boolean eol() { return index == line.length; } private String readLine() { try { return r.readLine(); } catch (Exception e) { throw new Error (e); } } private final java.io.BufferedReader r; private MyScanner () { this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in))); } private MyScanner (java.io.BufferedReader r) { try { this.r = r; while (!r.ready()) Thread.sleep(1); start(); } catch (Exception e) { throw new Error(e); } } private String [] line; private int index; private void newLine() { if (line == null || eol()) { line = split(readLine()); index = 0; } } private java.util.stream.Stream<String> nextStream() { return java.util.Arrays.stream(nextStrings()); } private String [] split(String s) { return s.length() > 0 ? s.split(" ") : new String [0]; } } private static String build(Object o, Object ... A) { return buildDelim(" ", o, A); } private static String buildDelim(String delim, Object o, Object ... A) { StringBuilder b = new StringBuilder(); append(b, o, delim); for (Object p : A) append(b, p, delim); return b.substring(delim.length()); } ////////////////////////////////////////////////////////////////////////////////// private static void start() { if (t == 0) t = millis(); } private static void append(java.util.function.Consumer<Object> f, java.util.function.Consumer<Object> g, final Object o) { if (o.getClass().isArray()) { int len = java.lang.reflect.Array.getLength(o); for (int i = 0; i < len; ++i) f.accept(java.lang.reflect.Array.get(o, i)); } else if (o instanceof Iterable<?>) ((Iterable<?>)o).forEach(f::accept); else g.accept(o instanceof Double ? new java.text.DecimalFormat("#.#########").format(o) : o); } private static void append(final StringBuilder b, Object o, final String delim) { append(x -> { append(b, x, delim); }, x -> b.append(delim).append(x), o); } private static java.io.PrintWriter pw = new java.io.PrintWriter(System.out); private static Object print(Object o, Object ... A) { pw.println(build(o, A)); return null; } private static void err(Object o, Object ... A) { System.err.println(build(o, A)); } private static boolean PRINT; private static void write(Object o) { err(o, '(', time(), ')'); if (PRINT) pw.println(o); } private static void exit() { IOUtils.pw.close(); System.out.flush(); err("------------------"); err(time()); System.exit(0); } private static long t; private static long millis() { return System.currentTimeMillis(); } private static String time() { return "Time: " + (millis() - t) / 1000.0; } private static void run(int N) { try { PRINT = System.getProperties().containsKey("PRINT"); } catch (Throwable t) {} for (int n = 1; n <= N; ++n) { Object res = new D().solve(); if (res != null) write("Case #" + n + ": " + build(res)); } exit(); } } public static void main(String[] args) { init(); int N = ONE_TEST_CASE ? 1 : sc.nextInt(); IOUtils.run(N); } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
0e20a752cada3cfa3496c68803de0f98
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.io.*; import java.util.*; public class problemB { public static void main(String[] args) throws IOException{ // TODO Auto-generated method stub BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()); int m = Integer.parseInt(st.nextToken()); int [][] ans = new int[n][m]; int []arr = new int[n]; int [] brr = new int[m]; st = new StringTokenizer(br.readLine()); for(int i= 0;i<n;i++){ arr[i] = Integer.parseInt(st.nextToken()); } st = new StringTokenizer(br.readLine()); for(int i = 0;i<m;i++){ brr[i] = Integer.parseInt(st.nextToken()); } int a = brr[m-1]; for(int i = 0;i+1<n;i++){ a^=arr[i]; ans[i][m-1] = arr[i]; } int b = arr[n-1]; for(int i = 0;i+1<m;i++){ b^=brr[i]; ans[n-1][i] = brr[i]; } if(a!=b){ System.out.println("NO"); return; } else{ System.out.println("YES"); ans[n-1][m-1] = a; for(int i = 0;i<n;i++){ for(int j= 0;j<m;j++){ System.out.print(ans[i][j] + " "); } System.out.println(); } } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
d16eced79b024ceaf9eae30ad5858e26
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.util.*; import java.io.*; import java.io.FileWriter; // Solution public class Main { public static void main (String[] argv) { new Main(); } boolean test = false; final int[][] dirs8 = {{0,1}, {0,-1}, {-1,0}, {1,0}, {1,1},{1,-1},{-1,1},{-1,-1}}; final int MOD = 998244353;//1000000007; int n_bit = 1; int[] bit; public Main() { FastReader in = new FastReader(new BufferedReader(new InputStreamReader(System.in))); //FastReader in = new FastReader(new BufferedReader(new FileReader("Main.in"))); //int nt = in.nextInt(); int nt = 1; StringBuilder sb = new StringBuilder(); for (int it = 0; it < nt; it++) { int n = in.nextInt(); int m = in.nextInt(); int[] rsum = new int[n]; int[] csum = new int[m]; for (int i = 0; i < n; i++) rsum[i] = in.nextInt(); for (int i = 0; i < m; i++) csum[i] = in.nextInt(); int zero = 0; for (int v : rsum) zero ^= v; for (int v : csum) zero ^= v; if (zero != 0) System.out.println("NO"); else { System.out.println("YES"); int[][] a = new int[n][m]; List<Integer> rones = new ArrayList<>(); List<Integer> cones = new ArrayList<>(); for (int digit = 0; digit < 32; digit ++) { int mask = 1 << digit; rones.clear(); cones.clear(); for (int i = 0; i < n; i++) { if ((rsum[i] & mask) != 0) { rones.add(i); } } for (int i = 0; i < m; i++) { if ((csum[i] & mask) != 0) { cones.add(i); } } if (rones.size() <= cones.size()) { int sz = rones.size(); for (int i = 0; i < sz; i++){ a[rones.get(i)][cones.get(i)] |= mask; } for (int i = sz; i < cones.size(); i++) a[0][cones.get(i)] |= mask; }else { int sz = cones.size(); for (int i = 0; i < sz; i++){ a[rones.get(i)][cones.get(i)] |= mask; } for (int i = sz; i < rones.size(); i++) a[rones.get(i)][0] |= mask; } } for (int i = 0 ; i < n; i++){ for (int j = 0; j < m; j++){ sb.append(a[i][j] + " "); } sb.append("\n"); } System.out.print(sb); /* int[] myr = new int[n]; int[] myc = new int[m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { myr[i] ^= a[i][j]; myc[j] ^= a[i][j]; } } System.out.println("my row sum : "); for (int i = 0 ; i < n; i++){ System.out.print(myr[i] + " "); } System.out.println(); System.out.println("my col sum : "); for (int i = 0 ; i < m; i++){ System.out.print(myc[i] + " "); } System.out.println(); */ } //System.out.print(sb); } //System.out.print(sb); } private int[] build_z_function(String s) { int n = s.length(); int[] zfun = new int[n]; int l = -1, r = -1; for (int i = 1; i < n; i++) { // Set the start value if (i <= r) zfun[i] = Math.min(zfun[i-l], r - i + 1); while (i + zfun[i] < n && s.charAt(i + zfun[i]) == s.charAt(zfun[i])) zfun[i]++; if (i + zfun[i] - 1> r){ l = i; r = i + zfun[i] - 1; } } if (test) { System.out.println("Z-function of " + s); for (int i = 0; i < n; i++) System.out.print(zfun[i] + " "); System.out.println(); } return zfun; } private int query(int p) { int sum = 0; for (; p > 0; p -= (p & (-p))) { sum += bit[p]; } return sum; } private void add(int p, int val) { //System.out.println("add to BIT " + p); for (; p <= n_bit; p += (p & (-p))) { bit[p] += val; } } private List<Integer> getMinFactor(int sum) { List<Integer> factors = new ArrayList<>(); for (int sz = 2; sz <= sum / sz; sz++){ if (sum % sz == 0) { factors.add(sz); factors.add(sum / sz); } } if (factors.size() == 0) factors.add(sum); return factors; } /* Tree class */ class Tree { int V = 0; int root = 0; List<Integer>[] nbs; int[][] timeRange; int[] subTreeSize; int t; boolean dump = false; public Tree(int V, int root) { if (dump) System.out.println("build tree with size = " + V + ", root = " + root); this.V = V; this.root = root; nbs = new List[V]; subTreeSize = new int[V]; for (int i = 0; i < V; i++) nbs[i] = new ArrayList<>(); } public void doneInput() { dfsEuler(); } public void addEdge(int p, int q) { nbs[p].add(q); nbs[q].add(p); } private void dfsEuler() { timeRange = new int[V][2]; t = 1; dfs(root); } private void dfs(int node) { if (dump) System.out.println("dfs on node " + node + ", at time " + t); timeRange[node][0] = t; for (int next : nbs[node]) { if (timeRange[next][0] == 0) { ++t; dfs(next); } } timeRange[node][1] = t; subTreeSize[node] = t - timeRange[node][0] + 1; } public List<Integer> getNeighbors(int p) { return nbs[p]; } public int[] getSubTreeSize(){ return subTreeSize; } public int[][] getTimeRange() { if (dump){ for (int i = 0; i < V; i++){ System.out.println(i + ": " + timeRange[i][0] + " - " + timeRange[i][1]); } } return timeRange; } } /* segment tree */ class SegTree { long[] tree; long[] lazy; int n; boolean dump = false; public SegTree(int n) { if (dump) System.out.println("create segTree with size " + n); this.n = n; tree = new long[n*4]; lazy = new long[n*4]; } public SegTree(int n, int[] a) { this(n); buildTree(1, 0, n-1, a); } private void buildTree(int node, int lo, int hi, int[] a) { if (lo == hi) { tree[node] = a[lo]; return; } int m = (lo + hi) / 2; buildTree(node * 2, lo, m, a); buildTree(node * 2 + 1, m + 1, hi, a); pushUp(node, lo, hi); } private void pushUp(int node, int lo, int hi) { if (lo >= hi) return; // add combine fcn } private void pushDown(int node, int lo, int hi) { if (lo > hi || lazy[node] == 0) return; tree[node] += lazy[node]; tree[node] %= MOD; if (lo < hi) { lazy[node * 2] += lazy[node]; lazy[node * 2 + 1] += lazy[node]; lazy[node * 2] %= MOD; lazy[node * 2 + 1] %= MOD; } lazy[node] = 0; } public void rangeUpdate(int fr, int to, long val) { if (dump) System.out.println("rangeUpdate : " + fr + " - " + to + " delta = " + val); rangeUpdate(1, 0, n-1, fr, to, val); } public long pointQuery(int p) { return pointQuery(1, 0, n-1, p); } private void rangeUpdate(int node, int lo, int hi, int fr, int to, long val) { if (dump) System.out.println("rangeUpdate : " + node + "[" + lo + " - " + hi + "]" + fr + " - " + to + " delta = " + val); pushDown(node, lo, hi); if (lo == fr && hi == to) { lazy[node] = val; return; } int m = (lo + hi) / 2; if (to <= m) rangeUpdate(node * 2 , lo, m, fr, to, val); else if (fr > m) rangeUpdate(node * 2 + 1, m + 1, hi, fr, to, val); else { rangeUpdate(node * 2, lo, m, fr, m, val); rangeUpdate(node * 2 + 1, m + 1, hi, m + 1, to, val); } pushUp(node, lo, hi); } /* pre-condition: lo <= p <= hi */ private long pointQuery(int node, int lo, int hi, int p) { pushDown(node, lo, hi); if (lo == hi) { return tree[node]; } int m = (lo + hi) / 2; if (p <= m) return pointQuery(node * 2, lo, m, p); else return pointQuery(node * 2 + 1, m + 1, hi, p); } } private long inv(long v) { return pow(v, MOD-2); } private long pow(long v, int p) { long ans = 1; while (p > 0) { if (p % 2 == 1) ans = ans * v % MOD; v = v * v % MOD; p = p / 2; } return ans; } private double dist(double x, double y, double xx, double yy) { return Math.sqrt((xx - x) * (xx - x) + (yy - y) * (yy - y)); } private int mod_add(int a, int b) { int v = a + b; if (v >= MOD) v -= MOD; return v; } private long overlap(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) { if (x1 > x3) return overlap(x3, y3, x4, y4, x1, y1, x2, y2); if (x3 > x2 || y4 < y1 || y3 > y2) return 0L; //(x3, ?, x2, ?) int yL = Math.max(y1, y3); int yH = Math.min(y2, y4); int xH = Math.min(x2, x4); return f(x3, yL, xH, yH); } //return #black cells in rectangle private long f(int x1, int y1, int x2, int y2) { long dx = 1L + x2 - x1; long dy = 1L + y2 - y1; if (dx % 2 == 0 || dy % 2 == 0 || (x1 + y1) % 2 == 0) return 1L * dx * dy / 2; return 1L * dx * dy / 2 + 1; } private int distM(int x, int y, int xx, int yy) { return abs(x - xx) + abs(y - yy); } private boolean less(int x, int y, int xx, int yy) { return x < xx || y > yy; } private int mul(int x, int y) { return (int)(1L * x * y % MOD); } private int nBit1(int v) { int v0 = v; int c = 0; while (v != 0) { ++c; v = v & (v - 1); } return c; } private long abs(long v) { return v > 0 ? v : -v; } private int abs(int v) { return v > 0 ? v : -v; } private int common(int v) { int c = 0; while (v != 1) { v = (v >>> 1); ++c; } return c; } private void reverse(char[] a, int i, int j) { while (i < j) { swap(a, i++, j--); } } private void swap(char[] a, int i, int j) { char t = a[i]; a[i] = a[j]; a[j] = t; } private int gcd(int x, int y) { if (y == 0) return x; return gcd(y, x % y); } private long gcd(long x, long y) { if (y == 0) return x; return gcd(y, x % y); } private int max(int a, int b) { return a > b ? a : b; } private long max(long a, long b) { return a > b ? a : b; } private int min(int a, int b) { return a > b ? b : a; } private long min(long a, long b) { return a > b ? b : a; } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader(BufferedReader in) { br = in; } String next() { while (st == null || !st.hasMoreElements()) { try { String line = br.readLine(); if (line == null || line.length() == 0) return ""; st = new StringTokenizer(line); } catch (IOException e) { return ""; //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) { return null; //e.printStackTrace(); } return str; } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
562448231629167ebe0c98afb191e191
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.util.*; import java.io.*; public class A { public static void main(String[] args) { FastScanner fs=new FastScanner(); int height=fs.nextInt(); int width=fs.nextInt(); int[] rowXors=fs.readArray(height); int[] colXors=fs.readArray(width); int[][] matrix=new int[width][height]; for (int i=0; i<height; i++) matrix[0][i]=rowXors[i]; for (int x=0; x<width; x++) { int total=0; for (int y=0; y<height; y++) total^=matrix[x][y]; int stillNeed=(total^colXors[x]); matrix[x][0]^=stillNeed; if (x==width-1&&stillNeed!=0) { System.out.println("NO"); return; } else { if (stillNeed!=0) matrix[x+1][0]^=stillNeed; } } System.out.println("YES"); for (int y=0; y<height; y++) { for (int x=0; x<width; x++) System.out.print(matrix[x][y]+" "); System.out.println(); } } private static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long[] readLongArray(int n) { long[] a=new long[n]; for (int i=0; i<n; i++) a[i]=nextLong(); return a; } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
dd61bcfbb89fe222ae6d51c41f2ec9f1
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.util.*; import java.io.*; public class Matrix { static int N, M, K; static String s; static StringTokenizer st; static int[] d; public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); st = new StringTokenizer(br.readLine()); int N = Integer.parseInt(st.nextToken()); int M = Integer.parseInt(st.nextToken()); int[] a = new int[N]; int[] b = new int[M]; int ax = 0; int bx = 0; st = new StringTokenizer(br.readLine()); for (int i = 0; i < N; i++) { a[i] = Integer.parseInt(st.nextToken()); ax ^= a[i]; } st = new StringTokenizer(br.readLine()); for (int i = 0; i < M; i++) { b[i] = Integer.parseInt(st.nextToken()); bx ^= b[i]; } if(ax == bx){ System.out.println("YES"); int[][] d = new int[N][M]; int cur = 0; for (int i = 1; i < N; i++) { d[i][0] = a[i]; cur ^= a[i]; } d[0][0] = cur ^ b[0]; cur = d[0][0]; for (int i = 1; i < M-1; i++) { d[0][i] = b[i]; cur ^= b[i]; } d[0][M-1] = cur ^ a[0]; d[1][M-1] = b[M-1] ^ d[0][M-1]; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { out.print(d[i][j]); out.print(" "); } out.println(); } }else{ System.out.println("NO"); } out.close(); } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
05119bb3aae7fa0e03dc5a0b3e4b97a8
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.util.*; import java.io.*; public class CF { static InputReader in; static PrintWriter out; public static void main(String[] args) { in = new InputReader(System.in); out = new PrintWriter(System.out); int n = in.nextInt(); int m = in.nextInt(); int[] a = new int[n]; int[] b = new int[m]; int[][] arr = new int[n][m]; int xor = 0; for(int i = 0; i < n; i++) { a[i] = in.nextInt(); xor ^= a[i]; } for(int i = 0; i < m; i++) { b[i] = in.nextInt(); xor ^= b[i]; } if(xor == 0){ out.println("YES"); for(int i = 0; i < n - 1; i++) { xor = 0; for(int j = 0; j < m - 1; j++) { arr[i][j] = a[i] ^ b[j]; xor ^= arr[i][j]; } arr[i][m - 1] = xor ^ a[i]; } for(int j = 0; j < m; j++) { xor = 0; for(int i = 0; i < n - 1; i++) { xor ^= arr[i][j]; } arr[n - 1][j] = xor ^ b[j]; } for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++) out.print(arr[i][j] + " "); out.println(); } } else out.println("NO"); out.close(); } static class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int snext() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } public long[] nextLongArray(int n) { long a[] = new long[n]; for (int i = 0; i < n; i++) { a[i] = nextLong(); } return a; } public String readString() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = snext(); while (isSpaceChar(c)) c = snext(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isEndOfLine(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
fff4ca11a3fb51e69cb60af2c4da44de
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.io.*; import java.math.BigInteger; import java.util.*; public class Main implements Runnable { int maxn = (int)1e2+111; int n,m,k; int a[][] = new int[maxn][maxn]; int row[] = new int[maxn]; int col[] = new int[maxn]; void solve() throws Exception { n = in.nextInt(); m = in.nextInt(); for (int i=1; i<=n; i++) { row[i] = in.nextInt(); a[i][m] = row[i]; } for (int i=1; i<=m; i++) { col[i] = in.nextInt(); a[n][i] = col[i]; } for (int i=1; i<=n-1; i++) { for (int j=1; j<=m-1; j++) { a[i][j] = 0; } } a[n][m] = 0; int lastCol = 0; for (int i=1; i<=n-1; i++) { lastCol ^= a[i][m]; } int lastRow = 0; for (int i=1; i<=m-1; i++) { lastRow ^= a[n][i]; } int left = lastRow^row[n]; a[n][m] = left; int right = lastCol^a[n][m]; if (right==col[m]) { out.println("YES"); for (int i=1; i<=n; i++) { for (int j=1; j<=m; j++) { out.print(a[i][j] + " "); } out.println(); } } else { out.println("NO"); } } /* 2 2 1000000000 1000000000 1000000000 1000000000 */ class Pair { int x, y; public Pair(int x, int y) { this.x = x; this.y = y; } } String fileInName = ""; boolean file = false; boolean isAcmp = false; static Throwable throwable; public static void main (String [] args) throws Throwable { Thread thread = new Thread(null, new Main(), "", (1 << 26)); thread.start(); thread.join(); thread.run(); if (throwable != null) throw throwable; } FastReader in; PrintWriter out; public void run() { String fileIn = "absum.in"; String fileOut = "absum.out"; try { if (isAcmp) { if (file) { in = new FastReader(new BufferedReader(new FileReader(fileIn))); out = new PrintWriter (fileOut); } else { in = new FastReader(new BufferedReader(new InputStreamReader(System.in))); out = new PrintWriter(System.out); } } else if (file) { in = new FastReader(new BufferedReader(new FileReader(fileInName+".in"))); out = new PrintWriter (fileInName + ".out"); } else { in = new FastReader(new BufferedReader(new InputStreamReader(System.in))); out = new PrintWriter(System.out); } solve(); } catch(Exception e) { throwable = e; } finally { out.close(); } } } class FastReader { BufferedReader bf; StringTokenizer tk = null; public FastReader(BufferedReader bf) { this.bf = bf; } public String nextToken () throws Exception { if (tk==null || !tk.hasMoreTokens()) { tk = new StringTokenizer(bf.readLine()); } if (!tk.hasMoreTokens()) return nextToken(); else return tk.nextToken(); } public int nextInt() throws Exception { return Integer.parseInt(nextToken()); } public long nextLong() throws Exception { return Long.parseLong(nextToken()); } public double nextDouble() throws Exception { return Double.parseDouble(nextToken()); } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
a3a8c3f55e60ae2cc4a951542ac1cb24
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.io.BufferedInputStream; import java.util.Scanner; /** * */ public class VasyaAndTheMatrix { public static void main(String[] args) { Scanner in = new Scanner(new BufferedInputStream(System.in)); while (in.hasNext()) { int n = in.nextInt(); int m = in.nextInt(); int[] a = new int[n]; int[] b = new int[m]; int aXor = 0; int bXor = 0; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); aXor ^= a[i]; } for (int i = 0; i < m; i++) { b[i] = in.nextInt(); bXor ^= b[i]; } if (aXor != bXor) { System.out.println("NO"); } else { System.out.println("YES"); for (int i = 0; i < n - 1; i++) { StringBuilder sb = new StringBuilder(); for (int j = 0; j < m; j++) { if (j < m - 1) { sb.append(0).append(' '); } else { sb.append(a[i]); } } System.out.println(sb); } StringBuilder sb = new StringBuilder(); for (int j = 0; j < m; j++) { if (j < m - 1) { sb.append(b[j]).append(' '); } else { sb.append(aXor ^ b[m - 1] ^ a[n - 1]); } } System.out.println(sb); } } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
92eb1f6bdf7d05ce4c8d12bef2c14a5f
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
//package contese_476; import java.util.*; public class q1 { int m=(int)1e9+7; public class Node { int a; int b; public void Node(int a,int b) { this.a=a; this.b=b; } } public int mul(int a ,int b) { a=a%m; b=b%m; return((a*b)%m); } public int pow(int a,int b) { int x=1; while(b>0) { if(b%2!=0) x=mul(x,a); a=mul(a,a); b=b/2; } return x; } public static long gcd(long a,long b) { if(b==0) return a; else return gcd(b,a%b); } public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); int[][] f=new int[n][m]; int[] a=new int[n]; int[] b=new int[m]; int x1=0,x2=0; for(int i=0;i<n;i++) { a[i]=sc.nextInt(); x1=x1^a[i]; } for(int i=0;i<m;i++) b[i]=sc.nextInt(); for(int i=m-1;i>=1;i--) { x2=x2^b[i]; } if(x1!=(x2^b[0])) { System.out.print("NO"); } else { System.out.println("YES"); f[0][0]=a[0]^x2; for(int i=1;i<m;i++) { f[0][i]=b[i]; } for(int i=1;i<n;i++) { f[i][0]=a[i]; } for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { System.out.print(f[i][j]+" "); } System.out.print('\n'); } } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
021b5e4079402d44c12cced9e929b397
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
//package que_b; import java.io.*; import java.util.*; import java.math.*; public class utkarsh { InputStream is; PrintWriter out; long mod = (long) (1e9 + 7); boolean SHOW_TIME; void solve() { //Enter code here utkarsh //SHOW_TIME = true; int n = ni(), m = ni(); int a[] = na(n); int b[] = na(m); int dp[][] = new int[n][m]; int x = 0, y = 0; for(int i = 1; i < n; i++) { dp[i][0] = a[i]; x ^= a[i]; } for(int j = 1; j < m; j++) { dp[0][j] = b[j]; y ^= b[j]; } y ^= a[0]; x ^= b[0]; if(x == y) { dp[0][0] = x; out.println("YES"); for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) out.print(dp[i][j] + " "); out.println(); } } else out.println("NO"); } //---------- I/O Template ---------- public static void main(String[] args) { new utkarsh().run(); } void run() { is = System.in; out = new PrintWriter(System.out); long start = System.currentTimeMillis(); solve(); long end = System.currentTimeMillis(); if(SHOW_TIME) out.println("\n" + (end - start) + " ms"); out.flush(); } byte input[] = new byte[1024]; int len = 0, ptr = 0; int readByte() { if(ptr >= len) { ptr = 0; try { len = is.read(input); } catch(IOException e) { throw new InputMismatchException(); } if(len <= 0) { return -1; } } return input[ptr++]; } boolean isSpaceChar(int c) { return !( c >= 33 && c <= 126 ); } int skip() { int b = readByte(); while(b != -1 && isSpaceChar(b)) { b = readByte(); } return b; } char nc() { return (char)skip(); } String ns() { int b = skip(); StringBuilder sb = new StringBuilder(); while(!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } String nLine() { int b = skip(); StringBuilder sb = new StringBuilder(); while( !(isSpaceChar(b) && b != ' ') ) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } int ni() { int n = 0, b = readByte(); boolean minus = false; while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); } if(b == '-') { minus = true; b = readByte(); } if(b == -1) { return -1; } //no input while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); } return minus ? -n : n; } long nl() { long n = 0L; int b = readByte(); boolean minus = false; while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); } if(b == '-') { minus = true; b = readByte(); } while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); } return minus ? -n : n; } double nd() { return Double.parseDouble(ns()); } float nf() { return Float.parseFloat(ns()); } int[] na(int n) { int a[] = new int[n]; for(int i = 0; i < n; i++) { a[i] = ni(); } return a; } char[] ns(int n) { char c[] = new char[n]; int i, b = skip(); for(i = 0; i < n; i++) { if(isSpaceChar(b)) { break; } c[i] = (char)b; b = readByte(); } return i == n ? c : Arrays.copyOf(c,i); } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
9502094638acb9558f507551c6f9933b
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.util.Scanner; public class Main { private static boolean check(int n , int m) { long value = 0; for (int i = 0;i < n;i ++) { value ^= row[i]; } for (int i = 0;i < m;i ++) { value ^= col[i]; } return value == 0; } private static long[] row = new long[200]; private static long[] col = new long[200]; private static long[][] ans = new long[200][200]; public static void main(String[] args) throws Exception { Scanner scan = new Scanner(System.in); int i , j , n = scan.nextInt() , m = scan.nextInt(); for (i = 0;i < n;i ++) { row[i] = scan.nextLong(); } for (i = 0;i < m;i ++) { col[i] = scan.nextLong(); } if (check(n , m)) { long temp = 0; for (i = 0;i < n - 1;i ++) { ans[i][0] = row[i]; temp ^= row[i]; } ans[n - 1][0] = temp ^ col[0]; for (j = 1;j < m;j ++) { ans[n - 1][j] = col[j]; } System.out.println("YES"); for (i = 0;i < n;i ++) { for (j = 0;j < m;j ++) { if (j > 0) { System.out.print(" "); } System.out.print(ans[i][j]); } System.out.println(); } } else { System.out.println("NO"); } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
d5896503a2dec4bfdf2f71b7e71b4344
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; MyScan in = new MyScan(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskD solver = new TaskD(); solver.solve(1, in, out); out.close(); } static class TaskD { public void solve(int testNumber, MyScan in, PrintWriter out) { int n = in.nextInt(); int m = in.nextInt(); int[] xn = in.na(n); int[] xm = in.na(m); int[][] ans = new int[n][m]; int xor1 = 0; for (int l = 0; l < n - 1; l++) { ans[l][m - 1] = xn[l]; xor1 ^= xn[l]; } int xor2 = 0; for (int l = 0; l < m - 1; l++) { ans[n - 1][l] = xm[l]; xor2 ^= xm[l]; } ans[n - 1][m - 1] = xor1 ^ xm[m - 1]; int f1 = xor1 ^ xm[m - 1]; int f2 = xor2 ^ xn[n - 1]; if (f1 != f2) { out.println("NO"); return; } out.println("YES"); for (int i = 0; i < n; i++) { for (int s : ans[i]) { out.print(s + " "); } out.println(); } } } static class MyScan { private final InputStream in; private byte[] inbuf = new byte[1024]; public int lenbuf = 0; public int ptrbuf = 0; public MyScan(InputStream in) { this.in = in; } private int readByte() { if (lenbuf == -1) throw new InputMismatchException(); if (ptrbuf >= lenbuf) { ptrbuf = 0; try { lenbuf = in.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if (lenbuf <= 0) return -1; } return inbuf[ptrbuf++]; } public int[] na(int n) { int[] k = new int[n]; for (int i = 0; i < n; i++) { k[i] = nextInt(); } return k; } 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 * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
b413f64c02f1e2a5dd62adf4e6b562e9
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.io.*; import java.util.*; public class CF1016D { static int[] aa, bb, ii, jj; static int[][] cc; static void solve(int n, int m, int k) { int n1 = 0, m1 = 0; for (int i = 0; i < n; i++) if ((aa[i] & 1 << k) != 0) ii[n1++] = i; for (int j = 0; j < m; j++) if ((bb[j] & 1 << k) != 0) jj[m1++] = j; while (n1 > 0 || m1 > 0) { int i = n1 == 0 ? 0 : ii[n1 - 1]; int j = m1 == 0 ? 0 : jj[m1 - 1]; cc[i][j] |= 1 << k; if (n1 > m1) n1--; else if (n1 < m1) m1--; else { n1--; m1--; } } } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()); int m = Integer.parseInt(st.nextToken()); st = new StringTokenizer(br.readLine()); aa = new int[n]; int a = 0; for (int i = 0; i < n; i++) a ^= aa[i] = Integer.parseInt(st.nextToken()); st = new StringTokenizer(br.readLine()); bb = new int[m]; int b = 0; for (int j = 0; j < m; j++) b ^= bb[j] = Integer.parseInt(st.nextToken()); if (a != b) { System.out.println("NO"); return; } ii = new int[n]; jj = new int[m]; cc = new int[n][m]; for (int k = 0; k < 30; k++) solve(n, m, k); PrintWriter pw = new PrintWriter(System.out); pw.println("YES"); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) pw.print(cc[i][j] + " "); pw.println(); } pw.close(); } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
6979104a1ab0a113eb84f6092140818c
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.util.*; /** * * @author user */ public class JavaApplication8 { public static void main(String[] args) { Scanner in = new Scanner(System.in) ; int n = in.nextInt() ; int m = in.nextInt() ; int[] a = new int[n] ; int[] b = new int[m] ; for(int i=0;i<n;i++){ a[i] = in.nextInt() ; } for(int i=0;i<m;i++){ b[i] = in.nextInt() ; } int xor1 =0, xor2 = 0 ; for(int i=0;i<n-1;i++){ xor1 ^= a[i] ; } xor1 ^= b[m-1] ; for(int i=0;i<m-1;i++){ xor2 ^= b[i] ; } xor2 ^= a[n-1] ; if(xor1 != xor2){ System.out.println("NO") ; }else{ System.out.println("YES") ; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ if(i == n-1 && j == m-1){ System.out.print(xor1) ; }else if(i== n-1){ System.out.print(b[j]+" "); }else if(j==m-1){ System.out.print(a[i]+" "); }else{ System.out.print(0+" "); } } System.out.println(); } } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
fc4105ab70cdd5c6af47be343e2a3bd0
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.ArrayDeque; public class D { static int R,C; static long xR[], xC[]; static long b[][]; public static void main(String[] args) { JS in = new JS();// PrintWriter out = new PrintWriter(System.out); R = in.nextInt(); C = in.nextInt(); xR = new long[R]; xC = new long[C]; for(int i = 0; i < R; i++) xR[i] = in.nextLong(); for(int i = 0; i < C; i++) xC[i] = in.nextLong(); b = new long[R][C]; boolean good = true; for(int bit = 0; bit <= 30; bit++) { int eR = 0; int oR = 0; int eC = 0; int oC = 0; for(int i = 0; i < R; i++) { if( (xR[i]&(1L<<bit)) > 0 ) oR++; else eR++; } for(int i = 0; i < C; i++) { if( (xC[i]&(1L<<bit)) > 0 ) oC++; else eC++; } if(oR%2 != oC%2) { good = false; break; } boolean usedR[] = new boolean[R]; boolean usedC[] = new boolean[C]; //Match all odds to other odds for(int r = 0; r < R; r++) { if((xR[r]&(1L<<bit)) == 0)continue; for(int c = 0; c < C; c++) { if(usedR[r] || usedC[c])continue; if((xC[c]&(1L<<bit)) == 0)continue; usedR[r]=true; usedC[c]=true; oR--; oC--; xR[r] -= (1L<<bit); xC[c] -= (1L<<bit); b[r][c] += (1L<<bit); } } if(oR == 0 && oC == 0) continue; else { if(oR > 0) { //go through columns and match even to oR ArrayDeque<Integer> oddRows = new ArrayDeque<Integer>(); for(int r = 0; r < R; r++) { if(usedR[r])continue; if((xR[r] & (1L<<bit)) > 0) oddRows.add(r); } for(int c = 0; c < C; c++) { if((xC[c]&(1L<<bit)) == 0) { //if even int r1 = oddRows.poll(); int r2 = oddRows.poll(); b[r1][c]+=(1L<<bit); b[r2][c]+=(1L<<bit); c--; if(oddRows.isEmpty())break; } } } else { //go through rows and match even to oR ArrayDeque<Integer> oddCols = new ArrayDeque<Integer>(); for(int c = 0; c < C; c++) { if(usedC[c])continue; if((xC[c] & (1L<<bit)) > 0) oddCols.add(c); } for(int r = 0; r < R; r++) { if((xR[r]&(1L<<bit)) == 0) { //if even int c1 = oddCols.poll(); int c2 = oddCols.poll(); b[r][c1]+=(1L<<bit); b[r][c2]+=(1L<<bit); r--; if(oddCols.isEmpty())break; } } } } } if(good) { out.println("YES"); for(int i = 0; i < R; i++) { for(int j = 0; j < C; j++) { out.print(b[i][j]+" "); }out.println(); } } else { out.println("NO"); } out.close(); } static class JS{ public int BS = 1<<16; public char NC = (char)0; byte[] buf = new byte[BS]; int bId = 0, size = 0; char c = NC; double num = 1; BufferedInputStream in; public JS() { in = new BufferedInputStream(System.in, BS); } public JS(String s) throws FileNotFoundException { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } public char nextChar(){ while(bId==size) { try { size = in.read(buf); }catch(Exception e) { return NC; } if(size==-1)return NC; bId=0; } return (char)buf[bId++]; } public int nextInt() { return (int)nextLong(); } public long nextLong() { num=1; boolean neg = false; if(c==NC)c=nextChar(); for(;(c<'0' || c>'9'); c = nextChar()) { if(c=='-')neg=true; } long res = 0; for(; c>='0' && c <='9'; c=nextChar()) { res = (res<<3)+(res<<1)+c-'0'; num*=10; } return neg?-res:res; } public double nextDouble() { while(c!='.'&&c!='-'&&(c <'0' || c>'9')) c = nextChar(); boolean neg = c=='-'; if(neg)c=nextChar(); boolean fl = c=='.'; double cur = nextLong(); if(fl) return neg ? -cur/num : cur/num; if(c == '.') { double next = nextLong(); return neg ? -cur-next/num : cur+next/num; } else return neg ? -cur : cur; } public String next() { StringBuilder res = new StringBuilder(); while(c<=32)c=nextChar(); while(c>32) { res.append(c); c=nextChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while(c<=32)c=nextChar(); while(c!='\n') { res.append(c); c=nextChar(); } return res.toString(); } public boolean hasNext() { if(c>32)return true; while(true) { c=nextChar(); if(c==NC)return false; else if(c>32)return true; } } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
407f72e104bed97412ebc369b3d35802
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author SNEHITH */ import java.util.*; public class problem_D { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int z=0,zz=0,temp=0; int row[] = new int[n]; int column[] = new int[m]; int res[][] = new int[n][m]; for(int i=0;i<n;i++){ row[i] = sc.nextInt(); z = z^row[i]; } for(int i=0;i<m;i++){ column[i] = sc.nextInt(); zz = zz^column[i]; } if(z != zz) System.out.println("NO"); else{ System.out.println("YES"); for(int i=0;i<m-1;i++) res[n-1][i] = column[i]; for(int i=0;i<n-1;i++) res[i][m-1] = row[i]; for(int i=0;i<m-1;i++) temp = temp^column[i]; res[n-1][m-1] = temp^row[n-1]; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ System.out.print(" "+res[i][j]); } System.out.println(); } } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
df924b4986c622516e08029abe4f03d8
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
//package math_codet; import java.io.*; import java.util.*; import java.math.*; /****************************************** * AUTHOR: AMAN KUMAR SINGH * * INSTITUITION: KALYANI GOVERNMENT ENGINEERING COLLEGE * ******************************************/ public class lets_do { InputReader in; PrintWriter out; Helper_class h; final long mod=1000000007; final int N=200005; int MAX_Ai=100005; public static void main(String[] args) throws java.lang.Exception{ new lets_do().run(); } void run() throws Exception{ in=new InputReader(System.in); out = new PrintWriter(System.out); h = new Helper_class(); int t=1; while(t-->0){ solve(); } out.flush(); out.close(); } void solve(){ int n=h.ni(); int m=h.ni(); int[] row=new int[n]; int[] column=new int[m]; int i=0,j=0; int xor1=0; int xor2=0; for(i=0;i<n;i++){ row[i]=h.ni(); xor1^=row[i]; } for(i=0;i<m;i++){ column[i]=h.ni(); xor2^=column[i]; } if(xor1==xor2){ h.pn("YES"); for(i=0;i<n-1;i++){ for(j=0;j<m-1;j++) h.p(0+" "); h.p(row[i]); h.pn(""); } xor2^=row[n-1]; xor2^=column[m-1]; for(i=0;i<m-1;i++) h.p(column[i]+" "); h.p(xor2); } else h.pn("NO"); } final Comparator<Entity> com=new Comparator<Entity>(){ public int compare(Entity x, Entity y){ int xx=Integer.compare(y.a,x.a); if(xx==0) return Integer.compare(x.a,y.a); else return xx; } }; class Entity{ int a; int b; Entity(int p, int q){ a=p; b=q; } } class Helper_class{ long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);} int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);} long gcd1(long a, long b){return (b==0)?a:gcd(b,a%b);} int bitcount(long n){return (n==0)?0:(1+bitcount(n&(n-1)));} void p(Object o){out.print(o);} void pn(Object o){out.println(o);} void pni(Object o){out.println(o);out.flush();} String n(){return in.next();} String nln(){return in.nextLine();} int ni(){return in.nextInt();} long nl(){return in.nextLong();} double nd(){return in.nextDouble();} long mul(long a,long b){ if(a>=mod)a%=mod; if(b>=mod)b%=mod; a*=b; if(a>=mod)a%=mod; return a; } long modPow(long a, long p){ long o = 1; while(p>0){ if((p&1)==1)o = mul(o,a); a = mul(a,a); p>>=1; } return o; } long add(long a, long b){ if(a>=mod)a%=mod; if(b>=mod)b%=mod; if(b<0)b+=mod; a+=b; if(a>=mod)a-=mod; return a; } } class InputReader{ private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new UnknownError(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new UnknownError(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int peek() { if (numChars == -1) return -1; if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { return -1; } if (numChars <= 0) return -1; } return buf[curChar]; } public void skip(int x) { while (x-- > 0) read(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public String nextString() { return next(); } public String next() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuffer res = new StringBuffer(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { StringBuffer buf = new StringBuffer(); int c = read(); while (c != '\n' && c != -1) { if (c != '\r') buf.appendCodePoint(c); c = read(); } return buf.toString(); } public double nextDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public boolean hasNext() { int value; while (isSpaceChar(value = peek()) && value != -1) read(); return value != -1; } private boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
8ded0a2a749b36072af8688a0cceec74
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.io.*; import java.util.*; public class CF1016_D { public static void main(String[] args)throws Throwable { MyScanner sc=new MyScanner(); PrintWriter pw=new PrintWriter(System.out); int n=sc.nextInt(); int m=sc.nextInt(); int [] a=new int [n]; int [] b=new int [m]; int x1=0; for(int i=0;i<n;i++){ a[i]=sc.nextInt(); x1^=a[i]; } int x2=0; for(int i=0;i<m;i++){ b[i]=sc.nextInt(); x2^=b[i]; } if(x1!=x2) pw.println("NO"); else{ pw.println("YES"); int [][] mat=new int [n][m]; for(int i=1;i<n;i++) mat[i][0]=a[i]; for(int j=1;j<m;j++) mat[0][j]=b[j]; mat[0][0]=a[0]^b[0]^x1; for(int i=0;i<n;i++){ for(int j=0;j<m;j++) pw.print(mat[i][j]+" "); pw.println(); } } pw.flush(); pw.close(); } 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
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
b7d481fb03aa8a4939afe87eeddd35d7
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.FilterInputStream; import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.File; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Atharva Nagarkar */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; JoltyScanner in = new JoltyScanner(inputStream); PrintWriter out = new PrintWriter(outputStream); DVasyaAndTheMatrix solver = new DVasyaAndTheMatrix(); solver.solve(1, in, out); out.close(); } static class DVasyaAndTheMatrix { public void solve(int testNumber, JoltyScanner in, PrintWriter out) { int n = in.nextInt(), m = in.nextInt(); int[] rows = new int[n]; int[] cols = new int[m]; for (int i = 0; i < n; ++i) rows[i] = in.nextInt(); for (int i = 0; i < m; ++i) cols[i] = in.nextInt(); int[][] grid = new int[n][m]; int[] xorRow = new int[n]; int[] xorCol = new int[m]; grid[0][0] = xorCol[0] = xorRow[0] = Math.max((Integer.highestOneBit(cols[0]) << 1) - 1, 0); boolean possible = true; for (int r = 0; possible && r < n; ++r) { for (int c = 0; possible && c < m; ++c) { if (r == 0 && c == 0) continue; int rowRemain = rows[r] ^ xorRow[r]; int colRemain = cols[c] ^ xorCol[c]; if (r == n - 1 && c == m - 1 && rowRemain != colRemain) { possible = false; continue; } if (c == m - 1) { grid[r][c] = rowRemain; xorRow[r] ^= rowRemain; xorCol[c] ^= rowRemain; } else { grid[r][c] = colRemain; xorRow[r] ^= colRemain; xorCol[c] ^= colRemain; } } } for (int r = 0; r < n; ++r) if (rows[r] != xorRow[r]) possible = false; for (int c = 0; c < m; ++c) if (cols[c] != xorCol[c]) possible = false; if (!possible) { out.println("NO"); return; } out.println("YES"); for (int r = 0; r < n; ++r) { for (int c = 0; c < m; ++c) { out.print(grid[r][c] + " "); } out.println(); } } } static class JoltyScanner { public int BS = 1 << 16; public char NC = (char) 0; public byte[] buf = new byte[BS]; public int bId = 0; public int size = 0; public char c = NC; public double num = 1; public BufferedInputStream in; public JoltyScanner(InputStream is) { in = new BufferedInputStream(is, BS); } public JoltyScanner(String s) throws FileNotFoundException { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } public char nextChar() { while (bId == size) { try { size = in.read(buf); } catch (Exception e) { return NC; } if (size == -1) return NC; bId = 0; } return (char) buf[bId++]; } public int nextInt() { return (int) nextLong(); } public long nextLong() { num = 1; boolean neg = false; if (c == NC) c = nextChar(); for (; (c < '0' || c > '9'); c = nextChar()) { if (c == '-') neg = true; } long res = 0; for (; c >= '0' && c <= '9'; c = nextChar()) { res = (res << 3) + (res << 1) + c - '0'; num *= 10; } return neg ? -res : res; } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
89f7c92fd8fdfa6d70e9ce62576bd188
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.util.Scanner; public class Codeforces { public static void main(String[] args) { Scanner in = new Scanner(System.in); int[] x = new int[111], y = new int[111]; int[][] a = new int[111][111]; int n = in.nextInt(), m = in.nextInt(); int all = 0; for (int i = 1; i <= n; i++) { x[i] = in.nextInt(); all ^= x[i]; } for (int i = 1; i <= m; i++) { y[i] = in.nextInt(); all ^= y[i]; } if (all != 0) { System.out.println("NO"); return; } System.out.println("YES"); for (int j = 2; j <= m; j++) { a[1][j] = y[j]; } for (int i = 2; i <= n; i++) { a[i][1] = x[i]; } all = x[1]; for (int j = 2; j <= m; j++) { all ^= y[j]; } a[1][1] = all; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { System.out.print(a[i][j] + " "); } System.out.println(); } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
a848a4dad89ddacf641cdc9df8430d0c
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.util.*; import java.io.*; public class Main implements Runnable{ FastScanner sc; PrintWriter pw; final class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); st = new StringTokenizer(br.readLine()); } catch (Exception e) { e.printStackTrace(); } } public long nlo() { return Long.parseLong(next()); } public String next() { if (st.hasMoreTokens()) return st.nextToken(); try { st = new StringTokenizer(br.readLine()); } catch (Exception e) { e.printStackTrace(); } return st.nextToken(); } public int ni() { return Integer.parseInt(next()); } public String nli() { String line = ""; if (st.hasMoreTokens()) line = st.nextToken(); else try { return br.readLine(); } catch (IOException e) { e.printStackTrace(); } while (st.hasMoreTokens()) line += " " + st.nextToken(); return line; } public double nd() { return Double.parseDouble(next()); } } public static void main(String[] args) throws Exception { new Thread(null,new Main(),"codeforces",1<<28).start(); } public void run() { sc=new FastScanner(); pw=new PrintWriter(System.out); solve(); pw.flush(); pw.close(); } public long gcd(long a,long b) { return b==0L?a:gcd(b,a%b); } public long ppow(long a,long b,long mod) { if(b==0L) return 1L; long tmp=1; while(b>1L) { if((b&1L)==1) tmp*=a; a*=a; a%=mod; tmp%=mod; b>>=1; } return (tmp*a)%mod; } public int gcd(int x,int y) { return y==0?x:gcd(y,x%y); } ////////////////////////////////// ///////////// LOGIC /////////// //////////////////////////////// ArrayList<Long> list; ArrayList<Integer>[] adj; int[] visit; public void solve() { int n=sc.ni(); int m=sc.ni(); int[] arr=new int[n]; int[] brr=new int[m]; int x=0,y=0; for(int i=0;i<n;i++) x^=arr[i]=sc.ni(); for(int i=0;i<m;i++) y^=brr[i]=sc.ni(); if(x!=y) { pw.println("NO"); return; } pw.println("YES"); for(int i=1;i<n;i++) brr[0]^=arr[i]; pw.print(brr[0]+" "); for(int j=1;j<m;j++) pw.print(brr[j]+" "); pw.println(""); for(int i=1;i<n;i++) { pw.print(arr[i]+" "); for(int j=1;j<m;j++) pw.print(0+" "); pw.println(""); } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
8cd1c6a665e76290347377c51c44e7bb
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.io.*; import java.util.*; public class Main { FastReader scn; PrintWriter out; String INPUT = ""; void solve() { int n = scn.nextInt(), m = scn.nextInt(); int[] row = new int[n], col = new int[m]; int x1 = 0, x2 = 0; for(int i = 0; i < n; i++) { x1 ^= row[i] = scn.nextInt(); } for(int i = 0; i < m; i++) { x2 ^= col[i] = scn.nextInt(); } if(x1 != x2) { out.println("NO"); return; } out.println("YES"); for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { int x = 0; if(j == 0) { if(i != n - 1) { x = row[i]; } else { x = row[n - 1] ^ x1 ^ col[0]; } } else if(i == n - 1 && j != 0) { x = col[j]; } out.print(x + " "); } out.println(); } } void run() throws Exception { long time = System.currentTimeMillis(); boolean oj = System.getProperty("ONLINE_JUDGE") != null; out = new PrintWriter(System.out); scn = new FastReader(oj); solve(); out.flush(); if (!oj) { System.out.println(Arrays.deepToString(new Object[] { System.currentTimeMillis() - time + " ms" })); } } public static void main(String[] args) throws Exception { new Main().run(); } class FastReader { InputStream is; public FastReader(boolean onlineJudge) { is = onlineJudge ? System.in : new ByteArrayInputStream(INPUT.getBytes()); } byte[] inbuf = new byte[1024]; public int lenbuf = 0, ptrbuf = 0; 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++]; } boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } int skip() { int b; while ((b = readByte()) != -1 && isSpaceChar(b)) ; return b; } double nextDouble() { return Double.parseDouble(next()); } char nextChar() { return (char) skip(); } String next() { int b = skip(); StringBuilder sb = new StringBuilder(); while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } 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); } 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 * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } 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 * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } char[][] nextMatrix(int n, int m) { char[][] map = new char[n][]; for (int i = 0; i < n; i++) map[i] = next(m); return map; } int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long[] nextLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } int[][] next2DInt(int n, int m) { int[][] arr = new int[n][]; for (int i = 0; i < n; i++) { arr[i] = nextIntArray(m); } return arr; } long[][] next2DLong(int n, int m) { long[][] arr = new long[n][]; for (int i = 0; i < n; i++) { arr[i] = nextLongArray(m); } return arr; } int[] shuffle(int[] arr) { Random r = new Random(); for (int i = 1, j; i < arr.length; i++) { j = r.nextInt(i); arr[i] = arr[i] ^ arr[j]; arr[j] = arr[i] ^ arr[j]; arr[i] = arr[i] ^ arr[j]; } return arr; } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
24891958c6def1602704b67a78dfe1d5
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; public class d{ static void solve(){ int n = ni(), m=ni(); int[] a = nia(n); int[] b = nia(m); int x = 0; for(int i=0;i<n;++i)x^=a[i]; int y = 0; for(int i=0;i<m;++i)y^=b[i]; if(x==y){ out.println("YES"); int p=a[n-1]; for(int i=0;i<m-1;++i)p^=b[i]; for(int i=0;i<n;++i)for(int j=0;j<m;++j){ if(i==n-1&&j==m-1)out.println(p); else if(i==n-1)out.print(b[j]+(j==m-1 ? "\n":" ")); else if(j==m-1)out.println(a[i]); else out.print(0+" "); } return; } out.println("NO"); } public static void main(String[] args){ solve(); out.flush(); } private static InputStream in = System.in; private static PrintWriter out = new PrintWriter(System.out); private static final byte[] buffer = new byte[1<<15]; private static int ptr = 0; private static int buflen = 0; private static boolean hasNextByte(){ if(ptr<buflen)return true; ptr = 0; try{ buflen = in.read(buffer); } catch (IOException e){ e.printStackTrace(); } return buflen>0; } private static int readByte(){ if(hasNextByte()) return buffer[ptr++]; else return -1;} private static boolean isSpaceChar(int c){ return !(33<=c && c<=126);} private static int skip(){int res; while((res=readByte())!=-1 && isSpaceChar(res)); return res;} private static double nd(){ return Double.parseDouble(ns()); } private static char nc(){ return (char)skip(); } private static String ns(){ StringBuilder sb = new StringBuilder(); for(int b=skip();!isSpaceChar(b);b=readByte())sb.append((char)b); return sb.toString(); } private static int[] nia(int n){ int[] res = new int[n]; for(int i=0;i<n;++i)res[i]=ni(); return res; } private static long[] nla(int n){ long[] res = new long[n]; for(int i=0;i<n;++i)res[i]=nl(); return res; } private static int ni(){ int res=0,b; boolean minus=false; while((b=readByte())!=-1 && !((b>='0'&&b<='9') || b=='-')); if(b=='-'){ minus=true; b=readByte(); } for(;'0'<=b&&b<='9';b=readByte())res=res*10+(b-'0'); return minus ? -res:res; } private static long nl(){ long res=0,b; boolean minus=false; while((b=readByte())!=-1 && !((b>='0'&&b<='9') || b=='-')); if(b=='-'){ minus=true; b=readByte(); } for(;'0'<=b&&b<='9';b=readByte())res=res*10+(b-'0'); return minus ? -res:res; } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
15268f528f5137fa3346c88be0b4d5b9
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; public class d{ static void solve(){ int n = ni(), m=ni(); int[] a = nia(n); int[] b = nia(m); int x = 0; for(int i=0;i<n;++i)x^=a[i]; int y = 0; for(int i=0;i<m;++i)y^=b[i]; if(x==y){ out.println("YES"); int p=a[n-1]; for(int i=0;i<m-1;++i)p^=b[i]; for(int i=0;i<n;++i)for(int j=0;j<m;++j){ if(i==n-1&&j==m-1)out.println(p); else if(i==n-1)out.print(b[j]+(j==m-1 ? "\n":" ")); else if(j==m-1)out.println(a[i]); else out.print(0+" "); } return; } for(int i=0;i<n;++i){ for(int j=0;j<m;++j){ if((x^b[j])==a[i]&&(y^a[i])==b[j]){ out.println("YES"); for(int ii=0;ii<n;++ii){ for(int jj=0;jj<m;++jj){ if(ii==i && jj==j){ out.print(a[ii]+" "); }else if(ii==i){ out.print(b[jj]+" "); }else if(jj==j){ out.print(a[ii]+" "); }else{ out.print(0+" "); } } out.println(); } return; } } } out.println("NO"); } public static void main(String[] args){ solve(); out.flush(); } private static InputStream in = System.in; private static PrintWriter out = new PrintWriter(System.out); private static final byte[] buffer = new byte[1<<15]; private static int ptr = 0; private static int buflen = 0; private static boolean hasNextByte(){ if(ptr<buflen)return true; ptr = 0; try{ buflen = in.read(buffer); } catch (IOException e){ e.printStackTrace(); } return buflen>0; } private static int readByte(){ if(hasNextByte()) return buffer[ptr++]; else return -1;} private static boolean isSpaceChar(int c){ return !(33<=c && c<=126);} private static int skip(){int res; while((res=readByte())!=-1 && isSpaceChar(res)); return res;} private static double nd(){ return Double.parseDouble(ns()); } private static char nc(){ return (char)skip(); } private static String ns(){ StringBuilder sb = new StringBuilder(); for(int b=skip();!isSpaceChar(b);b=readByte())sb.append((char)b); return sb.toString(); } private static int[] nia(int n){ int[] res = new int[n]; for(int i=0;i<n;++i)res[i]=ni(); return res; } private static long[] nla(int n){ long[] res = new long[n]; for(int i=0;i<n;++i)res[i]=nl(); return res; } private static int ni(){ int res=0,b; boolean minus=false; while((b=readByte())!=-1 && !((b>='0'&&b<='9') || b=='-')); if(b=='-'){ minus=true; b=readByte(); } for(;'0'<=b&&b<='9';b=readByte())res=res*10+(b-'0'); return minus ? -res:res; } private static long nl(){ long res=0,b; boolean minus=false; while((b=readByte())!=-1 && !((b>='0'&&b<='9') || b=='-')); if(b=='-'){ minus=true; b=readByte(); } for(;'0'<=b&&b<='9';b=readByte())res=res*10+(b-'0'); return minus ? -res:res; } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
4dd0f8d7524aa90d77327a5476a887c5
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.util.*; import java.lang.*; public class Solution { static Scanner in = new Scanner(System.in); public static void main(String []args){ int m = in.nextInt(); int n = in.nextInt(); int a[] = new int[m]; int b[] = new int[n]; int xm = 0, xn = 0; for(int i = 0; i < m; i++){ a[i] = in.nextInt(); xm ^= a[i]; } for(int i = 0; i < n; i++){ b[i] = in.nextInt(); xn ^= b[i]; } if(xm != xn) System.out.println("NO"); else{ System.out.println("YES"); for(int i = 0; i < m-1; i++){ for(int j = 0; j < n-1; j++){ System.out.print(0 + " "); } System.out.print(a[i] + "\n"); } for(int i = 0; i < n-1; i++){ System.out.print(b[i] + " "); } System.out.println(xn^a[m-1]^b[n-1]); } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
8b44df8d88f56ea7f21f50a917eea8c3
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.io.*; import java.lang.reflect.Array; import java.math.BigInteger; import java.util.*; import java.util.Random; import java.util.StringTokenizer; public class Main { final long b = 31; String fileName = ""; ////////////////////// SOLUTION SOLUTION SOLUTION ////////////////////////////// int INF = Integer.MAX_VALUE/10; long MODULO = 1000_1000_100l; int MAX_VALUE = 1000_1000; long sum = 0; void solve() throws IOException { int n = readInt(); int m = readInt(); int[] a = readIntArray(n); int[] b = readIntArray(m); int[][] ans = new int[n][m]; HashSet<Integer> used = new HashSet<>(); ArrayDeque<Integer> one = new ArrayDeque<>(); ArrayDeque<Integer> zero = new ArrayDeque<>(); for (int bit=31; bit>=0; --bit){ int countCol = 0; int countRow = 0; for (int i=0; i<n; ++i){ if (((a[i]>>bit)&1) == 1){ countRow++; } } for (int i=0; i<m; ++i){ if (((b[i]>>bit)&1) == 1) { countCol++; } } if (countCol <= countRow){ for (int i=0; i<m; ++i){ if (((b[i]>>bit)&1) == 1) { one.add(i); } else zero.add(i); } for (int i=0; i<n; ++i){ if (((a[i]>>bit)&1) == 1){ if (one.size() > 0){ int cur = one.poll(); ans[i][cur] += 1<<bit; zero.add(cur); }else{ int cur = zero.poll(); ans[i][cur] += 1<<bit; one.add(cur); } } } if (one.size() > 0){ out.println("NO"); return; } }else{ for (int i=0; i<n; ++i){ if (((a[i]>>bit)&1) == 1) { one.add(i); } else zero.add(i); } for (int i=0; i<m; ++i){ if (((b[i]>>bit)&1) == 1){ if (one.size() > 0){ int cur = one.poll(); ans[cur][i] += 1<<bit; zero.add(cur); }else{ int cur = zero.poll(); ans[cur][i] += 1<<bit; one.add(cur); } } } if (one.size() > 0){ out.println("NO"); return; } } one.clear(); zero.clear(); } out.println("YES"); for (int i=0; i<n; ++i){ for (int j=0; j<m; ++j){ out.print(ans[i][j] +" "); } out.println(); } } class Star{ int x, y, len; Star(int x, int y, int len){ this.x = x; this.len = len; this.y = y; } } class Number implements Comparable<Number>{ int x, cost; Number(int x, int cost){ this.x = x; this.cost = cost; } @Override public int compareTo(Number o) { return Integer.compare(this.cost, o.cost); } } class Point{ int x, y; Point(int x, int y){ this.x = x; this.y = y; } } class Vertex implements Comparable<Vertex>{ int num, depth, e, c; Vertex(int num, int depth, int e, int c){ this.num = num; this.e = e; this.depth = depth; this.c = c; } @Override public int compareTo(Vertex o) { return Integer.compare(this.e, o.e); } } /////////////////////////////////////////////////////////////////////////////////////////// class Edge{ int from, to, num; Edge(int to, int num){ this.to = to; this.num = num; } } class SparseTable{ int[][] rmq; int[] logTable; int n; SparseTable(int[] a){ n = a.length; logTable = new int[n+1]; for(int i = 2; i <= n; ++i){ logTable[i] = logTable[i >> 1] + 1; } rmq = new int[logTable[n] + 1][n]; for(int i=0; i<n; ++i){ rmq[0][i] = a[i]; } for(int k=1; (1 << k) < n; ++k){ for(int i=0; i + (1 << k) <= n; ++i){ int max1 = rmq[k - 1][i]; int max2 = rmq[k-1][i + (1 << (k-1))]; rmq[k][i] = Math.max(max1, max2); } } } int max(int l, int r){ int k = logTable[r - l]; int max1 = rmq[k][l]; int max2 = rmq[k][r - (1 << k) + 1]; return Math.max(max1, max2); } } long checkBit(long mask, int bit){ return (mask >> bit) & 1; } class Dsu{ int[] parent; int countSets; Dsu(int n){ countSets = n; parent = new int[n]; for(int i=0; i<n; ++i){ parent[i] = i; } } int findSet(int a){ if(parent[a] == a) return a; parent[a] = findSet(parent[a]); return parent[a]; } void unionSets(int a, int b){ a = findSet(a); b = findSet(b); if(a!=b){ countSets--; parent[a] = b; } } } static int checkBit(int mask, int bit) { return (mask >> bit) & 1; } boolean isLower(char c){ return c >= 'a' && c <= 'z'; } //////////////////////////////////////////////////////////// class SegmentTree{ int[] t; int n; SegmentTree(int n){ t = new int[4*n]; build(new int[n+1], 1, 1, n); } void build (int a[], int v, int tl, int tr) { if (tl == tr) t[v] = a[tl]; else { int tm = (tl + tr) / 2; build (a, v*2, tl, tm); build (a, v*2+1, tm+1, tr); } } void update (int v, int tl, int tr, int l, int r, int add) { if (l > r) return; if (l == tl && tr == r) t[v] += add; else { int tm = (tl + tr) / 2; update (v*2, tl, tm, l, Math.min(r,tm), add); update (v*2+1, tm+1, tr, Math.max(l,tm+1), r, add); } } int get (int v, int tl, int tr, int pos) { if (tl == tr) return t[v]; int tm = (tl + tr) / 2; if (pos <= tm) return t[v] + get (v*2, tl, tm, pos); else return t[v] + get (v*2+1, tm+1, tr, pos); } } class Fenwik { long[] t; int length; Fenwik(int[] a) { length = a.length + 100; t = new long[length]; for (int i = 0; i < a.length; ++i) { inc(i, a[i]); } } void inc(int ind, int delta) { for (; ind < length; ind = ind | (ind + 1)) { t[ind] = Math.max(delta, t[ind]); } } long getMax(int r) { long sum = 0; for (; r >= 0; r = (r & (r + 1)) - 1) { sum = Math.max(sum, t[r]); } return sum; } } int gcd(int a, int b){ return b == 0 ? a : gcd(b, a%b); } long gcd(long a, long b){ return b == 0 ? a : gcd(b, a%b); } double binPow(double a, int pow){ if (pow == 0) return 1; if (pow % 2 == 1) { return a * binPow(a, pow - 1); } else { double c = binPow(a, pow / 2); return c * c; } } long binPow(long a, long b, long m) { if (b == 0) { return 1; } if (b % 2 == 1) { return ((a % m) * (binPow(a, b - 1, m) % m)) % m; } else { long c = binPow(a, b / 2, m); return (c * c) % m; } } int minInt(int... values) { int min = Integer.MAX_VALUE; for (int value : values) min = Math.min(min, value); return min; } int maxInt(int... values) { int max = Integer.MIN_VALUE; for (int value : values) max = Math.max(max, value); return max; } public static void main(String[] args) throws NumberFormatException, IOException { // TODO Auto-generated method stub new Main().run(); } void run() throws NumberFormatException, IOException { solve(); out.close(); }; BufferedReader in; PrintWriter out; StringTokenizer tok; String delim = " "; Random rnd = new Random(); Main() throws FileNotFoundException { try { in = new BufferedReader(new FileReader("input.txt")); out = new PrintWriter("output.txt"); } catch (Exception e) { if (fileName.isEmpty()) { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); } else { in = new BufferedReader(new FileReader(fileName + ".in")); out = new PrintWriter(fileName + ".out"); } } tok = new StringTokenizer(""); } String readLine() throws IOException { return in.readLine(); } String readString() throws IOException { while (!tok.hasMoreTokens()) { String nextLine = readLine(); if (null == nextLine) { return null; } tok = new StringTokenizer(nextLine); } return tok.nextToken(); } int readInt() throws NumberFormatException, IOException { return Integer.parseInt(readString()); } byte readByte() throws NumberFormatException, IOException { return Byte.parseByte(readString()); } int[] readIntArray (int n) throws NumberFormatException, IOException { int[] a = new int[n]; for(int i=0; i<n; ++i){ a[i] = readInt(); } return a; } Integer[] readIntegerArray (int n) throws NumberFormatException, IOException { Integer[] a = new Integer[n]; for(int i=0; i<n; ++i){ a[i] = readInt(); } return a; } long readLong() throws NumberFormatException, IOException { return Long.parseLong(readString()); } double readDouble() throws NumberFormatException, IOException { return Double.parseDouble(readString()); } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
dd1cd336a2567b5491dfce8a9fde1662
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskD solver = new TaskD(); solver.solve(1, in, out); out.close(); } static class TaskD { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); int m = in.nextInt(); int[] a = new int[n]; int aXor = 0; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); aXor ^= a[i]; } int[] b = new int[m]; int bXor = 0; for (int i = 0; i < m; i++) { b[i] = in.nextInt(); bXor ^= b[i]; } if (aXor == bXor) { out.println("YES"); int corner = a[0]; for (int i = 1; i < m; i++) { corner ^= b[i]; } out.print(corner); for (int i = 1; i < m; i++) { out.print(" " + b[i]); } out.println(); for (int i = 1; i < n; i++) { out.print(a[i]); for (int j = 1; j < m; j++) { out.print(" 0"); } out.println(); } } else { out.println("NO"); } } } static class InputReader { private BufferedReader reader; private StringTokenizer stt; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); } public String nextLine() { try { return reader.readLine(); } catch (IOException e) { return null; } } public String next() { while (stt == null || !stt.hasMoreTokens()) { stt = new StringTokenizer(nextLine()); } return stt.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
cef09da8fd6f61bd5fa57614085073e9
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; public class r48p4{ public static void main(String args[]) { InputReader sc = new InputReader(System.in); PrintWriter pw = new PrintWriter(System.out); int row = sc.nextInt(), col = sc.nextInt(); long a[] = new long[row], b[] = new long[col], xor = 0, grid[][] = new long[row][col]; for(int i=0; i<row; i++) { a[i] = sc.nextLong(); xor = xor^a[i]; } for(int i=0; i<col; i++) { b[i] = sc.nextLong(); xor = xor^b[i]; } if(xor != 0) pw.println("NO"); else { pw.println("YES"); for (int i = 0; i < row - 1; i++) grid[i][0] = a[i]; for (int i = 0; i < row - 1; i++) { for (int j = 1; j < col; j++) grid[i][j] = 0; } xor = a[row - 1]; for (int j = 1; j < col; j++) { grid[row - 1][j] = b[j]; xor = xor ^ b[j]; } grid[row - 1][0] = xor; for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) pw.print(grid[i][j] + " "); pw.println(); } } pw.flush(); pw.close(); } static class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; private SpaceCharFilter filter; InputReader(InputStream stream) { this.stream = stream; } int snext() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } int nextInt() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } long nextLong() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } String readString() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isSpaceChar(c)); return res.toString(); } String nextLine() { int c = snext(); while (isSpaceChar(c)) c = snext(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isEndOfLine(c)); return res.toString(); } boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } public interface SpaceCharFilter { boolean isSpaceChar(int ch); } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
70f23c60ab8186dcc137219936931e76
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.io.PrintWriter; import java.util.Arrays; import java.util.Scanner; public class Vasya_And_The_Matrix { public static void main(String[] args) { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int n=sc.nextInt(); int m=sc.nextInt(); int [] a=new int [n]; int [] rows = new int[n]; int [] b=new int [m]; int col[]= new int[m]; int ans [] [] = new int[n][m]; int x1 = 0 ; for(int i=0;i<n;i++){ a[i]=sc.nextInt(); x1^=a[i]; } int x2=0; for(int i=0;i<m;i++){ b[i]=sc.nextInt(); x2^=b[i]; } if(x1!=x2) pw.println("NO"); else{ pw.println("YES"); for(int i=0;i<n-1;i++){ ans[i][0]=a[i]; } for(int i=0;i<m;i++){ ans[n-1][i]=b[i]; } ans[n-1][0]=x1^a[n-1]^b[0]; for(int i=0;i<n;i++){ for(int j=0;j<m;j++) pw.print(ans[i][j]+" "); pw.print("\n"); } } pw.close(); } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
6438a26b4b1a5257331beea5b459d07a
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.io.*; import java.util.*; public class Main { private static class Solver { private void Solve() { int n = inp.nextInt(); int m = inp.nextInt(); int[] a = inp.nextIntArray(n); int[] b = inp.nextIntArray(m); int[][] ans = new int[n][m]; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { ans[i][j] = 0; } } for (int bit = 0; bit < 30; ++bit) { int[] ta = new int[n]; int[] tb = new int[m]; int sa = 0; int sb = 0; for (int i = 0; i < n; ++i) { ta[i] = a[i] >> bit & 1; sa += ta[i]; } for (int i = 0; i < m; ++i) { tb[i] = b[i] >> bit & 1; sb += tb[i]; } if (sa % 2 != sb % 2) { out.println("NO"); return; } for (int i = 0; i < n; ++i) { if (ta[i] == 0) { continue; } for (int j = 0; j < m; ++j) { if (tb[j] == 0) { continue; } ans[i][j] |= 1 << bit; tb[j] = 0; ta[i] = 0; break; } } int f = -1; for (int i = 0; i < n; ++i) { if (ta[i] > 0) { f = 0; break; } } for (int i = 0; i < m; ++i) { if (tb[i] > 0) { if (f == 0) { out.println("WUT"); } f = 1; break; } } if (f == 0) { for (int i = 0; i < n; ++i) { if (ta[i] == 0) { continue; } ans[i][0] |= 1 << bit; } } else if (f == 1) { for (int i = 0; i < m; ++i) { if (tb[i] == 0) { continue; } ans[0][i] |= 1 << bit; } } } out.println("YES"); for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { out.print(ans[i][j] + " "); } out.println(""); } } static InputReader inp; static PrintWriter out; } private static class InputReader { private BufferedReader reader; private StringTokenizer tokenizer; private InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } private String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } private int nextInt() { return Integer.parseInt(next()); } private long nextLong() { return Long.parseLong(next()); } private int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; ++i) { a[i] = nextInt(); } return a; } } public static void main(String[] args) throws IOException { if (!"true".equals(System.getProperty("ONLINE_JUDGE"))) { System.setIn(new FileInputStream(new File("input.txt"))); } InputStream inputStream = System.in; OutputStream outputStream = System.out; Solver.inp = new InputReader(inputStream); Solver.out = new PrintWriter(outputStream); Solver solver = new Solver(); solver.Solve(); Solver.out.close(); } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
c6ea475a080dbaa853d718eb54ea55e8
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.util.*; import java.io.*; public class D1016{ public static void main(String args[])throws IOException{ Scanner sc=new Scanner(new BufferedReader(new InputStreamReader(System.in))); PrintWriter pw=new PrintWriter(System.out); int n=sc.nextInt(); int m=sc.nextInt(); int row[]=new int[n]; int xor=0; for(int i=0;i<n;i++){ row[i]=sc.nextInt(); xor^=row[i]; } int col[]=new int[m]; for(int i=0;i<m;i++){ col[i]=sc.nextInt(); xor^=col[i]; } if(xor!=0){ pw.print("NO"); } else{ pw.println("YES"); xor=0; for(int i=0;i<n-1;i++){ xor^=row[i]; pw.print(row[i]+" "); for(int j=1;j<m-1;j++) pw.print(0+" "); pw.println(0); } col[0]^=xor; for(int i=0;i<m-1;i++) pw.print(col[i]+" "); pw.print(col[m-1]); } pw.close(); } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
674ace273f1af2652c15d55e6ce88aa1
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.charset.Charset; import java.util.Comparator; public class ECF48A { public static void main(String[] args) throws Exception { boolean local = System.getProperty("ONLINE_JUDGE") == null; boolean async = false; Charset charset = Charset.forName("ascii"); FastIO io = local ? new FastIO(new FileInputStream("E:\\DATABASE\\TESTCASE\\ECF48A.in"), System.out, charset) : new FastIO(System.in, System.out, charset); Task task = new Task(io); if (async) { Thread t = new Thread(null, task, "dalt", 1 << 27); t.setPriority(Thread.MAX_PRIORITY); t.start(); t.join(); } else { task.run(); } io.flush(); } public static class Task implements Runnable { final FastIO io; public Task(FastIO io) { this.io = io; } @Override public void run() { solve(); } public void solve() { int n = io.readInt(); int m = io.readInt(); int[][] mat = new int[n][m]; int[] row = new int[n]; int[] col = new int[m]; int xor = 0; for (int i = 0; i < n; i++) { row[i] = io.readInt(); xor ^= row[i]; } for (int j = 0; j < m; j++) { col[j] = io.readInt(); xor ^= col[j]; } if (xor != 0) { io.cache.append("NO"); return; } io.cache.append("YES\n"); int corner = 0; for (int i = 0, until = n - 1; i < until; i++) { mat[i][0] = row[i]; corner ^= row[i]; } corner ^= col[0]; for (int i = 1; i < m; i++) { mat[n - 1][i] = col[i]; } mat[n - 1][0] = corner; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { io.cache.append(mat[i][j]).append(' '); } io.cache.append('\n'); } } } public static class FastIO { private final InputStream is; private final OutputStream os; private final Charset charset; private StringBuilder defaultStringBuf = new StringBuilder(1 << 8); public final StringBuilder cache = new StringBuilder(); private byte[] buf = new byte[1 << 13]; private int bufLen; private int bufOffset; private int next; public FastIO(InputStream is, OutputStream os, Charset charset) { this.is = is; this.os = os; this.charset = charset; } private int read() { while (bufLen == bufOffset) { bufOffset = 0; try { bufLen = is.read(buf); } catch (IOException e) { throw new RuntimeException(e); } if (bufLen == -1) { return -1; } } return buf[bufOffset++]; } public void skipBlank() { while (next >= 0 && next <= 32) { next = read(); } } public int readInt() { int sign = 1; skipBlank(); if (next == '+' || next == '-') { sign = next == '+' ? 1 : -1; next = read(); } int val = 0; if (sign == 1) { while (next >= '0' && next <= '9') { val = val * 10 + next - '0'; next = read(); } } else { while (next >= '0' && next <= '9') { val = val * 10 - next + '0'; next = read(); } } return val; } public long readLong() { int sign = 1; skipBlank(); if (next == '+' || next == '-') { sign = next == '+' ? 1 : -1; next = read(); } long val = 0; if (sign == 1) { while (next >= '0' && next <= '9') { val = val * 10 + next - '0'; next = read(); } } else { while (next >= '0' && next <= '9') { val = val * 10 - next + '0'; next = read(); } } return val; } public double readDouble() { long num = readLong(); if (next != '.') { return num; } next = read(); long divisor = 1; long later = 0; while (next >= '0' && next <= '9') { divisor = divisor * 10; later = later * 10 + next - '0'; next = read(); } if (num >= 0) { return num + (later / (double) divisor); } else { return num - (later / (double) divisor); } } public String readString(StringBuilder builder) { skipBlank(); while (next > 32) { builder.append((char) next); next = read(); } return builder.toString(); } public String readString() { defaultStringBuf.setLength(0); return readString(defaultStringBuf); } public int readString(char[] data, int offset) { skipBlank(); int originalOffset = offset; while (next > 32) { data[offset++] = (char) next; next = read(); } return offset - originalOffset; } public int readString(byte[] data, int offset) { skipBlank(); int originalOffset = offset; while (next > 32) { data[offset++] = (byte) next; next = read(); } return offset - originalOffset; } public void flush() { try { os.write(cache.toString().getBytes(charset)); os.flush(); cache.setLength(0); } catch (IOException e) { throw new RuntimeException(e); } } public boolean hasMore() { skipBlank(); return next != -1; } } public static class Memory { public static <T> void swap(T[] data, int i, int j) { T tmp = data[i]; data[i] = data[j]; data[j] = tmp; } public static <T> int min(T[] data, int from, int to, Comparator<T> cmp) { int m = from; for (int i = from + 1; i < to; i++) { if (cmp.compare(data[m], data[i]) > 0) { m = i; } } return m; } public static <T> void move(T[] data, int from, int to, int step) { int len = to - from; step = len - (step % len + len) % len; Object[] buf = new Object[len]; for (int i = 0; i < len; i++) { buf[i] = data[(i + step) % len + from]; } System.arraycopy(buf, 0, data, from, len); } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
cba66e09fe9e9880c9389baccf02b216
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.io.*; import java.util.*; public class D { static long mod = (long)1e9+7; public static void main(String[] args) { FastScanner sc=new FastScanner(); int n = sc.nextInt(); int m = sc.nextInt(); int ar[] = sc.readArray(n); int br[] = sc.readArray(m); int xor = 0; for(int i : ar) xor^= i; for(int i : br) xor^=i; if(xor!=0) System.out.println("NO"); else { System.out.println("YES"); xor = ar[0]; for(int i = 1; i<m; i++) xor^=br[i]; System.out.print(xor+" "); for(int i = 1; i<m; i++) System.out.print(br[i]+" "); System.out.println(); for(int i = 1; i<n; i++) { System.out.print(ar[i]+" "); for(int j = 1; j<m; j++) System.out.print("0"+" "); System.out.println(); } } } static final Random random = new Random(); static void sort(int[] a) { int n = a.length; for(int i =0; i<n; i++) { int val = random.nextInt(n); int cur = a[i]; a[i] = a[val]; a[val] = cur; } Arrays.sort(a); } static void sortl(long[] a) { int n = a.length; for(int i =0; i<n; i++) { int val = random.nextInt(n); long cur = a[i]; a[i] = a[val]; a[val] = cur; } Arrays.sort(a); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (st == null || !st.hasMoreTokens()) { try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } 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()); } double nextDouble() { return Double.parseDouble(next()); } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
df0fb6b11e3260b5184bd9a43863fdbe
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Vadim Semenov */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskD solver = new TaskD(); solver.solve(1, in, out); out.close(); } static final class TaskD { public void solve(int __, InputReader in, PrintWriter out) { int rows = in.nextInt(); int cols = in.nextInt(); int[] row = in.nextIntArray(rows); int[] col = in.nextIntArray(cols); int rowXor = 0; for (int r : row) rowXor ^= r; int colXor = 0; for (int c : col) colXor ^= c; if (rowXor != colXor) { out.println("NO"); return; } out.println("YES"); int[][] matrix = new int[rows][cols]; for (int i = 1; i < rows; ++i) { matrix[i][0] = row[i]; } for (int j = 1; j < cols; ++j) { matrix[0][j] = col[j]; } matrix[0][0] = rowXor ^ col[0] ^ row[0]; assertRows(rows, cols, row, matrix); assertCols(rows, cols, col, matrix); for (int i = 0; i < rows; ++i) { for (int j = 0; j < cols; ++j) { out.print(matrix[i][j] + " "); } out.println(); } } private void assertCols(int rows, int cols, int[] col, int[][] matrix) { for (int j = 0; j < cols; ++j) { int xor = 0; for (int i = 0; i < rows; ++i) { xor ^= matrix[i][j]; } if (xor != col[j]) { throw new AssertionError(xor + " " + j); } } } private void assertRows(int rows, int cols, int[] row, int[][] matrix) { for (int i = 0; i < rows; ++i) { int xor = 0; for (int j = 0; j < cols; ++j) { xor ^= matrix[i][j]; } if (xor != row[i]) { throw new AssertionError(xor + " " + i); } } } } static class InputReader { private final BufferedReader reader; private StringTokenizer tokenizer; public InputReader(InputStream in) { reader = new BufferedReader(new InputStreamReader(in)); } public int[] nextIntArray(int size) { int[] array = new int[size]; for (int i = 0; i < size; ++i) { array[i] = nextInt(); } return array; } public int nextInt() { return Integer.parseInt(next()); } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(readLine()); } return tokenizer.nextToken(); } public String readLine() { String line; try { line = reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } return line; } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
a4a1ac6f7c104817e892712f1644e282
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.util.*; import java.io.*; public class A { public static void main(String[] args) { FastScanner fs=new FastScanner(); int height=fs.nextInt(); int width=fs.nextInt(); int[] rowXors=fs.readArray(height); int[] colXors=fs.readArray(width); int[][] matrix=new int[width][height]; for (int i=0; i<height; i++) matrix[0][i]=rowXors[i]; for (int x=0; x<width; x++) { int total=0; for (int y=0; y<height; y++) total^=matrix[x][y]; int stillNeed=(total^colXors[x]); matrix[x][0]^=stillNeed; if (x==width-1&&stillNeed!=0) { System.out.println("NO"); return; } else { if (stillNeed!=0) matrix[x+1][0]^=stillNeed; } } System.out.println("YES"); for (int y=0; y<height; y++) { for (int x=0; x<width; x++) System.out.print(matrix[x][y]+" "); System.out.println(); } } private static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long[] readLongArray(int n) { long[] a=new long[n]; for (int i=0; i<n; i++) a[i]=nextLong(); return a; } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
f548fdce74cd660f54db00d419683e09
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Random; import java.util.StringTokenizer; public class Main implements Runnable { int INF = (int) 1e9 + 7; static class Pair { long a; long b; public Pair(long a, long b) { this.a = a; this.b = b; } } private void solve() throws IOException { int n = nextInt(); int m = nextInt(); int a[] = new int[n]; int b[] = new int[m]; int xor = 0; for (int i = 0; i < n; ++i) { a[i] = nextInt(); xor ^= a[i]; } int tmp = xor; for (int i = 0; i < m; ++i) { b[i] = nextInt(); xor ^= b[i]; } if (xor != 0) { pw.println("NO"); return; } int ans[][] = new int[n][m]; for (int i = 1; i < n; ++i) { ans[i][0] = a[i]; } for (int i = 1; i < m; ++i) { ans[0][i] = b[i]; } tmp ^= a[0]; tmp ^= b[0]; ans[0][0] = tmp; pw.println("YES"); for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { pw.print(ans[i][j] + " "); } pw.println(); } // System.err.println(12 ^ 9); } void test() throws IOException { Random rnd = new Random(); for (int i = 0; i < 5; ++i) { int n = rnd.nextInt(5) + 1; int m = rnd.nextInt(5) + 1; System.err.println(n + " " + m); for (int j = 0; j < m; ++j) { int l = rnd.nextInt(n) + 1; int r = l + rnd.nextInt(n - l + 1); int q = rnd.nextInt(10); System.err.println(l + " " + r + " " + q); } // solve(n, a); System.err.println(); } } BufferedReader br; StringTokenizer st; PrintWriter pw; public static void main(String args[]) { new Main().run(); } public void run() { try { br = new BufferedReader(new InputStreamReader(System.in), 32768); pw = new PrintWriter(System.out); st = null; solve(); pw.flush(); pw.close(); br.close(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } } int nextInt() throws IOException { return Integer.parseInt(next()); } long nextLong() throws IOException { return Long.parseLong(next()); } double nextDouble() throws IOException { return Double.parseDouble(next()); } String next() throws IOException { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
5ffbbbe44dc8ac61a4cda8b10f300f76
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Random; import java.util.StringTokenizer; public class Main implements Runnable { int INF = (int) 1e9 + 7; static class Pair { long a; long b; public Pair(long a, long b) { this.a = a; this.b = b; } } private void solve() throws IOException { int n = nextInt(); int m = nextInt(); int a[] = new int[n]; int b[] = new int[m]; int xor = 0; for (int i = 0; i < n; ++i) { a[i] = nextInt(); xor ^= a[i]; } int tmp = xor; for (int i = 0; i < m; ++i) { b[i] = nextInt(); xor ^= b[i]; } if (xor != 0) { pw.println("NO"); return; } int ans[][] = new int[n][m]; for (int i = 1; i < n; ++i) { ans[i][0] = a[i]; } for (int i = 1; i < m; ++i) { ans[0][i] = b[i]; } tmp ^= a[0]; tmp ^= b[0]; ans[0][0] = tmp; pw.println("YES"); for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { pw.print(ans[i][j] + " "); } pw.println(); } System.err.println(12 ^ 9); } void test() throws IOException { Random rnd = new Random(); for (int i = 0; i < 5; ++i) { int n = rnd.nextInt(5) + 1; int m = rnd.nextInt(5) + 1; System.err.println(n + " " + m); for (int j = 0; j < m; ++j) { int l = rnd.nextInt(n) + 1; int r = l + rnd.nextInt(n - l + 1); int q = rnd.nextInt(10); System.err.println(l + " " + r + " " + q); } // solve(n, a); System.err.println(); } } BufferedReader br; StringTokenizer st; PrintWriter pw; public static void main(String args[]) { new Main().run(); } public void run() { try { br = new BufferedReader(new InputStreamReader(System.in), 32768); pw = new PrintWriter(System.out); st = null; solve(); pw.flush(); pw.close(); br.close(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } } int nextInt() throws IOException { return Integer.parseInt(next()); } long nextLong() throws IOException { return Long.parseLong(next()); } double nextDouble() throws IOException { return Double.parseDouble(next()); } String next() throws IOException { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
b7772e58b472acecd3baf3079742365a
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) { FastReader reader = new FastReader(); PrintWriter writer = new PrintWriter(System.out); int n = reader.nextInt(); int m = reader.nextInt(); long[] a = new long[n]; long[] b = new long[m]; long xor = 0; for (int i=0; i<n; i++) { a[i] = reader.nextLong(); xor ^= a[i]; } for (int j=0; j<m; j++) { b[j] = reader.nextLong(); xor ^= b[j]; } if (xor == 0) { long[][] mat = new long[n][m]; for (int i=0; i<n; i++) mat[i][0] = a[i]; for (int j=1; j<m; j++) { mat[n-1][0] ^= b[j]; mat[n-1][j] = b[j]; } writer.println("YES"); for (int i=0; i<n; i++) { for (int j=0; j<m; j++) writer.print(mat[i][j] + " "); writer.println(); } } else writer.println("NO"); writer.close(); } 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
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
cd7e9d9b3fdc11d676d2e2a63bae81df
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) { FastReader reader = new FastReader(); PrintWriter writer = new PrintWriter(System.out); //maybe int n = reader.nextInt(); int m = reader.nextInt(); long[] a = new long[n]; long[] b = new long[m]; long xor = 0; for (int i=0; i<n; i++) { a[i] = reader.nextLong(); xor ^= a[i]; } for (int j=0; j<m; j++) { b[j] = reader.nextLong(); xor ^= b[j]; } if (xor == 0) { long[][] mat = new long[n][m]; for (int i=0; i<n; i++) mat[i][0] = a[i]; for (int j=1; j<m; j++) { mat[n-1][0] ^= b[j]; mat[n-1][j] = b[j]; } writer.println("YES"); for (int i=0; i<n; i++) { for (int j=0; j<m; j++) writer.print(mat[i][j] + " "); writer.println(); } } else writer.println("NO"); writer.close(); } 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
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
c49393956e63ff48a0ee547e03365d24
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) { FastReader reader = new FastReader(); PrintWriter writer = new PrintWriter(System.out); //sample int n = reader.nextInt(); int m = reader.nextInt(); long[] a = new long[n]; long[] b = new long[m]; long xor = 0; for (int i=0; i<n; i++) { a[i] = reader.nextLong(); xor ^= a[i]; } for (int j=0; j<m; j++) { b[j] = reader.nextLong(); xor ^= b[j]; } if (xor == 0) { long[][] mat = new long[n][m]; for (int i=0; i<n; i++) mat[i][0] = a[i]; for (int j=1; j<m; j++) { mat[n-1][0] ^= b[j]; mat[n-1][j] = b[j]; } writer.println("YES"); for (int i=0; i<n; i++) { for (int j=0; j<m; j++) writer.print(mat[i][j] + " "); writer.println(); } } else writer.println("NO"); writer.close(); } 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
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
dfaf916bd763fa7cf63961852577c166
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.io.*; import java.util.Arrays; import java.util.BitSet; import java.util.Scanner; public class Main { static int N=1010; static int[][] map=new int[110][110]; static int[] a=new int[110]; static int[] b=new int[110]; static int n,m,k,q,tot,root; static StreamTokenizer in=new StreamTokenizer(new BufferedReader((new InputStreamReader(System.in)))); static int nextInt() throws IOException{ in.nextToken(); return (int)in.nval; } static String next() throws IOException{ in.nextToken(); return in.sval; } static PrintWriter out =new PrintWriter(new OutputStreamWriter(System.out)); public static void main(String args[])throws IOException{ n=nextInt(); m=nextInt(); for(int i=1;i<=n;i++){ a[i]=nextInt(); } for(int i=1;i<=m;i++){ b[i]=nextInt(); } int xa=0; int xb=0; for(int i=1;i<=n;i++){ xa=xa^a[i]; } for(int i=1;i<=m;i++){ xb=xb^b[i]; } if(xa!=xb){ out.println("NO"); out.flush(); } else{ out.println("YES"); out.flush(); map[1][1]=xa^a[1]^b[1]; for(int i=2;i<=n;i++){ map[i][1]=a[i]; } for(int i=2;i<=m;i++){ map[1][i]=b[i]; } for(int i=1;i<=n;i++){ for(int j=1;j<m;j++){ out.print(map[i][j]+" "); } out.println(map[i][m]); out.flush(); } } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
bf9dae07b3bab71caa6a5ca98cadf604
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
//package pack; import java.util.*; public class second { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); int[][] arr=new int[n][m]; int[] rowarr=new int[n]; int[] colarr=new int[m]; int xor=0; int xor1=0; int xor2=0; for(int i=0;i<n;i++) { rowarr[i]=sc.nextInt(); xor1^=rowarr[i]; } for(int j=0;j<m;j++) { colarr[j]=sc.nextInt(); xor2^=colarr[j]; } xor=xor1^xor2; if(xor!=0) { System.out.println("NO"); return; } System.out.println("YES"); for(int i=0;i<n-1;i++) arr[i][m-1]=rowarr[i]; for(int j=0;j<m-1;j++) arr[n-1][j]=colarr[j]; arr[n-1][m-1]=xor1^rowarr[n-1]^colarr[m-1]; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) System.out.print(arr[i][j]+" "); System.out.println(); } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
6b5ef134dbdf762deccfbf867e4bd021
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
/* * * @Author Ajudiya_13(Bhargav Girdharbhai Ajudiya) * Dhirubhai Ambani Institute of Information And Communication Technology * */ import java.util.*; import java.io.*; import java.lang.*; public class Code330 { public static void main(String[] args) { InputReader in = new InputReader(System.in); PrintWriter pw = new PrintWriter(System.out); int n = in.nextInt(); int m = in.nextInt(); long[] a = new long[n]; long[] b = new long[m]; long xor = 0; for(int i=0;i<n;i++) { a[i] = in.nextLong(); xor ^= a[i]; } for(int i=0;i<m;i++) { b[i] = in.nextLong(); xor^=b[i]; } if(xor!=0) { pw.println("NO"); pw.flush(); pw.close(); System.exit(0); } else { long[][] ans = new long[n][m]; long x = 0; for(int i=0;i<n-1;i++) { x ^= a[i]; ans[i][m-1] = a[i]; } long y = 0; for(int i=0;i<m-1;i++) { y ^= b[i]; ans[n-1][i] = b[i]; } x ^= b[m-1]; y ^= a[n-1]; if(x!=y) pw.println("NO"); else { ans[n-1][m-1] = x; pw.println("YES"); for(int i=0;i<n;i++) { for(int j=0;j<m;j++) pw.print(ans[i][j] + " "); pw.println(); } } } pw.flush(); pw.close(); } static class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int snext() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } public String readString() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = snext(); while (isSpaceChar(c)) c = snext(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isEndOfLine(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } public static long mod = 1000000007; public static int d; public static int p; public static int q; public static int[] suffle(int[] a,Random gen) { int n = a.length; for(int i=0;i<n;i++) { int ind = gen.nextInt(n-i)+i; int temp = a[ind]; a[ind] = a[i]; a[i] = temp; } return a; } public static void swap(int a, int b){ int temp = a; a = b; b = temp; } public static HashSet<Integer> primeFactorization(int n) { HashSet<Integer> a =new HashSet<Integer>(); for(int i=2;i*i<=n;i++) { while(n%i==0) { a.add(i); n/=i; } } if(n!=1) a.add(n); return a; } public static void sieve(boolean[] isPrime,int n) { for(int i=1;i<n;i++) isPrime[i] = true; isPrime[0] = false; isPrime[1] = false; for(int i=2;i*i<n;i++) { if(isPrime[i] == true) { for(int j=(2*i);j<n;j+=i) isPrime[j] = false; } } } public static int GCD(int a,int b) { if(b==0) return a; else return GCD(b,a%b); } public static long GCD(long a,long b) { if(b==0) return a; else return GCD(b,a%b); } public static void extendedEuclid(int A,int B) { if(B==0) { d = A; p = 1 ; q = 0; } else { extendedEuclid(B, A%B); int temp = p; p = q; q = temp - (A/B)*q; } } public static long LCM(long a,long b) { return (a*b)/GCD(a,b); } public static int LCM(int a,int b) { return (a*b)/GCD(a,b); } public static int binaryExponentiation(int x,int n) { int result=1; while(n>0) { if(n % 2 ==1) result=result * x; x=x*x; n=n/2; } return result; } public static long binaryExponentiation(long x,long n) { long result=1; while(n>0) { if(n % 2 ==1) result=result * x; x=x*x; n=n/2; } return result; } public static int modularExponentiation(int x,int n,int M) { int result=1; while(n>0) { if(n % 2 ==1) result=(result * x)%M; x=(x*x)%M; n=n/2; } return result; } public static long modularExponentiation(long x,long n,long M) { long result=1; while(n>0) { if(n % 2 ==1) result=(result * x)%M; x=(x*x)%M; n=n/2; } return result; } public static int modInverse(int A,int M) { return modularExponentiation(A,M-2,M); } public static long modInverse(long A,long M) { return modularExponentiation(A,M-2,M); } public static boolean isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n%2 == 0 || n%3 == 0) return false; for (int i=5; i*i<=n; i=i+6) { if (n%i == 0 || n%(i+2) == 0) return false; } return true; } static class pair implements Comparable<pair> { Integer x, y; pair(int x,int y) { this.x=x; this.y=y; } public int compareTo(pair o) { int result = x.compareTo(o.x); if(result==0) result = y.compareTo(o.y); return result; } public String toString() { return x+" "+y; } public boolean equals(Object o) { if (o instanceof pair) { pair p = (pair)o; return (Math.abs(p.x-x)==0 && Math.abs(p.y-y)==0); } return false; } public int hashCode() { return new Long(x).hashCode()*31 + new Long(y).hashCode(); } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
969450e1d0d0ddf25a4bb9b6b146a435
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.io.*; import java.util.StringTokenizer; public class Solution { public static void main(String[] args) throws IOException { FastScanner in = new FastScanner(System.in); PrintWriter out = new PrintWriter(System.out); int n = in.nextInt(); int m = in.nextInt(); int[] rowSums = new int[n]; int[] columnSums = new int[m]; int sum1 = 0; int sum2 = 0; for (int i = 0; i < n; i++) { rowSums[i] = in.nextInt(); sum1 ^= rowSums[i]; } for (int i = 0; i < m; i++) { columnSums[i] = in.nextInt(); sum2 ^= columnSums[i]; } if (sum1 != sum2) { out.println("NO"); } else { out.println("YES"); out.print(sum1^rowSums[0]^columnSums[0]); for(int i=1;i<m;i++){ out.write(' '); out.print(columnSums[i]); } for(int i=1;i<n;i++){ out.write('\n'); out.print(rowSums[i]); for(int j=1;j<m;j++){ out.write(' '); out.write('0'); } } } out.close(); } private static boolean checkSubstring(int i, int n, int m, String s, String t) { if (i + m > n) return false; for (int k = 0; k < m; k++) { if (s.charAt(i + k) != t.charAt(k)) return false; } return true; } private static class FastScanner { BufferedReader br; StringTokenizer stok; FastScanner(InputStream is) { this.br = new BufferedReader(new InputStreamReader(is)); } String nextToken() throws IOException { while (stok == null || !stok.hasMoreTokens()) { String s = br.readLine(); if (s == null) return null; stok = new StringTokenizer(s); } return stok.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(nextToken()); } double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } long nextLong() throws IOException { return Long.parseLong(nextToken()); } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
9fde1df890fa3e436f47938687540305
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
//package aug; import java.io.*; import java.util.*; public class EdRnd48D { InputStream is; PrintWriter out; String INPUT = ""; //boolean codechef=true; boolean codechef=true; void solve() { int n=ni(),m=ni(); int[] a=na(n); int[] b=na(m); int k1=0,k2=0,x=0,y=0; for(int i=0;i<m-1;i++) { x^=b[i]; } for(int i=0;i<n-1;i++) { y^=a[i]; } k1=x^a[n-1]; k2=y^b[m-1]; if(k1!=k2) { out.println("NO"); return; } int[][] ans=new int[n][m]; for(int i=0;i<n-1;i++) { ans[i][m-1]=a[i]; } for(int j=0;j<m-1;j++) { ans[n-1][j]=b[j]; } ans[n-1][m-1]=k1; out.println("YES"); for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { out.print(ans[i][j]+" "); } out.println(); } } static void dfs(int[][] g,int u,int[] vis,int p) { vis[u]=p; for(int v:g[u]) { if(vis[v]==0)dfs(g,v,vis,u); } } static int[][] packD(int n, int[] from, int[] to) { int[][] g = new int[n][]; int[] p = new int[n]; for (int f : from) p[f]++; for (int i = 0; i < n; i++) g[i] = new int[p[i]]; for (int i = 0; i < from.length; i++) { g[from[i]][--p[from[i]]] = to[i]; } return g; } public boolean check(int[] cnt,int m) { boolean ch=true; for(int i=2;i<=m;i++) { if(cnt[i]>=cnt[1]) { ch=false;break; } } return ch; } static class Pair { int a,b; public Pair(int a,int b) { this.a=a; this.b=b; } } static long lcm(int a,int b) { long val=a; val*=b; return (val/gcd(a,b)); } static long gcd(long a,long b) { if(a==0)return b; return gcd(b%a,a); } static int pow(int a, int b, int p) { long ans = 1, base = a; while (b!=0) { if ((b & 1)!=0) { ans *= base; ans%= p; } base *= base; base%= p; b >>= 1; } return (int)ans; } static int inv(int x, int p) { return pow(x, p - 2, p); } void run() throws Exception { if(codechef)oj=true; is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes()); out = new PrintWriter(System.out); long s = System.currentTimeMillis(); solve(); out.flush(); tr(System.currentTimeMillis()-s+"ms"); } public static void main(String[] args) throws Exception {new EdRnd48D().run();} private byte[] inbuf = new byte[1024]; public int lenbuf = 0, ptrbuf = 0; private int readByte() { if(lenbuf == -1)throw new InputMismatchException(); if(ptrbuf >= lenbuf){ ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if(lenbuf <= 0)return -1; } return inbuf[ptrbuf++]; } private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; } private double nd() { return Double.parseDouble(ns()); } private char nc() { return (char)skip(); } private String ns() { int b = skip(); StringBuilder sb = new StringBuilder(); while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } private char[] ns(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while(p < n && !(isSpaceChar(b))){ buf[p++] = (char)b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } private char[][] nm(int n, int m) { char[][] map = new char[n][]; for(int i = 0;i < n;i++)map[i] = ns(m); return map; } private int[] na(int n) { int[] a = new int[n]; for(int i = 0;i < n;i++)a[i] = ni(); return a; } private int ni() { int num = 0, b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-'){ minus = true; b = readByte(); } while(true){ if(b >= '0' && b <= '9'){ num = num * 10 + (b - '0'); }else{ return minus ? -num : num; } b = readByte(); } } private long nl() { long num = 0; int b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-'){ minus = true; b = readByte(); } while(true){ if(b >= '0' && b <= '9'){ num = num * 10 + (b - '0'); }else{ return minus ? -num : num; } b = readByte(); } } private boolean oj = System.getProperty("ONLINE_JUDGE") != null; private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
86be406653957cab7d232002a434fee1
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
/* Author: Ronak Agarwal, reader part not written by me*/ import java.io.* ; import java.util.* ; import static java.lang.Math.min ; import static java.lang.Math.max ; import static java.lang.Math.abs ; import static java.lang.Math.log ; import static java.lang.Math.pow ; import static java.lang.Math.sqrt ; /* Thread is created here to increase the stack size of the java code so that recursive dfs can be performed */ public class Codeshefcode{ public static void main(String[] args) throws IOException{ new Thread(null,new Runnable(){ public void run(){ exec_Code() ;} },"Solver",1l<<27).start() ; } static void exec_Code(){ try{ Solver Machine = new Solver() ; Machine.Solve() ; Machine.Finish() ;} catch(Exception e){ e.printStackTrace() ; print_and_exit() ;} catch(Error e){ e.printStackTrace() ; print_and_exit() ; } } static void print_and_exit(){ System.out.flush() ; System.exit(-1) ;} } /* Implementation of the Reader class */ class Reader { private InputStream mIs; private byte[] buf = new byte[1024]; private int curChar,numChars; public Reader() { this(System.in); } public Reader(InputStream is) { mIs = is;} public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = mIs.read(buf);} catch (IOException e) { throw new InputMismatchException();} if (numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine(){ int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString() ; } public String s(){ int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); }while (!isSpaceChar(c)); return res.toString(); } public long l(){ int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1 ; c = read() ; } long res = 0; do{ if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10 ; res += c - '0' ; c = read(); }while(!isSpaceChar(c)); return res * sgn; } public int i(){ int c = read() ; while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1 ; c = read() ; } int res = 0; do{ if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10 ; res += c - '0' ; c = read() ; }while(!isSpaceChar(c)); return res * sgn; } public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } } /* All the useful functions,constants,renamings are here*/ class Template{ /* Constants Section */ final int INT_MIN = Integer.MIN_VALUE ; final int INT_MAX = Integer.MAX_VALUE ; final long LONG_MIN = Long.MIN_VALUE ; final long LONG_MAX = Long.MAX_VALUE ; static long MOD = 1000000007 ; static Reader ip = new Reader() ; static PrintWriter op = new PrintWriter(System.out) ; /* Methods for writing */ static void p(Object o){ op.print(o) ; } static void pln(Object o){ op.println(o) ;} static void Finish(){ op.flush(); op.close(); } /* Implementation of operations modulo MOD */ static long inv(long a){ return powM(a,MOD-2) ; } static long m(long a,long b){ return (a*b)%MOD ; } static long d(long a,long b){ return (a*inv(b))%MOD ; } static long powM(long a,long b){ if(b<0) return powM(inv(a),-b) ; long ans=1 ; for( ; b!=0 ; a=(a*a)%MOD , b/=2) if((b&1)==1) ans = (ans*a)%MOD ; return ans ; } /* Renaming of some generic utility classes */ final static class mylist extends ArrayList<Integer>{} final static class myset extends TreeSet<pair>{} final static class mystack extends Stack<Integer>{} final static class mymap extends TreeMap<Integer,Integer>{} } /* Implementation of the pair class, useful for every other problem */ class pair implements Comparable<pair>{ int x ; int y ; pair(int _x,int _y){ x=_x ; y=_y ;} public int compareTo(pair p){ return (this.x<p.x ? -1 : (this.x>p.x ? 1 : (this.y<p.y ? -1 : (this.y>p.y ? 1 : 0)))) ; } } /* Main code starts here */ class Solver extends Template{ public void Solve() throws IOException{ int n = ip.i(); int m = ip.i(); long a[] = new long[n+1]; long b[] = new long[m+1]; for(int i=1 ; i<=n ; i++) a[i] = ip.i(); for(int j=1 ; j<=m ; j++) b[j] = ip.i(); long res[][] = new long[n+1][m+1]; long ba[] = new long[n+1]; long bb[] = new long[m+1]; boolean flag=true; long tmp[][] = new long[n+1][m+1]; for(int pos=0 ; pos<30 ; pos++){ for(int i=1 ; i<=n ; i++) ba[i] = ((a[i]&(1l<<pos))!=0 ? 1 : 0); for(int j=1 ; j<=m ; j++) bb[j] = ((b[j]&(1l<<pos))!=0 ? 1 : 0); long xsuma=0,xsumb=0; for(int i=1 ; i<=n ; i++) xsuma^=ba[i]; for(int j=1 ; j<=m ; j++) xsumb^=bb[j]; if(xsuma!=xsumb){ flag=false; break;} for(int i=1 ; i<n ; i++) for(int j=1 ; j<m ; j++) tmp[i][j]=0; for(int i=1 ; i<n ; i++) tmp[i][m]=ba[i]; for(int j=1 ; j<m ; j++) tmp[n][j]=bb[j]; tmp[n][m]=bb[m]^xsuma^ba[n]; for(int i=1 ; i<=n ; i++) for(int j=1 ; j<=m ; j++) res[i][j]|=((tmp[i][j]==0) ? 0 : (1<<pos)); } if(!flag) pln("NO"); else{ pln("YES"); for(int i=1 ; i<=n ; i++){ for(int j=1 ; j<=m ; j++) p(res[i][j]+" "); pln(""); } } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
aed27f82b096d78d587faea7d5ab616e
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in Actual solution is at the top * * @author MaxHeap */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskD solver = new TaskD(); solver.solve(1, in, out); out.close(); } static class TaskD { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); int m = in.nextInt(); int[] a = in.nextIntArray(n); int[] b = in.nextIntArray(m); int first = 0; int second = 0; int d = 0; for (int i = 0; i < n; i++) { first ^= a[i]; if (i < n - 1) { d ^= a[i]; } } for (int i = 0; i < m; i++) { second ^= b[i]; } if (first != second) { out.println("NO"); return; } int[][] ret = new int[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (i == n - 1) { ret[i][j] = b[j]; } if (j == m - 1) { ret[i][j] = a[i]; } if (i == n - 1 && j == m - 1) { ret[i][j] = d ^ b[m - 1]; } } } out.println("YES"); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { out.print(ret[i][j] + " "); } out.println(); } } } static class InputReader { private InputStream stream; private byte[] buf = new byte[1 << 13]; private int curChar; private int numChars; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (this.numChars == -1) { throw new UnknownError(); } else { if (this.curChar >= this.numChars) { this.curChar = 0; try { this.numChars = this.stream.read(this.buf); } catch (IOException ex) { throw new InputMismatchException(); } if (this.numChars <= 0) { return -1; } } return this.buf[this.curChar++]; } } public int nextInt() { int c; for (c = this.read(); isSpaceChar(c); c = this.read()) { } byte sgn = 1; if (c == 45) { sgn = -1; c = this.read(); } int res = 0; while (c >= 48 && c <= 57) { res *= 10; res += c - 48; c = this.read(); if (isSpaceChar(c)) { return res * sgn; } } throw new InputMismatchException(); } public static boolean isSpaceChar(int c) { return c == 32 || c == 10 || c == 13 || c == 9 || c == -1; } public int[] nextIntArray(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = nextInt(); } return arr; } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
808507d8424ef5cdedd0dae4effa22a5
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.io.BufferedReader; // import java.io.FileInputStream; // import java.io.FileOutputStream; import java.io.InputStream; import java.io.InputStreamReader; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.StringTokenizer; import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.sqrt; import static java.util.Arrays.copyOf; import static java.util.Arrays.fill; import static java.util.Arrays.sort; import static java.util.Collections.reverse; public class Main { FastScanner in; PrintWriter out; private void solve() throws IOException { int n = in.nextInt(), m = in.nextInt(), xor = 0; int[] a = new int[n], b = new int[m]; for (int i = 0; i < n; i++) xor ^= (a[i] = in.nextInt()); for (int i = 0; i < m; i++) xor ^= (b[i] = in.nextInt()); out.println(xor == 0 ? "YES" : "NO"); if (xor == 0) { int[][] c = new int[n][m]; for (int bit = 1; bit <= 1_000_000_000; bit <<= 1) { for (int i = 0; i < n; i++) { xor = 0; for (int j = 0; j < m; j++) { xor ^= b[j] & bit; c[i][j] |= b[j] & bit; b[j] -= b[j] & bit; } if (xor != (a[i] & bit)) { c[i][0] ^= bit; b[0] ^= bit; } } } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) out.print(c[i][j] + " "); out.println(); } } } class FastScanner { StringTokenizer st; BufferedReader br; FastScanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } boolean hasNext() throws IOException { return br.ready() || (st != null && st.hasMoreTokens()); } int nextInt() throws IOException { return Integer.parseInt(next()); } long nextLong() throws IOException { return Long.parseLong(next()); } double nextDouble() throws IOException { return Double.parseDouble(next().replace(',', '.')); } String nextLine() throws IOException { return br.readLine(); } boolean hasNextLine() throws IOException { return br.ready(); } } private void run() throws IOException { in = new FastScanner(System.in); // new FastScanner(new FileInputStream(".in")); out = new PrintWriter(System.out); // new PrintWriter(new FileOutputStream(".out")); solve(); out.flush(); out.close(); } public static void main(String[] args) throws IOException { new Main().run(); } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
391ec56e71323549237f840eab3a92b1
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; import java.io.InputStreamReader; import java.io.IOException; import java.io.PrintWriter; import java.math.BigInteger; import java.util.ArrayList; import java.util.StringTokenizer; import java.util.TreeSet; import static java.lang.Math.abs; import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.round; import static java.util.Arrays.copyOf; import static java.util.Arrays.fill; import static java.util.Arrays.sort; import static java.util.Collections.reverseOrder; import static java.util.Collections.sort; import static java.util.Comparator.comparing; public class Main { FastScanner in; PrintWriter out; private void solve() throws IOException { int n = in.nextInt(), m = in.nextInt(), xor = 0; int[] a = new int[n]; for (int i = 0; i < n; i++) xor ^= (a[i] = in.nextInt()); int[] b = new int[m]; for (int i = 0; i < m; i++) xor ^= (b[i] = in.nextInt()); out.println(xor == 0 ? "YES" : "NO"); if (xor == 0) { for (int i = 0; i < m; i++) xor ^= i == 0 ? a[i] : b[i]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) out.print((i == 0 ? j == 0 ? xor : b[j] : j == 0 ? a[i] : 0) + " "); out.println(); } } } class FastScanner { StringTokenizer st; BufferedReader br; FastScanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } boolean hasNext() throws IOException { return br.ready() || (st != null && st.hasMoreTokens()); } int nextInt() throws IOException { return Integer.parseInt(next()); } long nextLong() throws IOException { return Long.parseLong(next()); } double nextDouble() throws IOException { return Double.parseDouble(next()); } String nextLine() throws IOException { return br.readLine(); } boolean hasNextLine() throws IOException { return br.ready(); } } private void run() throws IOException { in = new FastScanner(System.in); // new FastScanner(new FileInputStream("input.txt")); out = new PrintWriter(System.out); // new PrintWriter(new FileOutputStream("output.txt")); solve(); out.flush(); out.close(); } public static void main(String[] args) throws IOException { new Main().run(); } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
0f7b9c8c052bbef07f46794fa21cbf0c
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.io.*; import java.util.*; public class MainClass { public static void main(String[] args)throws IOException { Reader in = new Reader(); int n = in.nextInt(); int m = in.nextInt(); long[] rows = new long[n]; long[] cols = new long[m]; long xor = 0L; for (int i=0;i<n;i++) { rows[i] = in.nextLong(); xor ^= rows[i]; } for (int i=0;i<m;i++) { cols[i] = in.nextLong(); xor ^= cols[i]; } if (xor != 0L) System.out.println("NO"); else { long[][] A = new long[n][m]; long xx = 0L; for (int i=0;i<m - 1;i++) { A[n - 1][i] = cols[i]; xx ^= cols[i]; } for (int i=0;i<n - 1;i++) A[i][m - 1] = rows[i]; xx ^= rows[n - 1]; A[n - 1][m - 1] = xx; StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("YES\n"); for (int i=0;i<n;i++) { for (int j=0;j<m;j++) stringBuilder.append(A[i][j]).append(" "); stringBuilder.append("\n"); } System.out.println(stringBuilder); } } } class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
804b34fac0c0338d807aa2f3a941b1ce
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.BitSet; import java.util.Calendar; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.PriorityQueue; import java.util.SortedSet; import java.util.Stack; import java.util.StringTokenizer; import java.util.TreeMap; import java.util.TreeSet; /** * # * @author pttrung */ public class D_Edu_Round_48 { public static long MOD = 998244353; static long[][][]dp; public static void main(String[] args) throws FileNotFoundException { // PrintWriter out = new PrintWriter(new FileOutputStream(new File( // "output.txt"))); PrintWriter out = new PrintWriter(System.out); Scanner in = new Scanner(); int n = in.nextInt(); int m = in.nextInt(); int[]row = new int[n]; int[]col = new int[m]; for(int i = 0; i < n; i++){ row[i] = in.nextInt(); } for(int i = 0; i < m ; i++){ col[i] = in.nextInt(); } boolean ok = true; int[][]re = new int[n][m]; for(int k = 0; k < 31; k++){ int a = 0; int b = 0; for(int i = 0; i < n; i++){ if(((1<<k) & row[i]) != 0){ a++; } } for(int i = 0; i < m; i++){ if(((1<<k) & col[i]) != 0){ b++; } } if((a % 2) == (b % 2)){ if(a % 2 == 0){ if(a > 0 && b > 0){ int count = -1; for(int i = 0; i < n; i++){ if(((1 << k) & row[i]) != 0){ if(count == -1) { for (int j = 0; j < m; j++) { if (((1 << k) & col[j]) != 0) { if(count == -1){ count = j; continue; } re[i][j] |= (1 << k); } } }else{ re[i][count] |= (1 << k); } } } }else if(a == 0 && b > 0){ for (int j = 0; j < m; j++) { if (((1 << k) & col[j]) != 0) { re[0][j] |= (1 << k); } } }else if(a > 0 && b == 0){ for(int i = 0; i < n; i++){ if(((1 << k) & row[i]) != 0){ re[i][0] |= (1 << k); } } } }else{ boolean found = false; for(int i = 0; i < n; i++){ if(((1 << k) & row[i]) != 0){ if(!found) { found = true; for (int j = 0; j < m; j++) { if (((1 << k) & col[j]) != 0) { re[i][j] |= (1 << k); } } }else{ re[i][0] |= (1 << k); } } } } }else{ ok = false; break; } } if(ok){ out.println("YES"); for(int [] a : re){ for(int i : a){ out.print(i + " "); } out.println(); } }else{ out.println("NO"); } out.close(); } static long cal(int index, int last, int n, int left){ if(index == n ){ return left == 0 ? 1 : 0; } if(left < 0){ return 0; } if(dp[last][index][left] != -1){ return dp[last][index][left]; } long result = 0; for(int i = 0; i < 4; i++){ result += cal(index + 1, i, n, left - count(last, i)); result %= MOD; } return dp[last][index][left] = result; } static int count(int last, int cur){ if(last == cur){ return 0; } if(last == 0 && cur != 0){ return 1; } if(last == 1 ){ if(cur == 2){ return 2; } return 0; } if(last == 2){ if(cur == 1){ return 2; } return 0; } return 1; } public static boolean div(int need, String v) { int cur = 0; for (int i = 0; i < v.length(); i++) { cur += v.charAt(i) - '0'; if (cur == need) { cur = 0; } else if (cur > need) { return false; } } return true; } public static int[] KMP(String val) { int i = 0; int j = -1; int[] result = new int[val.length() + 1]; result[0] = -1; while (i < val.length()) { while (j >= 0 && val.charAt(j) != val.charAt(i)) { j = result[j]; } j++; i++; result[i] = j; } return result; } public static boolean nextPer(int[] data) { int i = data.length - 1; while (i > 0 && data[i] < data[i - 1]) { i--; } if (i == 0) { return false; } int j = data.length - 1; while (data[j] < data[i - 1]) { j--; } int temp = data[i - 1]; data[i - 1] = data[j]; data[j] = temp; Arrays.sort(data, i, data.length); return true; } public static int digit(long n) { int result = 0; while (n > 0) { n /= 10; result++; } return result; } public static double dist(long a, long b, long x, long y) { double val = (b - a) * (b - a) + (x - y) * (x - y); val = Math.sqrt(val); double other = x * x + a * a; other = Math.sqrt(other); return val + other; } public static class Point implements Comparable<Point> { int x, y; public Point(int start, int end) { this.x = start; this.y = end; } @Override public int hashCode() { int hash = 5; hash = 47 * hash + this.x; hash = 47 * hash + this.y; return hash; } @Override public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final Point other = (Point) obj; if (this.x != other.x) { return false; } if (this.y != other.y) { return false; } return true; } @Override public int compareTo(Point o) { return Integer.compare(x, o.x); } } public static class FT { long[] data; FT(int n) { data = new long[n]; } public void update(int index, long value) { while (index < data.length) { data[index] += value; index += (index & (-index)); } } public long get(int index) { long result = 0; while (index > 0) { result += data[index]; index -= (index & (-index)); } return result; } } public static long gcd(long a, long b) { if (b == 0) { return a; } return gcd(b, a % b); } public static long pow(long a, long b, long MOD) { if (b == 0) { return 1; } if (b == 1) { return a; } long val = pow(a, b / 2, MOD); if (b % 2 == 0) { return val * val % MOD; } else { return val * (val * a % MOD) % MOD; } } static class Scanner { BufferedReader br; StringTokenizer st; public Scanner() throws FileNotFoundException { // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true)); br = new BufferedReader(new InputStreamReader(System.in)); // br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt")))); } public String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) { throw new RuntimeException(); } } return st.nextToken(); } public long nextLong() { return Long.parseLong(next()); } public int nextInt() { return Integer.parseInt(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String nextLine() { st = null; try { return br.readLine(); } catch (Exception e) { throw new RuntimeException(); } } public boolean endLine() { try { String next = br.readLine(); while (next != null && next.trim().isEmpty()) { next = br.readLine(); } if (next == null) { return true; } st = new StringTokenizer(next); return st.hasMoreTokens(); } catch (Exception e) { throw new RuntimeException(); } } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
5406f4218878367a99bf7d5b90ff27d0
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.util.*; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.Scanner; import java.util.StringTokenizer; public class temp { void solve() throws IOException { FastReader sc=new FastReader(); int n = sc.nextInt(); int m = sc.nextInt(); long r[] = new long[n]; long c[] = new long[m]; long xor = 0; for(int i=0;i<n;i++) { r[i] = sc.nextLong(); xor^=r[i]; } for(int i=0;i<m;i++) { c[i] = sc.nextLong(); xor^=c[i]; } if(xor == 0) { long ans[][] = new long[n][m]; for(int i=0;i<n;i++) ans[i][0] = r[i]; for(int i=1;i<m;i++) { ans[n-1][0] ^= c[i]; ans[n-1][i] = c[i]; } System.out.println("YES"); for(int i=0;i<n;i++) { for(int j=0;j<m;j++) System.out.print(ans[i][j]+" "); System.out.println(); } } else System.out.println("NO"); } public static void main(String[] args) throws IOException { // TODO Auto-generated method stub new temp().solve(); } 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
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
eed3ea1e69213e526a3f2235740c2512
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.io.*; import java.util.*; import java.text.*; import java.lang.*; import java.math.BigInteger; import java.util.regex.*; public class Myclass { /*public static ArrayList a[]=new ArrayList[200001]; static boolean visited[]=new boolean [200001]; static long value[]; static long maxi[]; static long dp[]=new long[200001]; static long ans; static void dfs(pair n,int p) { visited[n.x]=true; dp[n.x]=Math.max(dp[p]+n.y,n.y); if(dp[n.x]>value[n.x]) { ans++; return; } for(int i=0;i<a[n.x].size();i++) { pair y=(pair) a[n.x].get(i); if(!visited[y.x]) { dfs(y,n.x); } } }*/ public static void main(String[] args) { InputReader in = new InputReader(System.in); PrintWriter pw = new PrintWriter(System.out); int n=in.nextInt(); int m=in.nextInt(); long a[]=new long[n]; long b[]=new long[m]; long xor=0; long xor1=0; long ans[][]=new long[n][m]; for(int i=0;i<n;i++) { a[i]=in.nextLong(); xor^=a[i]; } for(int i=0;i<m;i++) { b[i]=in.nextLong(); xor1^=b[i]; } if(xor!=xor1) { pw.println("NO"); } else { long upto=0; long upto1=0; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { if(i==n-1 && j==m-1) continue; if(i==n-1) { ans[i][j]=b[j]; upto^=b[j]; } if(j==m-1) { ans[i][j]=a[i]; upto1^=a[i]; } } } ans[n-1][m-1]=xor^upto^upto1; pw.println("YES"); for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { pw.print(ans[i][j]+" "); } pw.println(); } } pw.flush(); pw.close(); } static class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int snext() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } static class tri implements Comparable<tri> { int p, c, l; tri(int p, int c, int l) { this.p = p; this.c = c; this.l = l; } public int compareTo(tri o) { return Integer.compare(l, o.l); } } public String readString() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = snext(); while (isSpaceChar(c)) c = snext(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isEndOfLine(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } public static long mod = 1000000007; public static int d; public static int p; public static int q; public static int[] suffle(int[] a,Random gen) { int n = a.length; for(int i=0;i<n;i++) { int ind = gen.nextInt(n-i)+i; int temp = a[ind]; a[ind] = a[i]; a[i] = temp; } return a; } public static void swap(int a, int b){ int temp = a; a = b; b = temp; } public static HashSet<Integer> primeFactorization(int n) { HashSet<Integer> a =new HashSet<Integer>(); for(int i=2;i*i<=n;i++) { while(n%i==0) { a.add(i); n/=i; } } if(n!=1) a.add(n); return a; } public static void sieve(boolean[] isPrime,int n) { for(int i=1;i<n;i++) isPrime[i] = true; isPrime[0] = false; isPrime[1] = false; for(int i=2;i*i<n;i++) { if(isPrime[i] == true) { for(int j=(2*i);j<n;j+=i) isPrime[j] = false; } } } public static int GCD(int a,int b) { if(b==0) return a; else return GCD(b,a%b); } public static long GCD(long a,long b) { if(b==0) return a; else return GCD(b,a%b); } public static void extendedEuclid(int A,int B) { if(B==0) { d = A; p = 1 ; q = 0; } else { extendedEuclid(B, A%B); int temp = p; p = q; q = temp - (A/B)*q; } } public static long LCM(long a,long b) { return (a*b)/GCD(a,b); } public static int LCM(int a,int b) { return (a*b)/GCD(a,b); } public static int binaryExponentiation(int x,int n) { int result=1; while(n>0) { if(n % 2 ==1) result=result * x; x=x*x; n=n/2; } return result; } public static long binaryExponentiation(long x,long n) { long result=1; while(n>0) { if(n % 2 ==1) result=result * x; x=x*x; n=n/2; } return result; } public static int modularExponentiation(int x,int n,int M) { int result=1; while(n>0) { if(n % 2 ==1) result=(result * x)%M; x=(x%M*x)%M; n=n/2; } return result; } public static long modularExponentiation(long x,long n,long M) { long result=1; while(n>0) { if(n % 2 ==1) result=(result%M * x%M)%M; x=(x%M * x%M)%M; n=n/2; } return result; } public static long modInverse(int A,int M) { return modularExponentiation(A,M-2,M); } public static long modInverse(long A,long M) { return modularExponentiation(A,M-2,M); } public static boolean isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n%2 == 0 || n%3 == 0) return false; for (int i=5; i*i<=n; i=i+6) { if (n%i == 0 || n%(i+2) == 0) return false; } return true; } public static long[] shuffle(long[] a, Random gen){ for(int i = 0, n = a.length;i < n;i++){ int ind = gen.nextInt(n-i)+i; long d = a[i]; a[i] = a[ind]; a[ind] = d; } return a; } static class pair implements Comparable<pair> { Integer x; Integer y; pair(int a,int m) { this.x=a; this.y=m; } public boolean isEmpty() { // TODO Auto-generated method stub return false; } public int compareTo(pair o) { int result = x.compareTo(o.x); if(result==0) result = y.compareTo(o.y); return result; } public String toString() { return x+" "+y; } public boolean equals(Object o) { if (o instanceof pair) { pair p = (pair)o; return p.x == x && p.y == y ; } return false; } public int hashCode() { return new Long(x).hashCode()*31 + new Long(y).hashCode(); } } static class triplet { Long x; Long y; Integer z; triplet(long x,long y,int z) { this.x=x; this.y=y; this.z=z; } } static class jodi { Integer x; Integer y; jodi(int x,int y) { this.x=x; this.y=y; } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
cf578ff4672d6544de057eab7d47122c
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.util.Scanner; public class VasyaMatrix { public static void main(String[] args) { /* */ Scanner in = new Scanner(System.in); int n = in.nextInt(); int m = in.nextInt(); int[] a = new int[n]; int[] b = new int[m]; int aXor = 0; int bXor = 0; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); aXor ^= a[i]; } for (int i = 0; i < m; i++) { b[i] = in.nextInt(); bXor ^= b[i]; } if (aXor != bXor) { System.out.println("NO"); return; } System.out.println("YES"); for (int row = 0; row < n; row++) { for (int col = 0; col < m; col++) { if (col > 0) { System.out.print(" "); } int val = 0; if (row == 0 && col == 0) { val = a[0] ^ bXor ^ b[0]; } else if (row == 0) { val = b[col]; } else if (col == 0) { val = a[row]; } System.out.print(val); } System.out.println(); } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
e86447f575827d90c02c46993dfd6539
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.util.*; import java.io.*; public class codeforces { public static void main(String[] args) { InputReader in = new InputReader(System.in); PrintWriter pw = new PrintWriter(System.out); int n = in.nextInt(); int m = in.nextInt(); int[] a = in.nextIntArray(n); int[] b = in.nextIntArray(m); int a1 = a[0], a2 = b[0]; for(int i=1;i<m;i++) a1 ^= b[i]; for(int i=1;i<n;i++) a2 ^= a[i]; if(a1!=a2) pw.println("NO"); else { pw.println("YES"); for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { if(i==0 && j==0) pw.print(a1+" "); else if(i==0) pw.print(b[j]+" "); else if(j==0) pw.print(a[i]+" "); else pw.print(0+" "); } pw.println(); } } pw.flush(); pw.close(); } static class pair implements Comparable<pair> { Integer x, y; pair(int x,int y) { this.x=x; this.y=y; } public int compareTo(pair o) { int result = x.compareTo(o.x); if(result==0) result = y.compareTo(o.y); return result; } public String toString() { return x+" "+y; } public boolean equals(Object o) { if (o instanceof pair) { pair p = (pair)o; return p.x == x && p.y == y ; } return false; } public int hashCode() { return new Long(x).hashCode()*31 + new Long(y).hashCode(); } } static class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int snext() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } public String readString() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = snext(); while (isSpaceChar(c)) c = snext(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isEndOfLine(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } static class CodeX { public static void sort(long arr[]) { merge_sort(arr, 0, arr.length - 1); } private static void merge_sort(long A[], long start, long end) { if (start < end) { long mid = (start + end) / 2; merge_sort(A, start, mid); merge_sort(A, mid + 1, end); merge(A, start, mid, end); } } private static void merge(long A[], long start,long mid, long end) { long p = start, q = mid + 1; long Arr[] = new long[(int)(end - start + 1)]; long k = 0; for (int i = (int)start; i <= end; i++) { if (p > mid) Arr[(int)k++] = A[(int)q++]; else if (q > end) Arr[(int)k++] = A[(int)p++]; else if (A[(int)p] < A[(int)q]) Arr[(int)k++] = A[(int)p++]; else Arr[(int)k++] = A[(int)q++]; } for (int i = 0; i < k; i++) { A[(int)start++] = Arr[i]; } } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
287d7be068b8c522eceef06213467940
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.util.*; import java.io.*; import static java.lang.Math.*; public class Main { static MyScanner scan; static PrintWriter pw; public static void main(String[] args) { new Thread(null,null,"_",1<<25) { public void run() { try { solve(); } catch(Exception e) { e.printStackTrace(); System.exit(1); } } }.start(); } static void solve() throws IOException { scan = new MyScanner(); pw = new PrintWriter(System.out,true); StringBuilder sb = new StringBuilder(); int n = ni(); int m = ni(); int row[] = new int[n]; int col[] = new int[m]; int x = 0; for(int i=0;i<n;++i) { row[i] = ni(); x^=row[i]; } for(int i=0;i<m;++i) { col[i] = ni(); x^=col[i]; } if(x!=0) pl("NO"); else { pl("YES"); int mat[][] = new int[n][m]; int xx = 0; for(int i=0;i<n-1;++i) { mat[i][m-1] = row[i]; xx^=row[i]; } mat[n-1][m-1] = xx^col[m-1]; for(int i=0;i<m-1;++i) mat[n-1][i] = col[i]; for(int i=0;i<n;++i) { for(int j=0;j<m;++j) p(mat[i][j]); pl(); } } pw.flush(); pw.close(); } static int ni() throws IOException { return scan.nextInt(); } static long nl() throws IOException { return scan.nextLong(); } static double nd() throws IOException { return scan.nextDouble(); } static String ne() throws IOException { return scan.next(); } static String nel() throws IOException { return scan.nextLine(); } static void pl() { pw.println(); } static void p(Object o) { pw.print(o+" "); } static void pl(Object o) { pw.println(o); } static void psb(StringBuilder sb) { pw.print(sb); } static class MyScanner { BufferedReader br; StringTokenizer st; MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String nextLine()throws IOException { return br.readLine(); } String next() throws IOException { if(st==null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(next()); } long nextLong() throws IOException { return Long.parseLong(next()); } double nextDouble() throws IOException { return Double.parseDouble(next()); } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
268cb0673c61126c6be03b19d900fcf4
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author prakharjain */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); TaskD solver = new TaskD(); solver.solve(1, in, out); out.close(); } static class TaskD { public void solve(int testNumber, InputReader in, OutputWriter out) { int n = in.nextInt(); int m = in.nextInt(); int[][] ans = new int[n][m]; long x = 0; int[] row = new int[n]; for (int i = 0; i < n; i++) { row[i] = in.nextInt(); x ^= (row[i]); } long y = 0; int[] col = new int[m]; for (int i = 0; i < m; i++) { col[i] = in.nextInt(); y ^= col[i]; } if (x != y) { out.println("NO"); return; } long z = x; for (int i = 0; i < n - 1; i++) { ans[i][m - 1] = row[i]; z ^= row[i]; } for (int j = 0; j < m - 1; j++) { ans[n - 1][j] = col[j]; z ^= col[j]; } ans[n - 1][m - 1] = (int) z; out.println("YES"); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { out.print(ans[i][j] + " "); } out.println(); } } } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private InputReader.SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return isWhitespace(c); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) { writer.print(' '); } writer.print(objects[i]); } } public void println() { writer.println(); } public void println(Object... objects) { print(objects); writer.println(); } public void close() { writer.close(); } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
7022d02a39a20857415b8b13c148f8ca
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.util.*; import java.io.*; import java.text.*; public class Main{ long mod = (int)1e9+7, IINF = (long)1e17; final int MAX = (int)1e6+1, INF = (int)1e9, root = 3; DecimalFormat df = new DecimalFormat("0.00000000"); double PI = 3.141592653589793238462643383279502884197169399375105820974944; static boolean multipleTC = false, memory = false; FastReader in;PrintWriter out; public static void main(String[] args) throws Exception{ if(memory)new Thread(null, new Runnable() {public void run(){try{new Main().run();}catch(Exception e){e.printStackTrace();}}}, "1", 1 << 28).start(); else new Main().run(); } void run() throws Exception{ in = new FastReader(); out = new PrintWriter(System.out); for(int i = 1, T= (multipleTC)?ni():1; i<= T; i++)solve(i); out.flush(); out.close(); } void solve(int TC) throws Exception{ int n = ni(), m = ni(); int[] r = new int[n], c = new int[m]; int x = 0; for(int i = 0; i< n; i++){r[i] = ni();x^=r[i];} for(int i = 0; i< m; i++){c[i] = ni();x^=c[i];} if(x!=0)pn("NO"); else { pn("YES"); int[][] ans = new int[n][m]; for(int i = 0; i< n-1; i++){ for(int j = 0; j< m; j++){ if(j==m-1){ ans[i][j] = r[i]; c[j]^=ans[i][j]; } else { ans[i][j] = 1; r[i]^=1; c[j]^=1; } } } for(int j = 0; j< m; j++)ans[n-1][j] = c[j]; for(int i = 0; i< n; i++){ for(int j = 0; j< m; j++)p(ans[i][j]+" "); pn(""); } } } long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);} int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);} int bitcount(long n){return (n==0)?0:(1+bitcount(n&(n-1)));} void p(Object o){out.print(o);} void pn(Object o){out.println(o);} void pni(Object o){out.println(o);out.flush();} String n(){return in.next();} String nln(){return in.nextLine();} int ni(){return Integer.parseInt(in.next());} long nl(){return Long.parseLong(in.next());} double nd(){return Double.parseDouble(in.next());} class FastReader{ BufferedReader br; StringTokenizer st; public FastReader(){ br = new BufferedReader(new InputStreamReader(System.in)); } public FastReader(String s) throws Exception{ br = new BufferedReader(new FileReader(s)); } String next(){ while (st == null || !st.hasMoreElements()){ try{ st = new StringTokenizer(br.readLine()); }catch (IOException e){ e.printStackTrace(); } } return st.nextToken(); } String nextLine(){ String str = ""; try{ str = br.readLine(); }catch (IOException e){ e.printStackTrace(); } return str; } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
6abbc40f8dd20bbe042e693b3301fc77
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.io.*; import java.util.*; import static java.lang.Math.exp; import static java.lang.Math.max; import static java.lang.Math.min; public class Main { private static FastScanner in = new FastScanner(); private static FastOutput out = new FastOutput(); public void run() { int n = in.nextInt(), m = in.nextInt(); long[] ns = new long[n], ms = new long[m]; for (int i = 0; i < n; i++) { ns[i] = in.nextLong(); } for (int i = 0; i < m; i++) { ms[i] = in.nextLong(); } long ns_s = 0, ms_s = 0; for (int i = 0; i < n - 1; i++) { ns_s = ns_s ^ ns[i]; } for (int i = 0; i < m - 1; i++) { ms_s = ms_s ^ ms[i]; } String bits = Long.toBinaryString(ms_s); String need = Long.toBinaryString(ns[ns.length - 1]); int bitl = bits.length(), needl = need.length(); int maxl = max(bitl, needl), minl = min(bitl, needl); char[] res = new char[maxl]; for (int i = 0; i < maxl; i++) { if (i < minl) { if (bits.charAt(bitl - 1 - i) != need.charAt(needl - 1 - i)) { res[maxl - 1 - i] = '1'; } else { res[maxl - 1 - i] = '0'; } } else { if (bitl == minl) res[maxl - 1 - i] = need.charAt(needl - 1 - i); else res[maxl - 1 - i] = bits.charAt(bitl - 1 - i); } } String res_s = new String(res); long res_l = Long.parseLong(res_s, 2); if ((res_l ^ ns_s) != ms[ms.length - 1]) { out.println("NO"); return; } out.println("YES"); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (i == n - 1 && j == m - 1) { out.print(res_l); continue; } if (i == n - 1) { out.print(ms[j]); } else if (j == m - 1) { out.print(ns[i]); } else { out.print(0); } } out.println(""); } } public static void main(String[] args) { new Main().run(); out.flush(); out.close(); } } class FastScanner { BufferedReader br; StringTokenizer st; FastScanner() { this(System.in); } FastScanner(InputStream stream) { br = new BufferedReader(new InputStreamReader(stream)); } FastScanner(File file) { try { br = new BufferedReader(new FileReader(file)); } catch (FileNotFoundException e) { throw new RuntimeException(e); } } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } } class FastOutput { private final BufferedWriter bf; public FastOutput(OutputStream outputStream) { bf = new BufferedWriter(new OutputStreamWriter(outputStream)); } public FastOutput() { this(System.out); } private void printOne(Object s) { try { bf.write(s.toString()); } catch (IOException e) { throw new RuntimeException(e); } } public void println(Object s) { printOne(s); printOne("\n"); } public void print(Object ...os) { printd(" ", os); } public void printd(String delimiter, Object ...os) { for (Object o : os) { printOne(o); printOne(delimiter); } } public void flush() { try { bf.flush(); } catch (IOException e) { throw new RuntimeException(e); } } public void close() { try { bf.close(); } catch (IOException e) { throw new RuntimeException(e); } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
2659aa61d427182d3b909cd83124c130
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; public InputReader(InputStream st) { this.stream = st; } public int read() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } public String readString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); } public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } } public static int[][] find(int n,int m,int[] arr,int[] brr) { int[][] crr = new int[n+1][m+1]; int xor = 0; for(int i=m;i>n;i--) { crr[n][i] = brr[i]; xor = xor^brr[i]; } int i=n,j=n; while(i > 0 && j > 0) { crr[i][j] = xor^arr[i]; xor = crr[i][j]; if(i - 1 > 0) { crr[i-1][j] = xor^brr[j]; xor = crr[i-1][j]; } j--;i--; } return crr; } public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] str = (br.readLine()).trim().split(" "); int n = Integer.parseInt(str[0]); int m = Integer.parseInt(str[1]); int[] arr = new int[n+1]; int[] brr = new int[m+1]; str = (br.readLine()).trim().split(" "); int xor = 0; for(int i=1;i<=n;i++) { arr[i] = Integer.parseInt(str[i-1]); xor = xor^arr[i]; } str = (br.readLine()).trim().split(" "); for(int i=1;i<=m;i++) { brr[i] = Integer.parseInt(str[i-1]); xor = xor^brr[i]; } if(xor != 0) { System.out.println("NO"); return; } System.out.println("YES"); if(n <= m) { int[][] ans = find(n,m,arr,brr); for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { System.out.print(ans[i][j] + " "); } System.out.println(); } } else if(n > m) { int[][] ans = find(m,n,brr,arr); for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) System.out.print(ans[j][i] + " "); System.out.println(); } } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
b5e3becd1f225b78757aeb0a6e1c4a0e
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
//package Contest501div2; import java.util.Scanner; public class main501D { public static Scanner enter = new Scanner(System.in); public static void main(String[] args) { int n=enter.nextInt(); int m=enter.nextInt(); int[] a = new int[n]; int[] b = new int[m]; int[][] mass= new int[n][m]; int summ=0; int tmp=0; for (int i = 0; i <n ; i++) { a[i]=enter.nextInt(); tmp^=a[i]; } summ^=a[0]; for (int i = 0; i <m ; i++) { b[i]=enter.nextInt(); tmp^=b[i]; summ^=b[i]; } summ^=b[0]; if(tmp!=0){ System.out.println("NO"); } else { System.out.println("YES"); mass[0][0] = summ; for (int i = 1; i < m; i++) { mass[0][i] = b[i]; } for (int i = 1; i < n; i++) { mass[i][0] = a[i]; } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { System.out.print(mass[i][j] + " "); } System.out.println(); } } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
99e4db51078ed82b3eb1d61323228d17
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.Writer; import java.util.InputMismatchException; /** * @author thesparkboy * */ public class A3 { public static void main(String[] args) { InputReader in = new InputReader(System.in); OutputWriter out = new OutputWriter(System.out); int n = in.readInt(); int m = in.readInt(); long ans = 0; long row[] = new long[n]; long col[] = new long[m]; long xor1 = 0, xor2 = 0; for (int j = 0; j < n; j++) { row[j] = in.readLong(); xor1 ^= row[j]; } long arr[][] = new long[n][m]; for (int j = 0; j < m; j++) { col[j] = in.readLong(); xor2 ^= col[j]; } if (xor1 != xor2) { System.out.println("NO"); } else { long xorTemp = 0; for (int i = 0; i < m - 1; i++) { arr[0][i] = col[i]; xorTemp ^= col[i]; } arr[0][m - 1] = xorTemp ^ row[0]; xorTemp = 0; for (int i = 1; i < n; i++) { arr[i][m - 1] = row[i]; xorTemp ^= row[i]; } System.out.println("YES"); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { System.out.print(arr[i][j] + " "); } System.out.println(); } } out.close(); } private static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public long readLong() { int c = read(); while (isSpaceChar(c)) c = read(); long sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int readInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuffer res = new StringBuffer(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } static boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } } private static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(outputStream); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) writer.print(' '); writer.print(objects[i]); } } public void printLine(Object... objects) { print(objects); writer.println(); } public void close() { writer.close(); } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
7f1cfa7b084e98a950319612d99bf2ac
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.io.*; import java.util.*; public class D implements Runnable{ public static void main (String[] args) {new Thread(null, new D(), "_cf", 1 << 28).start();} public void run() { FastScanner fs = new FastScanner(); PrintWriter out = new PrintWriter(System.out); System.err.println("Go!"); int n = fs.nextInt(); int m = fs.nextInt(); int[] rows = fs.nextIntArray(n); int[] cols = fs.nextIntArray(m); int xrow = 0, xcol = 0; for(int x : rows) xrow ^= x; for(int x : cols) xcol ^= x; int[][] res = new int[n][m]; for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { int ncol = xcol ^ cols[j]; int nrow = xrow ^ rows[i]; int n1 = ncol ^ rows[i]; int n2 = nrow ^ cols[j]; if(n1 == n2) { out.println("YES"); for(int k = 0; k < m; k++) { if(k == j) res[i][k] = n1; else res[i][k] = cols[k]; } for(int k = 0; k < n; k++) { if(k != i) res[k][j] = rows[k]; } for(int k = 0; k < n; k++) { for(int l = 0; l < m; l++) { out.print(res[k][l] + " "); } out.println(); } out.close(); return; } } } out.println("NO"); out.close(); } class FastScanner { public int BS = 1<<16; public char NC = (char)0; byte[] buf = new byte[BS]; int bId = 0, size = 0; char c = NC; double num = 1; BufferedInputStream in; public FastScanner() { in = new BufferedInputStream(System.in, BS); } public FastScanner(String s) throws FileNotFoundException { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } public char nextChar(){ while(bId==size) { try { size = in.read(buf); }catch(Exception e) { return NC; } if(size==-1)return NC; bId=0; } return (char)buf[bId++]; } public int nextInt() { return (int)nextLong(); } public long nextLong() { num=1; boolean neg = false; if(c==NC)c=nextChar(); for(;(c<'0' || c>'9'); c = nextChar()) { if(c=='-')neg=true; } long res = 0; for(; c>='0' && c <='9'; c=nextChar()) { res = (res<<3)+(res<<1)+c-'0'; num*=10; } return neg?-res:res; } public double nextDouble() { double cur = nextLong(); return c!='.' ? cur:cur+nextLong()/num; } public String next() { StringBuilder res = new StringBuilder(); while(c<=32)c=nextChar(); while(c>32) { res.append(c); c=nextChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while(c<=32)c=nextChar(); while(c!='\n') { res.append(c); c=nextChar(); } return res.toString(); } public boolean hasNext() { if(c>32)return true; while(true) { c=nextChar(); if(c==NC)return false; else if(c>32)return true; } } public int[] nextIntArray(int n) { int[] res = new int[n]; for(int i = 0; i < n; i++) res[i] = nextInt(); return res; } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
abf32b2eab723a2a758e7a381d56c01b
train_002.jsonl
1533307500
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
256 megabytes
import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; //XOR of any number by 0 will give number itself //when we XOR two same numbers we will get ans 0 public class EducationalRound48D { public static void main(String[] args) { // TODO Auto-generated method stub out=new PrintWriter(new BufferedOutputStream(System.out)); FastReader s=new FastReader(); int n=s.nextInt(); int m=s.nextInt(); int[] a=new int[n]; int[] b=new int[m]; long valueofa=0,valueofb=0; for(int i=0;i<n;i++) { a[i]=s.nextInt(); valueofa^=a[i]; } for(int i=0;i<m;i++) { b[i]=s.nextInt(); valueofb^=b[i]; } if(valueofa!=valueofb) { out.println("NO"); out.close(); return; } int[][] ans=new int[n][m]; //for 1rst element.... int temp=a[0]; for(int i=1;i<m;i++) { temp^=b[i]; } ans[0][0]=temp; for(int i=1;i<m;i++) { ans[0][i]=b[i]; } for(int i=1;i<(n);i++) { ans[i][0]=a[i]; } out.println("YES"); for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { out.print(ans[i][j]+" "); } out.println(); } out.close(); } public static PrintWriter out; public static class FastReader { BufferedReader br; StringTokenizer st; //it reads the data about the specified point and divide the data about it ,it is quite fast //than using direct public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next());//converts string to integer } double nextDouble() { return Double.parseDouble(next()); } long nextLong() { return Long.parseLong(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (Exception e) { e.printStackTrace(); } return str; } } }
Java
["2 3\n2 9\n5 3 13", "3 3\n1 7 6\n2 15 12"]
2 seconds
["YES\n3 4 5\n6 7 8", "NO"]
null
Java 8
standard input
[ "constructive algorithms", "flows", "math" ]
3815d18843dbd15a73383d69eb6880dd
The first line contains two numbers n and mΒ (2 ≀ n, m ≀ 100) β€” the dimensions of the matrix. The second line contains n numbers a1, a2, ..., anΒ (0 ≀ ai ≀ 109), where ai is the xor of all elements in row i. The third line contains m numbers b1, b2, ..., bmΒ (0 ≀ bi ≀ 109), where bi is the xor of all elements in column i.
1,800
If there is no matrix satisfying the given constraints in the first line, output "NO". Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cimΒ (0 ≀ cij ≀ 2Β·109) β€” the description of the matrix. If there are several suitable matrices, it is allowed to print any of them.
standard output
PASSED
0d029febaae670ee88e6f278c56dcf6d
train_002.jsonl
1538750100
Vasya has recently got a job as a cashier at a local store. His day at work is $$$L$$$ minutes long. Vasya has already memorized $$$n$$$ regular customers, the $$$i$$$-th of which comes after $$$t_{i}$$$ minutes after the beginning of the day, and his service consumes $$$l_{i}$$$ minutes. It is guaranteed that no customer will arrive while Vasya is servicing another customer. Vasya is a bit lazy, so he likes taking smoke breaks for $$$a$$$ minutes each. Those breaks may go one after another, but Vasya must be present at work during all the time periods he must serve regular customers, otherwise one of them may alert his boss. What is the maximum number of breaks Vasya can take during the day?
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class pre215 { 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[]) { FastReader obj = new FastReader(); int n = obj.nextInt(),L = obj.nextInt(),a = obj.nextInt(); if(n==0){System.out.println(L/a); return;} else { int t[] = new int[n],l[] = new int[n]; for(int i=0;i<n;i++) { t[i] = obj.nextInt(); l[i] = obj.nextInt(); } int count = 0,start=0; for(int i=0;i<n;i++) { count += (t[i]-start)/a; start = l[i]+t[i]; } count += (L-start)/a; System.out.println(count); } } }
Java
["2 11 3\n0 1\n1 1", "0 5 2", "1 3 2\n1 2"]
2 seconds
["3", "2", "0"]
NoteIn the first sample Vasya can take $$$3$$$ breaks starting after $$$2$$$, $$$5$$$ and $$$8$$$ minutes after the beginning of the day.In the second sample Vasya can take $$$2$$$ breaks starting after $$$0$$$ and $$$2$$$ minutes after the beginning of the day.In the third sample Vasya can't take any breaks.
Java 8
standard input
[ "implementation" ]
00acb3b54975820989a788b9389c7c0b
The first line contains three integers $$$n$$$, $$$L$$$ and $$$a$$$ ($$$0 \le n \le 10^{5}$$$, $$$1 \le L \le 10^{9}$$$, $$$1 \le a \le L$$$). The $$$i$$$-th of the next $$$n$$$ lines contains two integers $$$t_{i}$$$ and $$$l_{i}$$$ ($$$0 \le t_{i} \le L - 1$$$, $$$1 \le l_{i} \le L$$$). It is guaranteed that $$$t_{i} + l_{i} \le t_{i + 1}$$$ and $$$t_{n} + l_{n} \le L$$$.
1,000
Output one integer Β β€” the maximum number of breaks.
standard output
PASSED
fd4c37cb03174bb1d8c76d1b25b81ab2
train_002.jsonl
1538750100
Vasya has recently got a job as a cashier at a local store. His day at work is $$$L$$$ minutes long. Vasya has already memorized $$$n$$$ regular customers, the $$$i$$$-th of which comes after $$$t_{i}$$$ minutes after the beginning of the day, and his service consumes $$$l_{i}$$$ minutes. It is guaranteed that no customer will arrive while Vasya is servicing another customer. Vasya is a bit lazy, so he likes taking smoke breaks for $$$a$$$ minutes each. Those breaks may go one after another, but Vasya must be present at work during all the time periods he must serve regular customers, otherwise one of them may alert his boss. What is the maximum number of breaks Vasya can take during the day?
256 megabytes
import java.io.*; import java.util.*; public class ku { public static void main(String[] args) throws IOException { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int l=sc.nextInt(); int a=sc.nextInt(); Queue <cus> q=new LinkedList(); for(int i=0;i<n;i++) { int f=sc.nextInt(); int t=sc.nextInt(); q.add(new cus(f,t)); } int last=0; int num=0; int k=0; while(!q.isEmpty()) { cus cur=q.remove(); num+=(cur.from-k)/a; last=cur.to; k=cur.from+cur.to; }l=l-k; num=num+l/a; System.out.println(num); } static class cus implements Comparable<cus>{ int from; int to; cus(int f,int t){ from=f; to=t; } public String toString() { return from+" "+to; } public int compareTo(cus s) { return from-s.from; } } 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 boolean ready() throws IOException { return br.ready(); } public void waitForInput() throws InterruptedException { Thread.sleep(3000); } } }
Java
["2 11 3\n0 1\n1 1", "0 5 2", "1 3 2\n1 2"]
2 seconds
["3", "2", "0"]
NoteIn the first sample Vasya can take $$$3$$$ breaks starting after $$$2$$$, $$$5$$$ and $$$8$$$ minutes after the beginning of the day.In the second sample Vasya can take $$$2$$$ breaks starting after $$$0$$$ and $$$2$$$ minutes after the beginning of the day.In the third sample Vasya can't take any breaks.
Java 8
standard input
[ "implementation" ]
00acb3b54975820989a788b9389c7c0b
The first line contains three integers $$$n$$$, $$$L$$$ and $$$a$$$ ($$$0 \le n \le 10^{5}$$$, $$$1 \le L \le 10^{9}$$$, $$$1 \le a \le L$$$). The $$$i$$$-th of the next $$$n$$$ lines contains two integers $$$t_{i}$$$ and $$$l_{i}$$$ ($$$0 \le t_{i} \le L - 1$$$, $$$1 \le l_{i} \le L$$$). It is guaranteed that $$$t_{i} + l_{i} \le t_{i + 1}$$$ and $$$t_{n} + l_{n} \le L$$$.
1,000
Output one integer Β β€” the maximum number of breaks.
standard output
PASSED
da590885d34697db330e9d474dca38a3
train_002.jsonl
1538750100
Vasya has recently got a job as a cashier at a local store. His day at work is $$$L$$$ minutes long. Vasya has already memorized $$$n$$$ regular customers, the $$$i$$$-th of which comes after $$$t_{i}$$$ minutes after the beginning of the day, and his service consumes $$$l_{i}$$$ minutes. It is guaranteed that no customer will arrive while Vasya is servicing another customer. Vasya is a bit lazy, so he likes taking smoke breaks for $$$a$$$ minutes each. Those breaks may go one after another, but Vasya must be present at work during all the time periods he must serve regular customers, otherwise one of them may alert his boss. What is the maximum number of breaks Vasya can take during the day?
256 megabytes
import static java.lang.System.exit; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.Scanner; import java.util.*; /** * * @author abdelmagied */ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Scanner; import javafx.scene.Node; /** * * @author abdelmagied */ public class JavaApplication1 { /** * @param args the command line arguments */ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt() , l = sc.nextInt() , a = sc.nextInt(); int totalSmokeNumber = 0 , currentTime = 0; for(int i = 0 ; i < n ; i++){ int custArriveTime = sc.nextInt(); int serviceTimeNeeded = sc.nextInt(); totalSmokeNumber += (custArriveTime - currentTime) / a; currentTime = custArriveTime + serviceTimeNeeded; } totalSmokeNumber += (l - currentTime) / a; System.out.println(totalSmokeNumber); } }
Java
["2 11 3\n0 1\n1 1", "0 5 2", "1 3 2\n1 2"]
2 seconds
["3", "2", "0"]
NoteIn the first sample Vasya can take $$$3$$$ breaks starting after $$$2$$$, $$$5$$$ and $$$8$$$ minutes after the beginning of the day.In the second sample Vasya can take $$$2$$$ breaks starting after $$$0$$$ and $$$2$$$ minutes after the beginning of the day.In the third sample Vasya can't take any breaks.
Java 8
standard input
[ "implementation" ]
00acb3b54975820989a788b9389c7c0b
The first line contains three integers $$$n$$$, $$$L$$$ and $$$a$$$ ($$$0 \le n \le 10^{5}$$$, $$$1 \le L \le 10^{9}$$$, $$$1 \le a \le L$$$). The $$$i$$$-th of the next $$$n$$$ lines contains two integers $$$t_{i}$$$ and $$$l_{i}$$$ ($$$0 \le t_{i} \le L - 1$$$, $$$1 \le l_{i} \le L$$$). It is guaranteed that $$$t_{i} + l_{i} \le t_{i + 1}$$$ and $$$t_{n} + l_{n} \le L$$$.
1,000
Output one integer Β β€” the maximum number of breaks.
standard output
PASSED
f0b03ca51c31b2fcbc14700f5dcecfad
train_002.jsonl
1538750100
Vasya has recently got a job as a cashier at a local store. His day at work is $$$L$$$ minutes long. Vasya has already memorized $$$n$$$ regular customers, the $$$i$$$-th of which comes after $$$t_{i}$$$ minutes after the beginning of the day, and his service consumes $$$l_{i}$$$ minutes. It is guaranteed that no customer will arrive while Vasya is servicing another customer. Vasya is a bit lazy, so he likes taking smoke breaks for $$$a$$$ minutes each. Those breaks may go one after another, but Vasya must be present at work during all the time periods he must serve regular customers, otherwise one of them may alert his boss. What is the maximum number of breaks Vasya can take during the day?
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.ArrayList; import java.util.Arrays; import java.util.BitSet; import java.util.Collections; import java.util.Comparator; import java.util.Map; import java.util.PriorityQueue; import java.util.List; import java.util.StringTokenizer; import java.util.TreeMap; import java.util.TreeSet; public class Main { static int sum(long s){ int sum=0; while (s>0){ sum+=s%10; s/=10; } return sum; } public static void main(String[] args) throws IOException { Scanner in = new Scanner(System.in); try (PrintWriter or = new PrintWriter(System.out)) { int n = in.nextInt(); int l = in.nextInt(); int a= in.nextInt(); if (n==0&&a<=l){ or.println((int)l/a);return; }else if (a>l){ or.print(0);return; } ArrayList<Pair8> s= new ArrayList<>(); for (int i=0;i<n;++i){ int f=in.nextInt(),t=in.nextInt(); s.add(new Pair8(f,t+f)); } int ans=0; if (a<=s.get(0).from)ans+=s.get(0).from/a; int till=s.get(0).to; for (int i=1;i<n;++i){ if (a+till<=s.get(i).from&&a+till<=l){ ans+=(Math.abs(s.get(i).from-till)/a); } till= s.get(i).to; } ans+=((l-(till))/a); or.println(ans); } } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) { if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) { f *= 10; } } } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public boolean ready() throws IOException { return br.ready(); } } } class Pair8 { int from; int to; // int min; public Pair8(int from, int to) { this.from = from; this.to = to; //min = m; } }
Java
["2 11 3\n0 1\n1 1", "0 5 2", "1 3 2\n1 2"]
2 seconds
["3", "2", "0"]
NoteIn the first sample Vasya can take $$$3$$$ breaks starting after $$$2$$$, $$$5$$$ and $$$8$$$ minutes after the beginning of the day.In the second sample Vasya can take $$$2$$$ breaks starting after $$$0$$$ and $$$2$$$ minutes after the beginning of the day.In the third sample Vasya can't take any breaks.
Java 8
standard input
[ "implementation" ]
00acb3b54975820989a788b9389c7c0b
The first line contains three integers $$$n$$$, $$$L$$$ and $$$a$$$ ($$$0 \le n \le 10^{5}$$$, $$$1 \le L \le 10^{9}$$$, $$$1 \le a \le L$$$). The $$$i$$$-th of the next $$$n$$$ lines contains two integers $$$t_{i}$$$ and $$$l_{i}$$$ ($$$0 \le t_{i} \le L - 1$$$, $$$1 \le l_{i} \le L$$$). It is guaranteed that $$$t_{i} + l_{i} \le t_{i + 1}$$$ and $$$t_{n} + l_{n} \le L$$$.
1,000
Output one integer Β β€” the maximum number of breaks.
standard output
PASSED
6bcd686c351e4abf5159379b3d74d819
train_002.jsonl
1538750100
Vasya has recently got a job as a cashier at a local store. His day at work is $$$L$$$ minutes long. Vasya has already memorized $$$n$$$ regular customers, the $$$i$$$-th of which comes after $$$t_{i}$$$ minutes after the beginning of the day, and his service consumes $$$l_{i}$$$ minutes. It is guaranteed that no customer will arrive while Vasya is servicing another customer. Vasya is a bit lazy, so he likes taking smoke breaks for $$$a$$$ minutes each. Those breaks may go one after another, but Vasya must be present at work during all the time periods he must serve regular customers, otherwise one of them may alert his boss. What is the maximum number of breaks Vasya can take during the day?
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Scanner; public class CodeForces { public static void main(String[] args) { Scanner input = new Scanner(new BufferedReader(new InputStreamReader(System.in))); int n = input.nextInt(); int L = input.nextInt(); int a = input.nextInt(); int count = 0; int start = 0; for (int i = 0; i < n; i++) { int t = input.nextInt(); int l = input.nextInt(); count += (t - start) / a; start = t + l; } count += (L - start) / a; System.out.println(count); } }
Java
["2 11 3\n0 1\n1 1", "0 5 2", "1 3 2\n1 2"]
2 seconds
["3", "2", "0"]
NoteIn the first sample Vasya can take $$$3$$$ breaks starting after $$$2$$$, $$$5$$$ and $$$8$$$ minutes after the beginning of the day.In the second sample Vasya can take $$$2$$$ breaks starting after $$$0$$$ and $$$2$$$ minutes after the beginning of the day.In the third sample Vasya can't take any breaks.
Java 8
standard input
[ "implementation" ]
00acb3b54975820989a788b9389c7c0b
The first line contains three integers $$$n$$$, $$$L$$$ and $$$a$$$ ($$$0 \le n \le 10^{5}$$$, $$$1 \le L \le 10^{9}$$$, $$$1 \le a \le L$$$). The $$$i$$$-th of the next $$$n$$$ lines contains two integers $$$t_{i}$$$ and $$$l_{i}$$$ ($$$0 \le t_{i} \le L - 1$$$, $$$1 \le l_{i} \le L$$$). It is guaranteed that $$$t_{i} + l_{i} \le t_{i + 1}$$$ and $$$t_{n} + l_{n} \le L$$$.
1,000
Output one integer Β β€” the maximum number of breaks.
standard output
PASSED
3755a31c39ef23be03f95a4b1647cfa3
train_002.jsonl
1538750100
Vasya has recently got a job as a cashier at a local store. His day at work is $$$L$$$ minutes long. Vasya has already memorized $$$n$$$ regular customers, the $$$i$$$-th of which comes after $$$t_{i}$$$ minutes after the beginning of the day, and his service consumes $$$l_{i}$$$ minutes. It is guaranteed that no customer will arrive while Vasya is servicing another customer. Vasya is a bit lazy, so he likes taking smoke breaks for $$$a$$$ minutes each. Those breaks may go one after another, but Vasya must be present at work during all the time periods he must serve regular customers, otherwise one of them may alert his boss. What is the maximum number of breaks Vasya can take during the day?
256 megabytes
import java.util.Scanner; public class Cashier { public static void main(String[] args) { Scanner s = new Scanner(System.in); int m = s.nextInt(), n = s.nextInt(), a = s.nextInt(),arr[][]=new int[m][2],sec=0; long FinalAns=0; for (int i = 0; i < m; i++) { int first=s.nextInt(); FinalAns+=(first-sec)/a; sec=s.nextInt(); sec+=first; } FinalAns+=(n-sec)/a; System.out.println(FinalAns); } }
Java
["2 11 3\n0 1\n1 1", "0 5 2", "1 3 2\n1 2"]
2 seconds
["3", "2", "0"]
NoteIn the first sample Vasya can take $$$3$$$ breaks starting after $$$2$$$, $$$5$$$ and $$$8$$$ minutes after the beginning of the day.In the second sample Vasya can take $$$2$$$ breaks starting after $$$0$$$ and $$$2$$$ minutes after the beginning of the day.In the third sample Vasya can't take any breaks.
Java 8
standard input
[ "implementation" ]
00acb3b54975820989a788b9389c7c0b
The first line contains three integers $$$n$$$, $$$L$$$ and $$$a$$$ ($$$0 \le n \le 10^{5}$$$, $$$1 \le L \le 10^{9}$$$, $$$1 \le a \le L$$$). The $$$i$$$-th of the next $$$n$$$ lines contains two integers $$$t_{i}$$$ and $$$l_{i}$$$ ($$$0 \le t_{i} \le L - 1$$$, $$$1 \le l_{i} \le L$$$). It is guaranteed that $$$t_{i} + l_{i} \le t_{i + 1}$$$ and $$$t_{n} + l_{n} \le L$$$.
1,000
Output one integer Β β€” the maximum number of breaks.
standard output
PASSED
a9c44958d0734ad0504dfd9a05a7385e
train_002.jsonl
1538750100
Vasya has recently got a job as a cashier at a local store. His day at work is $$$L$$$ minutes long. Vasya has already memorized $$$n$$$ regular customers, the $$$i$$$-th of which comes after $$$t_{i}$$$ minutes after the beginning of the day, and his service consumes $$$l_{i}$$$ minutes. It is guaranteed that no customer will arrive while Vasya is servicing another customer. Vasya is a bit lazy, so he likes taking smoke breaks for $$$a$$$ minutes each. Those breaks may go one after another, but Vasya must be present at work during all the time periods he must serve regular customers, otherwise one of them may alert his boss. What is the maximum number of breaks Vasya can take during the day?
256 megabytes
import java.util.*; public class vasya { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int l=sc.nextInt(); int a=sc.nextInt(); long psum=0,ans=0; for(int i=0;i<n;i++) { int t=sc.nextInt(); int l1=sc.nextInt(); if((t-psum)>=a) ans=ans+((t-psum)/a); psum=t+l1; } if((l-psum)>=a) { ans=ans + ((l-psum)/a); } System.out.println(ans); } }
Java
["2 11 3\n0 1\n1 1", "0 5 2", "1 3 2\n1 2"]
2 seconds
["3", "2", "0"]
NoteIn the first sample Vasya can take $$$3$$$ breaks starting after $$$2$$$, $$$5$$$ and $$$8$$$ minutes after the beginning of the day.In the second sample Vasya can take $$$2$$$ breaks starting after $$$0$$$ and $$$2$$$ minutes after the beginning of the day.In the third sample Vasya can't take any breaks.
Java 8
standard input
[ "implementation" ]
00acb3b54975820989a788b9389c7c0b
The first line contains three integers $$$n$$$, $$$L$$$ and $$$a$$$ ($$$0 \le n \le 10^{5}$$$, $$$1 \le L \le 10^{9}$$$, $$$1 \le a \le L$$$). The $$$i$$$-th of the next $$$n$$$ lines contains two integers $$$t_{i}$$$ and $$$l_{i}$$$ ($$$0 \le t_{i} \le L - 1$$$, $$$1 \le l_{i} \le L$$$). It is guaranteed that $$$t_{i} + l_{i} \le t_{i + 1}$$$ and $$$t_{n} + l_{n} \le L$$$.
1,000
Output one integer Β β€” the maximum number of breaks.
standard output
PASSED
a44a6222ec1b0f3805752696eb7a441b
train_002.jsonl
1538750100
Vasya has recently got a job as a cashier at a local store. His day at work is $$$L$$$ minutes long. Vasya has already memorized $$$n$$$ regular customers, the $$$i$$$-th of which comes after $$$t_{i}$$$ minutes after the beginning of the day, and his service consumes $$$l_{i}$$$ minutes. It is guaranteed that no customer will arrive while Vasya is servicing another customer. Vasya is a bit lazy, so he likes taking smoke breaks for $$$a$$$ minutes each. Those breaks may go one after another, but Vasya must be present at work during all the time periods he must serve regular customers, otherwise one of them may alert his boss. What is the maximum number of breaks Vasya can take during the day?
256 megabytes
import java.io.IOException; import java.util.Scanner; public class P3 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); try { System.out.println(solve(scanner)); } catch (IOException e) { e.printStackTrace(); } } public static int solve(Scanner scanner) throws IOException { //Ignoro nΓΊmero de clientes. scanner.nextInt(); Integer dayTime = scanner.nextInt(); Integer breakLength = scanner.nextInt(); int currentTime = 0; int breakCount = 0; if(scanner.hasNextLine()) { scanner.nextLine(); while(scanner.hasNextInt()) { int initialTime = scanner.nextInt(); int duration = scanner.nextInt(); while(currentTime + breakLength <= initialTime) { currentTime += breakLength; breakCount++; } currentTime = initialTime + duration; } } while(currentTime + breakLength <= dayTime) { currentTime += breakLength; breakCount++; } return breakCount; } }
Java
["2 11 3\n0 1\n1 1", "0 5 2", "1 3 2\n1 2"]
2 seconds
["3", "2", "0"]
NoteIn the first sample Vasya can take $$$3$$$ breaks starting after $$$2$$$, $$$5$$$ and $$$8$$$ minutes after the beginning of the day.In the second sample Vasya can take $$$2$$$ breaks starting after $$$0$$$ and $$$2$$$ minutes after the beginning of the day.In the third sample Vasya can't take any breaks.
Java 8
standard input
[ "implementation" ]
00acb3b54975820989a788b9389c7c0b
The first line contains three integers $$$n$$$, $$$L$$$ and $$$a$$$ ($$$0 \le n \le 10^{5}$$$, $$$1 \le L \le 10^{9}$$$, $$$1 \le a \le L$$$). The $$$i$$$-th of the next $$$n$$$ lines contains two integers $$$t_{i}$$$ and $$$l_{i}$$$ ($$$0 \le t_{i} \le L - 1$$$, $$$1 \le l_{i} \le L$$$). It is guaranteed that $$$t_{i} + l_{i} \le t_{i + 1}$$$ and $$$t_{n} + l_{n} \le L$$$.
1,000
Output one integer Β β€” the maximum number of breaks.
standard output
PASSED
8838455ed6b3ace5bdbc33135698af40
train_002.jsonl
1538750100
Vasya has recently got a job as a cashier at a local store. His day at work is $$$L$$$ minutes long. Vasya has already memorized $$$n$$$ regular customers, the $$$i$$$-th of which comes after $$$t_{i}$$$ minutes after the beginning of the day, and his service consumes $$$l_{i}$$$ minutes. It is guaranteed that no customer will arrive while Vasya is servicing another customer. Vasya is a bit lazy, so he likes taking smoke breaks for $$$a$$$ minutes each. Those breaks may go one after another, but Vasya must be present at work during all the time periods he must serve regular customers, otherwise one of them may alert his boss. What is the maximum number of breaks Vasya can take during the day?
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int L = sc.nextInt(); int a = sc.nextInt(); int[] customerTime = new int[n]; int[] serviceTime = new int[n]; for (int i = 0; i < n; i++) { customerTime[i] = sc.nextInt(); serviceTime[i] = sc.nextInt(); } int result = 0; if (n == 0) { result += L / a; } else { int i = 0; //System.out.println(i + "," + (customerTime[i] - 0)); result += (customerTime[i] - 0) / a; for (i = 0; i < n - 1; i++) { //System.out.println(i + "," + (customerTime[i+1] - (customerTime[i] + serviceTime[i]))); result += (customerTime[i+1] - (customerTime[i] + serviceTime[i])) / a; } if (i < n) { //System.out.println(i + "," + (L - (customerTime[i] + serviceTime[i]))); result += (L - (customerTime[i] + serviceTime[i])) / a; } } System.out.println(result); } }
Java
["2 11 3\n0 1\n1 1", "0 5 2", "1 3 2\n1 2"]
2 seconds
["3", "2", "0"]
NoteIn the first sample Vasya can take $$$3$$$ breaks starting after $$$2$$$, $$$5$$$ and $$$8$$$ minutes after the beginning of the day.In the second sample Vasya can take $$$2$$$ breaks starting after $$$0$$$ and $$$2$$$ minutes after the beginning of the day.In the third sample Vasya can't take any breaks.
Java 8
standard input
[ "implementation" ]
00acb3b54975820989a788b9389c7c0b
The first line contains three integers $$$n$$$, $$$L$$$ and $$$a$$$ ($$$0 \le n \le 10^{5}$$$, $$$1 \le L \le 10^{9}$$$, $$$1 \le a \le L$$$). The $$$i$$$-th of the next $$$n$$$ lines contains two integers $$$t_{i}$$$ and $$$l_{i}$$$ ($$$0 \le t_{i} \le L - 1$$$, $$$1 \le l_{i} \le L$$$). It is guaranteed that $$$t_{i} + l_{i} \le t_{i + 1}$$$ and $$$t_{n} + l_{n} \le L$$$.
1,000
Output one integer Β β€” the maximum number of breaks.
standard output
PASSED
c73e63f1dd5db294660dc72d721803c4
train_002.jsonl
1538750100
Vasya has recently got a job as a cashier at a local store. His day at work is $$$L$$$ minutes long. Vasya has already memorized $$$n$$$ regular customers, the $$$i$$$-th of which comes after $$$t_{i}$$$ minutes after the beginning of the day, and his service consumes $$$l_{i}$$$ minutes. It is guaranteed that no customer will arrive while Vasya is servicing another customer. Vasya is a bit lazy, so he likes taking smoke breaks for $$$a$$$ minutes each. Those breaks may go one after another, but Vasya must be present at work during all the time periods he must serve regular customers, otherwise one of them may alert his boss. What is the maximum number of breaks Vasya can take during the day?
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { static class Reader { static BufferedReader br; static StringTokenizer st; public Reader() { this.br = new BufferedReader(new InputStreamReader(System.in)); } public int nextInt() throws Exception { if (st == null || !st.hasMoreTokens()) readLine(); return Integer.parseInt(st.nextToken()); } public Long nextLong() throws Exception { if (st == null || !st.hasMoreTokens()) readLine(); return Long.parseLong(st.nextToken()); } public static void readLine() throws Exception { st = new StringTokenizer(br.readLine()); } } public static void main(String[] args) throws Exception { Reader in = new Reader(); int n = in.nextInt(); int L = in.nextInt(); int a = in.nextInt(); int[] t1 = new int[n]; int[] t2 = new int[n]; for(int i = 0; i<n; i++) { t1[i] = in.nextInt(); t2[i] = in.nextInt(); } int ans = 0; int last = 0; for(int i = 0; i<n; i++) { ans+=(t1[i]-last)/a; last = t1[i]+t2[i]; } ans+=(L-last)/a; System.out.println(ans); } }
Java
["2 11 3\n0 1\n1 1", "0 5 2", "1 3 2\n1 2"]
2 seconds
["3", "2", "0"]
NoteIn the first sample Vasya can take $$$3$$$ breaks starting after $$$2$$$, $$$5$$$ and $$$8$$$ minutes after the beginning of the day.In the second sample Vasya can take $$$2$$$ breaks starting after $$$0$$$ and $$$2$$$ minutes after the beginning of the day.In the third sample Vasya can't take any breaks.
Java 8
standard input
[ "implementation" ]
00acb3b54975820989a788b9389c7c0b
The first line contains three integers $$$n$$$, $$$L$$$ and $$$a$$$ ($$$0 \le n \le 10^{5}$$$, $$$1 \le L \le 10^{9}$$$, $$$1 \le a \le L$$$). The $$$i$$$-th of the next $$$n$$$ lines contains two integers $$$t_{i}$$$ and $$$l_{i}$$$ ($$$0 \le t_{i} \le L - 1$$$, $$$1 \le l_{i} \le L$$$). It is guaranteed that $$$t_{i} + l_{i} \le t_{i + 1}$$$ and $$$t_{n} + l_{n} \le L$$$.
1,000
Output one integer Β β€” the maximum number of breaks.
standard output
PASSED
7c363b293963ae5656059bdc33949484
train_002.jsonl
1538750100
Vasya has recently got a job as a cashier at a local store. His day at work is $$$L$$$ minutes long. Vasya has already memorized $$$n$$$ regular customers, the $$$i$$$-th of which comes after $$$t_{i}$$$ minutes after the beginning of the day, and his service consumes $$$l_{i}$$$ minutes. It is guaranteed that no customer will arrive while Vasya is servicing another customer. Vasya is a bit lazy, so he likes taking smoke breaks for $$$a$$$ minutes each. Those breaks may go one after another, but Vasya must be present at work during all the time periods he must serve regular customers, otherwise one of them may alert his boss. What is the maximum number of breaks Vasya can take during the day?
256 megabytes
/*package whatever //do not write package name here */ import java.util.*; import java.lang.*; import java.io.*; public class first { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int L = sc.nextInt(); int a = sc.nextInt(); int[] t = new int[n]; int[] l = new int[n]; for(int i = 0;i<n;i++) { t[i] = sc.nextInt(); l[i] = sc.nextInt(); } int counter = 0; int counter_1 = 0; int status =0 ; int sum = 0; while(counter<L) { if(counter_1<n && counter==t[counter_1]) { counter = counter + l[counter_1]; counter_1++; sum = sum + (status/a); status = 0; continue; } else { status++; } counter++; } sum = sum + status/a; System.out.println(sum); } }
Java
["2 11 3\n0 1\n1 1", "0 5 2", "1 3 2\n1 2"]
2 seconds
["3", "2", "0"]
NoteIn the first sample Vasya can take $$$3$$$ breaks starting after $$$2$$$, $$$5$$$ and $$$8$$$ minutes after the beginning of the day.In the second sample Vasya can take $$$2$$$ breaks starting after $$$0$$$ and $$$2$$$ minutes after the beginning of the day.In the third sample Vasya can't take any breaks.
Java 8
standard input
[ "implementation" ]
00acb3b54975820989a788b9389c7c0b
The first line contains three integers $$$n$$$, $$$L$$$ and $$$a$$$ ($$$0 \le n \le 10^{5}$$$, $$$1 \le L \le 10^{9}$$$, $$$1 \le a \le L$$$). The $$$i$$$-th of the next $$$n$$$ lines contains two integers $$$t_{i}$$$ and $$$l_{i}$$$ ($$$0 \le t_{i} \le L - 1$$$, $$$1 \le l_{i} \le L$$$). It is guaranteed that $$$t_{i} + l_{i} \le t_{i + 1}$$$ and $$$t_{n} + l_{n} \le L$$$.
1,000
Output one integer Β β€” the maximum number of breaks.
standard output
PASSED
efb7f2cdff2b9b4e00b7a90fb31f9b88
train_002.jsonl
1538750100
Vasya has recently got a job as a cashier at a local store. His day at work is $$$L$$$ minutes long. Vasya has already memorized $$$n$$$ regular customers, the $$$i$$$-th of which comes after $$$t_{i}$$$ minutes after the beginning of the day, and his service consumes $$$l_{i}$$$ minutes. It is guaranteed that no customer will arrive while Vasya is servicing another customer. Vasya is a bit lazy, so he likes taking smoke breaks for $$$a$$$ minutes each. Those breaks may go one after another, but Vasya must be present at work during all the time periods he must serve regular customers, otherwise one of them may alert his boss. What is the maximum number of breaks Vasya can take during the day?
256 megabytes
import java.util.ArrayList; import java.util.Scanner; public class Main { static Scanner sc = new Scanner(System.in); static long n, l, a; static ArrayList<Consumer> consumers = new ArrayList<>(); static boolean hasCons = false; static long sumLi; public static void main(String[] args) { initData(); if (hasCons) { long currentTime = 0; long a_count = 0; Consumer consumerFirst = consumers.get(0); a_count += consumerFirst.ti / a; currentTime = consumerFirst.ti + consumerFirst.li; for (int i = 1; i < n; i++) { Consumer consumer = consumers.get(i); a_count += (consumer.ti - currentTime) / a; currentTime = consumer.ti + consumer.li; } long ost = l - currentTime; a_count += ost / a; System.out.println(a_count); return; } System.out.println(l / a); } private static void initData() { String data = sc.nextLine(); String[] datas1 = data.split(" "); n = Long.parseLong(datas1[0]); l = Long.parseLong(datas1[1]); a = Long.parseLong(datas1[2]); if (n != 0) { hasCons = true; for (int i = 0; i < n; i++) { data = sc.nextLine(); String[] datas2 = data.split(" "); Consumer consumer = new Consumer(); consumer.ti = Long.parseLong(datas2[0]); consumer.li = Long.parseLong(datas2[1]); sumLi += consumer.li; consumers.add(consumer); } } } static class Consumer { long ti, li; } }
Java
["2 11 3\n0 1\n1 1", "0 5 2", "1 3 2\n1 2"]
2 seconds
["3", "2", "0"]
NoteIn the first sample Vasya can take $$$3$$$ breaks starting after $$$2$$$, $$$5$$$ and $$$8$$$ minutes after the beginning of the day.In the second sample Vasya can take $$$2$$$ breaks starting after $$$0$$$ and $$$2$$$ minutes after the beginning of the day.In the third sample Vasya can't take any breaks.
Java 8
standard input
[ "implementation" ]
00acb3b54975820989a788b9389c7c0b
The first line contains three integers $$$n$$$, $$$L$$$ and $$$a$$$ ($$$0 \le n \le 10^{5}$$$, $$$1 \le L \le 10^{9}$$$, $$$1 \le a \le L$$$). The $$$i$$$-th of the next $$$n$$$ lines contains two integers $$$t_{i}$$$ and $$$l_{i}$$$ ($$$0 \le t_{i} \le L - 1$$$, $$$1 \le l_{i} \le L$$$). It is guaranteed that $$$t_{i} + l_{i} \le t_{i + 1}$$$ and $$$t_{n} + l_{n} \le L$$$.
1,000
Output one integer Β β€” the maximum number of breaks.
standard output
PASSED
9cdcb2f0247e6d9ec2435c93af77b385
train_002.jsonl
1538750100
Vasya has recently got a job as a cashier at a local store. His day at work is $$$L$$$ minutes long. Vasya has already memorized $$$n$$$ regular customers, the $$$i$$$-th of which comes after $$$t_{i}$$$ minutes after the beginning of the day, and his service consumes $$$l_{i}$$$ minutes. It is guaranteed that no customer will arrive while Vasya is servicing another customer. Vasya is a bit lazy, so he likes taking smoke breaks for $$$a$$$ minutes each. Those breaks may go one after another, but Vasya must be present at work during all the time periods he must serve regular customers, otherwise one of them may alert his boss. What is the maximum number of breaks Vasya can take during the day?
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner s=new Scanner(System.in); int n=s.nextInt(); int l=s.nextInt(); int a=s.nextInt(); int ct=0; int prev=0; for(int i=0;i<n;i++) { int x=s.nextInt(); int y=s.nextInt(); if(x-prev>=a) ct=ct+((x-prev)/a); prev=x+y; } if(l-prev>=a) ct=ct+((l-prev)/a); System.out.println(ct); } }
Java
["2 11 3\n0 1\n1 1", "0 5 2", "1 3 2\n1 2"]
2 seconds
["3", "2", "0"]
NoteIn the first sample Vasya can take $$$3$$$ breaks starting after $$$2$$$, $$$5$$$ and $$$8$$$ minutes after the beginning of the day.In the second sample Vasya can take $$$2$$$ breaks starting after $$$0$$$ and $$$2$$$ minutes after the beginning of the day.In the third sample Vasya can't take any breaks.
Java 8
standard input
[ "implementation" ]
00acb3b54975820989a788b9389c7c0b
The first line contains three integers $$$n$$$, $$$L$$$ and $$$a$$$ ($$$0 \le n \le 10^{5}$$$, $$$1 \le L \le 10^{9}$$$, $$$1 \le a \le L$$$). The $$$i$$$-th of the next $$$n$$$ lines contains two integers $$$t_{i}$$$ and $$$l_{i}$$$ ($$$0 \le t_{i} \le L - 1$$$, $$$1 \le l_{i} \le L$$$). It is guaranteed that $$$t_{i} + l_{i} \le t_{i + 1}$$$ and $$$t_{n} + l_{n} \le L$$$.
1,000
Output one integer Β β€” the maximum number of breaks.
standard output
PASSED
9a753f405cf11941c1be6faabfb9bcb4
train_002.jsonl
1538750100
Vasya has recently got a job as a cashier at a local store. His day at work is $$$L$$$ minutes long. Vasya has already memorized $$$n$$$ regular customers, the $$$i$$$-th of which comes after $$$t_{i}$$$ minutes after the beginning of the day, and his service consumes $$$l_{i}$$$ minutes. It is guaranteed that no customer will arrive while Vasya is servicing another customer. Vasya is a bit lazy, so he likes taking smoke breaks for $$$a$$$ minutes each. Those breaks may go one after another, but Vasya must be present at work during all the time periods he must serve regular customers, otherwise one of them may alert his boss. What is the maximum number of breaks Vasya can take during the day?
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; inclass in = new inclass(inputStream); PrintWriter out = new PrintWriter(outputStream); ACashier solver = new ACashier(); solver.solve(1, in, out); out.close(); } static class ACashier { public void solve(int testNumber, inclass in, PrintWriter out) { int n = in.nextInt(), daylong = in.nextInt(), breaklong = in.nextInt(); long sum = 0; long prev = 0; long ans = 0; for (int i = 0; i < n; i++) { int a = in.nextInt(), b = in.nextInt(); sum = (a - prev); ans += (sum / breaklong); prev = (long) a + (long) b; } ans += (daylong - prev) / breaklong; out.print(ans); } } static class inclass { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private inclass.SpaceCharFilter filter; public inclass(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
Java
["2 11 3\n0 1\n1 1", "0 5 2", "1 3 2\n1 2"]
2 seconds
["3", "2", "0"]
NoteIn the first sample Vasya can take $$$3$$$ breaks starting after $$$2$$$, $$$5$$$ and $$$8$$$ minutes after the beginning of the day.In the second sample Vasya can take $$$2$$$ breaks starting after $$$0$$$ and $$$2$$$ minutes after the beginning of the day.In the third sample Vasya can't take any breaks.
Java 8
standard input
[ "implementation" ]
00acb3b54975820989a788b9389c7c0b
The first line contains three integers $$$n$$$, $$$L$$$ and $$$a$$$ ($$$0 \le n \le 10^{5}$$$, $$$1 \le L \le 10^{9}$$$, $$$1 \le a \le L$$$). The $$$i$$$-th of the next $$$n$$$ lines contains two integers $$$t_{i}$$$ and $$$l_{i}$$$ ($$$0 \le t_{i} \le L - 1$$$, $$$1 \le l_{i} \le L$$$). It is guaranteed that $$$t_{i} + l_{i} \le t_{i + 1}$$$ and $$$t_{n} + l_{n} \le L$$$.
1,000
Output one integer Β β€” the maximum number of breaks.
standard output