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
af14bde3ef939f63275052e48e3d3f46
train_003.jsonl
1400167800
You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: A substring s[i..j] (1 ≀ i ≀ j ≀ |s|) of string s is string sisi + 1...sj. The prefix of string s of length l (1 ≀ l ≀ |s|) is string s[1..l]. The suffix of string s of length l (1 ≀ l ≀ |s|) is string s[|s| - l + 1..|s|]. Your task is, for any prefix of string s which matches a suffix of string s, print the number of times it occurs in string s as a substring.
256 megabytes
import java.util.*; import java.io.*; public class ZalgorithmString { public static void main(String[] args) throws Exception{ BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); String a = bf.readLine().trim(); int[] z = calculateZ(a.toCharArray()); int[] freq = new int[z.length+1]; for(int i = 1;i<z.length;i++){ freq[z[i]]++; } freq[z.length]++; TreeSet<Integer> set = new TreeSet<Integer>(); for(int j = z.length-1;j>0;j--){ if (z[j] == z.length-j) set.add(z[j]); } set.add(z.length); int sum = 0; ArrayList<Integer> ab = new ArrayList<Integer>(); ArrayList<Integer> b = new ArrayList<Integer>(); int prev = z.length+1; for(int i : set.descendingSet()){ for(int j = i;j<prev;j++) sum+=freq[j]; prev = i; ab.add(i); b.add(sum); } out.println(ab.size()); Collections.reverse(ab); Collections.reverse(b); for(int i = 0;i<ab.size();i++){ out.println(ab.get(i) + " " + b.get(i)); } out.close(); } public static int[] calculateZ(char input[]) { //this is an array where the value at index i is the length of the longest prefix subsequence starting at 0 and i that match int Z[] = new int[input.length]; int left = 0; int right = 0; for(int k = 1; k < input.length; k++) { if(k > right) { left = right = k; while(right < input.length && input[right] == input[right - left]) { right++; } Z[k] = right - left; right--; } else { //we are operating inside box int k1 = k - left; //if value does not stretches till right bound then just copy it. if(Z[k1] < right - k + 1) { Z[k] = Z[k1]; } else { //otherwise try to see if there are more matches. left = k; while(right < input.length && input[right] == input[right - left]) { right++; } Z[k] = right - left; right--; } } } return Z; } }
Java
["ABACABA", "AAA"]
1 second
["3\n1 4\n3 2\n7 1", "3\n1 3\n2 2\n3 1"]
null
Java 8
standard input
[ "dp", "two pointers", "string suffix structures", "strings" ]
3fb70a77e4de4851ed93f988140df221
The single line contains a sequence of characters s1s2...s|s| (1 ≀ |s| ≀ 105) β€” string s. The string only consists of uppercase English letters.
2,000
In the first line, print integer k (0 ≀ k ≀ |s|) β€” the number of prefixes that match a suffix of string s. Next print k lines, in each line print two integers li ci. Numbers li ci mean that the prefix of the length li matches the suffix of length li and occurs in string s as a substring ci times. Print pairs li ci in the order of increasing li.
standard output
PASSED
1425733250243464f2afc17f6424b71e
train_003.jsonl
1400167800
You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: A substring s[i..j] (1 ≀ i ≀ j ≀ |s|) of string s is string sisi + 1...sj. The prefix of string s of length l (1 ≀ l ≀ |s|) is string s[1..l]. The suffix of string s of length l (1 ≀ l ≀ |s|) is string s[|s| - l + 1..|s|]. Your task is, for any prefix of string s which matches a suffix of string s, print the number of times it occurs in string s as a substring.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; public class PrefixesAndSuffixes { static int [] z(String str) { char s[] = str.toCharArray(); int n = s.length; int z[] = new int[n]; for(int i = 1, L = 0, R = 0; i < n; ++i) { if(R < i) { L = R = i; while(R < n && s[R - L] == s[R]) R++; z[i] = R - L; R--; } else { int k = i - L; if(i + z[k] <= R) z[i] = z[k]; else { L = i; while(R < n && s[R] == s[R - L]) R++; z[i] = R - L; R--; } } } return z; } public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringBuilder out = new StringBuilder(); String s = in.readLine(); int[] z = z(s); z[0] = z.length; // System.out.println(Arrays.toString(z)); int[] occ = new int[1000000]; for (int i = 0; i < z.length; i++) { occ[z[i]]++; } for (int i = occ.length - 2; i >= 0; i--) { occ[i] = occ[i + 1] + occ[i]; } int res = 0; for (int i = z.length - 1; i >= 0; i--) { if(z[i] + i == z.length) { res++; out.append(z[i] + " " + occ[z[i]] + "\n"); } } System.out.println(res); System.out.println(out); } }
Java
["ABACABA", "AAA"]
1 second
["3\n1 4\n3 2\n7 1", "3\n1 3\n2 2\n3 1"]
null
Java 8
standard input
[ "dp", "two pointers", "string suffix structures", "strings" ]
3fb70a77e4de4851ed93f988140df221
The single line contains a sequence of characters s1s2...s|s| (1 ≀ |s| ≀ 105) β€” string s. The string only consists of uppercase English letters.
2,000
In the first line, print integer k (0 ≀ k ≀ |s|) β€” the number of prefixes that match a suffix of string s. Next print k lines, in each line print two integers li ci. Numbers li ci mean that the prefix of the length li matches the suffix of length li and occurs in string s as a substring ci times. Print pairs li ci in the order of increasing li.
standard output
PASSED
cf67c39659adf08ae0c4163c8b7a055e
train_003.jsonl
1400167800
You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: A substring s[i..j] (1 ≀ i ≀ j ≀ |s|) of string s is string sisi + 1...sj. The prefix of string s of length l (1 ≀ l ≀ |s|) is string s[1..l]. The suffix of string s of length l (1 ≀ l ≀ |s|) is string s[|s| - l + 1..|s|]. Your task is, for any prefix of string s which matches a suffix of string s, print the number of times it occurs in string s as a substring.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; public class PrefixesAndSuffixes { public static int[] z(String s) { int n = s.length(); int[] res = new int[n]; int l, r; l = r = 0; for (int i = 1; i < n; i++) { if(i > r) { l = r = i; while(r < n && s.charAt(r) == s.charAt(r - l)) r++; res[i] = r - l; r--; } else { if(res[i - l] + i <= r) { res[i] = res[i - l]; } else { l = i; while(r < n && s.charAt(r) == s.charAt(r - l)) r++; res[i] = r - l; r--; } } } return res; } public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringBuilder out = new StringBuilder(); String s = in.readLine(); int[] z = z(s); z[0] = z.length; // System.out.println(Arrays.toString(z)); int[] occ = new int[1000000]; for (int i = 0; i < z.length; i++) { occ[z[i]]++; } for (int i = occ.length - 2; i >= 0; i--) { occ[i] = occ[i + 1] + occ[i]; } int res = 0; for (int i = z.length - 1; i >= 0; i--) { if(z[i] + i == z.length) { res++; out.append(z[i] + " " + occ[z[i]] + "\n"); } } System.out.println(res); System.out.println(out); } }
Java
["ABACABA", "AAA"]
1 second
["3\n1 4\n3 2\n7 1", "3\n1 3\n2 2\n3 1"]
null
Java 8
standard input
[ "dp", "two pointers", "string suffix structures", "strings" ]
3fb70a77e4de4851ed93f988140df221
The single line contains a sequence of characters s1s2...s|s| (1 ≀ |s| ≀ 105) β€” string s. The string only consists of uppercase English letters.
2,000
In the first line, print integer k (0 ≀ k ≀ |s|) β€” the number of prefixes that match a suffix of string s. Next print k lines, in each line print two integers li ci. Numbers li ci mean that the prefix of the length li matches the suffix of length li and occurs in string s as a substring ci times. Print pairs li ci in the order of increasing li.
standard output
PASSED
162de0fb7cb97dd059caedb64064261a
train_003.jsonl
1400167800
You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: A substring s[i..j] (1 ≀ i ≀ j ≀ |s|) of string s is string sisi + 1...sj. The prefix of string s of length l (1 ≀ l ≀ |s|) is string s[1..l]. The suffix of string s of length l (1 ≀ l ≀ |s|) is string s[|s| - l + 1..|s|]. Your task is, for any prefix of string s which matches a suffix of string s, print the number of times it occurs in string s as a substring.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.Collection; import java.util.LinkedList; import java.util.Locale; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException { new Thread(null, new Runnable() { public void run() { try { long prevTime = System.currentTimeMillis(); new Main().run(); System.err.println("Total time: " + (System.currentTimeMillis() - prevTime) + " ms"); System.err.println("Memory status: " + memoryStatus()); } catch (IOException e) { e.printStackTrace(); } } }, "1", 1L << 24).start(); } void run() throws IOException { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); Object o = solve(); if (o != null) out.println(o); out.close(); in.close(); } private Object solve() throws IOException { String s = in.readLine(); int n = s.length(); int[] p = new int[n+1]; for(int len=2;len<=n;len++){ int prev = p[len-1]; while(true){ if(s.charAt(prev)==s.charAt(len-1)){ p[len]=1+prev; break; } if(prev==0) break; prev = p[prev]; } } int[] cnt = new int[n+1]; Arrays.fill(cnt, 1); for(int len = n;len>0;len--){ cnt[p[len]]+=cnt[len]; } LinkedList<Integer> ret = new LinkedList<Integer>(); int k =n; while(k>0){ ret.addFirst(k); k = p[k]; } pln(ret.size()); for(int a : ret) pln(a +" "+ cnt[a]); return null; } BufferedReader in; PrintWriter out; StringTokenizer strTok = new StringTokenizer(""); String nextToken() throws IOException { while (!strTok.hasMoreTokens()) strTok = new StringTokenizer(in.readLine()); return strTok.nextToken(); } int ni() throws IOException { return Integer.parseInt(nextToken()); } long nl() throws IOException { return Long.parseLong(nextToken()); } double nd() throws IOException { return Double.parseDouble(nextToken()); } int[] nia(int size) throws IOException { int[] ret = new int[size]; for (int i = 0; i < size; i++) ret[i] = ni(); return ret; } long[] nla(int size) throws IOException { long[] ret = new long[size]; for (int i = 0; i < size; i++) ret[i] = nl(); return ret; } double[] nda(int size) throws IOException { double[] ret = new double[size]; for (int i = 0; i < size; i++) ret[i] = nd(); return ret; } String nextLine() throws IOException { strTok = new StringTokenizer(""); return in.readLine(); } boolean EOF() throws IOException { while (!strTok.hasMoreTokens()) { String s = in.readLine(); if (s == null) return true; strTok = new StringTokenizer(s); } return false; } void printRepeat(String s, int count) { for (int i = 0; i < count; i++) out.print(s); } void printArray(int[] array) { for (int i = 0; i < array.length; i++) { if (i > 0) out.print(' '); out.print(array[i]); } out.println(); } void printArray(long[] array) { for (int i = 0; i < array.length; i++) { if (i > 0) out.print(' '); out.print(array[i]); } out.println(); } void printArray(double[] array) { for (int i = 0; i < array.length; i++) { if (i > 0) out.print(' '); out.print(array[i]); } out.println(); } void printArray(double[] array, String spec) { for (int i = 0; i < array.length; i++) { if (i > 0) out.print(' '); out.printf(Locale.US, spec, array[i]); } out.println(); } void printArray(Object[] array) { boolean blank = false; for (Object x : array) { if (blank) out.print(' '); else blank = true; out.print(x); } out.println(); } @SuppressWarnings("rawtypes") void printCollection(Collection collection) { boolean blank = false; for (Object x : collection) { if (blank) out.print(' '); else blank = true; out.print(x); } out.println(); } static String memoryStatus() { return (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory() >> 20) + "/" + (Runtime.getRuntime().totalMemory() >> 20) + " MB"; } public void pln() { out.println(); } public void pln(int arg) { out.println(arg); } public void pln(long arg) { out.println(arg); } public void pln(double arg) { out.println(arg); } public void pln(String arg) { out.println(arg); } public void pln(boolean arg) { out.println(arg); } public void pln(char arg) { out.println(arg); } public void pln(float arg) { out.println(arg); } public void pln(Object arg) { out.println(arg); } public void p(int arg) { out.print(arg); } public void p(long arg) { out.print(arg); } public void p(double arg) { out.print(arg); } public void p(String arg) { out.print(arg); } public void p(boolean arg) { out.print(arg); } public void p(char arg) { out.print(arg); } public void p(float arg) { out.print(arg); } public void p(Object arg) { out.print(arg); } }
Java
["ABACABA", "AAA"]
1 second
["3\n1 4\n3 2\n7 1", "3\n1 3\n2 2\n3 1"]
null
Java 8
standard input
[ "dp", "two pointers", "string suffix structures", "strings" ]
3fb70a77e4de4851ed93f988140df221
The single line contains a sequence of characters s1s2...s|s| (1 ≀ |s| ≀ 105) β€” string s. The string only consists of uppercase English letters.
2,000
In the first line, print integer k (0 ≀ k ≀ |s|) β€” the number of prefixes that match a suffix of string s. Next print k lines, in each line print two integers li ci. Numbers li ci mean that the prefix of the length li matches the suffix of length li and occurs in string s as a substring ci times. Print pairs li ci in the order of increasing li.
standard output
PASSED
de4e7c935c761ee97b4a745d269473f3
train_003.jsonl
1400167800
You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: A substring s[i..j] (1 ≀ i ≀ j ≀ |s|) of string s is string sisi + 1...sj. The prefix of string s of length l (1 ≀ l ≀ |s|) is string s[1..l]. The suffix of string s of length l (1 ≀ l ≀ |s|) is string s[|s| - l + 1..|s|]. Your task is, for any prefix of string s which matches a suffix of string s, print the number of times it occurs in string s as a substring.
256 megabytes
/** * Created by Aminul on 10/17/2017. */ import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; public class CF432D { public static int n; static char [] s; public static void main(String[] args)throws Exception { FastReader in = new FastReader(System.in); PrintWriter pw = new PrintWriter(System.out); s = in.nextCharArray(); n = s.length; int z[] = Z_array(); z[0] = n; long count[] = new long[n+1]; boolean valid[] = new boolean[n+1]; // debug(z); int cnt = 0; for(int i = 0; i < n; i++){ if(i + z[i] == n) { cnt++; valid[z[i]] = true; } count[z[i]]++; } long s = 0; for(int i = n; i >= 1; i--){ count[i] += s; s = count[i]; } pw.println(cnt); for(int i = 1; i <= n; i++){ if(valid[i]){ pw.println(i+" "+count[i]); } } pw.close(); } static int[] Z_array(){ int L = 0, R = 0, z[] = new int[n]; for (int i = 1; i < n; i++) { if (i > R) { L = R = i; while (R < n && s[R-L] == s[R]) R++; z[i] = R-L; R--; } else { int k = i-L; if (z[k] < R-i+1) z[i] = z[k]; else { L = i; while (R < n && s[R-L] == s[R]) R++; z[i] = R-L; R--; } } } return z; } static void debug(Object...obj) { System.err.println(Arrays.deepToString(obj)); } static class FastReader { InputStream is; private byte[] inbuf = new byte[1024]; private int lenbuf = 0, ptrbuf = 0; static final int ints[] = new int[128]; public FastReader(InputStream is){ for(int i='0';i<='9';i++) ints[i]=i-'0'; this.is = is; } public int readByte(){ if(lenbuf == -1)throw new InputMismatchException(); if(ptrbuf >= lenbuf){ ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if(lenbuf <= 0)return -1; } return inbuf[ptrbuf++]; } public boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } public int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; } public String next(){ int b = skip(); StringBuilder sb = new StringBuilder(); while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public int nextInt(){ int num = 0, b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-'){ minus = true; b = readByte(); } while(true){ if(b >= '0' && b <= '9'){ num = (num<<3) + (num<<1) + ints[b]; }else{ return minus ? -num : num; } b = readByte(); } } public long nextLong() { long num = 0; int b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-'){ minus = true; b = readByte(); } while(true){ if(b >= '0' && b <= '9'){ num = (num<<3) + (num<<1) + ints[b]; }else{ return minus ? -num : num; } b = readByte(); } } public double nextDouble() { return Double.parseDouble(next()); } /* public char nextChar() { return (char)skip(); }*/ public char[] next(int n){ char[] buf = new char[n]; int b = skip(), p = 0; while(p < n && !(isSpaceChar(b))){ buf[p++] = (char)b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } private char buff[] = new char[100005]; public char[] nextCharArray(){ int b = skip(), p = 0; while(!(isSpaceChar(b))){ buff[p++] = (char)b; b = readByte(); } return Arrays.copyOf(buff, p); } } }
Java
["ABACABA", "AAA"]
1 second
["3\n1 4\n3 2\n7 1", "3\n1 3\n2 2\n3 1"]
null
Java 8
standard input
[ "dp", "two pointers", "string suffix structures", "strings" ]
3fb70a77e4de4851ed93f988140df221
The single line contains a sequence of characters s1s2...s|s| (1 ≀ |s| ≀ 105) β€” string s. The string only consists of uppercase English letters.
2,000
In the first line, print integer k (0 ≀ k ≀ |s|) β€” the number of prefixes that match a suffix of string s. Next print k lines, in each line print two integers li ci. Numbers li ci mean that the prefix of the length li matches the suffix of length li and occurs in string s as a substring ci times. Print pairs li ci in the order of increasing li.
standard output
PASSED
9f681469ad24a486faea08a3f87f80ea
train_003.jsonl
1400167800
You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: A substring s[i..j] (1 ≀ i ≀ j ≀ |s|) of string s is string sisi + 1...sj. The prefix of string s of length l (1 ≀ l ≀ |s|) is string s[1..l]. The suffix of string s of length l (1 ≀ l ≀ |s|) is string s[|s| - l + 1..|s|]. Your task is, for any prefix of string s which matches a suffix of string s, print the number of times it occurs in string s as a substring.
256 megabytes
/** * Created by Aminul on 10/17/2018. */ import java.io.*; import java.util.*; import static java.lang.Math.*; public class CF432D_Hash_Test { public static void main(String[] args)throws Exception { FastReader in = new FastReader(System.in); PrintWriter pw = new PrintWriter(System.out); char [] str = in.next().toCharArray(); int z[] = build_Z_array_with_hashing(str); int n = str.length; long count[] = new long[n+1]; boolean valid[] = new boolean[n+1]; int cnt = 0; for(int i = 0; i < n; i++){ if(i + z[i] == n) { cnt++; valid[z[i]] = true; } count[z[i]]++; } long s = 0; for(int i = n; i >= 1; i--){ count[i] += s; s = count[i]; } pw.println(cnt); for(int i = 1; i <= n; i++){ if(valid[i]){ pw.println(i+" "+count[i]); } } pw.close(); } static int[] build_Z_array_with_hashing(char[] s) { int n = s.length; int z[] = new int[n]; Hashing hash = new Hashing(s); for(int i = 0; i < n; i++) { z[i] = binarySearch(i, n, hash); } return z; } static int binarySearch(int start, int n, Hashing hash) { int lo = 1, hi = n - start, mid; while (lo < hi) { mid = (lo + hi) / 2; long prefixHash = hash.getHash(0, mid-1), currentHash = hash.getHash(start, start+mid-1); if (prefixHash != currentHash) hi = mid; else lo = mid + 1; } if(hash.getHash(0, lo-1) != hash.getHash(start, start+lo-1)) lo--; return lo; } static class Hashing{ long[] hash1, hash2; long[] inv1, inv2; int n; long mod1 = 1000000097L; long mod2 = (long) 1e9 + 9; long multiplier1 = 43, multiplier2 = 31; long invMultiplier1 = 441860508; long invMultiplier2 = 838709685; Hashing(char[] s) { build_Hash(s); } void build_Hash(char[] s) { n = s.length; hash1 = new long[n + 1]; hash2 = new long[n + 1]; inv1 = new long[n + 1]; inv2 = new long[n + 1]; inv1[0] = 1; inv2[0] = 1; long p1 = 1; long p2 = 1; for (int i = 0; i < n; i++) { hash1[i + 1] = (hash1[i] + s[i] * p1) % mod1; p1 = (p1 * multiplier1) % mod1; inv1[i + 1] = inv1[i] * invMultiplier1 % mod1; hash2[i + 1] = (hash2[i] + s[i] * p2) % mod2; p2 = (p2 * multiplier2) % mod2; inv2[i + 1] = inv2[i] * invMultiplier2 % mod2; } } long getHash(int i, int j) { //0-based return getHash_2(i, j - i+1); } long getHash_2(int i, int len) { //i is 0 based indexed return (((hash1[i + len] - hash1[i] + mod1) * inv1[i] % mod1) << 32) + (hash2[i + len] - hash2[i] + mod2) * inv2[i] % mod2; } long revHash(int i, int j){ ////0-based return getHash(n-j-1, n-i-1); } } static void debug(Object...obj) { System.err.println(Arrays.deepToString(obj)); } static class FastReader { InputStream is; private byte[] inbuf = new byte[1024]; private int lenbuf = 0, ptrbuf = 0; public FastReader(InputStream is) { this.is = is; } public int readByte() { if (lenbuf == -1) throw new InputMismatchException(); if (ptrbuf >= lenbuf) { ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if (lenbuf <= 0) return -1; } return inbuf[ptrbuf++]; } public boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } public int skip() { int b; while ((b = readByte()) != -1 && isSpaceChar(b)) ; return b; } public String next() { int b = skip(); StringBuilder sb = new StringBuilder(); while (!(isSpaceChar(b))) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public String nextLine() { int c = skip(); StringBuilder sb = new StringBuilder(); while (!isEndOfLine(c)){ sb.appendCodePoint(c); c = readByte(); } return sb.toString(); } public int nextInt() { int num = 0, b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = (num << 3) + (num << 1) + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } public long nextLong() { long num = 0; int b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = (num << 3) + (num << 1) + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } public double nextDouble() { return Double.parseDouble(next()); } public char[] next(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while (p < n && !(isSpaceChar(b))) { buf[p++] = (char) b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } public char readChar() { return (char) skip(); } } }
Java
["ABACABA", "AAA"]
1 second
["3\n1 4\n3 2\n7 1", "3\n1 3\n2 2\n3 1"]
null
Java 8
standard input
[ "dp", "two pointers", "string suffix structures", "strings" ]
3fb70a77e4de4851ed93f988140df221
The single line contains a sequence of characters s1s2...s|s| (1 ≀ |s| ≀ 105) β€” string s. The string only consists of uppercase English letters.
2,000
In the first line, print integer k (0 ≀ k ≀ |s|) β€” the number of prefixes that match a suffix of string s. Next print k lines, in each line print two integers li ci. Numbers li ci mean that the prefix of the length li matches the suffix of length li and occurs in string s as a substring ci times. Print pairs li ci in the order of increasing li.
standard output
PASSED
ec4e427c88d7453b399389f5fd3c3332
train_003.jsonl
1400167800
You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: A substring s[i..j] (1 ≀ i ≀ j ≀ |s|) of string s is string sisi + 1...sj. The prefix of string s of length l (1 ≀ l ≀ |s|) is string s[1..l]. The suffix of string s of length l (1 ≀ l ≀ |s|) is string s[|s| - l + 1..|s|]. Your task is, for any prefix of string s which matches a suffix of string s, print the number of times it occurs in string s as a substring.
256 megabytes
import java.io.*; import java.util.*; import java.util.Map.Entry; public class Problem_432D { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(); PrintWriter pw = new PrintWriter(System.out); char[]s=sc.nextLine().toCharArray(); int[]z=z(s); // System.out.println(Arrays.toString(z)); int n=s.length; TreeMap<Integer, Integer>hm=new TreeMap<>(Collections.reverseOrder()); long[]h=new long[n]; for(int i=n-1;i>=0;i--) { if(z[i]+i==n) hm.put(z[i], 1); else if(hm.containsKey(z[i])) hm.put(z[i], hm.get(z[i])+1); else h[z[i]]++; } for(int i=n-2;i>=0;i--)h[i]+=h[i+1]; pw.println(hm.size()+1); long cum=1; TreeMap<Integer, Long>tm=new TreeMap<>(); for(Entry<Integer, Integer>e:hm.entrySet()) { cum+=e.getValue(); tm.put(e.getKey(), cum+h[e.getKey()]); } for(Entry<Integer,Long>e:tm.entrySet()) pw.println(e.getKey()+" "+e.getValue()); pw.println(n+" "+1); pw.close(); } static int[] z(char[]s) { int n=s.length; int[]z=new int[n]; for(int i=1,l=0,r=0;i<n;i++) { if(i<=r) z[i]=Math.min(r-i+1, z[i-l]); while( i + z[i] < n && s[z[i]]==s[i+z[i]]) z[i]++; if(i + z[i] -1 > r) { l=i; r=i+z[i]-1; } } return z; } static class Scanner { BufferedReader br; StringTokenizer st; Scanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() throws IOException { while (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()); } String nextLine() throws IOException { return br.readLine(); } boolean hasnext() throws IOException { return br.ready(); } } }
Java
["ABACABA", "AAA"]
1 second
["3\n1 4\n3 2\n7 1", "3\n1 3\n2 2\n3 1"]
null
Java 8
standard input
[ "dp", "two pointers", "string suffix structures", "strings" ]
3fb70a77e4de4851ed93f988140df221
The single line contains a sequence of characters s1s2...s|s| (1 ≀ |s| ≀ 105) β€” string s. The string only consists of uppercase English letters.
2,000
In the first line, print integer k (0 ≀ k ≀ |s|) β€” the number of prefixes that match a suffix of string s. Next print k lines, in each line print two integers li ci. Numbers li ci mean that the prefix of the length li matches the suffix of length li and occurs in string s as a substring ci times. Print pairs li ci in the order of increasing li.
standard output
PASSED
81c644df78f2dce3c609525b9126b059
train_003.jsonl
1400167800
You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: A substring s[i..j] (1 ≀ i ≀ j ≀ |s|) of string s is string sisi + 1...sj. The prefix of string s of length l (1 ≀ l ≀ |s|) is string s[1..l]. The suffix of string s of length l (1 ≀ l ≀ |s|) is string s[|s| - l + 1..|s|]. Your task is, for any prefix of string s which matches a suffix of string s, print the number of times it occurs in string s as a substring.
256 megabytes
//package CodeForces; import java.io.*; import java.util.*; import java.util.Map.Entry; public class Problem_432D { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(); PrintWriter pw = new PrintWriter(System.out); char[]s=sc.nextLine().toCharArray(); int[]z=z(s); // System.out.println(Arrays.toString(z)); int n=s.length; TreeMap<Integer, Integer>hm=new TreeMap<>(Collections.reverseOrder()); TreeMap<Integer, Integer>help=new TreeMap<>(); long[]h=new long[n]; for(int i=n-1;i>=0;i--) { if(z[i]+i==n) hm.put(z[i], 1); else if(hm.containsKey(z[i])) hm.put(z[i], hm.get(z[i])+1); else { help.put(z[i], help.getOrDefault(z[i], 0)+1); h[z[i]]++; } } for(int i=n-2;i>=0;i--)h[i]+=h[i+1]; pw.println(hm.size()+1); long cum=1; TreeMap<Integer, Long>tm=new TreeMap<>(); for(Entry<Integer, Integer>e:hm.entrySet()) { cum+=e.getValue(); tm.put(e.getKey(), cum+h[e.getKey()]); } for(Entry<Integer,Long>e:tm.entrySet()) pw.println(e.getKey()+" "+e.getValue()); pw.println(n+" "+1); pw.close(); } static int[] z(char[]s) { int n=s.length; int[]z=new int[n]; for(int i=1,l=0,r=0;i<n;i++) { if(i<=r) z[i]=Math.min(r-i+1, z[i-l]); while( i + z[i] < n && s[z[i]]==s[i+z[i]]) z[i]++; if(i + z[i] -1 > r) { l=i; r=i+z[i]-1; } } return z; } static class Scanner { BufferedReader br; StringTokenizer st; Scanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() throws IOException { while (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()); } String nextLine() throws IOException { return br.readLine(); } boolean hasnext() throws IOException { return br.ready(); } } }
Java
["ABACABA", "AAA"]
1 second
["3\n1 4\n3 2\n7 1", "3\n1 3\n2 2\n3 1"]
null
Java 8
standard input
[ "dp", "two pointers", "string suffix structures", "strings" ]
3fb70a77e4de4851ed93f988140df221
The single line contains a sequence of characters s1s2...s|s| (1 ≀ |s| ≀ 105) β€” string s. The string only consists of uppercase English letters.
2,000
In the first line, print integer k (0 ≀ k ≀ |s|) β€” the number of prefixes that match a suffix of string s. Next print k lines, in each line print two integers li ci. Numbers li ci mean that the prefix of the length li matches the suffix of length li and occurs in string s as a substring ci times. Print pairs li ci in the order of increasing li.
standard output
PASSED
d733416c5ea54a880a8b34612b9ef43d
train_003.jsonl
1400167800
You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: A substring s[i..j] (1 ≀ i ≀ j ≀ |s|) of string s is string sisi + 1...sj. The prefix of string s of length l (1 ≀ l ≀ |s|) is string s[1..l]. The suffix of string s of length l (1 ≀ l ≀ |s|) is string s[|s| - l + 1..|s|]. Your task is, for any prefix of string s which matches a suffix of string s, print the number of times it occurs in string s as a substring.
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.util.TreeMap; import java.util.Map; import java.util.Map.Entry; 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; ScanReader in = new ScanReader(inputStream); PrintWriter out = new PrintWriter(outputStream); DPrefixesAndSuffixes solver = new DPrefixesAndSuffixes(); solver.solve(1, in, out); out.close(); } static class DPrefixesAndSuffixes { public void solve(int testNumber, ScanReader in, PrintWriter out) { String ss = in.scanString(); int pi[] = CodeX.prefix_function(ss); int n = pi.length; int has[] = new int[1000007]; for (int i = 0; i < n; i++) has[pi[i]]++; for (int i = n - 1; i > 0; i--) has[pi[i - 1]] += has[i]; for (int i = 0; i <= n; i++) has[i]++; int j = pi.length - 1; TreeMap<Integer, Integer> arrayList = new TreeMap<>(); while (pi[j] != 0) { if (has[pi[j]] >= 1) { arrayList.put(pi[j], has[pi[j]]); } j = pi[j] - 1; } arrayList.put(ss.length(), 1); out.println(arrayList.size()); for (Map.Entry<Integer, Integer> pp : arrayList.entrySet()) { out.println(pp.getKey() + " " + pp.getValue()); } } } static class ScanReader { private byte[] buf = new byte[4 * 1024]; private int INDEX; private BufferedInputStream in; private int TOTAL; public ScanReader(InputStream inputStream) { in = new BufferedInputStream(inputStream); } private int scan() { if (INDEX >= TOTAL) { INDEX = 0; try { TOTAL = in.read(buf); } catch (Exception e) { e.printStackTrace(); } if (TOTAL <= 0) return -1; } return buf[INDEX++]; } public String scanString() { int c = scan(); while (isWhiteSpace(c)) c = scan(); StringBuilder RESULT = new StringBuilder(); do { RESULT.appendCodePoint(c); c = scan(); } while (!isWhiteSpace(c)); return RESULT.toString(); } private boolean isWhiteSpace(int n) { if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true; else return false; } } static class CodeX { public static int[] prefix_function(String s) { int n = s.length(); int[] pi = new int[n]; for (int i = 1; i < n; i++) { int j = pi[i - 1]; while (j > 0 && s.charAt(i) != s.charAt(j)) j = pi[j - 1]; if (s.charAt(i) == s.charAt(j)) j++; pi[i] = j; } return pi; } } }
Java
["ABACABA", "AAA"]
1 second
["3\n1 4\n3 2\n7 1", "3\n1 3\n2 2\n3 1"]
null
Java 8
standard input
[ "dp", "two pointers", "string suffix structures", "strings" ]
3fb70a77e4de4851ed93f988140df221
The single line contains a sequence of characters s1s2...s|s| (1 ≀ |s| ≀ 105) β€” string s. The string only consists of uppercase English letters.
2,000
In the first line, print integer k (0 ≀ k ≀ |s|) β€” the number of prefixes that match a suffix of string s. Next print k lines, in each line print two integers li ci. Numbers li ci mean that the prefix of the length li matches the suffix of length li and occurs in string s as a substring ci times. Print pairs li ci in the order of increasing li.
standard output
PASSED
96e538fc025706aaf92dae51aaf87d42
train_003.jsonl
1400167800
You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: A substring s[i..j] (1 ≀ i ≀ j ≀ |s|) of string s is string sisi + 1...sj. The prefix of string s of length l (1 ≀ l ≀ |s|) is string s[1..l]. The suffix of string s of length l (1 ≀ l ≀ |s|) is string s[|s| - l + 1..|s|]. Your task is, for any prefix of string s which matches a suffix of string s, print the number of times it occurs in string s as a substring.
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.util.Comparator; import java.util.Collections; import java.util.ArrayList; 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; ScanReader in = new ScanReader(inputStream); PrintWriter out = new PrintWriter(outputStream); DPrefixesAndSuffixes solver = new DPrefixesAndSuffixes(); solver.solve(1, in, out); out.close(); } static class DPrefixesAndSuffixes { public void solve(int testNumber, ScanReader in, PrintWriter out) { String ss = in.scanString(); int pi[] = CodeX.prefix_function(ss); int n = pi.length; int has[] = new int[1000007]; for (int i = 0; i < n; i++) has[pi[i]]++; for (int i = n - 1; i > 0; i--) has[pi[i - 1]] += has[i]; for (int i = 0; i <= n; i++) has[i]++; int j = pi.length - 1; ArrayList<pair> arrayList = new ArrayList<>(); while (pi[j] != 0) { if (has[pi[j]] >= 1) { arrayList.add(new pair(pi[j], has[pi[j]])); } j = pi[j] - 1; } arrayList.add(new pair(ss.length(), 1)); Collections.sort(arrayList, new Comparator<pair>() { public int compare(pair o1, pair o2) { return o1.a - o2.a; } }); out.println(arrayList.size()); for (pair pp : arrayList) { out.println(pp.a + " " + pp.b); } } class pair { int a; int b; public pair(int a, int b) { this.a = a; this.b = b; } } } static class ScanReader { private byte[] buf = new byte[4 * 1024]; private int INDEX; private BufferedInputStream in; private int TOTAL; public ScanReader(InputStream inputStream) { in = new BufferedInputStream(inputStream); } private int scan() { if (INDEX >= TOTAL) { INDEX = 0; try { TOTAL = in.read(buf); } catch (Exception e) { e.printStackTrace(); } if (TOTAL <= 0) return -1; } return buf[INDEX++]; } public String scanString() { int c = scan(); while (isWhiteSpace(c)) c = scan(); StringBuilder RESULT = new StringBuilder(); do { RESULT.appendCodePoint(c); c = scan(); } while (!isWhiteSpace(c)); return RESULT.toString(); } private boolean isWhiteSpace(int n) { if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true; else return false; } } static class CodeX { public static int[] prefix_function(String s) { int n = s.length(); int[] pi = new int[n]; for (int i = 1; i < n; i++) { int j = pi[i - 1]; while (j > 0 && s.charAt(i) != s.charAt(j)) j = pi[j - 1]; if (s.charAt(i) == s.charAt(j)) j++; pi[i] = j; } return pi; } } }
Java
["ABACABA", "AAA"]
1 second
["3\n1 4\n3 2\n7 1", "3\n1 3\n2 2\n3 1"]
null
Java 8
standard input
[ "dp", "two pointers", "string suffix structures", "strings" ]
3fb70a77e4de4851ed93f988140df221
The single line contains a sequence of characters s1s2...s|s| (1 ≀ |s| ≀ 105) β€” string s. The string only consists of uppercase English letters.
2,000
In the first line, print integer k (0 ≀ k ≀ |s|) β€” the number of prefixes that match a suffix of string s. Next print k lines, in each line print two integers li ci. Numbers li ci mean that the prefix of the length li matches the suffix of length li and occurs in string s as a substring ci times. Print pairs li ci in the order of increasing li.
standard output
PASSED
bd3cb93b6dcd088f51b8b5faca751966
train_003.jsonl
1400167800
You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: A substring s[i..j] (1 ≀ i ≀ j ≀ |s|) of string s is string sisi + 1...sj. The prefix of string s of length l (1 ≀ l ≀ |s|) is string s[1..l]. The suffix of string s of length l (1 ≀ l ≀ |s|) is string s[|s| - l + 1..|s|]. Your task is, for any prefix of string s which matches a suffix of string s, print the number of times it occurs in string s as a substring.
256 megabytes
import java.io.*; import java.io.IOException; import java.util.*; //import javafx.util.Pair; //import java.util.concurrent.LinkedBlockingDeque; //import sun.net.www.content.audio.wav; public class Codeforces { public static long mod = (long)Math.pow(10, 9)+7 ; public static double epsilon=0.00000000008854;//value of epsilon public static InputReader sc = new InputReader(System.in); public static PrintWriter pw = new PrintWriter(System.out); public static int firstNode(int a,HashMap<Integer,Integer> p){ if(p.containsKey(a)){ p.put(a, firstNode(p.get(a), p)); } else return a; return p.get(a); } public static void Union(int a,int b,HashMap<Integer,Integer> p){ //int a=firstNode(a1, p); //int b=firstNode(b1, p); /*if(a!=b){ if(r[a]<r[b]){ p[a]=b; } else if(r[a]>r[b]){ p[b]=a; } else{ r[b]++; p[a]=b; } }*/ a=firstNode(a, p); b=firstNode(b, p); if(a!=b) p.put(a, b);//if no rank than } public static double getvalue(double beta[],double f1[],double f2[],double y[],int i){ Double ans=beta[0]+beta[1]*f1[i]+beta[2]*f2[i]-y[i]; return ans; } public static int values(int x[],int y[],int cx[],int cy[],int i,int j){ return (x[i]-cx[j])*(x[i]-cx[j])+(y[i]-cy[j])*(y[i]-cy[j]); } public static int dp(String s,String t,int i,int d[],int a[],int b[]){ if(i>=s.length()) return 0; if(d[i]>=0){ return d[i]; } int c=0; if(a[i]==1){ int k=t.length()-1; while(k>=0){ c=Math.max(1+dp(s, t, i+t.length()-b[k], d, a, b),c); k=b[k]-1; } //return d[i]=Math.max(dp(s, t, i+1, d, a, b),c); } return d[i]=Math.max(dp(s, t, i+1, d, a, b),c); } public static int[] GetLps(int s[]){ int n=s.length; int a[]=new int[n]; int j=0; for(int i=1;i<n;i++){ if(s[i]==s[j]){ j++; a[i]=j; } else if(j>0){ while(j>0&&s[i]!=s[j]){ j=a[--j]; } if(s[i]==s[j]) a[i]=++j; } } //pw.println(Arrays.toString(a)); return a; } public static int[] GetLps(String s){ int n=s.length(); int a[]=new int[n]; int j=0; for(int i=1;i<n;i++){ if(s.charAt(i)==s.charAt(j)){ j++; a[i]=j; } else if(j>0){ while(j>0&&s.charAt(i)!=s.charAt(j)){ j=a[--j]; } if(s.charAt(i)==s.charAt(j)) a[i]=++j; } } //pw.println(Arrays.toString(a)); return a; } public static void main(String[] args) { // code starts.. String s=sc.nextLine(); int a[]=GetLps(s); int v[]=new int[s.length()+1]; // pw.println(Arrays.toString(a)); for(int i=0;i<s.length();i++){ v[a[i]]++; } //v[s.length()]=1; for(int i=s.length()-1;i>0;i--){ v[a[i-1]]+=v[i]; } ArrayList<Integer> l=new ArrayList<>(); l.add(s.length()); int k=s.length()-1; while(a[k]>0){ l.add(a[k]); k=a[k]-1; } Collections.sort(l); pw.println(l.size()); for(int i=0;i<l.size();i++){ pw.println(l.get(i)+" "+(v[l.get(i)]+1)); } // Code ends... pw.flush(); pw.close(); } public static String reverseString(String s){ StringBuilder input1 = new StringBuilder(); input1.append(s); input1 = input1.reverse(); return input1.toString(); } public static int[] scanArray(int n){ int a[]=new int [n]; for(int i=0;i<n;i++) a[i]=sc.nextInt(); return a; } public static long[] scanLongArray(int n){ long a[]=new long [n]; for(int i=0;i<n;i++) a[i]=sc.nextLong(); return a; } public static String [] scanStrings(int n){ String a[]=new String [n]; for(int i=0;i<n;i++) a[i]=sc.nextLine(); return a; } } 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); } }
Java
["ABACABA", "AAA"]
1 second
["3\n1 4\n3 2\n7 1", "3\n1 3\n2 2\n3 1"]
null
Java 8
standard input
[ "dp", "two pointers", "string suffix structures", "strings" ]
3fb70a77e4de4851ed93f988140df221
The single line contains a sequence of characters s1s2...s|s| (1 ≀ |s| ≀ 105) β€” string s. The string only consists of uppercase English letters.
2,000
In the first line, print integer k (0 ≀ k ≀ |s|) β€” the number of prefixes that match a suffix of string s. Next print k lines, in each line print two integers li ci. Numbers li ci mean that the prefix of the length li matches the suffix of length li and occurs in string s as a substring ci times. Print pairs li ci in the order of increasing li.
standard output
PASSED
1d8f46e7b00d459343228de4c465f76f
train_003.jsonl
1400167800
You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: A substring s[i..j] (1 ≀ i ≀ j ≀ |s|) of string s is string sisi + 1...sj. The prefix of string s of length l (1 ≀ l ≀ |s|) is string s[1..l]. The suffix of string s of length l (1 ≀ l ≀ |s|) is string s[|s| - l + 1..|s|]. Your task is, for any prefix of string s which matches a suffix of string s, print the number of times it occurs in string s as a substring.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Stack; public class Main { public static void main(String[] args) throws IOException { //Scanner sc = new Scanner(System.in); BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); char[] s = reader.readLine().toCharArray(); int n = s.length; int[] pi = new int[n]; for(int i = 1; i < n; ++i){ int j = pi[i - 1]; while(j > 0 && s[i] != s[j]){ j = pi[j - 1]; } if(s[i] == s[j]) ++j; pi[i] = j; } int[] ans = new int[n + 1]; for(int i = n - 1; i >= 1; --i) ans[pi[i]]++; for(int i = n - 1; i >= 1; --i) ans[pi[i - 1]] += ans[i]; for(int i = n; i >= 1; --i) ans[i]++; int j = pi[n - 1]; Stack<String> stack = new Stack<>(); while(j > 0){ stack.push(j + " " + ans[j]); j = pi[j - 1]; } out.println(stack.size() + 1); while(!stack.isEmpty()){ out.println(stack.pop()); } out.println(n + " " + 1); out.close(); } }
Java
["ABACABA", "AAA"]
1 second
["3\n1 4\n3 2\n7 1", "3\n1 3\n2 2\n3 1"]
null
Java 8
standard input
[ "dp", "two pointers", "string suffix structures", "strings" ]
3fb70a77e4de4851ed93f988140df221
The single line contains a sequence of characters s1s2...s|s| (1 ≀ |s| ≀ 105) β€” string s. The string only consists of uppercase English letters.
2,000
In the first line, print integer k (0 ≀ k ≀ |s|) β€” the number of prefixes that match a suffix of string s. Next print k lines, in each line print two integers li ci. Numbers li ci mean that the prefix of the length li matches the suffix of length li and occurs in string s as a substring ci times. Print pairs li ci in the order of increasing li.
standard output
PASSED
5a23f127363f3ffaf40da3da0b067301
train_003.jsonl
1400167800
You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: A substring s[i..j] (1 ≀ i ≀ j ≀ |s|) of string s is string sisi + 1...sj. The prefix of string s of length l (1 ≀ l ≀ |s|) is string s[1..l]. The suffix of string s of length l (1 ≀ l ≀ |s|) is string s[|s| - l + 1..|s|]. Your task is, for any prefix of string s which matches a suffix of string s, print the number of times it occurs in string s as a substring.
256 megabytes
import java.util.*; import java.io.*; import java.math.BigInteger; public class tr0 { static PrintWriter out; static StringBuilder sb; static int mod = 1000000007; static long inf = (long) 1e16; static int n, m; static ArrayList<Integer>[] ad; static long[][][] memo; static boolean f; static boolean vis[]; static int[] sub; static char[] a; static ArrayList<Long> ar; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); out = new PrintWriter(System.out); char[] s = sc.nextLine().toCharArray(); n = s.length; int[] p = new int[n]; int[] c = new int[n]; for (int i = 1; i < n; i++) { int j = p[i - 1]; while (j > 0 && s[i] != s[j]) { j = p[j-1]; // System.out.println(j); } if (s[i] == s[j]) j++; p[i] = j; c[j]++; } for (int i = n - 1; i > 0; i--) { c[p[i - 1]] += c[i]; } for (int i = 0; i < n; i++) c[i]++; Stack<Integer> st = new Stack<>(); st.add(1); st.add(n); int j = p[n - 1]; while (j > 0) { st.add(c[j]); st.add(j); j = p[j - 1]; // System.out.println(j); } out.println(st.size() / 2); while(!st.isEmpty()) { out.println(st.pop()+" "+st.pop()); } out.flush(); } public static class FenwickTree { // one-based DS int n; int[] ft; FenwickTree(int size) { n = size; ft = new int[n + 1]; } int rsq(int b) // O(log n) { int sum = 0; while (b > 0) { sum += ft[b]; b -= b & -b; } // min? return sum; } int rsq(int a, int b) { return rsq(b) - rsq(a - 1); } void point_update(int k, int val) // O(log n), update = increment { while (k <= n) { ft[k] += val; k += k & -k; } // min? } } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream system) { br = new BufferedReader(new InputStreamReader(system)); } public Scanner(String file) throws Exception { br = new BufferedReader(new FileReader(file)); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public String nextLine() throws IOException { return br.readLine(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public char nextChar() throws IOException { return next().charAt(0); } public Long nextLong() throws IOException { return Long.parseLong(next()); } public int[] nextArrInt(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public long[] nextArrLong(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public boolean ready() throws IOException { return br.ready(); } public void waitForInput() throws InterruptedException { Thread.sleep(3000); } } }
Java
["ABACABA", "AAA"]
1 second
["3\n1 4\n3 2\n7 1", "3\n1 3\n2 2\n3 1"]
null
Java 8
standard input
[ "dp", "two pointers", "string suffix structures", "strings" ]
3fb70a77e4de4851ed93f988140df221
The single line contains a sequence of characters s1s2...s|s| (1 ≀ |s| ≀ 105) β€” string s. The string only consists of uppercase English letters.
2,000
In the first line, print integer k (0 ≀ k ≀ |s|) β€” the number of prefixes that match a suffix of string s. Next print k lines, in each line print two integers li ci. Numbers li ci mean that the prefix of the length li matches the suffix of length li and occurs in string s as a substring ci times. Print pairs li ci in the order of increasing li.
standard output
PASSED
d8a05503b9749869a2dbef297ea696f3
train_003.jsonl
1400167800
You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: A substring s[i..j] (1 ≀ i ≀ j ≀ |s|) of string s is string sisi + 1...sj. The prefix of string s of length l (1 ≀ l ≀ |s|) is string s[1..l]. The suffix of string s of length l (1 ≀ l ≀ |s|) is string s[|s| - l + 1..|s|]. Your task is, for any prefix of string s which matches a suffix of string s, print the number of times it occurs in string s as a substring.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.OutputStream; import java.io.InputStreamReader; import java.io.FileNotFoundException; import java.io.File; import java.util.ArrayList; import java.util.StringTokenizer; import java.io.Writer; import java.io.BufferedReader; import java.util.Comparator; import java.util.Collections; import java.io.UnsupportedEncodingException; 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; FastReader in = new FastReader(inputStream); OutputWriter out = new OutputWriter(outputStream); PrefixesAndSuffixes solver = new PrefixesAndSuffixes(); solver.solve(1, in, out); out.close(); } static class PrefixesAndSuffixes { int[] zFunction(char[] s) { int n = s.length; int[] z = new int[n]; int l = 0, r = 0; for (int i = 1; i < n; i++) { z[i] = Math.max(0, Math.min(z[i - l], r - i + 1)); while (z[i] + i < n && s[z[i] + i] == s[z[i]]) { l = i; r = z[i] + i; z[i]++; } } return z; } public void solve(int testNumber, FastReader in, OutputWriter out) { String cur = in.next(); int[] z = zFunction(cur.toCharArray()); int n = cur.length(); ArrayList<IntPair> zs = new ArrayList<>(); for (int i = 0; i < z.length; i++) { zs.add(new IntPair(i, z[i])); } Collections.sort(zs, Comparator.comparing(e -> e.getSecond())); ArrayList<IntPair> ans = new ArrayList<>(); boolean[] was = new boolean[n + 1]; for (int i = n - 1; i >= 1; i--) { if (was[z[i]]) continue; IntPair id = find(z[i], zs); if (id.getFirst() + id.getSecond() >= n) { int lo = findLow(id.getSecond(), zs); ans.add(new IntPair(z[i], n - lo + 1)); } was[z[i]] = true; } out.println(ans.size() + 1); for (IntPair p : ans) out.println(p.getFirst() + " " + p.getSecond()); out.println(cur.length() + " 1"); } private IntPair find(int t, ArrayList<IntPair> zs) { int lo = 0, hi = zs.size() - 1; int ans = -1; while (lo <= hi) { int mid = (lo + hi) >> 1; if (zs.get(mid).getSecond() <= t) { ans = mid; lo = mid + 1; } else { hi = mid - 1; } } assert ans != -1; return zs.get(ans); } private int findLow(int t, ArrayList<IntPair> zs) { int lo = 0, hi = zs.size() - 1; int ans = -1; while (lo <= hi) { int mid = (lo + hi) >> 1; if (zs.get(mid).getSecond() >= t) { ans = mid; hi = mid - 1; } else { lo = mid + 1; } } assert ans != -1; return ans; } } static class FastReader { BufferedReader reader; StringTokenizer st; public FastReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); st = null; } public String next() { while (st == null || !st.hasMoreTokens()) { try { String line = reader.readLine(); if (line == null) { return null; } st = new StringTokenizer(line); } catch (Exception e) { throw new RuntimeException(); } } return st.nextToken(); } } static class OutputWriter extends PrintWriter { public OutputWriter(OutputStream os, boolean autoFlush) { super(os, autoFlush); } public OutputWriter(Writer out) { super(out); } public OutputWriter(Writer out, boolean autoFlush) { super(out, autoFlush); } public OutputWriter(String fileName) throws FileNotFoundException { super(fileName); } public OutputWriter(String fileName, String csn) throws FileNotFoundException, UnsupportedEncodingException { super(fileName, csn); } public OutputWriter(File file) throws FileNotFoundException { super(file); } public OutputWriter(File file, String csn) throws FileNotFoundException, UnsupportedEncodingException { super(file, csn); } public OutputWriter(OutputStream out) { super(out); } public void flush() { super.flush(); } public void close() { super.close(); } } static class IntPair implements Comparable<IntPair> { int first; int second; public IntPair() { first = second = 0; } public IntPair(int first, int second) { this.first = first; this.second = second; } public int compareTo(IntPair a) { if (second == a.second) { return Integer.compare(first, a.first); } return Integer.compare(second, a.second); } public String toString() { return "<" + first + ", " + second + ">"; } public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; IntPair a = (IntPair) o; if (first != a.first) return false; return second == a.second; } public int hashCode() { int result = first; result = 31 * result + second; return result; } public int getFirst() { return first; } public int getSecond() { return second; } } }
Java
["ABACABA", "AAA"]
1 second
["3\n1 4\n3 2\n7 1", "3\n1 3\n2 2\n3 1"]
null
Java 8
standard input
[ "dp", "two pointers", "string suffix structures", "strings" ]
3fb70a77e4de4851ed93f988140df221
The single line contains a sequence of characters s1s2...s|s| (1 ≀ |s| ≀ 105) β€” string s. The string only consists of uppercase English letters.
2,000
In the first line, print integer k (0 ≀ k ≀ |s|) β€” the number of prefixes that match a suffix of string s. Next print k lines, in each line print two integers li ci. Numbers li ci mean that the prefix of the length li matches the suffix of length li and occurs in string s as a substring ci times. Print pairs li ci in the order of increasing li.
standard output
PASSED
5c2a434569e69bc45b9f69760c953e2d
train_003.jsonl
1400167800
You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: A substring s[i..j] (1 ≀ i ≀ j ≀ |s|) of string s is string sisi + 1...sj. The prefix of string s of length l (1 ≀ l ≀ |s|) is string s[1..l]. The suffix of string s of length l (1 ≀ l ≀ |s|) is string s[|s| - l + 1..|s|]. Your task is, for any prefix of string s which matches a suffix of string s, print the number of times it occurs in string s as a substring.
256 megabytes
/* Method 2: Using KMP, as per the editorial. Though the Z-function approach is way simpler, and more intuitive. Checking for prefix suffix match is pretty straightforward: p[|s|], p[p[|s|]], p[p[p[|s|]]], etc. Finding count of all occurrences of all prefixes (why it works): edge from pi[v] to v denotes that the immediate fallback value of v is pi[v], and so, v will directly contribute to the count of pi[v]. */ //created by Whiplash99 import java.io.*; import java.util.*; public class A { private static ArrayDeque<Integer>[] edge; private static int[] sum; private static void calcPi(char[] str, int[] pi, int N) { for (int i = 1, j=0; i < N; i++) { while (j > 0 && str[i] != str[j]) j = pi[j-1]; if (str[i] == str[j]) j++; pi[i] = j; } } private static void DFS(int u) { for(int v:edge[u]) { DFS(v); sum[u]+=sum[v]; } } public static void main(String[] args) throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int i,N; char[] str=br.readLine().trim().toCharArray(); N=str.length; int[] pi=new int[N+1]; calcPi(str,pi,N); for(i=N;i>0;i--) pi[i]=pi[i-1]; edge=new ArrayDeque[N+1]; sum=new int[N+1]; for(i=0;i<=N;i++) edge[i]=new ArrayDeque<>(); for(i=1;i<=N;i++) edge[pi[i]].add(i); Arrays.fill(sum,1); DFS(0); ArrayDeque<Integer> P=new ArrayDeque<>(); ArrayDeque<Integer> freq=new ArrayDeque<>(); P.addFirst(N); freq.addFirst(1); for(i=pi[N];i>0;i=pi[i]) { P.addFirst(i); freq.addFirst(sum[i]); } System.out.println(P.size()); StringBuilder sb=new StringBuilder(); while (!P.isEmpty()) { sb.append(P.pollFirst()).append(" "); sb.append(freq.pollFirst()).append("\n"); } System.out.println(sb); } }
Java
["ABACABA", "AAA"]
1 second
["3\n1 4\n3 2\n7 1", "3\n1 3\n2 2\n3 1"]
null
Java 8
standard input
[ "dp", "two pointers", "string suffix structures", "strings" ]
3fb70a77e4de4851ed93f988140df221
The single line contains a sequence of characters s1s2...s|s| (1 ≀ |s| ≀ 105) β€” string s. The string only consists of uppercase English letters.
2,000
In the first line, print integer k (0 ≀ k ≀ |s|) β€” the number of prefixes that match a suffix of string s. Next print k lines, in each line print two integers li ci. Numbers li ci mean that the prefix of the length li matches the suffix of length li and occurs in string s as a substring ci times. Print pairs li ci in the order of increasing li.
standard output
PASSED
848a17b25625b4ee78c313b8c4f50be4
train_003.jsonl
1400167800
You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: A substring s[i..j] (1 ≀ i ≀ j ≀ |s|) of string s is string sisi + 1...sj. The prefix of string s of length l (1 ≀ l ≀ |s|) is string s[1..l]. The suffix of string s of length l (1 ≀ l ≀ |s|) is string s[|s| - l + 1..|s|]. Your task is, for any prefix of string s which matches a suffix of string s, print the number of times it occurs in string s as a substring.
256 megabytes
//created by Whiplash99 import java.io.*; import java.util.*; public class A { private static void computeZArr(char str[], int z[]) { int l = 0, r = 0, N = str.length; for (int i = 1; i < N; i++) { if (i <= r) z[i] = Math.min(r - i + 1, z[i - l]); while (i + z[i] < N && str[z[i]] == str[i + z[i]]) ++z[i]; if (i + z[i] - 1 > r) { l = i; r = i + z[i] - 1; } } } public static void main(String[] args) throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int i,N; char[] str=br.readLine().trim().toCharArray(); N=str.length; int[] z=new int[N]; computeZArr(str,z); int[] diff=new int[N+1]; for(i=1;i<N;i++) diff[z[i]]++; for(i=N-1;i>=0;i--) diff[i]+=diff[i+1]; int k=0; StringBuilder sb=new StringBuilder(); for(i=0;i<N-1;i++) { if(z[N-i-1]==i+1) { k++; sb.append(i + 1).append(" ").append(1 +diff[i+1]).append("\n"); } } k++; sb.append(N).append(" ").append(1).append("\n"); System.out.println(k); System.out.println(sb); } }
Java
["ABACABA", "AAA"]
1 second
["3\n1 4\n3 2\n7 1", "3\n1 3\n2 2\n3 1"]
null
Java 8
standard input
[ "dp", "two pointers", "string suffix structures", "strings" ]
3fb70a77e4de4851ed93f988140df221
The single line contains a sequence of characters s1s2...s|s| (1 ≀ |s| ≀ 105) β€” string s. The string only consists of uppercase English letters.
2,000
In the first line, print integer k (0 ≀ k ≀ |s|) β€” the number of prefixes that match a suffix of string s. Next print k lines, in each line print two integers li ci. Numbers li ci mean that the prefix of the length li matches the suffix of length li and occurs in string s as a substring ci times. Print pairs li ci in the order of increasing li.
standard output
PASSED
31264873eaba1590b485dbbeb7f1dc1e
train_003.jsonl
1400167800
You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: A substring s[i..j] (1 ≀ i ≀ j ≀ |s|) of string s is string sisi + 1...sj. The prefix of string s of length l (1 ≀ l ≀ |s|) is string s[1..l]. The suffix of string s of length l (1 ≀ l ≀ |s|) is string s[|s| - l + 1..|s|]. Your task is, for any prefix of string s which matches a suffix of string s, print the number of times it occurs in string s as a substring.
256 megabytes
//created by Whiplash99 import java.io.*; import java.util.*; public class A { static class Hashing { long[] hash,pow; long P, MOD; int N; Hashing(char str[], long P, long MOD) { this.N=str.length;this.P=P;this.MOD=MOD; hash=new long[N+1];pow=new long[N+1]; init(str); } void init(char str[]) { pow[0]=1; for(int i=N-1;i>=0;i--) { hash[i]=((hash[i+1]*P)%MOD+(str[i]-'A'+1))%MOD; pow[N-i]=(pow[N-i-1]*P)%MOD; } pow[N]=(pow[N-1]*P)%MOD; } long getHash(){return getHash(0,N-1);} long getHash(int l, int r){return (MOD-(hash[r+1]*pow[r-l+1])%MOD+hash[l])%MOD;} } private static void computeZArr(char str[], int z[]) { int l = 0, r = 0, N = str.length; for (int i = 1; i < N; i++) { if (i <= r) z[i] = Math.min(r - i + 1, z[i - l]); while (i + z[i] < N && str[z[i]] == str[i + z[i]]) ++z[i]; if (i + z[i] - 1 > r) { l = i; r = i + z[i] - 1; } } } public static void main(String[] args) throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int i,N; char[] str=br.readLine().trim().toCharArray(); N=str.length; Hashing hash=new Hashing(str,31,(int)1e9+9); int[] z=new int[N]; computeZArr(str,z); int[] diff=new int[N+1]; for(i=1;i<N;i++) diff[z[i]]++; for(i=N-1;i>=0;i--) diff[i]+=diff[i+1]; int k=0; StringBuilder sb=new StringBuilder(); for(i=0;i<N-1;i++) { if(hash.getHash(0,i)==hash.getHash(N-i-1,N-1)) { k++; sb.append(i + 1).append(" ").append(1 +diff[i+1]).append("\n"); } } k++; sb.append(N).append(" ").append(1).append("\n"); System.out.println(k); System.out.println(sb); } }
Java
["ABACABA", "AAA"]
1 second
["3\n1 4\n3 2\n7 1", "3\n1 3\n2 2\n3 1"]
null
Java 8
standard input
[ "dp", "two pointers", "string suffix structures", "strings" ]
3fb70a77e4de4851ed93f988140df221
The single line contains a sequence of characters s1s2...s|s| (1 ≀ |s| ≀ 105) β€” string s. The string only consists of uppercase English letters.
2,000
In the first line, print integer k (0 ≀ k ≀ |s|) β€” the number of prefixes that match a suffix of string s. Next print k lines, in each line print two integers li ci. Numbers li ci mean that the prefix of the length li matches the suffix of length li and occurs in string s as a substring ci times. Print pairs li ci in the order of increasing li.
standard output
PASSED
21475e159b9e3596e26e7894a1b8151a
train_003.jsonl
1400167800
You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: A substring s[i..j] (1 ≀ i ≀ j ≀ |s|) of string s is string sisi + 1...sj. The prefix of string s of length l (1 ≀ l ≀ |s|) is string s[1..l]. The suffix of string s of length l (1 ≀ l ≀ |s|) is string s[|s| - l + 1..|s|]. Your task is, for any prefix of string s which matches a suffix of string s, print the number of times it occurs in string s as a substring.
256 megabytes
import java.util.*; import java.io.*; public class PrefixesAndSuffixes { public static void main(String[] args){ Scanner scan = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); char[] s = scan.next().toCharArray(); int n = s.length; int[] ans = new int[n+2]; int[] z = zValues(s); for(int i = 0; i < n; i++) ans[z[i]+1]--; int res = 0; for(int i = 1; i <= n; i++) if(z[n-i] == i) res++; out.println(res); int roll = n; for(int i = 1; i <= n; i++) { roll += ans[i]; if(z[n-i] == i) out.println(i+" "+roll); } out.flush(); } public static int[] zValues(char[] s) { int n = s.length; int[] z = new int[n]; z[0] = n; int L = 0, R = 0; int[] left = new int[n], right = new int[n]; for(int i = 1; i < n; ++i) { if(i > R) { L = R = i; while(R < n && s[R-L] == s[R]) R++; z[i] = R - L; R--; } else { int k = i-L; if(z[k] < R-i+1) z[i] = z[k]; else { L = i; while(R < n && s[R-L] == s[R]) R++; z[i] = R - L; R--; } } left[i] = L; right[i] = R; } return z; } }
Java
["ABACABA", "AAA"]
1 second
["3\n1 4\n3 2\n7 1", "3\n1 3\n2 2\n3 1"]
null
Java 8
standard input
[ "dp", "two pointers", "string suffix structures", "strings" ]
3fb70a77e4de4851ed93f988140df221
The single line contains a sequence of characters s1s2...s|s| (1 ≀ |s| ≀ 105) β€” string s. The string only consists of uppercase English letters.
2,000
In the first line, print integer k (0 ≀ k ≀ |s|) β€” the number of prefixes that match a suffix of string s. Next print k lines, in each line print two integers li ci. Numbers li ci mean that the prefix of the length li matches the suffix of length li and occurs in string s as a substring ci times. Print pairs li ci in the order of increasing li.
standard output
PASSED
e03611a7a26dbe36cd8163867c5cbe09
train_003.jsonl
1400167800
You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: A substring s[i..j] (1 ≀ i ≀ j ≀ |s|) of string s is string sisi + 1...sj. The prefix of string s of length l (1 ≀ l ≀ |s|) is string s[1..l]. The suffix of string s of length l (1 ≀ l ≀ |s|) is string s[|s| - l + 1..|s|]. Your task is, for any prefix of string s which matches a suffix of string s, print the number of times it occurs in string s as a substring.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.io.InputStreamReader; import java.util.function.IntPredicate; import java.util.AbstractCollection; import java.util.StringTokenizer; import java.io.BufferedReader; import java.util.LinkedList; 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); PrefixesAndSuffixes solver = new PrefixesAndSuffixes(); solver.solve(1, in, out); out.close(); } static class PrefixesAndSuffixes { public void solve(int testNumber, InputReader in, PrintWriter out) { int[] z = Utils.calculateZ(in.next().toCharArray()); int[] sortedZ = new int[z.length]; System.arraycopy(z, 0, sortedZ, 0, z.length); Arrays.sort(sortedZ); LinkedList<Pair<Integer, Integer>> answer = new LinkedList<>(); answer.add(new Pair<>(z.length, 1)); for (int i = 0; i < z.length; i++) { if (z.length - i == z[i]) { final int e = z[i]; int j = Utils.lowerBound(sortedZ, 0, sortedZ.length - 1, idx -> sortedZ[idx] >= e); j = sortedZ.length - j + 1; answer.add(new Pair<>(z[i], j)); } } out.println(answer.size()); printAnswer(out, answer); } void printAnswer(PrintWriter out, LinkedList<Pair<Integer, Integer>> answer) { if (!answer.isEmpty()) { Pair<Integer, Integer> p = answer.removeFirst(); printAnswer(out, answer); out.println(p.first + " " + p.second); } } } static class Utils { public static int lowerBound(int[] arr, int l, int r, IntPredicate filter) { int m, answer = -1; while (l <= r) { m = (l + r) >> 1; if (filter.test(m)) { answer = m; r = m - 1; } else { l = m + 1; } } return answer; } public static int[] calculateZ(char input[]) { int Z[] = new int[input.length]; int left = 0; int right = 0; for (int k = 1; k < input.length; k++) { if (k > right) { left = right = k; while (right < input.length && input[right] == input[right - left]) { right++; } Z[k] = right - left; right--; } else { int k1 = k - left; if (Z[k1] < right - k + 1) { Z[k] = Z[k1]; } else { left = k; while (right < input.length && input[right] == input[right - left]) { right++; } Z[k] = right - left; right--; } } } return Z; } } static class Pair<U, V> { public U first; public V second; public Pair() { } public Pair(U first, V second) { this.first = first; this.second = second; } public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Pair<?, ?> pair = (Pair<?, ?>) o; if (!first.equals(pair.first)) return false; return second.equals(pair.second); } public int hashCode() { int result = first.hashCode(); result = 31 * result + second.hashCode(); return result; } public String toString() { return "Pair{" + "first=" + first + ", second=" + second + '}'; } } static class InputReader { private StringTokenizer tokenizer; private BufferedReader reader; public InputReader(InputStream inputStream) { reader = new BufferedReader(new InputStreamReader(inputStream)); } private void fillTokenizer() { if (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (Exception e) { throw new RuntimeException(e); } } } public String next() { fillTokenizer(); return tokenizer.nextToken(); } } }
Java
["ABACABA", "AAA"]
1 second
["3\n1 4\n3 2\n7 1", "3\n1 3\n2 2\n3 1"]
null
Java 8
standard input
[ "dp", "two pointers", "string suffix structures", "strings" ]
3fb70a77e4de4851ed93f988140df221
The single line contains a sequence of characters s1s2...s|s| (1 ≀ |s| ≀ 105) β€” string s. The string only consists of uppercase English letters.
2,000
In the first line, print integer k (0 ≀ k ≀ |s|) β€” the number of prefixes that match a suffix of string s. Next print k lines, in each line print two integers li ci. Numbers li ci mean that the prefix of the length li matches the suffix of length li and occurs in string s as a substring ci times. Print pairs li ci in the order of increasing li.
standard output
PASSED
f20f017c06d4d653d1c7552e210784b7
train_003.jsonl
1400167800
You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: A substring s[i..j] (1 ≀ i ≀ j ≀ |s|) of string s is string sisi + 1...sj. The prefix of string s of length l (1 ≀ l ≀ |s|) is string s[1..l]. The suffix of string s of length l (1 ≀ l ≀ |s|) is string s[|s| - l + 1..|s|]. Your task is, for any prefix of string s which matches a suffix of string s, print the number of times it occurs in string s as a substring.
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 dipankar12 */ import java.io.*; import java.util.*; public class r246d { void computelpsarray(String str,int len,int lps[]) { int j=0,i=1; lps[0]=0; while(i<len) { if(str.charAt(i)==str.charAt(j)) { lps[i]=j+1; j++; i++; } else { if(j!=0) j=lps[j-1]; else { lps[i]=j; i++; } } } } int[] kmpsearch(int lps[]) { int count[]=new int[lps.length]; Arrays.fill(count, 1); for(int i=lps.length-1;i>=0;i--) { if(lps[i]>0) count[lps[i]-1]+=count[i]; } return count; } public static void main(String args[]) { fastio in=new fastio(System.in); PrintWriter pw=new PrintWriter(System.out); String str=in.readString(); r246d ob=new r246d(); int lps[]=new int[str.length()]; ob.computelpsarray(str, str.length(), lps); int count[]=ob.kmpsearch(lps); /*for(int i=0;i<lps.length;i++) pw.print(lps[i]+" "); pw.println(); for(int i=0;i<count.length;i++) pw.print(count[i]+" "); pw.println();*/ LinkedList<Integer> ll=new LinkedList<Integer>(); ll.add(str.length()); int pre=lps[str.length()-1]; int counts=0; while(pre!=0) { ll.addFirst(pre); pre=lps[pre-1]; counts++; } pw.println(ll.size()); while(!ll.isEmpty()) { int fix=ll.removeFirst(); pw.println(fix+" "+count[fix-1]); } pw.close(); } static class fastio { private final InputStream stream; private final byte[] buf = new byte[8192]; private int cchar, snchar; private SpaceCharFilter filter; public fastio(InputStream stream) { this.stream = stream; } public int nxt() { if (snchar == -1) throw new InputMismatchException(); if (cchar >= snchar) { cchar = 0; try { snchar = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snchar <= 0) return -1; } return buf[cchar++]; } public int nextInt() { int c = nxt(); while (isSpaceChar(c)) { c = nxt(); } int sgn = 1; if (c == '-') { sgn = -1; c = nxt(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = nxt(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = nxt(); while (isSpaceChar(c)) { c = nxt(); } int sgn = 1; if (c == '-') { sgn = -1; c = nxt(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = nxt(); } 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 = nxt(); while (isSpaceChar(c)) { c = nxt(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = nxt(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = nxt(); while (isSpaceChar(c)) c = nxt(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = nxt(); } 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
["ABACABA", "AAA"]
1 second
["3\n1 4\n3 2\n7 1", "3\n1 3\n2 2\n3 1"]
null
Java 8
standard input
[ "dp", "two pointers", "string suffix structures", "strings" ]
3fb70a77e4de4851ed93f988140df221
The single line contains a sequence of characters s1s2...s|s| (1 ≀ |s| ≀ 105) β€” string s. The string only consists of uppercase English letters.
2,000
In the first line, print integer k (0 ≀ k ≀ |s|) β€” the number of prefixes that match a suffix of string s. Next print k lines, in each line print two integers li ci. Numbers li ci mean that the prefix of the length li matches the suffix of length li and occurs in string s as a substring ci times. Print pairs li ci in the order of increasing li.
standard output
PASSED
a559ba902cd3e402aef6b03eee2a6f7b
train_003.jsonl
1400167800
You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: A substring s[i..j] (1 ≀ i ≀ j ≀ |s|) of string s is string sisi + 1...sj. The prefix of string s of length l (1 ≀ l ≀ |s|) is string s[1..l]. The suffix of string s of length l (1 ≀ l ≀ |s|) is string s[|s| - l + 1..|s|]. Your task is, for any prefix of string s which matches a suffix of string s, print the number of times it occurs in string s as a substring.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; import java.io.BufferedReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author anand.oza */ 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); DPrefixesAndSuffixes solver = new DPrefixesAndSuffixes(); solver.solve(1, in, out); out.close(); } static class DPrefixesAndSuffixes { public void solve(int testNumber, InputReader in, PrintWriter out) { char[] s = in.next().toCharArray(); final int n = s.length; int[] z = ZAlgorithm.zAlgorithm(s); List<String> answer = new ArrayList<>(); IntSumSegmentTree count = new IntSumSegmentTree(n + 1); for (int i = 0; i < n; i++) { count.update_LAZY(z[i], 1 + count.get(z[i])); } count.rebuild(); for (int i = n - 1; i >= 0; i--) { if (i + z[i] == n) { answer.add(Util.join(z[i], count.query(z[i], n + 1))); } } out.println(answer.size()); for (String x : answer) { out.println(x); } } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } } static class ZAlgorithm { private ZAlgorithm() { } public static int[] zAlgorithm(char[] s) { int n = s.length; int[] z = new int[n]; z[0] = n; for (int i = 1, l = -1, r = -1; i < n; i++) { z[i] = r > i ? Math.min(r - i, z[i - l]) : 0; while (i + z[i] < n && s[i + z[i]] == s[z[i]]) z[i]++; if (i + z[i] > r) { l = i; r = i + z[i]; } } return z; } } static class IntSumSegmentTree { public int size; public int[] value; public IntSumSegmentTree(int size) { this.size = size; value = new int[2 * size]; } public void rebuild() { for (int i = size - 1; i > 0; i--) { value[i] = value[2 * i] + value[2 * i + 1]; } } public int get(int i) { return value[size + i]; } public void update_LAZY(int i, int v) { i += size; value[i] = v; } public int query(int i, int j) { int res_left = 0, res_right = 0; for (i += size, j += size; i < j; i /= 2, j /= 2) { if ((i & 1) == 1) { int b = value[i++]; res_left = res_left + b; } if ((j & 1) == 1) { int a = value[--j]; res_right = a + res_right; } } return res_left + res_right; } } static class Util { public static String join(int... i) { StringBuilder sb = new StringBuilder(); for (int o : i) { sb.append(o); sb.append(" "); } if (sb.length() > 0) { sb.deleteCharAt(sb.length() - 1); } return sb.toString(); } } }
Java
["ABACABA", "AAA"]
1 second
["3\n1 4\n3 2\n7 1", "3\n1 3\n2 2\n3 1"]
null
Java 8
standard input
[ "dp", "two pointers", "string suffix structures", "strings" ]
3fb70a77e4de4851ed93f988140df221
The single line contains a sequence of characters s1s2...s|s| (1 ≀ |s| ≀ 105) β€” string s. The string only consists of uppercase English letters.
2,000
In the first line, print integer k (0 ≀ k ≀ |s|) β€” the number of prefixes that match a suffix of string s. Next print k lines, in each line print two integers li ci. Numbers li ci mean that the prefix of the length li matches the suffix of length li and occurs in string s as a substring ci times. Print pairs li ci in the order of increasing li.
standard output
PASSED
f9a4ec9cc0977f298b05cef577b30fc1
train_003.jsonl
1400167800
You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: A substring s[i..j] (1 ≀ i ≀ j ≀ |s|) of string s is string sisi + 1...sj. The prefix of string s of length l (1 ≀ l ≀ |s|) is string s[1..l]. The suffix of string s of length l (1 ≀ l ≀ |s|) is string s[|s| - l + 1..|s|]. Your task is, for any prefix of string s which matches a suffix of string s, print the number of times it occurs in string s as a substring.
256 megabytes
import java.io.*; import java.lang.reflect.Array; import java.math.*; import java.util.*; public class icpc { public static void main(String[] args)throws IOException { //Reader in = new Reader(); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String s = in.readLine(); int[] lps = new KMPAlgorithm().computeTemporalArray(s.toCharArray()); int[] Z = new ZAlgorithm().calculateZ(s.toCharArray()); StringBuilder stringBuilder = new StringBuilder(); ArrayList<StringBuilder> A = new ArrayList<>(); A.add(new StringBuilder().append(s.length()).append(" ").append(1)); int len = lps[lps.length - 1]; int[] h = new int[100001]; for (int i=0;i<lps.length;i++) h[Z[i]]++; for (int i=h.length - 2;i>=0;i--) h[i] += h[i + 1]; int count = 1; while (len > 0) { count ++; A.add(new StringBuilder().append(len).append(" ").append((1 + h[len]))); len = lps[len - 1]; } stringBuilder.append(count).append("\n"); for (int i=A.size() - 1;i>=0;i--) stringBuilder.append(A.get(i)).append("\n"); System.out.println(stringBuilder); } } class NumberTheory { public boolean isPrime(long n) { if(n < 2) return false; for(long x = 2;x * x <= n;x++) { if(n % x == 0) return false; } return true; } public ArrayList<Long> primeFactorisation(long n) { ArrayList<Long> f = new ArrayList<>(); for(long x=2;x * x <= n;x++) { while(n % x == 0) { f.add(x); n /= x; } } if(n > 1) f.add(n); return f; } public int[] sieveOfEratosthenes(int n) { int[] sieve = new int[n + 1]; for(int x=2;x<=n;x++) { if(sieve[x] != 0) continue; sieve[x] = x; for(int u=2*x;u<=n;u+=x) if(sieve[u] == 0) sieve[u] = x; } return sieve; } public long gcd(long a, long b) { if(b == 0) return a; return gcd(b, a % b); } public long phi(long n) { double result = n; for(long p=2;p*p<=n;p++) { if(n % p == 0) { while (n % p == 0) n /= p; result *= (1.0 - (1.0 / (double)p)); } } if(n > 1) result *= (1.0 - (1.0 / (double)n)); return (long)result; } public Name extendedEuclid(long a, long b) { if(b == 0) return new Name(a, 1, 0); Name n1 = extendedEuclid(b, a % b); Name n2 = new Name(n1.d, n1.y, n1.x - (long)Math.floor((double)a / b) * n1.y); return n2; } public long modularExponentiation(long a, long b, long n) { long d = 1L; String bString = Long.toBinaryString(b); for(int i=0;i<bString.length();i++) { d = (d * d) % n; if(bString.charAt(i) == '1') d = (d * a) % n; } return d; } } class Name { long d; long x; long y; public Name(long d, long x, long y) { this.d = d; this.x = x; this.y = y; } } class SuffixArray { int ALPHABET_SZ = 256, N; int[] T, lcp, sa, sa2, rank, tmp, c; public SuffixArray(String str) { this(toIntArray(str)); } private static int[] toIntArray(String s) { int[] text = new int[s.length()]; for (int i = 0; i < s.length(); i++) text[i] = s.charAt(i); return text; } public SuffixArray(int[] text) { T = text; N = text.length; sa = new int[N]; sa2 = new int[N]; rank = new int[N]; c = new int[Math.max(ALPHABET_SZ, N)]; construct(); kasai(); } private void construct() { int i, p, r; for (i = 0; i < N; ++i) c[rank[i] = T[i]]++; for (i = 1; i < ALPHABET_SZ; ++i) c[i] += c[i - 1]; for (i = N - 1; i >= 0; --i) sa[--c[T[i]]] = i; for (p = 1; p < N; p <<= 1) { for (r = 0, i = N - p; i < N; ++i) sa2[r++] = i; for (i = 0; i < N; ++i) if (sa[i] >= p) sa2[r++] = sa[i] - p; Arrays.fill(c, 0, ALPHABET_SZ, 0); for (i = 0; i < N; ++i) c[rank[i]]++; for (i = 1; i < ALPHABET_SZ; ++i) c[i] += c[i - 1]; for (i = N - 1; i >= 0; --i) sa[--c[rank[sa2[i]]]] = sa2[i]; for (sa2[sa[0]] = r = 0, i = 1; i < N; ++i) { if (!(rank[sa[i - 1]] == rank[sa[i]] && sa[i - 1] + p < N && sa[i] + p < N && rank[sa[i - 1] + p] == rank[sa[i] + p])) r++; sa2[sa[i]] = r; } tmp = rank; rank = sa2; sa2 = tmp; if (r == N - 1) break; ALPHABET_SZ = r + 1; } } private void kasai() { lcp = new int[N]; int[] inv = new int[N]; for (int i = 0; i < N; i++) inv[sa[i]] = i; for (int i = 0, len = 0; i < N; i++) { if (inv[i] > 0) { int k = sa[inv[i] - 1]; while ((i + len < N) && (k + len < N) && T[i + len] == T[k + len]) len++; lcp[inv[i] - 1] = len; if (len > 0) len--; } } } } class ZAlgorithm { public int[] calculateZ(char input[]) { int Z[] = new int[input.length]; int left = 0; int right = 0; for(int k = 1; k < input.length; k++) { if(k > right) { left = right = k; while(right < input.length && input[right] == input[right - left]) { right++; } Z[k] = right - left; right--; } else { //we are operating inside box int k1 = k - left; //if value does not stretches till right bound then just copy it. if(Z[k1] < right - k + 1) { Z[k] = Z[k1]; } else { //otherwise try to see if there are more matches. left = k; while(right < input.length && input[right] == input[right - left]) { right++; } Z[k] = right - left; right--; } } } return Z; } public ArrayList<Integer> matchPattern(char text[], char pattern[]) { char newString[] = new char[text.length + pattern.length + 1]; int i = 0; for(char ch : pattern) { newString[i] = ch; i++; } newString[i] = '$'; i++; for(char ch : text) { newString[i] = ch; i++; } ArrayList<Integer> result = new ArrayList<>(); int Z[] = calculateZ(newString); for(i = 0; i < Z.length ; i++) { if(Z[i] == pattern.length) { result.add(i - pattern.length - 1); } } return result; } } class KMPAlgorithm { public int[] computeTemporalArray(char[] pattern) { int[] lps = new int[pattern.length]; int index = 0; for(int i=1;i<pattern.length;) { if(pattern[i] == pattern[index]) { lps[i] = index + 1; index++; i++; } else { if(index != 0) { index = lps[index - 1]; } else { lps[i] = 0; i++; } } } return lps; } public ArrayList<Integer> KMPMatcher(char[] text, char[] pattern) { int[] lps = computeTemporalArray(pattern); int j = 0; int i = 0; int n = text.length; int m = pattern.length; ArrayList<Integer> indices = new ArrayList<>(); while(i < n) { if(pattern[j] == text[i]) { i++; j++; } if(j == m) { indices.add(i - j); j = lps[j - 1]; } else if(i < n && pattern[j] != text[i]) { if(j != 0) j = lps[j - 1]; else i = i + 1; } } return indices; } } class Hashing { public long[] computePowers(long p, int n, long m) { long[] powers = new long[n]; powers[0] = 1; for(int i=1;i<n;i++) { powers[i] = (powers[i - 1] * p) % m; } return powers; } public long computeHash(String s) { long p = 31; long m = 1_000_000_009; long hashValue = 0L; long[] powers = computePowers(p, s.length(), m); for(int i=0;i<s.length();i++) { char ch = s.charAt(i); hashValue = (hashValue + (ch - 'a' + 1) * powers[i]) % m; } return hashValue; } } class BasicFunctions { public long min(long[] A) { long min = Long.MAX_VALUE; for(int i=0;i<A.length;i++) { min = Math.min(min, A[i]); } return min; } public long max(long[] A) { long max = Long.MAX_VALUE; for(int i=0;i<A.length;i++) { max = Math.max(max, A[i]); } return max; } } class Matrix { long a; long b; long c; long d; public Matrix(long a, long b, long c, long d) { this.a = a; this.b = b; this.c = c; this.d = d; } } class MergeSortInt { // Merges two subarrays of arr[]. // First subarray is arr[l..m] // Second subarray is arr[m+1..r] void merge(int arr[], int l, int m, int r) { // Find sizes of two subarrays to be merged int n1 = m - l + 1; int n2 = r - m; /* Create temp arrays */ int L[] = new int[n1]; int R[] = new int[n2]; /*Copy data to temp arrays*/ for (int i = 0; i < n1; ++i) L[i] = arr[l + i]; for (int j = 0; j < n2; ++j) R[j] = arr[m + 1 + j]; /* Merge the temp arrays */ // Initial indexes of first and second subarrays int i = 0, j = 0; // Initial index of merged subarry array int k = l; while (i < n1 && j < n2) { if (L[i] <= R[j]) { arr[k] = L[i]; i++; } else { arr[k] = R[j]; j++; } k++; } /* Copy remaining elements of L[] if any */ while (i < n1) { arr[k] = L[i]; i++; k++; } /* Copy remaining elements of R[] if any */ while (j < n2) { arr[k] = R[j]; j++; k++; } } // Main function that sorts arr[l..r] using // merge() void sort(int arr[], int l, int r) { if (l < r) { // Find the middle point int m = (l + r) / 2; // Sort first and second halves sort(arr, l, m); sort(arr, m + 1, r); // Merge the sorted halves merge(arr, l, m, r); } } } class MergeSortLong { // Merges two subarrays of arr[]. // First subarray is arr[l..m] // Second subarray is arr[m+1..r] void merge(long arr[], int l, int m, int r) { // Find sizes of two subarrays to be merged int n1 = m - l + 1; int n2 = r - m; /* Create temp arrays */ long L[] = new long[n1]; long R[] = new long[n2]; /*Copy data to temp arrays*/ for (int i = 0; i < n1; ++i) L[i] = arr[l + i]; for (int j = 0; j < n2; ++j) R[j] = arr[m + 1 + j]; /* Merge the temp arrays */ // Initial indexes of first and second subarrays int i = 0, j = 0; // Initial index of merged subarry array int k = l; while (i < n1 && j < n2) { if (L[i] <= R[j]) { arr[k] = L[i]; i++; } else { arr[k] = R[j]; j++; } k++; } /* Copy remaining elements of L[] if any */ while (i < n1) { arr[k] = L[i]; i++; k++; } /* Copy remaining elements of R[] if any */ while (j < n2) { arr[k] = R[j]; j++; k++; } } // Main function that sorts arr[l..r] using // merge() void sort(long arr[], int l, int r) { if (l < r) { // Find the middle point int m = (l + r) / 2; // Sort first and second halves sort(arr, l, m); sort(arr, m + 1, r); // Merge the sorted halves merge(arr, l, m, r); } } } class Node { String s; Node(String s) { this.s = s; } @Override public boolean equals(Object ob) { if(ob == null) return false; if(!(ob instanceof Node)) return false; if(ob == this) return true; Node obj = (Node)ob; if(this.s.equals(obj.s)) return true; return false; } @Override public int hashCode() { return (int)this.s.length(); } } 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(); } } class FenwickTree { public void update(long[] fenwickTree,long delta,int index) { index += 1; while(index < fenwickTree.length) { fenwickTree[index] += delta; index = index + (index & (-index)); } } public long prefixSum(long[] fenwickTree,int index) { long sum = 0L; index += 1; while(index > 0) { sum += fenwickTree[index]; index -= (index & (-index)); } return sum; } } class SegmentTree { public int nextPowerOfTwo(int num) { if(num == 0) return 1; if(num > 0 && (num & (num - 1)) == 0) return num; while((num &(num - 1)) > 0) { num = num & (num - 1); } return num << 1; } public int[] createSegmentTree(int[] input) { int np2 = nextPowerOfTwo(input.length); int[] segmentTree = new int[np2 * 2 - 1]; for(int i=0;i<segmentTree.length;i++) segmentTree[i] = Integer.MIN_VALUE; constructSegmentTree(segmentTree,input,0,input.length-1,0); return segmentTree; } private void constructSegmentTree(int[] segmentTree,int[] input,int low,int high,int pos) { if(low == high) { segmentTree[pos] = input[low]; return; } int mid = (low + high)/ 2; constructSegmentTree(segmentTree,input,low,mid,2*pos + 1); constructSegmentTree(segmentTree,input,mid+1,high,2*pos + 2); segmentTree[pos] = Math.max(segmentTree[2*pos + 1],segmentTree[2*pos + 2]); } public int rangeMinimumQuery(int []segmentTree,int qlow,int qhigh,int len) { return rangeMinimumQuery(segmentTree,0,len-1,qlow,qhigh,0); } private int rangeMinimumQuery(int segmentTree[],int low,int high,int qlow,int qhigh,int pos) { if(qlow <= low && qhigh >= high){ return segmentTree[pos]; } if(qlow > high || qhigh < low){ return Integer.MIN_VALUE; } int mid = (low+high)/2; return Math.max(rangeMinimumQuery(segmentTree, low, mid, qlow, qhigh, 2 * pos + 1), rangeMinimumQuery(segmentTree, mid + 1, high, qlow, qhigh, 2 * pos + 2)); } } class Trie { private class TrieNode { Map<Character, TrieNode> children; boolean endOfWord; public TrieNode() { children = new HashMap<>(); endOfWord = false; } } private final TrieNode root; public Trie() { root = new TrieNode(); } public void insert(String word) { TrieNode current = root; for (int i = 0; i < word.length(); i++) { char ch = word.charAt(i); TrieNode node = current.children.get(ch); if (node == null) { node = new TrieNode(); current.children.put(ch, node); } current = node; } current.endOfWord = true; } public boolean search(String word) { TrieNode current = root; for (int i = 0; i < word.length(); i++) { char ch = word.charAt(i); TrieNode node = current.children.get(ch); if (node == null) { return false; } current = node; } return current.endOfWord; } public void delete(String word) { delete(root, word, 0); } private boolean delete(TrieNode current, String word, int index) { if (index == word.length()) { if (!current.endOfWord) { return false; } current.endOfWord = false; return current.children.size() == 0; } char ch = word.charAt(index); TrieNode node = current.children.get(ch); if (node == null) { return false; } boolean shouldDeleteCurrentNode = delete(node, word, index + 1); if (shouldDeleteCurrentNode) { current.children.remove(ch); return current.children.size() == 0; } return false; } }
Java
["ABACABA", "AAA"]
1 second
["3\n1 4\n3 2\n7 1", "3\n1 3\n2 2\n3 1"]
null
Java 8
standard input
[ "dp", "two pointers", "string suffix structures", "strings" ]
3fb70a77e4de4851ed93f988140df221
The single line contains a sequence of characters s1s2...s|s| (1 ≀ |s| ≀ 105) β€” string s. The string only consists of uppercase English letters.
2,000
In the first line, print integer k (0 ≀ k ≀ |s|) β€” the number of prefixes that match a suffix of string s. Next print k lines, in each line print two integers li ci. Numbers li ci mean that the prefix of the length li matches the suffix of length li and occurs in string s as a substring ci times. Print pairs li ci in the order of increasing li.
standard output
PASSED
7115f1194cf26cd5337e84c29e2c6b28
train_003.jsonl
1400167800
You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: A substring s[i..j] (1 ≀ i ≀ j ≀ |s|) of string s is string sisi + 1...sj. The prefix of string s of length l (1 ≀ l ≀ |s|) is string s[1..l]. The suffix of string s of length l (1 ≀ l ≀ |s|) is string s[|s| - l + 1..|s|]. Your task is, for any prefix of string s which matches a suffix of string s, print the number of times it occurs in string s as a substring.
256 megabytes
import java.util.*; import java.io.*; public class PrefixesandSuffixes { /************************ SOLUTION STARTS HERE ************************/ static int[] KMPPrefixFunction(char str[]) { int n = str.length; int prefix[] = new int[n]; // Stores the length of largest border for a prefix for(int i = 1; i < n; i++) { int border; for(border = prefix[i - 1]; border > 0 && str[border] != str[i]; border = prefix[border - 1]) ; prefix[i] = str[i] == str[border] ? border + 1: 0; } return prefix; } static ArrayList<Integer>[] adj; static int reachable[]; static int countReachable(int u, int par) { for(int v : adj[u]) if(v != par) reachable[u] += countReachable(v, u); return reachable[u]; } private static void solve() { char str[] = nextLine().toCharArray(); int prefix[] = KMPPrefixFunction(str); // System.out.println(Arrays.toString(prefix)); adj = new ArrayList[str.length + 1]; reachable = new int[str.length + 1]; for(int i = 0; i <= str.length; i++) adj[i] = new ArrayList<>(); for(int i = 1; i <= str.length; i++) { reachable[prefix[i - 1]]++; adj[prefix[i - 1]].add(i); } countReachable(0, -1); ArrayDeque<int[]> stack = new ArrayDeque<>(); stack.push(new int[] {str.length, 1}); for(int border = prefix[str.length - 1]; border > 0; border = prefix[border - 1]) stack.push(new int[] {border, reachable[border] + 1}); // one for the prefix println(stack.size()); stack.stream().forEach(pair -> println(pair[0] + " " + pair[1])); } /************************ SOLUTION ENDS HERE ************************/ /************************ TEMPLATE STARTS HERE **********************/ public static void main(String[] args) throws IOException { reader = new BufferedReader(new InputStreamReader(System.in)); writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false); st = null; solve(); reader.close(); writer.close(); } static BufferedReader reader; static PrintWriter writer; static StringTokenizer st; static String next() {while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;} st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();} static String nextLine() {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;} static int nextInt() {return Integer.parseInt(next());} static long nextLong() {return Long.parseLong(next());} static double nextDouble(){return Double.parseDouble(next());} static char nextChar() {return next().charAt(0);} static int[] nextIntArray(int n) {int[] a= new int[n]; int i=0;while(i<n){a[i++]=nextInt();} return a;} static long[] nextLongArray(int n) {long[]a= new long[n]; int i=0;while(i<n){a[i++]=nextLong();} return a;} static int[] nextIntArrayOneBased(int n) {int[] a= new int[n+1]; int i=1;while(i<=n){a[i++]=nextInt();} return a;} static long[] nextLongArrayOneBased(int n){long[]a= new long[n+1];int i=1;while(i<=n){a[i++]=nextLong();}return a;} static void print(Object o) { writer.print(o); } static void println(Object o){ writer.println(o);} /************************ TEMPLATE ENDS HERE ************************/ }
Java
["ABACABA", "AAA"]
1 second
["3\n1 4\n3 2\n7 1", "3\n1 3\n2 2\n3 1"]
null
Java 8
standard input
[ "dp", "two pointers", "string suffix structures", "strings" ]
3fb70a77e4de4851ed93f988140df221
The single line contains a sequence of characters s1s2...s|s| (1 ≀ |s| ≀ 105) β€” string s. The string only consists of uppercase English letters.
2,000
In the first line, print integer k (0 ≀ k ≀ |s|) β€” the number of prefixes that match a suffix of string s. Next print k lines, in each line print two integers li ci. Numbers li ci mean that the prefix of the length li matches the suffix of length li and occurs in string s as a substring ci times. Print pairs li ci in the order of increasing li.
standard output
PASSED
75fe334e27dea61d7b99a276a05ce8ab
train_003.jsonl
1400167800
You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: A substring s[i..j] (1 ≀ i ≀ j ≀ |s|) of string s is string sisi + 1...sj. The prefix of string s of length l (1 ≀ l ≀ |s|) is string s[1..l]. The suffix of string s of length l (1 ≀ l ≀ |s|) is string s[|s| - l + 1..|s|]. Your task is, for any prefix of string s which matches a suffix of string s, print the number of times it occurs in string s as a substring.
256 megabytes
import java.util.Scanner; public class _29_Prefixes_and_Suffixes { public static void main(String[] args) { Scanner scn = new Scanner(System.in); String s = scn.next(); int[] z = new int[s.length()]; int[] count = new int[s.length() + 1]; getZarr(s, z); int k = 0; for (int i = 0; i < z.length; i++) { count[z[i]]++; } for (int i = s.length() - 1; i >= 0; i--) { count[i] += count[i + 1]; if (z[i] == s.length() - i) { k++; } } System.out.println(k+1); for (int i = s.length()-1; i >=0; i--) { if (z[i] == s.length() - i) { System.out.println(z[i] + " " + (count[z[i]]+1)); } } System.out.println(s.length()+" "+1); } public static void getZarr(String str, int[] Z) { int n = str.length(); // [L,R] make a window which matches with // prefix of s int L = 0, R = 0; for (int i = 0; i < n; ++i) { // if i>R nothing matches so we will calculate. // Z[i] using naive way. if (i > R) { L = R = i; // R-L = 0 in starting, so it will start // checking from 0'th index. For example, // for "ababab" and i = 1, the value of R // remains 0 and Z[i] becomes 0. For string // "aaaaaa" and i = 1, Z[i] and R become 5 while (R < n && str.charAt(R - L) == str.charAt(R)) R++; Z[i] = R - L; R--; } else { // k = i-L so k corresponds to number which // matches in [L,R] interval. int k = i - L; // if Z[k] is less than remaining interval // then Z[i] will be equal to Z[k]. // For example, str = "ababab", i = 3, R = 5 // and L = 2 if (Z[k] < R - i + 1) Z[i] = Z[k]; // For example str = "aaaaaa" and i = 2, R is 5, // L is 0 else { // else start from R and check manually L = i; while (R < n && str.charAt(R - L) == str.charAt(R)) R++; Z[i] = R - L; R--; } } } } }
Java
["ABACABA", "AAA"]
1 second
["3\n1 4\n3 2\n7 1", "3\n1 3\n2 2\n3 1"]
null
Java 8
standard input
[ "dp", "two pointers", "string suffix structures", "strings" ]
3fb70a77e4de4851ed93f988140df221
The single line contains a sequence of characters s1s2...s|s| (1 ≀ |s| ≀ 105) β€” string s. The string only consists of uppercase English letters.
2,000
In the first line, print integer k (0 ≀ k ≀ |s|) β€” the number of prefixes that match a suffix of string s. Next print k lines, in each line print two integers li ci. Numbers li ci mean that the prefix of the length li matches the suffix of length li and occurs in string s as a substring ci times. Print pairs li ci in the order of increasing li.
standard output
PASSED
4c562fcf212753c1eadde4679701247a
train_003.jsonl
1400167800
You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: A substring s[i..j] (1 ≀ i ≀ j ≀ |s|) of string s is string sisi + 1...sj. The prefix of string s of length l (1 ≀ l ≀ |s|) is string s[1..l]. The suffix of string s of length l (1 ≀ l ≀ |s|) is string s[|s| - l + 1..|s|]. Your task is, for any prefix of string s which matches a suffix of string s, print the number of times it occurs in string s as a substring.
256 megabytes
import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; public class Main { InputStream is; PrintWriter out; String INPUT = ""; void solve() { char[] s = ns().toCharArray(); int[] z = Z(s); int n = z.length; long[] f = new long[n + 5]; boolean[] zf = new boolean[n + 5]; int ct = 0; for(int i = 0; i < n; i++) { if(z[i] + i == n) { zf[z[i]] = true; ct++; } f[z[i]]++; } long sum = 0; for(int i = f.length-1; i >= 0; i--) { if(f[i] > 0) { f[i] += sum; sum = f[i]; } } out.println(ct); for(int i = 1; i <= n; i++) { if(zf[i]) { out.println(i+" "+f[i]); } } } public static int[] Z(char[] str) { int n = str.length; int[] z = new int[n]; if(n == 0)return z; z[0] = n; int l = 0, r = 0; for(int i = 1;i < n;i++){ if(i > r){ l = r = i; while(r < n && str[r-l] == str[r])r++; z[i] = r-l; r--; }else{ if(z[i-l] < r-i+1){ z[i] = z[i-l]; }else{ l = i; while(r < n && str[r-l] == str[r])r++; z[i] = r-l; r--; } } } return z; } void run() throws Exception { is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes()); out = new PrintWriter(System.out); long s = System.currentTimeMillis(); solve(); out.flush(); if (!INPUT.isEmpty()) tr(System.currentTimeMillis() - s + "ms"); } public static void main(String[] args) throws Exception { new Main().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 float nf() { return Float.parseFloat(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 static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); } }
Java
["ABACABA", "AAA"]
1 second
["3\n1 4\n3 2\n7 1", "3\n1 3\n2 2\n3 1"]
null
Java 8
standard input
[ "dp", "two pointers", "string suffix structures", "strings" ]
3fb70a77e4de4851ed93f988140df221
The single line contains a sequence of characters s1s2...s|s| (1 ≀ |s| ≀ 105) β€” string s. The string only consists of uppercase English letters.
2,000
In the first line, print integer k (0 ≀ k ≀ |s|) β€” the number of prefixes that match a suffix of string s. Next print k lines, in each line print two integers li ci. Numbers li ci mean that the prefix of the length li matches the suffix of length li and occurs in string s as a substring ci times. Print pairs li ci in the order of increasing li.
standard output
PASSED
348bf88f28d0a3d646288e56c7398710
train_003.jsonl
1400167800
You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: A substring s[i..j] (1 ≀ i ≀ j ≀ |s|) of string s is string sisi + 1...sj. The prefix of string s of length l (1 ≀ l ≀ |s|) is string s[1..l]. The suffix of string s of length l (1 ≀ l ≀ |s|) is string s[|s| - l + 1..|s|]. Your task is, for any prefix of string s which matches a suffix of string s, print the number of times it occurs in string s as a substring.
256 megabytes
// ONE DAY, YOU WILL BE BEYOND THE REACH OF SPACE AND TIME. // // UNTIL THEN, STAY LOW AND CODE HARD. // // Author :- Saurabh// //BIT MESRA, RANCHI// import java.io.*; import java.util.*; import static java.lang.Math.*; public class prefixesAndSuffixes { static void Bolo_Jai_Mata_Di() { char ch[]=(" "+ns()).toCharArray(); n=ch.length-1; int dp[]=new int[100005]; int j=0; for(int i=2;i<=n;i++){ while(j!=0 && ch[j+1]!= ch[i])j=dp[j]; if(ch[j+1]==ch[i])j++; dp[i]=j; } j=n; int ar[]=new int[100005];int c=0; while(j!=0){ ar[j]++; c++; j=dp[j]; } int ans[]=new int[100005]; for(int i=n;i>=1;i--) ans[dp[i]]++; for(int i=n;i>=1;i--) ans[dp[i]]+=ans[i]; pl(c); for(int i=1;i<=n;i++) if(ar[i]!=0)pl(i+" "+(ans[i]+1)); flush(); } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //THE DON'T CARE ZONE BEGINS HERE...// static Calendar ts, te; //For time calculation static int mod9 = 1000000007; static int n, m, k, t, mod = 998244353; static Lelo input = new Lelo(System.in); static PrintWriter pw = new PrintWriter(System.out, true); public static void main(String[] args) { //threading has been used to increase the stack size. new Thread(null, null, "BlackRise", 1 << 25) //the last parameter is stack size desired., { public void run() { try { tsc(); Bolo_Jai_Mata_Di(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } }.start(); } static class Lelo { //Lelo class for fast input private InputStream ayega; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public Lelo(InputStream ayega) { this.ayega = ayega; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = ayega.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); } } // functions to take input// static int ni() { return input.nextInt(); } static long nl() { return input.nextLong(); } static double nd() { return input.nextDouble(); } static String ns() { return input.readString(); } //functions to give output static void pl() { pw.println(); } static void p(Object o) { pw.print(o + " "); } static void pws(Object o) { pw.print(o + ""); } static void pl(Object o) { pw.println(o); } static void tsc() //calculates the starting time of execution { ts = Calendar.getInstance(); ts.setTime(new Date()); } static void tec() //calculates the ending time of execution { te = Calendar.getInstance(); te.setTime(new Date()); } static void pwt() //prints the time taken for execution { pw.printf("\nExecution time was :- %f s\n", (te.getTimeInMillis() - ts.getTimeInMillis()) / 1000.00); } static void sort(int ar[], int n) { for (int i = 0; i < n; i++) { int ran = (int) (Math.random() * n); int temp = ar[i]; ar[i] = ar[ran]; ar[ran] = temp; } Arrays.sort(ar); } static void sort(long ar[], int n) { for (int i = 0; i < n; i++) { int ran = (int) (Math.random() * n); long temp = ar[i]; ar[i] = ar[ran]; ar[ran] = temp; } Arrays.sort(ar); } static void sort(char ar[], int n) { for (int i = 0; i < n; i++) { int ran = (int) (Math.random() * n); char temp = ar[i]; ar[i] = ar[ran]; ar[ran] = temp; } Arrays.sort(ar); } static void flush() { tec(); //ending time of execution //pwt(); //prints the time taken to execute the program pw.flush(); pw.close(); } }
Java
["ABACABA", "AAA"]
1 second
["3\n1 4\n3 2\n7 1", "3\n1 3\n2 2\n3 1"]
null
Java 8
standard input
[ "dp", "two pointers", "string suffix structures", "strings" ]
3fb70a77e4de4851ed93f988140df221
The single line contains a sequence of characters s1s2...s|s| (1 ≀ |s| ≀ 105) β€” string s. The string only consists of uppercase English letters.
2,000
In the first line, print integer k (0 ≀ k ≀ |s|) β€” the number of prefixes that match a suffix of string s. Next print k lines, in each line print two integers li ci. Numbers li ci mean that the prefix of the length li matches the suffix of length li and occurs in string s as a substring ci times. Print pairs li ci in the order of increasing li.
standard output
PASSED
669cf5f952d7f4771b85b13529d888bc
train_003.jsonl
1400167800
You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: A substring s[i..j] (1 ≀ i ≀ j ≀ |s|) of string s is string sisi + 1...sj. The prefix of string s of length l (1 ≀ l ≀ |s|) is string s[1..l]. The suffix of string s of length l (1 ≀ l ≀ |s|) is string s[|s| - l + 1..|s|]. Your task is, for any prefix of string s which matches a suffix of string s, print the number of times it occurs in string s as a substring.
256 megabytes
/** * BaZ :D */ 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,"BaZ",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(); char c[] = ne().toCharArray(); int n = c.length; char aux[] = new char[2*n+1]; for(int i=0;i<n;++i) { aux[i] = c[i]; } aux[n] = '#'; for(int i=n+1;i<=2*n;++i) { aux[i] = c[i-n-1]; } int Z[] = ComputeZArray(aux); int f[] = new int[n]; int idx = 1,j = 0; while(idx<n) { if(c[idx]==c[j]) { f[idx++] = ++j; } else if(j>0) { j = f[j-1]; } else idx++; } ArrayList<Integer> list = new ArrayList<>(); int len = n; while(len>0) { list.add(len); len = f[len-1]; } Collections.sort(list); int g[] = new int[n+1]; for(int i=n+1;i<=2*n;++i) { g[Z[i]]++; } for(int i=n-1;i>=0;--i) { g[i]+=g[i+1]; } pl(list.size()); for(int e:list) { pl(e+" "+g[e]); } pw.flush(); pw.close(); } static int[] ComputeZArray(char input[]) { int Z[] = new int[input.length]; int right = 0; int left = 0; for(int i=1;i<input.length;++i) { if(i>right) { left = right = i; while(right<input.length && input[right]==input[right-left]) ++right; Z[i] = right-left; --right; } else { int k = i-left; if(i+Z[k]<=right) Z[i] =Z[k]; else { left = i; while(right<input.length && input[right]==input[right-left]) ++right; Z[i] = right-left; --right; } } } return Z; } 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 void pa(String arrayName, Object arr[]) { pl(arrayName+" : "); for(Object o : arr) p(o); pl(); } static void pa(String arrayName, int arr[]) { pl(arrayName+" : "); for(int o : arr) p(o); pl(); } static void pa(String arrayName, long arr[]) { pl(arrayName+" : "); for(long o : arr) p(o); pl(); } static void pa(String arrayName, double arr[]) { pl(arrayName+" : "); for(double o : arr) p(o); pl(); } static void pa(String arrayName, char arr[]) { pl(arrayName+" : "); for(char o : arr) p(o); pl(); } static void pa(String listName, List list) { pl(listName+" : "); for(Object o : list) p(o); pl(); } static void pa(String arrayName, Object[][] arr) { pl(arrayName+" : "); for(int i=0;i<arr.length;++i) { for(Object o : arr[i]) p(o); pl(); } } static void pa(String arrayName, int[][] arr) { pl(arrayName+" : "); for(int i=0;i<arr.length;++i) { for(int o : arr[i]) p(o); pl(); } } static void pa(String arrayName, long[][] arr) { pl(arrayName+" : "); for(int i=0;i<arr.length;++i) { for(long o : arr[i]) p(o); pl(); } } static void pa(String arrayName, char[][] arr) { pl(arrayName+" : "); for(int i=0;i<arr.length;++i) { for(char o : arr[i]) p(o); pl(); } } static void pa(String arrayName, double[][] arr) { pl(arrayName+" : "); for(int i=0;i<arr.length;++i) { for(double o : arr[i]) p(o); pl(); } } 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
["ABACABA", "AAA"]
1 second
["3\n1 4\n3 2\n7 1", "3\n1 3\n2 2\n3 1"]
null
Java 8
standard input
[ "dp", "two pointers", "string suffix structures", "strings" ]
3fb70a77e4de4851ed93f988140df221
The single line contains a sequence of characters s1s2...s|s| (1 ≀ |s| ≀ 105) β€” string s. The string only consists of uppercase English letters.
2,000
In the first line, print integer k (0 ≀ k ≀ |s|) β€” the number of prefixes that match a suffix of string s. Next print k lines, in each line print two integers li ci. Numbers li ci mean that the prefix of the length li matches the suffix of length li and occurs in string s as a substring ci times. Print pairs li ci in the order of increasing li.
standard output
PASSED
2b3a8efafbd1a91c78cde9a4ebbca19a
train_003.jsonl
1400167800
You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: A substring s[i..j] (1 ≀ i ≀ j ≀ |s|) of string s is string sisi + 1...sj. The prefix of string s of length l (1 ≀ l ≀ |s|) is string s[1..l]. The suffix of string s of length l (1 ≀ l ≀ |s|) is string s[|s| - l + 1..|s|]. Your task is, for any prefix of string s which matches a suffix of string s, print the number of times it occurs in string s as a substring.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Iterator; import java.util.TreeSet; public class _432D { public static void main(String[] args) throws IOException { InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); String s = br.readLine(); int n = s.length(); int[] f = new int[n + 1]; int[] h = new int[n]; int[] ch = new int[n]; f[0] = f[1] = 0; TreeSet<Integer> set = new TreeSet<Integer>(); for (int i = 2; i <= n; i++) { int p = f[i - 1]; while (true) { if (s.charAt(p) == s.charAt(i - 1)) { f[i] = p + 1; break; } if (p == 0) { f[i] = 0; break; } p = f[p]; } if (f[i] != 0) { h[f[i]]++; ch[f[i]]++; set.add(f[i]); } } Iterator<Integer> tsi = set.descendingIterator(); boolean[] isc = new boolean[n]; while (tsi.hasNext()) { int tse = tsi.next(); if (!isc[tse]) { int pp = tse; isc[pp] = true; ch[pp] = h[pp]; int cp = f[tse]; int cs = h[pp]; while (cp > 0) { ch[cp] += cs; if (!isc[cp]) { cs += h[cp]; isc[cp] = true; } pp = cp; cp = f[pp]; } } } int p = f[n]; ArrayList<Integer> a1 = new ArrayList<Integer>(); ArrayList<Integer> a2 = new ArrayList<Integer>(); a1.add(n); a2.add(1); while (p > 0) { a1.add(p); a2.add(ch[p] + 1); p = f[p]; } System.out.println(a1.size()); for (int i = a1.size() - 1; i >= 0; i--) { System.out.println(a1.get(i) + " " + a2.get(i)); } } }
Java
["ABACABA", "AAA"]
1 second
["3\n1 4\n3 2\n7 1", "3\n1 3\n2 2\n3 1"]
null
Java 8
standard input
[ "dp", "two pointers", "string suffix structures", "strings" ]
3fb70a77e4de4851ed93f988140df221
The single line contains a sequence of characters s1s2...s|s| (1 ≀ |s| ≀ 105) β€” string s. The string only consists of uppercase English letters.
2,000
In the first line, print integer k (0 ≀ k ≀ |s|) β€” the number of prefixes that match a suffix of string s. Next print k lines, in each line print two integers li ci. Numbers li ci mean that the prefix of the length li matches the suffix of length li and occurs in string s as a substring ci times. Print pairs li ci in the order of increasing li.
standard output
PASSED
65bdfe021c036815379fecf4e61183d6
train_003.jsonl
1400167800
You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: A substring s[i..j] (1 ≀ i ≀ j ≀ |s|) of string s is string sisi + 1...sj. The prefix of string s of length l (1 ≀ l ≀ |s|) is string s[1..l]. The suffix of string s of length l (1 ≀ l ≀ |s|) is string s[|s| - l + 1..|s|]. Your task is, for any prefix of string s which matches a suffix of string s, print the number of times it occurs in string s as a substring.
256 megabytes
import java.util.*; public class Main{ static long MOD=(int)1e9+7; static int MAXN=1010; static long ncr[][]=new long[MAXN+4][MAXN+4]; public static void main(String args[]){ Scanner sc=new Scanner(System.in); String s=sc.next(); int z[]=zfun(s); int cnt[]=new int[s.length()+10]; StringBuilder sb=new StringBuilder(""); int cr=0; for(int i=0;i<z.length;i++){ if(z[i]>0){ cnt[0]++; cnt[z[i]+1]--; } } for(int i=1;i<=s.length();i++)cnt[i]+=cnt[i-1]; for(int i=s.length()-1;i>=0;i--){ if(i+z[i]==s.length()){sb.append(z[i]+" "+(cnt[z[i]]+1)+"\n");cr++;} } sb.append(s.length()+" "+1); System.out.println(cr+1); System.out.println(sb.toString()); } public static int[] zfun(String s){ int z[]=new int[s.length()]; int n=s.length(); //z[0]=n; for(int i=1,l=0,r=0;i<n;i++){ if(i>r){ l=r=i; while(r<n&&s.charAt(r-l)==s.charAt(r))r++; z[i]=r-l; r--; }else{ int k=i-l; if(z[k]<r-i+1){ z[i]=z[k]; }else{ l=i; while(r<n&&s.charAt(r-l)==s.charAt(r))r++; z[i]=r-l; r--; } } } return z; } }
Java
["ABACABA", "AAA"]
1 second
["3\n1 4\n3 2\n7 1", "3\n1 3\n2 2\n3 1"]
null
Java 8
standard input
[ "dp", "two pointers", "string suffix structures", "strings" ]
3fb70a77e4de4851ed93f988140df221
The single line contains a sequence of characters s1s2...s|s| (1 ≀ |s| ≀ 105) β€” string s. The string only consists of uppercase English letters.
2,000
In the first line, print integer k (0 ≀ k ≀ |s|) β€” the number of prefixes that match a suffix of string s. Next print k lines, in each line print two integers li ci. Numbers li ci mean that the prefix of the length li matches the suffix of length li and occurs in string s as a substring ci times. Print pairs li ci in the order of increasing li.
standard output
PASSED
b3b83d36d8c93c6a067a03c7d28922cb
train_003.jsonl
1400167800
You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: A substring s[i..j] (1 ≀ i ≀ j ≀ |s|) of string s is string sisi + 1...sj. The prefix of string s of length l (1 ≀ l ≀ |s|) is string s[1..l]. The suffix of string s of length l (1 ≀ l ≀ |s|) is string s[|s| - l + 1..|s|]. Your task is, for any prefix of string s which matches a suffix of string s, print the number of times it occurs in string s as a substring.
256 megabytes
import java.util.*; import java.lang.*; import java.math.*; import java.io.*; /* spar5h */ public class cf4 implements Runnable{ static class tuple { int i, x, y; public tuple(int i, int x, int y) { this.i = i; this.x = x; this.y = y; } } static class comp implements Comparator<tuple> { public int compare(tuple a, tuple b) { if(a.x < b.x) return -1; if(a.x > b.x) return 1; if(a.y < b.y) return -1; if(a.y > b.y) return 1; return 0; } } static int[][] rank; //longest common prefix static int lcp(int x, int y, int n, int lim) { if(x == y) return n - x; int res = 0; for(int i = lim - 1; i >= 0 && x < n && y < n; i--) { if(rank[x][i] == rank[y][i]) { x += 1 << i; y += 1 << i; res += 1 << i; } } return res; } public void run() { InputReader s = new InputReader(System.in); PrintWriter w = new PrintWriter(System.out); char[] c = s.next().toCharArray(); int n = c.length; int lim = (int)Math.ceil(Math.log(n) / Math.log(2)) + 1; int[] pow2 = new int[lim + 1]; pow2[0] = 1; for(int i = 1; i <= lim; i++) pow2[i] = pow2[i - 1] * 2; //obtain ranks & suffix array rank = new int[n][lim]; ArrayList<tuple> sa = new ArrayList<tuple>(); for(int i = 0; i < n; i++) sa.add(new tuple(i, c[i] - 'a', 0)); Collections.sort(sa, new comp()); int r = 0, pos = 0; while(pos < n) { int x = sa.get(pos).x; int y = sa.get(pos).y; while(pos < n && x == sa.get(pos).x && y == sa.get(pos).y) { rank[sa.get(pos).i][0] = r; pos++; } r++; } for(int i = 1; i < lim; i++) { sa = new ArrayList<tuple>(); for(int j = 0; j < n; j++) sa.add(new tuple(j, rank[j][i - 1], (j + pow2[i - 1] < n) ? rank[j + pow2[i - 1]][i - 1] : -1)); Collections.sort(sa, new comp()); r = 0; pos = 0; while(pos < n) { int x = sa.get(pos).x; int y = sa.get(pos).y; while(pos < n && x == sa.get(pos).x && y == sa.get(pos).y) { rank[sa.get(pos).i][i] = r; pos++; } r++; } } //solution boolean valid[] = new boolean[n]; for(int i = 0; i < n; i++) if(lcp(i, 0, n, lim) == n - i) valid[i] = true; int[] res = new int[n]; for(int i = 0; i < n; i++) { if(!valid[sa.get(i).i]) continue; int L = i, R = n - 1; while(L <= R) { int mid = (L + R) / 2; if(lcp(sa.get(i).i, sa.get(mid).i, n, lim) == n - sa.get(i).i) { res[sa.get(i).i] = mid - i + 1; L = mid + 1; } else R = mid - 1; } } int count = 0; for(int i = 0; i < n; i++) if(valid[i]) count++; w.println(count); for(int i = n - 1; i >= 0; i--) if(valid[i]) w.println(n - i + " " + res[i]); w.close(); } 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); } } public static void main(String args[]) throws Exception { new Thread(null, new cf4(),"cf4",1<<26).start(); } }
Java
["ABACABA", "AAA"]
1 second
["3\n1 4\n3 2\n7 1", "3\n1 3\n2 2\n3 1"]
null
Java 8
standard input
[ "dp", "two pointers", "string suffix structures", "strings" ]
3fb70a77e4de4851ed93f988140df221
The single line contains a sequence of characters s1s2...s|s| (1 ≀ |s| ≀ 105) β€” string s. The string only consists of uppercase English letters.
2,000
In the first line, print integer k (0 ≀ k ≀ |s|) β€” the number of prefixes that match a suffix of string s. Next print k lines, in each line print two integers li ci. Numbers li ci mean that the prefix of the length li matches the suffix of length li and occurs in string s as a substring ci times. Print pairs li ci in the order of increasing li.
standard output
PASSED
09500a76e6a177f330f21ed1b7d9bb6b
train_003.jsonl
1400167800
You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: A substring s[i..j] (1 ≀ i ≀ j ≀ |s|) of string s is string sisi + 1...sj. The prefix of string s of length l (1 ≀ l ≀ |s|) is string s[1..l]. The suffix of string s of length l (1 ≀ l ≀ |s|) is string s[|s| - l + 1..|s|]. Your task is, for any prefix of string s which matches a suffix of string s, print the number of times it occurs in string s as a substring.
256 megabytes
import java.io.*; import java.util.*; public class b { public static void main(String[] args) throws IOException, InterruptedException { Scanner zizo = new Scanner(System.in); PrintWriter wr = new PrintWriter(System.out); char[]c = zizo.next().toCharArray(); int[] z = zAlgo(c); ArrayList<Integer> a= new ArrayList<>(); for(int i = 0;i < c.length; i++) a.add(z[i]); Collections.sort(a, Collections.reverseOrder()); HashMap<Integer, Integer>map = new HashMap<>(); for(int i = 0;i < c.length; i++) map.put(a.get(i), i+1); PriorityQueue<pair>ans = new PriorityQueue<>(); for(int i = 0;i < c.length; i++) if(z[z.length-i-1] == i+1) ans.add(new pair(i+1,map.get(i+1)+1)); ans.add(new pair(z.length,1)); wr.println(ans.size()); while(!ans.isEmpty()) wr.println(ans.peek().l+" "+ans.poll().c); wr.close(); } static int[] zAlgo(char[] s) { int n = s.length; int[] z = new int[n]; for(int i = 1, l = 0, r = 0; i < n; ++i) { if(i <= r) z[i] = Math.min(r - i + 1, z[i - l]); while(i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i]; if(i + z[i] - 1 > r) r = i + z[l = i] - 1; } return z; } } class pair implements Comparable<pair>{ int l,c; pair(int a,int b){l = a;c = b;} @Override public int compareTo(pair o) { // TODO Auto-generated method stub return l-o.l; } } class DSU { int n,sets; int[]rank,parent,size; DSU(int n){ sets = n; rank = new int[n]; parent = new int[n]; size = new int[n]; for(int i = 0;i < n; i++) { size[i] = 1; parent[i] = i; } } int findSet(int i) { return parent[i] == i? i : (parent[i] = findSet(parent[i])); } boolean union(int u,int v) { int x = findSet(u); int y = findSet(v); if(x == y) return false; if(rank[x] < rank[y]) { size[y] += size[x]; parent[x] = y; } else { size[x] += size[y]; if(rank[x] == rank[y]) rank[x]++; parent[y] = x; } sets--; return true; } } class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));} public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException {return Integer.parseInt(next());} public long nextLong() throws IOException {return Long.parseLong(next());} public String nextLine() throws IOException {return br.readLine();} public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if(x.charAt(0) == '-') { neg = true; start++; } for(int i = start; i < x.length(); i++) if(x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if(dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg?-1:1); } public boolean ready() throws IOException {return br.ready();} }
Java
["ABACABA", "AAA"]
1 second
["3\n1 4\n3 2\n7 1", "3\n1 3\n2 2\n3 1"]
null
Java 8
standard input
[ "dp", "two pointers", "string suffix structures", "strings" ]
3fb70a77e4de4851ed93f988140df221
The single line contains a sequence of characters s1s2...s|s| (1 ≀ |s| ≀ 105) β€” string s. The string only consists of uppercase English letters.
2,000
In the first line, print integer k (0 ≀ k ≀ |s|) β€” the number of prefixes that match a suffix of string s. Next print k lines, in each line print two integers li ci. Numbers li ci mean that the prefix of the length li matches the suffix of length li and occurs in string s as a substring ci times. Print pairs li ci in the order of increasing li.
standard output
PASSED
ec5baba1603cf621ca4783604fcb5bb4
train_003.jsonl
1400167800
You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: A substring s[i..j] (1 ≀ i ≀ j ≀ |s|) of string s is string sisi + 1...sj. The prefix of string s of length l (1 ≀ l ≀ |s|) is string s[1..l]. The suffix of string s of length l (1 ≀ l ≀ |s|) is string s[|s| - l + 1..|s|]. Your task is, for any prefix of string s which matches a suffix of string s, print the number of times it occurs in string s as a substring.
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 Ribhav */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; FastReader in = new FastReader(inputStream); PrintWriter out = new PrintWriter(outputStream); DPrefixesAndSuffixes solver = new DPrefixesAndSuffixes(); solver.solve(1, in, out); out.close(); } static class DPrefixesAndSuffixes { public void solve(int testNumber, FastReader s, PrintWriter out) { String str = s.nextString(); int[] z = z(str); z[0] = z.length; // System.out.println(Arrays.toString(z)); int[] occ = new int[1000000]; for (int i = 0; i < z.length; i++) { occ[z[i]]++; } for (int i = occ.length - 2; i >= 0; i--) { occ[i] = occ[i + 1] + occ[i]; } int res = 0; for (int i = z.length - 1; i >= 0; i--) { if (z[i] + i == z.length) { res++; } } out.println(res); for (int i = z.length - 1; i >= 0; i--) { if (z[i] + i == z.length) { out.append(z[i] + " " + occ[z[i]] + "\n"); } } } static int[] z(String str) { char s[] = str.toCharArray(); int n = s.length; int z[] = new int[n]; for (int i = 1, L = 0, R = 0; i < n; ++i) { if (R < i) { L = R = i; while (R < n && s[R - L] == s[R]) R++; z[i] = R - L; R--; } else { int k = i - L; if (i + z[k] <= R) z[i] = z[k]; else { L = i; while (R < n && s[R] == s[R - L]) R++; z[i] = R - L; R--; } } } return z; } } static class FastReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private FastReader.SpaceCharFilter filter; public FastReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public String nextString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { if (Character.isValidCodePoint(c)) { res.appendCodePoint(c); } c = read(); } while (!isSpaceChar(c)); return res.toString(); } public 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
["ABACABA", "AAA"]
1 second
["3\n1 4\n3 2\n7 1", "3\n1 3\n2 2\n3 1"]
null
Java 8
standard input
[ "dp", "two pointers", "string suffix structures", "strings" ]
3fb70a77e4de4851ed93f988140df221
The single line contains a sequence of characters s1s2...s|s| (1 ≀ |s| ≀ 105) β€” string s. The string only consists of uppercase English letters.
2,000
In the first line, print integer k (0 ≀ k ≀ |s|) β€” the number of prefixes that match a suffix of string s. Next print k lines, in each line print two integers li ci. Numbers li ci mean that the prefix of the length li matches the suffix of length li and occurs in string s as a substring ci times. Print pairs li ci in the order of increasing li.
standard output
PASSED
8fece586ae577fa82396c41ce7786573
train_003.jsonl
1400167800
You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: A substring s[i..j] (1 ≀ i ≀ j ≀ |s|) of string s is string sisi + 1...sj. The prefix of string s of length l (1 ≀ l ≀ |s|) is string s[1..l]. The suffix of string s of length l (1 ≀ l ≀ |s|) is string s[|s| - l + 1..|s|]. Your task is, for any prefix of string s which matches a suffix of string s, print the number of times it occurs in string s as a substring.
256 megabytes
import java.io.*; import java.util.*; public class A implements Runnable{ public static void main (String[] args) {new Thread(null, new A(), "", 1 << 28).start();} public void run() { FastScanner fs = new FastScanner(); PrintWriter out = new PrintWriter(System.out); char[] a = fs.nextCharArray(); int n = a.length; int[] z = getZ(a); //a suffix is also a prefix if z[n - len(prefix)] = len(prefix) //the frequency of a prefix/suffix in a string is the number of //z values >= the length of the prefix/suffix int sz = 0; int[] freq = new int[n + 10]; boolean[] isBoth = new boolean[n]; for(int i = 0; i < n; i++) { freq[z[i]]++; if(z[n - i - 1] == i+1) { isBoth[i] = true; sz++; } } int[] res = new int[n]; int sum = 0; for(int i = n-1; i >= 0; i--) { sum += freq[i+1]; res[i] = sum; } isBoth[n-1] = true; sz++; out.println(sz); for(int i = 0; i < n; i++) { if(isBoth[i]) { out.println((i+1) + " " + (res[i] + 1)); } } out.close(); } int[] getZ (char[] a) { int[] z = new int[a.length]; int left = 0, right = 0; //left and right bounds for my z box for(int k = 1; k < a.length; k++) { if(k > right) { //we have to do actual comparisons here left = right = k; while(right < a.length && a[right] == a[right - left]) { //while my right pointer is matching the prefix of the string right++; } z[k] = right - left; //the length that was matched right--; } else { //reuse values because k lies inside my z box int k1 = k - left; //the position that we can reuse if(z[k1] < right - k + 1) { //the z value for this previous position can't get any more matches so just copy it. z[k] = z[k1]; } else { //we have to check to see if there are more matches left = k; while(right < a.length && a[right] == a[right - left]) { right++; } z[k] = right - left; right--; } } } return z; } public static int[] otherZ(String s) { int[] z = new int[s.length()]; for (int i = 1, l = 0, r = 0; i < z.length; ++i) { if (i <= r) z[i] = Math.min(r - i + 1, z[i - l]); while (i + z[i] < z.length && s.charAt(z[i]) == s.charAt(i + z[i])) ++z[i]; if (r < i + z[i] - 1) { l = i; r = i + z[i] - 1; } } return z; } class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); // br = new BufferedReader(new FileReader("chess.in")); st = new StringTokenizer(""); } catch (Exception e){e.printStackTrace();} } 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 nextInt() {return Integer.parseInt(next());} public long nextLong() {return Long.parseLong(next());} public double nextDouble() {return Double.parseDouble(next());} public String nextLine() { String line = ""; try {line = br.readLine();} catch (Exception e) {e.printStackTrace();} return line; } public Integer[] nextIntegerArray(int n) { Integer[] a = new Integer[n]; for(int i = 0; i < n; i++) a[i] = nextInt(); return a; } public int[] nextIntArray(int n) { int[] a = new int[n]; for(int i = 0; i < n; i++) a[i] = nextInt(); return a; } public char[] nextCharArray() {return nextLine().toCharArray();} } }
Java
["ABACABA", "AAA"]
1 second
["3\n1 4\n3 2\n7 1", "3\n1 3\n2 2\n3 1"]
null
Java 8
standard input
[ "dp", "two pointers", "string suffix structures", "strings" ]
3fb70a77e4de4851ed93f988140df221
The single line contains a sequence of characters s1s2...s|s| (1 ≀ |s| ≀ 105) β€” string s. The string only consists of uppercase English letters.
2,000
In the first line, print integer k (0 ≀ k ≀ |s|) β€” the number of prefixes that match a suffix of string s. Next print k lines, in each line print two integers li ci. Numbers li ci mean that the prefix of the length li matches the suffix of length li and occurs in string s as a substring ci times. Print pairs li ci in the order of increasing li.
standard output
PASSED
55cda523a597c1464ab296f7409a66e2
train_003.jsonl
1400167800
You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: A substring s[i..j] (1 ≀ i ≀ j ≀ |s|) of string s is string sisi + 1...sj. The prefix of string s of length l (1 ≀ l ≀ |s|) is string s[1..l]. The suffix of string s of length l (1 ≀ l ≀ |s|) is string s[|s| - l + 1..|s|]. Your task is, for any prefix of string s which matches a suffix of string s, print the number of times it occurs in string s as a substring.
256 megabytes
import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.StringTokenizer; public class Round246D { public static class HashingUtility { //If tle comes we can reduce number of hashes to even two... //Utilities final int[] m = new int[] { (int) 1e9 + 7, (int) 982451653, (int) 2038074743 }; final int[] p = new int[] { (int) 3571, (int) 7919, (int) 541 }; public int max; long[][] pre; long[][] invpre; int primes; String main_str; public long fast(long a, long n, long mod) { // used for inverse calculation and power calculation if (n == 0) { return 1; } else if (n == 1) { return a % mod; } long ans = fast(a, n / 2, mod); ans = ans * ans; ans %= mod; if ((n & 1) == 1) { ans = ans * (a % mod); ans %= mod; } return ans; } public HashingUtility(int primes, int max) { this.max = max; this.primes = primes; pre = new long[max][primes]; invpre = new long[max][primes]; PreCompute(); } public void PreCompute() { //creates powers and inverse powers for each hash for (int i = 0; i < primes; i++) { long val = p[i]; pre[0][i] = 1; invpre[0][i] = 1; long invval = fast(p[i], m[i] - 2, m[i]); long mod = m[i]; for (int j = 1; j < max; j++) { pre[j][i] = (pre[j - 1][i] * val) % mod; invpre[j][i] = (invpre[j - 1][i] * invval) % mod; } } } } public static class HashingTemplate { HashingUtility utis; int[][] prefix; int[][] suffix; String str; int primes; int n; public HashingTemplate(HashingUtility utis, String str, int primes) { this.str = str; this.utis = utis; this.n = str.length(); this.primes = primes; prefix = new int[n][primes]; suffix = new int[n][primes]; PREFIX(); SUFFIX(); } public int add(int a, int b, int mod) { long ans = (long) a + (long) b; if (ans >= mod) { ans -= mod; } return (int) ans; } public int mul(int a, int b, int mod) { long ans = (long) a * (long) b; if (ans >= mod) { ans %= mod; } return (int) ans; } public int get(char cc) { if (cc >= 'a' && cc <= 'z') { return cc - 'a' + 1; } //Considering only capital letters return cc - 'A' + 'z' - 'a' + 2; } public void PREFIX() { for (int j = 0; j < primes; j++) { prefix[0][j] = get(str.charAt(0)); int mod = utis.m[j]; for (int i = 1; i < n; i++) { prefix[i][j] = add(prefix[i - 1][j], mul(get(str.charAt(i)), (int) utis.pre[i][j], mod), mod); } } } public void SUFFIX() { for (int j = 0; j < primes; j++) { suffix[n - 1][j] = get(str.charAt(n - 1)); int mod = utis.m[j]; for (int i = n - 2; i >= 0; i--) { suffix[i][j] = add(suffix[i + 1][j], mul(get(str.charAt(i)), (int) utis.pre[n - i - 1][j], mod), mod); } } } public int[] RangeHash_Prefix(int start, int end) {// here start refers to left and end refers to right int[] hashes = new int[primes]; for (int i = 0; i < primes; i++) { long curr = (prefix[end][i] - (start == 0 ? 0 : prefix[start - 1][i])); if (curr < 0) { curr += utis.m[i]; } curr *= utis.invpre[start][i]; curr %= utis.m[i]; hashes[i] = (int) curr; } return hashes; } public int[] RangeHash_Suffix(int start, int end) { // here start refers to left and end refers to right int[] hashes = new int[primes]; for (int i = 0; i < primes; i++) { long curr = (suffix[start][i] - (end == n - 1 ? 0 : suffix[end + 1][i])); if (curr < 0) { curr += utis.m[i]; } curr *= utis.invpre[n - end - 1][i]; curr %= utis.m[i]; hashes[i] = (int) curr; } return hashes; } public boolean check(int[] hash1, int[] hash2) { int n = hash1.length; for (int i = 0; i < n; i++) { if (hash1[i] != hash2[i]) { return false; } } return true; } } public static int max = (int)1e5+10; public static HashingUtility utis; public static HashingTemplate hash; public static int[] ans; public static void solve() { utis = new HashingUtility(2, max); hash = new HashingTemplate(utis, s.next(), 2); int n = hash.n; ans = new int[n + 1]; ArrayList<Integer> start = new ArrayList<Integer>(); for(int i = 0; i < n; i++) { int[] hash1 = hash.RangeHash_Prefix(0, i); int[] hash2 = hash.RangeHash_Prefix(n - i - 1, n - 1); if(hash.check(hash1, hash2)) { start.add(i); } bs(i, n - 1); } for(int i = 2; i <= n; i++) { ans[i] += ans[i - 1]; } out.println(start.size()); for(Integer x : start) { out.println((x+1)+" "+(ans[x + 1])); } } public static void bs(int start, int end) { int len = -1; int tempstart = start; while(start <= end) { int mid = (start + end)>>1; int[] hash1 = hash.RangeHash_Prefix(tempstart, mid); int length = mid - tempstart + 1; int[] hash2 = hash.RangeHash_Prefix(0, length - 1); if(hash.check(hash1, hash2)) { start = mid + 1; len = length; }else { end = mid - 1; } } if(len == -1) return; ans[1] ++; if(len + 1 <= hash.n) ans[len+1] --; } public static void main(String[] args) { out = new PrintWriter(new BufferedOutputStream(System.out)); s = new FastReader(); solve(); out.close(); } public static FastReader s; public static PrintWriter out; public static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } double nextDouble() { return Double.parseDouble(next()); } long nextLong() { return Long.parseLong(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (Exception e) { e.printStackTrace(); } return str; } } }
Java
["ABACABA", "AAA"]
1 second
["3\n1 4\n3 2\n7 1", "3\n1 3\n2 2\n3 1"]
null
Java 8
standard input
[ "dp", "two pointers", "string suffix structures", "strings" ]
3fb70a77e4de4851ed93f988140df221
The single line contains a sequence of characters s1s2...s|s| (1 ≀ |s| ≀ 105) β€” string s. The string only consists of uppercase English letters.
2,000
In the first line, print integer k (0 ≀ k ≀ |s|) β€” the number of prefixes that match a suffix of string s. Next print k lines, in each line print two integers li ci. Numbers li ci mean that the prefix of the length li matches the suffix of length li and occurs in string s as a substring ci times. Print pairs li ci in the order of increasing li.
standard output
PASSED
e18753a39f9310353fcdbdd0e809d806
train_003.jsonl
1400167800
You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: A substring s[i..j] (1 ≀ i ≀ j ≀ |s|) of string s is string sisi + 1...sj. The prefix of string s of length l (1 ≀ l ≀ |s|) is string s[1..l]. The suffix of string s of length l (1 ≀ l ≀ |s|) is string s[|s| - l + 1..|s|]. Your task is, for any prefix of string s which matches a suffix of string s, print the number of times it occurs in string s as a substring.
256 megabytes
import java.util.Scanner; import java.util.Stack; public class Main { private static int[][] dfa = new int[27][100_005]; // the KMP automoton static int[] pref; /** * Preprocesses the pattern string. * * @param pat * the pattern string */ public static void KMP(String pat) { int m = pat.length(); pref = new int[m + 1]; dfa[pat.charAt(0) - 'A'][0] = 1; for (int lps = 0, j = 1; j < m; j++) { for (int c = 0; c < 26; c++) dfa[c][j] = dfa[c][lps]; // Copy mismatch cases. dfa[pat.charAt(j) - 'A'][j] = j + 1; // Set match case. pref[j] = lps = dfa[pat.charAt(j) - 'A'][lps]; // Update restart // state. } } public static void main(String[] args) { String s = new Scanner(System.in).next(); KMP(s); int[] ans = new int[s.length() + 1]; for (int i = 0; i < s.length(); i++) ans[pref[i]]++; for (int i = s.length() - 1; i > 0; i--) ans[pref[i - 1]] += ans[i]; for (int i = 0; i <= s.length(); i++) ans[i]++; int lps = pref[s.length() - 1]; Stack<Integer> st = new Stack(); while (lps > 0) { st.add(lps); lps = pref[lps - 1]; } System.out.println(st.size() + 1); while (!st.isEmpty()) { int len = st.pop(); System.out.println(len + " " + ans[len]); } System.out.println(s.length() + " " + 1); } }
Java
["ABACABA", "AAA"]
1 second
["3\n1 4\n3 2\n7 1", "3\n1 3\n2 2\n3 1"]
null
Java 8
standard input
[ "dp", "two pointers", "string suffix structures", "strings" ]
3fb70a77e4de4851ed93f988140df221
The single line contains a sequence of characters s1s2...s|s| (1 ≀ |s| ≀ 105) β€” string s. The string only consists of uppercase English letters.
2,000
In the first line, print integer k (0 ≀ k ≀ |s|) β€” the number of prefixes that match a suffix of string s. Next print k lines, in each line print two integers li ci. Numbers li ci mean that the prefix of the length li matches the suffix of length li and occurs in string s as a substring ci times. Print pairs li ci in the order of increasing li.
standard output
PASSED
ce7d9ee18a57ed4179781264448c8d6f
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
import java.util.* ; public class A { public static void main(String[] args) { Scanner sc = new Scanner(System.in); StringBuilder sb = new StringBuilder(); int t = sc.nextInt(); while(t-->0) { String a = sc.next(),b=sc.next(),c=sc.next(); sb.append((solve(a,b,c) ? "YES" : "NO") + "\n"); } System.out.print(sb); } static boolean solve(String a, String b , String c) { for(int i=0;i<a.length();i++) { if(a.charAt(i) != b.charAt(i)) { if(a.charAt(i)==c.charAt(i) || b.charAt(i)==c.charAt(i)) { continue; } else { return false; } } else { if(a.charAt(i)!=c.charAt(i)) { return false; } } } return true; } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
c9b5b85c528c02dcfe84d31b86198cf8
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
import java.util.*; public class cpts { public static void main (String[] args) { Scanner in = new Scanner(System.in); int T=in.nextInt(); for(int t=0;t<T;t++) { String a = in.next(); String b = in.next(); String c = in.next(); for (int i = 0; i < a.length(); i++) { if (c.charAt(i) != a.charAt(i) && b.charAt(i) != c.charAt(i)) { System.out.println("NO"); break; } if (i == a.length() - 1) { System.out.println("YES"); } } } } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
d5a1b3b8d2b734b744d4abe1e1c6d5d6
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
import java.util.Scanner; public class Chatroom { public static void main(String[] args) { Scanner s=new Scanner(System.in); int t=s.nextInt(); while(t-->0) { int flag=0; String a=s.next(); String b=s.next(); String c=s.next(); char []a1=a.toCharArray(); char []b1=b.toCharArray(); char[]c1=c.toCharArray(); for(int i=0;i<a1.length;i++) { char temp=0; if(c1[i]==a1[i]) { temp=c1[i]; c1[i]=a1[i]; a1[i]=temp; } else if(c1[i]==b1[i]) { temp=c1[i]; c1[i]=b1[i]; b1[i]=temp; } else { flag=1; break; } } if(flag==1) { System.out.println("NO"); } else { System.out.println("YES"); } } } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
c8cca821b0a9510b56043a3055fba8aa
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
import java.util.*; import java.io.*; public class Main{ public static void main(String []args)throws Exception{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int T=Integer.parseInt(br.readLine()); while(T-- > 0){ String a=br.readLine(); String b=br.readLine(); String c=br.readLine(); int len=b.length(); int count=0; for(int i=0;i<len;i++){ char ch=c.charAt(i); if(a.charAt(i)==ch ||b.charAt(i)==ch)count++; else break; } if(count==len)System.out.println("YES"); else System.out.println("NO"); } } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
052417b273f37e1cf6a997c672ab4761
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
import java.io.*; import java.util.*; public class MyClass { public static void main(String args[]) { FastReader sc = new FastReader(); //For Fast IO //func f = new func(); //Call func for swap , permute, upper bound and for sort. StringBuilder sb = new StringBuilder(); int t = sc.nextInt(); while(t-->0){ String a = sc.nextLine(); String b = sc.nextLine(); String c = sc.nextLine(); int n = a.length(); int f=0; int x=0; for(int i=0;i<n;i++){ char a1 = a.charAt(i); char b1 = b.charAt(i); char c1 = c.charAt(i); if(a1==b1 && a1==c1 && x==0){continue;} else if(c1==b1){x=1;continue;} else if(c1==a1){x=1;continue;} else{ f=1; break; } } if(f==1){ sb.append("NO\n"); } else{ sb.append("YES\n"); } } System.out.println(sb); } } class Pair{ int x; int y; Pair(int i,int j){ x=i; y=j; } @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Pair)) return false; Pair key = (Pair) o; return x == key.x && y == key.y; } @Override public int hashCode() { int result = x; result = 31*result + y; return result; } } class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } class func{ static ArrayList<String> al = new ArrayList<>(); public static void sort(long[] arr) { int n = arr.length, mid, h, s, l, i, j, k; long[] res = new long[n]; for (s = 1; s < n; s <<= 1) { for (l = 0; l < n - 1; l += (s << 1)) { h = Math.min(l + (s << 1) - 1, n - 1); mid = Math.min(l + s - 1, n - 1); i = l; j = mid + 1; k = l; while (i <= mid && j <= h) res[k++] = (arr[i] <= arr[j] ? arr[i++] : arr[j++]); while (i <= mid) res[k++] = arr[i++]; while (j <= h) res[k++] = arr[j++]; for (k = l; k <= h; k++) arr[k] = res[k]; } } } public static void permute(char a[] , int i , int n){ if(i==n-1){ String s = new String(a); al.add(s); // al stores all permutations of string. return; } for(int j=i;j<n;j++){ swap(a,i,j); permute(a,i+1,n); swap(a,i,j); } } public static void swap(char a[],int i, int j){ char temp = a[i]; a[i] = a[j]; a[j] = temp; } public static void swap(int a[],int i, int j){ int temp = a[i]; a[i] = a[j]; a[j] = temp; } //-It returns index of first element which is strictly greater than searched value. public static int upperBound(long[] array, int length, long value) { int low = 0; int high = length; while (low < high) { final int mid = (low + high) / 2; if (value >= array[mid]) { low = mid + 1; } else { high = mid; } } return low; } /*If searched element doesn't exist function returns index of first element which is bigger than searched value.<br> * -If searched element is bigger than any array element function returns first index after last element.<br> * -If searched element is lower than any array element function returns index of first element.<br> * -If there are many values equals searched value function returns first occurrence.<br>*/ public static int lowerBound(long[] array, int length, long value) { int low = 0; int high = length; while (low < high) { final int mid = (low + high) / 2; if (value <= array[mid]) { high = mid; } else { low = mid + 1; } } return low; } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
7708fd3b3e8edfe3ab7b47b886e128b7
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Ideone { public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ String a=sc.next(); String b=sc.next(); String c=sc.next(); int count=0; for(int i=0;i<a.length();i++){ if(a.charAt(i)==c.charAt(i)|| b.charAt(i)==c.charAt(i)){ count++; } else break; } if(count==a.length()){ System.out.println("YES"); } else{ System.out.println("NO"); } } } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
de9cd7b24bb3fe72508075eba27f7d2e
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Solution { public static void main(String [] args) throws NumberFormatException, IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); while(t-->0) { String a = br.readLine(); String b = br.readLine(); String c = br.readLine(); int n = a.length(); boolean flag = true; for(int i=0;i<n;i++) { if(!(c.charAt(i)==b.charAt(i) || c.charAt(i)==a.charAt(i))) { System.out.println("NO"); flag = false; break; } } if(flag) { System.out.println("YES"); } } } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
de759058bed16e369cfee565ae6e58a9
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.InputMismatchException; public class A { public static void main(String[] args) throws Exception { // TODO Auto-generated method stub InputReader s = new InputReader(System.in); PrintWriter p = new PrintWriter(System.out); int t = s.nextInt(); while (t-- > 0) { String a = s.nextLine(); String b = s.nextLine(); String c = s.nextLine(); int flag = 0; for (int i = 0; i < a.length(); i++) { if (a.charAt(i) == b.charAt(i)) { if (a.charAt(i) != c.charAt(i)) { flag = 1; break; } } else if (a.charAt(i) != c.charAt(i) && b.charAt(i) != c.charAt(i)) { flag = 1; break; } } if (flag == 0) p.println("YES"); else p.println("NO"); } p.flush(); p.close(); } public static boolean prime(long n) { if (n == 1) { return false; } if (n == 2) { return true; } for (long i = 2; i <= (long) Math.sqrt(n); i++) { if (n % i == 0) return false; } return true; } public static ArrayList Divisors(long n) { ArrayList<Long> div = new ArrayList<>(); for (long i = 1; i <= Math.sqrt(n); i++) { if (n % i == 0) { div.add(i); if (n / i != i) div.add(n / i); } } return div; } public static int BinarySearch(long[] a, long k) { int n = a.length; int i = 0, j = n - 1; int mid = 0; if (k < a[0]) return 0; else if (k >= a[n - 1]) return n; else { while (j - i > 1) { mid = (i + j) / 2; if (k >= a[mid]) i = mid; else j = mid; } } return i + 1; } public static long GCD(long a, long b) { if (b == 0) return a; else return GCD(b, a % b); } public static long LCM(long a, long b) { return (a * b) / GCD(a, b); } 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 == 0 && p.y - y == 0; } 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
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
8aee5637b8733219b063840021ab912e
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); // StringTokenizer st = new StringTokenizer(br.readLine()); // int x = Integer.parseInt(st.nextToken()); int T = Integer.parseInt(br.readLine()); for (int t = 0; t < T; t++) { // int N = Integer.parseInt(br.readLine()); String a = br.readLine(); String b = br.readLine(); String c = br.readLine(); boolean no = false; for (int i = 0; i < a.length(); i++) { // if (a.charAt(i) == b.charAt(i)) { // continue; // } if (a.charAt(i) == c.charAt(i)) { continue; } else if (b.charAt(i) == c.charAt(i)) { continue; } no = true; break; } if (no) System.out.println("no"); else System.out.println("yes"); } } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
aa947723f4ae0f4a43bee7bb4d5ce792
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
import java.util.*; public class NewClass{ public static void main(String sdf[]){ Scanner in = new Scanner(System.in); int t = in.nextInt(); in.nextLine(); while(t-->0){ String a = in.nextLine(); String b = in.nextLine(); String c = in.nextLine(); int n = a.length(); boolean ans = true; for(int i=0;i<n;i++){ if(a.charAt(i)!=c.charAt(i) && b.charAt(i)!=c.charAt(i)){ ans = false; break; } } if(ans){ System.out.println("YES"); }else{ System.out.println("NO"); } } } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
298a42d8f0473689cfeaf3c0ee7ddd9d
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
import java.util.ArrayList; import java.awt.Dimension; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Objects; import java.util.PriorityQueue; import java.util.Queue; import java.util.Scanner; import java.util.Set; import java.util.SortedMap; import java.util.SortedSet; import java.util.Stack; import java.util.TreeMap; import java.util.TreeSet; import java.util.regex.Pattern; import java.util.stream.Collectors; import com.sun.org.apache.xpath.internal.operations.Mod; import java.util.Comparator; import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.text.SimpleDateFormat; import java.time.LocalDate; public class myFile { public void finalize() { System.out.println("Cl"); } public static void main(String args[]) { int test,n,i,length; String a,b,c; Scanner sc = new Scanner(System.in); test = sc.nextInt(); sc.nextLine(); while(test>0) { test--; a=sc.nextLine(); b=sc.nextLine(); c=sc.nextLine(); length=a.length(); boolean ans=true; for(i=0;i<length;i++) { if(a.charAt(i)==c.charAt(i) || b.charAt(i)==c.charAt(i)) { continue; } else ans=false; } if(ans)System.out.println("YES"); else System.out.println("NO"); } } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
e15c56cb0d8661f5f7e9905776af08ba
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
import java.io.*; import java.math.*; import java.security.*; import java.text.*; import java.time.LocalTime; import java.util.*; import java.util.concurrent.*; import java.util.regex.*; public class Main { public static void main(String[] args) { FastScanner scan = new FastScanner(); int t = scan.nextInt(); for(int tt=0; tt<t; tt++) { String a = scan.next(), b = scan.next(), c = scan.next(); boolean works = true; for(int i=0; i<a.length() && works; i++) { if(a.charAt(i) == b.charAt(i) && a.charAt(i) != c.charAt(i)) works = false; if(a.charAt(i) != c.charAt(i) && b.charAt(i) != c.charAt(i)) works = false; } System.out.println((works) ? "YES" : "NO"); } } static class FastScanner{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() { while(!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e){ e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int [] readArray(int n) { int [] a = new int[n]; for(int i=0; i<n ; i++) a[i] = nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
2a2bb7eab7fe6b325cab23c7fc9ac7d0
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
import java.util.*; public class solution{ public static void main(String args[]){ Scanner sc = new Scanner(System.in); int test=sc.nextInt(); while(test-->0){ String s1=sc.next(); String s2=sc.next(); String s3=sc.next(); boolean done=true; for(int i=0;i<s1.length();i++){ if(s1.charAt(i)!=s3.charAt(i) && s2.charAt(i)!=s3.charAt(i)) { done=false; break; } } if(done) System.out.println("YES"); else System.out.println("NO"); } } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
6f49e14388edb47bf15a4a1315db8fe6
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
import java.io.*; public class P1301A_ThreeStrings { public static void main(String subhani[]) throws IOException, NumberFormatException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); while (t-- > 0) { String a = br.readLine(), b = br.readLine(), c = br.readLine(); solution(a, b, c); } } public static void solution(String a, String b, String c) { for (int i = 0; i < a.length(); ++i) { if (a.charAt(i) != b.charAt(i)) { if (a.charAt(i) == c.charAt(i)) { b = b.substring(0, i) + c.charAt(i) + b.substring(i + 1); } else if (b.charAt(i) == c.charAt(i)) { a = a.substring(0, i) + c.charAt(i) + a.substring(i + 1); } else { break; } } else if (a.charAt(i) == b.charAt(i) && a.charAt(i) != c.charAt(i)) { a = a.substring(0, i) + c.charAt(i) + a.substring(i + 1);// to make NO break; } } if (a.contentEquals(b)) System.out.println("YES"); else System.out.println("NO"); } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
d64e4fa2812cb925217b570c43b88c67
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
import java.util.Scanner; public class S { public static void main(String[] args) { // write your code here Scanner sc=new Scanner(System.in); int t=sc.nextInt(); try { for(int i=0;i<t;i++) { String a=sc.next(); String b=sc.next(); String c=sc.next(); int check=0; for(int j=0;j<a.length();j++) { char a1=a.charAt(j); char b1=b.charAt(j); char c1=c.charAt(j); if(a1==c1 || b1==c1 ) { check=0; } else { check=1; break; } } if(check==1) { System.out.println("NO"); } else { System.out.println("YES"); } } } catch (Exception e) { System.out.println(e); } } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
628ca4763c108958a3159d5cb67563a7
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
//package com.company; import java.util.Scanner; public class Main { static boolean solve(String a, String b, String c) { for (int i = 0; i < a.length(); i++) { char ac = a.charAt(i); char bc = b.charAt(i); char cc = c.charAt(i); if (ac != cc && bc != cc) return false; } return true; } // static void test(String a, String b, String c, boolean expected) { // boolean result = solve(a, b, c); // if (result != expected) { // throw new Error(); // } // } static Scanner scanner = new Scanner(System.in); public static void main(String[] args) { // write your code here int t = Integer.parseInt(scanner.nextLine()); for (int i = 0; i < t; i++) { String a = scanner.nextLine(); String b = scanner.nextLine(); String c = scanner.nextLine(); System.out.println(solve(a, b, c) ? "YES" : "NO"); } // test("aaa","bbb", "ccc", false); // test("abc","bca", "bca", true); // test("aabb","bbaa", "baba", true); // test("imi","mii", "iim", false); } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
66733b77b1e7c70c06e57f7c7d5d17c8
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
import java.util.*; import java.io.*; public final class Solution { public static boolean isPossible(String a,String b,String c,int n) { int cnt = 0; for(int i=0;i<n;i++) { if(a.charAt(i) == b.charAt(i)) { if((c.charAt(i) == b.charAt(i))) continue; else return false; } else if(a.charAt(i) == c.charAt(i) || b.charAt(i) == c.charAt(i)) { //swap occurs. cnt++; continue; } else { return false; } } return true; } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); for(int v=0;v<t;v++) { String s1 = br.readLine().trim(); String s2 = br.readLine().trim(); String s3 = br.readLine().trim(); int n = s1.length(); boolean res = isPossible(s1,s2,s3,n); if(res) System.out.println("YES"); else System.out.println("NO"); } } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
55ed1c7cddcee1801c5a22e427322452
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
import java.util.Scanner; // import java.util.ArrayList; // import java.util.Arrays; // import java.util.HashMap; // import java.util.HashSet; public class ans1{ static int mod = (int)10e8; public static int lower(int arr[],int key){ int low = 0; int high = arr.length-1; while(low < high){ int mid = low + (high - low)/2; if(arr[mid] >= key){ high = mid; } else{ low = mid+1; } } return low; } public static int upper(int arr[],int key){ int low = 0; int high = arr.length-1; while(low < high){ int mid = low + (high - low+1)/2; if(arr[mid] <= key){ low = mid; } else{ high = mid-1; } } return low; } public static void main(String args[]){ Scanner scn = new Scanner(System.in); int test = scn.nextInt(); StringBuilder sb = new StringBuilder(); scn.nextLine(); while(test-- > 0){ String a = scn.nextLine(); String b = scn.nextLine(); String c = scn.nextLine(); boolean flag = false; for(int i = 0 ; i < a.length() ; i++){ if(a.charAt(i) != c.charAt(i) && b.charAt(i) != c.charAt(i)){ sb.append("NO"); sb.append("\n"); flag = true; break; } } if(!flag){ sb.append("YES"); sb.append("\n"); } } System.out.println(sb); } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
0b26af32d42dc1420c17197f63ea1804
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
import java.util.*; public class MyClass { public static void main(String args[]) { Scanner in=new Scanner(System.in); int t=in.nextInt(); for(int j=0;j<t;j++){ char a[]=in.next().toCharArray(); char b[]=in.next().toCharArray(); char c[]=in.next().toCharArray(); int n=a.length; boolean poss=true; for(int i=0;i<n;i++){ if((a[i]==b[i]) && (a[i]!=c[i])){ poss=false; break; } if((a[i]==c[i]) || (b[i]==c[i])); else{ poss=false; break; } } if(poss) System.out.println("YES"); else System.out.println("NO"); } } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
ba07554714cfa92d6449e14297905c0c
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
import java.util.*; import java.io.*; public class A{ public static void main(String args[]){ Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0) { char a[] = sc.next().toCharArray(); char b[] = sc.next().toCharArray(); char[] c = sc.next().toCharArray(); boolean flag = true; for(int i =0;i<a.length;i++) { if(b[i] == c[i]) continue; if(a[i] == c[i]) continue; else { flag = false; break; } } if(flag) System.out.println("YES"); else System.out.println("NO"); } } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
47c215bec58d0703d3871dc189e841fd
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner scan = new Scanner(System.in); int t = scan.nextInt(); while(t-->0) { String a = scan.next(),b=scan.next(),c=scan.next(); int n=a.length(); boolean x = true; for(int i=0;i<n;i++) { char ai = a.charAt(i), bi = b.charAt(i), ci = c.charAt(i); if((ai!= bi && ci!=ai && bi!=ci) || (ai==bi && ci!=ai))x = false; //System.out.println(x+ " "+ai+" "+bi+" "+ci); } System.out.println(x?"YES":"NO"); } } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
9db88c0c2f0cdb6ee271a37ce7040929
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner input = new Scanner(System.in); String s=input.nextLine(); int n=Integer.parseInt(s); String[][] x=new String[n][3]; for(int i=0; i<n; i++){ for(int j=0; j<3; j++) {x[i][j]=input.nextLine();} } for(int i=0; i<n; i++){ if(x[i][0].equals(x[i][2])||x[i][1].equals(x[i][2])) {System.out.println("YES");} else{ boolean c=true; for(int k=0; k<x[i][0].length(); k++){ if(x[i][0].charAt(k)==x[i][2].charAt(k)|| x[i][1].charAt(k)==x[i][2].charAt(k)) {}else{c=false; break;} } System.out.println(c?"YES":"NO"); }} } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
8e767d410f7268586e8ba3d84899a361
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
import java.util.Scanner; public class Threestring { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while (t!=0){ String a=sc.next(),b=sc.next(),c=sc.next(); boolean bb=true; for (int i = 0; i < a.length(); i++) { if((a.charAt(i)==c.charAt(i))|| (c.charAt(i)==b.charAt(i))){ continue; } else { bb=false; } } if(bb){ System.out.println("Yes"); } else { System.out.println("No"); } t--; } }}
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
dfbf649f3f87d565cf801575fb633d1c
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { FastScanner scr = new FastScanner(); int t = scr.nextInt(); while (t-- > 0) { solve(scr); } } static void solve(FastScanner scr) { String aa = scr.nextToken(); String bb = scr.nextToken(); String cc = scr.nextToken(); int n = aa.length(); char a[] = aa.toCharArray(); char b[] = bb.toCharArray(); char c[] = cc.toCharArray(); int count = 0; for (int i = 0; i < n; i++) { if (a[i] == c[i]) { char tmp = b[i]; b[i] = c[i]; c[i] = tmp; count++; } else if (b[i] == c[i]) { char tmp = a[i]; a[i] = c[i]; c[i] = tmp; count++; } } if (Arrays.toString(a).equals(Arrays.toString(b)) && count == n) System.out.println("YES"); else System.out.println("NO"); } } class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner() { init(); } public FastScanner(String name) { init(name); } public FastScanner(boolean isOnlineJudge) { if (!isOnlineJudge || System.getProperty("ONLINE_JUDGE") != null) { init(); } else { init("input.txt"); } } private void init() { br = new BufferedReader(new InputStreamReader(System.in)); } private void init(String name) { try { br = new BufferedReader(new FileReader(name)); } catch (FileNotFoundException e) { e.printStackTrace(); } } public String nextToken() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(nextToken()); } public long nextLong() { return Long.parseLong(nextToken()); } public double nextDouble() { return Double.parseDouble(nextToken()); } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
359c964b04ed20466eb75dcbb073a21b
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
import java.util.Scanner; public class pre108 { public static void main(String args[]) { Scanner obj = new Scanner(System.in); int tc = obj.nextInt(); while(tc--!=0) { char[] s1 = obj.next().toCharArray(), s2 = obj.next().toCharArray(), s3 = obj.next().toCharArray(); boolean flag = true; if(((s1.length&s2.length)&s3.length)!=s1.length) { System.out.println("NO"); flag = false; } else { for(int i=0;i<s1.length;i++) { if(s1[i]==s2[i] && s1[i]!=s3[i]) { flag = false; break; } else if(s1[i]!=s3[i] && s3[i]!=s2[i]) { flag = false; break; } } } if(flag) System.out.println("YES"); else System.out.println("NO"); } } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
58ef02f9c2f9973b6b34b1f522771678
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
//package com.company.CompititivePrograming; import java.io.*; public class ThreeStrings { public static void main(String args[])throws IOException { BufferedWriter out=new BufferedWriter(new OutputStreamWriter(System.out)); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); for(int t=Integer.parseInt(br.readLine());t>0;t--){ String a=br.readLine(); String b=br.readLine(); String c=br.readLine(); boolean f=true; for(int i=0;i<a.length();i++){ if(a.charAt(i)!=c.charAt(i)&&b.charAt(i)!=c.charAt(i)){ f=false; break; } } if(f){ out.write("YES"+"\n"); }else{ out.write("NO"+"\n"); } } out.flush(); } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
3b2989d0e561812f7cc3038dd110b231
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
import java.io.*; public class A { private static String a, b, c = null; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); StringBuilder sb = new StringBuilder(); int t = Integer.parseInt(br.readLine()); for (int i = 0; i < t; i++) { a = br.readLine(); b = br.readLine(); c = br.readLine(); sb.append(answer()).append("\n"); a = null; b = null; c = null; } bw.write(sb.toString()); bw.flush(); bw.close(); br.close(); } private static String answer() { boolean answer = true; char[] aArr = a.toCharArray(); char[] bArr = b.toCharArray(); char[] cArr = c.toCharArray(); for (int i = 0; i < a.length(); i++) { if(aArr[i] == bArr[i] && aArr[i] != cArr[i]){ answer = false; break; } if(aArr[i] != bArr[i] && !(aArr[i] == cArr[i] || bArr[i] == cArr[i])){ answer = false; break; } } return answer? "YES" : "NO"; } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
7dbcde2a619aa725efffa2013cb01795
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
import java.util.*; public class ThreeStrings { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); sc.nextLine(); while(t-->0) { String a=sc.nextLine(); String b=sc.nextLine(); String c=sc.nextLine(); int n=a.length(); boolean ans=isTrue(a,b,c,n); if(ans==true) System.out.println("YES"); else System.out.println("NO"); } } static boolean isTrue(String a,String b,String c,int n) { boolean flag=false; for(int i=0;i<n;i++) { if(a.charAt(i)==c.charAt(i)||b.charAt(i)==c.charAt(i)) { flag=true; }else { flag=false; break; } } return flag; } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
b98fcfe042a0f5aa10c031cd9271d97c
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
import java.util.*; import java.lang.Math.*; public class Contests { public static void nl(){ System.out.println(); } public static Scanner sc = new Scanner(System.in); public static int rdint(){ return sc.nextInt(); } public static double rddbl(){ return sc.nextDouble(); } public static long rdlong(){ return sc.nextLong(); } public static long max(long a, long b){ return a > b ? a : b; } public static long max(long a, long b, long c){ return max(max(a, b), c); } public static long min(long a, long b){ return a < b ? a : b; } public static long min(long a, long b, long c){ return min(min(a, b), c); } public static void main(String[] args) { int t; t = rdint(); while(t-- != 0) { Set<Character> S = new HashSet<>(); String a = new String(), b = new String(), c = new String(); a = sc.next(); b = sc.next(); c = sc.next(); int n = a.length(); Boolean can = true; for(int i = 0; i < n; i++) { if(a.charAt(i) != c.charAt(i) && b.charAt(i) != c.charAt(i)) can = false; } System.out.println(can ? "YES" : "NO"); } } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
8a762ed58e4ce5037ae4e011575974a4
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
//package codeforces; public class ThreeStrings { public static void main(String[] args) { int t; String a, b, c; java.util.Scanner sc = new java.util.Scanner(System.in); t = sc.nextInt(); while(t-- != 0) { a = sc.next(); b = sc.next(); c = sc.next(); int flag = 0; for(int i = 0; i < a.length(); i++) { if(a.charAt(i) != c.charAt(i) && b.charAt(i) != c.charAt(i)) { flag = 1; break; } } if(flag == 0) { System.out.println("YES"); } else System.out.println("NO"); } sc.close(); } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
d52778760f98a6cadb3d3fbd6a7c60d6
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
import java.util.*; import java.io.*; import static java.lang.Math.*; public class Scanner_ { //global methods static class MyReader { BufferedReader br; StringTokenizer st; public MyReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String ne() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int ni() { return Integer.parseInt(ne()); } long nl() { return Long.parseLong(ne()); } double nd() { return Double.parseDouble(ne()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) { new Thread(null, null, "Rahsut", 1 << 25) { public void run() { try { Freak(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } }.start(); } static long modPow(long x, long p, long m) { if (p == 0) return 1; if (p % 2 == 0) return modPow((x * x) % m, p >> 1, m) % m; return x * (modPow(x, p - 1, m) % m) % m; } static long mul(long a, long b, long m) { a %= m; b %= m; return (a * b) % m; } static long gcd(long a,long b) { if(b%a==0) return a; return gcd(b%a,a); } static long lcm(long a, long b) { a/=gcd(a,b); return a*b; } public static class Pair implements Comparable<Pair> { long x, y; Pair(long x, long y) { this.x = x; this.y = y; } public int compareTo(Pair o) { if (x != o.x) return (int)x - (int)o.x; return (int)y - (int)o.y; } public String toString() { return x + " " + y; } } //global variables static MyReader sc = new MyReader(); static StringBuilder sb = new StringBuilder(); static PrintWriter pw = new PrintWriter(System.out, true); static int dir1[][]= {{1,0},{-1,0},{0,1},{0,-1}},n,q,t; static int dir2[][] ={{1,-1},{-1,1},{1,1},{-1,-1}}; static int dp[][], mod = (int)1e9 + 7; static char arr[]; static void Freak() throws IOException { int t = sc.ni(); while(t-->0) { char a[]= sc.ne().toCharArray(); char b[]= sc.ne().toCharArray(); char c[]= sc.ne().toCharArray(); n = a.length; boolean bool = false; for(int i =0;i<n;i++) { if(a[i]==c[i] || b[i]==c[i]) continue; // System.out.println(i); bool = true; break; } if(bool) sb.append("NO\n"); else sb.append("YES\n"); } pw.println(sb); pw.flush(); pw.close(); } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
c936f2b705215c974eff36c03dbc8890
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
import java.lang.*; import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { String a=sc.next(); String b=sc.next(); String c=sc.next(); char[] a1=a.toCharArray(); char[] b1=b.toCharArray(); char[] c1=c.toCharArray(); boolean ans=false; if(b.equals(c) || a.equals(c)) System.out.println("YES"); else{ for(int i=0;i<c1.length;i++) { if(c1[i]==b1[i] || c1[i]!=a1[i]) a1[i]=c1[i]; else if(c1[i]==a1[i] || c1[i]!=b1[i]) b1[i]=c1[i]; } String A=new String(a1); String B=new String(b1); if(A.equals(B)) System.out.println("YES"); else{ System.out.println("NO"); } } } } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
4bf591b32634238cd8573ac07e8e8f3d
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
import java.io.*; public class Test{ public static void main(String[] args)throws Exception { int t; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); t = Integer.parseInt(br.readLine()); while(t-- >0){ String a,b,c; a = br.readLine(); b = br.readLine(); c = br.readLine(); String[] s1 = a.split(""); String[] s2 = b.split(""); String[] s3 = c.split(""); int cp = 0; for(int i=0;i<s1.length;i++){ if(s1[i].equals(s3[i])) cp++; else if(s2[i].equals(s3[i])) cp++; } // System.out.print(cp); if(cp == s1.length) System.out.println("YES"); else System.out.println("NO"); } } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
0e5d1517b35393445431d6876be92fb8
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
import java.util.*; public class SST { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); while(n-->0) { String a=sc.next(); String b=sc.next(); String c=sc.next(); int f=0; for(int i=0;i<a.length();i++) { if(!(c.charAt(i)==a.charAt(i) || c.charAt(i)==b.charAt(i))) { f=1; break; }} if(f==0) System.out.println("YES"); else System.out.println("NO"); } } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
a054efefafc3dcc54df88cea0370d17b
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
import java.io.*; import java.util.*; public class ths{ public static void main(String []args){ Scanner sc = new Scanner(System.in); int n=sc.nextInt(); while(n-->0){ String a=sc.next(); String b=sc.next(); String c=sc.next(); int f=0; for(int i=0;i<a.length();i++){ if(a.charAt(i)==b.charAt(i) && c.charAt(i)==a.charAt(i)){ continue; }else if(a.charAt(i)!=b.charAt(i) && (a.charAt(i)==c.charAt(i) || b.charAt(i)==c.charAt(i))){ continue; }else{ System.out.println("NO"); f=1; break; } } if(f==0){ System.out.println("YES"); } } } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
056034feb5424d53327dde722282795c
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
import java.util.*; public class file{ public static void main(String[ ] args){ Scanner s=new Scanner(System.in); int test =s.nextInt(); s.nextLine(); for(int i=0;i<test ;i++){ String a=s.nextLine(); String b=s.nextLine(); String c=s.nextLine(); boolean flag =true; for(int j=0;j<c.length() ;j++){ if(a.charAt(j)==c.charAt(j) || b.charAt(j)== c.charAt(j)){ continue; }else{ System.out.println("NO"); flag =false ; break; } } if(flag){ System.out.println("YES"); } } } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
0c37a3843a8f5557923cd35f9005f623
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
//https://codeforces.com/contest/1301/problem/0 import java.util.Scanner; public class Problem_1301_A { private static Scanner scanner = new Scanner(System.in); public static void main(String[] args) { int t = scanner.nextInt(); scanner.nextLine(); while (t-->0){ String a = scanner.nextLine(); String b = scanner.nextLine(); String c = scanner.nextLine(); boolean flag = false; for (int i=0; i<a.length(); i++){ if ((a.charAt(i)==b.charAt(i) && a.charAt(i)==c.charAt(i)) || (a.charAt(i) != b.charAt(i) && (c.charAt(i)==a.charAt(i) || c.charAt(i) == b.charAt(i)))) flag = true; else { flag = false; break; } } if (flag) System.out.println("YES"); else System.out.println("NO"); } scanner.close(); } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
d111e6cf2128f108de1631f77e309562
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
import java.util.*; import java.util.spi.LocaleNameProvider; import java.io.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int t=sc.nextInt(); for(int i=0;i<t;i++) { String a=sc.next(); String b=sc.next(); String c=sc.next(); boolean T=true; for(int j=0;j<a.length();j++){ if(c.charAt(j)!=a.charAt(j)&&c.charAt(j)!=b.charAt(j)) { T=false; } } if(T) { pw.println("YES"); } else { pw.println("NO"); } } pw.close(); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader r) { br = new BufferedReader(r); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public boolean ready() throws IOException { return br.ready(); } } static class pair implements Comparable<pair> { int x; int y; public pair(int x,int y) { this.x=x; this.y=y; } public String toString(){ return x+" "+y; } public int compareTo(pair other) { if(this.x==other.x) { return this.y-other.y; } else { return this.x-other.x; } } } static class tuble implements Comparable<tuble> { int x; int y; int z; public tuble(int x,int y,int z) { this.x=x; this.y=y; this.z=z; } public String toString(){ return x+" "+y+" "+z; } public int compareTo(tuble other) { if(this.x==other.x) { return this.y-other.y; } else { return this.x-other.x; } } } public static long GCD(long a, long b) { if(b==0)return a; if(a==0)return b; return (a>b)?GCD(a%b, b):GCD(a, b%a); } public static long LCM(long a, long b) { return a*b/GCD(a, b); } public static long nCk(int n, int k) { //O(K) if (k > n) { return 0; } long res = 1; for(int i = 1; i<=k; i++) { res = ((n - k + i) * res/i)%1000000007; } return res; } public static long C(int a, int b, long[][] s) { int m = (int) 1e9 + 7; if (s[a][b] >= 0) { return s[a][b]; } else if (a < b | a < 0 | b < 0) { s[a][b] = 0; return 0; } else if (a == b | b == 0) { s[a][b] = 1; return 1; } else { return s[a][b] = (C(a - 1, b, s) % m + C(a - 1, b - 1, s) % m) % m; } } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
05b0150e33d9547e5e75556ac4390fd8
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ //package tester; import java.util.*; import java.io.*; public class Tester { static int mod = (int)1e9+7; public static void main (String [] args) { InputReader input = new InputReader(System.in); int T = input.readInt(); String a, b, c; int n; boolean can; while (T>0) { a = input.readLine(); b = input.readLine(); c = input.readLine(); n = a.length(); can = true; for (int i = 0; i < n; i++) { if (!(c.charAt(i)==a.charAt(i) || c.charAt(i)==b.charAt(i))) { System.out.println("NO"); can = false; break; } } if (can) System.out.println("YES"); T--; } } 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 int readInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long readLong() { return Long.parseLong(readString()); } 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 readLine() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isNewLine(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 boolean isNewLine (int c) { if (filter!=null) return filter.isSpaceChar(c); return c=='\n' || c=='\r' || c==-1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
0288e820f1546886d3db114db5d2f48e
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
import java.util.Scanner; public class First1 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t!=0){ String a = sc.next(); String b = sc.next(); String c = sc.next(); int c1 =0; for(int i=0;i<a.length();i++){ if((a.charAt(i)!=b.charAt(i))||a.charAt(i)==c.charAt(i)||b.charAt(i)==c.charAt(i)){ if(a.charAt(i)==c.charAt(i)){ c1++; } else if(b.charAt(i)==c.charAt(i)){ c1++; } } } if(c1==a.length()) System.out.println("YES"); else if (a.equals(b) && a.equals(c)) System.out.println("YES"); else System.out.println("NO"); t--; } } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
6185285e8dc63427c88ae3905bad27fc
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.LinkedList; import java.util.Queue; import java.util.StringTokenizer; public class Problem2 { public int find(int pr[],int i) { if(i==pr[i]) return i; else { pr[i]=find(pr,pr[i]); return pr[i]; } } public void join(int[] pr,int i,int j) { i=find(pr,i); j=find(pr,j); if(i==j) return; if(pr[i]>=pr[j]) { pr[j]= i; } else { pr[i] = j; } } public void swap(char ar[],int i,int j) { char f = ar[i]; ar[i]=ar[j]; ar[j]=f; } public void bfs(int index, boolean arr[]) { Queue<Integer> q = new LinkedList<>(); q.add(index); arr[index] = true; while(!q.isEmpty()) { int cur = q.poll(); for(int adjacent: graph[cur]) { if(!arr[adjacent]) { q.add(adjacent); } } } } public void dfs(int index,boolean arr[]) { arr[index]=true; for(int i=0;i<graph[index].size();i++) { if(!arr[graph[index].get(i)]) { dfs(graph[index].get(i),arr); } } } /* * return index of target ... -1 if not exist. */ public int binarySearch(int ar[],int target) { int left = 0; int right = ar.length - 1; while(left < right) { int mid= (left + right) / 2; if(ar[mid] == target) { return mid; } if(ar[mid] < target) { left = mid + 1; } else { right = mid - 1; } } return -1; } /** * GCD * @param a * @param b * @return */ public int gcd(int a, int b) { if(a % b == 0) return b; return gcd(b, a%b); } ArrayList<Integer> graph[] ; public static void main(String[] args) { MyReader read = new MyReader(); int t = read.i(); while(t-- > 0) { String ans = ""; char[] a = read.next().toCharArray(); char[] b = read.next().toCharArray(); char[] c = read.next().toCharArray(); boolean flag = false; for(int i = 0; i < a.length; i++) { if(c[i] == b[i]) { char temp = c[i]; c[i] = a[i]; a[i] = temp; } else if(c[i] == a[i]) { char temp = c[i]; c[i] = b[i]; b[i] = temp; } else { System.out.println("NO"); i = a.length; flag = true; } } if(!flag) System.out.println("YES"); } } static class MyReader { private BufferedReader br; private StringTokenizer st; public MyReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) { e.printStackTrace(); } } return st.nextToken(); } int i() { return Integer.parseInt(next()); } long l() { return Long.parseLong(next()); } double d() { return Double.parseDouble(next()); } float f() { return Float.parseFloat(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (Exception e) { e.printStackTrace(); } return str; } } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
ab4d0175a0c0162587555af14067cbdd
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class ThreeStrings { public static void main(String[] args) { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int t = 0; try { t = Integer.parseInt(reader.readLine()); for (int i = 0; i < t; i++) { String a = reader.readLine(); String b = reader.readLine(); String c = reader.readLine(); int k = 0; for (int j = 0; j < a.length(); j++) { if (!(a.charAt(j) != c.charAt(j) && b.charAt(j) != c.charAt(j))) { k++; } } if (k == a.length()) { System.out.println("YES"); } else { System.out.println("NO"); } } } catch (IOException e) { e.printStackTrace(); } } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
832c08e16870bca9338ab3ea5ce4a2f4
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class sample { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[]args) throws Exception { FastReader sc=new FastReader(); int t=sc.nextInt(); StringBuffer sb=new StringBuffer(); while(t-->0) { //int n=sc.nextInt(); //int a[]=new int[n]; String a= sc.next(); String b=sc.next(); String c=sc.next(); char p[]=a.toCharArray(); char q[]=b.toCharArray(); char r[]=c.toCharArray();int temp=0; for(int i=0;i<p.length;i++) { if((p[i]==q[i] && r[i]!=p[i]) || (r[i]!=p[i] && r[i]!=q[i])) { temp=1; System.out.print("NO"+"\n"); break; } } if(temp==0) System.out.print("YES"+"\n"); } //System.out.println(sb); } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
71044ec2a91ae4db96a9f93f403958f4
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
//package codeforces; import java.util.Scanner; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.TreeMap; import java.util.TreeSet; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Stack; import java.util.Set; public class q { static Scanner scn = new Scanner(System.in); static int mod = 1000000007; static long count = 0; public static void main(String[] args) { int t = scn.nextInt(); while (t-- > 0) { String a=scn.next(); String b=scn.next(); String c=scn.next(); char a1[]=a.toCharArray(); char b1[]=b.toCharArray(); char c1[]=c.toCharArray(); int count=0,l=0,n=a.length(); char temp=' '; boolean bl=true; for(int i=0;i<n;i++) { if(a1[i]==c1[i]) { temp=b1[i]; b1[i]=c1[i]; c1[i]=temp; } else if(b1[i]==c1[i]) { temp=a1[i]; a1[i]=c1[i]; c1[i]=temp; } else if(a1[i]==c1[i]&&b1[i]==c1[i]) { continue; } else { bl=false; break; } } if(bl) System.out.println("YES"); else System.out.println("NO"); //System.out.println(count); } } public static long hel(long d) { if (d < 1) return 0; if (d == 1) return 1; else { return 1 + 2 * hel(Math.floorDiv(d, 2)); } } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
68982ae8169a43cac7eec11087ce9689
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
import java.util.*; import java.io.*; public class CFE { BufferedReader br; PrintWriter out; StringTokenizer st; boolean eof; private static final long MOD = 1000L * 1000L * 1000L + 7; private static final int[] dx = {0, -1, 0, 1}; private static final int[] dy = {1, 0, -1, 0}; private static final String yes = "Yes"; private static final String no = "No"; void solve() { int T = nextInt(); for (int i = 0; i < T; i++) { helper(); } } void helper() { char[] a = nextString().toCharArray(); char[] b = nextString().toCharArray(); char[] c = nextString().toCharArray(); int n = a.length; for (int i = 0; i < n; i++) { if (a[i] == c[i] || b[i] == c[i]) { continue; } outln(no.toUpperCase()); return; } outln(yes.toUpperCase()); } void shuffle(long[] a) { int n = a.length; for(int i = 0; i < n; i++) { int r = i + (int) (Math.random() * (n - i)); long tmp = a[i]; a[i] = a[r]; a[r] = tmp; } } long gcd(long a, long b) { while(a != 0 && b != 0) { long c = b; b = a % b; a = c; } return a + b; } private void outln(Object o) { out.println(o); } private void out(Object o) { out.print(o); } private void formatPrint(double val) { outln(String.format("%.9f%n", val)); } public CFE() { br = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); solve(); out.close(); } public static void main(String[] args) { new CFE(); } public long[] nextLongArr(int n) { long[] res = new long[n]; for(int i = 0; i < n; i++) res[i] = nextLong(); return res; } public int[] nextIntArr(int n) { int[] res = new int[n]; for(int i = 0; i < n; i++) res[i] = nextInt(); return res; } public String nextToken() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) { eof = true; return null; } } return st.nextToken(); } public String nextString() { try { return br.readLine(); } catch (IOException e) { eof = true; return null; } } public int nextInt() { return Integer.parseInt(nextToken()); } public long nextLong() { return Long.parseLong(nextToken()); } public double nextDouble() { return Double.parseDouble(nextToken()); } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
814894c6bad036ee5ebda55cdcd0203a
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class medo { public static void main (String[] args) { Scanner sc=new Scanner(System.in); int t,i; t=sc.nextInt(); while(t>0) { t--; char a[]=sc.next().toCharArray(); char b[]=sc.next().toCharArray(); char c[]=sc.next().toCharArray(); int n=a.length; String ans="YES"; for(i=0;i<n;i++) { if(a[i]!=c[i]&&b[i]!=c[i]) { ans="NO"; break; } } System.out.println(ans); } } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
b55b3a4ec0a0501efee7dd8d9cf953eb
train_003.jsonl
1581604500
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.util.*; import java.io.*; public class Main { public static void main(String args[]) { InputReader obj = new InputReader(System.in); int t=obj.nextInt(); while(t-->0) { String a=obj.next(); String b=obj.next(); String c=obj.next(); boolean chk=false; for(int i=0;i<a.length();i++) { char a1=a.charAt(i); char b1=b.charAt(i); char c1=c.charAt(i); if(a1==c1 && b1!=c1) { chk=false; } else if(a1==b1 && b1==c1) { chk=false; } else if(b1==c1 && b1!=a1) { chk=false; } else { chk=true; break; } } if(!chk) { System.out.println("YES"); } else { System.out.println("NO"); } } } public static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } } }
Java
["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"]
1 second
["NO\nYES\nYES\nNO"]
NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.
Java 8
standard input
[ "implementation", "strings" ]
08679e44ee5d3c3287230befddf7eced
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.
800
Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.
standard output
PASSED
f5b74905d71dba5628d05bc76be28d36
train_003.jsonl
1566743700
Cengiz recently learned Fibonacci numbers and now he is studying different algorithms to find them. After getting bored of reading them, he came with his own new type of numbers that he named XORinacci numbers. He defined them as follows: $$$f(0) = a$$$; $$$f(1) = b$$$; $$$f(n) = f(n-1) \oplus f(n-2)$$$ when $$$n &gt; 1$$$, where $$$\oplus$$$ denotes the bitwise XOR operation. You are given three integers $$$a$$$, $$$b$$$, and $$$n$$$, calculate $$$f(n)$$$.You have to answer for $$$T$$$ independent test cases.
256 megabytes
import java.util.ArrayList; import java.util.Scanner; public class CF_1208A { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int T=sc.nextInt(); while(T-->0) { int a=sc.nextInt(),b=sc.nextInt(),n=sc.nextInt(); int c=a^b; if(n%3==0) { System.out.println(a); } else { if(n%3==1) System.out.println(b); else System.out.println(c); } } } }
Java
["3\n3 4 2\n4 5 0\n325 265 1231232"]
1 second
["7\n4\n76"]
NoteIn the first example, $$$f(2) = f(0) \oplus f(1) = 3 \oplus 4 = 7$$$.
Java 8
standard input
[ "math" ]
64a375c7c49591c676dbdb039c93d218
The input contains one or more independent test cases. The first line of input contains a single integer $$$T$$$ ($$$1 \le T \le 10^3$$$), the number of test cases. Each of the $$$T$$$ following lines contains three space-separated integers $$$a$$$, $$$b$$$, and $$$n$$$ ($$$0 \le a, b, n \le 10^9$$$) respectively.
900
For each test case, output $$$f(n)$$$.
standard output
PASSED
e6f3a5b743851c1d34d723c3a9a60638
train_003.jsonl
1566743700
Cengiz recently learned Fibonacci numbers and now he is studying different algorithms to find them. After getting bored of reading them, he came with his own new type of numbers that he named XORinacci numbers. He defined them as follows: $$$f(0) = a$$$; $$$f(1) = b$$$; $$$f(n) = f(n-1) \oplus f(n-2)$$$ when $$$n &gt; 1$$$, where $$$\oplus$$$ denotes the bitwise XOR operation. You are given three integers $$$a$$$, $$$b$$$, and $$$n$$$, calculate $$$f(n)$$$.You have to answer for $$$T$$$ independent test cases.
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 tarek */ 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); AXORinacci solver = new AXORinacci(); solver.solve(1, in, out); out.close(); } static class AXORinacci { public void solve(int testNumber, InputReader in, OutputWriter out) { int t = in.readInt(); while (t-- > 0) { long a = in.readLong(); long b = in.readLong(); long n = in.readLong(); n %= 3; if (n == 0) { out.printLine(a); } else if (n == 1) { out.printLine(b); } else { out.printLine(a ^ b); } } } } 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 long readLong() { 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 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 close() { writer.close(); } public void printLine(long i) { writer.println(i); } } }
Java
["3\n3 4 2\n4 5 0\n325 265 1231232"]
1 second
["7\n4\n76"]
NoteIn the first example, $$$f(2) = f(0) \oplus f(1) = 3 \oplus 4 = 7$$$.
Java 8
standard input
[ "math" ]
64a375c7c49591c676dbdb039c93d218
The input contains one or more independent test cases. The first line of input contains a single integer $$$T$$$ ($$$1 \le T \le 10^3$$$), the number of test cases. Each of the $$$T$$$ following lines contains three space-separated integers $$$a$$$, $$$b$$$, and $$$n$$$ ($$$0 \le a, b, n \le 10^9$$$) respectively.
900
For each test case, output $$$f(n)$$$.
standard output
PASSED
57ea35c625d0aacc4ab6fe73966c8031
train_003.jsonl
1566743700
Cengiz recently learned Fibonacci numbers and now he is studying different algorithms to find them. After getting bored of reading them, he came with his own new type of numbers that he named XORinacci numbers. He defined them as follows: $$$f(0) = a$$$; $$$f(1) = b$$$; $$$f(n) = f(n-1) \oplus f(n-2)$$$ when $$$n &gt; 1$$$, where $$$\oplus$$$ denotes the bitwise XOR operation. You are given three integers $$$a$$$, $$$b$$$, and $$$n$$$, calculate $$$f(n)$$$.You have to answer for $$$T$$$ independent test cases.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); int t=in.nextInt(); for(int i=0;i<t;i++) { int a=in.nextInt(); int b=in.nextInt(); int n=in.nextInt(); int first=a,second=b; n=n%3; if(n>1){ second=(a^b); } else if(n==0) { second=a; } else if(n==1) { second=b; } System.out.println(second); } } }
Java
["3\n3 4 2\n4 5 0\n325 265 1231232"]
1 second
["7\n4\n76"]
NoteIn the first example, $$$f(2) = f(0) \oplus f(1) = 3 \oplus 4 = 7$$$.
Java 8
standard input
[ "math" ]
64a375c7c49591c676dbdb039c93d218
The input contains one or more independent test cases. The first line of input contains a single integer $$$T$$$ ($$$1 \le T \le 10^3$$$), the number of test cases. Each of the $$$T$$$ following lines contains three space-separated integers $$$a$$$, $$$b$$$, and $$$n$$$ ($$$0 \le a, b, n \le 10^9$$$) respectively.
900
For each test case, output $$$f(n)$$$.
standard output
PASSED
116076f1e17fb690fa1b77d8fdb51db7
train_003.jsonl
1566743700
Cengiz recently learned Fibonacci numbers and now he is studying different algorithms to find them. After getting bored of reading them, he came with his own new type of numbers that he named XORinacci numbers. He defined them as follows: $$$f(0) = a$$$; $$$f(1) = b$$$; $$$f(n) = f(n-1) \oplus f(n-2)$$$ when $$$n &gt; 1$$$, where $$$\oplus$$$ denotes the bitwise XOR operation. You are given three integers $$$a$$$, $$$b$$$, and $$$n$$$, calculate $$$f(n)$$$.You have to answer for $$$T$$$ independent test cases.
256 megabytes
import java.util.*; import java.io.*; public class Main{ public static void main(String args[]) { Scanner sc = new Scanner(System.in); int t; t = sc.nextInt(); while(t>0) { int a = sc.nextInt(); int b = sc.nextInt(); int n = sc.nextInt(); n%=3; if(n==0) b=a; if(n==2) b=a^b; System.out.println(b); t--; } } }
Java
["3\n3 4 2\n4 5 0\n325 265 1231232"]
1 second
["7\n4\n76"]
NoteIn the first example, $$$f(2) = f(0) \oplus f(1) = 3 \oplus 4 = 7$$$.
Java 8
standard input
[ "math" ]
64a375c7c49591c676dbdb039c93d218
The input contains one or more independent test cases. The first line of input contains a single integer $$$T$$$ ($$$1 \le T \le 10^3$$$), the number of test cases. Each of the $$$T$$$ following lines contains three space-separated integers $$$a$$$, $$$b$$$, and $$$n$$$ ($$$0 \le a, b, n \le 10^9$$$) respectively.
900
For each test case, output $$$f(n)$$$.
standard output
PASSED
e20b5d2776bf3e8b089fe84e761c0c4e
train_003.jsonl
1566743700
Cengiz recently learned Fibonacci numbers and now he is studying different algorithms to find them. After getting bored of reading them, he came with his own new type of numbers that he named XORinacci numbers. He defined them as follows: $$$f(0) = a$$$; $$$f(1) = b$$$; $$$f(n) = f(n-1) \oplus f(n-2)$$$ when $$$n &gt; 1$$$, where $$$\oplus$$$ denotes the bitwise XOR operation. You are given three integers $$$a$$$, $$$b$$$, and $$$n$$$, calculate $$$f(n)$$$.You have to answer for $$$T$$$ independent test cases.
256 megabytes
import java.util.Scanner; public class Scratch { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for(int i=0;i<t;i++){ int a = sc.nextInt(); int b = sc.nextInt(); int n = sc.nextInt(); if(n%3==0){ System.out.println(a); continue; }else if (n%3==1){ System.out.println(b); continue; } else{ System.out.println(a^b); } } } }
Java
["3\n3 4 2\n4 5 0\n325 265 1231232"]
1 second
["7\n4\n76"]
NoteIn the first example, $$$f(2) = f(0) \oplus f(1) = 3 \oplus 4 = 7$$$.
Java 8
standard input
[ "math" ]
64a375c7c49591c676dbdb039c93d218
The input contains one or more independent test cases. The first line of input contains a single integer $$$T$$$ ($$$1 \le T \le 10^3$$$), the number of test cases. Each of the $$$T$$$ following lines contains three space-separated integers $$$a$$$, $$$b$$$, and $$$n$$$ ($$$0 \le a, b, n \le 10^9$$$) respectively.
900
For each test case, output $$$f(n)$$$.
standard output
PASSED
7692fe904b0c41e539b23ce0c4257b47
train_003.jsonl
1566743700
Cengiz recently learned Fibonacci numbers and now he is studying different algorithms to find them. After getting bored of reading them, he came with his own new type of numbers that he named XORinacci numbers. He defined them as follows: $$$f(0) = a$$$; $$$f(1) = b$$$; $$$f(n) = f(n-1) \oplus f(n-2)$$$ when $$$n &gt; 1$$$, where $$$\oplus$$$ denotes the bitwise XOR operation. You are given three integers $$$a$$$, $$$b$$$, and $$$n$$$, calculate $$$f(n)$$$.You have to answer for $$$T$$$ independent test cases.
256 megabytes
import java.util.*; public class Main { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0) { int a = sc.nextInt(); int b = sc.nextInt(); long c = sc.nextLong(); long n = c+1; if(n%3 == 1) { System.out.println(""+a); } if(n%3 == 2) { System.out.println(""+b); } if(n%3 == 0) { System.out.println(""+(a^b)); } } } }
Java
["3\n3 4 2\n4 5 0\n325 265 1231232"]
1 second
["7\n4\n76"]
NoteIn the first example, $$$f(2) = f(0) \oplus f(1) = 3 \oplus 4 = 7$$$.
Java 8
standard input
[ "math" ]
64a375c7c49591c676dbdb039c93d218
The input contains one or more independent test cases. The first line of input contains a single integer $$$T$$$ ($$$1 \le T \le 10^3$$$), the number of test cases. Each of the $$$T$$$ following lines contains three space-separated integers $$$a$$$, $$$b$$$, and $$$n$$$ ($$$0 \le a, b, n \le 10^9$$$) respectively.
900
For each test case, output $$$f(n)$$$.
standard output
PASSED
168fcdb171772327d506edbad580fdbf
train_003.jsonl
1566743700
Cengiz recently learned Fibonacci numbers and now he is studying different algorithms to find them. After getting bored of reading them, he came with his own new type of numbers that he named XORinacci numbers. He defined them as follows: $$$f(0) = a$$$; $$$f(1) = b$$$; $$$f(n) = f(n-1) \oplus f(n-2)$$$ when $$$n &gt; 1$$$, where $$$\oplus$$$ denotes the bitwise XOR operation. You are given three integers $$$a$$$, $$$b$$$, and $$$n$$$, calculate $$$f(n)$$$.You have to answer for $$$T$$$ independent test cases.
256 megabytes
import java.util.*; public class Main { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0) { int a = sc.nextInt(); int b = sc.nextInt(); long c = sc.nextLong(); long n = c+1; if(n%3 == 1) { System.out.println(""+a); } if(n%3 == 2) { System.out.println(""+b); } if(n%3 == 0) { System.out.println(""+(a^b)); } } } }
Java
["3\n3 4 2\n4 5 0\n325 265 1231232"]
1 second
["7\n4\n76"]
NoteIn the first example, $$$f(2) = f(0) \oplus f(1) = 3 \oplus 4 = 7$$$.
Java 8
standard input
[ "math" ]
64a375c7c49591c676dbdb039c93d218
The input contains one or more independent test cases. The first line of input contains a single integer $$$T$$$ ($$$1 \le T \le 10^3$$$), the number of test cases. Each of the $$$T$$$ following lines contains three space-separated integers $$$a$$$, $$$b$$$, and $$$n$$$ ($$$0 \le a, b, n \le 10^9$$$) respectively.
900
For each test case, output $$$f(n)$$$.
standard output
PASSED
a9b8a2aaf3f95e5ebaaeec544b89ee7d
train_003.jsonl
1566743700
Cengiz recently learned Fibonacci numbers and now he is studying different algorithms to find them. After getting bored of reading them, he came with his own new type of numbers that he named XORinacci numbers. He defined them as follows: $$$f(0) = a$$$; $$$f(1) = b$$$; $$$f(n) = f(n-1) \oplus f(n-2)$$$ when $$$n &gt; 1$$$, where $$$\oplus$$$ denotes the bitwise XOR operation. You are given three integers $$$a$$$, $$$b$$$, and $$$n$$$, calculate $$$f(n)$$$.You have to answer for $$$T$$$ independent test cases.
256 megabytes
import java.util.Scanner; public class XORinacci { /* public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t > 0) { int a = sc.nextInt(); int b = sc.nextInt(); int n = sc.nextInt(); if (n == 0 || n == 1) { if (n == 0) { System.out.println(a); } else { System.out.println(b); } t--; continue; } int[] res = new int[n + 1]; res[0] = a; res[1] = b; for (int i = 2; i <= n; i++) { int x = res[i - 1] ^ res[i - 2]; res[i] = x; } System.out.println(res[n]); t--; } sc.close(); }*/ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t > 0) { int a = sc.nextInt(); int b = sc.nextInt(); int n = sc.nextInt(); switch(n%3){ case 0: System.out.println(a); break; case 1: System.out.println(b); break; default: System.out.println(a^b); break; } t--; } sc.close(); } }
Java
["3\n3 4 2\n4 5 0\n325 265 1231232"]
1 second
["7\n4\n76"]
NoteIn the first example, $$$f(2) = f(0) \oplus f(1) = 3 \oplus 4 = 7$$$.
Java 8
standard input
[ "math" ]
64a375c7c49591c676dbdb039c93d218
The input contains one or more independent test cases. The first line of input contains a single integer $$$T$$$ ($$$1 \le T \le 10^3$$$), the number of test cases. Each of the $$$T$$$ following lines contains three space-separated integers $$$a$$$, $$$b$$$, and $$$n$$$ ($$$0 \le a, b, n \le 10^9$$$) respectively.
900
For each test case, output $$$f(n)$$$.
standard output
PASSED
a07169b333dae6b68dd68014a10f5fc7
train_003.jsonl
1566743700
Cengiz recently learned Fibonacci numbers and now he is studying different algorithms to find them. After getting bored of reading them, he came with his own new type of numbers that he named XORinacci numbers. He defined them as follows: $$$f(0) = a$$$; $$$f(1) = b$$$; $$$f(n) = f(n-1) \oplus f(n-2)$$$ when $$$n &gt; 1$$$, where $$$\oplus$$$ denotes the bitwise XOR operation. You are given three integers $$$a$$$, $$$b$$$, and $$$n$$$, calculate $$$f(n)$$$.You have to answer for $$$T$$$ independent test cases.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner Input = new Scanner(System.in); int N = Input.nextInt(); for (int I = 0; I < N; I++) { int[] Arr = new int[3]; Arr[0] = Input.nextInt(); Arr[1] = Input.nextInt(); long IDK = Input.nextLong(); Arr[2] = Arr[0] ^ Arr[1]; System.out.println(Arr[(int) IDK % 3]); } } }
Java
["3\n3 4 2\n4 5 0\n325 265 1231232"]
1 second
["7\n4\n76"]
NoteIn the first example, $$$f(2) = f(0) \oplus f(1) = 3 \oplus 4 = 7$$$.
Java 8
standard input
[ "math" ]
64a375c7c49591c676dbdb039c93d218
The input contains one or more independent test cases. The first line of input contains a single integer $$$T$$$ ($$$1 \le T \le 10^3$$$), the number of test cases. Each of the $$$T$$$ following lines contains three space-separated integers $$$a$$$, $$$b$$$, and $$$n$$$ ($$$0 \le a, b, n \le 10^9$$$) respectively.
900
For each test case, output $$$f(n)$$$.
standard output
PASSED
5bbfb2235925cf0076922de2c762f666
train_003.jsonl
1566743700
Cengiz recently learned Fibonacci numbers and now he is studying different algorithms to find them. After getting bored of reading them, he came with his own new type of numbers that he named XORinacci numbers. He defined them as follows: $$$f(0) = a$$$; $$$f(1) = b$$$; $$$f(n) = f(n-1) \oplus f(n-2)$$$ when $$$n &gt; 1$$$, where $$$\oplus$$$ denotes the bitwise XOR operation. You are given three integers $$$a$$$, $$$b$$$, and $$$n$$$, calculate $$$f(n)$$$.You have to answer for $$$T$$$ independent test cases.
256 megabytes
import java.io.*; import java.util.*; import java.math.*; //import java.lang.*; public class snack4 { static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[1000000]; // 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(); } } public static int findClosest(int numbers[], int myNumber) { int distance = Math.abs(numbers[0] - myNumber); int idx = 0; for(int c = 1; c < numbers.length; c++){ int cdistance = Math.abs(numbers[c] - myNumber); if(cdistance < distance){ idx = c; distance = cdistance; } } return numbers[idx]; } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static int countUnsetBits(int n) { int x = n; // Make all bits set MSB // (including MSB) // This makes sure two bits // (From MSB and including MSB) // are set n |= n >> 1; // This makes sure 4 bits // (From MSB and including MSB) // are set n |= n >> 2; n |= n >> 4; n |= n >> 8; n |= n >> 16; // Count set bits in toggled number return Integer.bitCount(x^ n); } // static long fib(int a,int b, int n) // { // if (n == 0) // return a; // if (n == 1) // return b; // return fib(a,b,n-1)^fib(a,b,n-2); // } // static int fib(int a,int b, int n) // { // int a1 = a, b1 = b, c; // if (n == 0) // return a1; // if (n == 1) // return b1; // for (int i = 2; i <= n; i++) // { // c = a ^ b; // a = b; // b = c; // } // return b; // } static long fib(int a, int b, int n) { /* Declare an array to store Fibonacci numbers. */ long f[] = new long[n+2]; // 1 extra to handle case, n = 0 int i; /* 0th and 1st number of the series are 0 and 1*/ f[0] = a; f[1] = b; for (i = 2; i <= n; i++) { /* Add the previous 2 numbers in the series and store it */ f[i] = f[i-1] ^ f[i-2]; } return f[n]; } public static void main(String[] args) throws IOException { Scanner sc=new Scanner(System.in); //Scanner sc=new Scanner(System.in); int T=sc.nextInt(); while(T-- > 0){ //b,p,f int a=sc.nextInt(); int b=sc.nextInt(); int N=sc.nextInt(); //int A[]=new int[N]; if(N%3 == 0) System.out.println(a); if(N%3 == 1) System.out.println(b); if(N%3 == 2) System.out.println(a^b); } } }
Java
["3\n3 4 2\n4 5 0\n325 265 1231232"]
1 second
["7\n4\n76"]
NoteIn the first example, $$$f(2) = f(0) \oplus f(1) = 3 \oplus 4 = 7$$$.
Java 8
standard input
[ "math" ]
64a375c7c49591c676dbdb039c93d218
The input contains one or more independent test cases. The first line of input contains a single integer $$$T$$$ ($$$1 \le T \le 10^3$$$), the number of test cases. Each of the $$$T$$$ following lines contains three space-separated integers $$$a$$$, $$$b$$$, and $$$n$$$ ($$$0 \le a, b, n \le 10^9$$$) respectively.
900
For each test case, output $$$f(n)$$$.
standard output
PASSED
16214c05ae91df67fd5bbcab05a17b2d
train_003.jsonl
1566743700
Cengiz recently learned Fibonacci numbers and now he is studying different algorithms to find them. After getting bored of reading them, he came with his own new type of numbers that he named XORinacci numbers. He defined them as follows: $$$f(0) = a$$$; $$$f(1) = b$$$; $$$f(n) = f(n-1) \oplus f(n-2)$$$ when $$$n &gt; 1$$$, where $$$\oplus$$$ denotes the bitwise XOR operation. You are given three integers $$$a$$$, $$$b$$$, and $$$n$$$, calculate $$$f(n)$$$.You have to answer for $$$T$$$ independent test cases.
256 megabytes
// Working program with FastReader import java.io.*; import java.util.*; import java.text.*; import java.math.*; public final class Main { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) { FastReader sc=new FastReader(); int t=sc.nextInt(); while(t-- > 0) { int f0=sc.nextInt(); int f1=sc.nextInt(); int n=sc.nextInt(); int m=f0^f1; if(n==0) System.out.println(f0); else if(n==1) System.out.println(f1); else if(n==2) System.out.println(m); else { int x=n%3; if(x==0) System.out.println(f0); else if(x==1) System.out.println(f0^m); else System.out.println(m); } } } }
Java
["3\n3 4 2\n4 5 0\n325 265 1231232"]
1 second
["7\n4\n76"]
NoteIn the first example, $$$f(2) = f(0) \oplus f(1) = 3 \oplus 4 = 7$$$.
Java 8
standard input
[ "math" ]
64a375c7c49591c676dbdb039c93d218
The input contains one or more independent test cases. The first line of input contains a single integer $$$T$$$ ($$$1 \le T \le 10^3$$$), the number of test cases. Each of the $$$T$$$ following lines contains three space-separated integers $$$a$$$, $$$b$$$, and $$$n$$$ ($$$0 \le a, b, n \le 10^9$$$) respectively.
900
For each test case, output $$$f(n)$$$.
standard output
PASSED
f34bc5f20c38464be576c93ee611044e
train_003.jsonl
1566743700
Cengiz recently learned Fibonacci numbers and now he is studying different algorithms to find them. After getting bored of reading them, he came with his own new type of numbers that he named XORinacci numbers. He defined them as follows: $$$f(0) = a$$$; $$$f(1) = b$$$; $$$f(n) = f(n-1) \oplus f(n-2)$$$ when $$$n &gt; 1$$$, where $$$\oplus$$$ denotes the bitwise XOR operation. You are given three integers $$$a$$$, $$$b$$$, and $$$n$$$, calculate $$$f(n)$$$.You have to answer for $$$T$$$ independent test cases.
256 megabytes
import java.util.*; public final class Main{ /* static int f(int n,int a,int b){ if(n==0) return a; else if(n==1) return b; return f(n-1,a,b)^f(n-2,a,b); }*/ public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int a=sc.nextInt(); int b=sc.nextInt(); int n=sc.nextInt(); if(n%3==0) System.out.println(a); else if(n%3==1) System.out.println(b); else System.out.println(a^b); } } }
Java
["3\n3 4 2\n4 5 0\n325 265 1231232"]
1 second
["7\n4\n76"]
NoteIn the first example, $$$f(2) = f(0) \oplus f(1) = 3 \oplus 4 = 7$$$.
Java 8
standard input
[ "math" ]
64a375c7c49591c676dbdb039c93d218
The input contains one or more independent test cases. The first line of input contains a single integer $$$T$$$ ($$$1 \le T \le 10^3$$$), the number of test cases. Each of the $$$T$$$ following lines contains three space-separated integers $$$a$$$, $$$b$$$, and $$$n$$$ ($$$0 \le a, b, n \le 10^9$$$) respectively.
900
For each test case, output $$$f(n)$$$.
standard output
PASSED
d8c69e019e7e82f124411ffaf45b3201
train_003.jsonl
1566743700
Cengiz recently learned Fibonacci numbers and now he is studying different algorithms to find them. After getting bored of reading them, he came with his own new type of numbers that he named XORinacci numbers. He defined them as follows: $$$f(0) = a$$$; $$$f(1) = b$$$; $$$f(n) = f(n-1) \oplus f(n-2)$$$ when $$$n &gt; 1$$$, where $$$\oplus$$$ denotes the bitwise XOR operation. You are given three integers $$$a$$$, $$$b$$$, and $$$n$$$, calculate $$$f(n)$$$.You have to answer for $$$T$$$ independent test cases.
256 megabytes
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws IOException{ Scanner sc = new Scanner(System.in); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); OutputStream pr = System.out; PrintWriter out = new PrintWriter(pr); int t = sc.nextInt(); for(int i=0;i<t;i++){ long a = sc.nextLong(); long b = sc.nextLong(); long n = sc.nextLong(); if(n%3==0){ out.println(a); }else if(n%3==1){ out.println(b); }else{ out.println(a^b); } } out.close(); } public static String dp(int p,int n,String s){ if(p==n){ return "no"; }else{ boolean boo = dp1(s); if(boo){ return s; }else{ if(dp1(s.substring(0,p-1)+s.substring(p,s.length()))){ return s.substring(0,p-1)+s.substring(p,s.length()); }else{ return dp(p+1,n,s); } } } } public static boolean dp1(String s){ int val = Integer.parseInt(s); if(val%8==0){ return true; }else{ return false; } } }
Java
["3\n3 4 2\n4 5 0\n325 265 1231232"]
1 second
["7\n4\n76"]
NoteIn the first example, $$$f(2) = f(0) \oplus f(1) = 3 \oplus 4 = 7$$$.
Java 8
standard input
[ "math" ]
64a375c7c49591c676dbdb039c93d218
The input contains one or more independent test cases. The first line of input contains a single integer $$$T$$$ ($$$1 \le T \le 10^3$$$), the number of test cases. Each of the $$$T$$$ following lines contains three space-separated integers $$$a$$$, $$$b$$$, and $$$n$$$ ($$$0 \le a, b, n \le 10^9$$$) respectively.
900
For each test case, output $$$f(n)$$$.
standard output
PASSED
37acac10b9fdd49e8173a8a99b993e11
train_003.jsonl
1566743700
Cengiz recently learned Fibonacci numbers and now he is studying different algorithms to find them. After getting bored of reading them, he came with his own new type of numbers that he named XORinacci numbers. He defined them as follows: $$$f(0) = a$$$; $$$f(1) = b$$$; $$$f(n) = f(n-1) \oplus f(n-2)$$$ when $$$n &gt; 1$$$, where $$$\oplus$$$ denotes the bitwise XOR operation. You are given three integers $$$a$$$, $$$b$$$, and $$$n$$$, calculate $$$f(n)$$$.You have to answer for $$$T$$$ independent test cases.
256 megabytes
import java.util.Scanner; public class q1 { public static void main(String[] args) { int n,a,b; // System.out.println((4^(7^4))^(4^7)^(4^(7^4))); // System.out.println(4^(4^7)); // a=265; // b=325; // int c; // for(int j=2;j<=10;j++){ // c=a^b; // a=b; // b=c; // System.out.println(c); // } Scanner s=new Scanner(System.in); int t=s.nextInt(); for(int i=0;i<t;i++) { a = s.nextInt(); b = s.nextInt(); n = s.nextInt(); if(n==0){ System.out.println(a); continue;} if(n==1){ System.out.println(b); continue; } if((n-1)%3==0){ System.out.println(b); } else if((n-1)%3==1){ System.out.println((a^b)); } else if((n-1)%3==2){ System.out.println(a); } } } }
Java
["3\n3 4 2\n4 5 0\n325 265 1231232"]
1 second
["7\n4\n76"]
NoteIn the first example, $$$f(2) = f(0) \oplus f(1) = 3 \oplus 4 = 7$$$.
Java 8
standard input
[ "math" ]
64a375c7c49591c676dbdb039c93d218
The input contains one or more independent test cases. The first line of input contains a single integer $$$T$$$ ($$$1 \le T \le 10^3$$$), the number of test cases. Each of the $$$T$$$ following lines contains three space-separated integers $$$a$$$, $$$b$$$, and $$$n$$$ ($$$0 \le a, b, n \le 10^9$$$) respectively.
900
For each test case, output $$$f(n)$$$.
standard output
PASSED
349a94b42a8470b62332cd56c0813e5f
train_003.jsonl
1566743700
Cengiz recently learned Fibonacci numbers and now he is studying different algorithms to find them. After getting bored of reading them, he came with his own new type of numbers that he named XORinacci numbers. He defined them as follows: $$$f(0) = a$$$; $$$f(1) = b$$$; $$$f(n) = f(n-1) \oplus f(n-2)$$$ when $$$n &gt; 1$$$, where $$$\oplus$$$ denotes the bitwise XOR operation. You are given three integers $$$a$$$, $$$b$$$, and $$$n$$$, calculate $$$f(n)$$$.You have to answer for $$$T$$$ independent test cases.
256 megabytes
import java.io.*; import java.util.*; public class Main { private static final int MAX = Integer.MAX_VALUE; private static final int MIN = Integer.MIN_VALUE; public static void main(String[] args) throws IOException { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); InputReader.OutputWriter out = new InputReader.OutputWriter(outputStream); Scanner scanner = new Scanner(System.in); int t = in.nextInt(); while (t-->0) { int a = in.nextInt(); int b = in.nextInt(); int n = in.nextInt(); if(n == 0) { out.println(a); } else if(n== 1) { out.println(b); } else { int res = n%3; if(res == 0) { out.println(a); }else if(res == 1) { out.println(b); } else { out.println(a^b); } } } out.flush(); } private static int [] freq(char [] c) { int [] f = new int[26]; for(char cc : c) { f[cc-'a']++; } return f; } private static void shuffle(int [] a) { for (int i = 0; i < a.length; i++) { int index = (int)(Math.random()*(i+1)); int temp = a[index]; a[index] = a[i]; a[i] = temp; } } private static int lowerBound(int [] a, int target) { int lo = 0; int hi = a.length - 1; while (lo<=hi) { int med = lo + (hi-lo)/2; if(target >= a[med]) { lo = med + 1; } else { hi = med - 1; } } return lo; } static int numberOfSubsequences(String a, String b) { int [] dp = new int[b.length()+1]; dp[0] = 1; for (int i = 0; i < a.length(); i++) { for (int j = b.length() - 1; j >=0;j--) { if(a.charAt(i) == b.charAt(j)) { dp[j+1]+=dp[j]; } } } return dp[dp.length - 1]; } static long count(String a, String b) { int m = a.length(); int n = b.length(); // Create a table to store // results of sub-problems long lookup[][] = new long[m + 1][n + 1]; // If first string is empty for (int i = 0; i <= n; ++i) lookup[0][i] = 0; // If second string is empty for (int i = 0; i <= m; ++i) lookup[i][0] = 1; // Fill lookup[][] in // bottom up manner for (int i = 1; i <= m; i++) { for (int j = 1; j <= n; j++) { // If last characters are // same, we have two options - // 1. consider last characters // of both strings in solution // 2. ignore last character // of first string if (a.charAt(i - 1) == b.charAt(j - 1)) lookup[i][j] = lookup[i - 1][j - 1] + lookup[i - 1][j]; else // If last character are // different, ignore last // character of first string lookup[i][j] = lookup[i - 1][j]; } } return lookup[m][n]; } } class Point { private int x; private int y; public int getX() { return x; } public int getY() { return y; } public Point(int x,int y) { this.x = x; this.y = y; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Point point = (Point) o; return x == point.x && y == point.y; } @Override public int hashCode() { return Objects.hash(x, y); } } class InputReader extends BufferedReader { StringTokenizer tokenizer; public InputReader(InputStream inputStream) { super(new InputStreamReader(inputStream), 32768); } public InputReader(String filename) { super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename))); } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(readLine()); } catch (IOException e) { throw new RuntimeException(); } } return tokenizer.nextToken(); } public Integer nextInt(){ return Integer.valueOf(next()); } public Long nextLong() { return Long.valueOf(next()); } public Double nextDouble() { return Double.valueOf(next()); } static class OutputWriter extends PrintWriter { public OutputWriter(OutputStream outputStream) { super(outputStream); } public OutputWriter(Writer writer) { super(writer); } public OutputWriter(String filename) throws FileNotFoundException { super(filename); } public void close() { super.close(); } } }
Java
["3\n3 4 2\n4 5 0\n325 265 1231232"]
1 second
["7\n4\n76"]
NoteIn the first example, $$$f(2) = f(0) \oplus f(1) = 3 \oplus 4 = 7$$$.
Java 8
standard input
[ "math" ]
64a375c7c49591c676dbdb039c93d218
The input contains one or more independent test cases. The first line of input contains a single integer $$$T$$$ ($$$1 \le T \le 10^3$$$), the number of test cases. Each of the $$$T$$$ following lines contains three space-separated integers $$$a$$$, $$$b$$$, and $$$n$$$ ($$$0 \le a, b, n \le 10^9$$$) respectively.
900
For each test case, output $$$f(n)$$$.
standard output
PASSED
23b203224efb930aefb0c29595fbf41b
train_003.jsonl
1566743700
Cengiz recently learned Fibonacci numbers and now he is studying different algorithms to find them. After getting bored of reading them, he came with his own new type of numbers that he named XORinacci numbers. He defined them as follows: $$$f(0) = a$$$; $$$f(1) = b$$$; $$$f(n) = f(n-1) \oplus f(n-2)$$$ when $$$n &gt; 1$$$, where $$$\oplus$$$ denotes the bitwise XOR operation. You are given three integers $$$a$$$, $$$b$$$, and $$$n$$$, calculate $$$f(n)$$$.You have to answer for $$$T$$$ independent test cases.
256 megabytes
import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int i=0;i<t;i++) { int a=sc.nextInt(); int b=sc.nextInt(); int n=sc.nextInt(); int temp=a^b; int c=n%3; if(c==0) System.out.println(a); if(c==1) System.out.println(b); if(c==2) System.out.println(temp); } } }
Java
["3\n3 4 2\n4 5 0\n325 265 1231232"]
1 second
["7\n4\n76"]
NoteIn the first example, $$$f(2) = f(0) \oplus f(1) = 3 \oplus 4 = 7$$$.
Java 8
standard input
[ "math" ]
64a375c7c49591c676dbdb039c93d218
The input contains one or more independent test cases. The first line of input contains a single integer $$$T$$$ ($$$1 \le T \le 10^3$$$), the number of test cases. Each of the $$$T$$$ following lines contains three space-separated integers $$$a$$$, $$$b$$$, and $$$n$$$ ($$$0 \le a, b, n \le 10^9$$$) respectively.
900
For each test case, output $$$f(n)$$$.
standard output
PASSED
e2025fe517848ca556b4e004a2bdc708
train_003.jsonl
1566743700
Cengiz recently learned Fibonacci numbers and now he is studying different algorithms to find them. After getting bored of reading them, he came with his own new type of numbers that he named XORinacci numbers. He defined them as follows: $$$f(0) = a$$$; $$$f(1) = b$$$; $$$f(n) = f(n-1) \oplus f(n-2)$$$ when $$$n &gt; 1$$$, where $$$\oplus$$$ denotes the bitwise XOR operation. You are given three integers $$$a$$$, $$$b$$$, and $$$n$$$, calculate $$$f(n)$$$.You have to answer for $$$T$$$ independent test cases.
256 megabytes
import java.util.*; public class Main{ public static void main(String ... strings){ Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-- > 0){ int a = sc.nextInt() , b = sc.nextInt() , c = sc.nextInt(); if(c % 3 == 0) System.out.println(a); else if( c % 3 == 1) System.out.println(b); else System.out.println((a^b)); } } }
Java
["3\n3 4 2\n4 5 0\n325 265 1231232"]
1 second
["7\n4\n76"]
NoteIn the first example, $$$f(2) = f(0) \oplus f(1) = 3 \oplus 4 = 7$$$.
Java 8
standard input
[ "math" ]
64a375c7c49591c676dbdb039c93d218
The input contains one or more independent test cases. The first line of input contains a single integer $$$T$$$ ($$$1 \le T \le 10^3$$$), the number of test cases. Each of the $$$T$$$ following lines contains three space-separated integers $$$a$$$, $$$b$$$, and $$$n$$$ ($$$0 \le a, b, n \le 10^9$$$) respectively.
900
For each test case, output $$$f(n)$$$.
standard output
PASSED
1bbc41b1ee2ee98fa77e93dbcd721d28
train_003.jsonl
1566743700
Cengiz recently learned Fibonacci numbers and now he is studying different algorithms to find them. After getting bored of reading them, he came with his own new type of numbers that he named XORinacci numbers. He defined them as follows: $$$f(0) = a$$$; $$$f(1) = b$$$; $$$f(n) = f(n-1) \oplus f(n-2)$$$ when $$$n &gt; 1$$$, where $$$\oplus$$$ denotes the bitwise XOR operation. You are given three integers $$$a$$$, $$$b$$$, and $$$n$$$, calculate $$$f(n)$$$.You have to answer for $$$T$$$ independent test cases.
256 megabytes
import java.util.ArrayList; import java.util.HashMap; import java.util.Scanner; public class codefest19 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner s = new Scanner(System.in); int t = s.nextInt(); while (t-- > 0) { int a = s.nextInt(); int b = s.nextInt(); int n = s.nextInt(); if(n==0) { System.out.println(a); continue; } System.out.println(xorsum(n, a, b)); } } public static int xorsum(int n, int a, int b) { ArrayList<Integer> list = new ArrayList<>(); list.add(a); list.add(b); if (n == 0 || n == 1) { return list.get(n); } HashMap<Integer, Integer> vis = new HashMap<>(); for (int i = 2; i < n + 1; i++) { int ans = list.get(i-1) ^ list.get(i-2); if (vis.containsKey(ans)) { int diff = i - vis.get(ans); return list.get(n%diff); } vis.put(ans, i); list.add(ans); } return list.get(n); } }
Java
["3\n3 4 2\n4 5 0\n325 265 1231232"]
1 second
["7\n4\n76"]
NoteIn the first example, $$$f(2) = f(0) \oplus f(1) = 3 \oplus 4 = 7$$$.
Java 8
standard input
[ "math" ]
64a375c7c49591c676dbdb039c93d218
The input contains one or more independent test cases. The first line of input contains a single integer $$$T$$$ ($$$1 \le T \le 10^3$$$), the number of test cases. Each of the $$$T$$$ following lines contains three space-separated integers $$$a$$$, $$$b$$$, and $$$n$$$ ($$$0 \le a, b, n \le 10^9$$$) respectively.
900
For each test case, output $$$f(n)$$$.
standard output