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 | 714729935b3389b203e019e6c8024aff | train_002.jsonl | 1601219100 | You are given an array $$$a$$$ consisting of $$$n$$$ integers numbered from $$$1$$$ to $$$n$$$.Let's define the $$$k$$$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $$$k$$$ (recall that a subsegment of $$$a$$$ of length $$$k$$$ is a contiguous part of $$$a$$$ containing exactly $$$k$$$ elements). If there is no integer occuring in all subsegments of length $$$k$$$ for some value of $$$k$$$, then the $$$k$$$-amazing number is $$$-1$$$.For each $$$k$$$ from $$$1$$$ to $$$n$$$ calculate the $$$k$$$-amazing number of the array $$$a$$$. | 256 megabytes | import java.io.*;
import java.util.*;
import java.lang.*;
public class Santosh{
public static void main(String[] args)throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(br.readLine());
while(t-->0){
int n=Integer.parseInt(br.readLine());
String[] str=br.readLine().trim().split("\\s");
int[] arr=new int[n];
for(int i=0;i<n;i++){
arr[i]=Integer.parseInt(str[i]);
}
List<Integer>pos[]=new ArrayList[n+1];
for(int i=0;i<n+1;i++){
pos[i]=new ArrayList<Integer>();
pos[i].add(0);
}
for(int i=0;i<n;i++){
pos[arr[i]].add(i+1);
}
int[] diff=new int[n+1];
Arrays.fill(diff,Integer.MAX_VALUE);
for(int i=1;i<n+1;i++){
int maxdiff=0;
int j=1;
for(j=1;j<pos[i].size();j++){
int curdiff=pos[i].get(j)-pos[i].get(j-1);
if(curdiff>maxdiff) maxdiff=curdiff;
}
if(maxdiff!=0 && (maxdiff<(n+1-pos[i].get(j-1)))){
maxdiff=(n+1-pos[i].get(j-1));
}
if(diff[maxdiff]>i) diff[maxdiff]=i;
}
int min=Integer.MAX_VALUE;
for(int i=1;i<n+1;i++){
if(diff[i]>min) diff[i]=min;
else{
min=diff[i];
}
}
StringBuilder sb=new StringBuilder();
for(int i=1;i<n+1;i++){
if(diff[i]>n) sb.append(-1+" ");
else sb.append(diff[i]+" ");
}
System.out.println(sb);
}
}
} | Java | ["3\n5\n1 2 3 4 5\n5\n4 4 4 4 2\n6\n1 3 1 5 3 1"] | 1 second | ["-1 -1 3 2 1 \n-1 4 4 4 2 \n-1 -1 1 1 1 1"] | null | Java 11 | standard input | [
"data structures"
] | b7abfb1103bb1796c8f89653c303d7dc | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) — the number of elements in the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,500 | For each test case print $$$n$$$ integers, where the $$$i$$$-th integer is equal to the $$$i$$$-amazing number of the array. | standard output | |
PASSED | 726449ece8e018362d36780f844f7b48 | train_002.jsonl | 1601219100 | You are given an array $$$a$$$ consisting of $$$n$$$ integers numbered from $$$1$$$ to $$$n$$$.Let's define the $$$k$$$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $$$k$$$ (recall that a subsegment of $$$a$$$ of length $$$k$$$ is a contiguous part of $$$a$$$ containing exactly $$$k$$$ elements). If there is no integer occuring in all subsegments of length $$$k$$$ for some value of $$$k$$$, then the $$$k$$$-amazing number is $$$-1$$$.For each $$$k$$$ from $$$1$$$ to $$$n$$$ calculate the $$$k$$$-amazing number of the array $$$a$$$. | 256 megabytes | //package com.company;
import java.io.BufferedReader;
import java.io.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;
public class solution {
BufferedReader br;
PrintWriter out;
private void solve() {
int t = ni();
while(t-- > 0) {
int n = ni();
int[] ans = new int[n];
int[] arr = new int[n];
int[] prev = new int[n];
int[] next = new int[n];
HashMap<Integer, Integer> index = new HashMap<>();
for(int i = 0; i < n; i++) {
arr[i] = ni();
prev[i] = i+1;
next[i] = n - i;
ans[i] = Integer.MAX_VALUE;;
}
for (int i = 0; i < n; i++) {
if(index.containsKey(arr[i])) {
prev[i] = i - index.get(arr[i]);
}
index.put(arr[i], i);
}
//out.println("prev: " + Arrays.toString(prev));
index = new HashMap<>();
for(int i = n-1; i >= 0; i--) {
if(index.containsKey(arr[i])) {
next[i] = index.get(arr[i]) - i;
}
index.put(arr[i], i);
}
//out.println("next: " + Arrays.toString(next));
index = new HashMap<>();
for (int i = 0; i < n; i++) {
int max = Math.max(prev[i], next[i]);
if(!index.containsKey(arr[i]) || index.get(arr[i]) < max) {
index.put(arr[i], max);
}
// } else if() {
// index.put(arr[i], max);
// }
}
ArrayList<int[]> sorted = new ArrayList<>();
index.forEach((k, v) -> sorted.add(new int[]{k, v}));
Collections.sort(sorted, (int[] a1, int[] a2) -> {
if(a1[1] == a2[1]) {
return a1[0] - a2[0];
}
return a1[1] - a2[1];
});
//for(int i = 0; i < sorted.size(); i++) {
// out.println(Arrays.toString(sorted.get(i)));
//}
// int min = Integer.MAX_VALUE;
for(int i = 0; i < sorted.size(); i++) {
if(ans[sorted.get(i)[1]-1] > sorted.get(i)[0]) {
ans[sorted.get(i)[1]-1] = sorted.get(i)[0];
}
}
// out.println("ans: " + Arrays.toString(ans));
//for(int i = 0; i < sorted.size(); i++) {
// out.println(Arrays.toString(sorted.get(i)));
//}
for(int i = 1; i < n; i++) {
if(ans[i] > ans[i-1]) {
ans[i] = ans[i-1];
}
}
for(int i = 0; i < n; i++){
if(ans[i] == Integer.MAX_VALUE) ans[i] = -1;
}
for(int i = 0; i < n-1; i++) {
out.print(ans[i] + " " );
}
out.println(ans[n-1]);
}
}
// -------- I/O Template -------------
char nc() {
return ns().charAt(0);
}
String nLine() {
try {
return br.readLine();
} catch(IOException e) {
return "-1";
}
}
double nd() {
return Double.parseDouble(ns());
}
long nl() {
return Long.parseLong(ns());
}
int ni() {
return Integer.parseInt(ns());
}
StringTokenizer ip;
String ns() {
while(ip == null || !ip.hasMoreTokens()) {
try {
ip = new StringTokenizer(br.readLine());
} catch(IOException e) {
throw new InputMismatchException();
}
}
return ip.nextToken();
}
void run() {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
out.flush();
}
public static void main(String[] args) {
new solution().run();
}
}
| Java | ["3\n5\n1 2 3 4 5\n5\n4 4 4 4 2\n6\n1 3 1 5 3 1"] | 1 second | ["-1 -1 3 2 1 \n-1 4 4 4 2 \n-1 -1 1 1 1 1"] | null | Java 11 | standard input | [
"data structures"
] | b7abfb1103bb1796c8f89653c303d7dc | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) — the number of elements in the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,500 | For each test case print $$$n$$$ integers, where the $$$i$$$-th integer is equal to the $$$i$$$-amazing number of the array. | standard output | |
PASSED | 207399843cc3574f0747acab3b14870a | train_002.jsonl | 1601219100 | You are given an array $$$a$$$ consisting of $$$n$$$ integers numbered from $$$1$$$ to $$$n$$$.Let's define the $$$k$$$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $$$k$$$ (recall that a subsegment of $$$a$$$ of length $$$k$$$ is a contiguous part of $$$a$$$ containing exactly $$$k$$$ elements). If there is no integer occuring in all subsegments of length $$$k$$$ for some value of $$$k$$$, then the $$$k$$$-amazing number is $$$-1$$$.For each $$$k$$$ from $$$1$$$ to $$$n$$$ calculate the $$$k$$$-amazing number of the array $$$a$$$. | 256 megabytes | /*
Author: Anthony Ngene
Created: 28/09/2020 - 05:19
*/
import java.io.*;
import java.util.*;
public class C {
// checks: 1. edge cases 2. overflow 3. possible errors (e.g 1/0, arr[out]) 4. time/space complexity
void solver() throws IOException {
int cases = in.intNext();
for (int t = 1; t <= cases; t++) {
int n = in.intNext();
int[] arr = in.nextIntArray(n);
HashMap<Integer, Tuple> lastSeen = new HashMap<>();
for (int i = 1; i < n + 1; i++) {
int num = arr[i - 1];
if (!lastSeen.containsKey(num)) lastSeen.put(num, new Tuple(0, 0));
Tuple node = lastSeen.get(num);
node.b = max(node.b, i - node.a);
if (node.a == 0) node.c = n + 1 - i;
else node.c = 0;
node.a = i;
}
for (Tuple val: lastSeen.values()) val.b = max(val.b, n + 1 - val.a);
int[] res = new int[n + 1];
Arrays.fill(res, Integer.MAX_VALUE);
for (int k : lastSeen.keySet()) {
int mn = lastSeen.get(k).b;
res[mn] = min(res[mn], k);
}
for (int i = 1; i < n + 1; i++) {
if (res[i-1] != Integer.MAX_VALUE) res[i] = min(res[i], res[i - 1]);
out.p(res[i] == Integer.MAX_VALUE ? -1 : res[i]).p(" ");
}
out.println("");
}
}
// Generated Code Below:
private static final FastWriter out = new FastWriter();
private static FastScanner in;
static ArrayList<Integer>[] adj;
private static long e97 = (long)1e9 + 7;
public static void main(String[] args) throws IOException {
in = new FastScanner();
new C().solver();
out.close();
}
static class FastWriter {
private static final int IO_BUFFERS = 128 * 1024;
private final StringBuilder out;
public FastWriter() { out = new StringBuilder(IO_BUFFERS); }
public FastWriter p(Object object) { out.append(object); return this; }
public FastWriter p(String format, Object... args) { out.append(String.format(format, args)); return this; }
public FastWriter pp(Object... args) { for (Object ob : args) { out.append(ob).append(" "); } out.append("\n"); return this; }
public FastWriter pp(int[] args) { for (int ob : args) { out.append(ob).append(" "); } out.append("\n"); return this; }
public FastWriter pp(long[] args) { for (long ob : args) { out.append(ob).append(" "); } out.append("\n"); return this; }
public FastWriter pp(char[] args) { for (char ob : args) { out.append(ob).append(" "); } out.append("\n"); return this; }
public void println(long[] arr) { for(long e: arr) out.append(e).append(" "); out.append("\n"); }
public void println(int[] arr) { for(int e: arr) out.append(e).append(" "); out.append("\n"); }
public void println(char[] arr) { for(char e: arr) out.append(e).append(" "); out.append("\n"); }
public void println(double[] arr) { for(double e: arr) out.append(e).append(" "); out.append("\n"); }
public void println(boolean[] arr) { for(boolean e: arr) out.append(e).append(" "); out.append("\n"); }
public <T>void println(T[] arr) { for(T e: arr) out.append(e).append(" "); out.append("\n"); }
public void println(long[][] arr) { for (long[] row: arr) out.append(Arrays.toString(row)).append("\n"); }
public void println(int[][] arr) { for (int[] row: arr) out.append(Arrays.toString(row)).append("\n"); }
public void println(char[][] arr) { for (char[] row: arr) out.append(Arrays.toString(row)).append("\n"); }
public void println(double[][] arr) { for (double[] row: arr) out.append(Arrays.toString(row)).append("\n"); }
public <T>void println(T[][] arr) { for (T[] row: arr) out.append(Arrays.toString(row)).append("\n"); }
public FastWriter println(Object object) { out.append(object).append("\n"); return this; }
public void toFile(String fileName) throws IOException {
BufferedWriter writer = new BufferedWriter(new FileWriter(fileName));
writer.write(out.toString());
writer.close();
}
public void close() throws IOException { System.out.print(out); }
}
static class FastScanner {
private InputStream sin = System.in;
private final byte[] buffer = new byte[1024];
private int ptr = 0;
private int buflen = 0;
public FastScanner(){}
public FastScanner(String filename) throws FileNotFoundException {
File file = new File(filename);
sin = new FileInputStream(file);
}
private boolean hasNextByte() {
if (ptr < buflen) {
return true;
}else{
ptr = 0;
try {
buflen = sin.read(buffer);
} catch (IOException e) {
e.printStackTrace();
}
if (buflen <= 0) {
return false;
}
}
return true;
}
private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
public String next() {
if (!hasNext()) throw new NoSuchElementException();
StringBuilder sb = new StringBuilder();
int b = readByte();
while(isPrintableChar(b)) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public long longNext() {
if (!hasNext()) throw new NoSuchElementException();
long n = 0;
boolean minus = false;
int b = readByte();
if (b == '-') {
minus = true;
b = readByte();
}
if (b < '0' || '9' < b) {
throw new NumberFormatException();
}
while(true){
if ('0' <= b && b <= '9') {
n *= 10;
n += b - '0';
}else if(b == -1 || !isPrintableChar(b) || b == ':'){
return minus ? -n : n;
}else{
throw new NumberFormatException();
}
b = readByte();
}
}
public int intNext() {
long nl = longNext();
if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
return (int) nl;
}
public double doubleNext() { return Double.parseDouble(next());}
public long[] nextLongArray(final int n){
final long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = longNext();
return a;
}
public int[] nextIntArray(final int n){
final int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = intNext();
return a;
}
public double[] nextDoubleArray(final int n){
final double[] a = new double[n];
for (int i = 0; i < n; i++)
a[i] = doubleNext();
return a;
}
public ArrayList<Integer>[] getAdj(int n) {
ArrayList<Integer>[] adj = new ArrayList[n + 1];
for (int i = 1; i <= n; i++) adj[i] = new ArrayList<>();
return adj;
}
public ArrayList<Integer>[] adjacencyList(int nodes, int edges) throws IOException {
return adjacencyList(nodes, edges, false);
}
public ArrayList<Integer>[] adjacencyList(int nodes, int edges, boolean isDirected) throws IOException {
adj = getAdj(nodes);
for (int i = 0; i < edges; i++) {
int a = intNext(), b = intNext();
adj[a].add(b);
if (!isDirected) adj[b].add(a);
}
return adj;
}
}
static class u {
public static int upperBound(long[] array, long obj) {
int l = 0, r = array.length - 1;
while (r - l >= 0) {
int c = (l + r) / 2;
if (obj < array[c]) {
r = c - 1;
} else {
l = c + 1;
}
}
return l;
}
public static int upperBound(ArrayList<Long> array, long obj) {
int l = 0, r = array.size() - 1;
while (r - l >= 0) {
int c = (l + r) / 2;
if (obj < array.get(c)) {
r = c - 1;
} else {
l = c + 1;
}
}
return l;
}
public static int lowerBound(long[] array, long obj) {
int l = 0, r = array.length - 1;
while (r - l >= 0) {
int c = (l + r) / 2;
if (obj <= array[c]) {
r = c - 1;
} else {
l = c + 1;
}
}
return l;
}
public static int lowerBound(ArrayList<Long> array, long obj) {
int l = 0, r = array.size() - 1;
while (r - l >= 0) {
int c = (l + r) / 2;
if (obj <= array.get(c)) {
r = c - 1;
} else {
l = c + 1;
}
}
return l;
}
static <T> T[][] deepCopy(T[][] matrix) { return Arrays.stream(matrix).map(el -> el.clone()).toArray($ -> matrix.clone()); }
static int[][] deepCopy(int[][] matrix) { return Arrays.stream(matrix).map(int[]::clone).toArray($ -> matrix.clone()); }
static long[][] deepCopy(long[][] matrix) { return Arrays.stream(matrix).map(long[]::clone).toArray($ -> matrix.clone()); }
private static void sort(int[][] arr){ Arrays.sort(arr, Comparator.comparingDouble(o -> o[0])); }
private static void sort(long[][] arr){ Arrays.sort(arr, Comparator.comparingDouble(o -> o[0])); }
private static <T>void rSort(T[] arr) { Arrays.sort(arr, Collections.reverseOrder()); }
private static void customSort(int[][] arr) {
Arrays.sort(arr, new Comparator<int[]>() {
public int compare(int[] a, int[] b) {
if (a[0] == b[0]) return Integer.compare(a[1], b[1]);
return Integer.compare(a[0], b[0]);
}
});
}
public static int[] swap(int[] arr, int left, int right) {
int temp = arr[left];
arr[left] = arr[right];
arr[right] = temp;
return arr;
}
public static char[] swap(char[] arr, int left, int right) {
char temp = arr[left];
arr[left] = arr[right];
arr[right] = temp;
return arr;
}
public static int[] reverse(int[] arr, int left, int right) {
while (left < right) {
int temp = arr[left];
arr[left++] = arr[right];
arr[right--] = temp;
}
return arr;
}
public static boolean findNextPermutation(int[] data) {
if (data.length <= 1) return false;
int last = data.length - 2;
while (last >= 0) {
if (data[last] < data[last + 1]) break;
last--;
}
if (last < 0) return false;
int nextGreater = data.length - 1;
for (int i = data.length - 1; i > last; i--) {
if (data[i] > data[last]) {
nextGreater = i;
break;
}
}
data = swap(data, nextGreater, last);
data = reverse(data, last + 1, data.length - 1);
return true;
}
public static int biSearch(int[] dt, int target){
int left=0, right=dt.length-1;
int mid=-1;
while(left<=right){
mid = (right+left)/2;
if(dt[mid] == target) return mid;
if(dt[mid] < target) left=mid+1;
else right=mid-1;
}
return -1;
}
public static int biSearchMax(long[] dt, long target){
int left=-1, right=dt.length;
int mid=-1;
while((right-left)>1){
mid = left + (right-left)/2;
if(dt[mid] <= target) left=mid;
else right=mid;
}
return left;
}
public static int biSearchMaxAL(ArrayList<Integer> dt, long target){
int left=-1, right=dt.size();
int mid=-1;
while((right-left)>1){
mid = left + (right-left)/2;
if(dt.get(mid) <= target) left=mid;
else right=mid;
}
return left;
}
private static <T>void fill(T[][] ob, T res){for(int i=0;i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){ ob[i][j] = res; }}}
private static void fill(boolean[][] ob,boolean res){for(int i=0;i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){ ob[i][j] = res; }}}
private static void fill(int[][] ob, int res){ for(int i=0; i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){ ob[i][j] = res; }}}
private static void fill(long[][] ob, long res){ for(int i=0; i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){ ob[i][j] = res; }}}
private static void fill(char[][] ob, char res){ for(int i=0; i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){ ob[i][j] = res; }}}
private static void fill(double[][] ob, double res){for(int i=0; i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){ ob[i][j] = res; }}}
private static void fill(int[][][] ob,int res){for(int i=0;i<ob.length;i++){for(int j=0;j<ob[0].length;j++){for(int k=0;k<ob[0][0].length;k++){ob[i][j][k]=res;}}}}
private static void fill(long[][][] ob,long res){for(int i=0;i<ob.length;i++){for(int j=0;j<ob[0].length;j++){for(int k=0;k<ob[0][0].length;k++){ob[i][j][k]=res;}}}}
private static <T>void fill(T[][][] ob,T res){for(int i=0;i<ob.length;i++){for(int j=0;j<ob[0].length;j++){for(int k=0;k<ob[0][0].length;k++){ob[i][j][k]=res;}}}}
private static void fill_parent(int[] ob){ for(int i=0; i<ob.length; i++) ob[i]=i; }
private static boolean same3(long a, long b, long c){
if(a!=b) return false;
if(b!=c) return false;
if(c!=a) return false;
return true;
}
private static boolean dif3(long a, long b, long c){
if(a==b) return false;
if(b==c) return false;
if(c==a) return false;
return true;
}
private static double hypotenuse(double a, double b){
return Math.sqrt(a*a+b*b);
}
private static long factorial(int n) {
long ans=1;
for(long i=n; i>0; i--){ ans*=i; }
return ans;
}
private static long facMod(int n, long mod) {
long ans=1;
for(long i=n; i>0; i--) ans = (ans * i) % mod;
return ans;
}
private static long lcm(long m, long n){
long ans = m/gcd(m,n);
ans *= n;
return ans;
}
private static long gcd(long m, long n) {
if(m < n) return gcd(n, m);
if(n == 0) return m;
return gcd(n, m % n);
}
private static boolean isPrime(long a){
if(a==1) return false;
for(int i=2; i<=Math.sqrt(a); i++){ if(a%i == 0) return false; }
return true;
}
static long modInverse(long a, long mod) {
/* Fermat's little theorem: a^(MOD-1) => 1
Therefore (divide both sides by a): a^(MOD-2) => a^(-1) */
return binpowMod(a, mod - 2, mod);
}
static long binpowMod(long a, long b, long mod) {
long res = 1;
while (b > 0) {
if (b % 2 == 1) res = (res * a) % mod;
a = (a * a) % mod;
b /= 2;
}
return res;
}
private static int getDigit2(long num){
long cf = 1; int d=0;
while(num >= cf){ d++; cf = 1<<d; }
return d;
}
private static int getDigit10(long num){
long cf = 1; int d=0;
while(num >= cf){ d++; cf*=10; }
return d;
}
private static boolean isInArea(int y, int x, int h, int w){
if(y<0) return false;
if(x<0) return false;
if(y>=h) return false;
if(x>=w) return false;
return true;
}
private static ArrayList<Integer> generatePrimes(int n) {
int[] lp = new int[n + 1];
ArrayList<Integer> pr = new ArrayList<>();
for (int i = 2; i <= n; ++i) {
if (lp[i] == 0) {
lp[i] = i;
pr.add(i);
}
for (int j = 0; j < pr.size() && pr.get(j) <= lp[i] && i * pr.get(j) <= n; ++j) {
lp[i * pr.get(j)] = pr.get(j);
}
}
return pr;
}
static long nPrMod(int n, int r, long MOD) {
long res = 1;
for (int i = (n - r + 1); i <= n; i++) {
res = (res * i) % MOD;
}
return res;
}
static long nCr(int n, int r) {
if (r > (n - r))
r = n - r;
long ans = 1;
for (int i = 1; i <= r; i++) {
ans *= n;
ans /= i;
n--;
}
return ans;
}
static long nCrMod(int n, int r, long MOD) {
long rFactorial = nPrMod(r, r, MOD);
long first = nPrMod(n, r, MOD);
long second = binpowMod(rFactorial, MOD-2, MOD);
return (first * second) % MOD;
}
static void printBitRepr(int n) {
StringBuilder res = new StringBuilder();
for (int i = 0; i < 32; i++) {
int mask = (1 << i);
res.append((mask & n) == 0 ? "0" : "1");
}
out.println(res);
}
static String bitString(int n) {return Integer.toBinaryString(n);}
static int setKthBitToOne(int n, int k) { return (n | (1 << k)); } // zero indexed
static int setKthBitToZero(int n, int k) { return (n & ~(1 << k)); }
static int invertKthBit(int n, int k) { return (n ^ (1 << k)); }
static boolean isPowerOfTwo(int n) { return (n & (n - 1)) == 0; }
static HashMap<Character, Integer> counts(String word) {
HashMap<Character, Integer> counts = new HashMap<>();
for (int i = 0; i < word.length(); i++) counts.merge(word.charAt(i), 1, Integer::sum);
return counts;
}
static HashMap<Integer, Integer> counts(int[] arr) {
HashMap<Integer, Integer> counts = new HashMap<>();
for (int value : arr) counts.merge(value, 1, Integer::sum);
return counts;
}
static HashMap<Long, Integer> counts(long[] arr) {
HashMap<Long, Integer> counts = new HashMap<>();
for (long l : arr) counts.merge(l, 1, Integer::sum);
return counts;
}
static HashMap<Character, Integer> counts(char[] arr) {
HashMap<Character, Integer> counts = new HashMap<>();
for (char c : arr) counts.merge(c, 1, Integer::sum);
return counts;
}
static long hash(int x, int y) {
return x* 1_000_000_000L +y;
}
static final Random random = new Random();
static void sort(int[] a) {
int n = a.length;// shuffle, then sort
for (int i = 0; i < n; i++) {
int oi = random.nextInt(n), temp = a[oi];
a[oi] = a[i];
a[i] = temp;
}
Arrays.sort(a);
}
static void sort(long[] arr) {
shuffleArray(arr);
Arrays.sort(arr);
}
static void shuffleArray(long[] arr) {
int n = arr.length;
for(int i=0; i<n; ++i){
long tmp = arr[i];
int randomPos = i + random.nextInt(n-i);
arr[i] = arr[randomPos];
arr[randomPos] = tmp;
}
}
}
static class Tuple implements Comparable<Tuple> {
int a;
int b;
int c;
public Tuple(int a, int b) {
this.a = a;
this.b = b;
this.c = 0;
}
public Tuple(int a, int b, int c) {
this.a = a;
this.b = b;
this.c = c;
}
public int getA() { return a; }
public int getB() { return b; }
public int getC() { return c; }
public int compareTo(Tuple other) {
if (this.a == other.a) {
if (this.b == other.b) return Long.compare(this.c, other.c);
return Long.compare(this.b, other.b);
}
return Long.compare(this.a, other.a);
}
@Override
public int hashCode() { return Arrays.deepHashCode(new Integer[]{a, b, c}); }
@Override
public boolean equals(Object o) {
if (!(o instanceof Tuple)) return false;
Tuple pairo = (Tuple) o;
return (this.a == pairo.a && this.b == pairo.b && this.c == pairo.c);
}
@Override
public String toString() { return String.format("(%d %d %d) ", this.a, this.b, this.c); }
}
private static int abs(int a){ return (a>=0) ? a: -a; }
private static int min(int... ins){ int min = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] < min) min = ins[i]; } return min; }
private static int max(int... ins){ int max = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] > max) max = ins[i]; } return max; }
private static int sum(int... ins){ int total = 0; for (int v : ins) { total += v; } return total; }
private static long abs(long a){ return (a>=0) ? a: -a; }
private static long min(long... ins){ long min = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] < min) min = ins[i]; } return min; }
private static long max(long... ins){ long max = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] > max) max = ins[i]; } return max; }
private static long sum(long... ins){ long total = 0; for (long v : ins) { total += v; } return total; }
private static double abs(double a){ return (a>=0) ? a: -a; }
private static double min(double... ins){ double min = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] < min) min = ins[i]; } return min; }
private static double max(double... ins){ double max = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] > max) max = ins[i]; } return max; }
private static double sum(double... ins){ double total = 0; for (double v : ins) { total += v; } return total; }
}
| Java | ["3\n5\n1 2 3 4 5\n5\n4 4 4 4 2\n6\n1 3 1 5 3 1"] | 1 second | ["-1 -1 3 2 1 \n-1 4 4 4 2 \n-1 -1 1 1 1 1"] | null | Java 11 | standard input | [
"data structures"
] | b7abfb1103bb1796c8f89653c303d7dc | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) — the number of elements in the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,500 | For each test case print $$$n$$$ integers, where the $$$i$$$-th integer is equal to the $$$i$$$-amazing number of the array. | standard output | |
PASSED | 4499fd677b1296d643b1b7e386d38e61 | train_002.jsonl | 1601219100 | You are given an array $$$a$$$ consisting of $$$n$$$ integers numbered from $$$1$$$ to $$$n$$$.Let's define the $$$k$$$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $$$k$$$ (recall that a subsegment of $$$a$$$ of length $$$k$$$ is a contiguous part of $$$a$$$ containing exactly $$$k$$$ elements). If there is no integer occuring in all subsegments of length $$$k$$$ for some value of $$$k$$$, then the $$$k$$$-amazing number is $$$-1$$$.For each $$$k$$$ from $$$1$$$ to $$$n$$$ calculate the $$$k$$$-amazing number of the array $$$a$$$. | 256 megabytes | /*
Author: Anthony Ngene
Created: 28/09/2020 - 05:19
*/
import java.io.*;
import java.util.*;
public class C {
// checks: 1. edge cases 2. overflow 3. possible errors (e.g 1/0, arr[out]) 4. time/space complexity
void solver() throws IOException {
int cases = in.intNext();
for (int t = 1; t <= cases; t++) {
int n = in.intNext();
int[] arr = in.nextIntArray(n);
HashMap<Integer, Tuple> lastSeen = new HashMap<>();
for (int i = 1; i < n + 1; i++) {
int num = arr[i - 1];
if (!lastSeen.containsKey(num)) lastSeen.put(num, new Tuple(0, 0));
Tuple node = lastSeen.get(num);
node.b = max(node.b, i - node.a);
node.a = i;
}
for (Tuple val: lastSeen.values()) val.a = n + 1;
for (int i = n; i >= 1; i--) {
int num = arr[i - 1];
Tuple node = lastSeen.get(num);
node.b = max(node.b, node.a - i);
node.a = i;
}
int[] res = new int[n + 1];
Arrays.fill(res, Integer.MAX_VALUE);
for (int k : lastSeen.keySet()) {
int mn = lastSeen.get(k).b;
res[mn] = min(res[mn], k);
}
for (int i = 1; i < n + 1; i++) {
if (res[i-1] != Integer.MAX_VALUE) res[i] = min(res[i], res[i - 1]);
out.p(res[i] == Integer.MAX_VALUE ? -1 : res[i]).p(" ");
}
out.println("");
}
}
// Generated Code Below:
private static final FastWriter out = new FastWriter();
private static FastScanner in;
static ArrayList<Integer>[] adj;
private static long e97 = (long)1e9 + 7;
public static void main(String[] args) throws IOException {
in = new FastScanner();
new C().solver();
out.close();
}
static class FastWriter {
private static final int IO_BUFFERS = 128 * 1024;
private final StringBuilder out;
public FastWriter() { out = new StringBuilder(IO_BUFFERS); }
public FastWriter p(Object object) { out.append(object); return this; }
public FastWriter p(String format, Object... args) { out.append(String.format(format, args)); return this; }
public FastWriter pp(Object... args) { for (Object ob : args) { out.append(ob).append(" "); } out.append("\n"); return this; }
public FastWriter pp(int[] args) { for (int ob : args) { out.append(ob).append(" "); } out.append("\n"); return this; }
public FastWriter pp(long[] args) { for (long ob : args) { out.append(ob).append(" "); } out.append("\n"); return this; }
public FastWriter pp(char[] args) { for (char ob : args) { out.append(ob).append(" "); } out.append("\n"); return this; }
public void println(long[] arr) { for(long e: arr) out.append(e).append(" "); out.append("\n"); }
public void println(int[] arr) { for(int e: arr) out.append(e).append(" "); out.append("\n"); }
public void println(char[] arr) { for(char e: arr) out.append(e).append(" "); out.append("\n"); }
public void println(double[] arr) { for(double e: arr) out.append(e).append(" "); out.append("\n"); }
public void println(boolean[] arr) { for(boolean e: arr) out.append(e).append(" "); out.append("\n"); }
public <T>void println(T[] arr) { for(T e: arr) out.append(e).append(" "); out.append("\n"); }
public void println(long[][] arr) { for (long[] row: arr) out.append(Arrays.toString(row)).append("\n"); }
public void println(int[][] arr) { for (int[] row: arr) out.append(Arrays.toString(row)).append("\n"); }
public void println(char[][] arr) { for (char[] row: arr) out.append(Arrays.toString(row)).append("\n"); }
public void println(double[][] arr) { for (double[] row: arr) out.append(Arrays.toString(row)).append("\n"); }
public <T>void println(T[][] arr) { for (T[] row: arr) out.append(Arrays.toString(row)).append("\n"); }
public FastWriter println(Object object) { out.append(object).append("\n"); return this; }
public void toFile(String fileName) throws IOException {
BufferedWriter writer = new BufferedWriter(new FileWriter(fileName));
writer.write(out.toString());
writer.close();
}
public void close() throws IOException { System.out.print(out); }
}
static class FastScanner {
private InputStream sin = System.in;
private final byte[] buffer = new byte[1024];
private int ptr = 0;
private int buflen = 0;
public FastScanner(){}
public FastScanner(String filename) throws FileNotFoundException {
File file = new File(filename);
sin = new FileInputStream(file);
}
private boolean hasNextByte() {
if (ptr < buflen) {
return true;
}else{
ptr = 0;
try {
buflen = sin.read(buffer);
} catch (IOException e) {
e.printStackTrace();
}
if (buflen <= 0) {
return false;
}
}
return true;
}
private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
public String next() {
if (!hasNext()) throw new NoSuchElementException();
StringBuilder sb = new StringBuilder();
int b = readByte();
while(isPrintableChar(b)) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public long longNext() {
if (!hasNext()) throw new NoSuchElementException();
long n = 0;
boolean minus = false;
int b = readByte();
if (b == '-') {
minus = true;
b = readByte();
}
if (b < '0' || '9' < b) {
throw new NumberFormatException();
}
while(true){
if ('0' <= b && b <= '9') {
n *= 10;
n += b - '0';
}else if(b == -1 || !isPrintableChar(b) || b == ':'){
return minus ? -n : n;
}else{
throw new NumberFormatException();
}
b = readByte();
}
}
public int intNext() {
long nl = longNext();
if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
return (int) nl;
}
public double doubleNext() { return Double.parseDouble(next());}
public long[] nextLongArray(final int n){
final long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = longNext();
return a;
}
public int[] nextIntArray(final int n){
final int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = intNext();
return a;
}
public double[] nextDoubleArray(final int n){
final double[] a = new double[n];
for (int i = 0; i < n; i++)
a[i] = doubleNext();
return a;
}
public ArrayList<Integer>[] getAdj(int n) {
ArrayList<Integer>[] adj = new ArrayList[n + 1];
for (int i = 1; i <= n; i++) adj[i] = new ArrayList<>();
return adj;
}
public ArrayList<Integer>[] adjacencyList(int nodes, int edges) throws IOException {
return adjacencyList(nodes, edges, false);
}
public ArrayList<Integer>[] adjacencyList(int nodes, int edges, boolean isDirected) throws IOException {
adj = getAdj(nodes);
for (int i = 0; i < edges; i++) {
int a = intNext(), b = intNext();
adj[a].add(b);
if (!isDirected) adj[b].add(a);
}
return adj;
}
}
static class u {
public static int upperBound(long[] array, long obj) {
int l = 0, r = array.length - 1;
while (r - l >= 0) {
int c = (l + r) / 2;
if (obj < array[c]) {
r = c - 1;
} else {
l = c + 1;
}
}
return l;
}
public static int upperBound(ArrayList<Long> array, long obj) {
int l = 0, r = array.size() - 1;
while (r - l >= 0) {
int c = (l + r) / 2;
if (obj < array.get(c)) {
r = c - 1;
} else {
l = c + 1;
}
}
return l;
}
public static int lowerBound(long[] array, long obj) {
int l = 0, r = array.length - 1;
while (r - l >= 0) {
int c = (l + r) / 2;
if (obj <= array[c]) {
r = c - 1;
} else {
l = c + 1;
}
}
return l;
}
public static int lowerBound(ArrayList<Long> array, long obj) {
int l = 0, r = array.size() - 1;
while (r - l >= 0) {
int c = (l + r) / 2;
if (obj <= array.get(c)) {
r = c - 1;
} else {
l = c + 1;
}
}
return l;
}
static <T> T[][] deepCopy(T[][] matrix) { return Arrays.stream(matrix).map(el -> el.clone()).toArray($ -> matrix.clone()); }
static int[][] deepCopy(int[][] matrix) { return Arrays.stream(matrix).map(int[]::clone).toArray($ -> matrix.clone()); }
static long[][] deepCopy(long[][] matrix) { return Arrays.stream(matrix).map(long[]::clone).toArray($ -> matrix.clone()); }
private static void sort(int[][] arr){ Arrays.sort(arr, Comparator.comparingDouble(o -> o[0])); }
private static void sort(long[][] arr){ Arrays.sort(arr, Comparator.comparingDouble(o -> o[0])); }
private static <T>void rSort(T[] arr) { Arrays.sort(arr, Collections.reverseOrder()); }
private static void customSort(int[][] arr) {
Arrays.sort(arr, new Comparator<int[]>() {
public int compare(int[] a, int[] b) {
if (a[0] == b[0]) return Integer.compare(a[1], b[1]);
return Integer.compare(a[0], b[0]);
}
});
}
public static int[] swap(int[] arr, int left, int right) {
int temp = arr[left];
arr[left] = arr[right];
arr[right] = temp;
return arr;
}
public static char[] swap(char[] arr, int left, int right) {
char temp = arr[left];
arr[left] = arr[right];
arr[right] = temp;
return arr;
}
public static int[] reverse(int[] arr, int left, int right) {
while (left < right) {
int temp = arr[left];
arr[left++] = arr[right];
arr[right--] = temp;
}
return arr;
}
public static boolean findNextPermutation(int[] data) {
if (data.length <= 1) return false;
int last = data.length - 2;
while (last >= 0) {
if (data[last] < data[last + 1]) break;
last--;
}
if (last < 0) return false;
int nextGreater = data.length - 1;
for (int i = data.length - 1; i > last; i--) {
if (data[i] > data[last]) {
nextGreater = i;
break;
}
}
data = swap(data, nextGreater, last);
data = reverse(data, last + 1, data.length - 1);
return true;
}
public static int biSearch(int[] dt, int target){
int left=0, right=dt.length-1;
int mid=-1;
while(left<=right){
mid = (right+left)/2;
if(dt[mid] == target) return mid;
if(dt[mid] < target) left=mid+1;
else right=mid-1;
}
return -1;
}
public static int biSearchMax(long[] dt, long target){
int left=-1, right=dt.length;
int mid=-1;
while((right-left)>1){
mid = left + (right-left)/2;
if(dt[mid] <= target) left=mid;
else right=mid;
}
return left;
}
public static int biSearchMaxAL(ArrayList<Integer> dt, long target){
int left=-1, right=dt.size();
int mid=-1;
while((right-left)>1){
mid = left + (right-left)/2;
if(dt.get(mid) <= target) left=mid;
else right=mid;
}
return left;
}
private static <T>void fill(T[][] ob, T res){for(int i=0;i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){ ob[i][j] = res; }}}
private static void fill(boolean[][] ob,boolean res){for(int i=0;i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){ ob[i][j] = res; }}}
private static void fill(int[][] ob, int res){ for(int i=0; i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){ ob[i][j] = res; }}}
private static void fill(long[][] ob, long res){ for(int i=0; i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){ ob[i][j] = res; }}}
private static void fill(char[][] ob, char res){ for(int i=0; i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){ ob[i][j] = res; }}}
private static void fill(double[][] ob, double res){for(int i=0; i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){ ob[i][j] = res; }}}
private static void fill(int[][][] ob,int res){for(int i=0;i<ob.length;i++){for(int j=0;j<ob[0].length;j++){for(int k=0;k<ob[0][0].length;k++){ob[i][j][k]=res;}}}}
private static void fill(long[][][] ob,long res){for(int i=0;i<ob.length;i++){for(int j=0;j<ob[0].length;j++){for(int k=0;k<ob[0][0].length;k++){ob[i][j][k]=res;}}}}
private static <T>void fill(T[][][] ob,T res){for(int i=0;i<ob.length;i++){for(int j=0;j<ob[0].length;j++){for(int k=0;k<ob[0][0].length;k++){ob[i][j][k]=res;}}}}
private static void fill_parent(int[] ob){ for(int i=0; i<ob.length; i++) ob[i]=i; }
private static boolean same3(long a, long b, long c){
if(a!=b) return false;
if(b!=c) return false;
if(c!=a) return false;
return true;
}
private static boolean dif3(long a, long b, long c){
if(a==b) return false;
if(b==c) return false;
if(c==a) return false;
return true;
}
private static double hypotenuse(double a, double b){
return Math.sqrt(a*a+b*b);
}
private static long factorial(int n) {
long ans=1;
for(long i=n; i>0; i--){ ans*=i; }
return ans;
}
private static long facMod(int n, long mod) {
long ans=1;
for(long i=n; i>0; i--) ans = (ans * i) % mod;
return ans;
}
private static long lcm(long m, long n){
long ans = m/gcd(m,n);
ans *= n;
return ans;
}
private static long gcd(long m, long n) {
if(m < n) return gcd(n, m);
if(n == 0) return m;
return gcd(n, m % n);
}
private static boolean isPrime(long a){
if(a==1) return false;
for(int i=2; i<=Math.sqrt(a); i++){ if(a%i == 0) return false; }
return true;
}
static long modInverse(long a, long mod) {
/* Fermat's little theorem: a^(MOD-1) => 1
Therefore (divide both sides by a): a^(MOD-2) => a^(-1) */
return binpowMod(a, mod - 2, mod);
}
static long binpowMod(long a, long b, long mod) {
long res = 1;
while (b > 0) {
if (b % 2 == 1) res = (res * a) % mod;
a = (a * a) % mod;
b /= 2;
}
return res;
}
private static int getDigit2(long num){
long cf = 1; int d=0;
while(num >= cf){ d++; cf = 1<<d; }
return d;
}
private static int getDigit10(long num){
long cf = 1; int d=0;
while(num >= cf){ d++; cf*=10; }
return d;
}
private static boolean isInArea(int y, int x, int h, int w){
if(y<0) return false;
if(x<0) return false;
if(y>=h) return false;
if(x>=w) return false;
return true;
}
private static ArrayList<Integer> generatePrimes(int n) {
int[] lp = new int[n + 1];
ArrayList<Integer> pr = new ArrayList<>();
for (int i = 2; i <= n; ++i) {
if (lp[i] == 0) {
lp[i] = i;
pr.add(i);
}
for (int j = 0; j < pr.size() && pr.get(j) <= lp[i] && i * pr.get(j) <= n; ++j) {
lp[i * pr.get(j)] = pr.get(j);
}
}
return pr;
}
static long nPrMod(int n, int r, long MOD) {
long res = 1;
for (int i = (n - r + 1); i <= n; i++) {
res = (res * i) % MOD;
}
return res;
}
static long nCr(int n, int r) {
if (r > (n - r))
r = n - r;
long ans = 1;
for (int i = 1; i <= r; i++) {
ans *= n;
ans /= i;
n--;
}
return ans;
}
static long nCrMod(int n, int r, long MOD) {
long rFactorial = nPrMod(r, r, MOD);
long first = nPrMod(n, r, MOD);
long second = binpowMod(rFactorial, MOD-2, MOD);
return (first * second) % MOD;
}
static void printBitRepr(int n) {
StringBuilder res = new StringBuilder();
for (int i = 0; i < 32; i++) {
int mask = (1 << i);
res.append((mask & n) == 0 ? "0" : "1");
}
out.println(res);
}
static String bitString(int n) {return Integer.toBinaryString(n);}
static int setKthBitToOne(int n, int k) { return (n | (1 << k)); } // zero indexed
static int setKthBitToZero(int n, int k) { return (n & ~(1 << k)); }
static int invertKthBit(int n, int k) { return (n ^ (1 << k)); }
static boolean isPowerOfTwo(int n) { return (n & (n - 1)) == 0; }
static HashMap<Character, Integer> counts(String word) {
HashMap<Character, Integer> counts = new HashMap<>();
for (int i = 0; i < word.length(); i++) counts.merge(word.charAt(i), 1, Integer::sum);
return counts;
}
static HashMap<Integer, Integer> counts(int[] arr) {
HashMap<Integer, Integer> counts = new HashMap<>();
for (int value : arr) counts.merge(value, 1, Integer::sum);
return counts;
}
static HashMap<Long, Integer> counts(long[] arr) {
HashMap<Long, Integer> counts = new HashMap<>();
for (long l : arr) counts.merge(l, 1, Integer::sum);
return counts;
}
static HashMap<Character, Integer> counts(char[] arr) {
HashMap<Character, Integer> counts = new HashMap<>();
for (char c : arr) counts.merge(c, 1, Integer::sum);
return counts;
}
static long hash(int x, int y) {
return x* 1_000_000_000L +y;
}
static final Random random = new Random();
static void sort(int[] a) {
int n = a.length;// shuffle, then sort
for (int i = 0; i < n; i++) {
int oi = random.nextInt(n), temp = a[oi];
a[oi] = a[i];
a[i] = temp;
}
Arrays.sort(a);
}
static void sort(long[] arr) {
shuffleArray(arr);
Arrays.sort(arr);
}
static void shuffleArray(long[] arr) {
int n = arr.length;
for(int i=0; i<n; ++i){
long tmp = arr[i];
int randomPos = i + random.nextInt(n-i);
arr[i] = arr[randomPos];
arr[randomPos] = tmp;
}
}
}
static class Tuple implements Comparable<Tuple> {
int a;
int b;
int c;
public Tuple(int a, int b) {
this.a = a;
this.b = b;
this.c = 0;
}
public Tuple(int a, int b, int c) {
this.a = a;
this.b = b;
this.c = c;
}
public int getA() { return a; }
public int getB() { return b; }
public int getC() { return c; }
public int compareTo(Tuple other) {
if (this.a == other.a) {
if (this.b == other.b) return Long.compare(this.c, other.c);
return Long.compare(this.b, other.b);
}
return Long.compare(this.a, other.a);
}
@Override
public int hashCode() { return Arrays.deepHashCode(new Integer[]{a, b, c}); }
@Override
public boolean equals(Object o) {
if (!(o instanceof Tuple)) return false;
Tuple pairo = (Tuple) o;
return (this.a == pairo.a && this.b == pairo.b && this.c == pairo.c);
}
@Override
public String toString() { return String.format("(%d %d %d) ", this.a, this.b, this.c); }
}
private static int abs(int a){ return (a>=0) ? a: -a; }
private static int min(int... ins){ int min = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] < min) min = ins[i]; } return min; }
private static int max(int... ins){ int max = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] > max) max = ins[i]; } return max; }
private static int sum(int... ins){ int total = 0; for (int v : ins) { total += v; } return total; }
private static long abs(long a){ return (a>=0) ? a: -a; }
private static long min(long... ins){ long min = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] < min) min = ins[i]; } return min; }
private static long max(long... ins){ long max = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] > max) max = ins[i]; } return max; }
private static long sum(long... ins){ long total = 0; for (long v : ins) { total += v; } return total; }
private static double abs(double a){ return (a>=0) ? a: -a; }
private static double min(double... ins){ double min = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] < min) min = ins[i]; } return min; }
private static double max(double... ins){ double max = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] > max) max = ins[i]; } return max; }
private static double sum(double... ins){ double total = 0; for (double v : ins) { total += v; } return total; }
}
| Java | ["3\n5\n1 2 3 4 5\n5\n4 4 4 4 2\n6\n1 3 1 5 3 1"] | 1 second | ["-1 -1 3 2 1 \n-1 4 4 4 2 \n-1 -1 1 1 1 1"] | null | Java 11 | standard input | [
"data structures"
] | b7abfb1103bb1796c8f89653c303d7dc | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) — the number of elements in the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,500 | For each test case print $$$n$$$ integers, where the $$$i$$$-th integer is equal to the $$$i$$$-amazing number of the array. | standard output | |
PASSED | 09d809ba3ab31400bb17a26fdfccafc1 | train_002.jsonl | 1601219100 | You are given an array $$$a$$$ consisting of $$$n$$$ integers numbered from $$$1$$$ to $$$n$$$.Let's define the $$$k$$$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $$$k$$$ (recall that a subsegment of $$$a$$$ of length $$$k$$$ is a contiguous part of $$$a$$$ containing exactly $$$k$$$ elements). If there is no integer occuring in all subsegments of length $$$k$$$ for some value of $$$k$$$, then the $$$k$$$-amazing number is $$$-1$$$.For each $$$k$$$ from $$$1$$$ to $$$n$$$ calculate the $$$k$$$-amazing number of the array $$$a$$$. | 256 megabytes | import java.io.*;
import java.util.*;
import java.util.stream.Collectors;
public class C {
public static void main(String[] args) throws Exception {
FastScanner sc = new FastScanner();
FastWriter writer = new FastWriter();
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
int ar[] = sc.nextIntArray(n);
List<Integer> pos[] = new List[n + 1];
Arrays.setAll(pos, (i) -> new ArrayList<>());
for(int i = 1; i <= n; i++)
pos[i].add(0);
for (int i = 0; i < n; i++) {
pos[ar[i]].add(i+1);
}
int ans[] = new int[n+2];
Arrays.fill(ans, -1);
for (int i = 1; i <= n; i++) {
if(pos[i].size() == 0)
continue;
pos[i].add(n+1);
int max = 0;
for (int j = 0; j < pos[i].size() - 1; j++) {
max = max(max, pos[i].get(j+1) - pos[i].get(j));
}
for(int j = max; j <= n; j++) {
if(ans[j] != -1)
break;
ans[j] = i;
}
}
for(int i = 1; i <= n;i++)
writer.print(ans[i] + " ");
writer.println("");
}
writer.close();
}
static final Random random = new Random();
static class FastScanner {
private InputStream sin = System.in;
private final byte[] buffer = new byte[1024];
private int ptr = 0;
private int buflen = 0;
public FastScanner(){}
public FastScanner(String filename) throws FileNotFoundException {
File file = new File(filename);
sin = new FileInputStream(file);
}
private boolean hasNextByte() {
if (ptr < buflen) {
return true;
}else{
ptr = 0;
try {
buflen = sin.read(buffer);
} catch (IOException e) {
e.printStackTrace();
}
if (buflen <= 0) {
return false;
}
}
return true;
}
private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
public String next() {
if (!hasNext()) throw new NoSuchElementException();
StringBuilder sb = new StringBuilder();
int b = readByte();
while(isPrintableChar(b)) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public long nextLong() {
if (!hasNext()) throw new NoSuchElementException();
long n = 0;
boolean minus = false;
int b = readByte();
if (b == '-') {
minus = true;
b = readByte();
}
if (b < '0' || '9' < b) {
throw new NumberFormatException();
}
while(true){
if ('0' <= b && b <= '9') {
n *= 10;
n += b - '0';
}else if(b == -1 || !isPrintableChar(b) || b == ':'){
return minus ? -n : n;
}else{
throw new NumberFormatException();
}
b = readByte();
}
}
public int nextInt() {
long nl = nextLong();
if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
return (int) nl;
}
public double nextDouble() { return Double.parseDouble(next());}
public long[] nextLongArray(final int n){
final long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public int[] nextIntArray(final int n){
final int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public double[] nextDoubleArray(final int n){
final double[] a = new double[n];
for (int i = 0; i < n; i++)
a[i] = nextDouble();
return a;
}
public List<Integer>[] adjacencyList(int nodes, int edges) {
return adjacencyList(nodes, edges, false);
}
public List<Integer>[] adjacencyList(int nodes, int edges, boolean isDirected) {
List<Integer>[] adj = new ArrayList[nodes + 1];
Arrays.setAll(adj, (i) -> new ArrayList<>());
for (int i = 0; i < edges; i++) {
int a = nextInt(), b = nextInt();
adj[a].add(b);
if (!isDirected) adj[b].add(a);
}
return adj;
}
}
static class FastWriter {
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
void print(int n) throws Exception { writer.write(n + ""); }
void println(int n) throws Exception { writer.write(n + "\n"); }
void print(long n) throws Exception { writer.write(n + ""); }
void println(long n) throws Exception { writer.write(n + "\n"); }
void print(String s) throws Exception { writer.write(s); }
void println(String s) throws Exception { writer.write(s); writer.newLine(); }
void println(int ar[]) throws Exception { for(int e : ar) writer.write(e + " "); writer.newLine(); }
void println(long ar[]) throws Exception { for(long e : ar) writer.write(e + " "); writer.newLine(); }
void println(double ar[]) throws Exception { for(double e : ar) writer.write(e + " "); writer.newLine(); }
void close() throws Exception { writer.close(); }
<T> void println(List<T> L) throws Exception { for(T o : L) writer.write(o + " "); writer.newLine(); }
}
static int findDistance(List<Integer> G[], int nodes, int src, int dst) {
LinkedList<Integer> queue = new LinkedList<>();
int dist[] = new int[nodes + 1];
int ans = -1;
dist[src] = 0;
queue.add(src);
while(queue.size() > 0) {
int u = queue.poll();
if(u == dst) {
ans = dist[u];
}
for(int v : G[u]) {
if(dist[v] >= 0)
continue;
queue.add(v);
dist[v] = dist[u] + 1;
}
}
return ans;
}
static void sort(List<Integer> A) {
shuffleList(A);
Collections.sort(A);
}
static void shuffleList(List<Integer> A) {
int n = A.size();
for(int i = 0; i < n; i++) {
int tmp = A.get(i);
int randomPos = i + random.nextInt(n-i);
A.set(i, A.get(randomPos));
A.set(randomPos, tmp);
}
}
static void sort(int A[]) {
shuffleArray(A);
Arrays.sort(A);
}
static void sort(long A[]) {
shuffleArray(A);
Arrays.sort(A);
}
static void sort(double A[]) {
shuffleArray(A);
Arrays.sort(A);
}
static void shuffleArray(int[] A) {
int n = A.length;
for(int i = 0; i < n; i++) {
int tmp = A[i];
int randomPos = i + random.nextInt(n-i);
A[i] = A[randomPos];
A[randomPos] = tmp;
}
}
static void shuffleArray(long[] A) {
int n = A.length;
for(int i = 0; i < n; i++) {
long tmp = A[i];
int randomPos = i + random.nextInt(n-i);
A[i] = A[randomPos];
A[randomPos] = tmp;
}
}
static void shuffleArray(double[] A) {
int n = A.length;
for(int i = 0; i < n; i++) {
double tmp = A[i];
int randomPos = i + random.nextInt(n-i);
A[i] = A[randomPos];
A[randomPos] = tmp;
}
}
static int[] subArray(int A[], int x, int y) {
int B[] = new int[y - x + 1];
for(int i = x; i <= y; i++)
B[i-x] = A[i];
return B;
}
static int[] toArray(List<Integer> L) {
return L.stream().mapToInt(x -> x).toArray();
}
static void println(int[] A) {
for(int e: A) System.out.print(e + " ");
System.out.println();
}
static void println(long[] A) {
for(long e: A) System.out.print(e + " ");
System.out.println();
}
static void println(List arr) {
for(Object e: arr) System.out.print(e + " ");
System.out.println();
}
static void print(String s) {
System.out.print(s);
}
static void println(String s) {
System.out.println(s);
}
static List<Integer> toList(int ar[]) {
return Arrays.stream(ar).boxed().collect(Collectors.toList());
}
static List<Long> toList(long ar[]) {
return Arrays.stream(ar).boxed().collect(Collectors.toList());
}
static List<Double> toList(double ar[]) {
return Arrays.stream(ar).boxed().collect(Collectors.toList());
}
static long gcd(long a, long b) {
if(b == 0)
return a;
return gcd(b, a % b);
}
private static int abs(int a){ return (a>=0) ? a: -a; }
private static int min(int... ins){ return Arrays.stream(ins).min().getAsInt(); }
private static int max(int... ins){ return Arrays.stream(ins).max().getAsInt(); }
private static int sum(int... ins){ return Arrays.stream(ins).sum(); }
private static long abs(long a){ return (a>=0) ? a: -a; }
private static long min(long... ins){ return Arrays.stream(ins).min().getAsLong(); }
private static long max(long... ins){ return Arrays.stream(ins).max().getAsLong(); }
private static long sum(long... ins){ return Arrays.stream(ins).sum(); }
private static double abs(double a){ return (a>=0) ? a: -a; }
private static double min(double... ins){ return Arrays.stream(ins).min().getAsDouble(); }
private static double max(double... ins){ return Arrays.stream(ins).max().getAsDouble(); }
private static double sum(double... ins){ return Arrays.stream(ins).sum(); }
private static class Pair implements Comparable<Pair> {
int x, y;
Pair(int x, int y) { this.x = x; this.y = y; }
Pair() {}
@Override
public int compareTo(Pair other) {
return x == other.x ? y - other.y : x - other.x;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Pair pair = (Pair) o;
return x == pair.x &&
y == pair.y;
}
@Override
public int hashCode() {
return Objects.hash(x, y);
}
}
}
| Java | ["3\n5\n1 2 3 4 5\n5\n4 4 4 4 2\n6\n1 3 1 5 3 1"] | 1 second | ["-1 -1 3 2 1 \n-1 4 4 4 2 \n-1 -1 1 1 1 1"] | null | Java 11 | standard input | [
"data structures"
] | b7abfb1103bb1796c8f89653c303d7dc | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) — the number of elements in the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,500 | For each test case print $$$n$$$ integers, where the $$$i$$$-th integer is equal to the $$$i$$$-amazing number of the array. | standard output | |
PASSED | ae2c81b766e166663020071d75f0e136 | train_002.jsonl | 1601219100 | You are given an array $$$a$$$ consisting of $$$n$$$ integers numbered from $$$1$$$ to $$$n$$$.Let's define the $$$k$$$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $$$k$$$ (recall that a subsegment of $$$a$$$ of length $$$k$$$ is a contiguous part of $$$a$$$ containing exactly $$$k$$$ elements). If there is no integer occuring in all subsegments of length $$$k$$$ for some value of $$$k$$$, then the $$$k$$$-amazing number is $$$-1$$$.For each $$$k$$$ from $$$1$$$ to $$$n$$$ calculate the $$$k$$$-amazing number of the array $$$a$$$. | 256 megabytes | /** */
import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.*;
import java.math.*;
public class Main{
/*********************************************Constants***********************************/
static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static long mod=(long)1e9+7;
static long mod1=998244353;
static ArrayList<Integer> graph[];
static int pptr=0,pptrmax=0;
static String st[];
/*****************************************Solution Begins*********************************/
public static void main(String args[]) throws Exception{
int tt=pi();
while(tt-->0){
int n=pi();
int last[]=new int[n+1];
int min[]=new int[n+1];
int input[]=new int[n];
for(int i=0;i<n;i++){
int a=pi();
input[i]=a;
min[a]=Math.max(min[a],i-last[a]);
last[a]=i+1;
}
for(int u:input){
min[u]=Math.max(min[u],n-last[u]);
}
int ans[]=new int[n+1];
Arrays.fill(ans,Integer.MAX_VALUE);
for(int i=0;i<n;i++){
ans[min[input[i]]]=Math.min(ans[min[input[i]]],input[i]);
}
int cur=Integer.MAX_VALUE;
for(int i=0;i<n;i++){
cur=Math.min(cur,ans[i]);
int fans=cur;
if(fans==Integer.MAX_VALUE){
fans=-1;
}
out.print(fans+" ");
}
out.println();
}
/****************************************Solution Ends*************************************/
clr();
}
static void clr(){
out.flush();
out.close();
}
static void nl() throws Exception{
pptr=0;
st=br.readLine().split(" ");
pptrmax=st.length;
}
static void nls() throws Exception{
pptr=0;
st=br.readLine().split("");
pptrmax=st.length;
}
static int pi() throws Exception{
if(pptr==pptrmax)
nl();
return Integer.parseInt(st[pptr++]);
}
static long pl() throws Exception{
if(pptr==pptrmax)
nl();
return Long.parseLong(st[pptr++]);
}
static double pd() throws Exception{
if(pptr==pptrmax)
nl();
return Double.parseDouble(st[pptr++]);
}
static String ps() throws Exception{
if(pptr==pptrmax)
nl();
return st[pptr++];
}
/***************************************Precision Printing*********************************/
static void printPrecision(double d){
DecimalFormat ft = new DecimalFormat("0.00000000000");
out.println(ft.format(d));
}
/**************************************Bit Manipulation************************************/
static int countBit(long mask){
int ans=0;
while(mask!=0){
mask&=(mask-1);
ans++;
}
return ans;
}
/******************************************Graph******************************************/
static void Makegraph(int n){
graph=new ArrayList[n];
for(int i=0;i<n;i++)
graph[i]=new ArrayList<>();
}
static void addEdge(int a,int b){
graph[a].add(b);
}
// static void addEdge(int a,int b,int c){
// graph[a].add(new Pair(b,c));
// }
/*********************************************PAIR*****************************************/
static class Pair{
int u;
int v;
public Pair(int u, int v) {
this.u = u;
this.v = v;
}
public int hashCode() {
int hu = (int) (u ^ (u >>> 32));
int hv = (int) (v ^ (v >>> 32));
return 31 * hu + hv;
}
public boolean equals(Object o) {
Pair other = (Pair) o;
return u == other.u && v == other.v;
}
public String toString() {
return "[u=" + u + ", v=" + v + "]";
}
}
/******************************************Long Pair***************************************/
static class Pairl{
long u;
long v;
public Pairl(long u, long v) {
this.u = u;
this.v = v;
}
public int hashCode() {
int hu = (int) (u ^ (u >>> 32));
int hv = (int) (v ^ (v >>> 32));
return 31 * hu + hv;
}
public boolean equals(Object o) {
Pairl other = (Pairl) o;
return u == other.u && v == other.v;
}
public String toString() {
return "[u=" + u + ", v=" + v + "]";
}
}
/*****************************************DEBUG********************************************/
public static void debug(Object... o){
System.out.println(Arrays.deepToString(o));
}
/************************************MODULAR EXPONENTIATION********************************/
static long modulo(long a,long b,long c){
long x=1,y=a%c;
while(b > 0){
if(b%2 == 1)
x=(x*y)%c;
y = (y*y)%c;
b = b>>1;
}
return x%c;
}
/********************************************GCD*******************************************/
static long gcd(long x, long y){
if(x==0)
return y;
if(y==0)
return x;
long r=0, a, b;
a = (x > y) ? x : y;
b = (x < y) ? x : y;
r = b;
while(a % b != 0){
r = a % b;
a = b;
b = r;
}
return r;
}
} | Java | ["3\n5\n1 2 3 4 5\n5\n4 4 4 4 2\n6\n1 3 1 5 3 1"] | 1 second | ["-1 -1 3 2 1 \n-1 4 4 4 2 \n-1 -1 1 1 1 1"] | null | Java 11 | standard input | [
"data structures"
] | b7abfb1103bb1796c8f89653c303d7dc | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) — the number of elements in the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,500 | For each test case print $$$n$$$ integers, where the $$$i$$$-th integer is equal to the $$$i$$$-amazing number of the array. | standard output | |
PASSED | 81d96461a7e82662bdec0b22b9825107 | train_002.jsonl | 1601219100 | You are given an array $$$a$$$ consisting of $$$n$$$ integers numbered from $$$1$$$ to $$$n$$$.Let's define the $$$k$$$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $$$k$$$ (recall that a subsegment of $$$a$$$ of length $$$k$$$ is a contiguous part of $$$a$$$ containing exactly $$$k$$$ elements). If there is no integer occuring in all subsegments of length $$$k$$$ for some value of $$$k$$$, then the $$$k$$$-amazing number is $$$-1$$$.For each $$$k$$$ from $$$1$$$ to $$$n$$$ calculate the $$$k$$$-amazing number of the array $$$a$$$. | 256 megabytes | import java.util.*;
import java.io.*;
public class C {
static FastReader f = new FastReader();
static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) {
int t = f.nextInt();
while(t-- > 0)
solve();
out.close();
}
static void solve() {
int n = f.nextInt();
int[] arr = new int[n];
for(int i=0;i<n;i++) {
arr[i] = f.nextInt();
}
ArrayList<Integer>[] list = new ArrayList[n+1];
ArrayList<Integer>[] ans = new ArrayList[n+1];
for(int i=0;i<=n;i++) {
list[i] = new ArrayList<>();
ans[i] = new ArrayList<>();
}
for(int i=0;i<n;i++) {
list[arr[i]].add(i);
}
for(int i=1;i<=n;i++) {
if(list[i].isEmpty()) {
continue;
}
int min = list[i].get(0) + 1;
for(int j=1;j<list[i].size();j++) {
min = Math.max(min, list[i].get(j) - list[i].get(j-1));
}
min = Math.max(min, n - list[i].get(list[i].size() - 1));
ans[min].add(i);
}
int min = Integer.MAX_VALUE;
for(int i=1;i<=n;i++) {
for(int j : ans[i]) {
min = Math.min(min, j);
}
out.print(min == Integer.MAX_VALUE ? -1 : min);
out.print(' ');
}
out.println();
}
static class FastReader {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
String next() {
while(st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch(IOException ioe) {
ioe.printStackTrace();
}
}
return st.nextToken();
}
String nextLine() {
String s = "";
try {
s = br.readLine();
} catch(IOException ioe) {
ioe.printStackTrace();
}
return s;
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
}
} | Java | ["3\n5\n1 2 3 4 5\n5\n4 4 4 4 2\n6\n1 3 1 5 3 1"] | 1 second | ["-1 -1 3 2 1 \n-1 4 4 4 2 \n-1 -1 1 1 1 1"] | null | Java 11 | standard input | [
"data structures"
] | b7abfb1103bb1796c8f89653c303d7dc | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) — the number of elements in the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,500 | For each test case print $$$n$$$ integers, where the $$$i$$$-th integer is equal to the $$$i$$$-amazing number of the array. | standard output | |
PASSED | b95c82ca04debab1d3f56b2395e722fa | train_002.jsonl | 1601219100 | You are given an array $$$a$$$ consisting of $$$n$$$ integers numbered from $$$1$$$ to $$$n$$$.Let's define the $$$k$$$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $$$k$$$ (recall that a subsegment of $$$a$$$ of length $$$k$$$ is a contiguous part of $$$a$$$ containing exactly $$$k$$$ elements). If there is no integer occuring in all subsegments of length $$$k$$$ for some value of $$$k$$$, then the $$$k$$$-amazing number is $$$-1$$$.For each $$$k$$$ from $$$1$$$ to $$$n$$$ calculate the $$$k$$$-amazing number of the array $$$a$$$. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
public class D{
private static FastScanner fs = new FastScanner();
private static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) {
int t = fs.nextInt();
while(t-->0)
{
int n = fs.nextInt();
int arr[] = new int [n];
for(int i=0;i<n;i++) {
arr[i] = fs.nextInt();
--arr[i];
}
List<Integer> indexPos[] = new ArrayList[n];
for(int i=0;i<n;i++) {
indexPos[i] = new ArrayList<>();
indexPos[i].add(-1);
}
for(int i=0;i<n;i++)
{
indexPos[arr[i]].add(i);
}
for(int i=0;i<n;i++) indexPos[i].add(n);
int gap[] = new int[n+1];
for(int i=0;i<n;i++)
{
for(int j=1;j< indexPos[i].size();j++)
{
gap[i] = Math.max(gap[i],indexPos[i].get(j)-indexPos[i].get(j-1)-1);
}
}
int best[] = new int [n+1];
for(int i=0;i<n;i++) best[i] = Integer.MAX_VALUE;
for(int i=0;i<n;i++)
{
best[gap[i]] = Math.min(best[gap[i]],i+1);
}
int r = n+1;
for(int i=0;i<n;i++)
{
r = Math.min(r,best[i]);
if(r==n+1) out.print(-1+" ");
else out.print(r+" ");
}
out.println();
}
out.close();
}
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
int gcd(int a,int b)
{
while (b > 0)
{
int temp = b;
b = a % b;
a = temp;
}
return a;
}
private 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 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;
}
}
} | Java | ["3\n5\n1 2 3 4 5\n5\n4 4 4 4 2\n6\n1 3 1 5 3 1"] | 1 second | ["-1 -1 3 2 1 \n-1 4 4 4 2 \n-1 -1 1 1 1 1"] | null | Java 11 | standard input | [
"data structures"
] | b7abfb1103bb1796c8f89653c303d7dc | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) — the number of elements in the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,500 | For each test case print $$$n$$$ integers, where the $$$i$$$-th integer is equal to the $$$i$$$-amazing number of the array. | standard output | |
PASSED | 702a6f754ce528ec3be907f79d499212 | train_002.jsonl | 1601219100 | You are given an array $$$a$$$ consisting of $$$n$$$ integers numbered from $$$1$$$ to $$$n$$$.Let's define the $$$k$$$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $$$k$$$ (recall that a subsegment of $$$a$$$ of length $$$k$$$ is a contiguous part of $$$a$$$ containing exactly $$$k$$$ elements). If there is no integer occuring in all subsegments of length $$$k$$$ for some value of $$$k$$$, then the $$$k$$$-amazing number is $$$-1$$$.For each $$$k$$$ from $$$1$$$ to $$$n$$$ calculate the $$$k$$$-amazing number of the array $$$a$$$. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
public class C{
private static FastScanner fs = new FastScanner();
public static void main(String[] args) {
int t = fs.nextInt();
PrintWriter out=new PrintWriter(System.out);
while(t-->0)
{
int n = fs.nextInt();
List<Integer>[]indexPos = new ArrayList[n+1];
for(int i=1;i<=n;i++) {
indexPos[i] = new ArrayList<>();
indexPos[i].add(-1);
}
for(int i =0;i<n;i++)
{
int a = fs.nextInt();
indexPos[a].add(i);
}
for(int i=1;i<=n;i++) indexPos[i].add(n);
int gap[] = new int[n+1];
for(int i=1;i<=n;i++)
{
for(int j=1;j<indexPos[i].size();j++)
{
gap[i] = Math.max(gap[i],indexPos[i].get(j)- indexPos[i].get(j-1) -1);
}
}
int best[] = new int [n+1];
for(int i=0;i<=n;i++) best[i] = Integer.MAX_VALUE;
for(int i=1;i<=n;i++) best[gap[i]] = Math.min(best[gap[i]],i);
int r = n+1;
for(int i=0;i<n;i++)
{
r = Math.min(r,best[i]);
if(r== n+1) out.print(-1+" ");
else out.print(r+" ");
}
out.println();
}
out.close();
}
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
return a;
}
long nextLong() {
return Long.parseLong(next());
}
int gcd(int a,int b)
{
while (b > 0)
{
int temp = b;
b = a % b;
a = temp;
}
return a;
}
private 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 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;
}
}
} | Java | ["3\n5\n1 2 3 4 5\n5\n4 4 4 4 2\n6\n1 3 1 5 3 1"] | 1 second | ["-1 -1 3 2 1 \n-1 4 4 4 2 \n-1 -1 1 1 1 1"] | null | Java 11 | standard input | [
"data structures"
] | b7abfb1103bb1796c8f89653c303d7dc | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) — the number of elements in the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,500 | For each test case print $$$n$$$ integers, where the $$$i$$$-th integer is equal to the $$$i$$$-amazing number of the array. | standard output | |
PASSED | 54818f72ccdafe7ca4d9368c7f640aa0 | train_002.jsonl | 1601219100 | You are given an array $$$a$$$ consisting of $$$n$$$ integers numbered from $$$1$$$ to $$$n$$$.Let's define the $$$k$$$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $$$k$$$ (recall that a subsegment of $$$a$$$ of length $$$k$$$ is a contiguous part of $$$a$$$ containing exactly $$$k$$$ elements). If there is no integer occuring in all subsegments of length $$$k$$$ for some value of $$$k$$$, then the $$$k$$$-amazing number is $$$-1$$$.For each $$$k$$$ from $$$1$$$ to $$$n$$$ calculate the $$$k$$$-amazing number of the array $$$a$$$. | 256 megabytes | // package cf.cf1417;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
import java.util.function.IntConsumer;
public class CFC {
private static final String INPUT = "3\n" +
"5\n" +
"1 2 3 4 5\n" +
"5\n" +
"4 4 4 4 2\n" +
"6\n" +
"1 3 1 5 3 1\n";
private static final int MOD = 1_000_000_007;
FastScanner sc;
PrintWriter out;
public static void main(String[] args) {
new CFC().run();
}
public CFC() {
sc = new FastScanner(oj ? System.in : new ByteArrayInputStream(INPUT.getBytes()));
out = new PrintWriter(System.out);
}
public void run() {
long start = System.currentTimeMillis();
times(sc.nextInt(), this::solve);
out.flush();
tr(System.currentTimeMillis() - start + "ms");
}
static class Num implements Comparable<Num> {
int n;
int order;
int side = -1;
public Num(int n, int order) {
this.n = n;
this.order = order;
}
@Override
public int compareTo(Num o) {
return Comparator.comparingInt((Num nm) -> nm.n).thenComparingInt(nm -> nm.order).compare(this, o);
}
@Override
public String toString() {
return n + " " + order;
}
}
public void solve(int time) {
int n = sc.nextInt();
int[] a = readIntArray(n);
int[] vals = new int[n + 1];
int[] mxlen = new int[n + 1];
int[] prev = new int[n + 1];
Arrays.fill(prev, -1);
for (int i = 0; i < n; i++) {
int v = a[i];
vals[v]++;
int len = i - prev[v];
mxlen[v] = Math.max(mxlen[v], len);
prev[v] = i;
}
for (int i = 0; i <= n; i++) {
int v = vals[i];
if (v > 0) {
mxlen[i] = Math.max(mxlen[i], n - prev[i]);
}
}
int size = (n+1)/2;
int[] ans = new int[n+1];
Arrays.fill(ans, -1);
int max = n + 1;
for (int i = 1; i <= n; i++) {
int v = mxlen[i];
if (v > 0 && v < max) {
for (int j = v; j < max; j++) {
ans[j] = i;
}
max = v;
}
}
for (int i = 1; i <= n; i++) {
write(ans[i] + " ");
}
writeln();
}
//---------------------------------------------------------------------------------------------------
/**
* If searched element doesn't exist, 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>
*/
private static int lowerBound(long[] arr, long key) {
int lo = 0;
int hi = arr.length - 1;
while (lo < hi) {
int mid = (lo + hi) / 2;
if (key <= arr[mid]) {
hi = mid - 1;
} else {
lo = mid + 1;
}
}
return arr[lo] < key ? lo + 1 : lo;
}
/**
* Returns index of first element which is grater than searched value.
* If searched element is bigger than any array element, returns first index after last element.
*/
private static int upperBound(long[] arr, long key) {
int lo = 0;
int hi = arr.length - 1;
while (lo < hi) {
int mid = (lo + hi) / 2;
if (key >= arr[mid]) {
lo = mid + 1;
} else {
hi = mid;
}
}
return arr[lo] <= key ? lo + 1 : lo;
}
private long[] prefixSum(long[] array) {
long[] result = new long[array.length];
result[0] = array[0];
for (int i = 1; i < array.length; i++) result[i] = result[i - 1] + array[i];
return result;
}
private int[] sort(int[] array) {
shuffle(array);
Arrays.sort(array);
return array;
}
private static void shuffle(int[] array) {
Random random = new Random();
for (int i = array.length - 1; i > 0; i--) {
int index = random.nextInt(i + 1);
{
int tmp = array[index];
array[index] = array[i];
array[i] = tmp;
}
}
}
private long[] sort(long[] array) {
shuffle(array);
Arrays.sort(array);
return array;
}
private static void shuffle(long[] array) {
Random random = new Random();
for (int i = array.length - 1; i > 0; i--) {
int index = random.nextInt(i + 1);
{
long tmp = array[index];
array[index] = array[i];
array[i] = tmp;
}
}
}
static class ExitException extends RuntimeException {
}
private int iread() {
int res = sc.nextInt();
if (res <= 0) {
throw new ExitException();
}
return res;
}
private void iwrite(char[] chars) {
for (char chr : chars) {
out.print(chr);
}
out.println();
out.flush();
}
private void write(Object obj) {
out.print(obj);
}
private void writeln(Object obj) {
out.println(obj);
}
private void writeln() {
out.println();
}
private void answer(Object ans) {
out.println(ans);
throw new ExitException();
}
private void times(int n, IntConsumer consumer) {
for (int i = 0; i < n; i++) {
try {
consumer.accept(i);
} catch (ExitException ignored) {
}
}
}
private int[] readIntArray(int n) {
int[] res = new int[n];
for (int i = 0; i < n; i++) {
res[i] = sc.nextInt();
}
return res;
}
private long[] readLongArray(int n) {
long[] res = new long[n];
for (int i = 0; i < n; i++) {
res[i] = sc.nextLong();
}
return res;
}
static class FastScanner {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
FastScanner(InputStream stream) {
this.stream = stream;
}
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++];
}
boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
boolean isEndline(int c) {
return c == '\n' || c == '\r' || c == -1;
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String next() {
int c = read();
while (isSpaceChar(c)) c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public String nextLine() {
int c = read();
while (isEndline(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndline(c));
return res.toString();
}
}
private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
private void tr(Object... o) {
if (!oj) System.out.println(Arrays.deepToString(o));
}
}
| Java | ["3\n5\n1 2 3 4 5\n5\n4 4 4 4 2\n6\n1 3 1 5 3 1"] | 1 second | ["-1 -1 3 2 1 \n-1 4 4 4 2 \n-1 -1 1 1 1 1"] | null | Java 11 | standard input | [
"data structures"
] | b7abfb1103bb1796c8f89653c303d7dc | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) — the number of elements in the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,500 | For each test case print $$$n$$$ integers, where the $$$i$$$-th integer is equal to the $$$i$$$-amazing number of the array. | standard output | |
PASSED | e4029f9db683c1007d0bb2dd6a64a9de | train_002.jsonl | 1601219100 | You are given an array $$$a$$$ consisting of $$$n$$$ integers numbered from $$$1$$$ to $$$n$$$.Let's define the $$$k$$$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $$$k$$$ (recall that a subsegment of $$$a$$$ of length $$$k$$$ is a contiguous part of $$$a$$$ containing exactly $$$k$$$ elements). If there is no integer occuring in all subsegments of length $$$k$$$ for some value of $$$k$$$, then the $$$k$$$-amazing number is $$$-1$$$.For each $$$k$$$ from $$$1$$$ to $$$n$$$ calculate the $$$k$$$-amazing number of the array $$$a$$$. | 256 megabytes | import java.util.*;
import java.io.*;
public class C
{
public static void main(String args[]) throws IOException
{
// BufferedReader br = new BufferedReader(new FileReader("input.txt"));
// BufferedWriter bw = new BufferedWriter(new FileWriter("output.txt"));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int t, n, a[], ul, ll, nn, min, p[], f[], i;
String inp[];
TreeMap<Integer, Integer> h;
t = Integer.parseInt(br.readLine());
while(t-->0)
{
n = Integer.parseInt(br.readLine());
inp = br.readLine().split(" ");
a = new int[n];
p = new int[n+1];
f = new int[n+1];
Arrays.fill(p, -1);
h = new TreeMap<>();
for(i = 0; i < n; i++)
{
a[i] = Integer.parseInt(inp[i]);
if(p[a[i]] == -1)
f[a[i]] = p[a[i]] = i;
else
{
f[a[i]] = Math.max(f[a[i]], i - p[a[i]] - 1);
p[a[i]] = i;
}
}
for(i = 1; i <= n; i++)
f[i] = Math.max(f[i], n - 1 - p[i]);
for(i = 1; i <= n; i++)
{
if(h.containsKey(f[i]+1))
h.put(f[i]+1, Math.min(h.get(f[i]+1), i));
else
h.put(f[i]+1, i);
}
for(i = 1, min = Integer.MAX_VALUE; i <= n; i++)
{
if(h.containsKey(i))
min = Math.min(min, h.get(i));
if(min == Integer.MAX_VALUE)
bw.write("-1 ");
else
bw.write(min + " ");
}
bw.write("\n");
}
bw.flush();
}
} | Java | ["3\n5\n1 2 3 4 5\n5\n4 4 4 4 2\n6\n1 3 1 5 3 1"] | 1 second | ["-1 -1 3 2 1 \n-1 4 4 4 2 \n-1 -1 1 1 1 1"] | null | Java 11 | standard input | [
"data structures"
] | b7abfb1103bb1796c8f89653c303d7dc | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) — the number of elements in the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,500 | For each test case print $$$n$$$ integers, where the $$$i$$$-th integer is equal to the $$$i$$$-amazing number of the array. | standard output | |
PASSED | 50f88932666c3d36519ecff4a88c608b | train_002.jsonl | 1601219100 | You are given an array $$$a$$$ consisting of $$$n$$$ integers numbered from $$$1$$$ to $$$n$$$.Let's define the $$$k$$$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $$$k$$$ (recall that a subsegment of $$$a$$$ of length $$$k$$$ is a contiguous part of $$$a$$$ containing exactly $$$k$$$ elements). If there is no integer occuring in all subsegments of length $$$k$$$ for some value of $$$k$$$, then the $$$k$$$-amazing number is $$$-1$$$.For each $$$k$$$ from $$$1$$$ to $$$n$$$ calculate the $$$k$$$-amazing number of the array $$$a$$$. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main
{
public static void main(String args[])throws Exception
{
Reader sc=new Reader();
PrintWriter out=new PrintWriter(System.out);
int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
int arr[]=new int[n];
boolean allsame=true;
for(int i=0;i<n;i++)
arr[i]=sc.nextInt();
for(int i=1;i<n;i++)
{
if(arr[i]!=arr[0])
allsame=false;
}
if(allsame)
{
for(int i=0;i<n;i++)
out.print(arr[0]+" ");
out.println();
continue;
}
int res[]=new int[n+2];
Arrays.fill(res,n+1);
/*if(n%2==0)
{
for(int i=n/2,j=n/2-1;i<=n-1;i++,j--)
res[i]=arr[j];
}
else
{
for(int i=n/2+1,j=n/2-1;i<=n-1;i++,j--)
res[i]=arr[j];
if(n%2!=0)
res[n/2]=arr[n/2];
}
res[n-1]=Math.min(arr[0],arr[n-1]);*/
ArrayList<Integer> list[]=new ArrayList[n+1];
for(int i=1;i<=n;i++)
{
list[i]=new ArrayList<>();
list[i].add(-1);
}
for(int i=0;i<n;i++)
list[arr[i]].add(i);
/*int mx,val=n;
if(n%2==0)
mx=n/2+1;
else
mx=(n+1)/2;*/
for(int i=1;i<=n;i++)
list[i].add(n);
for(int i=1;i<=n;i++)
{
int max=0;
for(int j=1;j<list[i].size();j++)
max=Math.max(max,list[i].get(j)-list[i].get(j-1));
/*if(max<=mx)
{
mx=max;
if(i<val)
val=i;
}*/
res[max]=Math.min(res[max],i);
}
for(int i=1;i<=n;i++)
{
res[i]=Math.min(res[i],res[i-1]);
if(res[i]!=n+1)
out.print(res[i]+" ");
else
out.print("-1 ");
}
out.println();
/*if((n%2==0&&mx==n/2+1)||(n%2!=0&&mx==(n+1)/2))
{
for(int i:res)
out.print(i+" ");
out.println();
}
else
{
for(int i=1;i<=n;i++)
{
if(i<mx)
out.print("-1 ");
else
{
if(res[i-1]!=-1&&val>res[i-1])
val=res[i-1];
out.print(val+" ");
}
}
out.println();
}*/
}
out.flush();
out.close();
}
static class Reader
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1)
{
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.')
{
while ((c = read()) >= '0' && c <= '9')
{
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
} | Java | ["3\n5\n1 2 3 4 5\n5\n4 4 4 4 2\n6\n1 3 1 5 3 1"] | 1 second | ["-1 -1 3 2 1 \n-1 4 4 4 2 \n-1 -1 1 1 1 1"] | null | Java 11 | standard input | [
"data structures"
] | b7abfb1103bb1796c8f89653c303d7dc | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) — the number of elements in the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,500 | For each test case print $$$n$$$ integers, where the $$$i$$$-th integer is equal to the $$$i$$$-amazing number of the array. | standard output | |
PASSED | c5600bcea1b6a35758dc30d37f94bcfd | train_002.jsonl | 1601219100 | You are given an array $$$a$$$ consisting of $$$n$$$ integers numbered from $$$1$$$ to $$$n$$$.Let's define the $$$k$$$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $$$k$$$ (recall that a subsegment of $$$a$$$ of length $$$k$$$ is a contiguous part of $$$a$$$ containing exactly $$$k$$$ elements). If there is no integer occuring in all subsegments of length $$$k$$$ for some value of $$$k$$$, then the $$$k$$$-amazing number is $$$-1$$$.For each $$$k$$$ from $$$1$$$ to $$$n$$$ calculate the $$$k$$$-amazing number of the array $$$a$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
static ArrayList<Integer> adj[];
static int k;
static int[] a;
static int b[];
static int m;
static class Pair implements Comparable<Pair> {
int c;
int d;
public Pair(int b, int l) {
c = b;
d = l;
}
@Override
public int compareTo(Pair o) {
return o.d-this.d;
}
}
static ArrayList<Pair> adjlist[];
// static char c[];
static long mod = (long) (998244353);
static int V;
static long INF = (long) 1E16;
static int n;
static char c[];
static Pair p[];
static long grid[][];
static Scanner sc = new Scanner(System.in);
static PrintWriter out = new PrintWriter(System.out);
public static void main(String args[]) throws Exception {
int t=sc.nextInt();
while(t-->0) {
int n=sc.nextInt();
int a[]=readarray(n);
TreeSet<Integer> set[]=new TreeSet[n+1];
for (int i = 0; i < set.length; i++) {
set[i]=new TreeSet<>();
}
int min=(int) 3e5+1;
for (int i = 0; i < a.length; i++) {
set[a[i]].add(i+1);
min=Math.min(min,a[i]);
}
int ans[]=new int[n+1];
Arrays.fill(ans,(int) 1e8);
HashSet<Integer> checked=new HashSet<>();
for (int i = 0; i < a.length; i++) {
if(checked.contains(a[i]))
continue;
int start=0;
int maxdiff=0;
for(int x:set[a[i]]) {
maxdiff=Math.max(maxdiff,x-start);
start=x;
}
maxdiff=Math.max(maxdiff,n+1-set[a[i]].last());
//System.out.println(maxdiff+" "+a[i]);
ans[maxdiff]=Math.min(a[i],ans[maxdiff]);
checked.add(a[i]);
}
for (int i = 2; i < ans.length; i++) {
ans[i]=Math.min(ans[i-1],ans[i]);
}
for (int i = 1; i < ans.length; i++) {
out.print(ans[i]==1e8?-1+" ":ans[i]+" ");
}
out.println();
}
out.flush();
}
static int dp(int idx) {
if(idx==n) {
return 0;
}
if(div4[idx]!=-1)
return div4[idx];
int ans=0;
boolean larger=false;
boolean smaller=false;
for (int i = idx+1; i < a.length; i++) {
if(a[idx]>=a[i]&&Math.abs(a[idx]-a[i])<=k) {
larger=true;
ans=Math.max(ans,1+dp(i));
}
if(a[idx]<a[i]&&Math.abs(a[idx]-a[i])<=k) {
smaller=true;
ans=Math.max(ans,1+dp(i));
}
if(larger&&smaller)
break;
}
return div4[idx]= ans;
}
static void dfs(int u) {
vis[u]=true;
for(int v:adj[u]) {
if(!vis[v]) {
dfs(v);
}
}
}
static void update(int idx,int val) {
if(idx==0) {
total-=a[0];
if(idx+1<a.length)
total-=Math.max(0,a[idx+1]-a[idx]);
a[0]=val;
total+=a[0];
if(idx+1<a.length)
total+=Math.max(0,a[idx+1]-a[idx]);
return;
}
if(idx>0) {
total-=Math.max(0,a[idx]-a[idx-1]);
}
if(idx+1<a.length) {
total-=Math.max(0,a[idx+1]-a[idx]);
}
a[idx]=val;
if(idx>0) {
total+=Math.max(0,a[idx]-a[idx-1]);
}
if(idx+1<a.length) {
total+=Math.max(0,a[idx+1]-a[idx]);
}
}
static int[] compreessarray(int c[]) {
Stack<Integer> st=new Stack<>();
for (int i = 0; i < c.length; i++) {
if(st.isEmpty()||c[i]!=st.peek())
st.add(c[i]);
}
b=new int[st.size()];
for (int i = b.length-1; i>=0; i--) {
b[i]=st.pop();
}
return b;
}
static int div4[];
static long [] reversearray(long a[]) {
for (int i = 0; i <a.length/2; i++) {
long temp=a[i];
a[i]=a[a.length-i-1];
a[a.length-i-1]=temp;
}
return a;
}
static int [] reversearray(int a[]) {
for (int i = 0; i <=a.length/2; i++) {
int temp=a[i];
a[i]=a[a.length-i-1];
a[a.length-i-1]=temp;
}
return a;
}
static class SegmentTree { // 1-based DS, OOP
int N; //the number of elements in the array as a power of 2 (i.e. after padding)
int[] array, sTree, lazy;
SegmentTree(int[] in)
{
array = in; N = in.length - 1;
sTree = new int[N<<1]; //no. of nodes = 2*N - 1, we add one to cross out index zero
lazy = new int[N<<1];
build(1,1,N);
}
void build(int node, int b, int e) // O(n)
{
if(b == e)
sTree[node] = array[b];
else
{
int mid = b + e >> 1;
build(node<<1,b,mid);
build(node<<1|1,mid+1,e);
sTree[node] = sTree[node<<1]+sTree[node<<1|1];
}
}
void update_point(int index, int val) // O(log n)
{
index += N - 1;
sTree[index] += val;
while(index>1)
{
index >>= 1;
sTree[index] = sTree[index<<1] + sTree[index<<1|1];
}
}
void update_range(int i, int j, int val) // O(log n)
{
update_range(1,1,N,i,j,val);
}
void update_range(int node, int b, int e, int i, int j, int val)
{
if(i > e || j < b)
return;
if(b >= i && e <= j)
{
sTree[node] += (e-b+1)*val;
lazy[node] += val;
}
else
{
int mid = b + e >> 1;
propagate(node, b, mid, e);
update_range(node<<1,b,mid,i,j,val);
update_range(node<<1|1,mid+1,e,i,j,val);
sTree[node] = sTree[node<<1] + sTree[node<<1|1];
}
}
void propagate(int node, int b, int mid, int e)
{
lazy[node<<1] += lazy[node];
lazy[node<<1|1] += lazy[node];
sTree[node<<1] += (mid-b+1)*lazy[node];
sTree[node<<1|1] += (e-mid)*lazy[node];
lazy[node] = 0;
}
int query(int i, int j)
{
return query(1,1,N,i,j);
}
int query(int node, int b, int e, int i, int j) // O(log n)
{
if(i>e || j <b)
return 0;
if(b>= i && e <= j)
return sTree[node];
int mid = b + e >> 1;
propagate(node, b, mid, e);
int q1 = query(node<<1,b,mid,i,j);
int q2 = query(node<<1|1,mid+1,e,i,j);
return q1 + q2;
}
}
static TreeSet<Integer> ts=new TreeSet();
static HashMap<Integer, Integer> compress(int a[]) {
ts = new TreeSet<>();
HashMap<Integer, Integer> hm = new HashMap<>();
for (int x : a)
ts.add(x);
for (int x : ts) {
hm.put(x, hm.size() + 1);
}
return hm;
}
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 ArrayList<Integer> euler=new ArrayList<>();
static ArrayList<Integer> arr;
static long total;
static TreeMap<Integer,Integer> map1;
static int zz;
//static int dp(int idx,int left,int state) {
//if(idx>=k-((zz-left)*2)||idx+1==n) {
// return 0;
//}
//if(memo[idx][left][state]!=-1) {
// return memo[idx][left][state];
//}
//int ans=a[idx+1]+dp(idx+1,left,0);
//if(left>0&&state==0&&idx>0) {
// ans=Math.max(ans,a[idx-1]+dp(idx-1,left-1,1));
//}
//return memo[idx][left][state]=ans;
//}21
static HashMap<Integer,Integer> map;
static int maxa=0;
static int ff=123123;
static long[][] memo;
static long modmod=998244353;
static int dx[]= {1,-1,0,0};
static int dy[]= {0,0,1,-1};
static class BBOOK implements Comparable<BBOOK>{
int t;
int alice;
int bob;
public BBOOK(int x,int y,int z) {
t=x;
alice=y;
bob=z;
}
@Override
public int compareTo(BBOOK o) {
return this.t-o.t;
}
}
private static long lcm(long a2, long b2) {
return (a2*b2)/gcd(a2,b2);
}
static class Edge implements Comparable<Edge>
{
int node;long cost ; long time;
Edge(int a, long b,long c) { node = a; cost = b; time=c; }
public int compareTo(Edge e){ return Long.compare(time,e.time); }
}
static void sieve(int N) // O(N log log N)
{
isComposite = new int[N+1];
isComposite[0] = isComposite[1] = 1; // 0 indicates a prime number
primes = new ArrayList<Integer>();
for (int i = 2; i <= N; ++i) //can loop till i*i <= N if primes array is not needed O(N log log sqrt(N))
if (isComposite[i] == 0) //can loop in 2 and odd integers for slightly better performance
{
primes.add(i);
if(1l * i * i <= N)
for (int j = i * i; j <= N; j += i) // j = i * 2 will not affect performance too much, may alter in modified sieve
isComposite[j] = 1;
}
}
static TreeSet<Integer> factors;
static TreeSet<Integer> primeFactors(int N) // O(sqrt(N) / ln sqrt(N))
{
factors = new TreeSet<Integer>(); //take abs(N) in case of -ve integers
int idx = 0, p = primes.get(idx);
while(1l*p * p <= N)
{
while(N % p == 0) { factors.add(p); N /= p; }
p = primes.get(++idx);
}
if(N != 1) // last prime factor may be > sqrt(N)
factors.add(N); // for integers whose largest prime factor has a power of 1
return factors;
}
static class UnionFind {
int[] p, rank, setSize;
int numSets;
int max[];
public UnionFind(int N) {
p = new int[numSets = N];
rank = new int[N];
setSize = new int[N];
for (int i = 0; i < N; i++) {
p[i] = i;
setSize[i] = 1;
}
}
public int findSet(int i) {
return p[i] == i ? i : (p[i] = findSet(p[i]));
}
public boolean isSameSet(int i, int j) {
return findSet(i) == findSet(j);
}
public int chunion(int i,int j, int x2) {
if (isSameSet(i, j))
return 0;
numSets--;
int x = findSet(i), y = findSet(j);
int z=findSet(x2);
p[x]=z;;
p[y]=z;
return x;
}
public void unionSet(int i, int j) {
if (isSameSet(i, j))
return;
numSets--;
int x = findSet(i), y = findSet(j);
if (rank[x] > rank[y]) {
p[y] = x;
setSize[x] += setSize[y];
} else {
p[x] = y;
setSize[y] += setSize[x];
if (rank[x] == rank[y])
rank[y]++;
}
}
public int numDisjointSets() {
return numSets;
}
public int sizeOfSet(int i) {
return setSize[findSet(i)];
}
}
static class Quad implements Comparable<Quad> {
int u;
int v;
char state;
int turns;
public Quad(int i, int j, char c, int k) {
u = i;
v = j;
state = c;
turns = k;
}
public int compareTo(Quad e) {
return (int) (turns - e.turns);
}
}
static long manhatandistance(long x, long x2, long y, long y2) {
return Math.abs(x - x2) + Math.abs(y - y2);
}
static long fib[];
static long fib(int n) {
if (n == 1 || n == 0) {
return 1;
}
if (fib[n] != -1) {
return fib[n];
} else
return fib[n] = ((fib(n - 2) % mod + fib(n - 1) % mod) % mod);
}
static class Point implements Comparable<Point>{
long x, y;
Point(long counth, long counts) {
x = counth;
y = counts;
}
@Override
public int compareTo(Point p )
{
return Long.compare(p.y*1l*x, p.x*1l*y);
}
}
static TreeSet<Long> primeFactors(long N) // O(sqrt(N) / ln sqrt(N))
{
TreeSet<Long> factors = new TreeSet<Long>(); // take abs(N) in case of -ve integers
int idx = 0, p = primes.get(idx);
while (p * p <= N) {
while (N % p == 0) {
factors.add((long) p);
N /= p;
}
if (primes.size() > idx + 1)
p = primes.get(++idx);
else
break;
}
if (N != 1) // last prime factor may be > sqrt(N)
factors.add(N); // for integers whose largest prime factor has a power of 1
return factors;
}
static boolean visited[];
/**
* static int bfs(int s) { Queue<Integer> q = new LinkedList<Integer>();
* q.add(s); int count=0; int maxcost=0; int dist[]=new int[n]; dist[s]=0;
* while(!q.isEmpty()) {
*
* int u = q.remove(); if(dist[u]==k) { break; } for(Pair v: adj[u]) {
* maxcost=Math.max(maxcost, v.cost);
*
*
*
* if(!visited[v.v]) {
*
* visited[v.v]=true; q.add(v.v); dist[v.v]=dist[u]+1; maxcost=Math.max(maxcost,
* v.cost); } }
*
* } return maxcost; }
**/
static boolean[] vis2;
static boolean f2 = false;
static long[][] matMul(long[][] a2, long[][] b, int p, int q, int r) // C(p x r) = A(p x q) x (q x r) -- O(p x q x
// r)
{
long[][] C = new long[p][r];
for (int i = 0; i < p; ++i) {
for (int j = 0; j < r; ++j) {
for (int k = 0; k < q; ++k) {
C[i][j] = (C[i][j] + (a2[i][k] % mod * b[k][j] % mod)) % mod;
C[i][j] %= mod;
}
}
}
return C;
}
public static int[] schuffle(int[] a2) {
for (int i = 0; i < a2.length; i++) {
int x = (int) (Math.random() * a2.length);
int temp = a2[x];
a2[x] = a2[i];
a2[i] = temp;
}
return a2;
}
static boolean vis[];
static HashSet<Integer> set = new HashSet<Integer>();
static long modPow(long ways, long count, long mod) // O(log e)
{
ways %= mod;
long res = 1;
while (count > 0) {
if ((count & 1) == 1)
res = (res * ways) % mod;
ways = (ways * ways) % mod;
count >>= 1;
}
return res % mod;
}
static long gcd(long l, long o) {
if (o == 0) {
return l;
}
return gcd(o, l % o);
}
static int[] isComposite;
static int[] valid;
static ArrayList<Integer> primes;
static ArrayList<Integer> l1;
static TreeSet<Integer> primus = new TreeSet<Integer>();
static void sieveLinear(int N)
{
int[] lp = new int[N + 1]; //lp[i] = least prime divisor of i
for(int i = 2; i <= N; ++i)
{
if(lp[i] == 0)
{
primus.add(i);
lp[i] = i;
}
int curLP = lp[i];
for(int p: primus)
if(p > curLP || p * i > N)
break;
else
lp[p * i] = i;
}
}
public static long[] schuffle(long[] a2) {
for (int i = 0; i < a2.length; i++) {
int x = (int) (Math.random() * a2.length);
long temp = a2[x];
a2[x] = a2[i];
a2[i] = temp;
}
return a2;
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream system) {
br = new BufferedReader(new InputStreamReader(system));
}
public Scanner(String file) throws Exception {
br = new BufferedReader(new FileReader(file));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public String nextLine() throws IOException {
return br.readLine();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public char nextChar() throws IOException {
return next().charAt(0);
}
public Long nextLong() throws IOException {
return Long.parseLong(next());
}
public boolean ready() throws IOException {
return br.ready();
}
public void waitForInput() throws InterruptedException {
Thread.sleep(3000);
}
public int[] nxtArr(int n) throws IOException {
int[] ans = new int[n];
for (int i = 0; i < n; i++)
ans[i] = nextInt();
return ans;
}
}
public static int[] sortarray(int a[]) {
schuffle(a);
Arrays.sort(a);
return a;
}
public static long[] sortarray(long a[]) {
schuffle(a);
Arrays.sort(a);
return a;
}
public static int[] readarray(int n) throws IOException {
int a[]=new int[n];
for (int i = 0; i < a.length; i++) {
a[i]=sc.nextInt();
}
return a;
}
public static long[] readlarray(int n) throws IOException {
long a[]=new long[n];
for (int i = 0; i < a.length; i++) {
a[i]=sc.nextLong();
}
return a;
}
} | Java | ["3\n5\n1 2 3 4 5\n5\n4 4 4 4 2\n6\n1 3 1 5 3 1"] | 1 second | ["-1 -1 3 2 1 \n-1 4 4 4 2 \n-1 -1 1 1 1 1"] | null | Java 11 | standard input | [
"data structures"
] | b7abfb1103bb1796c8f89653c303d7dc | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) — the number of elements in the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,500 | For each test case print $$$n$$$ integers, where the $$$i$$$-th integer is equal to the $$$i$$$-amazing number of the array. | standard output | |
PASSED | 1e686092fda0cd9d2ed1bfde13a05755 | train_002.jsonl | 1601219100 | You are given an array $$$a$$$ consisting of $$$n$$$ integers numbered from $$$1$$$ to $$$n$$$.Let's define the $$$k$$$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $$$k$$$ (recall that a subsegment of $$$a$$$ of length $$$k$$$ is a contiguous part of $$$a$$$ containing exactly $$$k$$$ elements). If there is no integer occuring in all subsegments of length $$$k$$$ for some value of $$$k$$$, then the $$$k$$$-amazing number is $$$-1$$$.For each $$$k$$$ from $$$1$$$ to $$$n$$$ calculate the $$$k$$$-amazing number of the array $$$a$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class d2prac implements Runnable
{
private boolean console=false;
public void solve()
{
int i; int n=in.ni(); int a[]=new int[n];
ArrayList<Integer> ans[]=new ArrayList[n];
for(i=0;i<n;i++) ans[i]=new ArrayList();
for(i=0;i<n;i++)
{
a[i]=in.ni()-1; ans[a[i]].add(i);
}
int val[]=new int[n];
for(i=0;i<n;i++)
{
if(ans[i].isEmpty()) continue;
int need=ans[i].get(0);
for(int j=1;j<ans[i].size();j++)
need=Math.max(need, ans[i].get(j)-ans[i].get(j-1)-1);
need=Math.max(n-1-ans[i].get(ans[i].size()-1), need);
for(int j=need;j<n;j++)
{
if(val[j]!=0) break;
val[j]=i+1;
}
}
for(int v:val)
{
v= (v==0?-1:v);
out.print(v+" ");
}
out.println();
}
@Override
public void run() {
try { init(); }
catch (FileNotFoundException e) { e.printStackTrace(); }
int t= in.ni();
while (t-->0) {
solve();
out.flush(); }
}
private FastInput in; private PrintWriter out;
public static void main(String[] args) throws Exception { new d2prac().run(); }
private void init() throws FileNotFoundException {
InputStream inputStream = System.in; OutputStream outputStream = System.out;
try { if (!console && System.getProperty("user.name").equals("sachan")) {
outputStream = new FileOutputStream("/home/sachan/Desktop/output.txt");
inputStream = new FileInputStream("/home/sachan/Desktop/input.txt"); }
} catch (Exception ignored) { }
out = new PrintWriter(outputStream); in = new FastInput(inputStream);
}
static class FastInput { InputStream obj;
public FastInput(InputStream obj) { this.obj = obj; }
byte inbuffer[] = new byte[1024]; int lenbuffer = 0, ptrbuffer = 0;
int readByte() { if (lenbuffer == -1) throw new InputMismatchException();
if (ptrbuffer >= lenbuffer) { ptrbuffer = 0;
try { lenbuffer = obj.read(inbuffer); }
catch (IOException e) { throw new InputMismatchException(); } }
if (lenbuffer <= 0) return -1;return inbuffer[ptrbuffer++]; }
String ns() { int b = skip();StringBuilder sb = new StringBuilder();
while (!(isSpaceChar(b))) { sb.appendCodePoint(b);b = readByte(); }return sb.toString();}
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(); }}
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 * 10L + (b - '0'); } else {
return minus ? -num : num; }b = readByte(); } }
boolean isSpaceChar(int c) { return (!(c >= 33 && c <= 126)); }
int skip() { int b;while ((b = readByte()) != -1 && isSpaceChar(b)) ;return b; }
float nf() {return Float.parseFloat(ns());}
double nd() {return Double.parseDouble(ns());}
char nc() {return (char) skip();}
}
}
| Java | ["3\n5\n1 2 3 4 5\n5\n4 4 4 4 2\n6\n1 3 1 5 3 1"] | 1 second | ["-1 -1 3 2 1 \n-1 4 4 4 2 \n-1 -1 1 1 1 1"] | null | Java 11 | standard input | [
"data structures"
] | b7abfb1103bb1796c8f89653c303d7dc | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) — the number of elements in the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,500 | For each test case print $$$n$$$ integers, where the $$$i$$$-th integer is equal to the $$$i$$$-amazing number of the array. | standard output | |
PASSED | aadd5d89ac99fa21302459d0cbda501d | train_002.jsonl | 1601219100 | You are given an array $$$a$$$ consisting of $$$n$$$ integers numbered from $$$1$$$ to $$$n$$$.Let's define the $$$k$$$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $$$k$$$ (recall that a subsegment of $$$a$$$ of length $$$k$$$ is a contiguous part of $$$a$$$ containing exactly $$$k$$$ elements). If there is no integer occuring in all subsegments of length $$$k$$$ for some value of $$$k$$$, then the $$$k$$$-amazing number is $$$-1$$$.For each $$$k$$$ from $$$1$$$ to $$$n$$$ calculate the $$$k$$$-amazing number of the array $$$a$$$. | 256 megabytes | import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.io.*;
import java.math.*;
public class Main7{
static public void main(String args[])throws IOException{
int tt=i();
StringBuilder sb=new StringBuilder();
for(int ttt=1;ttt<=tt;ttt++){
int n=i();
int[] a=new int[n];
int[] count=new int[n+1];
for(int i=0;i<n;i++){
a[i]=i();
}
int[] flag=new int[n+1];
for(int i=0;i<n;i++){
if(count[a[i]]==0){
count[a[i]]=i+1;
flag[a[i]]=count[a[i]];
}else{
flag[a[i]]=Math.max(flag[a[i]],i+1-count[a[i]]);
count[a[i]]=i+1;
}
}
for(int i=0;i<n;i++){
flag[a[i]]=Math.max(flag[a[i]],n-count[a[i]]+1);
}
int[] ans=new int[n+1];
for(int i=1;i<=n;i++){
int index=flag[i];
if(index==0){
continue;
}
for(int j=index;j<=n;j++){
if(ans[j]!=0){
break;
}
ans[j]=i;
}
}
for(int i=1;i<=n;i++){
if(ans[i]==0){
sb.append("-1 ");
}else
sb.append(ans[i]+" ");
}
sb.append("\n");
}
System.out.print(sb.toString());
}
static InputReader in=new InputReader(System.in);
static OutputWriter out=new OutputWriter(System.out);
static ArrayList<ArrayList<Integer>> graph;
static int mod=1000000007;
static class Pair{
int x;
int y;
Pair(int x,int y){
this.x=x;
this.y=y;
}
/*@Override
public int hashCode()
{
final int temp = 14;
int ans = 1;
ans =x*31+y*13;
return (int)ans;
}
@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null) {
return false;
}
if (this.getClass() != o.getClass()) {
return false;
}
Pair other = (Pair)o;
if (this.x != other.x || this.y!=other.y) {
return false;
}
return true;
}*/
}
public static int[] sort(int[] a){
int n=a.length;
ArrayList<Integer> ar=new ArrayList<>();
for(int i=0;i<a.length;i++){
ar.add(a[i]);
}
Collections.sort(ar);
for(int i=0;i<n;i++){
a[i]=ar.get(i);
}
return a;
}
public static long pow(long a, long b){
long result=1;
while(b>0){
if (b % 2 != 0){
result=(result*a);
b--;
}
a=(a*a);
b /= 2;
}
return result;
}
public static long gcd(long a, long b){
if (a == 0){
return b;
}
return gcd(b%a, a);
}
public static long lcm(long a, long b){
return a*(b/gcd(a,b));
}
public static long l(){
String s=in.String();
return Long.parseLong(s);
}
public static void pln(String value){
System.out.println(value);
}
public static int i(){
return in.Int();
}
public static String s(){
return in.String();
}
}
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 Int() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public String String() {
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 String();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object...objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
public void printLine(Object...objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
public void flush() {
writer.flush();
}
}
class IOUtils {
public static int[] readIntArray(InputReader in, int size) {
int[] array = new int[size];
for (int i = 0; i < size; i++)
array[i] = in.Int();
return array;
}
}
| Java | ["3\n5\n1 2 3 4 5\n5\n4 4 4 4 2\n6\n1 3 1 5 3 1"] | 1 second | ["-1 -1 3 2 1 \n-1 4 4 4 2 \n-1 -1 1 1 1 1"] | null | Java 11 | standard input | [
"data structures"
] | b7abfb1103bb1796c8f89653c303d7dc | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) — the number of elements in the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,500 | For each test case print $$$n$$$ integers, where the $$$i$$$-th integer is equal to the $$$i$$$-amazing number of the array. | standard output | |
PASSED | c9121dbdbb8edf880a0cbe1c1e530a62 | train_002.jsonl | 1601219100 | You are given an array $$$a$$$ consisting of $$$n$$$ integers numbered from $$$1$$$ to $$$n$$$.Let's define the $$$k$$$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $$$k$$$ (recall that a subsegment of $$$a$$$ of length $$$k$$$ is a contiguous part of $$$a$$$ containing exactly $$$k$$$ elements). If there is no integer occuring in all subsegments of length $$$k$$$ for some value of $$$k$$$, then the $$$k$$$-amazing number is $$$-1$$$.For each $$$k$$$ from $$$1$$$ to $$$n$$$ calculate the $$$k$$$-amazing number of the array $$$a$$$. | 256 megabytes | import java.util.*;
public class C {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int testCases = sc.nextInt();
StringBuilder sb = new StringBuilder();
for (int t = 0; t < testCases; t++) {
int n = sc.nextInt();
int arr[] = new int[n];
Map<Integer, ArrayList<Integer>> map = new HashMap<>();
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
ArrayList<Integer> al = map.getOrDefault(arr[i], new ArrayList<>());
al.add(i);
map.put(arr[i], al);
}
int ans[] = new int[n + 1];
int MAX_VAL = Integer.MAX_VALUE;
Arrays.fill(ans, MAX_VAL);
boolean vis[] = new boolean[n + 1];
for (int i = 0; i < n; i++) {
if (vis[i])
continue;
vis[i] = true;
int cur = arr[i];
ArrayList<Integer> cur_list = map.get(cur);
int prev = -1;
int max = Integer.MIN_VALUE;
for (int index : cur_list) {
vis[index] = true;
max = Math.max(max, index - prev);
prev = index;
}
max = Math.max(max, n - prev);
ans[max] = Math.min(ans[max], cur);
}
boolean firstTime = true;
for (int i = 1; i < n + 1; i++) {
if (ans[i] == MAX_VAL && firstTime) {
ans[i] = -1;
continue;
}
firstTime = false;
if (ans[i - 1] != -1 && ans[i - 1] != 0 && arr[i - 1] != MAX_VAL) {
ans[i] = Math.min(ans[i], ans[i - 1]);
}
}
for (int i = 1; i < n + 1; i++) {
sb.append(ans[i] + " ");
}
sb.append("\n");
}
System.out.print(sb);
}
} | Java | ["3\n5\n1 2 3 4 5\n5\n4 4 4 4 2\n6\n1 3 1 5 3 1"] | 1 second | ["-1 -1 3 2 1 \n-1 4 4 4 2 \n-1 -1 1 1 1 1"] | null | Java 11 | standard input | [
"data structures"
] | b7abfb1103bb1796c8f89653c303d7dc | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) — the number of elements in the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,500 | For each test case print $$$n$$$ integers, where the $$$i$$$-th integer is equal to the $$$i$$$-amazing number of the array. | standard output | |
PASSED | 04f91460c49eda5b2dcb3cc53da17596 | train_002.jsonl | 1601219100 | You are given an array $$$a$$$ consisting of $$$n$$$ integers numbered from $$$1$$$ to $$$n$$$.Let's define the $$$k$$$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $$$k$$$ (recall that a subsegment of $$$a$$$ of length $$$k$$$ is a contiguous part of $$$a$$$ containing exactly $$$k$$$ elements). If there is no integer occuring in all subsegments of length $$$k$$$ for some value of $$$k$$$, then the $$$k$$$-amazing number is $$$-1$$$.For each $$$k$$$ from $$$1$$$ to $$$n$$$ calculate the $$$k$$$-amazing number of the array $$$a$$$. | 256 megabytes | import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
public class Solution {
public static void main(String[] args){
new Thread(null, null, "Anshum Gupta", 99999999) {
public void run() {
try {
solve();
} catch(Exception e) {
e.printStackTrace();
System.exit(1);
}
}
}.start();
}
static final long mxx = (long)(1e18 + 5);
static final int mxN = (int)(1e6);
static final int mxV = (int)(1e6 + 5), log = 18;
static long mod = (long)(1e9+7);
static final int INF = (int)1e9;
static boolean[]vis;
static ArrayList<ArrayList<Integer>> adj;
static int n, m, k, q, cnt = 0;
static char[]str;
public static void solve() throws Exception {
// solve the problem here
s = new MyScanner();
out = new PrintWriter(new BufferedOutputStream(System.out), true);
// out = new PrintWriter("output.txt");
int tc = s.nextInt();
for(int i=1; i<=tc; i++) {
// out.print("Case #" + i + ": ");
testcase();
}
out.flush();
out.close();
}
static void testcase() {
n = s.nextInt();
int[] a = new int[n], ans = new int[n + 1];
Arrays.fill(ans, -1);
int next = n;
ArrayList<Integer>[] where = new ArrayList[n+1];
for(int i = 0; i < n; i++) {
where[i] = new ArrayList<Integer>();
}
for(int i = 0; i < n; i++) {
a[i] = s.nextInt() - 1;
where[a[i]].add(i);
}
for(int i = 0; i < n; i++) {
where[i].add(n);
int distance = -1, prev = -1;
for(int j = 0; j < where[i].size(); j++) {
distance = Math.max(distance, where[i].get(j) - prev);
prev = where[i].get(j);
}
while(distance <= next) {
ans[next--] = i + 1;
}
}
for(int i = 1; i <= n; i++) out.append(ans[i] + " ");
out.append("\n");
}
public static PrintWriter out;
public static MyScanner s;
static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public MyScanner(String fileName) {
try {
br = new BufferedReader(new FileReader(fileName));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
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()); }
int[] nextIntArray(int n){
int[]a = new int[n];
for(int i=0; i<n; i++) {
a[i] = this.nextInt();
}
return a;
}
long[] nextlongArray(int n) {
long[]a = new long[n];
for(int i=0; i<n; i++) {
a[i] = this.nextLong();
}
return a;
}
Integer[] nextIntegerArray(int n){
Integer[]a = new Integer[n];
for(int i=0; i<n; i++) {
a[i] = this.nextInt();
}
return a;
}
Long[] nextLongArray(int n) {
Long[]a = new Long[n];
for(int i=0; i<n; i++) {
a[i] = this.nextLong();
}
return a;
}
char[][] next2DCharArray(int n, int m){
char[][]arr = new char[n][m];
for(int i=0; i<n; i++) {
arr[i] = this.next().toCharArray();
}
return arr;
}
ArrayList<ArrayList<Integer>> readUndirectedUnweightedGraph(int n, int m) {
ArrayList<ArrayList<Integer>>adj = new ArrayList<ArrayList<Integer>>();
for(int i=0; i<=n; i++)adj.add(new ArrayList<Integer>());
for(int i=0; i<m; i++) {
int u = s.nextInt();
int v = s.nextInt();
adj.get(u).add(v);
adj.get(v).add(u);
}
return adj;
}
ArrayList<ArrayList<Integer>> readDirectedUnweightedGraph(int n, int m) {
ArrayList<ArrayList<Integer>>adj = new ArrayList<ArrayList<Integer>>();
for(int i=0; i<=n; i++)adj.add(new ArrayList<Integer>());
for(int i=0; i<m; i++) {
int u = s.nextInt();
int v = s.nextInt();
adj.get(u).add(v);
}
return adj;
}
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
} | Java | ["3\n5\n1 2 3 4 5\n5\n4 4 4 4 2\n6\n1 3 1 5 3 1"] | 1 second | ["-1 -1 3 2 1 \n-1 4 4 4 2 \n-1 -1 1 1 1 1"] | null | Java 11 | standard input | [
"data structures"
] | b7abfb1103bb1796c8f89653c303d7dc | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) — the number of elements in the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,500 | For each test case print $$$n$$$ integers, where the $$$i$$$-th integer is equal to the $$$i$$$-amazing number of the array. | standard output | |
PASSED | 85650c7ff5874b193712a9fd362e2fc5 | train_002.jsonl | 1601219100 | You are given an array $$$a$$$ consisting of $$$n$$$ integers numbered from $$$1$$$ to $$$n$$$.Let's define the $$$k$$$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $$$k$$$ (recall that a subsegment of $$$a$$$ of length $$$k$$$ is a contiguous part of $$$a$$$ containing exactly $$$k$$$ elements). If there is no integer occuring in all subsegments of length $$$k$$$ for some value of $$$k$$$, then the $$$k$$$-amazing number is $$$-1$$$.For each $$$k$$$ from $$$1$$$ to $$$n$$$ calculate the $$$k$$$-amazing number of the array $$$a$$$. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author sofiane
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
static class TaskA {
public void solve(int testNumber, Scanner in, PrintWriter out) {
int t = in.nextInt();
while (t-- > 0) {
int n = in.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = in.nextInt();
}
int[] last_number_id = new int[n + 1];
Arrays.fill(last_number_id, -1);
int[] max_d = new int[n + 1];
Arrays.fill(max_d, -1);
for (int i = 0; i < n; i++) {
max_d[a[i]] = Math.max(max_d[a[i]], i - last_number_id[a[i]]);
last_number_id[a[i]] = i;
}
for (int i = 1; i <= n; i++) {
max_d[i] = Math.max(max_d[i], n - last_number_id[i]);
}
int[] ans = new int[n + 1];
int mn = n + 1;
// out.println("==========");
// for(int i = 0; i<= n;i++){
// out.printf("%d ", max_d[i]);
// }
// out.println("=============");
for (int i = 1; i <= n; i++) {
if (max_d[i] < mn) {
ans[max_d[i]] = i;
mn = max_d[i];
}
}
int ans_ = n + 1;
for (int i = 1; i <= n; i++) {
if (i != 1) out.printf(" ");
// out.printf("//%d", ans[i]);
if (ans[i] != n + 1 && ans[i] != 0)
ans_ = ans[i];
if (ans_ != n + 1)
out.printf("%d", ans_);
else out.printf("-1");
}
out.printf("\n");
}
}
}
}
| Java | ["3\n5\n1 2 3 4 5\n5\n4 4 4 4 2\n6\n1 3 1 5 3 1"] | 1 second | ["-1 -1 3 2 1 \n-1 4 4 4 2 \n-1 -1 1 1 1 1"] | null | Java 11 | standard input | [
"data structures"
] | b7abfb1103bb1796c8f89653c303d7dc | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) — the number of elements in the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,500 | For each test case print $$$n$$$ integers, where the $$$i$$$-th integer is equal to the $$$i$$$-amazing number of the array. | standard output | |
PASSED | c5517cd54a1d1b59d6a7d7b27d4d45fe | train_002.jsonl | 1601219100 | You are given an array $$$a$$$ consisting of $$$n$$$ integers numbered from $$$1$$$ to $$$n$$$.Let's define the $$$k$$$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $$$k$$$ (recall that a subsegment of $$$a$$$ of length $$$k$$$ is a contiguous part of $$$a$$$ containing exactly $$$k$$$ elements). If there is no integer occuring in all subsegments of length $$$k$$$ for some value of $$$k$$$, then the $$$k$$$-amazing number is $$$-1$$$.For each $$$k$$$ from $$$1$$$ to $$$n$$$ calculate the $$$k$$$-amazing number of the array $$$a$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class A
{
static int n;
static int[] arr;
static char[] s;
public static void main(String[] args) throws IOException
{
Flash f = new Flash();
int T = f.ni();
for(int tc = 1; tc <= T; tc++){
n = f.ni(); arr = f.arr(n);
fn();
}
}
static void fn()
{
int[] ans = new int[n+1];
Arrays.fill(ans, (int)1e6);
HashMap<Integer, List<Integer>> map = new HashMap<>();
for(int i = 0; i < n; i++){
map.computeIfAbsent(arr[i], k->new ArrayList<>());
map.get(arr[i]).add(i);
}
for(int k : map.keySet()){
List<Integer> A = map.get(k);
int dist = 0;
for(int i = 1; i < A.size(); i++){
dist = Math.max(dist, A.get(i)-A.get(i-1));
}
dist = Math.max(dist, Math.max(A.get(0)+1, n-A.get(A.size()-1) ));
ans[dist] = Math.min(ans[dist], k);
}
for(int i = 1; i <= n; i++){
ans[i] = Math.min(ans[i], ans[i-1]);
}
for(int i = 1; i <= n; i++){
if(ans[i] == (int)1e6) ans[i] = -1;
}
StringBuilder sb = new StringBuilder();
for(int i = 1; i <= n; i++) sb.append(ans[i] + " ");
System.out.println(sb);
}
static void sort(int[] a){
List<Integer> A = new ArrayList<>();
for(int i : a) A.add(i);
Collections.sort(A);
for(int i = 0; i < A.size(); i++) a[i] = A.get(i);
}
static int swap(int itself, int dummy){
return itself;
}
static void print(int[] a){
StringBuilder sb = new StringBuilder();
for(int i : a) sb.append(i + " ");
System.out.println(sb);
}
//SecondThread
static class Flash
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next(){
while(!st.hasMoreTokens()){
try{
st = new StringTokenizer(br.readLine());
}catch(IOException e){
e.printStackTrace();
}
}
return st.nextToken();
}
String nextLine(){
String s = new String();
try{
s = br.readLine().trim();
}catch(IOException e){
e.printStackTrace();
}
return s;
}
int ni(){
return Integer.parseInt(next());
}
int[] arr(int n){
int[] a = new int[n];
for(int i = 0; i < n; i++) a[i] = ni();
return a;
}
long nl(){
return Long.parseLong(next());
}
}
} | Java | ["3\n5\n1 2 3 4 5\n5\n4 4 4 4 2\n6\n1 3 1 5 3 1"] | 1 second | ["-1 -1 3 2 1 \n-1 4 4 4 2 \n-1 -1 1 1 1 1"] | null | Java 11 | standard input | [
"data structures"
] | b7abfb1103bb1796c8f89653c303d7dc | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) — the number of elements in the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,500 | For each test case print $$$n$$$ integers, where the $$$i$$$-th integer is equal to the $$$i$$$-amazing number of the array. | standard output | |
PASSED | d4a3f5dfb25f2fdf3283a2a0f4819599 | train_002.jsonl | 1601219100 | You are given an array $$$a$$$ consisting of $$$n$$$ integers numbered from $$$1$$$ to $$$n$$$.Let's define the $$$k$$$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $$$k$$$ (recall that a subsegment of $$$a$$$ of length $$$k$$$ is a contiguous part of $$$a$$$ containing exactly $$$k$$$ elements). If there is no integer occuring in all subsegments of length $$$k$$$ for some value of $$$k$$$, then the $$$k$$$-amazing number is $$$-1$$$.For each $$$k$$$ from $$$1$$$ to $$$n$$$ calculate the $$$k$$$-amazing number of the array $$$a$$$. | 256 megabytes | // package cp;
import java.util.*;
import java.io.*;
import java.math.*;
public class Cp_2 {
BigInteger bi1=new BigInteger("2");//initialize as string
// 1.BigInteger bi=new BigInteger(Readers.next());- take input as biginteger
StringBuilder sb=new StringBuilder();
// 2.StringBuilder temp=new StringBuilder(str[i-1]);
// 3.String rev=temp.reverse().toString(); convert sb to string
// 4.if(str[i].compareTo(rev)>=0)minn=0;-compare two Strings
// 5.(Initialize as string) - (a.add(b)) - (array initialized with null and not 0)
Integer[] ARRE=new Integer[5];//Integer sort-TLE-Initialize object elements i.e a[0].
static final int mod1 = 1000000007;//or 1e9+7
// 6.System.exit(0); to exit from code....esp in recur
long gcd(long a,long b) {if(b==0)return a;else return gcd(b,a%b);}
long ceil(double d) {return (long)Math.ceil(1.0*d);}
int ch_int(char c) {return Integer.parseInt(String.valueOf(c));}//change char to Integer
String ch_str(char c) {return String.valueOf(c);}
String int_str(int num) {return Integer.toString(num);}
void divisor(long n,int start) {
int cnt=0;for(int i=start;i<=Math.sqrt(n);i++) {
if(n%i==0) {if(i==n/i)cnt++;else cnt+=2;}}}
static class pair{
int fir;
int sec;
pair(int _fir, int _sec){
fir=_fir;
sec=_sec;
}
}
public static void main(String[] args) throws IOException {
PrintWriter out = new PrintWriter(System.out);
Readers.init(System.in);
Cp_2 obj=new Cp_2();
int t=Readers.nextInt();
while(t-->0) {
int n=Readers.nextInt();
Integer[] a=new Integer[n];
for (int i = 0; i < a.length; i++) {
a[i]=Readers.nextInt();
}
// prev , maxx
HashMap<Integer,pair> map=new HashMap<>();
for (int i = 0; i < a.length; i++) {
if(map.get(a[i])==null) {
map.put(a[i],new pair(i,i+1));
}
else {
map.put(a[i], new pair(i,Math.max(map.get(a[i]).sec, i-map.get(a[i]).fir)));
}
}
for (int i = 0; i < a.length; i++) {
map.put(a[i], new pair(n,Math.max(map.get(a[i]).sec, n-map.get(a[i]).fir)));
}
int min=Integer.MAX_VALUE;
int num=0;
for (int i = 0; i < a.length; i++) {
if(map.get(a[i]).sec<min) {
min=map.get(a[i]).sec;
num=a[i];
}
}
Arrays.sort(a);
int[] ans=new int[n];
int ind_minn=n+1;
for (int i = 0; i < a.length; i++) {
if(map.get(a[i]).sec<ind_minn+1) {
ind_minn=map.get(a[i]).sec-1;
ans[ind_minn]=a[i];
}
}
int flag=0;
for (int i = 0; i < ans.length; i++) {
if(ans[i]==0 && flag==0) {
flag=1;
ans[i]=-1;
}
else if(ans[i]==0 && flag==1){
ans[i]=ans[i-1];
}
else flag=1;
}
for (int i = 0; i < ans.length; i++) {
out.print(ans[i]+" ");
}
out.println();
}
out.flush();
}
}
class Readers {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(new InputStreamReader(input));
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while ( ! tokenizer.hasMoreTokens() ) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt( next() );
}
static double nextDouble() throws IOException {
return Double.parseDouble( next() );
}
static long nextLong() throws IOException{
return Long.parseLong(next());
}
} | Java | ["3\n5\n1 2 3 4 5\n5\n4 4 4 4 2\n6\n1 3 1 5 3 1"] | 1 second | ["-1 -1 3 2 1 \n-1 4 4 4 2 \n-1 -1 1 1 1 1"] | null | Java 11 | standard input | [
"data structures"
] | b7abfb1103bb1796c8f89653c303d7dc | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) — the number of elements in the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,500 | For each test case print $$$n$$$ integers, where the $$$i$$$-th integer is equal to the $$$i$$$-amazing number of the array. | standard output | |
PASSED | c93d5e5da31c047487583cc37e26c365 | train_002.jsonl | 1601219100 | You are given an array $$$a$$$ consisting of $$$n$$$ integers numbered from $$$1$$$ to $$$n$$$.Let's define the $$$k$$$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $$$k$$$ (recall that a subsegment of $$$a$$$ of length $$$k$$$ is a contiguous part of $$$a$$$ containing exactly $$$k$$$ elements). If there is no integer occuring in all subsegments of length $$$k$$$ for some value of $$$k$$$, then the $$$k$$$-amazing number is $$$-1$$$.For each $$$k$$$ from $$$1$$$ to $$$n$$$ calculate the $$$k$$$-amazing number of the array $$$a$$$. | 256 megabytes | // package cp;
import java.util.*;
import java.io.*;
import java.math.*;
public class Cp_2 {
BigInteger bi1=new BigInteger("2");//initialize as string
// 1.BigInteger bi=new BigInteger(Readers.next());- take input as biginteger
StringBuilder sb=new StringBuilder();
// 2.StringBuilder temp=new StringBuilder(str[i-1]);
// 3.String rev=temp.reverse().toString(); convert sb to string
// 4.if(str[i].compareTo(rev)>=0)minn=0;-compare two Strings
// 5.(Initialize as string) - (a.add(b)) - (array initialized with null and not 0)
Integer[] ARRE=new Integer[5];//Integer sort-TLE-Initialize object elements i.e a[0].
static final int mod1 = 1000000007;//or 1e9+7
// 6.System.exit(0); to exit from code....esp in recur
long gcd(long a,long b) {if(b==0)return a;else return gcd(b,a%b);}
long ceil(double d) {return (long)Math.ceil(1.0*d);}
int ch_int(char c) {return Integer.parseInt(String.valueOf(c));}//change char to Integer
String ch_str(char c) {return String.valueOf(c);}
String int_str(int num) {return Integer.toString(num);}
void divisor(long n,int start) {
int cnt=0;for(int i=start;i<=Math.sqrt(n);i++) {
if(n%i==0) {if(i==n/i)cnt++;else cnt+=2;}}}
static class pair{
int fir;
int sec;
pair(int _fir, int _sec){
fir=_fir;
sec=_sec;
}
}
public static void main(String[] args) throws IOException {
PrintWriter out = new PrintWriter(System.out);
Readers.init(System.in);
Cp_2 obj=new Cp_2();
int t=Readers.nextInt();
while(t-->0) {
int n=Readers.nextInt();
Integer[] a=new Integer[n];
for (int i = 0; i < a.length; i++) {
a[i]=Readers.nextInt();
}
// prev , maxx
HashMap<Integer,pair> map=new HashMap<>();
for (int i = 0; i < a.length; i++) {
if(map.get(a[i])==null) {
map.put(a[i],new pair(i,i+1));
}
else {
map.put(a[i], new pair(i,Math.max(map.get(a[i]).sec, i-map.get(a[i]).fir)));
}
}
for (int i = 0; i < a.length; i++) {
map.put(a[i], new pair(n,Math.max(map.get(a[i]).sec, n-map.get(a[i]).fir)));
}
// for(int he:map.keySet()) {
// System.out.println(he+" map"+map.get(he).sec);
// }
int min=Integer.MAX_VALUE;
int num=0;
for (int i = 0; i < a.length; i++) {
// min=Math.min(min, map.get(a[i]).sec);
if(map.get(a[i]).sec<min) {
min=map.get(a[i]).sec;
num=a[i];
}
}
Arrays.sort(a);
int[] ans=new int[n];
int ind_minn=n+1;
for (int i = 0; i < a.length; i++) {
// if(map.get(a[i]).sec==n)continue;
if(map.get(a[i]).sec<ind_minn+1) {
ind_minn=map.get(a[i]).sec-1;
ans[ind_minn]=a[i];
}
else {
// ans[ind_minn-1]=a[i];
// ind_minn--;
}
// for (int j = 0; j < ans.length; j++) {
// System.out.print(ans[j]+" oh ");
// }
// System.out.println();
}
// System.out.println();
int flag=0;
for (int i = 0; i < ans.length; i++) {
if(ans[i]==0 && flag==0) {
flag=1;
ans[i]=-1;
}
else if(ans[i]==0 && flag==1){
ans[i]=ans[i-1];
}
else flag=1;
}
for (int i = 0; i < ans.length; i++) {
out.print(ans[i]+" ");
}
// System.out.println(min+"oh");
// for (int i = 0; i < a.length; i++) {
// if(i<(min-1))System.out.print(-1+" ");
// else System.out.print(num+" ");
// }
out.println();
}
out.flush();
}
}
class Readers {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(new InputStreamReader(input));
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while ( ! tokenizer.hasMoreTokens() ) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt( next() );
}
static double nextDouble() throws IOException {
return Double.parseDouble( next() );
}
static long nextLong() throws IOException{
return Long.parseLong(next());
}
} | Java | ["3\n5\n1 2 3 4 5\n5\n4 4 4 4 2\n6\n1 3 1 5 3 1"] | 1 second | ["-1 -1 3 2 1 \n-1 4 4 4 2 \n-1 -1 1 1 1 1"] | null | Java 11 | standard input | [
"data structures"
] | b7abfb1103bb1796c8f89653c303d7dc | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) — the number of elements in the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,500 | For each test case print $$$n$$$ integers, where the $$$i$$$-th integer is equal to the $$$i$$$-amazing number of the array. | standard output | |
PASSED | 0d9ebc207f75102f5a1eaf40f4167d8b | train_002.jsonl | 1601219100 | You are given an array $$$a$$$ consisting of $$$n$$$ integers numbered from $$$1$$$ to $$$n$$$.Let's define the $$$k$$$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $$$k$$$ (recall that a subsegment of $$$a$$$ of length $$$k$$$ is a contiguous part of $$$a$$$ containing exactly $$$k$$$ elements). If there is no integer occuring in all subsegments of length $$$k$$$ for some value of $$$k$$$, then the $$$k$$$-amazing number is $$$-1$$$.For each $$$k$$$ from $$$1$$$ to $$$n$$$ calculate the $$$k$$$-amazing number of the array $$$a$$$. | 256 megabytes |
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
public class competetive {
static class pair implements Comparable <pair>{
int f;
int s;
pair(int a , int b){
this.f=a;
this.s=b;
}
int getF(){
return f;
}
int getS(){
return s;
}
public int compareTo(pair p){
if(this.f==p.f){
return this.s-p.s;
}
return this.f-p.f;
}
}
static int ans[]=new int[400000];
public static void main(String[] args) throws java.lang.Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out), "ASCII"), 512);
int t=Integer.parseInt(br.readLine());
while (t-->0){
int n=Integer.parseInt(br.readLine());
int[]a=new int[n];
String line=br.readLine();
ArrayList<pair>pl=new ArrayList<>();
String[]s=line.trim().split(" ");
for(int i=0;i<n;i++){
pl.add(new pair(Integer.parseInt(s[i]),i));
}
Collections.sort(pl);
int i=1;
int num=pl.get(0).getF();
ArrayList<Integer>il=new ArrayList<>();
ArrayList<pair>l=new ArrayList<>();
il.add(pl.get(0).getS());
while (i<n){
if(pl.get(i).getF()==num) {
il.add(pl.get(i).getS());
}else{
int diff=il.get(0);
for(int j=0;j<il.size()-1;j++){
diff=Math.max(diff,il.get(j+1)-il.get(j)-1);
}
diff=Math.max(diff,n-1-il.get(il.size()-1));
il.clear();
l.add(new pair(num,diff));
num=pl.get(i).getF();
il.add(pl.get(i).getS());
}
if(i==n-1){
int diff=il.get(0);
for(int j=0;j<il.size()-1;j++){
diff=Math.max(diff,il.get(j+1)-il.get(j)-1);
}
diff=Math.max(diff,n-1-il.get(il.size()-1));
il.clear();
l.add(new pair(num,diff));
}
i++;
}
Collections.sort(l);
int[]ans=new int[n];
int min=l.get(0).getS();
a[min]=l.get(0).getF();
i=1;
while(i<l.size()){
min=Math.min(min,l.get(i).getS());
if(a[min]==0){
a[min]=l.get(i).getF();
}
i++;
}
int prev=-1;
for(i=0;i<n;i++){
if (a[i] == 0) {
out.write(String.valueOf(prev)+" ");
}else{
out.write(String.valueOf(a[i])+" ");
prev=a[i];
}
}
out.newLine();
}
out.flush();
}
}
| Java | ["3\n5\n1 2 3 4 5\n5\n4 4 4 4 2\n6\n1 3 1 5 3 1"] | 1 second | ["-1 -1 3 2 1 \n-1 4 4 4 2 \n-1 -1 1 1 1 1"] | null | Java 11 | standard input | [
"data structures"
] | b7abfb1103bb1796c8f89653c303d7dc | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) — the number of elements in the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,500 | For each test case print $$$n$$$ integers, where the $$$i$$$-th integer is equal to the $$$i$$$-amazing number of the array. | standard output | |
PASSED | 58fda60c367af915e6b395ebe280a7c2 | train_002.jsonl | 1268395200 | A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least i is found so that namei does not yet exist in the database. | 64 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.
*/
import java.util.HashMap;
import java.util.Scanner;
/**
*
* @author kacho
*/
public class prob4c {
public static void main(String[] args) {
HashMap <String, Integer> map = new HashMap<>();
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.nextLine();
for (int i = 0, j = 0; i < n; i++) {
String st = sc.nextLine();
if (map.containsKey(st)) {
System.out.println(st + map.get(st));
map.put(st, map.get(st) + 1);
} else {
System.out.println("OK");
map.put(st, 1);
}
}
}
}
| Java | ["4\nabacaba\nacaba\nabacaba\nacab", "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird"] | 5 seconds | ["OK\nOK\nabacaba1\nOK", "OK\nfirst1\nOK\nsecond1\nOK\nthird1"] | null | Java 11 | standard input | [
"data structures",
"implementation",
"hashing"
] | 24098df9c12d9704391949c9ff529c98 | The first line contains number n (1 ≤ n ≤ 105). The following n lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters. | 1,300 | Print n lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken. | standard output | |
PASSED | ebf2aee0e8a47374e517e4508e38f63b | train_002.jsonl | 1268395200 | A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least i is found so that namei does not yet exist in the database. | 64 megabytes |
import java.util.*;
public class MyClass {
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
HashMap<String, Integer> l1 = new HashMap<String, Integer>();
String str="";
String str1="";
int k=0;
while(t-->=1)
{
str=sc.next();
if(!l1.containsKey(str))
{
System.out.println("OK");
l1.put(str,0);
}
else
{
k=l1.get(str);
str1=str+(k+1);
l1.put(str1,(k+1));
System.out.println(str1);
l1.replace(str,(k+1));
}
}
}
}
| Java | ["4\nabacaba\nacaba\nabacaba\nacab", "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird"] | 5 seconds | ["OK\nOK\nabacaba1\nOK", "OK\nfirst1\nOK\nsecond1\nOK\nthird1"] | null | Java 11 | standard input | [
"data structures",
"implementation",
"hashing"
] | 24098df9c12d9704391949c9ff529c98 | The first line contains number n (1 ≤ n ≤ 105). The following n lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters. | 1,300 | Print n lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken. | standard output | |
PASSED | d04f38916d1afd25818cc125317bb2b9 | train_002.jsonl | 1268395200 | A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least i is found so that namei does not yet exist in the database. | 64 megabytes | import java.util.*;
public class practice {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int test = sc.nextInt();
HashMap<String,Integer> map = new HashMap<>();
while(test-- > 0){
String str = sc.next();
if(!map.containsKey(str)){
System.out.println("OK");
map.put(str,1);
}else{
String res = str + String.valueOf(map.get(str));
System.out.println(res);
map.put(str,map.get(str)+1);
}
}
}
}
| Java | ["4\nabacaba\nacaba\nabacaba\nacab", "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird"] | 5 seconds | ["OK\nOK\nabacaba1\nOK", "OK\nfirst1\nOK\nsecond1\nOK\nthird1"] | null | Java 11 | standard input | [
"data structures",
"implementation",
"hashing"
] | 24098df9c12d9704391949c9ff529c98 | The first line contains number n (1 ≤ n ≤ 105). The following n lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters. | 1,300 | Print n lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken. | standard output | |
PASSED | d2419fa0554f81ab964285dd824f4bad | train_002.jsonl | 1268395200 | A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least i is found so that namei does not yet exist in the database. | 64 megabytes |
import java.util.*;
import java.io.*;
public class Registrationsystem {
public static void main(String[] args) throws IOException, FileNotFoundException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
//BufferedReader in = new BufferedReader(new FileReader("Registrationsystem.in"));
// INPUT //
int n = Integer.parseInt(in.readLine());
HashMap<String, Integer> database = new HashMap<>();
for (int i = 0; i < n; i++) {
String a = in.readLine();
if (!database.containsKey(a)) {
System.out.println("OK");
database.put(a, 0);
}
else {
// uh oh the database already contains
int c = database.get(a);
database.replace(a, c+1);
c++;
a += c;
System.out.println(a);
}
}
}
}
/*
HashSet<String> database = new HashSet<>();
for (int i = 0; i < n; i++) {
String a = in.readLine();
if (!database.contains(a)) {
System.out.println("OK");
database.add(a);
}
else {
// uh oh the database already contains
int c = 1;
while(true) {
String b = a;
b += c;
if (!database.contains(b)) {
System.out.println(b);
database.add(b);
break;
}
c++;
}
}
}
*/ | Java | ["4\nabacaba\nacaba\nabacaba\nacab", "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird"] | 5 seconds | ["OK\nOK\nabacaba1\nOK", "OK\nfirst1\nOK\nsecond1\nOK\nthird1"] | null | Java 11 | standard input | [
"data structures",
"implementation",
"hashing"
] | 24098df9c12d9704391949c9ff529c98 | The first line contains number n (1 ≤ n ≤ 105). The following n lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters. | 1,300 | Print n lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken. | standard output | |
PASSED | d37bc97079e781966b9863a01e0e36f5 | train_002.jsonl | 1268395200 | A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least i is found so that namei does not yet exist in the database. | 64 megabytes | import java.io.PrintWriter;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;
public class Solution {
static Scanner in = new Scanner(System.in);
static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) {
solve();
out.close();
}
static void solve() {
int n = in.nextInt();
var set = new HashSet<String>();
var map = new HashMap<String, Integer>();
for (int t = 0; t < n; t++) {
String name = in.next();
if (set.contains(name)) {
int k = map.getOrDefault(name, 0) + 1;
String nameAfter = name + k;
set.add(nameAfter);
map.put(name, k);
out.println(nameAfter);
} else {
set.add(name);
out.println("OK");
}
}
}
}
| Java | ["4\nabacaba\nacaba\nabacaba\nacab", "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird"] | 5 seconds | ["OK\nOK\nabacaba1\nOK", "OK\nfirst1\nOK\nsecond1\nOK\nthird1"] | null | Java 11 | standard input | [
"data structures",
"implementation",
"hashing"
] | 24098df9c12d9704391949c9ff529c98 | The first line contains number n (1 ≤ n ≤ 105). The following n lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters. | 1,300 | Print n lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken. | standard output | |
PASSED | 9575acd231046c058203088a9826c660 | train_002.jsonl | 1268395200 | A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least i is found so that namei does not yet exist in the database. | 64 megabytes | import java.io.PrintWriter;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;
public class Solution {
static Scanner in = new Scanner(System.in);
static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) {
solve();
out.close();
}
static void solve() {
int n = in.nextInt();
var map = new HashMap<String, Integer>();
for (int t = 0; t < n; t++) {
String name = in.next();
if (!map.containsKey(name)) {
map.put(name, 0);
out.println("OK");
} else {
int idx = (map.get(name) + 1);
String newName = name + idx;
map.put(name, idx);
out.println(newName);
}
}
}
}
| Java | ["4\nabacaba\nacaba\nabacaba\nacab", "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird"] | 5 seconds | ["OK\nOK\nabacaba1\nOK", "OK\nfirst1\nOK\nsecond1\nOK\nthird1"] | null | Java 11 | standard input | [
"data structures",
"implementation",
"hashing"
] | 24098df9c12d9704391949c9ff529c98 | The first line contains number n (1 ≤ n ≤ 105). The following n lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters. | 1,300 | Print n lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken. | standard output | |
PASSED | 88941587972d8e3bacc448f23dcfa07b | train_002.jsonl | 1268395200 | A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least i is found so that namei does not yet exist in the database. | 64 megabytes | import java.util.*;
import java.lang.*;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
HashMap<String, Integer> h = new HashMap<>();
List<String> l = new ArrayList<>();
for(int i=0;i<n;i++)
{
String s = sc.next();
if(h.containsKey(s))
{
h.replace(s,h.get(s),h.get(s)+1);
String s1 = s.substring(0,s.length()) + Integer.toString(h.get(s));
System.out.println(s1);
}
else { System.out.println("OK");
h.put(s, 0);}
}
}
} | Java | ["4\nabacaba\nacaba\nabacaba\nacab", "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird"] | 5 seconds | ["OK\nOK\nabacaba1\nOK", "OK\nfirst1\nOK\nsecond1\nOK\nthird1"] | null | Java 11 | standard input | [
"data structures",
"implementation",
"hashing"
] | 24098df9c12d9704391949c9ff529c98 | The first line contains number n (1 ≤ n ≤ 105). The following n lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters. | 1,300 | Print n lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken. | standard output | |
PASSED | 0ffe4e4ee091def10870b816c7e1bdc2 | train_002.jsonl | 1268395200 | A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least i is found so that namei does not yet exist in the database. | 64 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
import static java.lang.Math.*;
public class Main implements Runnable {
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
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() {
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 Main(),"fast",1<<26).start();
}
public void run() {
InputReader sc = new InputReader(System.in);
PrintWriter w = new PrintWriter(System.out);
int n = sc.nextInt();
HashMap<String, Integer> h = new HashMap<>();
List<String> l = new ArrayList<>();
for(int i=0;i<n;i++)
{
String s = sc.next();
if(h.containsKey(s))
{
h.replace(s,h.get(s),h.get(s)+1);
String s1 = s.substring(0,s.length()) + Integer.toString(h.get(s));
w.println(s1);
}
else { w.println("OK");
h.put(s, 0);}
}
w.close();
}
} | Java | ["4\nabacaba\nacaba\nabacaba\nacab", "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird"] | 5 seconds | ["OK\nOK\nabacaba1\nOK", "OK\nfirst1\nOK\nsecond1\nOK\nthird1"] | null | Java 11 | standard input | [
"data structures",
"implementation",
"hashing"
] | 24098df9c12d9704391949c9ff529c98 | The first line contains number n (1 ≤ n ≤ 105). The following n lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters. | 1,300 | Print n lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken. | standard output | |
PASSED | ada4fdb816f1b31080e9d41845946fd5 | train_002.jsonl | 1268395200 | A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least i is found so that namei does not yet exist in the database. | 64 megabytes | import java.util.*;
public class S {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
String str;
HashMap<String,Integer> user = new HashMap<String,Integer>();
while(n-->0) {
str = in.next();
if(!user.containsKey(str)) {
System.out.println("OK");
user.put(str, 1);
}else {
System.out.println(str+user.get(str));
int a = user.get(str);
user.replace(str, ++a);
}
}
}
}
| Java | ["4\nabacaba\nacaba\nabacaba\nacab", "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird"] | 5 seconds | ["OK\nOK\nabacaba1\nOK", "OK\nfirst1\nOK\nsecond1\nOK\nthird1"] | null | Java 11 | standard input | [
"data structures",
"implementation",
"hashing"
] | 24098df9c12d9704391949c9ff529c98 | The first line contains number n (1 ≤ n ≤ 105). The following n lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters. | 1,300 | Print n lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken. | standard output | |
PASSED | e826334267480b37021964e1d8853ed3 | train_002.jsonl | 1268395200 | A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least i is found so that namei does not yet exist in the database. | 64 megabytes | import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Map<String,Integer> map = new HashMap<>();
int n = scanner.nextInt();
scanner.nextLine();
while (n-->0) {
String name = scanner.nextLine();
if (map.containsKey(name)) {
System.out.println(name + map.get(name));
map.put(name+map.get(name),1);
map.put(name,map.get(name)+1);
}
else {
map.put(name, 1);
System.out.println("OK");
}
}
}
}
| Java | ["4\nabacaba\nacaba\nabacaba\nacab", "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird"] | 5 seconds | ["OK\nOK\nabacaba1\nOK", "OK\nfirst1\nOK\nsecond1\nOK\nthird1"] | null | Java 11 | standard input | [
"data structures",
"implementation",
"hashing"
] | 24098df9c12d9704391949c9ff529c98 | The first line contains number n (1 ≤ n ≤ 105). The following n lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters. | 1,300 | Print n lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken. | standard output | |
PASSED | ca70b1b2003dc021d867b077719558d7 | train_002.jsonl | 1268395200 | A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least i is found so that namei does not yet exist in the database. | 64 megabytes | import java.util.HashMap;
import java.util.Scanner;
public class RegistrationSystem {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int l=in.nextInt();
HashMap<String,Integer>
map=new HashMap();
String s;
for(int i=0;i<l;i++)
{
s=in.next();
if(map.containsKey(s))
{
map.put(s,map.get(s)+1);
System.out.println(s+map.get(s));
}
else
{
map.put(s, 0);
System.out.println("OK");
}
}
}
} | Java | ["4\nabacaba\nacaba\nabacaba\nacab", "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird"] | 5 seconds | ["OK\nOK\nabacaba1\nOK", "OK\nfirst1\nOK\nsecond1\nOK\nthird1"] | null | Java 11 | standard input | [
"data structures",
"implementation",
"hashing"
] | 24098df9c12d9704391949c9ff529c98 | The first line contains number n (1 ≤ n ≤ 105). The following n lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters. | 1,300 | Print n lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken. | standard output | |
PASSED | 1aaa5f1d83188feba27fcc401f2f7378 | train_002.jsonl | 1268395200 | A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least i is found so that namei does not yet exist in the database. | 64 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class Main {
public static void main(String[] args) throws IOException {
InputStreamReader reader = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(reader);
String s = br.readLine();
HashMap<String, Integer> map = new HashMap<>();
int t = Integer.parseInt(s);
while (t-- > 0) {
s = br.readLine();
if (!map.containsKey(s)) {
System.out.println("OK");
map.put(s, 0);
continue;
} else {
int count = map.get(s);
map.put(s, count + 1);
s = s + (count + 1);
}
System.out.println(s);
}
}
}
| Java | ["4\nabacaba\nacaba\nabacaba\nacab", "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird"] | 5 seconds | ["OK\nOK\nabacaba1\nOK", "OK\nfirst1\nOK\nsecond1\nOK\nthird1"] | null | Java 11 | standard input | [
"data structures",
"implementation",
"hashing"
] | 24098df9c12d9704391949c9ff529c98 | The first line contains number n (1 ≤ n ≤ 105). The following n lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters. | 1,300 | Print n lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken. | standard output | |
PASSED | d869cd23b9bbf2d057300a58c7dff9ef | train_002.jsonl | 1268395200 | A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least i is found so that namei does not yet exist in the database. | 64 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.TreeSet;
public class RegistrationSystem_4C {
public static void main(String[] args) {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(reader.readLine());
HashMap<String,ArrayList<Integer>> db = new HashMap<>();
for (int i = 0; i < T; i++) {
String str = reader.readLine();
if (!db.containsKey(str)){
db.put(str,new ArrayList<>());
System.out.println("OK");
}else {
int k = db.get(str).size()+1;
db.get(str).add(k);
System.out.println(str+Integer.toString(k));
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
| Java | ["4\nabacaba\nacaba\nabacaba\nacab", "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird"] | 5 seconds | ["OK\nOK\nabacaba1\nOK", "OK\nfirst1\nOK\nsecond1\nOK\nthird1"] | null | Java 11 | standard input | [
"data structures",
"implementation",
"hashing"
] | 24098df9c12d9704391949c9ff529c98 | The first line contains number n (1 ≤ n ≤ 105). The following n lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters. | 1,300 | Print n lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken. | standard output | |
PASSED | 51db69f9d312032b702b0d6923f7d938 | train_002.jsonl | 1268395200 | A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least i is found so that namei does not yet exist in the database. | 64 megabytes | import java.util.*;
public class Solution{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
HashMap<String,Integer> database=new HashMap<>();
for(int i=0;i<n;i++){
String s=sc.next();
if(database.containsKey(s)){
database.put(s,database.get(s)+1);
s+=database.get(s).toString();
database.put(s,0);
System.out.println(s);
}
else{
database.put(s,0);
System.out.println("OK");
}
}
}
} | Java | ["4\nabacaba\nacaba\nabacaba\nacab", "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird"] | 5 seconds | ["OK\nOK\nabacaba1\nOK", "OK\nfirst1\nOK\nsecond1\nOK\nthird1"] | null | Java 11 | standard input | [
"data structures",
"implementation",
"hashing"
] | 24098df9c12d9704391949c9ff529c98 | The first line contains number n (1 ≤ n ≤ 105). The following n lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters. | 1,300 | Print n lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken. | standard output | |
PASSED | c1f8f300a6c6bdc4d076cc9ee9e48d23 | train_002.jsonl | 1268395200 | A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least i is found so that namei does not yet exist in the database. | 64 megabytes | import java.util.*;
public class c4 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
HashMap<String,Integer> a=new HashMap<>();
int n=sc.nextInt();
String s=sc.nextLine();
for(int i=0;i<n;i++)
{
s=sc.nextLine();
int j=0;
if(a.containsKey(s))
{
j=a.get(s);
j++;
}
a.put(s,j);
if(j==0)
{
System.out.println("OK");
}
else
{
System.out.println(s+j);
}
}
}
} | Java | ["4\nabacaba\nacaba\nabacaba\nacab", "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird"] | 5 seconds | ["OK\nOK\nabacaba1\nOK", "OK\nfirst1\nOK\nsecond1\nOK\nthird1"] | null | Java 11 | standard input | [
"data structures",
"implementation",
"hashing"
] | 24098df9c12d9704391949c9ff529c98 | The first line contains number n (1 ≤ n ≤ 105). The following n lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters. | 1,300 | Print n lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken. | standard output | |
PASSED | 01ccd15de7d4e45c1a4b4500025515ae | train_002.jsonl | 1268395200 | A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least i is found so that namei does not yet exist in the database. | 64 megabytes | // Java program to illustrate
// Java.util.HashMap
import java.util.*;
import java.io.BufferedInputStream;
public class Q_4C {
public static void main(String[] args) {
Scanner sc = new Scanner(new BufferedInputStream(System.in));
int n = Integer.valueOf(sc.nextLine());
String input;
HashMap<String, Integer> map = new HashMap<>();
for (int i = 0; i < n; i++) {
input = sc.nextLine();
if (map.containsKey(input)) {
map.put(input, map.get(input) + 1);
System.out.println(input + map.get(input));
} else {
map.put(input, 0);
System.out.println("OK");
}
}
sc.close();
}
}
| Java | ["4\nabacaba\nacaba\nabacaba\nacab", "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird"] | 5 seconds | ["OK\nOK\nabacaba1\nOK", "OK\nfirst1\nOK\nsecond1\nOK\nthird1"] | null | Java 11 | standard input | [
"data structures",
"implementation",
"hashing"
] | 24098df9c12d9704391949c9ff529c98 | The first line contains number n (1 ≤ n ≤ 105). The following n lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters. | 1,300 | Print n lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken. | standard output | |
PASSED | 04950930a564c301a7d14bbe5be8429d | train_002.jsonl | 1268395200 | A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least i is found so that namei does not yet exist in the database. | 64 megabytes | import java.util.*;
import java.io.*;
public class Q_4C {
// -----------PrintWriter for faster output---------------------------------
public static PrintWriter out;
// -----------MyScanner class for faster input----------
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
// --------------------------------------------------------
public static void main(String[] args) {
MyScanner sc = new MyScanner();
out = new PrintWriter(new BufferedOutputStream(System.out));
int n = Integer.valueOf(sc.nextLine());
String input;
HashMap<String, Integer> map = new HashMap<>();
for (int i = 0; i < n; i++) {
input = sc.nextLine();
if (map.containsKey(input)) {
map.put(input, map.get(input) + 1);
out.println(input + map.get(input));
} else {
map.put(input, 0);
out.println("OK");
}
}
// ---------------------------------------------------------------------------------
out.close();
}
}
| Java | ["4\nabacaba\nacaba\nabacaba\nacab", "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird"] | 5 seconds | ["OK\nOK\nabacaba1\nOK", "OK\nfirst1\nOK\nsecond1\nOK\nthird1"] | null | Java 11 | standard input | [
"data structures",
"implementation",
"hashing"
] | 24098df9c12d9704391949c9ff529c98 | The first line contains number n (1 ≤ n ≤ 105). The following n lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters. | 1,300 | Print n lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken. | standard output | |
PASSED | 94df5dd9621f2c964bf45943cac38eee | train_002.jsonl | 1268395200 | A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least i is found so that namei does not yet exist in the database. | 64 megabytes | import java.util.*;
import java.io.*;
public class template {
//-----------PrintWriter for faster output---------------------------------
public static PrintWriter out;
//-----------MyScanner class for faster input----------
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
//--------------------------------------------------------
public static void main(String[] args) {
MyScanner sc = new MyScanner();
out = new PrintWriter(new BufferedOutputStream(System.out));
int n = Integer.valueOf(sc.nextLine());
String input;
HashMap<String, Integer> map = new HashMap<>();
for (int i = 0; i < n; i++) {
input = sc.nextLine();
if (map.containsKey(input)) {
map.put(input, map.get(input) + 1);
System.out.println(input + map.get(input));
} else {
map.put(input, 0);
System.out.println("OK");
}
}
// ---------------------------------------------------------------------------------
out.close();
}
}
| Java | ["4\nabacaba\nacaba\nabacaba\nacab", "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird"] | 5 seconds | ["OK\nOK\nabacaba1\nOK", "OK\nfirst1\nOK\nsecond1\nOK\nthird1"] | null | Java 11 | standard input | [
"data structures",
"implementation",
"hashing"
] | 24098df9c12d9704391949c9ff529c98 | The first line contains number n (1 ≤ n ≤ 105). The following n lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters. | 1,300 | Print n lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken. | standard output | |
PASSED | 877b3153102a0e0a87e2ac8e804a85b4 | train_002.jsonl | 1268395200 | A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least i is found so that namei does not yet exist in the database. | 64 megabytes | import java.util.Scanner;
import java.util.HashMap;
public class RegistrationSystem{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
long n = in.nextLong();
HashMap<String, Integer> userNames = new HashMap<>();
String inputtedUsername;
while(n-->=1){
inputtedUsername = in.next();
if(userNames.containsKey(inputtedUsername)){
System.out.println(inputtedUsername+""+userNames.get(inputtedUsername));
userNames.put(inputtedUsername +""+ userNames.get(inputtedUsername), 1);
userNames.put(inputtedUsername, userNames.get(inputtedUsername)+1);
} else{
userNames.put(inputtedUsername, 1);
System.out.println("OK");
}
}
}
}
| Java | ["4\nabacaba\nacaba\nabacaba\nacab", "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird"] | 5 seconds | ["OK\nOK\nabacaba1\nOK", "OK\nfirst1\nOK\nsecond1\nOK\nthird1"] | null | Java 11 | standard input | [
"data structures",
"implementation",
"hashing"
] | 24098df9c12d9704391949c9ff529c98 | The first line contains number n (1 ≤ n ≤ 105). The following n lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters. | 1,300 | Print n lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken. | standard output | |
PASSED | 0719fdd8dc18019f0046bf4e55412092 | train_002.jsonl | 1268395200 | A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least i is found so that namei does not yet exist in the database. | 64 megabytes | import java.util.*;
public class Contest{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
HashMap<String, Integer> h = new HashMap<>();
while(n-- > 0){
String s = sc.next();
if(h.containsKey(s)){
System.out.println(s+h.get(s));
h.put(s+h.get(s), 1);
h.put(s, h.get(s)+1);
}else{
System.out.println("OK");
h.put(s, 1);
}
}
}
} | Java | ["4\nabacaba\nacaba\nabacaba\nacab", "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird"] | 5 seconds | ["OK\nOK\nabacaba1\nOK", "OK\nfirst1\nOK\nsecond1\nOK\nthird1"] | null | Java 11 | standard input | [
"data structures",
"implementation",
"hashing"
] | 24098df9c12d9704391949c9ff529c98 | The first line contains number n (1 ≤ n ≤ 105). The following n lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters. | 1,300 | Print n lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken. | standard output | |
PASSED | 885afa5f3d2698da0d12f9f92ccf8e93 | train_002.jsonl | 1268395200 | A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least i is found so that namei does not yet exist in the database. | 64 megabytes |
import java.util.*;
public class RegistrationSystem {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String str;
HashMap<String, Integer> map = new HashMap<>();
while (n-- > 0) {
str = sc.next();
if (map.containsKey(str)) {
int old = map.get(str);
System.out.println(str + old);
int mv = old + 1;
map.put(str, mv);
} else {
map.put(str, 1);
System.out.println("OK");
}
}
}
}
| Java | ["4\nabacaba\nacaba\nabacaba\nacab", "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird"] | 5 seconds | ["OK\nOK\nabacaba1\nOK", "OK\nfirst1\nOK\nsecond1\nOK\nthird1"] | null | Java 11 | standard input | [
"data structures",
"implementation",
"hashing"
] | 24098df9c12d9704391949c9ff529c98 | The first line contains number n (1 ≤ n ≤ 105). The following n lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters. | 1,300 | Print n lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken. | standard output | |
PASSED | 4fcce251faaa62b7c0b9f607892da14b | train_002.jsonl | 1268395200 | A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least i is found so that namei does not yet exist in the database. | 64 megabytes | import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class registrationSystem {
private static Scanner s = new Scanner(System.in);
public static void main(String[] args) {
int n = s.nextInt(); s.nextLine();
Map<String,Integer> user = new HashMap<>();
String str;
for(int i=0;i<n;i++){
str = s.nextLine();
if( !user.containsKey(str) ){
System.out.println("OK");
user.put(str,0);
}
else{
int no = user.get(str).intValue() + 1;
System.out.println(str+no);
user.put(str,no);
}
}
}
}
| Java | ["4\nabacaba\nacaba\nabacaba\nacab", "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird"] | 5 seconds | ["OK\nOK\nabacaba1\nOK", "OK\nfirst1\nOK\nsecond1\nOK\nthird1"] | null | Java 11 | standard input | [
"data structures",
"implementation",
"hashing"
] | 24098df9c12d9704391949c9ff529c98 | The first line contains number n (1 ≤ n ≤ 105). The following n lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters. | 1,300 | Print n lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken. | standard output | |
PASSED | 5d24f0ca59361b3393804783afc404ad | train_002.jsonl | 1268395200 | A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least i is found so that namei does not yet exist in the database. | 64 megabytes | import java.util.*;
public class regis {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
HashMap <String, Integer> user = new HashMap<String, Integer>();
for (int i = 0; i < n; i++) {
String a = in.next();
if(user.containsKey(a)){
user.computeIfPresent(a, (key,val)-> val+1);
System.out.println(a+user.get(a));
}else{
user.put(a, 0);
System.out.println("OK");
}
}
}
} | Java | ["4\nabacaba\nacaba\nabacaba\nacab", "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird"] | 5 seconds | ["OK\nOK\nabacaba1\nOK", "OK\nfirst1\nOK\nsecond1\nOK\nthird1"] | null | Java 11 | standard input | [
"data structures",
"implementation",
"hashing"
] | 24098df9c12d9704391949c9ff529c98 | The first line contains number n (1 ≤ n ≤ 105). The following n lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters. | 1,300 | Print n lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken. | standard output | |
PASSED | d7abce78669d493b016bfc8e5659d245 | train_002.jsonl | 1268395200 | A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least i is found so that namei does not yet exist in the database. | 64 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.*;
public class RegistrationSystem
{
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();
HashMap<String, Integer> mp = new HashMap<String,Integer>();
for(int i = 0;i<t;i++)
{
String s = sc.next();
if(!mp.containsKey(s))
{
mp.put(s, 0);
System.out.println("OK");
}
else
{
mp.put(s, mp.get(s)+1);
System.out.println(s+""+mp.get(s));
}
}
}
} | Java | ["4\nabacaba\nacaba\nabacaba\nacab", "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird"] | 5 seconds | ["OK\nOK\nabacaba1\nOK", "OK\nfirst1\nOK\nsecond1\nOK\nthird1"] | null | Java 11 | standard input | [
"data structures",
"implementation",
"hashing"
] | 24098df9c12d9704391949c9ff529c98 | The first line contains number n (1 ≤ n ≤ 105). The following n lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters. | 1,300 | Print n lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken. | standard output | |
PASSED | ebf0ca04dba83aa27cb376171fd4a553 | train_002.jsonl | 1268395200 | A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least i is found so that namei does not yet exist in the database. | 64 megabytes | import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Scanner;
public class RegistrationSystem4C1 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int quantity = scanner.nextInt();
String[] names = new String[quantity];
for (int i = 0; i < quantity; i++) {
names[i] = scanner.next();
}
Map<String, Integer> map = new LinkedHashMap<>();
String temp;
for (int i = 0; i < names.length; i++) {
temp = names[i];
if (map.containsKey(temp)) {
map.put(temp + String.valueOf(map.get(temp)), -1);
map.replace(temp, map.get(temp) + 1);
} else {
map.put(temp, 1);
}
}
for (Map.Entry entry : map.entrySet()) {
if (entry.getValue().equals(-1)) {
System.out.println(entry.getKey());
} else {
System.out.println("OK");
}
}
}
} | Java | ["4\nabacaba\nacaba\nabacaba\nacab", "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird"] | 5 seconds | ["OK\nOK\nabacaba1\nOK", "OK\nfirst1\nOK\nsecond1\nOK\nthird1"] | null | Java 11 | standard input | [
"data structures",
"implementation",
"hashing"
] | 24098df9c12d9704391949c9ff529c98 | The first line contains number n (1 ≤ n ≤ 105). The following n lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters. | 1,300 | Print n lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken. | standard output | |
PASSED | 52dabdd8f6b4660fe4f850abcda59dd1 | train_002.jsonl | 1268395200 | A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least i is found so that namei does not yet exist in the database. | 64 megabytes |
import java.util.*;
public class RegistrationSystem {
public static void main (String[] args){
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
Map<String,Integer> names = new HashMap<>(n);
while(n-->0){
String name = scanner.next();
int count = names.getOrDefault(name,0);
names.put(name,count+1);
if(count==0) {
System.out.printf("OK\n");
}else{
System.out.printf("%s%s\n",name,count);
}
} //Thank you JvR.
scanner.close();
}
}
| Java | ["4\nabacaba\nacaba\nabacaba\nacab", "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird"] | 5 seconds | ["OK\nOK\nabacaba1\nOK", "OK\nfirst1\nOK\nsecond1\nOK\nthird1"] | null | Java 11 | standard input | [
"data structures",
"implementation",
"hashing"
] | 24098df9c12d9704391949c9ff529c98 | The first line contains number n (1 ≤ n ≤ 105). The following n lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters. | 1,300 | Print n lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken. | standard output | |
PASSED | 4d42b95541efd0b82b7758af6ecc38ba | train_002.jsonl | 1268395200 | A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least i is found so that namei does not yet exist in the database. | 64 megabytes | import java.io.*;
import java.util.*;
public class regsystem {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
HashMap<String,Integer> hm = new HashMap<String,Integer>();
int n = Integer.parseInt(br.readLine());
while(n-- > 0) {
String str = br.readLine();
if(hm.containsKey(str)) {
String temp = str + Integer.toString(hm.get(str) + 1);
hm.put(str, hm.get(str) + 1);
System.out.println(temp);
}
else {
hm.put(str,0);
System.out.println("OK");
}
}
}
} | Java | ["4\nabacaba\nacaba\nabacaba\nacab", "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird"] | 5 seconds | ["OK\nOK\nabacaba1\nOK", "OK\nfirst1\nOK\nsecond1\nOK\nthird1"] | null | Java 11 | standard input | [
"data structures",
"implementation",
"hashing"
] | 24098df9c12d9704391949c9ff529c98 | The first line contains number n (1 ≤ n ≤ 105). The following n lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters. | 1,300 | Print n lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken. | standard output | |
PASSED | fad8f5c78b2cc62247dadd0dbec25e80 | train_002.jsonl | 1268395200 | A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least i is found so that namei does not yet exist in the database. | 64 megabytes | import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class RegistrazioniConMappa
{
public static void main(String[] args)
{
Scanner tastiera = new Scanner(System.in);
int lunghezza = Integer.parseInt(tastiera.nextLine());
Map<String, Integer> nomi = new HashMap<String, Integer>();
for(int i = 0; i < lunghezza; i ++)
{
String nome = tastiera.nextLine();
if(!nomi.containsKey(nome))
{
System.out.println("OK");
nomi.put(nome, 0);
}
else
{
nomi.put(nome, nomi.get(nome) + 1);
System.out.println(nome + nomi.get(nome));
}
}
}
}
| Java | ["4\nabacaba\nacaba\nabacaba\nacab", "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird"] | 5 seconds | ["OK\nOK\nabacaba1\nOK", "OK\nfirst1\nOK\nsecond1\nOK\nthird1"] | null | Java 11 | standard input | [
"data structures",
"implementation",
"hashing"
] | 24098df9c12d9704391949c9ff529c98 | The first line contains number n (1 ≤ n ≤ 105). The following n lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters. | 1,300 | Print n lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken. | standard output | |
PASSED | 29bf26e95e26860d85b5e582ea662750 | train_002.jsonl | 1268395200 | A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least i is found so that namei does not yet exist in the database. | 64 megabytes | import java.util.*;
public class registrationsystem
{
public static void main(String args[]) {
Scanner s = new Scanner(System.in);
long n = s.nextLong();
String input = new String();
Map<String, Integer> names = new HashMap<String, Integer>();
for (int i = 0; i < n; i++) {
input = s.next();
if (names.containsKey(input)) {
int tp = names.get(input);
names.replace(input, tp, tp+1);
System.out.println(input + Integer.toString(names.get(input)));
}
else {
System.out.println("OK");
names.put(input, 0);
}
}
s.close();
}
} | Java | ["4\nabacaba\nacaba\nabacaba\nacab", "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird"] | 5 seconds | ["OK\nOK\nabacaba1\nOK", "OK\nfirst1\nOK\nsecond1\nOK\nthird1"] | null | Java 11 | standard input | [
"data structures",
"implementation",
"hashing"
] | 24098df9c12d9704391949c9ff529c98 | The first line contains number n (1 ≤ n ≤ 105). The following n lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters. | 1,300 | Print n lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken. | standard output | |
PASSED | 6af56a58f2943d09bd1ad47012e2e8bc | train_002.jsonl | 1536330900 | You are given a set of $$$2n+1$$$ integer points on a Cartesian plane. Points are numbered from $$$0$$$ to $$$2n$$$ inclusive. Let $$$P_i$$$ be the $$$i$$$-th point. The $$$x$$$-coordinate of the point $$$P_i$$$ equals $$$i$$$. The $$$y$$$-coordinate of the point $$$P_i$$$ equals zero (initially). Thus, initially $$$P_i=(i,0)$$$.The given points are vertices of a plot of a piecewise function. The $$$j$$$-th piece of the function is the segment $$$P_{j}P_{j + 1}$$$.In one move you can increase the $$$y$$$-coordinate of any point with odd $$$x$$$-coordinate (i.e. such points are $$$P_1, P_3, \dots, P_{2n-1}$$$) by $$$1$$$. Note that the corresponding segments also change.For example, the following plot shows a function for $$$n=3$$$ (i.e. number of points is $$$2\cdot3+1=7$$$) in which we increased the $$$y$$$-coordinate of the point $$$P_1$$$ three times and $$$y$$$-coordinate of the point $$$P_5$$$ one time: Let the area of the plot be the area below this plot and above the coordinate axis OX. For example, the area of the plot on the picture above is 4 (the light blue area on the picture above is the area of the plot drawn on it).Let the height of the plot be the maximum $$$y$$$-coordinate among all initial points in the plot (i.e. points $$$P_0, P_1, \dots, P_{2n}$$$). The height of the plot on the picture above is 3.Your problem is to say which minimum possible height can have the plot consisting of $$$2n+1$$$ vertices and having an area equal to $$$k$$$. Note that it is unnecessary to minimize the number of moves.It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.*;
import java.awt.geom.*;
public class FunctionHeight {
public static void main(String[] args) {
MyScanner sc = new MyScanner();
long n = sc.nl();
long k = sc.nl();
long ans = (n+k-1)/n;
System.out.println(ans);
}
/////////// TEMPLATE FROM HERE /////////////////
private static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int ni() {
return Integer.parseInt(next());
}
float nf() {
return Float.parseFloat(next());
}
long nl() {
return Long.parseLong(next());
}
double nd() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
} | Java | ["4 3", "4 12", "999999999999999999 999999999999999986"] | 1 second | ["1", "3", "1"] | NoteOne of the possible answers to the first example: The area of this plot is 3, the height of this plot is 1.There is only one possible answer to the second example: The area of this plot is 12, the height of this plot is 3. | Java 8 | standard input | [
"math"
] | 31014efa929af5e4b7d9987bd9b59918 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^{18}$$$) — the number of vertices in a plot of a piecewise function and the area we need to obtain. | 1,000 | Print one integer — the minimum possible height of a plot consisting of $$$2n+1$$$ vertices and with an area equals $$$k$$$. It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | standard output | |
PASSED | b7b149366ccf1a03e4d39adae2f85c43 | train_002.jsonl | 1536330900 | You are given a set of $$$2n+1$$$ integer points on a Cartesian plane. Points are numbered from $$$0$$$ to $$$2n$$$ inclusive. Let $$$P_i$$$ be the $$$i$$$-th point. The $$$x$$$-coordinate of the point $$$P_i$$$ equals $$$i$$$. The $$$y$$$-coordinate of the point $$$P_i$$$ equals zero (initially). Thus, initially $$$P_i=(i,0)$$$.The given points are vertices of a plot of a piecewise function. The $$$j$$$-th piece of the function is the segment $$$P_{j}P_{j + 1}$$$.In one move you can increase the $$$y$$$-coordinate of any point with odd $$$x$$$-coordinate (i.e. such points are $$$P_1, P_3, \dots, P_{2n-1}$$$) by $$$1$$$. Note that the corresponding segments also change.For example, the following plot shows a function for $$$n=3$$$ (i.e. number of points is $$$2\cdot3+1=7$$$) in which we increased the $$$y$$$-coordinate of the point $$$P_1$$$ three times and $$$y$$$-coordinate of the point $$$P_5$$$ one time: Let the area of the plot be the area below this plot and above the coordinate axis OX. For example, the area of the plot on the picture above is 4 (the light blue area on the picture above is the area of the plot drawn on it).Let the height of the plot be the maximum $$$y$$$-coordinate among all initial points in the plot (i.e. points $$$P_0, P_1, \dots, P_{2n}$$$). The height of the plot on the picture above is 3.Your problem is to say which minimum possible height can have the plot consisting of $$$2n+1$$$ vertices and having an area equal to $$$k$$$. Note that it is unnecessary to minimize the number of moves.It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | 256 megabytes | import java.util.*;
public class MyClass {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
long n=sc.nextLong();
long k=sc.nextLong();
if(k%n==0)
System.out.println(k/n);
else
System.out.println(k/n+1);
}
}
| Java | ["4 3", "4 12", "999999999999999999 999999999999999986"] | 1 second | ["1", "3", "1"] | NoteOne of the possible answers to the first example: The area of this plot is 3, the height of this plot is 1.There is only one possible answer to the second example: The area of this plot is 12, the height of this plot is 3. | Java 8 | standard input | [
"math"
] | 31014efa929af5e4b7d9987bd9b59918 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^{18}$$$) — the number of vertices in a plot of a piecewise function and the area we need to obtain. | 1,000 | Print one integer — the minimum possible height of a plot consisting of $$$2n+1$$$ vertices and with an area equals $$$k$$$. It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | standard output | |
PASSED | b70cc67073225c0c4fad10e3b324dd31 | train_002.jsonl | 1536330900 | You are given a set of $$$2n+1$$$ integer points on a Cartesian plane. Points are numbered from $$$0$$$ to $$$2n$$$ inclusive. Let $$$P_i$$$ be the $$$i$$$-th point. The $$$x$$$-coordinate of the point $$$P_i$$$ equals $$$i$$$. The $$$y$$$-coordinate of the point $$$P_i$$$ equals zero (initially). Thus, initially $$$P_i=(i,0)$$$.The given points are vertices of a plot of a piecewise function. The $$$j$$$-th piece of the function is the segment $$$P_{j}P_{j + 1}$$$.In one move you can increase the $$$y$$$-coordinate of any point with odd $$$x$$$-coordinate (i.e. such points are $$$P_1, P_3, \dots, P_{2n-1}$$$) by $$$1$$$. Note that the corresponding segments also change.For example, the following plot shows a function for $$$n=3$$$ (i.e. number of points is $$$2\cdot3+1=7$$$) in which we increased the $$$y$$$-coordinate of the point $$$P_1$$$ three times and $$$y$$$-coordinate of the point $$$P_5$$$ one time: Let the area of the plot be the area below this plot and above the coordinate axis OX. For example, the area of the plot on the picture above is 4 (the light blue area on the picture above is the area of the plot drawn on it).Let the height of the plot be the maximum $$$y$$$-coordinate among all initial points in the plot (i.e. points $$$P_0, P_1, \dots, P_{2n}$$$). The height of the plot on the picture above is 3.Your problem is to say which minimum possible height can have the plot consisting of $$$2n+1$$$ vertices and having an area equal to $$$k$$$. Note that it is unnecessary to minimize the number of moves.It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class FunctionHeight {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
long vertices = Long.parseLong(st.nextToken());
long area = Long.parseLong(st.nextToken());
System.out.println((area + vertices - 1) / vertices);
}
}
| Java | ["4 3", "4 12", "999999999999999999 999999999999999986"] | 1 second | ["1", "3", "1"] | NoteOne of the possible answers to the first example: The area of this plot is 3, the height of this plot is 1.There is only one possible answer to the second example: The area of this plot is 12, the height of this plot is 3. | Java 8 | standard input | [
"math"
] | 31014efa929af5e4b7d9987bd9b59918 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^{18}$$$) — the number of vertices in a plot of a piecewise function and the area we need to obtain. | 1,000 | Print one integer — the minimum possible height of a plot consisting of $$$2n+1$$$ vertices and with an area equals $$$k$$$. It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | standard output | |
PASSED | 66943d8f3f9815e650fabb4440cc6692 | train_002.jsonl | 1536330900 | You are given a set of $$$2n+1$$$ integer points on a Cartesian plane. Points are numbered from $$$0$$$ to $$$2n$$$ inclusive. Let $$$P_i$$$ be the $$$i$$$-th point. The $$$x$$$-coordinate of the point $$$P_i$$$ equals $$$i$$$. The $$$y$$$-coordinate of the point $$$P_i$$$ equals zero (initially). Thus, initially $$$P_i=(i,0)$$$.The given points are vertices of a plot of a piecewise function. The $$$j$$$-th piece of the function is the segment $$$P_{j}P_{j + 1}$$$.In one move you can increase the $$$y$$$-coordinate of any point with odd $$$x$$$-coordinate (i.e. such points are $$$P_1, P_3, \dots, P_{2n-1}$$$) by $$$1$$$. Note that the corresponding segments also change.For example, the following plot shows a function for $$$n=3$$$ (i.e. number of points is $$$2\cdot3+1=7$$$) in which we increased the $$$y$$$-coordinate of the point $$$P_1$$$ three times and $$$y$$$-coordinate of the point $$$P_5$$$ one time: Let the area of the plot be the area below this plot and above the coordinate axis OX. For example, the area of the plot on the picture above is 4 (the light blue area on the picture above is the area of the plot drawn on it).Let the height of the plot be the maximum $$$y$$$-coordinate among all initial points in the plot (i.e. points $$$P_0, P_1, \dots, P_{2n}$$$). The height of the plot on the picture above is 3.Your problem is to say which minimum possible height can have the plot consisting of $$$2n+1$$$ vertices and having an area equal to $$$k$$$. Note that it is unnecessary to minimize the number of moves.It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.stream.IntStream;
public class DeathNote {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
long n = Long.parseLong(st.nextToken());
long m = Long.parseLong(st.nextToken());
System.out.println(m%n!=0?m/n+1:m/n);
}
}
| Java | ["4 3", "4 12", "999999999999999999 999999999999999986"] | 1 second | ["1", "3", "1"] | NoteOne of the possible answers to the first example: The area of this plot is 3, the height of this plot is 1.There is only one possible answer to the second example: The area of this plot is 12, the height of this plot is 3. | Java 8 | standard input | [
"math"
] | 31014efa929af5e4b7d9987bd9b59918 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^{18}$$$) — the number of vertices in a plot of a piecewise function and the area we need to obtain. | 1,000 | Print one integer — the minimum possible height of a plot consisting of $$$2n+1$$$ vertices and with an area equals $$$k$$$. It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | standard output | |
PASSED | 34a971c34a2d98a4eadc8d2f3dce6f96 | train_002.jsonl | 1536330900 | You are given a set of $$$2n+1$$$ integer points on a Cartesian plane. Points are numbered from $$$0$$$ to $$$2n$$$ inclusive. Let $$$P_i$$$ be the $$$i$$$-th point. The $$$x$$$-coordinate of the point $$$P_i$$$ equals $$$i$$$. The $$$y$$$-coordinate of the point $$$P_i$$$ equals zero (initially). Thus, initially $$$P_i=(i,0)$$$.The given points are vertices of a plot of a piecewise function. The $$$j$$$-th piece of the function is the segment $$$P_{j}P_{j + 1}$$$.In one move you can increase the $$$y$$$-coordinate of any point with odd $$$x$$$-coordinate (i.e. such points are $$$P_1, P_3, \dots, P_{2n-1}$$$) by $$$1$$$. Note that the corresponding segments also change.For example, the following plot shows a function for $$$n=3$$$ (i.e. number of points is $$$2\cdot3+1=7$$$) in which we increased the $$$y$$$-coordinate of the point $$$P_1$$$ three times and $$$y$$$-coordinate of the point $$$P_5$$$ one time: Let the area of the plot be the area below this plot and above the coordinate axis OX. For example, the area of the plot on the picture above is 4 (the light blue area on the picture above is the area of the plot drawn on it).Let the height of the plot be the maximum $$$y$$$-coordinate among all initial points in the plot (i.e. points $$$P_0, P_1, \dots, P_{2n}$$$). The height of the plot on the picture above is 3.Your problem is to say which minimum possible height can have the plot consisting of $$$2n+1$$$ vertices and having an area equal to $$$k$$$. Note that it is unnecessary to minimize the number of moves.It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | 256 megabytes | import java.util.*;
public class a{
public static void main(String args[]){
Scanner s = new Scanner(System.in);
long n = s.nextLong();
long k = s.nextLong();
long temp = k/n;
if (k%n != 0) temp++;
System.out.println(temp);
}
} | Java | ["4 3", "4 12", "999999999999999999 999999999999999986"] | 1 second | ["1", "3", "1"] | NoteOne of the possible answers to the first example: The area of this plot is 3, the height of this plot is 1.There is only one possible answer to the second example: The area of this plot is 12, the height of this plot is 3. | Java 8 | standard input | [
"math"
] | 31014efa929af5e4b7d9987bd9b59918 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^{18}$$$) — the number of vertices in a plot of a piecewise function and the area we need to obtain. | 1,000 | Print one integer — the minimum possible height of a plot consisting of $$$2n+1$$$ vertices and with an area equals $$$k$$$. It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | standard output | |
PASSED | a6ec576e976f347ed927e160953b1548 | train_002.jsonl | 1536330900 | You are given a set of $$$2n+1$$$ integer points on a Cartesian plane. Points are numbered from $$$0$$$ to $$$2n$$$ inclusive. Let $$$P_i$$$ be the $$$i$$$-th point. The $$$x$$$-coordinate of the point $$$P_i$$$ equals $$$i$$$. The $$$y$$$-coordinate of the point $$$P_i$$$ equals zero (initially). Thus, initially $$$P_i=(i,0)$$$.The given points are vertices of a plot of a piecewise function. The $$$j$$$-th piece of the function is the segment $$$P_{j}P_{j + 1}$$$.In one move you can increase the $$$y$$$-coordinate of any point with odd $$$x$$$-coordinate (i.e. such points are $$$P_1, P_3, \dots, P_{2n-1}$$$) by $$$1$$$. Note that the corresponding segments also change.For example, the following plot shows a function for $$$n=3$$$ (i.e. number of points is $$$2\cdot3+1=7$$$) in which we increased the $$$y$$$-coordinate of the point $$$P_1$$$ three times and $$$y$$$-coordinate of the point $$$P_5$$$ one time: Let the area of the plot be the area below this plot and above the coordinate axis OX. For example, the area of the plot on the picture above is 4 (the light blue area on the picture above is the area of the plot drawn on it).Let the height of the plot be the maximum $$$y$$$-coordinate among all initial points in the plot (i.e. points $$$P_0, P_1, \dots, P_{2n}$$$). The height of the plot on the picture above is 3.Your problem is to say which minimum possible height can have the plot consisting of $$$2n+1$$$ vertices and having an area equal to $$$k$$$. Note that it is unnecessary to minimize the number of moves.It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | 256 megabytes |
import java.util.Scanner;
public class ques1 {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
long n,k ;
n=sc.nextLong();
k=sc.nextLong();
if(k%n!=0)
System.out.println(k/n+1);
else
System.out.println(k/n);
}
}
| Java | ["4 3", "4 12", "999999999999999999 999999999999999986"] | 1 second | ["1", "3", "1"] | NoteOne of the possible answers to the first example: The area of this plot is 3, the height of this plot is 1.There is only one possible answer to the second example: The area of this plot is 12, the height of this plot is 3. | Java 8 | standard input | [
"math"
] | 31014efa929af5e4b7d9987bd9b59918 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^{18}$$$) — the number of vertices in a plot of a piecewise function and the area we need to obtain. | 1,000 | Print one integer — the minimum possible height of a plot consisting of $$$2n+1$$$ vertices and with an area equals $$$k$$$. It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | standard output | |
PASSED | 3e807ea81a863aa4f020d5055bdb1fee | train_002.jsonl | 1536330900 | You are given a set of $$$2n+1$$$ integer points on a Cartesian plane. Points are numbered from $$$0$$$ to $$$2n$$$ inclusive. Let $$$P_i$$$ be the $$$i$$$-th point. The $$$x$$$-coordinate of the point $$$P_i$$$ equals $$$i$$$. The $$$y$$$-coordinate of the point $$$P_i$$$ equals zero (initially). Thus, initially $$$P_i=(i,0)$$$.The given points are vertices of a plot of a piecewise function. The $$$j$$$-th piece of the function is the segment $$$P_{j}P_{j + 1}$$$.In one move you can increase the $$$y$$$-coordinate of any point with odd $$$x$$$-coordinate (i.e. such points are $$$P_1, P_3, \dots, P_{2n-1}$$$) by $$$1$$$. Note that the corresponding segments also change.For example, the following plot shows a function for $$$n=3$$$ (i.e. number of points is $$$2\cdot3+1=7$$$) in which we increased the $$$y$$$-coordinate of the point $$$P_1$$$ three times and $$$y$$$-coordinate of the point $$$P_5$$$ one time: Let the area of the plot be the area below this plot and above the coordinate axis OX. For example, the area of the plot on the picture above is 4 (the light blue area on the picture above is the area of the plot drawn on it).Let the height of the plot be the maximum $$$y$$$-coordinate among all initial points in the plot (i.e. points $$$P_0, P_1, \dots, P_{2n}$$$). The height of the plot on the picture above is 3.Your problem is to say which minimum possible height can have the plot consisting of $$$2n+1$$$ vertices and having an area equal to $$$k$$$. Note that it is unnecessary to minimize the number of moves.It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | 256 megabytes |
import java.io.*;
//import java.text.DecimalFormat;
import java.util.*;
public class Main {
static InputReader in;
static PrintWriter out;
public static void main(String args[] ) {
InputReader in = new InputReader(System.in);
PrintWriter out = new PrintWriter(System.out);
//Scanner in = new Scanner (System.in);
long n = in.nextLong();
long k = in.nextLong();
long x = k / n;
if (k % n != 0)
x++;
System.out.println(x);
out.close();
}
static class InputReader
{
private final InputStream stream;
private final byte[] buf = new byte[8192];
private int curChar, snumChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream)
{
this.stream = stream;
}
public int snext()
{
if (snumChars == -1)
throw new InputMismatchException();
if (curChar >= snumChars)
{
curChar = 0;
try
{
snumChars = stream.read(buf);
} catch (IOException e)
{
throw new InputMismatchException();
}
if (snumChars <= 0)
return -1;
}
return buf[curChar++];
}
public int nextInt()
{
int c = snext();
while (isSpaceChar(c))
{
c = snext();
}
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = snext();
}
int res = 0;
do
{
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = snext();
} while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong()
{
int c = snext();
while (isSpaceChar(c))
{
c = snext();
}
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = snext();
}
long res = 0;
do
{
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = snext();
} while (!isSpaceChar(c));
return res * sgn;
}
public int[] nextIntArray(int n)
{
int a[] = new int[n];
for (int i = 0; i < n; i++)
{
a[i] = nextInt();
}
return a;
}
public long[] nextLongArray(int n)
{
long a[] = new long[n];
for (int i = 0; i < n; i++)
{
a[i] = nextLong();
}
return a;
}
public String readString()
{
int c = snext();
while (isSpaceChar(c))
{
c = snext();
}
StringBuilder res = new StringBuilder();
do
{
res.appendCodePoint(c);
c = snext();
} while (!isSpaceChar(c));
return res.toString();
}
public String nextLine()
{
int c = snext();
while (isSpaceChar(c))
c = snext();
StringBuilder res = new StringBuilder();
do
{
res.appendCodePoint(c);
c = snext();
} while (!isEndOfLine(c));
return res.toString();
}
public boolean isSpaceChar(int c)
{
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private boolean isEndOfLine(int c)
{
return c == '\n' || c == '\r' || c == -1;
}
public interface SpaceCharFilter
{
public boolean isSpaceChar(int ch);
}
}
}
| Java | ["4 3", "4 12", "999999999999999999 999999999999999986"] | 1 second | ["1", "3", "1"] | NoteOne of the possible answers to the first example: The area of this plot is 3, the height of this plot is 1.There is only one possible answer to the second example: The area of this plot is 12, the height of this plot is 3. | Java 8 | standard input | [
"math"
] | 31014efa929af5e4b7d9987bd9b59918 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^{18}$$$) — the number of vertices in a plot of a piecewise function and the area we need to obtain. | 1,000 | Print one integer — the minimum possible height of a plot consisting of $$$2n+1$$$ vertices and with an area equals $$$k$$$. It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | standard output | |
PASSED | 00fad224fc5ba0713eff88c2fc0d47fd | train_002.jsonl | 1536330900 | You are given a set of $$$2n+1$$$ integer points on a Cartesian plane. Points are numbered from $$$0$$$ to $$$2n$$$ inclusive. Let $$$P_i$$$ be the $$$i$$$-th point. The $$$x$$$-coordinate of the point $$$P_i$$$ equals $$$i$$$. The $$$y$$$-coordinate of the point $$$P_i$$$ equals zero (initially). Thus, initially $$$P_i=(i,0)$$$.The given points are vertices of a plot of a piecewise function. The $$$j$$$-th piece of the function is the segment $$$P_{j}P_{j + 1}$$$.In one move you can increase the $$$y$$$-coordinate of any point with odd $$$x$$$-coordinate (i.e. such points are $$$P_1, P_3, \dots, P_{2n-1}$$$) by $$$1$$$. Note that the corresponding segments also change.For example, the following plot shows a function for $$$n=3$$$ (i.e. number of points is $$$2\cdot3+1=7$$$) in which we increased the $$$y$$$-coordinate of the point $$$P_1$$$ three times and $$$y$$$-coordinate of the point $$$P_5$$$ one time: Let the area of the plot be the area below this plot and above the coordinate axis OX. For example, the area of the plot on the picture above is 4 (the light blue area on the picture above is the area of the plot drawn on it).Let the height of the plot be the maximum $$$y$$$-coordinate among all initial points in the plot (i.e. points $$$P_0, P_1, \dots, P_{2n}$$$). The height of the plot on the picture above is 3.Your problem is to say which minimum possible height can have the plot consisting of $$$2n+1$$$ vertices and having an area equal to $$$k$$$. Note that it is unnecessary to minimize the number of moves.It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner in = new Scanner(System.in);
long n=in.nextLong();
long k=in.nextLong();
if(k%n==0){
System.out.println(k/n);
}
else{
System.out.println((k/n)+1);
}
}
}
| Java | ["4 3", "4 12", "999999999999999999 999999999999999986"] | 1 second | ["1", "3", "1"] | NoteOne of the possible answers to the first example: The area of this plot is 3, the height of this plot is 1.There is only one possible answer to the second example: The area of this plot is 12, the height of this plot is 3. | Java 8 | standard input | [
"math"
] | 31014efa929af5e4b7d9987bd9b59918 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^{18}$$$) — the number of vertices in a plot of a piecewise function and the area we need to obtain. | 1,000 | Print one integer — the minimum possible height of a plot consisting of $$$2n+1$$$ vertices and with an area equals $$$k$$$. It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | standard output | |
PASSED | 630589785fdeb2bf7de41e3e283795a3 | train_002.jsonl | 1536330900 | You are given a set of $$$2n+1$$$ integer points on a Cartesian plane. Points are numbered from $$$0$$$ to $$$2n$$$ inclusive. Let $$$P_i$$$ be the $$$i$$$-th point. The $$$x$$$-coordinate of the point $$$P_i$$$ equals $$$i$$$. The $$$y$$$-coordinate of the point $$$P_i$$$ equals zero (initially). Thus, initially $$$P_i=(i,0)$$$.The given points are vertices of a plot of a piecewise function. The $$$j$$$-th piece of the function is the segment $$$P_{j}P_{j + 1}$$$.In one move you can increase the $$$y$$$-coordinate of any point with odd $$$x$$$-coordinate (i.e. such points are $$$P_1, P_3, \dots, P_{2n-1}$$$) by $$$1$$$. Note that the corresponding segments also change.For example, the following plot shows a function for $$$n=3$$$ (i.e. number of points is $$$2\cdot3+1=7$$$) in which we increased the $$$y$$$-coordinate of the point $$$P_1$$$ three times and $$$y$$$-coordinate of the point $$$P_5$$$ one time: Let the area of the plot be the area below this plot and above the coordinate axis OX. For example, the area of the plot on the picture above is 4 (the light blue area on the picture above is the area of the plot drawn on it).Let the height of the plot be the maximum $$$y$$$-coordinate among all initial points in the plot (i.e. points $$$P_0, P_1, \dots, P_{2n}$$$). The height of the plot on the picture above is 3.Your problem is to say which minimum possible height can have the plot consisting of $$$2n+1$$$ vertices and having an area equal to $$$k$$$. Note that it is unnecessary to minimize the number of moves.It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | 256 megabytes | import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution
{
static class InputReader
{
private final InputStream stream;
private final byte[] buf = new byte[8192];
private int curChar, snumChars;
public InputReader(InputStream st) {
this.stream = st;
}
public int read() {
if (snumChars == -1)
throw new InputMismatchException();
if (curChar >= snumChars) {
curChar = 0;
try {
snumChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (snumChars <= 0)
return -1;
}
return buf[curChar++];
}
public int nextInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public int[] nextIntArray(int n) {
int a[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
return a;
}
public String readString() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public String nextLine() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
}
public static void main(String[] args) throws Exception
{
Scanner in = new Scanner(System.in);
long n = in.nextLong();
long k = in.nextLong();
long ans = k/n;
if(k%n > 0)
ans += 1;
System.out.println(ans);
}
} | Java | ["4 3", "4 12", "999999999999999999 999999999999999986"] | 1 second | ["1", "3", "1"] | NoteOne of the possible answers to the first example: The area of this plot is 3, the height of this plot is 1.There is only one possible answer to the second example: The area of this plot is 12, the height of this plot is 3. | Java 8 | standard input | [
"math"
] | 31014efa929af5e4b7d9987bd9b59918 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^{18}$$$) — the number of vertices in a plot of a piecewise function and the area we need to obtain. | 1,000 | Print one integer — the minimum possible height of a plot consisting of $$$2n+1$$$ vertices and with an area equals $$$k$$$. It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | standard output | |
PASSED | 2f7d058b9af19912c9feff251a3228cc | train_002.jsonl | 1536330900 | You are given a set of $$$2n+1$$$ integer points on a Cartesian plane. Points are numbered from $$$0$$$ to $$$2n$$$ inclusive. Let $$$P_i$$$ be the $$$i$$$-th point. The $$$x$$$-coordinate of the point $$$P_i$$$ equals $$$i$$$. The $$$y$$$-coordinate of the point $$$P_i$$$ equals zero (initially). Thus, initially $$$P_i=(i,0)$$$.The given points are vertices of a plot of a piecewise function. The $$$j$$$-th piece of the function is the segment $$$P_{j}P_{j + 1}$$$.In one move you can increase the $$$y$$$-coordinate of any point with odd $$$x$$$-coordinate (i.e. such points are $$$P_1, P_3, \dots, P_{2n-1}$$$) by $$$1$$$. Note that the corresponding segments also change.For example, the following plot shows a function for $$$n=3$$$ (i.e. number of points is $$$2\cdot3+1=7$$$) in which we increased the $$$y$$$-coordinate of the point $$$P_1$$$ three times and $$$y$$$-coordinate of the point $$$P_5$$$ one time: Let the area of the plot be the area below this plot and above the coordinate axis OX. For example, the area of the plot on the picture above is 4 (the light blue area on the picture above is the area of the plot drawn on it).Let the height of the plot be the maximum $$$y$$$-coordinate among all initial points in the plot (i.e. points $$$P_0, P_1, \dots, P_{2n}$$$). The height of the plot on the picture above is 3.Your problem is to say which minimum possible height can have the plot consisting of $$$2n+1$$$ vertices and having an area equal to $$$k$$$. Note that it is unnecessary to minimize the number of moves.It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | 256 megabytes | import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;
public class zizo {
public static void main(String[]args) throws IOException {
Scanner zizo = new Scanner(System.in);
PrintWriter wr = new PrintWriter(System.out);
long n = zizo.nextLong();
long k = zizo.nextLong();
System.out.println((( n+k-1) / n));
wr.close();
}
}
| Java | ["4 3", "4 12", "999999999999999999 999999999999999986"] | 1 second | ["1", "3", "1"] | NoteOne of the possible answers to the first example: The area of this plot is 3, the height of this plot is 1.There is only one possible answer to the second example: The area of this plot is 12, the height of this plot is 3. | Java 8 | standard input | [
"math"
] | 31014efa929af5e4b7d9987bd9b59918 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^{18}$$$) — the number of vertices in a plot of a piecewise function and the area we need to obtain. | 1,000 | Print one integer — the minimum possible height of a plot consisting of $$$2n+1$$$ vertices and with an area equals $$$k$$$. It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | standard output | |
PASSED | b6ba97055c17de34c03e46fc313d2f63 | train_002.jsonl | 1536330900 | You are given a set of $$$2n+1$$$ integer points on a Cartesian plane. Points are numbered from $$$0$$$ to $$$2n$$$ inclusive. Let $$$P_i$$$ be the $$$i$$$-th point. The $$$x$$$-coordinate of the point $$$P_i$$$ equals $$$i$$$. The $$$y$$$-coordinate of the point $$$P_i$$$ equals zero (initially). Thus, initially $$$P_i=(i,0)$$$.The given points are vertices of a plot of a piecewise function. The $$$j$$$-th piece of the function is the segment $$$P_{j}P_{j + 1}$$$.In one move you can increase the $$$y$$$-coordinate of any point with odd $$$x$$$-coordinate (i.e. such points are $$$P_1, P_3, \dots, P_{2n-1}$$$) by $$$1$$$. Note that the corresponding segments also change.For example, the following plot shows a function for $$$n=3$$$ (i.e. number of points is $$$2\cdot3+1=7$$$) in which we increased the $$$y$$$-coordinate of the point $$$P_1$$$ three times and $$$y$$$-coordinate of the point $$$P_5$$$ one time: Let the area of the plot be the area below this plot and above the coordinate axis OX. For example, the area of the plot on the picture above is 4 (the light blue area on the picture above is the area of the plot drawn on it).Let the height of the plot be the maximum $$$y$$$-coordinate among all initial points in the plot (i.e. points $$$P_0, P_1, \dots, P_{2n}$$$). The height of the plot on the picture above is 3.Your problem is to say which minimum possible height can have the plot consisting of $$$2n+1$$$ vertices and having an area equal to $$$k$$$. Note that it is unnecessary to minimize the number of moves.It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | 256 megabytes | import java.util.*;
public class CodeforcesFunctionHeight {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
long n = in.nextLong();
long k = in.nextLong();
long ans = (k%n == 0) ? k/n : k/n + 1;
System.out.println(ans);
in.close();
}
}
| Java | ["4 3", "4 12", "999999999999999999 999999999999999986"] | 1 second | ["1", "3", "1"] | NoteOne of the possible answers to the first example: The area of this plot is 3, the height of this plot is 1.There is only one possible answer to the second example: The area of this plot is 12, the height of this plot is 3. | Java 8 | standard input | [
"math"
] | 31014efa929af5e4b7d9987bd9b59918 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^{18}$$$) — the number of vertices in a plot of a piecewise function and the area we need to obtain. | 1,000 | Print one integer — the minimum possible height of a plot consisting of $$$2n+1$$$ vertices and with an area equals $$$k$$$. It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | standard output | |
PASSED | 46d065254bb4fec8c80bbd0939f1ef3c | train_002.jsonl | 1536330900 | You are given a set of $$$2n+1$$$ integer points on a Cartesian plane. Points are numbered from $$$0$$$ to $$$2n$$$ inclusive. Let $$$P_i$$$ be the $$$i$$$-th point. The $$$x$$$-coordinate of the point $$$P_i$$$ equals $$$i$$$. The $$$y$$$-coordinate of the point $$$P_i$$$ equals zero (initially). Thus, initially $$$P_i=(i,0)$$$.The given points are vertices of a plot of a piecewise function. The $$$j$$$-th piece of the function is the segment $$$P_{j}P_{j + 1}$$$.In one move you can increase the $$$y$$$-coordinate of any point with odd $$$x$$$-coordinate (i.e. such points are $$$P_1, P_3, \dots, P_{2n-1}$$$) by $$$1$$$. Note that the corresponding segments also change.For example, the following plot shows a function for $$$n=3$$$ (i.e. number of points is $$$2\cdot3+1=7$$$) in which we increased the $$$y$$$-coordinate of the point $$$P_1$$$ three times and $$$y$$$-coordinate of the point $$$P_5$$$ one time: Let the area of the plot be the area below this plot and above the coordinate axis OX. For example, the area of the plot on the picture above is 4 (the light blue area on the picture above is the area of the plot drawn on it).Let the height of the plot be the maximum $$$y$$$-coordinate among all initial points in the plot (i.e. points $$$P_0, P_1, \dots, P_{2n}$$$). The height of the plot on the picture above is 3.Your problem is to say which minimum possible height can have the plot consisting of $$$2n+1$$$ vertices and having an area equal to $$$k$$$. Note that it is unnecessary to minimize the number of moves.It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | 256 megabytes | import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
PrintWriter out = new PrintWriter(outputStream);
InputReader in = new InputReader(inputStream);
//InputStream uinputStream = new FileInputStream("3.in");
//InputReader in = new InputReader(uinputStream);
//PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("taming.out")));
Task t = new Task();
t.solve(in, out);
out.close();
}
static class Task {
public void solve(InputReader in, PrintWriter out) throws IOException {
long n = in.nextLong();
long k = in.nextLong();
BigInteger a = new BigInteger(n+"");
BigInteger b = new BigInteger(k+"");
long ret = Long.valueOf(b.divide(a).toString());
if(ret*n<k)ret++;
Dumper.print(ret);
}
class BIT{
int arr[];
int n;
public BIT(int t){
n=t+1;
arr = new int[n];
}
void add(int i, int delta) {
while(i<n) {
arr[i]+=delta;
i+=i&(-i);
}
}
int sum(int i) {
int s=0;
while(i>0) {
s+=arr[i];
i-=i&(-i);
}
return s;
}
}
public class TreeNode {
int val;
TreeNode left;
TreeNode right;
TreeNode(int x) { val = x; }
}
ArrayList<Integer> arr = new ArrayList<Integer>();
public TreeNode increasingBST(TreeNode root) {
TreeNode ret = null;
TreeNode cur = null;
inorder(root);
for(int i:arr){
if(cur==null) cur = new TreeNode(i);
else {
TreeNode tmp = new TreeNode(i);
cur.right = tmp;
cur = cur.right;
}
if(ret==null) ret = cur;
}
return ret;
}
public void inorder(TreeNode root){
if(root==null) return;
inorder(root.left);
arr.add(root.val);
inorder(root.right);
}
}
public class MinHeap<Key> implements Iterable<Key> {
private int maxN;
private int n;
private int[] pq;
private int[] qp;
private Key[] keys;
private Comparator<Key> comparator;
public MinHeap(int capacity){
if (capacity < 0) throw new IllegalArgumentException();
this.maxN = capacity;
n=0;
pq = new int[maxN+1];
qp = new int[maxN+1];
keys = (Key[]) new Object[capacity+1];
Arrays.fill(qp, -1);
}
public MinHeap(int capacity, Comparator<Key> c){
if (capacity < 0) throw new IllegalArgumentException();
this.maxN = capacity;
n=0;
pq = new int[maxN+1];
qp = new int[maxN+1];
keys = (Key[]) new Object[capacity+1];
Arrays.fill(qp, -1);
comparator = c;
}
public boolean isEmpty() { return n==0; }
public int size() { return n; }
public boolean contains(int i) {
if (i < 0 || i >= maxN) throw new IllegalArgumentException();
return qp[i] != -1;
}
public int peekIdx() {
if (n == 0) throw new NoSuchElementException("Priority queue underflow");
return pq[1];
}
public Key peek(){
if(isEmpty()) throw new NoSuchElementException("Priority queue underflow");
return keys[pq[1]];
}
public int poll(){
if(isEmpty()) throw new NoSuchElementException("Priority queue underflow");
int min = pq[1];
exch(1,n--);
down(1);
assert min==pq[n+1];
qp[min] = -1;
keys[min] = null;
pq[n+1] = -1;
return min;
}
public void update(int i, Key key) {
if (i < 0 || i >= maxN) throw new IllegalArgumentException();
if (!contains(i)) {
add(i,key);
}else{
keys[i] = key;
up(qp[i]);
down(qp[i]);
}
}
private void add(int i, Key x){
if (i < 0 || i >= maxN) throw new IllegalArgumentException();
if (contains(i)) throw new IllegalArgumentException("index is already in the priority queue");
n++;
qp[i] = n;
pq[n] = i;
keys[i] = x;
up(n);
}
private void up(int k){
while(k>1&&less(k,k/2)){
exch(k,k/2);
k/=2;
}
}
private void down(int k){
while(2*k<=n){
int j=2*k;
if(j<n&&less(j+1,j)) j++;
if(less(k,j)) break;
exch(k,j);
k=j;
}
}
public boolean less(int i, int j){
if (comparator == null) {
return ((Comparable<Key>) keys[pq[i]]).compareTo(keys[pq[j]]) < 0;
}
else {
return comparator.compare(keys[pq[i]], keys[pq[j]]) < 0;
}
}
public void exch(int i, int j){
int swap = pq[i];
pq[i] = pq[j];
pq[j] = swap;
qp[pq[i]] = i;
qp[pq[j]] = j;
}
@Override
public Iterator<Key> iterator() {
// TODO Auto-generated method stub
return null;
}
}
private static class InputReader
{
private InputStream stream;
private byte[] buf = new byte[1024];
private int zcurChar;
private int znumChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream)
{
this.stream = stream;
}
public int read()
{
if (znumChars == -1)
throw new InputMismatchException();
if (zcurChar >= znumChars)
{
zcurChar = 0;
try
{
znumChars = stream.read(buf);
} catch (IOException e)
{
throw new InputMismatchException();
}
if (znumChars <= 0)
return -1;
}
return buf[zcurChar++];
}
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 String nextString()
{
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do
{
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public 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 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 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 nextString();
}
public interface SpaceCharFilter
{
public boolean isSpaceChar(int ch);
}
}
static class Dumper {
static void print_int_arr(int[] arr) {
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
System.out.println();
System.out.println("---------------------");
}
static void print_char_arr(char[] arr) {
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
System.out.println();
System.out.println("---------------------");
}
static void print_double_arr(double[] arr) {
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
System.out.println();
System.out.println("---------------------");
}
static void print_2d_arr(int[][] arr, int x, int y) {
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
System.out.print(arr[i][j] + " ");
}
System.out.println();
}
System.out.println();
System.out.println("---------------------");
}
static void print_2d_arr(boolean[][] arr, int x, int y) {
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
System.out.print(arr[i][j] + " ");
}
System.out.println();
}
System.out.println();
System.out.println("---------------------");
}
static void print(Object o) {
System.out.println(o.toString());
}
static void getc() {
System.out.println("here");
}
}
}
| Java | ["4 3", "4 12", "999999999999999999 999999999999999986"] | 1 second | ["1", "3", "1"] | NoteOne of the possible answers to the first example: The area of this plot is 3, the height of this plot is 1.There is only one possible answer to the second example: The area of this plot is 12, the height of this plot is 3. | Java 8 | standard input | [
"math"
] | 31014efa929af5e4b7d9987bd9b59918 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^{18}$$$) — the number of vertices in a plot of a piecewise function and the area we need to obtain. | 1,000 | Print one integer — the minimum possible height of a plot consisting of $$$2n+1$$$ vertices and with an area equals $$$k$$$. It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | standard output | |
PASSED | ed86d0fa1876b176268b74600dae33c3 | train_002.jsonl | 1536330900 | You are given a set of $$$2n+1$$$ integer points on a Cartesian plane. Points are numbered from $$$0$$$ to $$$2n$$$ inclusive. Let $$$P_i$$$ be the $$$i$$$-th point. The $$$x$$$-coordinate of the point $$$P_i$$$ equals $$$i$$$. The $$$y$$$-coordinate of the point $$$P_i$$$ equals zero (initially). Thus, initially $$$P_i=(i,0)$$$.The given points are vertices of a plot of a piecewise function. The $$$j$$$-th piece of the function is the segment $$$P_{j}P_{j + 1}$$$.In one move you can increase the $$$y$$$-coordinate of any point with odd $$$x$$$-coordinate (i.e. such points are $$$P_1, P_3, \dots, P_{2n-1}$$$) by $$$1$$$. Note that the corresponding segments also change.For example, the following plot shows a function for $$$n=3$$$ (i.e. number of points is $$$2\cdot3+1=7$$$) in which we increased the $$$y$$$-coordinate of the point $$$P_1$$$ three times and $$$y$$$-coordinate of the point $$$P_5$$$ one time: Let the area of the plot be the area below this plot and above the coordinate axis OX. For example, the area of the plot on the picture above is 4 (the light blue area on the picture above is the area of the plot drawn on it).Let the height of the plot be the maximum $$$y$$$-coordinate among all initial points in the plot (i.e. points $$$P_0, P_1, \dots, P_{2n}$$$). The height of the plot on the picture above is 3.Your problem is to say which minimum possible height can have the plot consisting of $$$2n+1$$$ vertices and having an area equal to $$$k$$$. Note that it is unnecessary to minimize the number of moves.It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | 256 megabytes |
import java.io.*;
import java.util.*;
public class A {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
String[] s = br.readLine().trim().split(" ");
long n = Long.parseLong(s[0]);
long k = Long.parseLong(s[1]);
long x = k/n;
if(k%n > 0) System.out.println(x+1);
else System.out.println(x);
}
} | Java | ["4 3", "4 12", "999999999999999999 999999999999999986"] | 1 second | ["1", "3", "1"] | NoteOne of the possible answers to the first example: The area of this plot is 3, the height of this plot is 1.There is only one possible answer to the second example: The area of this plot is 12, the height of this plot is 3. | Java 8 | standard input | [
"math"
] | 31014efa929af5e4b7d9987bd9b59918 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^{18}$$$) — the number of vertices in a plot of a piecewise function and the area we need to obtain. | 1,000 | Print one integer — the minimum possible height of a plot consisting of $$$2n+1$$$ vertices and with an area equals $$$k$$$. It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | standard output | |
PASSED | 0aa461c03f8bf279461e8992fb594814 | train_002.jsonl | 1536330900 | You are given a set of $$$2n+1$$$ integer points on a Cartesian plane. Points are numbered from $$$0$$$ to $$$2n$$$ inclusive. Let $$$P_i$$$ be the $$$i$$$-th point. The $$$x$$$-coordinate of the point $$$P_i$$$ equals $$$i$$$. The $$$y$$$-coordinate of the point $$$P_i$$$ equals zero (initially). Thus, initially $$$P_i=(i,0)$$$.The given points are vertices of a plot of a piecewise function. The $$$j$$$-th piece of the function is the segment $$$P_{j}P_{j + 1}$$$.In one move you can increase the $$$y$$$-coordinate of any point with odd $$$x$$$-coordinate (i.e. such points are $$$P_1, P_3, \dots, P_{2n-1}$$$) by $$$1$$$. Note that the corresponding segments also change.For example, the following plot shows a function for $$$n=3$$$ (i.e. number of points is $$$2\cdot3+1=7$$$) in which we increased the $$$y$$$-coordinate of the point $$$P_1$$$ three times and $$$y$$$-coordinate of the point $$$P_5$$$ one time: Let the area of the plot be the area below this plot and above the coordinate axis OX. For example, the area of the plot on the picture above is 4 (the light blue area on the picture above is the area of the plot drawn on it).Let the height of the plot be the maximum $$$y$$$-coordinate among all initial points in the plot (i.e. points $$$P_0, P_1, \dots, P_{2n}$$$). The height of the plot on the picture above is 3.Your problem is to say which minimum possible height can have the plot consisting of $$$2n+1$$$ vertices and having an area equal to $$$k$$$. Note that it is unnecessary to minimize the number of moves.It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;
import java.util.StringTokenizer;
public class codeforces3 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
BigInteger nn=new BigInteger(st.nextToken());
BigInteger kk=new BigInteger(st.nextToken());
BigDecimal decnn = new BigDecimal(nn);
BigDecimal deckk = new BigDecimal(kk);
BigDecimal ress=deckk.divide(decnn, MathContext.DECIMAL128);
BigInteger anss=ress.toBigInteger();
if(kk.mod(nn).equals(BigInteger.ZERO)){
System.out.println(kk.divide(nn));
}
else if (ress.equals(anss)){
System.out.println(anss);
}else{
System.out.println(anss.add(BigInteger.ONE));
}
// long n = Long.parseLong(st.nextToken());
// long k = Long.parseLong(st.nextToken());
// float res = k / (float) n;
// long ans = (long) res;
// if (k%n==0){
// System.out.println("asff"+k/n);
// }
// else if (ans == res) {
// System.out.println(ans);
// } else {
// System.out.println(ans + 1);
// }
}
}
//"C:\Program Files\Java\jdk1.8.0_171\bin\java.exe" "-javaagent:E:\intelj\IntelliJ IDEA Community Edition 2018.2.1\lib\idea_rt.jar=53622:E:\intelj\IntelliJ IDEA Community Edition 2018.2.1\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_171\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\rt.jar;C:\Users\amitp\IdeaProjects\tictactow\out\production\tictactow" codeforces3
// 2
// 1 12346579
// 1.2346579E7
// 12346579
// 1 123456789123456789
// 1.23456789123456784E17
// 123456789123456784 | Java | ["4 3", "4 12", "999999999999999999 999999999999999986"] | 1 second | ["1", "3", "1"] | NoteOne of the possible answers to the first example: The area of this plot is 3, the height of this plot is 1.There is only one possible answer to the second example: The area of this plot is 12, the height of this plot is 3. | Java 8 | standard input | [
"math"
] | 31014efa929af5e4b7d9987bd9b59918 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^{18}$$$) — the number of vertices in a plot of a piecewise function and the area we need to obtain. | 1,000 | Print one integer — the minimum possible height of a plot consisting of $$$2n+1$$$ vertices and with an area equals $$$k$$$. It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | standard output | |
PASSED | 84b2a502b450601e2483cfbc45988f02 | train_002.jsonl | 1536330900 | You are given a set of $$$2n+1$$$ integer points on a Cartesian plane. Points are numbered from $$$0$$$ to $$$2n$$$ inclusive. Let $$$P_i$$$ be the $$$i$$$-th point. The $$$x$$$-coordinate of the point $$$P_i$$$ equals $$$i$$$. The $$$y$$$-coordinate of the point $$$P_i$$$ equals zero (initially). Thus, initially $$$P_i=(i,0)$$$.The given points are vertices of a plot of a piecewise function. The $$$j$$$-th piece of the function is the segment $$$P_{j}P_{j + 1}$$$.In one move you can increase the $$$y$$$-coordinate of any point with odd $$$x$$$-coordinate (i.e. such points are $$$P_1, P_3, \dots, P_{2n-1}$$$) by $$$1$$$. Note that the corresponding segments also change.For example, the following plot shows a function for $$$n=3$$$ (i.e. number of points is $$$2\cdot3+1=7$$$) in which we increased the $$$y$$$-coordinate of the point $$$P_1$$$ three times and $$$y$$$-coordinate of the point $$$P_5$$$ one time: Let the area of the plot be the area below this plot and above the coordinate axis OX. For example, the area of the plot on the picture above is 4 (the light blue area on the picture above is the area of the plot drawn on it).Let the height of the plot be the maximum $$$y$$$-coordinate among all initial points in the plot (i.e. points $$$P_0, P_1, \dots, P_{2n}$$$). The height of the plot on the picture above is 3.Your problem is to say which minimum possible height can have the plot consisting of $$$2n+1$$$ vertices and having an area equal to $$$k$$$. Note that it is unnecessary to minimize the number of moves.It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | 256 megabytes |
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.util.Scanner;
public class Function {
public static Integer[] getArray(int size) {
Integer[] array = new Integer[size];
for (int i = 0; i < size; i++) {
array[i] = sr.nextInt();
}
return array;
}
public static int[][] getMatrix(int sizeI, int sizeJ) {
int[][] array = new int[sizeI][sizeJ];
for (int i = 0; i < sizeI; i++) {
for (int j = 0; j < sizeJ; j++) {
array[i][j] = sr.nextInt();
}
}
return array;
}
public static boolean isSimpleNumber(int val) {
for (int i = 2; i <= Math.sqrt(val); i++) {
if (val % i == 0)
return false;
}
return true;
}
public static int NOD(int a, int b) {
while (a != 0 && b != 0) {
if (a > b) {
a = a % b;
} else {
b = b % a;
}
}
return a + b;
}
public static int NOK(int a, int b) {
return a * b / NOD(a, b);
}
public static long factorial(long i) {
long res = 1;
for (int j = 2; j <= i; j++) {
res *= j;
}
return res;
}
static char letters[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
static Scanner sr = new Scanner(System.in);
static int a[] = {0, 1, 2};
public static void main(String[] args) throws IOException {
long n = sr.nextLong();
long k = sr.nextLong();
BigDecimal first, second, result;
first = new BigDecimal(n);
second = new BigDecimal(k);
result = second.divide(first, 0, RoundingMode.CEILING);
System.out.println(result);
}
} | Java | ["4 3", "4 12", "999999999999999999 999999999999999986"] | 1 second | ["1", "3", "1"] | NoteOne of the possible answers to the first example: The area of this plot is 3, the height of this plot is 1.There is only one possible answer to the second example: The area of this plot is 12, the height of this plot is 3. | Java 8 | standard input | [
"math"
] | 31014efa929af5e4b7d9987bd9b59918 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^{18}$$$) — the number of vertices in a plot of a piecewise function and the area we need to obtain. | 1,000 | Print one integer — the minimum possible height of a plot consisting of $$$2n+1$$$ vertices and with an area equals $$$k$$$. It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | standard output | |
PASSED | 46fd7a837066147f7fb01f62585d63b3 | train_002.jsonl | 1536330900 | You are given a set of $$$2n+1$$$ integer points on a Cartesian plane. Points are numbered from $$$0$$$ to $$$2n$$$ inclusive. Let $$$P_i$$$ be the $$$i$$$-th point. The $$$x$$$-coordinate of the point $$$P_i$$$ equals $$$i$$$. The $$$y$$$-coordinate of the point $$$P_i$$$ equals zero (initially). Thus, initially $$$P_i=(i,0)$$$.The given points are vertices of a plot of a piecewise function. The $$$j$$$-th piece of the function is the segment $$$P_{j}P_{j + 1}$$$.In one move you can increase the $$$y$$$-coordinate of any point with odd $$$x$$$-coordinate (i.e. such points are $$$P_1, P_3, \dots, P_{2n-1}$$$) by $$$1$$$. Note that the corresponding segments also change.For example, the following plot shows a function for $$$n=3$$$ (i.e. number of points is $$$2\cdot3+1=7$$$) in which we increased the $$$y$$$-coordinate of the point $$$P_1$$$ three times and $$$y$$$-coordinate of the point $$$P_5$$$ one time: Let the area of the plot be the area below this plot and above the coordinate axis OX. For example, the area of the plot on the picture above is 4 (the light blue area on the picture above is the area of the plot drawn on it).Let the height of the plot be the maximum $$$y$$$-coordinate among all initial points in the plot (i.e. points $$$P_0, P_1, \dots, P_{2n}$$$). The height of the plot on the picture above is 3.Your problem is to say which minimum possible height can have the plot consisting of $$$2n+1$$$ vertices and having an area equal to $$$k$$$. Note that it is unnecessary to minimize the number of moves.It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | 256 megabytes | import java.util.Scanner;
public class A {
public static void main(String[] args) {
Scanner console = new Scanner(System.in);
long n = console.nextLong();
long k = console.nextLong();
System.out.println((long) (((k - 1) / n + 1)));
}
}
| Java | ["4 3", "4 12", "999999999999999999 999999999999999986"] | 1 second | ["1", "3", "1"] | NoteOne of the possible answers to the first example: The area of this plot is 3, the height of this plot is 1.There is only one possible answer to the second example: The area of this plot is 12, the height of this plot is 3. | Java 8 | standard input | [
"math"
] | 31014efa929af5e4b7d9987bd9b59918 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^{18}$$$) — the number of vertices in a plot of a piecewise function and the area we need to obtain. | 1,000 | Print one integer — the minimum possible height of a plot consisting of $$$2n+1$$$ vertices and with an area equals $$$k$$$. It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | standard output | |
PASSED | 65ad5a2b9b47ad68243d9c10c026067b | train_002.jsonl | 1536330900 | You are given a set of $$$2n+1$$$ integer points on a Cartesian plane. Points are numbered from $$$0$$$ to $$$2n$$$ inclusive. Let $$$P_i$$$ be the $$$i$$$-th point. The $$$x$$$-coordinate of the point $$$P_i$$$ equals $$$i$$$. The $$$y$$$-coordinate of the point $$$P_i$$$ equals zero (initially). Thus, initially $$$P_i=(i,0)$$$.The given points are vertices of a plot of a piecewise function. The $$$j$$$-th piece of the function is the segment $$$P_{j}P_{j + 1}$$$.In one move you can increase the $$$y$$$-coordinate of any point with odd $$$x$$$-coordinate (i.e. such points are $$$P_1, P_3, \dots, P_{2n-1}$$$) by $$$1$$$. Note that the corresponding segments also change.For example, the following plot shows a function for $$$n=3$$$ (i.e. number of points is $$$2\cdot3+1=7$$$) in which we increased the $$$y$$$-coordinate of the point $$$P_1$$$ three times and $$$y$$$-coordinate of the point $$$P_5$$$ one time: Let the area of the plot be the area below this plot and above the coordinate axis OX. For example, the area of the plot on the picture above is 4 (the light blue area on the picture above is the area of the plot drawn on it).Let the height of the plot be the maximum $$$y$$$-coordinate among all initial points in the plot (i.e. points $$$P_0, P_1, \dots, P_{2n}$$$). The height of the plot on the picture above is 3.Your problem is to say which minimum possible height can have the plot consisting of $$$2n+1$$$ vertices and having an area equal to $$$k$$$. Note that it is unnecessary to minimize the number of moves.It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;
/**
* @author khokharnikunj8
*/
public class Main {
public static void main(String[] args) {
new Thread(null, new Runnable() {
public void run() {
new Main().solve();
}
}, "1", 1 << 26).start();
}
void solve() {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
ScanReader in = new ScanReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
AFunctionHeight solver = new AFunctionHeight();
solver.solve(1, in, out);
out.close();
}
static class AFunctionHeight {
public void solve(int testNumber, ScanReader in, PrintWriter out) {
long n = in.scanLong();
long k = in.scanLong();
out.println((k / n + (k % n != 0 ? 1 : 0)));
}
}
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++];
}
private boolean isWhiteSpace(int n) {
if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
else return false;
}
public long scanLong() {
long integer = 0;
int n = scan();
while (isWhiteSpace(n)) n = scan();
int neg = 1;
if (n == '-') {
neg = -1;
n = scan();
}
while (!isWhiteSpace(n)) {
if (n >= '0' && n <= '9') {
integer *= 10;
integer += n - '0';
n = scan();
}
}
return neg * integer;
}
}
}
| Java | ["4 3", "4 12", "999999999999999999 999999999999999986"] | 1 second | ["1", "3", "1"] | NoteOne of the possible answers to the first example: The area of this plot is 3, the height of this plot is 1.There is only one possible answer to the second example: The area of this plot is 12, the height of this plot is 3. | Java 8 | standard input | [
"math"
] | 31014efa929af5e4b7d9987bd9b59918 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^{18}$$$) — the number of vertices in a plot of a piecewise function and the area we need to obtain. | 1,000 | Print one integer — the minimum possible height of a plot consisting of $$$2n+1$$$ vertices and with an area equals $$$k$$$. It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | standard output | |
PASSED | eaa1198143dc76247d04436d717bf754 | train_002.jsonl | 1536330900 | You are given a set of $$$2n+1$$$ integer points on a Cartesian plane. Points are numbered from $$$0$$$ to $$$2n$$$ inclusive. Let $$$P_i$$$ be the $$$i$$$-th point. The $$$x$$$-coordinate of the point $$$P_i$$$ equals $$$i$$$. The $$$y$$$-coordinate of the point $$$P_i$$$ equals zero (initially). Thus, initially $$$P_i=(i,0)$$$.The given points are vertices of a plot of a piecewise function. The $$$j$$$-th piece of the function is the segment $$$P_{j}P_{j + 1}$$$.In one move you can increase the $$$y$$$-coordinate of any point with odd $$$x$$$-coordinate (i.e. such points are $$$P_1, P_3, \dots, P_{2n-1}$$$) by $$$1$$$. Note that the corresponding segments also change.For example, the following plot shows a function for $$$n=3$$$ (i.e. number of points is $$$2\cdot3+1=7$$$) in which we increased the $$$y$$$-coordinate of the point $$$P_1$$$ three times and $$$y$$$-coordinate of the point $$$P_5$$$ one time: Let the area of the plot be the area below this plot and above the coordinate axis OX. For example, the area of the plot on the picture above is 4 (the light blue area on the picture above is the area of the plot drawn on it).Let the height of the plot be the maximum $$$y$$$-coordinate among all initial points in the plot (i.e. points $$$P_0, P_1, \dots, P_{2n}$$$). The height of the plot on the picture above is 3.Your problem is to say which minimum possible height can have the plot consisting of $$$2n+1$$$ vertices and having an area equal to $$$k$$$. Note that it is unnecessary to minimize the number of moves.It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | 256 megabytes | import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
long x = scan.nextLong();
long y = scan.nextLong();
long z = y/x ;
if(y%x != 0){
z++;
}
System.out.println(z);
}
}
| Java | ["4 3", "4 12", "999999999999999999 999999999999999986"] | 1 second | ["1", "3", "1"] | NoteOne of the possible answers to the first example: The area of this plot is 3, the height of this plot is 1.There is only one possible answer to the second example: The area of this plot is 12, the height of this plot is 3. | Java 8 | standard input | [
"math"
] | 31014efa929af5e4b7d9987bd9b59918 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^{18}$$$) — the number of vertices in a plot of a piecewise function and the area we need to obtain. | 1,000 | Print one integer — the minimum possible height of a plot consisting of $$$2n+1$$$ vertices and with an area equals $$$k$$$. It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | standard output | |
PASSED | ac7751cb092a435aa6f6416f5b1139e2 | train_002.jsonl | 1536330900 | You are given a set of $$$2n+1$$$ integer points on a Cartesian plane. Points are numbered from $$$0$$$ to $$$2n$$$ inclusive. Let $$$P_i$$$ be the $$$i$$$-th point. The $$$x$$$-coordinate of the point $$$P_i$$$ equals $$$i$$$. The $$$y$$$-coordinate of the point $$$P_i$$$ equals zero (initially). Thus, initially $$$P_i=(i,0)$$$.The given points are vertices of a plot of a piecewise function. The $$$j$$$-th piece of the function is the segment $$$P_{j}P_{j + 1}$$$.In one move you can increase the $$$y$$$-coordinate of any point with odd $$$x$$$-coordinate (i.e. such points are $$$P_1, P_3, \dots, P_{2n-1}$$$) by $$$1$$$. Note that the corresponding segments also change.For example, the following plot shows a function for $$$n=3$$$ (i.e. number of points is $$$2\cdot3+1=7$$$) in which we increased the $$$y$$$-coordinate of the point $$$P_1$$$ three times and $$$y$$$-coordinate of the point $$$P_5$$$ one time: Let the area of the plot be the area below this plot and above the coordinate axis OX. For example, the area of the plot on the picture above is 4 (the light blue area on the picture above is the area of the plot drawn on it).Let the height of the plot be the maximum $$$y$$$-coordinate among all initial points in the plot (i.e. points $$$P_0, P_1, \dots, P_{2n}$$$). The height of the plot on the picture above is 3.Your problem is to say which minimum possible height can have the plot consisting of $$$2n+1$$$ vertices and having an area equal to $$$k$$$. Note that it is unnecessary to minimize the number of moves.It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | 256 megabytes | import java.util.Scanner;
public class Triangle {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
long n = scan.nextLong();
long k = scan.nextLong();
long x = (n + k - 1)/n;
System.out.println(x);
}
}
| Java | ["4 3", "4 12", "999999999999999999 999999999999999986"] | 1 second | ["1", "3", "1"] | NoteOne of the possible answers to the first example: The area of this plot is 3, the height of this plot is 1.There is only one possible answer to the second example: The area of this plot is 12, the height of this plot is 3. | Java 8 | standard input | [
"math"
] | 31014efa929af5e4b7d9987bd9b59918 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^{18}$$$) — the number of vertices in a plot of a piecewise function and the area we need to obtain. | 1,000 | Print one integer — the minimum possible height of a plot consisting of $$$2n+1$$$ vertices and with an area equals $$$k$$$. It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | standard output | |
PASSED | 2cbfc1b118c944115ca520bc7ad8bee6 | train_002.jsonl | 1536330900 | You are given a set of $$$2n+1$$$ integer points on a Cartesian plane. Points are numbered from $$$0$$$ to $$$2n$$$ inclusive. Let $$$P_i$$$ be the $$$i$$$-th point. The $$$x$$$-coordinate of the point $$$P_i$$$ equals $$$i$$$. The $$$y$$$-coordinate of the point $$$P_i$$$ equals zero (initially). Thus, initially $$$P_i=(i,0)$$$.The given points are vertices of a plot of a piecewise function. The $$$j$$$-th piece of the function is the segment $$$P_{j}P_{j + 1}$$$.In one move you can increase the $$$y$$$-coordinate of any point with odd $$$x$$$-coordinate (i.e. such points are $$$P_1, P_3, \dots, P_{2n-1}$$$) by $$$1$$$. Note that the corresponding segments also change.For example, the following plot shows a function for $$$n=3$$$ (i.e. number of points is $$$2\cdot3+1=7$$$) in which we increased the $$$y$$$-coordinate of the point $$$P_1$$$ three times and $$$y$$$-coordinate of the point $$$P_5$$$ one time: Let the area of the plot be the area below this plot and above the coordinate axis OX. For example, the area of the plot on the picture above is 4 (the light blue area on the picture above is the area of the plot drawn on it).Let the height of the plot be the maximum $$$y$$$-coordinate among all initial points in the plot (i.e. points $$$P_0, P_1, \dots, P_{2n}$$$). The height of the plot on the picture above is 3.Your problem is to say which minimum possible height can have the plot consisting of $$$2n+1$$$ vertices and having an area equal to $$$k$$$. Note that it is unnecessary to minimize the number of moves.It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | 256 megabytes | import java.io.*;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.*;
public class Solu {
static StringBuffer str = new StringBuffer();
static InputReader in = new InputReader(System.in);
static int mm=1000000007;
public static void main(String[] args) {
int i,j,it,t;
long n;
n=in.nextLong();
long k=in.nextLong();
long hh=k/n;
if(k%n==0){
System.out.println(hh);
}else{
System.out.println(hh+1);
}
}
static long gcd(long a, long b){
return (b==0)?a:gcd(b,a%b);
}
static int gcdi(int a, int b){
return (b==0)?a:gcdi(b,a%b);
}
public static void ap(String st){
str.append(st);
}
public static void pn() {
System.out.println(str);
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1) {
throw new UnknownError();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new UnknownError();
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public int peek() {
if (numChars == -1) {
return -1;
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
return -1;
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar];
}
public void skip(int x) {
while (x-- > 0) {
read();
}
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public String nextString() {
return next();
}
public String next() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuffer res = new StringBuffer();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public String nextLine() {
StringBuffer buf = new StringBuffer();
int c = read();
while (c != '\n' && c != -1) {
if (c != '\r') {
buf.appendCodePoint(c);
}
c = read();
}
return buf.toString();
}
public double nextDouble() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E') {
return res * Math.pow(10, nextInt());
}
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
}
if (c == '.') {
c = read();
double m = 1;
while (!isSpaceChar(c)) {
if (c == 'e' || c == 'E') {
return res * Math.pow(10, nextInt());
}
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public boolean hasNext() {
int value;
while (isSpaceChar(value = peek()) && value != -1) {
read();
}
return value != -1;
}
private boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
}
}
| Java | ["4 3", "4 12", "999999999999999999 999999999999999986"] | 1 second | ["1", "3", "1"] | NoteOne of the possible answers to the first example: The area of this plot is 3, the height of this plot is 1.There is only one possible answer to the second example: The area of this plot is 12, the height of this plot is 3. | Java 8 | standard input | [
"math"
] | 31014efa929af5e4b7d9987bd9b59918 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^{18}$$$) — the number of vertices in a plot of a piecewise function and the area we need to obtain. | 1,000 | Print one integer — the minimum possible height of a plot consisting of $$$2n+1$$$ vertices and with an area equals $$$k$$$. It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | standard output | |
PASSED | 10eb713f7d3e034c82835ce5871a753f | train_002.jsonl | 1536330900 | You are given a set of $$$2n+1$$$ integer points on a Cartesian plane. Points are numbered from $$$0$$$ to $$$2n$$$ inclusive. Let $$$P_i$$$ be the $$$i$$$-th point. The $$$x$$$-coordinate of the point $$$P_i$$$ equals $$$i$$$. The $$$y$$$-coordinate of the point $$$P_i$$$ equals zero (initially). Thus, initially $$$P_i=(i,0)$$$.The given points are vertices of a plot of a piecewise function. The $$$j$$$-th piece of the function is the segment $$$P_{j}P_{j + 1}$$$.In one move you can increase the $$$y$$$-coordinate of any point with odd $$$x$$$-coordinate (i.e. such points are $$$P_1, P_3, \dots, P_{2n-1}$$$) by $$$1$$$. Note that the corresponding segments also change.For example, the following plot shows a function for $$$n=3$$$ (i.e. number of points is $$$2\cdot3+1=7$$$) in which we increased the $$$y$$$-coordinate of the point $$$P_1$$$ three times and $$$y$$$-coordinate of the point $$$P_5$$$ one time: Let the area of the plot be the area below this plot and above the coordinate axis OX. For example, the area of the plot on the picture above is 4 (the light blue area on the picture above is the area of the plot drawn on it).Let the height of the plot be the maximum $$$y$$$-coordinate among all initial points in the plot (i.e. points $$$P_0, P_1, \dots, P_{2n}$$$). The height of the plot on the picture above is 3.Your problem is to say which minimum possible height can have the plot consisting of $$$2n+1$$$ vertices and having an area equal to $$$k$$$. Note that it is unnecessary to minimize the number of moves.It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | 256 megabytes | import java.io.DataInputStream;
import java.io.IOException;
public class Main {
public static void main(String... args) throws IOException {
Reader reader = new Reader();
long n = reader.nextInt();
long k = reader.nextInt();
System.out.println(-Math.floorDiv(-k, n));
}
static class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
Reader() {
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
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);
}
//Will read words with space as delimiters
public String nextWord() throws IOException {
byte[] buf = new byte[64]; // word length
byte c = read();
while (c == ' ')
c = read();
int cnt = 0;
do {
buf[cnt++] = c;
c = read();
} while (c != ' ' && c != '\n');
return new String(buf, 0, cnt);
}
public long nextInt() 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;
}
private void fillBuffer() throws IOException {
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException {
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException {
if (din == null)
return;
din.close();
}
}
}
| Java | ["4 3", "4 12", "999999999999999999 999999999999999986"] | 1 second | ["1", "3", "1"] | NoteOne of the possible answers to the first example: The area of this plot is 3, the height of this plot is 1.There is only one possible answer to the second example: The area of this plot is 12, the height of this plot is 3. | Java 8 | standard input | [
"math"
] | 31014efa929af5e4b7d9987bd9b59918 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^{18}$$$) — the number of vertices in a plot of a piecewise function and the area we need to obtain. | 1,000 | Print one integer — the minimum possible height of a plot consisting of $$$2n+1$$$ vertices and with an area equals $$$k$$$. It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | standard output | |
PASSED | 7b0e8ab37755d3c59a09c8206c95180c | train_002.jsonl | 1536330900 | You are given a set of $$$2n+1$$$ integer points on a Cartesian plane. Points are numbered from $$$0$$$ to $$$2n$$$ inclusive. Let $$$P_i$$$ be the $$$i$$$-th point. The $$$x$$$-coordinate of the point $$$P_i$$$ equals $$$i$$$. The $$$y$$$-coordinate of the point $$$P_i$$$ equals zero (initially). Thus, initially $$$P_i=(i,0)$$$.The given points are vertices of a plot of a piecewise function. The $$$j$$$-th piece of the function is the segment $$$P_{j}P_{j + 1}$$$.In one move you can increase the $$$y$$$-coordinate of any point with odd $$$x$$$-coordinate (i.e. such points are $$$P_1, P_3, \dots, P_{2n-1}$$$) by $$$1$$$. Note that the corresponding segments also change.For example, the following plot shows a function for $$$n=3$$$ (i.e. number of points is $$$2\cdot3+1=7$$$) in which we increased the $$$y$$$-coordinate of the point $$$P_1$$$ three times and $$$y$$$-coordinate of the point $$$P_5$$$ one time: Let the area of the plot be the area below this plot and above the coordinate axis OX. For example, the area of the plot on the picture above is 4 (the light blue area on the picture above is the area of the plot drawn on it).Let the height of the plot be the maximum $$$y$$$-coordinate among all initial points in the plot (i.e. points $$$P_0, P_1, \dots, P_{2n}$$$). The height of the plot on the picture above is 3.Your problem is to say which minimum possible height can have the plot consisting of $$$2n+1$$$ vertices and having an area equal to $$$k$$$. Note that it is unnecessary to minimize the number of moves.It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | 256 megabytes | import java.io.DataInputStream;
import java.io.IOException;
public class R50PA {
public static void main(String... args) throws IOException {
Reader reader = new Reader();
long n = reader.nextInt();
long k = reader.nextInt();
System.out.println(-Math.floorDiv(-k, n));
}
static class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
Reader() {
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
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);
}
//Will read words with space as delimiters
public String nextWord() throws IOException {
byte[] buf = new byte[64]; // word length
byte c = read();
while (c == ' ')
c = read();
int cnt = 0;
do {
buf[cnt++] = c;
c = read();
} while (c != ' ' && c != '\n');
return new String(buf, 0, cnt);
}
public long nextInt() 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;
}
private void fillBuffer() throws IOException {
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException {
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException {
if (din == null)
return;
din.close();
}
}
}
| Java | ["4 3", "4 12", "999999999999999999 999999999999999986"] | 1 second | ["1", "3", "1"] | NoteOne of the possible answers to the first example: The area of this plot is 3, the height of this plot is 1.There is only one possible answer to the second example: The area of this plot is 12, the height of this plot is 3. | Java 8 | standard input | [
"math"
] | 31014efa929af5e4b7d9987bd9b59918 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^{18}$$$) — the number of vertices in a plot of a piecewise function and the area we need to obtain. | 1,000 | Print one integer — the minimum possible height of a plot consisting of $$$2n+1$$$ vertices and with an area equals $$$k$$$. It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | standard output | |
PASSED | 18899f33ad3f5f875f1951a3e98d6d1f | train_002.jsonl | 1536330900 | You are given a set of $$$2n+1$$$ integer points on a Cartesian plane. Points are numbered from $$$0$$$ to $$$2n$$$ inclusive. Let $$$P_i$$$ be the $$$i$$$-th point. The $$$x$$$-coordinate of the point $$$P_i$$$ equals $$$i$$$. The $$$y$$$-coordinate of the point $$$P_i$$$ equals zero (initially). Thus, initially $$$P_i=(i,0)$$$.The given points are vertices of a plot of a piecewise function. The $$$j$$$-th piece of the function is the segment $$$P_{j}P_{j + 1}$$$.In one move you can increase the $$$y$$$-coordinate of any point with odd $$$x$$$-coordinate (i.e. such points are $$$P_1, P_3, \dots, P_{2n-1}$$$) by $$$1$$$. Note that the corresponding segments also change.For example, the following plot shows a function for $$$n=3$$$ (i.e. number of points is $$$2\cdot3+1=7$$$) in which we increased the $$$y$$$-coordinate of the point $$$P_1$$$ three times and $$$y$$$-coordinate of the point $$$P_5$$$ one time: Let the area of the plot be the area below this plot and above the coordinate axis OX. For example, the area of the plot on the picture above is 4 (the light blue area on the picture above is the area of the plot drawn on it).Let the height of the plot be the maximum $$$y$$$-coordinate among all initial points in the plot (i.e. points $$$P_0, P_1, \dots, P_{2n}$$$). The height of the plot on the picture above is 3.Your problem is to say which minimum possible height can have the plot consisting of $$$2n+1$$$ vertices and having an area equal to $$$k$$$. Note that it is unnecessary to minimize the number of moves.It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
public class EDUA50 {
public static void main(String[] args) {
Scanner s = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
long n = s.nextLong();
long k = s.nextLong();
if (k <= n) {
System.out.println("1");
} else {
long ans = (k+n-1) / n;
System.out.println(ans);
}
s.close();
}
}
| Java | ["4 3", "4 12", "999999999999999999 999999999999999986"] | 1 second | ["1", "3", "1"] | NoteOne of the possible answers to the first example: The area of this plot is 3, the height of this plot is 1.There is only one possible answer to the second example: The area of this plot is 12, the height of this plot is 3. | Java 8 | standard input | [
"math"
] | 31014efa929af5e4b7d9987bd9b59918 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^{18}$$$) — the number of vertices in a plot of a piecewise function and the area we need to obtain. | 1,000 | Print one integer — the minimum possible height of a plot consisting of $$$2n+1$$$ vertices and with an area equals $$$k$$$. It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | standard output | |
PASSED | 5c39c924ae98ccb39a8d6379250e634d | train_002.jsonl | 1536330900 | You are given a set of $$$2n+1$$$ integer points on a Cartesian plane. Points are numbered from $$$0$$$ to $$$2n$$$ inclusive. Let $$$P_i$$$ be the $$$i$$$-th point. The $$$x$$$-coordinate of the point $$$P_i$$$ equals $$$i$$$. The $$$y$$$-coordinate of the point $$$P_i$$$ equals zero (initially). Thus, initially $$$P_i=(i,0)$$$.The given points are vertices of a plot of a piecewise function. The $$$j$$$-th piece of the function is the segment $$$P_{j}P_{j + 1}$$$.In one move you can increase the $$$y$$$-coordinate of any point with odd $$$x$$$-coordinate (i.e. such points are $$$P_1, P_3, \dots, P_{2n-1}$$$) by $$$1$$$. Note that the corresponding segments also change.For example, the following plot shows a function for $$$n=3$$$ (i.e. number of points is $$$2\cdot3+1=7$$$) in which we increased the $$$y$$$-coordinate of the point $$$P_1$$$ three times and $$$y$$$-coordinate of the point $$$P_5$$$ one time: Let the area of the plot be the area below this plot and above the coordinate axis OX. For example, the area of the plot on the picture above is 4 (the light blue area on the picture above is the area of the plot drawn on it).Let the height of the plot be the maximum $$$y$$$-coordinate among all initial points in the plot (i.e. points $$$P_0, P_1, \dots, P_{2n}$$$). The height of the plot on the picture above is 3.Your problem is to say which minimum possible height can have the plot consisting of $$$2n+1$$$ vertices and having an area equal to $$$k$$$. Note that it is unnecessary to minimize the number of moves.It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class Main
{
static long mod=1000000007;
public static void main(String[] args) throws IOException
{
FastReader in=new FastReader();
PrintWriter pw=new PrintWriter(System.out);
long n=in.nextLong();
long k=in.nextLong();
long ans=k/n;
if(k%n!=0)
ans++;
pw.print(ans);
pw.flush();
}
}
class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br=new BufferedReader(new InputStreamReader(System.in));
}
public String next() throws IOException
{
if(st==null || !st.hasMoreElements())
{
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());
}
} | Java | ["4 3", "4 12", "999999999999999999 999999999999999986"] | 1 second | ["1", "3", "1"] | NoteOne of the possible answers to the first example: The area of this plot is 3, the height of this plot is 1.There is only one possible answer to the second example: The area of this plot is 12, the height of this plot is 3. | Java 8 | standard input | [
"math"
] | 31014efa929af5e4b7d9987bd9b59918 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^{18}$$$) — the number of vertices in a plot of a piecewise function and the area we need to obtain. | 1,000 | Print one integer — the minimum possible height of a plot consisting of $$$2n+1$$$ vertices and with an area equals $$$k$$$. It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | standard output | |
PASSED | 33e2f7689b0d558d3064a5850eacd592 | train_002.jsonl | 1536330900 | You are given a set of $$$2n+1$$$ integer points on a Cartesian plane. Points are numbered from $$$0$$$ to $$$2n$$$ inclusive. Let $$$P_i$$$ be the $$$i$$$-th point. The $$$x$$$-coordinate of the point $$$P_i$$$ equals $$$i$$$. The $$$y$$$-coordinate of the point $$$P_i$$$ equals zero (initially). Thus, initially $$$P_i=(i,0)$$$.The given points are vertices of a plot of a piecewise function. The $$$j$$$-th piece of the function is the segment $$$P_{j}P_{j + 1}$$$.In one move you can increase the $$$y$$$-coordinate of any point with odd $$$x$$$-coordinate (i.e. such points are $$$P_1, P_3, \dots, P_{2n-1}$$$) by $$$1$$$. Note that the corresponding segments also change.For example, the following plot shows a function for $$$n=3$$$ (i.e. number of points is $$$2\cdot3+1=7$$$) in which we increased the $$$y$$$-coordinate of the point $$$P_1$$$ three times and $$$y$$$-coordinate of the point $$$P_5$$$ one time: Let the area of the plot be the area below this plot and above the coordinate axis OX. For example, the area of the plot on the picture above is 4 (the light blue area on the picture above is the area of the plot drawn on it).Let the height of the plot be the maximum $$$y$$$-coordinate among all initial points in the plot (i.e. points $$$P_0, P_1, \dots, P_{2n}$$$). The height of the plot on the picture above is 3.Your problem is to say which minimum possible height can have the plot consisting of $$$2n+1$$$ vertices and having an area equal to $$$k$$$. Note that it is unnecessary to minimize the number of moves.It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | 256 megabytes | import java.util.Scanner;
public class FunctionalHeights {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
long n = input.nextLong();
long k = input.nextLong();
//long i = n;
//int j = 1;
System.out.println((k+n-1)/n);
}
}
| Java | ["4 3", "4 12", "999999999999999999 999999999999999986"] | 1 second | ["1", "3", "1"] | NoteOne of the possible answers to the first example: The area of this plot is 3, the height of this plot is 1.There is only one possible answer to the second example: The area of this plot is 12, the height of this plot is 3. | Java 8 | standard input | [
"math"
] | 31014efa929af5e4b7d9987bd9b59918 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^{18}$$$) — the number of vertices in a plot of a piecewise function and the area we need to obtain. | 1,000 | Print one integer — the minimum possible height of a plot consisting of $$$2n+1$$$ vertices and with an area equals $$$k$$$. It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | standard output | |
PASSED | b9f5f83c1c269e1caf3f0de3bd8c6f7e | train_002.jsonl | 1536330900 | You are given a set of $$$2n+1$$$ integer points on a Cartesian plane. Points are numbered from $$$0$$$ to $$$2n$$$ inclusive. Let $$$P_i$$$ be the $$$i$$$-th point. The $$$x$$$-coordinate of the point $$$P_i$$$ equals $$$i$$$. The $$$y$$$-coordinate of the point $$$P_i$$$ equals zero (initially). Thus, initially $$$P_i=(i,0)$$$.The given points are vertices of a plot of a piecewise function. The $$$j$$$-th piece of the function is the segment $$$P_{j}P_{j + 1}$$$.In one move you can increase the $$$y$$$-coordinate of any point with odd $$$x$$$-coordinate (i.e. such points are $$$P_1, P_3, \dots, P_{2n-1}$$$) by $$$1$$$. Note that the corresponding segments also change.For example, the following plot shows a function for $$$n=3$$$ (i.e. number of points is $$$2\cdot3+1=7$$$) in which we increased the $$$y$$$-coordinate of the point $$$P_1$$$ three times and $$$y$$$-coordinate of the point $$$P_5$$$ one time: Let the area of the plot be the area below this plot and above the coordinate axis OX. For example, the area of the plot on the picture above is 4 (the light blue area on the picture above is the area of the plot drawn on it).Let the height of the plot be the maximum $$$y$$$-coordinate among all initial points in the plot (i.e. points $$$P_0, P_1, \dots, P_{2n}$$$). The height of the plot on the picture above is 3.Your problem is to say which minimum possible height can have the plot consisting of $$$2n+1$$$ vertices and having an area equal to $$$k$$$. Note that it is unnecessary to minimize the number of moves.It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
public class EDU_50 {
static Reader r = new Reader();
static PrintWriter out = new PrintWriter(System.out);
private static long binarySearch(long n, long k) {
long ans = Long.MAX_VALUE;
long lt = 1, rt = (long) 1e18;
while (lt <= rt) {
long mid = (lt + rt) / 2;
if (n * mid >= k) {
ans = Math.min(ans, mid);
rt = mid - 1;
} else {
lt = mid + 1;
}
}
return ans;
}
private static void solve1() throws IOException {
long n = r.nextLong();
long k = r.nextLong();
long ans = k / n;
if (ans * n < k) {
ans++;
}
out.print(ans);
out.close();
}
private static void solve2() throws IOException {
int t = r.nextInt();
StringBuilder res = new StringBuilder();
while (t-- > 0) {
int n = r.nextInt();
res.append(false).append("\n");
}
out.print(res);
out.close();
}
private static void solve3() throws IOException {
int t = r.nextInt();
StringBuilder res = new StringBuilder();
while (t-- > 0) {
int n = r.nextInt();
res.append(false).append("\n");
}
out.print(res);
out.close();
}
private static void solve4() throws IOException {
int t = r.nextInt();
StringBuilder res = new StringBuilder();
while (t-- > 0) {
int n = r.nextInt();
res.append(false).append("\n");
}
out.print(res);
out.close();
}
private static void solve5() throws IOException {
int t = r.nextInt();
StringBuilder res = new StringBuilder();
while (t-- > 0) {
int n = r.nextInt();
res.append(false).append("\n");
}
out.print(res);
out.close();
}
private static void solve6() throws IOException {
int t = r.nextInt();
StringBuilder res = new StringBuilder();
while (t-- > 0) {
int n = r.nextInt();
res.append(false).append("\n");
}
out.print(res);
out.close();
}
public static void main(String[] args) throws IOException {
solve1();
// solve2();
// solve3();
// solve4();
// solve5();
// solve6();
}
static class Reader {
final private int BUFFER_SIZE = 1 << 12;
boolean consume = false;
private byte[] buffer;
private int bufferPointer, bytesRead;
private boolean reachedEnd = false;
public Reader() {
buffer = new byte[BUFFER_SIZE];
bufferPointer = 0;
bytesRead = 0;
}
public boolean hasNext() {
return !reachedEnd;
}
private void fillBuffer() throws IOException {
bytesRead = System.in.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1) {
buffer[0] = -1;
reachedEnd = true;
}
}
private void consumeSpaces() throws IOException {
while (read() <= ' ' && reachedEnd == false)
;
bufferPointer--;
}
private byte read() throws IOException {
if (bufferPointer == bytesRead) {
fillBuffer();
}
return buffer[bufferPointer++];
}
public String next() throws IOException {
StringBuilder sb = new StringBuilder();
consumeSpaces();
byte c = read();
do {
sb.append((char) c);
} while ((c = read()) > ' ');
if (consume) {
consumeSpaces();
}
if (sb.length() == 0) {
return null;
}
return sb.toString();
}
public String nextLine() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = br.readLine();
return str;
}
public int nextInt() throws IOException {
consumeSpaces();
int ret = 0;
byte c = read();
boolean neg = (c == '-');
if (neg) {
c = read();
}
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (consume) {
consumeSpaces();
}
if (neg) {
return -ret;
}
return ret;
}
public long nextLong() throws IOException {
consumeSpaces();
long ret = 0;
byte c = read();
boolean neg = (c == '-');
if (neg) {
c = read();
}
do {
ret = ret * 10L + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (consume) {
consumeSpaces();
}
if (neg) {
return -ret;
}
return ret;
}
public double nextDouble() throws IOException {
consumeSpaces();
double ret = 0;
double div = 1;
byte 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 (consume) {
consumeSpaces();
}
if (neg) {
return -ret;
}
return ret;
}
public int[] nextIntArray(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
return a;
}
public long[] nextLongArray(int n) throws IOException {
long[] a = new long[n];
for (int i = 0; i < n; i++) {
a[i] = nextLong();
}
return a;
}
public int[][] nextIntMatrix(int n, int m) throws IOException {
int[][] grid = new int[n][m];
for (int i = 0; i < n; i++) {
grid[i] = nextIntArray(m);
}
return grid;
}
public char[][] nextCharacterMatrix(int n) throws IOException {
char[][] a = new char[n][];
for (int i = 0; i < n; i++) {
a[i] = next().toCharArray();
}
return a;
}
public void close() throws IOException {
if (System.in == null) {
return;
} else {
System.in.close();
}
}
}
} | Java | ["4 3", "4 12", "999999999999999999 999999999999999986"] | 1 second | ["1", "3", "1"] | NoteOne of the possible answers to the first example: The area of this plot is 3, the height of this plot is 1.There is only one possible answer to the second example: The area of this plot is 12, the height of this plot is 3. | Java 8 | standard input | [
"math"
] | 31014efa929af5e4b7d9987bd9b59918 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^{18}$$$) — the number of vertices in a plot of a piecewise function and the area we need to obtain. | 1,000 | Print one integer — the minimum possible height of a plot consisting of $$$2n+1$$$ vertices and with an area equals $$$k$$$. It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | standard output | |
PASSED | 6806e6a53541c82e9095b3549bf675f9 | train_002.jsonl | 1536330900 | You are given a set of $$$2n+1$$$ integer points on a Cartesian plane. Points are numbered from $$$0$$$ to $$$2n$$$ inclusive. Let $$$P_i$$$ be the $$$i$$$-th point. The $$$x$$$-coordinate of the point $$$P_i$$$ equals $$$i$$$. The $$$y$$$-coordinate of the point $$$P_i$$$ equals zero (initially). Thus, initially $$$P_i=(i,0)$$$.The given points are vertices of a plot of a piecewise function. The $$$j$$$-th piece of the function is the segment $$$P_{j}P_{j + 1}$$$.In one move you can increase the $$$y$$$-coordinate of any point with odd $$$x$$$-coordinate (i.e. such points are $$$P_1, P_3, \dots, P_{2n-1}$$$) by $$$1$$$. Note that the corresponding segments also change.For example, the following plot shows a function for $$$n=3$$$ (i.e. number of points is $$$2\cdot3+1=7$$$) in which we increased the $$$y$$$-coordinate of the point $$$P_1$$$ three times and $$$y$$$-coordinate of the point $$$P_5$$$ one time: Let the area of the plot be the area below this plot and above the coordinate axis OX. For example, the area of the plot on the picture above is 4 (the light blue area on the picture above is the area of the plot drawn on it).Let the height of the plot be the maximum $$$y$$$-coordinate among all initial points in the plot (i.e. points $$$P_0, P_1, \dots, P_{2n}$$$). The height of the plot on the picture above is 3.Your problem is to say which minimum possible height can have the plot consisting of $$$2n+1$$$ vertices and having an area equal to $$$k$$$. Note that it is unnecessary to minimize the number of moves.It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args)
{
InputReader in = new InputReader(System.in);
OutputWriter out = new OutputWriter(System.out);
long n = in.nextLong();
long m = in.nextLong();
if (m%n==0)
out.printLine(m/n);
else
out.printLine((m/n)+1);
out.flush();
}
}
class pair implements Comparable
{
int key;
int value;
public pair(Object key, Object value) {
this.key = (int)key;
this.value=(int)value;
}
@Override
public int compareTo(Object o) {
pair temp =(pair)o;
return key-temp.key;
}
}
class Graph {
int n;
ArrayList<Integer>[] adjList;
public Graph(int n) {
this.n = n;
adjList = new ArrayList[n];
for (int i = 0; i < n; i++)
adjList[i] = new ArrayList<>();
}
}
class InputReader {
private final InputStream stream;
private final byte[] buf = new byte[8192];
private int curChar, snumChars;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (snumChars == -1)
throw new InputMismatchException();
if (curChar >= snumChars) {
curChar = 0;
try {
snumChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (snumChars <= 0)
return -1;
}
return buf[curChar++];
}
public int nextInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public int[] nextIntArray(int n) {
int a[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
return a;
}
public String readString() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public String nextLine() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
}
class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
public void printLine(Object... objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
public void flush() {
writer.flush();
}
} | Java | ["4 3", "4 12", "999999999999999999 999999999999999986"] | 1 second | ["1", "3", "1"] | NoteOne of the possible answers to the first example: The area of this plot is 3, the height of this plot is 1.There is only one possible answer to the second example: The area of this plot is 12, the height of this plot is 3. | Java 8 | standard input | [
"math"
] | 31014efa929af5e4b7d9987bd9b59918 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^{18}$$$) — the number of vertices in a plot of a piecewise function and the area we need to obtain. | 1,000 | Print one integer — the minimum possible height of a plot consisting of $$$2n+1$$$ vertices and with an area equals $$$k$$$. It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | standard output | |
PASSED | f33def517f44414ad0abb53f3ec7b9d2 | train_002.jsonl | 1536330900 | You are given a set of $$$2n+1$$$ integer points on a Cartesian plane. Points are numbered from $$$0$$$ to $$$2n$$$ inclusive. Let $$$P_i$$$ be the $$$i$$$-th point. The $$$x$$$-coordinate of the point $$$P_i$$$ equals $$$i$$$. The $$$y$$$-coordinate of the point $$$P_i$$$ equals zero (initially). Thus, initially $$$P_i=(i,0)$$$.The given points are vertices of a plot of a piecewise function. The $$$j$$$-th piece of the function is the segment $$$P_{j}P_{j + 1}$$$.In one move you can increase the $$$y$$$-coordinate of any point with odd $$$x$$$-coordinate (i.e. such points are $$$P_1, P_3, \dots, P_{2n-1}$$$) by $$$1$$$. Note that the corresponding segments also change.For example, the following plot shows a function for $$$n=3$$$ (i.e. number of points is $$$2\cdot3+1=7$$$) in which we increased the $$$y$$$-coordinate of the point $$$P_1$$$ three times and $$$y$$$-coordinate of the point $$$P_5$$$ one time: Let the area of the plot be the area below this plot and above the coordinate axis OX. For example, the area of the plot on the picture above is 4 (the light blue area on the picture above is the area of the plot drawn on it).Let the height of the plot be the maximum $$$y$$$-coordinate among all initial points in the plot (i.e. points $$$P_0, P_1, \dots, P_{2n}$$$). The height of the plot on the picture above is 3.Your problem is to say which minimum possible height can have the plot consisting of $$$2n+1$$$ vertices and having an area equal to $$$k$$$. Note that it is unnecessary to minimize the number of moves.It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | 256 megabytes | import java.util.Scanner;
public class App {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long n = sc.nextLong(),k = sc.nextLong();
System.out.print((n + k - 1) / n);
}
}
| Java | ["4 3", "4 12", "999999999999999999 999999999999999986"] | 1 second | ["1", "3", "1"] | NoteOne of the possible answers to the first example: The area of this plot is 3, the height of this plot is 1.There is only one possible answer to the second example: The area of this plot is 12, the height of this plot is 3. | Java 8 | standard input | [
"math"
] | 31014efa929af5e4b7d9987bd9b59918 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^{18}$$$) — the number of vertices in a plot of a piecewise function and the area we need to obtain. | 1,000 | Print one integer — the minimum possible height of a plot consisting of $$$2n+1$$$ vertices and with an area equals $$$k$$$. It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | standard output | |
PASSED | c2e5134a797f31a09d9156b24110522c | train_002.jsonl | 1536330900 | You are given a set of $$$2n+1$$$ integer points on a Cartesian plane. Points are numbered from $$$0$$$ to $$$2n$$$ inclusive. Let $$$P_i$$$ be the $$$i$$$-th point. The $$$x$$$-coordinate of the point $$$P_i$$$ equals $$$i$$$. The $$$y$$$-coordinate of the point $$$P_i$$$ equals zero (initially). Thus, initially $$$P_i=(i,0)$$$.The given points are vertices of a plot of a piecewise function. The $$$j$$$-th piece of the function is the segment $$$P_{j}P_{j + 1}$$$.In one move you can increase the $$$y$$$-coordinate of any point with odd $$$x$$$-coordinate (i.e. such points are $$$P_1, P_3, \dots, P_{2n-1}$$$) by $$$1$$$. Note that the corresponding segments also change.For example, the following plot shows a function for $$$n=3$$$ (i.e. number of points is $$$2\cdot3+1=7$$$) in which we increased the $$$y$$$-coordinate of the point $$$P_1$$$ three times and $$$y$$$-coordinate of the point $$$P_5$$$ one time: Let the area of the plot be the area below this plot and above the coordinate axis OX. For example, the area of the plot on the picture above is 4 (the light blue area on the picture above is the area of the plot drawn on it).Let the height of the plot be the maximum $$$y$$$-coordinate among all initial points in the plot (i.e. points $$$P_0, P_1, \dots, P_{2n}$$$). The height of the plot on the picture above is 3.Your problem is to say which minimum possible height can have the plot consisting of $$$2n+1$$$ vertices and having an area equal to $$$k$$$. Note that it is unnecessary to minimize the number of moves.It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | 256 megabytes | import java.util.Scanner;
public class A {
public static void main(String[] args) throws Exception {
Scanner in = new Scanner(System.in);
long n = in.nextLong();
long k = in.nextLong();
System.out.println((k - 1)/n + 1);
in.close();
}
}
| Java | ["4 3", "4 12", "999999999999999999 999999999999999986"] | 1 second | ["1", "3", "1"] | NoteOne of the possible answers to the first example: The area of this plot is 3, the height of this plot is 1.There is only one possible answer to the second example: The area of this plot is 12, the height of this plot is 3. | Java 8 | standard input | [
"math"
] | 31014efa929af5e4b7d9987bd9b59918 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^{18}$$$) — the number of vertices in a plot of a piecewise function and the area we need to obtain. | 1,000 | Print one integer — the minimum possible height of a plot consisting of $$$2n+1$$$ vertices and with an area equals $$$k$$$. It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | standard output | |
PASSED | d07d6c24bcad65d2ab1edba66eb66d60 | train_002.jsonl | 1536330900 | You are given a set of $$$2n+1$$$ integer points on a Cartesian plane. Points are numbered from $$$0$$$ to $$$2n$$$ inclusive. Let $$$P_i$$$ be the $$$i$$$-th point. The $$$x$$$-coordinate of the point $$$P_i$$$ equals $$$i$$$. The $$$y$$$-coordinate of the point $$$P_i$$$ equals zero (initially). Thus, initially $$$P_i=(i,0)$$$.The given points are vertices of a plot of a piecewise function. The $$$j$$$-th piece of the function is the segment $$$P_{j}P_{j + 1}$$$.In one move you can increase the $$$y$$$-coordinate of any point with odd $$$x$$$-coordinate (i.e. such points are $$$P_1, P_3, \dots, P_{2n-1}$$$) by $$$1$$$. Note that the corresponding segments also change.For example, the following plot shows a function for $$$n=3$$$ (i.e. number of points is $$$2\cdot3+1=7$$$) in which we increased the $$$y$$$-coordinate of the point $$$P_1$$$ three times and $$$y$$$-coordinate of the point $$$P_5$$$ one time: Let the area of the plot be the area below this plot and above the coordinate axis OX. For example, the area of the plot on the picture above is 4 (the light blue area on the picture above is the area of the plot drawn on it).Let the height of the plot be the maximum $$$y$$$-coordinate among all initial points in the plot (i.e. points $$$P_0, P_1, \dots, P_{2n}$$$). The height of the plot on the picture above is 3.Your problem is to say which minimum possible height can have the plot consisting of $$$2n+1$$$ vertices and having an area equal to $$$k$$$. Note that it is unnecessary to minimize the number of moves.It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | 256 megabytes | import java.util.Scanner;
public class A {
public static void main(String[] args) throws Exception {
Scanner in = new Scanner(System.in);
long n = in.nextLong();
long k = in.nextLong();
long ans = (long) ((k - 1)/n);
System.out.println(ans + 1);
in.close();
}
}
| Java | ["4 3", "4 12", "999999999999999999 999999999999999986"] | 1 second | ["1", "3", "1"] | NoteOne of the possible answers to the first example: The area of this plot is 3, the height of this plot is 1.There is only one possible answer to the second example: The area of this plot is 12, the height of this plot is 3. | Java 8 | standard input | [
"math"
] | 31014efa929af5e4b7d9987bd9b59918 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^{18}$$$) — the number of vertices in a plot of a piecewise function and the area we need to obtain. | 1,000 | Print one integer — the minimum possible height of a plot consisting of $$$2n+1$$$ vertices and with an area equals $$$k$$$. It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $$$10^{18}$$$. | standard output | |
PASSED | 0f1e18be7a0dba52421e29ca32c8c51b | train_002.jsonl | 1324728000 | Vera adores poems. All the poems Vera knows are divided into quatrains (groups of four lines) and in each quatrain some lines contain rhymes.Let's consider that all lines in the poems consist of lowercase Latin letters (without spaces). Letters "a", "e", "i", "o", "u" are considered vowels.Two lines rhyme if their suffixes that start from the k-th vowels (counting from the end) match. If a line has less than k vowels, then such line can't rhyme with any other line. For example, if k = 1, lines commit and hermit rhyme (the corresponding suffixes equal it), and if k = 2, they do not rhyme (ommit ≠ ermit).Today on a literature lesson Vera learned that quatrains can contain four different schemes of rhymes, namely the following ones (the same letters stand for rhyming lines): Clerihew (aabb); Alternating (abab); Enclosed (abba). If all lines of a quatrain pairwise rhyme, then the quatrain can belong to any rhyme scheme (this situation is represented by aaaa).If all quatrains of a poem belong to the same rhyme scheme, then we can assume that the whole poem belongs to this rhyme scheme. If in each quatrain all lines pairwise rhyme, then the rhyme scheme of the poem is aaaa. Let us note that it doesn't matter whether lines from different quatrains rhyme with each other or not. In other words, it is possible that different quatrains aren't connected by a rhyme.Vera got a long poem as a home task. The girl has to analyse it and find the poem rhyme scheme. Help Vera cope with the task. | 256 megabytes | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class cf138a {
public static void main(String[] args) {
FastIO in = new FastIO(), out = in;
int n = 4*in.nextInt();
int k = in.nextInt();
String[] v = new String[n];
for(int i=0; i<n; i++) {
v[i] = trim(in.next().trim(), k);
if(v[i] == null) {
out.println("NO");
out.close();
return;
}
}
boolean aaaa = true, aabb = true, abab = true, abba = true;
for(int i=0; i<n; i+=4) {
if(!v[i].equals(v[i+1])) {
aaaa = false;
aabb = false;
}
if(!v[i].equals(v[i+2])) {
aaaa = false;
abab = false;
}
if(!v[i].equals(v[i+3])) {
aaaa = false;
abba = false;
}
if(!v[i+1].equals(v[i+2])) {
aaaa = false;
abba = false;
}
if(!v[i+1].equals(v[i+3])) {
aaaa = false;
abab = false;
}
if(!v[i+2].equals(v[i+3])) {
aaaa = false;
aabb = false;
}
}
if(aaaa) out.println("aaaa");
else if(abab) out.println("abab");
else if(aabb) out.println("aabb");
else if(abba) out.println("abba");
else out.println("NO");
out.close();
}
static String vowels = "aeiou";
static String trim(String x, int k) {
int count = 0;
for(int i=x.length()-1; i>=0; i--) {
if(vowels.indexOf(x.charAt(i)) >= 0)
count++;
if(count == k)
return x.substring(i);
}
return null;
}
static class FastIO extends PrintWriter {
BufferedReader br;
StringTokenizer st;
public FastIO() {
this(System.in,System.out);
}
public FastIO(InputStream in, OutputStream out) {
super(new BufferedWriter(new OutputStreamWriter(out)));
br = new BufferedReader(new InputStreamReader(in));
scanLine();
}
public void scanLine() {
try {
st = new StringTokenizer(br.readLine().trim());
} catch(Exception e) {
throw new RuntimeException(e.getMessage());
}
}
public int numTokens() {
if(!st.hasMoreTokens()) {
scanLine();
return numTokens();
}
return st.countTokens();
}
public String next() {
if(!st.hasMoreTokens()) {
scanLine();
return next();
}
return st.nextToken();
}
public double nextDouble() {
return Double.parseDouble(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
| Java | ["1 1\nday\nmay\nsun\nfun", "1 1\nday\nmay\ngray\nway", "2 1\na\na\na\na\na\na\ne\ne", "2 1\nday\nmay\nsun\nfun\ntest\nhill\nfest\nthrill"] | 2 seconds | ["aabb", "aaaa", "aabb", "NO"] | NoteIn the last sample both quatrains have rhymes but finding the common scheme is impossible, so the answer is "NO". | Java 7 | standard input | [
"implementation",
"strings"
] | a17bac596b1f060209534cbffdf0f40e | The first line contains two integers n and k (1 ≤ n ≤ 2500, 1 ≤ k ≤ 5) — the number of quatrains in the poem and the vowel's number, correspondingly. Next 4n lines contain the poem. Each line is not empty and only consists of small Latin letters. The total length of the lines does not exceed 104. If we assume that the lines are numbered starting from 1, then the first quatrain contains lines number 1, 2, 3, 4; the second one contains lines number 5, 6, 7, 8; and so on. | 1,600 | Print the rhyme scheme of the poem as "aabb", "abab", "abba", "aaaa"; or "NO" if the poem does not belong to any of the above mentioned schemes. | standard output | |
PASSED | 65be1e59fad1a6aba0eae26a183866bf | train_002.jsonl | 1316098800 | A company has n employees numbered from 1 to n. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee A is said to be the superior of another employee B if at least one of the following is true: Employee A is the immediate manager of employee B Employee B has an immediate manager employee C such that employee A is the superior of employee C. The company will not have a managerial cycle. That is, there will not exist an employee who is the superior of his/her own immediate manager.Today the company is going to arrange a party. This involves dividing all n employees into several groups: every employee must belong to exactly one group. Furthermore, within any single group, there must not be two employees A and B such that A is the superior of B.What is the minimum number of groups that must be formed? | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
static class Scan {
private byte[] buf=new byte[1024];
private int index;
private InputStream in;
private int total;
public Scan()
{
in=System.in;
}
public int scan()throws IOException
{
if(total<0)
throw new InputMismatchException();
if(index>=total)
{
index=0;
total=in.read(buf);
if(total<=0)
return -1;
}
return buf[index++];
}
public int scanInt()throws IOException
{
int integer=0;
int n=scan();
while(isWhiteSpace(n))
n=scan();
int neg=1;
if(n=='-')
{
neg=-1;
n=scan();
}
while(!isWhiteSpace(n))
{
if(n>='0'&&n<='9')
{
integer*=10;
integer+=n-'0';
n=scan();
}
else throw new InputMismatchException();
}
return neg*integer;
}
public double scanDouble()throws IOException
{
double doub=0;
int n=scan();
while(isWhiteSpace(n))
n=scan();
int neg=1;
if(n=='-')
{
neg=-1;
n=scan();
}
while(!isWhiteSpace(n)&&n!='.')
{
if(n>='0'&&n<='9')
{
doub*=10;
doub+=n-'0';
n=scan();
}
else throw new InputMismatchException();
}
if(n=='.')
{
n=scan();
double temp=1;
while(!isWhiteSpace(n))
{
if(n>='0'&&n<='9')
{
temp/=10;
doub+=(n-'0')*temp;
n=scan();
}
else throw new InputMismatchException();
}
}
return doub*neg;
}
public String scanString()throws IOException
{
StringBuilder sb=new StringBuilder();
int n=scan();
while(isWhiteSpace(n))
n=scan();
while(!isWhiteSpace(n))
{
sb.append((char)n);
n=scan();
}
return sb.toString();
}
private boolean isWhiteSpace(int n)
{
if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1)
return true;
return false;
}
}
public static void sort(int arr[],int l,int r) { //sort(arr,0,n-1);
if(l==r) {
return;
}
int mid=(l+r)/2;
sort(arr,l,mid);
sort(arr,mid+1,r);
merge(arr,l,mid,mid+1,r);
}
public static void merge(int arr[],int l1,int r1,int l2,int r2) {
int tmp[]=new int[r2-l1+1];
int indx1=l1,indx2=l2;
//sorting the two halves using a tmp array
for(int i=0;i<tmp.length;i++) {
if(indx1>r1) {
tmp[i]=arr[indx2];
indx2++;
continue;
}
if(indx2>r2) {
tmp[i]=arr[indx1];
indx1++;
continue;
}
if(arr[indx1]<arr[indx2]) {
tmp[i]=arr[indx1];
indx1++;
continue;
}
tmp[i]=arr[indx2];
indx2++;
}
//Copying the elements of tmp into the main array
for(int i=0,j=l1;i<tmp.length;i++,j++) {
arr[j]=tmp[i];
}
}
public static void sort(long arr[],int l,int r) { //sort(arr,0,n-1);
if(l==r) {
return;
}
int mid=(l+r)/2;
sort(arr,l,mid);
sort(arr,mid+1,r);
merge(arr,l,mid,mid+1,r);
}
public static void merge(long arr[],int l1,int r1,int l2,int r2) {
long tmp[]=new long[r2-l1+1];
int indx1=l1,indx2=l2;
//sorting the two halves using a tmp array
for(int i=0;i<tmp.length;i++) {
if(indx1>r1) {
tmp[i]=arr[indx2];
indx2++;
continue;
}
if(indx2>r2) {
tmp[i]=arr[indx1];
indx1++;
continue;
}
if(arr[indx1]<arr[indx2]) {
tmp[i]=arr[indx1];
indx1++;
continue;
}
tmp[i]=arr[indx2];
indx2++;
}
//Copying the elements of tmp into the main array
for(int i=0,j=l1;i<tmp.length;i++,j++) {
arr[j]=tmp[i];
}
}
static ArrayList<Integer> adj_lst[];
static int depth[];
static boolean vis[];
public static void main(String args[]) throws IOException {
Scan input=new Scan();
int n=input.scanInt();
adj_lst=new ArrayList[n];
depth=new int[n];
vis=new boolean[n];
for(int i=0;i<n;i++) {
adj_lst[i]=new ArrayList<>();
}
for(int i=0;i<n;i++) {
int tmp=input.scanInt();
if(tmp==-1) {
continue;
}
tmp--;
adj_lst[tmp].add(i);
}
int in[]=new int[n];
for(int i=0;i<n;i++) {
for(int j=0;j<adj_lst[i].size();j++) {
in[adj_lst[i].get(j)]++;
}
}
for(int i=0;i<n;i++) {
if(in[i]==0) {
DFS(i,1,-1);
}
}
for(int i=0;i<n;i++) {
if(!vis[i]) {
DFS(i,1,-1);
}
}
int max=0;
for(int i=0;i<n;i++) {
max=Math.max(max,depth[i]);
}
System.out.println(max);
}
public static void DFS(int root,int dep,int par) {
vis[root]=true;
depth[root]=dep;
for(int i=0;i<adj_lst[root].size();i++) {
if(adj_lst[root].get(i)==par || vis[adj_lst[root].get(i)]) {
continue;
}
DFS(adj_lst[root].get(i),dep+1,root);
}
}
}
| Java | ["5\n-1\n1\n2\n1\n-1"] | 3 seconds | ["3"] | NoteFor the first example, three groups are sufficient, for example: Employee 1 Employees 2 and 4 Employees 3 and 5 | Java 11 | standard input | [
"dfs and similar",
"trees",
"graphs"
] | 8d911f79dde31f2c6f62e73b925e6996 | The first line contains integer n (1 ≤ n ≤ 2000) — the number of employees. The next n lines contain the integers pi (1 ≤ pi ≤ n or pi = -1). Every pi denotes the immediate manager for the i-th employee. If pi is -1, that means that the i-th employee does not have an immediate manager. It is guaranteed, that no employee will be the immediate manager of him/herself (pi ≠ i). Also, there will be no managerial cycles. | 900 | Print a single integer denoting the minimum number of groups that will be formed in the party. | standard output | |
PASSED | 3384f666925ea87bc6a59501bf97bc5e | train_002.jsonl | 1363188600 | The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.A Bitlandish string is a string made only of characters "0" and "1".BitHaval (the mayor of Bitland) loves to play with Bitlandish strings. He takes some Bitlandish string a, and applies several (possibly zero) operations to it. In one operation the mayor may take any two adjacent characters of a string, define one of them as x and the other one as y. Then he calculates two values p and q: p = x xor y, q = x or y. Then he replaces one of the two taken characters by p and the other one by q.The xor operation means the bitwise excluding OR operation. The or operation is the bitwise OR operation.So for example one operation can transform string 11 to string 10 or to string 01. String 1 cannot be transformed into any other string.You've got two Bitlandish strings a and b. Your task is to check if it is possible for BitHaval to transform string a to string b in several (possibly zero) described operations. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
public class Main implements Runnable
{
static class InputReader
{
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
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()
{
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 Main(),"Main",1<<27).start();
}
static class Pair{
int f;
int s;
Pair(int f,int s){
this.f=f;
this.s=s;
}
public static Comparator<Pair> wc = new Comparator<Pair>(){
public int compare(Pair e1,Pair e2){
//reverse order
if(e1.s < e2.s)
return 1; // 1 for swaping.
else if (e1.s > e2.s)
return -1;
else {
//System.out.println("* "+e1.nod+" "+e2.nod);
return 0;
}
}
};
}
public static long gcd(long a,long b){
if(b==0)return a;
else return gcd(b,a%b);
}
////recursive BFS
public static int bfsr(int s,ArrayList<Integer>[] a,boolean[] b,int[] pre){
b[s]=true;
int p = 1;
int n = pre.length -1;
int t = a[s].size();
int max = 1;
for(int i=0;i<t;i++){
int x = a[s].get(i);
if(!b[x]){
//dist[x] = dist[s] + 1;
int xz = (bfsr(x,a,b,pre));
p+=xz;
max = Math.max(xz,max);
}
}
max = Math.max(max,(n-p));
pre[s] = max;
return p;
}
//// iterative BFS
public static int bfs(int s,ArrayList<Integer>[] a,int[] dist,boolean[] b,PrintWriter w){
b[s]=true;
int siz = 0;
Queue<Integer> q = new LinkedList<>();
q.add(s);
while(q.size()!=0){
int i=q.poll();
Iterator<Integer> it = a[i].listIterator();
int z=0;
while(it.hasNext()){
z=it.next();
if(!b[z]){
b[z]=true;
dist[z] = dist[i] + 1;
siz++;
q.add(z);
}
}
}
return siz;
}
public static int lower(int key, int[] a){
int l = 0;
int r = a.length-1;
int res = 0;
while(l<=r){
int mid = (l+r)/2;
if(a[mid]<=key){
l = mid+1;
res = mid+1;
}
else{
r = mid -1;
}
}
return res;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////
public void run()
{
InputReader sc = new InputReader(System.in);
PrintWriter w = new PrintWriter(System.out);
int defaultValue=0;
// int tc = sc.nextInt();
// while(tc-->0){
char[] a = sc.next().toCharArray();
char[] b = sc.next().toCharArray();
boolean ans = true;
boolean f = false;
int ao = 0;
int az = 0;
int bo = 0;
int bz = 0;
if(a.length==b.length && a.length>1){
int n = a.length;
for(int i=0;i<n;i++){
if(a[i]=='0')az++;
else ao++;
}
for(int i=0;i<n;i++){
if(b[i]=='0')bz++;
else bo++;
}
if(bo>0){
if(ao<=0){
ans = false;
}
}
else{
if(ao>0){
ans = false;
}
}
}
else if(a.length==b.length){
if(a[0]!=b[0]) ans = false;
}
else{
ans = false;
}
if(ans) w.println("YES");
else w.println("NO");
// }
w.flush();
w.close();
}
}
| Java | ["11\n10", "1\n01", "000\n101"] | 2 seconds | ["YES", "NO", "NO"] | null | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 113ae625e67c8ea5ab07be44c3b58a8f | The first line contains Bitlandish string a, the second line contains Bitlandish string b. The strings can have different lengths. It is guaranteed that the given strings only consist of characters "0" and "1". The strings are not empty, their length doesn't exceed 106. | 1,500 | Print "YES" if a can be transformed into b, otherwise print "NO". Please do not print the quotes. | standard output | |
PASSED | 5c46006618186cf01e3d275a83474653 | train_002.jsonl | 1363188600 | The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.A Bitlandish string is a string made only of characters "0" and "1".BitHaval (the mayor of Bitland) loves to play with Bitlandish strings. He takes some Bitlandish string a, and applies several (possibly zero) operations to it. In one operation the mayor may take any two adjacent characters of a string, define one of them as x and the other one as y. Then he calculates two values p and q: p = x xor y, q = x or y. Then he replaces one of the two taken characters by p and the other one by q.The xor operation means the bitwise excluding OR operation. The or operation is the bitwise OR operation.So for example one operation can transform string 11 to string 10 or to string 01. String 1 cannot be transformed into any other string.You've got two Bitlandish strings a and b. Your task is to check if it is possible for BitHaval to transform string a to string b in several (possibly zero) described operations. | 256 megabytes | import java.io.*;
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
public class CF282C {
static BufferedReader __in;
static PrintWriter __out;
static StringTokenizer input;
public static void main(String[] args) throws IOException {
__in = new BufferedReader(new InputStreamReader(System.in));
__out = new PrintWriter(new OutputStreamWriter(System.out));
char[] a = rcha(), b = rcha();
boolean aa = false, bb = false;
if(a.length == b.length) {
for(int i = 0; i < a.length; ++i) {
if(a[i] == '1') aa = true;
if(b[i] == '1') bb = true;
}
}
if(a.length == 1) aa = false;
if(Arrays.equals(a,b)) {
aa = true;
bb = true;
}
prYN(aa && bb);
close();
}
// references
// IBIG = 1e9 + 7
// IRAND ~= 3e8
// IMAX ~= 2e10
// LMAX ~= 9e18
// constants
static final int IBIG = 1000000007;
static final int IRAND = 327859546;
static final int IMAX = 2147483647;
static final int IMIN = -2147483648;
static final long LMAX = 9223372036854775807L;
static final long LMIN = -9223372036854775808L;
// util
static int minof(int a, int b, int c) {return min(a, min(b, c));}
static int minof(int... x) {return x.length == 1 ? x[0] : x.length == 2 ? min(x[0], x[1]) : min(x[0], minstarting(1, x));}
static int minstarting(int offset, int... x) {assert x.length > 2; return offset == x.length - 2 ? min(x[offset], x[offset + 1]) : min(x[offset], minstarting(offset + 1, x));}
static long minof(long a, long b, long c) {return min(a, min(b, c));}
static long minof(long... x) {return x.length == 1 ? x[0] : x.length == 2 ? min(x[0], x[1]) : min(x[0], minstarting(1, x));}
static long minstarting(int offset, long... x) {assert x.length > 2; return offset == x.length - 2 ? min(x[offset], x[offset + 1]) : min(x[offset], minstarting(offset + 1, x));}
static int maxof(int a, int b, int c) {return max(a, max(b, c));}
static int maxof(int... x) {return x.length == 1 ? x[0] : x.length == 2 ? max(x[0], x[1]) : max(x[0], maxstarting(1, x));}
static int maxstarting(int offset, int... x) {assert x.length > 2; return offset == x.length - 2 ? max(x[offset], x[offset + 1]) : max(x[offset], maxstarting(offset + 1, x));}
static long maxof(long a, long b, long c) {return max(a, max(b, c));}
static long maxof(long... x) {return x.length == 1 ? x[0] : x.length == 2 ? max(x[0], x[1]) : max(x[0], maxstarting(1, x));}
static long maxstarting(int offset, long... x) {assert x.length > 2; return offset == x.length - 2 ? max(x[offset], x[offset + 1]) : max(x[offset], maxstarting(offset + 1, x));}
static int powi(int a, int b) {if(a == 0) return 0; int ans = 1; while(b > 0) {if((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;}
static long powl(long a, int b) {if(a == 0) return 0; long ans = 1; while(b > 0) {if((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;}
static int floori(double d) {return (int)d;}
static int ceili(double d) {return (int)ceil(d);}
static long floorl(double d) {return (long)d;}
static long ceill(double d) {return (long)ceil(d);}
// input
static void r() throws IOException {input = new StringTokenizer(__in.readLine());}
static int ri() throws IOException {return Integer.parseInt(__in.readLine());}
static long rl() throws IOException {return Long.parseLong(__in.readLine());}
static int[] ria(int n) throws IOException {int[] a = new int[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Integer.parseInt(input.nextToken()); return a;}
static long[] rla(int n) throws IOException {long[] a = new long[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Long.parseLong(input.nextToken()); return a;}
static char[] rcha() throws IOException {return __in.readLine().toCharArray();}
static String rline() throws IOException {return __in.readLine();}
static int rni() throws IOException {input = new StringTokenizer(__in.readLine()); return Integer.parseInt(input.nextToken());}
static int ni() {return Integer.parseInt(input.nextToken());}
static long rnl() throws IOException {input = new StringTokenizer(__in.readLine()); return Long.parseLong(input.nextToken());}
static long nl() {return Long.parseLong(input.nextToken());}
// output
static void pr(int i) {__out.print(i);}
static void prln(int i) {__out.println(i);}
static void pr(long l) {__out.print(l);}
static void prln(long l) {__out.println(l);}
static void pr(double d) {__out.print(d);}
static void prln(double d) {__out.println(d);}
static void pr(char c) {__out.print(c);}
static void prln(char c) {__out.println(c);}
static void pr(char[] s) {__out.print(new String(s));}
static void prln(char[] s) {__out.println(new String(s));}
static void pr(String s) {__out.print(s);}
static void prln(String s) {__out.println(s);}
static void pr(Object o) {__out.print(o);}
static void prln(Object o) {__out.println(o);}
static void prln() {__out.println();}
static void pryes() {__out.println("yes");}
static void pry() {__out.println("Yes");}
static void prY() {__out.println("YES");}
static void prno() {__out.println("no");}
static void prn() {__out.println("No");}
static void prN() {__out.println("NO");}
static void pryesno(boolean b) {__out.println(b ? "yes" : "no");};
static void pryn(boolean b) {__out.println(b ? "Yes" : "No");}
static void prYN(boolean b) {__out.println(b ? "YES" : "NO");}
static void prln(int... a) {for(int i = 0, len = a.length - 1; i < len; __out.print(a[i]), __out.print(' '), ++i); __out.println(a[a.length - 1]);}
static void prln(long... a) {for(int i = 0, len = a.length - 1; i < len; __out.print(a[i]), __out.print(' '), ++i); __out.println(a[a.length - 1]);}
static <T> void prln(Collection<T> c) {int n = c.size() - 1; Iterator<T> iter = c.iterator(); for(int i = 0; i < n; __out.print(iter.next()), __out.print(' '), ++i); __out.println(iter.next());}
static void flush() {__out.flush();}
static void close() {__out.close();}} | Java | ["11\n10", "1\n01", "000\n101"] | 2 seconds | ["YES", "NO", "NO"] | null | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 113ae625e67c8ea5ab07be44c3b58a8f | The first line contains Bitlandish string a, the second line contains Bitlandish string b. The strings can have different lengths. It is guaranteed that the given strings only consist of characters "0" and "1". The strings are not empty, their length doesn't exceed 106. | 1,500 | Print "YES" if a can be transformed into b, otherwise print "NO". Please do not print the quotes. | standard output | |
PASSED | d3aceae7d8aa24bf3d576f2c9aaf1b22 | train_002.jsonl | 1363188600 | The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.A Bitlandish string is a string made only of characters "0" and "1".BitHaval (the mayor of Bitland) loves to play with Bitlandish strings. He takes some Bitlandish string a, and applies several (possibly zero) operations to it. In one operation the mayor may take any two adjacent characters of a string, define one of them as x and the other one as y. Then he calculates two values p and q: p = x xor y, q = x or y. Then he replaces one of the two taken characters by p and the other one by q.The xor operation means the bitwise excluding OR operation. The or operation is the bitwise OR operation.So for example one operation can transform string 11 to string 10 or to string 01. String 1 cannot be transformed into any other string.You've got two Bitlandish strings a and b. Your task is to check if it is possible for BitHaval to transform string a to string b in several (possibly zero) described operations. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
CXORAndOR solver = new CXORAndOR();
solver.solve(1, in, out);
out.close();
}
static class CXORAndOR {
public void solve(int testNumber, Scanner sc, PrintWriter pw) {
char[] cur = sc.next().toCharArray();
char[] transform = sc.next().toCharArray();
if (cur.length != transform.length) {
pw.println("NO");
return;
}
boolean onlyZeroCur = true;
boolean onlyZeroTransform = true;
for (int i = 0; i < cur.length; i++) {
onlyZeroCur &= cur[i] == '0';
onlyZeroTransform &= transform[i] == '0';
}
if (onlyZeroCur && !onlyZeroTransform || !onlyZeroCur && onlyZeroTransform) {
pw.println("NO");
} else
pw.println("YES");
}
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(FileReader r) {
br = new BufferedReader(r);
}
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return st.nextToken();
}
}
}
| Java | ["11\n10", "1\n01", "000\n101"] | 2 seconds | ["YES", "NO", "NO"] | null | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 113ae625e67c8ea5ab07be44c3b58a8f | The first line contains Bitlandish string a, the second line contains Bitlandish string b. The strings can have different lengths. It is guaranteed that the given strings only consist of characters "0" and "1". The strings are not empty, their length doesn't exceed 106. | 1,500 | Print "YES" if a can be transformed into b, otherwise print "NO". Please do not print the quotes. | standard output | |
PASSED | ce8249913bbf0001d04b126a50c0cf2c | train_002.jsonl | 1363188600 | The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.A Bitlandish string is a string made only of characters "0" and "1".BitHaval (the mayor of Bitland) loves to play with Bitlandish strings. He takes some Bitlandish string a, and applies several (possibly zero) operations to it. In one operation the mayor may take any two adjacent characters of a string, define one of them as x and the other one as y. Then he calculates two values p and q: p = x xor y, q = x or y. Then he replaces one of the two taken characters by p and the other one by q.The xor operation means the bitwise excluding OR operation. The or operation is the bitwise OR operation.So for example one operation can transform string 11 to string 10 or to string 01. String 1 cannot be transformed into any other string.You've got two Bitlandish strings a and b. Your task is to check if it is possible for BitHaval to transform string a to string b in several (possibly zero) described operations. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.*;
import java.util.Queue;
import java.util.StringTokenizer;
import java.math.BigInteger;
public class hello2
{static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
static String sum (String s)
{
String s1 = "";
if(s.contains("a"))
s1+="a";
if(s.contains("e"))
s1+="e";
if(s.contains("i"))
s1+="i";
if(s.contains("o"))
s1+="o";
if(s.contains("u"))
s1+="u";
return s1;
}
public static void main(String[] args)
{
FastReader sc =new FastReader();
char c1[]=sc.next().toCharArray(),c2[]=sc.next().toCharArray();
int l1=c1.length,l2=c2.length,f1=1,f2=1;
if(l1!=l2 || (l1==1 && c1[0]!=c2[0])){
System.out.println("NO");
}
else{
for(int i=0;i<l1;i++){
if(c1[i]=='1'){
f1=0;
}
if(c2[i]=='1'){
f2=0;
}
}
System.out.println(f1!=f2?"NO":"YES");
}
}
} | Java | ["11\n10", "1\n01", "000\n101"] | 2 seconds | ["YES", "NO", "NO"] | null | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 113ae625e67c8ea5ab07be44c3b58a8f | The first line contains Bitlandish string a, the second line contains Bitlandish string b. The strings can have different lengths. It is guaranteed that the given strings only consist of characters "0" and "1". The strings are not empty, their length doesn't exceed 106. | 1,500 | Print "YES" if a can be transformed into b, otherwise print "NO". Please do not print the quotes. | standard output | |
PASSED | 8d1e2802e2a18a4255e777fe7d88b3be | train_002.jsonl | 1363188600 | The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.A Bitlandish string is a string made only of characters "0" and "1".BitHaval (the mayor of Bitland) loves to play with Bitlandish strings. He takes some Bitlandish string a, and applies several (possibly zero) operations to it. In one operation the mayor may take any two adjacent characters of a string, define one of them as x and the other one as y. Then he calculates two values p and q: p = x xor y, q = x or y. Then he replaces one of the two taken characters by p and the other one by q.The xor operation means the bitwise excluding OR operation. The or operation is the bitwise OR operation.So for example one operation can transform string 11 to string 10 or to string 01. String 1 cannot be transformed into any other string.You've got two Bitlandish strings a and b. Your task is to check if it is possible for BitHaval to transform string a to string b in several (possibly zero) described operations. | 256 megabytes |
/**
* @author egaeus
* @mail sebegaeusprogram@gmail.com
* @veredict Not sended
* @url <https://codeforces.com/problemset/problem/282/C>
* @category ?
* @date 1/07/2020
**/
import java.io.*;
import java.util.*;
import java.util.stream.Collectors;
import static java.lang.Integer.*;
import static java.lang.Math.*;
public class CF282C {
static char[] A, B;
public static void main(String args[]) throws Throwable {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
for (String ln; (ln = in.readLine()) != null && !ln.equals(""); ) {
A = ln.toCharArray();
B = in.readLine().toCharArray();
if (A.length == B.length) {
int N = A.length;
boolean haveOne = false;
for (int i = 0; i < N; i++)
haveOne |= A[i] == '1';
boolean ws = true;
int ones = 0;
for (int i = 0; i < N; i++) {
if (B[i] == '1')
ones++;
}
for (int i = 0; i < N && ws; i++)
if (A[i] != B[i] && (A.length <= 1 || !haveOne || ones == 0))
ws = false;
System.out.println(ws ? "YES" : "NO");
} else System.out.println("NO");
}
}
}
| Java | ["11\n10", "1\n01", "000\n101"] | 2 seconds | ["YES", "NO", "NO"] | null | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 113ae625e67c8ea5ab07be44c3b58a8f | The first line contains Bitlandish string a, the second line contains Bitlandish string b. The strings can have different lengths. It is guaranteed that the given strings only consist of characters "0" and "1". The strings are not empty, their length doesn't exceed 106. | 1,500 | Print "YES" if a can be transformed into b, otherwise print "NO". Please do not print the quotes. | standard output | |
PASSED | f62c3bdad4f64253002682901df15844 | train_002.jsonl | 1363188600 | The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.A Bitlandish string is a string made only of characters "0" and "1".BitHaval (the mayor of Bitland) loves to play with Bitlandish strings. He takes some Bitlandish string a, and applies several (possibly zero) operations to it. In one operation the mayor may take any two adjacent characters of a string, define one of them as x and the other one as y. Then he calculates two values p and q: p = x xor y, q = x or y. Then he replaces one of the two taken characters by p and the other one by q.The xor operation means the bitwise excluding OR operation. The or operation is the bitwise OR operation.So for example one operation can transform string 11 to string 10 or to string 01. String 1 cannot be transformed into any other string.You've got two Bitlandish strings a and b. Your task is to check if it is possible for BitHaval to transform string a to string b in several (possibly zero) described operations. | 256 megabytes | import java.io.*;
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
public class cf282c {
public static void main(String[] args) throws IOException {
char[] s1 = rcha(), s2 = rcha();
int n1 = s1.length, n2 = s2.length;
boolean zero1 = true, zero2 = true;
for(char c : s1) {
if(c != '0') {
zero1 = false;
break;
}
}
for(char c : s2) {
if(c != '0') {
zero2 = false;
break;
}
}
prYN(n1 == n2 && zero1 == zero2);
close();
}
static BufferedReader __in = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter __out = new PrintWriter(new OutputStreamWriter(System.out));
static StringTokenizer input;
static Random rand = new Random();
// references
// IBIG = 1e9 + 7
// IRAND ~= 3e8
// IMAX ~= 2e10
// LMAX ~= 9e18
// constants
static final int IBIG = 1000000007;
static final int IRAND = 327859546;
static final int IMAX = 2147483647;
static final int IMIN = -2147483648;
static final long LMAX = 9223372036854775807L;
static final long LMIN = -9223372036854775808L;
// util
static int minof(int a, int b, int c) {return min(a, min(b, c));}
static int minof(int... x) {return x.length == 1 ? x[0] : x.length == 2 ? min(x[0], x[1]) : min(x[0], minstarting(1, x));}
static int minstarting(int offset, int... x) {assert x.length > 2; return offset == x.length - 2 ? min(x[offset], x[offset + 1]) : min(x[offset], minstarting(offset + 1, x));}
static long minof(long a, long b, long c) {return min(a, min(b, c));}
static long minof(long... x) {return x.length == 1 ? x[0] : x.length == 2 ? min(x[0], x[1]) : min(x[0], minstarting(1, x));}
static long minstarting(int offset, long... x) {assert x.length > 2; return offset == x.length - 2 ? min(x[offset], x[offset + 1]) : min(x[offset], minstarting(offset + 1, x));}
static int maxof(int a, int b, int c) {return max(a, max(b, c));}
static int maxof(int... x) {return x.length == 1 ? x[0] : x.length == 2 ? max(x[0], x[1]) : max(x[0], maxstarting(1, x));}
static int maxstarting(int offset, int... x) {assert x.length > 2; return offset == x.length - 2 ? max(x[offset], x[offset + 1]) : max(x[offset], maxstarting(offset + 1, x));}
static long maxof(long a, long b, long c) {return max(a, max(b, c));}
static long maxof(long... x) {return x.length == 1 ? x[0] : x.length == 2 ? max(x[0], x[1]) : max(x[0], maxstarting(1, x));}
static long maxstarting(int offset, long... x) {assert x.length > 2; return offset == x.length - 2 ? max(x[offset], x[offset + 1]) : max(x[offset], maxstarting(offset + 1, x));}
static int powi(int a, int b) {if(a == 0) return 0; int ans = 1; while(b > 0) {if((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;}
static long powl(long a, int b) {if(a == 0) return 0; long ans = 1; while(b > 0) {if((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;}
static int floori(double d) {return (int)d;}
static int ceili(double d) {return (int)ceil(d);}
static long floorl(double d) {return (long)d;}
static long ceill(double d) {return (long)ceil(d);}
static void shuffle(int[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); int swap = a[i]; a[i] = a[ind]; a[ind] = swap;}}
static void shuffle(long[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); long swap = a[i]; a[i] = a[ind]; a[ind] = swap;}}
static void shuffle(double[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); double swap = a[i]; a[i] = a[ind]; a[ind] = swap;}}
static <T> void shuffle(T[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); T swap = a[i]; a[i] = a[ind]; a[ind] = swap;}}
static void sort(int[] a) {shuffle(a); Arrays.sort(a);}
static void sort(long[] a) {shuffle(a); Arrays.sort(a);}
static void sort(double[] a) {shuffle(a); Arrays.sort(a);}
static void qsort(int[] a) {Arrays.sort(a);}
static void qsort(long[] a) {Arrays.sort(a);}
static void qsort(double[] a) {Arrays.sort(a);}
static int randInt(int min, int max) {return rand.nextInt(max - min + 1) + min;}
// input
static void r() throws IOException {input = new StringTokenizer(__in.readLine());}
static int ri() throws IOException {return Integer.parseInt(__in.readLine());}
static long rl() throws IOException {return Long.parseLong(__in.readLine());}
static int[] ria(int n) throws IOException {int[] a = new int[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Integer.parseInt(input.nextToken()); return a;}
static long[] rla(int n) throws IOException {long[] a = new long[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Long.parseLong(input.nextToken()); return a;}
static char[] rcha() throws IOException {return __in.readLine().toCharArray();}
static String rline() throws IOException {return __in.readLine();}
static int rni() throws IOException {input = new StringTokenizer(__in.readLine()); return Integer.parseInt(input.nextToken());}
static int ni() {return Integer.parseInt(input.nextToken());}
static long rnl() throws IOException {input = new StringTokenizer(__in.readLine()); return Long.parseLong(input.nextToken());}
static long nl() {return Long.parseLong(input.nextToken());}
// output
static void pr(int i) {__out.print(i);}
static void prln(int i) {__out.println(i);}
static void pr(long l) {__out.print(l);}
static void prln(long l) {__out.println(l);}
static void pr(double d) {__out.print(d);}
static void prln(double d) {__out.println(d);}
static void pr(char c) {__out.print(c);}
static void prln(char c) {__out.println(c);}
static void pr(char[] s) {__out.print(new String(s));}
static void prln(char[] s) {__out.println(new String(s));}
static void pr(String s) {__out.print(s);}
static void prln(String s) {__out.println(s);}
static void pr(Object o) {__out.print(o);}
static void prln(Object o) {__out.println(o);}
static void prln() {__out.println();}
static void pryes() {__out.println("yes");}
static void pry() {__out.println("Yes");}
static void prY() {__out.println("YES");}
static void prno() {__out.println("no");}
static void prn() {__out.println("No");}
static void prN() {__out.println("NO");}
static void pryesno(boolean b) {__out.println(b ? "yes" : "no");};
static void pryn(boolean b) {__out.println(b ? "Yes" : "No");}
static void prYN(boolean b) {__out.println(b ? "YES" : "NO");}
static void prln(int... a) {for(int i = 0, len = a.length - 1; i < len; __out.print(a[i]), __out.print(' '), ++i); __out.println(a[a.length - 1]);}
static void prln(long... a) {for(int i = 0, len = a.length - 1; i < len; __out.print(a[i]), __out.print(' '), ++i); __out.println(a[a.length - 1]);}
static <T> void prln(Collection<T> c) {int n = c.size() - 1; Iterator<T> iter = c.iterator(); for(int i = 0; i < n; __out.print(iter.next()), __out.print(' '), ++i); if(n >= 0) __out.println(iter.next());}
static void h() {__out.println("hlfd");}
static void flush() {__out.flush();}
static void close() {__out.close();}
} | Java | ["11\n10", "1\n01", "000\n101"] | 2 seconds | ["YES", "NO", "NO"] | null | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 113ae625e67c8ea5ab07be44c3b58a8f | The first line contains Bitlandish string a, the second line contains Bitlandish string b. The strings can have different lengths. It is guaranteed that the given strings only consist of characters "0" and "1". The strings are not empty, their length doesn't exceed 106. | 1,500 | Print "YES" if a can be transformed into b, otherwise print "NO". Please do not print the quotes. | standard output | |
PASSED | ef8d51f353e55aac5c3c4207dd8bd880 | train_002.jsonl | 1363188600 | The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.A Bitlandish string is a string made only of characters "0" and "1".BitHaval (the mayor of Bitland) loves to play with Bitlandish strings. He takes some Bitlandish string a, and applies several (possibly zero) operations to it. In one operation the mayor may take any two adjacent characters of a string, define one of them as x and the other one as y. Then he calculates two values p and q: p = x xor y, q = x or y. Then he replaces one of the two taken characters by p and the other one by q.The xor operation means the bitwise excluding OR operation. The or operation is the bitwise OR operation.So for example one operation can transform string 11 to string 10 or to string 01. String 1 cannot be transformed into any other string.You've got two Bitlandish strings a and b. Your task is to check if it is possible for BitHaval to transform string a to string b in several (possibly zero) described operations. | 256 megabytes | import java.io.*;
public class Q1
{
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String s1=br.readLine();
String s2=br.readLine();
if(s1.length()!=s2.length())
System.out.println("NO");
else
{ boolean a=false;boolean b=false;
for(int i=0;i<s1.length();i++)
{
if(s1.charAt(i)=='1')
a=true;
if(s2.charAt(i)=='1')
b=true;
}
if(s1.length()==1)
a=false;
if(s1.equals(s2)==true)
{
a=true;
b=true;
}
if(a==true&&b==true)
System.out.println("YES");
else
System.out.println("NO");
}
}
} | Java | ["11\n10", "1\n01", "000\n101"] | 2 seconds | ["YES", "NO", "NO"] | null | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 113ae625e67c8ea5ab07be44c3b58a8f | The first line contains Bitlandish string a, the second line contains Bitlandish string b. The strings can have different lengths. It is guaranteed that the given strings only consist of characters "0" and "1". The strings are not empty, their length doesn't exceed 106. | 1,500 | Print "YES" if a can be transformed into b, otherwise print "NO". Please do not print the quotes. | standard output | |
PASSED | 3476dca76be70f4d4b722a8dfc98b517 | train_002.jsonl | 1363188600 | The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.A Bitlandish string is a string made only of characters "0" and "1".BitHaval (the mayor of Bitland) loves to play with Bitlandish strings. He takes some Bitlandish string a, and applies several (possibly zero) operations to it. In one operation the mayor may take any two adjacent characters of a string, define one of them as x and the other one as y. Then he calculates two values p and q: p = x xor y, q = x or y. Then he replaces one of the two taken characters by p and the other one by q.The xor operation means the bitwise excluding OR operation. The or operation is the bitwise OR operation.So for example one operation can transform string 11 to string 10 or to string 01. String 1 cannot be transformed into any other string.You've got two Bitlandish strings a and b. Your task is to check if it is possible for BitHaval to transform string a to string b in several (possibly zero) described operations. | 256 megabytes | import javax.swing.*;
import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main {
static PrintWriter out = new PrintWriter(System.out);
static int[] tree;
static long m = 1000000007;
public static void main(String[] args) throws IOException {
//BufferedReader reader=new BufferedReader(new FileReader("input.txt"));
//PrintWriter pw=new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
//Scanner scanner=new Scanner(System.in);
//Reader sc = new Reader();
String m=reader.readLine();
String n=reader.readLine();
boolean f1=false,f2=false;
for (int i = 0; i <Math.min(m.length(),n.length()) ; i++) {
if (m.charAt(i)=='1')f1=true;
if (n.charAt(i)=='1')f2=true;
}
if(m.length()==1 && n.length()==1 && !m.equals(n))
System.out.println("NO");
else if (m.equals(n))
System.out.println("YES");
else if (m.length()!=n.length())
System.out.println("NO");
else if (f1&&f2)
System.out.println("YES");
else
System.out.println("NO");
out.close();
}
}
class node implements Comparable<node> {
Integer no;
Integer cost;
Vector<node> adj = new Vector<>();
public node(Integer no, Integer cost) {
this.no = no;
this.cost = cost;
}
@Override
public String toString() {
return "node{" +
"no=" + no +
", cost=" + cost +
'}';
}
@Override
public int compareTo(node o) {
return o.cost - this.cost;
}
}
class edge implements Comparable<edge> {
tuple u;
Double cost;
public edge(tuple u, Double cost) {
this.u = u;
this.cost = cost;
}
@Override
public int compareTo(edge o) {
return this.cost.compareTo(o.cost);
}
@Override
public String toString() {
return "edge{" +
"u=" + u +
", cost=" + cost +
'}';
}
}
///*
class tuple implements Comparable<tuple> {
Integer a;
Integer b;
public tuple(Integer a, Integer b) {
this.a = a;
this.b = b;
}
@Override
public int compareTo(tuple o) {
return (this.a - o.a);
}
@Override
public String toString() {
return "tuple{" +
"a=" + a +
", b=" + b +
'}';
}
}
//*/
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];
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n') break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException {
int ret = 0;
byte c = read();
while (c <= ' ') c = read();
boolean neg = (c == '-');
if (neg) c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg) return -ret;
return ret;
}
public long nextLong() throws IOException {
long ret = 0;
byte c = read();
while (c <= ' ') c = read();
boolean neg = (c == '-');
if (neg) c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg) return -ret;
return ret;
}
public double nextDouble() throws IOException {
double ret = 0, div = 1;
byte c = read();
while (c <= ' ') c = read();
boolean neg = (c == '-');
if (neg) c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (c == '.') while ((c = read()) >= '0' && c <= '9') ret += (c - '0') / (div *= 10);
if (neg) return -ret;
return ret;
}
private void fillBuffer() throws IOException {
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1) buffer[0] = -1;
}
private byte read() throws IOException {
if (bufferPointer == bytesRead) fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException {
if (din == null) return;
din.close();
}
} | Java | ["11\n10", "1\n01", "000\n101"] | 2 seconds | ["YES", "NO", "NO"] | null | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 113ae625e67c8ea5ab07be44c3b58a8f | The first line contains Bitlandish string a, the second line contains Bitlandish string b. The strings can have different lengths. It is guaranteed that the given strings only consist of characters "0" and "1". The strings are not empty, their length doesn't exceed 106. | 1,500 | Print "YES" if a can be transformed into b, otherwise print "NO". Please do not print the quotes. | standard output | |
PASSED | c0ec4dbdfa352b4b48e7b24bec835f60 | train_002.jsonl | 1363188600 | The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.A Bitlandish string is a string made only of characters "0" and "1".BitHaval (the mayor of Bitland) loves to play with Bitlandish strings. He takes some Bitlandish string a, and applies several (possibly zero) operations to it. In one operation the mayor may take any two adjacent characters of a string, define one of them as x and the other one as y. Then he calculates two values p and q: p = x xor y, q = x or y. Then he replaces one of the two taken characters by p and the other one by q.The xor operation means the bitwise excluding OR operation. The or operation is the bitwise OR operation.So for example one operation can transform string 11 to string 10 or to string 01. String 1 cannot be transformed into any other string.You've got two Bitlandish strings a and b. Your task is to check if it is possible for BitHaval to transform string a to string b in several (possibly zero) described operations. | 256 megabytes | import java.io.IOException;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
Scanner s = new Scanner(System.in);
StringBuilder sb=new StringBuilder();
char[] a=s.next().toCharArray();
char[] b=s.next().toCharArray();
if(a.length!=b.length) {
System.out.println("NO");System.exit(0);
}
int flag=0;
for(int i=0;i<a.length;i++){
if(a[i]=='1') flag=1;
}int flag2=0;
for(int i=0;i<b.length;i++){
if(b[i]=='1'){
flag2=1;break;
}
}
if(flag==0||flag2==0){
if(flag==0&&flag2==0) System.out.println("YES");else
System.out.println("NO");
}else System.out.println("YES");
}
static void computeLPSArray(String pat, int M, int lps[]) {
int len = 0;
int i = 1;
lps[0] = 0;
while (i < M) {
if (pat.charAt(i) == pat.charAt(len)) {
len++;
lps[i] = len;
i++;
}
else
{
if (len != 0) {
len = lps[len - 1];
}
else
{
lps[i] = len;
i++;
}
}
}
}
static boolean isPrime(int n) {
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
static long powerwithmod(long x, long y, int p) {
long res = 1;
x = x % p;
while (y > 0) {
if ((y & 1) == 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
static long powerwithoutmod(long x, int y) {
long temp;
if( y == 0)
return 1;
temp = powerwithoutmod(x, y/2);
if (y%2 == 0)
return temp*temp;
else
{
if(y > 0)
return x * temp * temp;
else
return (temp * temp) / x;
}
}
static void fracion(double x) {
String a = "" + x;
String spilts[] = a.split("\\."); // split using decimal
int b = spilts[1].length(); // find the decimal length
int denominator = (int) Math.pow(10, b); // calculate the denominator
int numerator = (int) (x * denominator); // calculate the nerumrator Ex
// 1.2*10 = 12
int gcd = (int) gcd((long) numerator, denominator); // Find the greatest common
// divisor bw them
String fraction = "" + numerator / gcd + "/" + denominator / gcd;
// System.out.println((denominator/gcd));
long x1 = modInverse(denominator / gcd, 998244353);
// System.out.println(x1);
System.out.println((((numerator / gcd) % 998244353 * (x1 % 998244353)) % 998244353));
}
static int bfs(int i1, ArrayList<Integer>[] h, int[] vis, int n,int val1) {
Queue<Integer> q = new LinkedList<Integer>();
q.add(i1);Queue<Integer> aq=new LinkedList<Integer>();
aq.add(0);
while(!q.isEmpty()){
int i=q.poll();
int val=aq.poll();
if(i==n){
return val;
}
if(h[i]!=null){
for(Integer j:h[i]){
if(vis[j]==0){
q.add(j);vis[j]=1;
aq.add(val+1);}
}
}
}return -1;
}
static long gcd(long a, long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
static long modInverse(long a, int m)
{
return (powerwithmod(a, m - 2, m));
}
static int MAXN=100001;
static int[] spf=new int[MAXN];
static void sieve() {
spf[1] = 1;
for (int i=2; i<MAXN; i++)
spf[i] = i;
for (int i=4; i<MAXN; i+=2)
spf[i] = 2;
for (int i=3; i*i<MAXN; i++)
{
if (spf[i] == i)
{
for (int j=i*i; j<MAXN; j+=i)
if (spf[j]==j)
spf[j] = i;
}
}
}
static Vector<Integer> getFactorizationUsingSeive(int x) {
Vector<Integer> ret = new Vector<Integer>();
while (x != 1)
{
ret.add(spf[x]);
x = x / spf[x];
}
return ret;
}
/* static long[] fac = new long[MAXN+1];
static void calculatefac(int mod){
for (int i = 1 ;i <= MAXN; i++)
fac[i] = fac[i-1] * i % mod;
}
static long nCrModPFermat(int n, int r, int mod) {
if (r == 0)
return 1;
fac[0] = 1;
return (fac[n]* modInverse(fac[r], mod)
% mod * modInverse(fac[n-r], mod)
% mod) % mod;
} */}
class Student {
int l;int r;
public Student(int l, int r) {
this.l = l;
this.r = r;
}
public String toString()
{
return this.l+" ";
}
}
class Sortbyroll implements Comparator<Student> {
public int compare(Student a, Student b){
if(a.l==b.l) return a.r-b.r;
return b.l-a.l; }
}
class Sortbyroll1 implements Comparator<Student> {
public int compare(Student a, Student b){
if(a.r==b.r) return a.l-b.l;
return b.l-a.l;
}
} | Java | ["11\n10", "1\n01", "000\n101"] | 2 seconds | ["YES", "NO", "NO"] | null | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 113ae625e67c8ea5ab07be44c3b58a8f | The first line contains Bitlandish string a, the second line contains Bitlandish string b. The strings can have different lengths. It is guaranteed that the given strings only consist of characters "0" and "1". The strings are not empty, their length doesn't exceed 106. | 1,500 | Print "YES" if a can be transformed into b, otherwise print "NO". Please do not print the quotes. | standard output | |
PASSED | 246f4b38afaf163303a4b1aff8f990c9 | train_002.jsonl | 1363188600 | The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.A Bitlandish string is a string made only of characters "0" and "1".BitHaval (the mayor of Bitland) loves to play with Bitlandish strings. He takes some Bitlandish string a, and applies several (possibly zero) operations to it. In one operation the mayor may take any two adjacent characters of a string, define one of them as x and the other one as y. Then he calculates two values p and q: p = x xor y, q = x or y. Then he replaces one of the two taken characters by p and the other one by q.The xor operation means the bitwise excluding OR operation. The or operation is the bitwise OR operation.So for example one operation can transform string 11 to string 10 or to string 01. String 1 cannot be transformed into any other string.You've got two Bitlandish strings a and b. Your task is to check if it is possible for BitHaval to transform string a to string b in several (possibly zero) described operations. | 256 megabytes | //I AM THE CREED
/* package codechef; // don't place package name! */
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.*;
public class HelloWorld{
public static void main(String[] args) throws IOException
{
Scanner input = new Scanner(System.in);
while(input.hasNext()){
String a=input.next();
String b=input.next();
if(a.equals(b)){
System.out.println("YES");
continue;
}
if(a.length()!=b.length()){
System.out.println("NO");
continue;
}
int o1=0;
int o2=0;
int z1=0;
int z2=0;
for(int i=0;i<a.length();i++){
if(a.charAt(i)=='1'){
o1++;
}
if(b.charAt(i)=='1'){
o2++;
}
if(a.charAt(i)=='0'){
z1++;
}
if(b.charAt(i)=='0'){
z2++;
}
}
if(o2!=0 && o1!=0){
System.out.println("YES");
continue;
}
if(o1==0 && o2==0){
System.out.println("YES");
continue;
}
System.out.println("NO");
}
}
} | Java | ["11\n10", "1\n01", "000\n101"] | 2 seconds | ["YES", "NO", "NO"] | null | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 113ae625e67c8ea5ab07be44c3b58a8f | The first line contains Bitlandish string a, the second line contains Bitlandish string b. The strings can have different lengths. It is guaranteed that the given strings only consist of characters "0" and "1". The strings are not empty, their length doesn't exceed 106. | 1,500 | Print "YES" if a can be transformed into b, otherwise print "NO". Please do not print the quotes. | standard output | |
PASSED | b75484f948a27f559c63899cf9e5bcfd | train_002.jsonl | 1363188600 | The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.A Bitlandish string is a string made only of characters "0" and "1".BitHaval (the mayor of Bitland) loves to play with Bitlandish strings. He takes some Bitlandish string a, and applies several (possibly zero) operations to it. In one operation the mayor may take any two adjacent characters of a string, define one of them as x and the other one as y. Then he calculates two values p and q: p = x xor y, q = x or y. Then he replaces one of the two taken characters by p and the other one by q.The xor operation means the bitwise excluding OR operation. The or operation is the bitwise OR operation.So for example one operation can transform string 11 to string 10 or to string 01. String 1 cannot be transformed into any other string.You've got two Bitlandish strings a and b. Your task is to check if it is possible for BitHaval to transform string a to string b in several (possibly zero) described operations. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class XORandOR {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String a = bf.readLine();
String b = bf.readLine();
if (a.equals(b)){
System.out.print("YES");
return;
}
if (a.length()!=b.length()){
System.out.print("NO");
return;
}
int sum_a=0;
int sum_b=0;
for (int i = 0; i < a.length(); i++) {
sum_a+=Integer.parseInt(a.substring(i,i+1));
sum_b+=Integer.parseInt(b.substring(i,i+1));
}
if (sum_a==0||sum_b==0){
System.out.print("NO");
return;
}
System.out.print("YES");
}
}
| Java | ["11\n10", "1\n01", "000\n101"] | 2 seconds | ["YES", "NO", "NO"] | null | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 113ae625e67c8ea5ab07be44c3b58a8f | The first line contains Bitlandish string a, the second line contains Bitlandish string b. The strings can have different lengths. It is guaranteed that the given strings only consist of characters "0" and "1". The strings are not empty, their length doesn't exceed 106. | 1,500 | Print "YES" if a can be transformed into b, otherwise print "NO". Please do not print the quotes. | standard output | |
PASSED | fdaa1ad31b2319e53792637a63f3d473 | train_002.jsonl | 1363188600 | The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.A Bitlandish string is a string made only of characters "0" and "1".BitHaval (the mayor of Bitland) loves to play with Bitlandish strings. He takes some Bitlandish string a, and applies several (possibly zero) operations to it. In one operation the mayor may take any two adjacent characters of a string, define one of them as x and the other one as y. Then he calculates two values p and q: p = x xor y, q = x or y. Then he replaces one of the two taken characters by p and the other one by q.The xor operation means the bitwise excluding OR operation. The or operation is the bitwise OR operation.So for example one operation can transform string 11 to string 10 or to string 01. String 1 cannot be transformed into any other string.You've got two Bitlandish strings a and b. Your task is to check if it is possible for BitHaval to transform string a to string b in several (possibly zero) described operations. | 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 Demo
{
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 (Exception e){
e.printStackTrace();
}
return str;
}
}
public static void main (String[] args) throws java.lang.Exception
{
FastReader in = new FastReader();
String a = in.next(), b = in.next();
String ans = "YES";
if(a.length() != b.length()) ans = "NO";
else if(a.equals(b)) ans = "YES";
else if(!a.contains("1") || !b.contains("1")) ans = "NO";
else ans = "YES";
System.out.println(ans);
}
}
| Java | ["11\n10", "1\n01", "000\n101"] | 2 seconds | ["YES", "NO", "NO"] | null | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 113ae625e67c8ea5ab07be44c3b58a8f | The first line contains Bitlandish string a, the second line contains Bitlandish string b. The strings can have different lengths. It is guaranteed that the given strings only consist of characters "0" and "1". The strings are not empty, their length doesn't exceed 106. | 1,500 | Print "YES" if a can be transformed into b, otherwise print "NO". Please do not print the quotes. | standard output | |
PASSED | 4eef3c2368d408039cbfb2384441aa93 | train_002.jsonl | 1363188600 | The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.A Bitlandish string is a string made only of characters "0" and "1".BitHaval (the mayor of Bitland) loves to play with Bitlandish strings. He takes some Bitlandish string a, and applies several (possibly zero) operations to it. In one operation the mayor may take any two adjacent characters of a string, define one of them as x and the other one as y. Then he calculates two values p and q: p = x xor y, q = x or y. Then he replaces one of the two taken characters by p and the other one by q.The xor operation means the bitwise excluding OR operation. The or operation is the bitwise OR operation.So for example one operation can transform string 11 to string 10 or to string 01. String 1 cannot be transformed into any other string.You've got two Bitlandish strings a and b. Your task is to check if it is possible for BitHaval to transform string a to string b in several (possibly zero) described operations. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class Main {
static int log(int n){
int ans=0;
while (n>0){
++ans;
n/=2;
}
return ans;
}
public static void main (String[]args) throws IOException {
Scanner in = new Scanner(System.in);
try (PrintWriter or = new PrintWriter(System.out)) {
char[]a=in.next().toCharArray();
char[]b=in.next().toCharArray();
boolean ans_a = false;
boolean ans_b = false;
if(a.length==b.length){
for(int i=0;i<a.length;i++){
if(a[i]=='1'){
ans_a=true;
}
if(b[i]=='1'){
ans_b=true;
}
}
}
if(a.length==1){
ans_a=false;
}
if(new String(a).equals(new String(b))){
ans_a=true;
ans_b=true;
}
or.println(ans_a&&ans_b?"YES":"NO");
}
}
static long gcd(long a, long b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
static int getlen(int r,int l,int a){
return (r-l+1+1)/(a+1);
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public String nextLine() throws IOException {
return br.readLine();
}
public double nextDouble() throws IOException {
String x = next();
StringBuilder sb = new StringBuilder("0");
double res = 0, f = 1;
boolean dec = false, neg = false;
int start = 0;
if (x.charAt(0) == '-') {
neg = true;
start++;
}
for (int i = start; i < x.length(); i++) {
if (x.charAt(i) == '.') {
res = Long.parseLong(sb.toString());
sb = new StringBuilder("0");
dec = true;
} else {
sb.append(x.charAt(i));
if (dec) {
f *= 10;
}
}
}
res += Long.parseLong(sb.toString()) / f;
return res * (neg ? -1 : 1);
}
public boolean ready() throws IOException {
return br.ready();
}
}
}
class Pair implements Comparable<Pair> {
int first, second;
public Pair(int first, int second) {
this.first = first;
this.second = second;
}
@Override
public int compareTo(Pair o) {
if (first!=o.first)return first-o.first;
return second-o.second;
}
}
class Tempo {
int first,second,third;
public Tempo(int first, int second, int third) {
this.first = first;
this.second = second;
this.third = third;
}
} | Java | ["11\n10", "1\n01", "000\n101"] | 2 seconds | ["YES", "NO", "NO"] | null | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 113ae625e67c8ea5ab07be44c3b58a8f | The first line contains Bitlandish string a, the second line contains Bitlandish string b. The strings can have different lengths. It is guaranteed that the given strings only consist of characters "0" and "1". The strings are not empty, their length doesn't exceed 106. | 1,500 | Print "YES" if a can be transformed into b, otherwise print "NO". Please do not print the quotes. | standard output | |
PASSED | 97a9a808833268ddb949aabdade1abcb | train_002.jsonl | 1363188600 | The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.A Bitlandish string is a string made only of characters "0" and "1".BitHaval (the mayor of Bitland) loves to play with Bitlandish strings. He takes some Bitlandish string a, and applies several (possibly zero) operations to it. In one operation the mayor may take any two adjacent characters of a string, define one of them as x and the other one as y. Then he calculates two values p and q: p = x xor y, q = x or y. Then he replaces one of the two taken characters by p and the other one by q.The xor operation means the bitwise excluding OR operation. The or operation is the bitwise OR operation.So for example one operation can transform string 11 to string 10 or to string 01. String 1 cannot be transformed into any other string.You've got two Bitlandish strings a and b. Your task is to check if it is possible for BitHaval to transform string a to string b in several (possibly zero) described operations. | 256 megabytes | import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner s = new Scanner(System.in);
String str1 = s.next();
String str2 = s.next();
if(str1.length()!=str2.length()){
System.out.println("NO");
return;
}
boolean allzeros1 = true;
boolean allzeros2 = true;
for(int i=0;i<str1.length();i++){
if(str1.charAt(i)=='1'){
allzeros1 = false;
}
if(str2.charAt(i)=='1'){
allzeros2 = false;
}
}
if(allzeros1&&allzeros2){//both string are same
System.out.println("YES");
}else if(allzeros1||allzeros2){
System.out.println("NO");
}else{
System.out.println("YES");
}
}
} | Java | ["11\n10", "1\n01", "000\n101"] | 2 seconds | ["YES", "NO", "NO"] | null | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 113ae625e67c8ea5ab07be44c3b58a8f | The first line contains Bitlandish string a, the second line contains Bitlandish string b. The strings can have different lengths. It is guaranteed that the given strings only consist of characters "0" and "1". The strings are not empty, their length doesn't exceed 106. | 1,500 | Print "YES" if a can be transformed into b, otherwise print "NO". Please do not print the quotes. | standard output | |
PASSED | 3b790442f6b95919b83fddd6844f5c98 | train_002.jsonl | 1363188600 | The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.A Bitlandish string is a string made only of characters "0" and "1".BitHaval (the mayor of Bitland) loves to play with Bitlandish strings. He takes some Bitlandish string a, and applies several (possibly zero) operations to it. In one operation the mayor may take any two adjacent characters of a string, define one of them as x and the other one as y. Then he calculates two values p and q: p = x xor y, q = x or y. Then he replaces one of the two taken characters by p and the other one by q.The xor operation means the bitwise excluding OR operation. The or operation is the bitwise OR operation.So for example one operation can transform string 11 to string 10 or to string 01. String 1 cannot be transformed into any other string.You've got two Bitlandish strings a and b. Your task is to check if it is possible for BitHaval to transform string a to string b in several (possibly zero) described operations. | 256 megabytes | import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner s = new Scanner(System.in);
String str1 = s.next();
String str2 = s.next();
if(str1.length()!=str2.length()){
System.out.println("NO");
return;
}
boolean allzeros1 = true;
boolean allzeros2 = true;
for(int i=0;i<str1.length();i++){
if(str1.charAt(i)=='1'){
allzeros1 = false;
}
if(str2.charAt(i)=='1'){
allzeros2 = false;
}
}
if(allzeros1||allzeros2){
if(allzeros1&&allzeros2){
System.out.println("YES");
}else
System.out.println("NO");
}else{
System.out.println("YES");
}
}
} | Java | ["11\n10", "1\n01", "000\n101"] | 2 seconds | ["YES", "NO", "NO"] | null | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 113ae625e67c8ea5ab07be44c3b58a8f | The first line contains Bitlandish string a, the second line contains Bitlandish string b. The strings can have different lengths. It is guaranteed that the given strings only consist of characters "0" and "1". The strings are not empty, their length doesn't exceed 106. | 1,500 | Print "YES" if a can be transformed into b, otherwise print "NO". Please do not print the quotes. | standard output | |
PASSED | 4942c96bc5026cc9908d6d497ab2408a | train_002.jsonl | 1363188600 | The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.A Bitlandish string is a string made only of characters "0" and "1".BitHaval (the mayor of Bitland) loves to play with Bitlandish strings. He takes some Bitlandish string a, and applies several (possibly zero) operations to it. In one operation the mayor may take any two adjacent characters of a string, define one of them as x and the other one as y. Then he calculates two values p and q: p = x xor y, q = x or y. Then he replaces one of the two taken characters by p and the other one by q.The xor operation means the bitwise excluding OR operation. The or operation is the bitwise OR operation.So for example one operation can transform string 11 to string 10 or to string 01. String 1 cannot be transformed into any other string.You've got two Bitlandish strings a and b. Your task is to check if it is possible for BitHaval to transform string a to string b in several (possibly zero) described operations. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
String a=in.next();
String b=in.next();
if (a.length()!=b.length()){
System.out.println("NO");
}
else{
boolean o=false;
boolean t=false;
for (char temp:a.toCharArray()){
if (temp=='1'){
o=true;
}
}
for (char temp:b.toCharArray()){
if (temp=='1'){
t=true;
}
}
if(o==t){
System.out.println("YES");
}
else{
System.out.println("NO");
}
}
}
}
| Java | ["11\n10", "1\n01", "000\n101"] | 2 seconds | ["YES", "NO", "NO"] | null | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 113ae625e67c8ea5ab07be44c3b58a8f | The first line contains Bitlandish string a, the second line contains Bitlandish string b. The strings can have different lengths. It is guaranteed that the given strings only consist of characters "0" and "1". The strings are not empty, their length doesn't exceed 106. | 1,500 | Print "YES" if a can be transformed into b, otherwise print "NO". Please do not print the quotes. | standard output | |
PASSED | d70f9d8af7addbedb9870204783aee6d | train_002.jsonl | 1363188600 | The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.A Bitlandish string is a string made only of characters "0" and "1".BitHaval (the mayor of Bitland) loves to play with Bitlandish strings. He takes some Bitlandish string a, and applies several (possibly zero) operations to it. In one operation the mayor may take any two adjacent characters of a string, define one of them as x and the other one as y. Then he calculates two values p and q: p = x xor y, q = x or y. Then he replaces one of the two taken characters by p and the other one by q.The xor operation means the bitwise excluding OR operation. The or operation is the bitwise OR operation.So for example one operation can transform string 11 to string 10 or to string 01. String 1 cannot be transformed into any other string.You've got two Bitlandish strings a and b. Your task is to check if it is possible for BitHaval to transform string a to string b in several (possibly zero) described operations. | 256 megabytes | import java.util.*;
public class mohammad{
public static void main(String args[]){
Scanner U = new Scanner(System.in);
String a; a=U.next();
long p =a.length();
String b; b=U.next();
long q =b.length();
boolean a1=false,b1=false;
if(p!=q)
System.out.println("NO");
else{
for(int i=0;i<p;i++){
if(a.charAt(i)=='1') a1=true;
if(b.charAt(i)=='1') b1=true;
}
if(a1==b1)
System.out.println("YES");
else
System.out.println("NO");
}}} | Java | ["11\n10", "1\n01", "000\n101"] | 2 seconds | ["YES", "NO", "NO"] | null | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"math"
] | 113ae625e67c8ea5ab07be44c3b58a8f | The first line contains Bitlandish string a, the second line contains Bitlandish string b. The strings can have different lengths. It is guaranteed that the given strings only consist of characters "0" and "1". The strings are not empty, their length doesn't exceed 106. | 1,500 | Print "YES" if a can be transformed into b, otherwise print "NO". Please do not print the quotes. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.