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 | 620f9e9163986398b593bb535a2e5a98 | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes | import java.util.*;
public class Problem60 {
public static void main(String[] args) {
Scanner read=new Scanner(System.in);
int n=read.nextInt(),k=read.nextInt();
int covered=0;
for(int i=0 ; i<n ; i++) {
int l=read.nextInt();
int r=read.nextInt();
covered+=(r-l+1);
}
covered%=k;
if(covered!=0)covered=k-covered;
System.out.print(covered);
}
} | Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | 425107d038a5a4655cc9635bada951b1 | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes |
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int k = input.nextInt();
int[] x = new int[n];
int[] y = new int[n];
int[] temp = new int[n];
int counter = 0;
for(int i=0;i<n;i++) {
x[i] = input.nextInt();
y[i] = input.nextInt();
counter += (Math.abs(x[i] - y[i])+1);
}
int i = 0;
while((counter+i)%k != 0) {
i++;
}
System.out.println(i);
}
}
| Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | c75c10ec9677e67285e9b9e2d365216b | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes | import java.util.Scanner;
public class A289 {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int k = in.nextInt();
int a ;
int b ;
int x = 0;
for (int i = 0 ; i < n ; i++){
a = in.nextInt();
b = in.nextInt();
x+= Math.abs(b-a+1);
}
//System.out.println(x);
for (int i = 0 ;;i++){
if ( /*((x-i)%k==0 && (x-i)>=n*2) ||*/ (x+i)%k==0){
System.out.println(i);
break;
}
}
}
}
| Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | d23949931095e9549d6217d2318812d3 | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes | import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class a {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n=s.nextInt();
int k=s.nextInt();
int sum=0;
for(int i=0;i<n;i++){
int a1=s.nextInt();
int a2=s.nextInt();
sum+=a2-a1+1;
}
sum%=k;
if(sum!=0)
sum=k-sum;
System.out.println(sum);
}
}
| Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | 5aa8743751aeb223e3bef047ed7dbb80 | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes | import java.util.Scanner;
/**
* @author Abdelrahman Mamdouh
*/
public class solve {
public static void main(String[] args) {
Scanner abd =new Scanner(System.in);
int x=abd.nextInt(),z=abd.nextInt(),r=0,l=0,c=0;
for(int i=0;i<x;i++){
l=abd.nextInt();r=abd.nextInt();
c+=r-l+1;
}
int q=(z-(c%z))%z;
System.out.println(q);
}
} | Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | 7ebb80683e4365ade6c9efc4df4417b3 | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes |
import java.util.Scanner;
public class JavaApplication37 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int k=sc.nextInt();
int sum=0;
for(int i=0;i<n;i++){
int c=sc.nextInt();
int v=sc.nextInt();
sum+=v-c+1;
}
if(sum%k==0) System.out.println(0);
else System.out.println(k-(sum%k));
}} | Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | ebdc736c38fa933cd6387bc0dd446a0c | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes | import java.util.Scanner;
public class PoloThePenguinAndSegments {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n=in.nextInt();
int k=in.nextInt();
int length=0;
for(int i=0;i<n;i++)
{
int r=in.nextInt();
int l=in.nextInt();
length+=((l-r)+1);//dont understand this
}
if(length%k==0)
{
System.out.println(length%k);
}
else
{
length=length%k-k;
System.out.println(Math.abs(length));
}
}
} | Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | 7fb53739f3868b9b80a8dcfc83949c95 | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int k = in.nextInt();
int sum = 0;
for(int i = 0; i < n; i++){
int l = in.nextInt();
int r = in.nextInt();
sum += r - l + 1;
}
int ans = 0;
System.out.println((sum % k == 0)? 0: (k - sum % k));
}
}
| Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | 72be8ed49768a2928ad88e83b5f3e74f | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes | import java.io.*;
import java.util.*;
public final class code
// public class Main
// class code
// public class Solution
{
static void solve()throws IOException
{
int n=nextInt();
int k=nextInt();
int sum=0;
for(int i=1;i<=n;i++)
{
int l=nextInt();
int r=nextInt();
sum+=r-l+1;
}
sum=sum%k;
out.println(sum==0?0:k-sum);
}
///////////////////////////////////////////////////////////
static final long mod=(long)(1e9+7);
static final int inf=(int)(1e9+1);
static final int maxn=(int)(1e6);
static final long lim=(long)(1e18);
public static void main(String args[])throws IOException
{
br=new BufferedReader(new InputStreamReader(System.in));
out=new PrintWriter(new BufferedOutputStream(System.out));
solve();
// int t=nextInt();
// for(int i=1;i<=t;i++)
// {
// // out.print("Case #"+i+": ");
// solve();
// }
out.close();
}
static int max(int ... a)
{
int ret=a[0];
for(int i=1;i<a.length;i++)
ret=Math.max(ret,a[i]);
return ret;
}
static int min(int ... a)
{
int ret=a[0];
for(int i=1;i<a.length;i++)
ret=Math.min(ret,a[i]);
return ret;
}
static void debug(Object ... a)
{
System.out.print("> ");
for(int i=0;i<a.length;i++)
System.out.print(a[i]+" ");
System.out.println();
}
static void debug(int a[]){debuga(Arrays.stream(a).boxed().toArray());}
static void debug(long a[]){debuga(Arrays.stream(a).boxed().toArray());}
static void debuga(Object a[])
{
System.out.print("> ");
for(int i=0;i<a.length;i++)
System.out.print(a[i]+" ");
System.out.println();
}
static Random random;
static BufferedReader br;
static StringTokenizer st;
static PrintWriter out;
static String nextToken()throws IOException
{
while(st==null || !st.hasMoreTokens())
st=new StringTokenizer(br.readLine());
return st.nextToken();
}
static String nextLine()throws IOException
{
return br.readLine();
}
static int nextInt()throws IOException
{
return Integer.parseInt(nextToken());
}
static long nextLong()throws IOException
{
return Long.parseLong(nextToken());
}
static double nextDouble()throws IOException
{
return Double.parseDouble(nextToken());
}
} | Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | 3b0cad5ed902e566aedba8bd4a77cbc8 | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 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.StringTokenizer;
public class A {
public static void main(String[] args) throws Exception{
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = sc.nextInt(), k = sc.nextInt();
int sum = 0;
for(int i = 0; i < n; i++)
sum += -sc.nextInt() + sc.nextInt() + 1;
if(sum % k == 0) out.println(0);
else
{
int mult = sum / k + 1;
out.println(k * mult - sum);
}
out.flush();
out.close();
}
static class Scanner
{
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream System){ br = new BufferedReader(new InputStreamReader(System));}
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(){for(long i = 0; i < 3e9; i++);}
}
} | Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | 186f7eb1bcd5551ddd6d020ef5581d1e | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes | import java.util.Scanner;
public class main{
public static void main(String[] args){
Scanner sc= new Scanner(System.in);
int ar[];
ar = new int[sc.nextInt()*2];
int k = sc.nextInt();
for(int i=0;i<ar.length;i++){
ar[i]=sc.nextInt();
}
System.out.println(polo(ar,k));
}
static int polo(int [] arr,int k){
int count=0;
for(int i =0;i<arr.length-1;i+=2){
count+= sum_range(arr[i],arr[i+1]);
}
return (k-(count%k))%k;
}
static int sum_range(int a,int b){
// return b*(b+1)/2-a*(a-1)/2;
return b-a+1;
}
} | Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | c647ce8ae1be77c7e57c865521d597e7 | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.BufferedReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author Hamza Hasbi
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
Polo_the_Penguin_and_Segments solver = new Polo_the_Penguin_and_Segments();
solver.solve(1, in, out);
out.close();
}
static class Polo_the_Penguin_and_Segments {
public void solve(int testNumber, InputReader in, OutputWriter out) {
int n = in.nextInt();
int k = in.nextInt();
int ans = 0;
for (int i = 0; i < n; i++) {
int a = in.nextInt();
int b = in.nextInt();
ans += b - a + 1;
}
if (ans % k == 0) out.printLine(0);
else {
int curr = k;
while (curr < ans) {
curr += k;
}
out.printLine(curr - ans);
}
}
}
static class InputReader {
BufferedReader reader;
StringTokenizer st;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
st = null;
}
public String next() {
while (st == null || !st.hasMoreTokens()) {
try {
String line = reader.readLine();
if (line == null) {
return null;
}
st = new StringTokenizer(line);
} catch (Exception e) {
throw new RuntimeException();
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void printLine(int i) {
writer.println(i);
}
public void close() {
writer.close();
}
}
}
| Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | a6a46e2e3e47ce522238bd64bf3a4951 | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes |
import java.util.Scanner;
public class A289_Polo_the_Penguin_and_Segments {
public static void main(String[] args) {
Scanner ss = new Scanner (System.in ) ;
int n = ss.nextInt() ;
int k = ss.nextInt() ;
int x = 0 ;
for (int i = 0 ; i < n ; ++ i ) {
int f = ss.nextInt() ;
int s = ss.nextInt();
x += (s-f+1) ;
}
if (x%k==0) {
System.out.println(0);
}
else {
System.out.println(k-x%k);
}
}
}
| Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | 2f8fae9c70c051be67e78d4a3dddc99e | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes |
import java.util.Scanner;
public class JavaApplication2
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int n=in.nextInt();
int k=in.nextInt();
int sum=0;
for(int i=0;i<n;i++)
{
int a=in.nextInt();
int b=in.nextInt();
sum+=(b-a+1);
}
sum=sum%k;
sum=k-sum;
System.out.println(sum%k);
}
}
| Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | 7bbd407c1d026fef6f8b40f476ef29aa | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
boolean env=System.getProperty("ONLINE_JUDGE") != null;
if(!env) {
try {
br=new BufferedReader(new FileReader("src\\input.txt"));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
else {
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 int MOD=1000000000+7;
//Radix Sort
public static int[] radixSort(int[] f){ return radixSort(f, f.length); }
public static int[] radixSort(int[] f, int n)
{
int[] to = new int[n];
{
int[] b = new int[65537];
for(int i = 0;i < n;i++)b[1+(f[i]&0xffff)]++;
for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
for(int i = 0;i < n;i++)to[b[f[i]&0xffff]++] = f[i];
int[] d = f; f = to;to = d;
}
{
int[] b = new int[65537];
for(int i = 0;i < n;i++)b[1+(f[i]>>>16)]++;
for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
for(int i = 0;i < n;i++)to[b[f[i]>>>16]++] = f[i];
int[] d = f; f = to;to = d;
}
return f;
}
//Brian Kernighan’s Algorithm
static long countSetBits(long n){
if(n==0) return 0;
return 1+countSetBits(n&(n-1));
}
//Euclidean Algorithm
static long gcd(long A,long B){
if(B==0) return A;
return gcd(B,A%B);
}
//Modular Exponentiation
static long fastExpo(long x,long n){
if(n==0) return 1;
if((n&1)==0) return fastExpo((x*x)%MOD,n/2)%MOD;
return ((x%MOD)*fastExpo((x*x)%MOD,(n-1)/2))%MOD;
}
//AKS Algorithm
static boolean isPrime(long 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+=6)
if(n%i==0 || n%(i+2)==0) return false;
return true;
}
//Sieve of eratosthenes
static int[] findPrimes(int n){
boolean isPrime[]=new boolean[n+1];
ArrayList<Integer> a=new ArrayList<>();
int result[];
Arrays.fill(isPrime,true);
isPrime[0]=false;
isPrime[1]=false;
for(int i=2;i*i<=n;++i){
if(isPrime[i]==true){
for(int j=i*i;j<=n;j+=i) isPrime[j]=false;
}
}
for(int i=0;i<=n;i++) if(isPrime[i]==true) a.add(i);
result=new int[a.size()];
for(int i=0;i<a.size();i++) result[i]=a.get(i);
return result;
}
//Lower Bound
static int lowerBound(ArrayList<Long> a, int low, int high, long element){
while(low < high){
int middle = low + (high - low)/2;
if(element > a.get(middle))
low = middle + 1;
else
high = middle;
}
return low;
}
//Upper Bound
static int upperBound(ArrayList<Long> a, int low, int high, long element){
while(low < high){
int middle = low + (high - low)/2;
if(a.get(middle) > element)
high = middle;
else
low = middle + 1;
}
return low;
}
public static void main (String[] args) throws java.lang.Exception
{
FastReader sc=new FastReader();
int test=1;
while(test-->0) {
int n=sc.nextInt(),k=sc.nextInt();
int ans=0;
for(int i=0;i<n;i++) {
int l=sc.nextInt(),r=sc.nextInt();
ans+=(r-l+1);
}
System.out.println((long)Math.ceil((double)ans/k)*k-ans);
}
}
} | Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | f31860a69011e489e897143949c33d6b | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes |
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int n=input.nextInt();
int k=input.nextInt();
int nm=0;
for(int i=0;i<n;i++){
int s=input.nextInt();
int e=input.nextInt();
nm+=(e-s+1);
}
if(nm==k){
System.out.println(0);
}else{
int num=nm%k;
if(num==0){
System.out.print(0);
}else{
System.out.print(k-num);
}
}
}
} | Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | bef211f66cac6792e273a7cb9b92c352 | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
FastReader read = new FastReader();
StringBuilder out = new StringBuilder();
int n = read.nextInt();
int k = read.nextInt();
int s , e;
int sum = 0;
for (int i = 0; i < n; i++) {
s = read.nextInt();
e = read.nextInt();
sum += (e - s) + 1;
}
int ans = 0;
if(sum % k != 0) {
while(sum % k != 0){
sum++;
ans++;
}
}
System.out.println(ans);
}
}
class Point {
int x, y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
}
class Pair implements Comparable<Pair> {
int x, y;
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public int compareTo(Pair o) {
if (this.x - o.x != 0) {
return this.x - o.x;
} else {
return o.y - this.y;
}
}
}
class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
| Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | 22e6f53b13deac70542c431028510a59 | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes |
import java.util.Scanner;
/**
*
* @author sokol
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int sum = 0;
int k = in.nextInt();
for (int i = 0; i < n; i++) {
int l = in.nextInt();
int r = in.nextInt();
sum += r - l + 1;
}
if (sum % k == 0) {
System.out.println("0");
return;
}
System.out.println(k - (sum % k));
}
}
| Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | 3a55bb32ee45bdcafd03e860925ea90c | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class CodeForces {
public static void main(String[] args) throws IOException {
reader input = new reader();
int n=input.nextInt();
int k=input.nextInt();
int total=0;
for(int i=0;i<n;i++){
int a=input.nextInt();
int b=input.nextInt();
total+=(b-a+1);
}
if(total%k==0)
System.out.println(0);
else
System.out.println(k-total%k);
}
}
class reader {
BufferedReader br;
StringTokenizer st;
public reader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
| Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | af8adb0b78e65fd2a5d1164ac8a61e7b | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes | import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.*;
import java.math.BigInteger;
import java.util.regex.*;
public class Test {
public static long mod = 1000000007;
public static void main(String[] args) {
FastReader cin = new FastReader(System.in);
PrintWriter cout = new PrintWriter(System.out);
// Hello
long n,m,i,j,k,l,x,y,z,cnt=0,ans=0;
n=cin.LONG();
k=cin.LONG();
for(i=0;i<n;i++){
x=cin.INT();
y=cin.INT();
cnt+=y-x+1;
}
while(cnt%k!=0){
cnt++;
ans++;
}
cout.print(ans);
// Bye
cout.flush();
cout.close();
}
private static void debug(Object... o) {System.out.println(Arrays.deepToString(o)); }
static class FastReader {
private final InputStream stream;
private final byte[] buf = new byte[8192];
private int curChar, snumChars;
private SpaceCharFilter filter;
public FastReader(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 INT() {
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 LONG(){
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[] ARRAY(int n) {
int a[] = new int[n];
for (int i = 0; i < n; i++) a[i] = INT();
return a;
}
public String NEXT(){
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 LINE(){
int c = snext();
while (isSpaceChar(c)) c = snext();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = snext();
} while (!isEndOfLine(c));
return res.toString();
}
public boolean isSpaceChar(int c){
if (filter != null) return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private boolean isEndOfLine(int c){return c == '\n' || c == '\r' || c == -1;}
public interface SpaceCharFilter{public boolean isSpaceChar(int ch);}
}
public static long[] suffle(long[] a,Random gen){
int n = a.length;
for(int i=0;i<n;i++){
int ind = gen.nextInt(n-i)+i;
long temp = a[ind];
a[ind] = a[i];
a[i] = temp;
}
return a;
}
public static <T> T swap(T a, T b){
return a;
}
public static HashSet<Integer> primeFactorization(int n)
{
HashSet<Integer> a =new HashSet<Integer>();
for(int i=2;i*i<=n;i++)
{
while(n%i==0)
{
a.add(i);
n/=i;
}
}
if(n!=1)
a.add(n);
return a;
}
public static void sieve(boolean[] pr,int lim)
{
for(int i=1;i<lim;i++) pr[i] = true;
pr[0] = pr[1] = false;
for(int i=2;i*i<lim;i++){
if(pr[i] == true){
for(int j=(2*i);j<lim;j+=i) pr[j] = false;
}
}
}
public static int GCD(int a,int b){
if(b==0) return a;
else return GCD(b,a%b);
}
static class pair implements Comparable<pair>
{
Integer x;
Integer y;
pair(int a,int a2){
this.x=a;
this.y=a2;
}
public int compareTo(pair o) {
int result = x.compareTo(o.x);
if(result==0) result = y.compareTo(o.y);
return result;
}
public String toString(){
return x+" "+y;
}
public boolean equals(Object o){
if (o instanceof pair){
pair p = (pair)o;
return p.x == x && p.y == y ;
}
return false;
}
public int hashCode(){
return new Long(x).hashCode()*31 + new Long(y).hashCode();
}
}
}
| Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | 198aef0747a49993dfd604d0d3b0d6be | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes | import java.util.HashSet;
import java.util.Scanner;
public class JavaApplication55 {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
HashSet<Integer> set=new HashSet();
int n=s.nextInt(),k=s.nextInt();
int x,y;
for (int i = 0; i < n; i++) {
x=s.nextInt();
y=s.nextInt();
for (int j = x; j <= y; j++) {
set.add(j);
}
}
int set_count=set.size();
while(set_count%k!=0){
set_count++;
}
System.out.println(set_count-set.size());
}
} | Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | e96bc11a23667cba0aebaea7063d8bbb | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes | import java.util.Scanner;
public class CF177A {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int k = scan.nextInt();
long count = 0;
for(int i = 0; i < n; i++){
int left = scan.nextInt();
int right = scan.nextInt();
count += (right-left)+1;
}
if(count % k == 0){
System.out.println("0");
return;
}
long ans = k - (count%k);
System.out.println(ans);
}
}
| Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | e7c21b75280c2dfbc76ce356d4c0d3d7 | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes |
import static java.lang.System.exit;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
import java.util.*;
/**
*
* @author abdelmagied
*/
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import javafx.scene.Node;
/**
*
* @author abdelmagied
*/
public class JavaApplication1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt() , k = sc.nextInt();
int sum = 0;
for(int i = 0 ; i < n ; i++){
int from = sc.nextInt() , to = sc.nextInt();
sum += (to - from) + 1;
}
int ans = (sum % k==0)?0:k - (sum % k);
System.out.println(ans);
}
}
| Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | e082935ca1656b54e297cbbe81dcf7e1 | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes |
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class PoloThePenguinAndSegments implements Closeable {
private InputReader in = new InputReader(System.in);
private PrintWriter out = new PrintWriter(System.out);
public void solve() {
int n = in.ni();
long k = in.ni();
long total = 0;
for (int i = 0; i < n; i++) {
long u = in.nl(), v = in.nl();
total += (v - u + 1L);
}
long rem = total % k;
if (rem > 0) {
rem = k - rem;
}
out.println(rem);
}
@Override
public void close() throws IOException {
in.close();
out.close();
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int ni() {
return Integer.parseInt(next());
}
public long nl() {
return Long.parseLong(next());
}
public void close() throws IOException {
reader.close();
}
}
public static void main(String[] args) throws IOException {
try (PoloThePenguinAndSegments instance = new PoloThePenguinAndSegments()) {
instance.solve();
}
}
}
| Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | 580ec27d8dcaaf86e09e505fba30f545 | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes |
import java.util.*;
public class Debug {
private static Scanner in =new Scanner(System.in);
public static void main(String[] args) {
int n=in.nextInt();
double k=in.nextInt();
Segement[]z=new Segement[n];
for(int i=0;i<n;i++)
z[i]=new Segement(in.nextInt(),in.nextInt());
Arrays.sort(z);
double count=z[0].b-z[0].a+1;
int last=z[0].b;
for(int i=1;i<n;i++){
Segement s=z[i];
if(last<=s.a){
last=s.b;
count+=(s.b-s.a)+1;
}
}
double res=count/k;
res=Math.ceil(res);
double d=k*res;
int ans=(int) (d-count);
System.out.println(ans);
}
private static class Segement implements Comparable<Segement>{
int a=-1,b=-1;
public Segement(int x,int y){
this.a=x;
this.b=y;
}
@Override
public int compareTo(Segement t) {
return this.b-t.b;
}
}
}
| Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | 0b85592a2aa4875c91e551e9366ea50b | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes | /**
* @(#)PoloThePernguinAndSegments.java
*
*
* @author
* @version 1.00 2017/6/23
*/
import java.util.*;
public class PoloThePernguinAndSegments {
public static void main(String[] args) {
// TODO code application logic here
Scanner in=new Scanner(System.in);
int start,end,covered=0;
int n=in.nextInt();
int k=in.nextInt();
for(int i=0;i<n;i++){
start=in.nextInt();
end=in.nextInt();
covered+=end-start+1;
}
covered%=k;
if(covered!=0){
covered=k-covered;
}
System.out.println(covered);
}
}
| Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | 804a61af0ef55aa2e257608a62e17022 | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes | import java.util.*;
import java.io.*;
//267630EY
public class Main289A
{
static PrintWriter out=new PrintWriter(System.out);
public static void main(String[] args) throws IOException
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int k=sc.nextInt();
int sum=0;
for(int i=0;i<n;i++)
{
int l=sc.nextInt();
int r=sc.nextInt();
sum+=(r-l+1);
}
if(sum%k==0)
out.println(0);
else
out.println(k-sum%k);
out.flush();
}
static class Scanner
{
BufferedReader br;
StringTokenizer tk=new StringTokenizer("");
public Scanner(InputStream is)
{
br=new BufferedReader(new InputStreamReader(is));
}
public int nextInt() throws IOException
{
if(tk.hasMoreTokens())
return Integer.parseInt(tk.nextToken());
tk=new StringTokenizer(br.readLine());
return nextInt();
}
public long nextLong() throws IOException
{
if(tk.hasMoreTokens())
return Long.parseLong(tk.nextToken());
tk=new StringTokenizer(br.readLine());
return nextLong();
}
public String next() throws IOException
{
if(tk.hasMoreTokens())
return (tk.nextToken());
tk=new StringTokenizer(br.readLine());
return next();
}
public String nextLine() throws IOException
{
tk=new StringTokenizer("");
return br.readLine();
}
public double nextDouble() throws IOException
{
if(tk.hasMoreTokens())
return Double.parseDouble(tk.nextToken());
tk=new StringTokenizer(br.readLine());
return nextDouble();
}
public char nextChar() throws IOException
{
if(tk.hasMoreTokens())
return (tk.nextToken().charAt(0));
tk=new StringTokenizer(br.readLine());
return nextChar();
}
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[] nextIntArrayOneBased(int n) throws IOException
{
int a[]=new int[n+1];
for(int i=1;i<=n;i++)
a[i]=nextInt();
return a;
}
public long[] nextLongArrayOneBased(int n) throws IOException
{
long a[]=new long[n+1];
for(int i=1;i<=n;i++)
a[i]=nextLong();
return a;
}
}
}
| Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | a445bb3ba01f4d4183a0a70ea99b120e | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes |
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt(), k = in.nextInt();
long r = 0;
while (n-- != 0) {
r += -(in.nextInt() - in.nextInt());
r++;
}
if(r%k != 0)
System.out.println(k-r%k);
else
System.out.println(0);
}
} | Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | 2bdd3c68f98096ae25d5cd7a63cf57cd | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes |
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt(), k = in.nextInt();
int r = 0;
while (n-- != 0) {
r += -(in.nextInt() - in.nextInt());
r++;
}
if(r%k != 0)
System.out.println(k-r%k);
else
System.out.println(0);
}
} | Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | 18012f97135b91e594f4d404d8e689c6 | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes | //package codeforces.A;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class PoloThePenguinAndSegments {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer tokenizer = new StringTokenizer(bufferedReader.readLine(), " ");
int n = Integer.parseInt(tokenizer.nextToken());
int k = Integer.parseInt(tokenizer.nextToken());
int x = 0;
for (int i = 0; i < n; i++) {
tokenizer = new StringTokenizer(bufferedReader.readLine(), " ");
x++;
int num1 = Integer.parseInt(tokenizer.nextToken());
int num2 = Integer.parseInt(tokenizer.nextToken());
x += num2 - num1;
}
if (x >= k && x % k == 0) {
System.out.println(0);
} else if (k > x) {
System.out.println(k - x);
} else {
System.out.println(k - x % k);
}
}
}
| Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | ca479ebe0fcd997652490eafc5356158 | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes | import java.util.Scanner;
public class CF289A {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int k = s.nextInt();
int value = 0;
for (int i = 0; i < n; i++) {
int l = s.nextInt();
int r =s.nextInt();
if((r-l)==1) {
value+=2;
}else {
value+=2+((r-l)-1);
}
}
if(value%k==0) {
System.out.println(0);
}else {
int a = ((int)value/k)+1;
int target = a*k;
System.out.println(target-value);
}
}
}
| Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | c99923512a6a28f30a974ba08c7cb2ab | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes | //package Div2A;
import java.util.Scanner;
public class PolothePenguinandSegments {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
int left[] = new int[n];
int right[] = new int[n];
int sum = 0;
for (int i = 0; i < right.length; i++) {
left[i] = sc.nextInt();
right[i] = sc.nextInt();
sum += (right[i] - left[i]) + 1;
}
System.out.println(sum%k!=0?k - sum%k:0);
}
}
| Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | 6a699af78d3f5af9f64954faf366532b | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes | import java.util.Scanner;
public class A289 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int N = in.nextInt();
int K = in.nextInt();
long sum = 0;
for (int n=0; n<N; n++) {
int L = in.nextInt();
int R = in.nextInt();
sum += R-L+1;
}
long r = sum%K;
long answer = (r == 0) ? 0 : K-r;
System.out.println(answer);
}
}
| Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | 1d7b27e36760582181d7554a55fbdeb6 | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
int n, k, interval=0;
Scanner input = new Scanner(System.in);
n = input.nextInt();
k = input.nextInt();
for(int i=0; i<n; i++)
{
int start = input.nextInt();
int end = input.nextInt();
interval += ((end-start) + 1);
}
System.out.println( (k - (interval%k) ) % k);
}
} | Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | 707ca026b186809cbeb6105ae578ee2e | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
/**
* 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);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
static class TaskA
{
public void solve(int testNumber, Scanner in, PrintWriter out)
{
int n = in.nextInt();
int k = in.nextInt();
int L[][] = new int[n][2];
for (int i = 0; i < n; i++)
{
L[i] = CPUtils.readIntArray(2, in);
}
int value = 0;
for (int i = 0; i < n; i++)
{
value += L[i][1] - L[i][0] + 1;
}
if (value % k == 0)
out.print(0);
else
out.print(k - value % k);
}
}
static class CPUtils
{
public static int[] readIntArray(int size, Scanner in)
{
int[] array = new int[size];
for (int i = 0; i < size; i++)
{
array[i] = in.nextInt();
}
return array;
}
}
}
| Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | 058f5d8268af0341ee1e842e975bcc6d | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int covered = 0;
int n = sc.nextInt();
int k = sc.nextInt();
for (int i = 0; i < n; i++) {
int start = sc.nextInt();
int end = sc.nextInt();
sc.nextLine();
covered += (end - start + 1);
}
int whole = covered / k;
int answer = k * (whole + 1) - covered;
if (covered % k == 0)
System.out.println(0);
else
System.out.println(answer);
}
} | Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | 2bff9f66d28e7db4680256e1aa83d59c | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes | public class Problem {
public static void main(String[] args) {
java.util.Scanner input = new java.util.Scanner(System.in);
long n = input.nextInt();
long k = input.nextInt();
long sum = 2*n , f , s;
for (int i = 0 ; i < n ; i++ ){
f = input.nextLong() ; s = input.nextLong();
if ( s-f == 0 )
sum--;
else if( s-f >= 2 )
sum += (s-f)-1;
}
if ( sum % k == 0 )
System.out.println(0);
else{
System.out.println(k - (sum%k));
}
}
}
| Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | baa41c7bf9d59ef72569d0892bd17cc8 | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes | import java.io.*;
import java.util.*;
public class A {
public static void main(String[] args) throws Exception {
BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
Scanner s = new Scanner(System.in);
String[] split = f.readLine().split("\\s+");
int n = Integer.parseInt(split[0]), k = Integer.parseInt(split[1]);
int diff = 0;
for(int i = 0; i < n; i++) {
split = f.readLine().split("\\s+");
int l = Integer.parseInt(split[0]), r = Integer.parseInt(split[1]);
diff += r - l + 1;
}
int cnt = 0;
// System.out.println(diff);
for(int i = diff; true ; i++) {
if(i%k == 0) {
break;
}
cnt++;
}
System.out.println(cnt);
}
} | Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | 35ec396e8ccde125347f6892690d1c99 | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes | import java.util.Scanner;
public class Segments {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
int n = keyboard.nextInt();
int k = keyboard.nextInt();
int value = 0;
for (int i = 0; i < n; i++) {
int a = keyboard.nextInt();
int b = keyboard.nextInt();
value += (b-a + 1);
}
if(value%k==0)
{
System.out.println("0");
}
else
{
System.out.println(k-value%k);
}
}
}
| Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | 72d92ec4d2a887285895f6d811e9100f | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes |
import java.util.*;
public class Code {
public static void main(String[] argh) {
Scanner input = new Scanner(System.in);
int n = input.nextInt(), k = input.nextInt();
int set_value = 0;
for (int i = 0; i < n; i++) {
int l = input.nextInt();
int r = input.nextInt();
set_value += r-l +1;
}
int r = set_value % k;
System.out.println(r == 0 ? 0 : k-r);
}
} | Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | dad26fa7224e3a1b36ce4079cfc75f6d | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
public class GGWPLivaem implements Runnable{
boolean withFiles = false;
class cc implements Comparable<cc>{
public int x, y;
cc(int x, int y) {
this.x = x;
this.y = y;
}
public int compareTo(cc other) {
if (this.x == other.x) {
return Integer.compare(this.y, other.y);
}
return Integer.compare(this.x, other.x);
}
}
private void solve() throws IOException {
int n = in.nextInt(), k = in.nextInt();
long ss = 0;
for (int i = 1; i <= n; ++i) {
int a = in.nextInt(), b = in.nextInt();
ss += b - a + 1;
}
out.printf("%d", (k - ss % k) % k);
}
private static class FastScanner{
private BufferedReader reader;
private StringTokenizer tokenizer;
String cache;
int cur;
FastScanner(Reader r) throws IOException{
reader = new BufferedReader(r);
tokenizer = new StringTokenizer("");
cache = null;
cur = 0;
}
public boolean hasNext(){
if (cache != null && cur < cache.length())
return true;
try {
while (!tokenizer.hasMoreTokens()){
String line = reader.readLine();
if (line == null)
return false;
tokenizer = new StringTokenizer(line);
}
cache = tokenizer.nextToken();
cur = 0;
}
catch(IOException e) {
return false;
}
return true;
}
public char nextChar() throws IOException{
if (!hasNext())
throw new EOFException();
return cache.charAt(cur++);
}
public String next() throws IOException{
if (!hasNext())
throw new EOFException();
String result = (cur == 0) ? cache : cache.substring(cur);
cache = null;
return result;
}
public int nextInt() throws IOException{
return Integer.parseInt(this.next());
}
public long nextLong() throws IOException{
return Long.parseLong(this.next());
}
public double nextDouble() throws IOException{
return Double.parseDouble(this.next());
}
public BigInteger nextBigInteger() throws IOException{
return new BigInteger(this.next());
}
public void close() throws IOException{
reader.close();
tokenizer = new StringTokenizer("");
}
}
public static void main(String args[]) throws IOException{
new Thread(null, new GGWPLivaem(), "Thread #228", 64 * 1024 * 1024).start();
}
public void run(){
try{
if (withFiles) {
in = new FastScanner(new FileReader("input.txt"));
out = new PrintWriter(new FileWriter("output.txt"));
}
else {
in = new FastScanner(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
}
solve();
in.close();
out.close();
}
catch(IOException e){
e.printStackTrace();
}
}
FastScanner in;
PrintWriter out;
}
| Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | ad53264b3f152373486f37599914ffd3 | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes | import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.Map;
import java.util.Map.Entry;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
int l=sc.nextInt();
boolean adi=false;
int m=sc.nextInt();
int cp=0,a=0;
int[][] arr=new int[l][2];
for(int i=0;i<l;i++){
arr[i][0]=sc.nextInt();
arr[i][1]=sc.nextInt();
a=a+arr[i][1]-arr[i][0]+1;
}
if(a%m==0)
System.out.println(0);
else
{
while(!adi){
cp++;
a++;
if(a%m==0){
adi=true;
System.out.println(cp);
}
}
}
}
}
| Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | acfd269046a3c83ee471393f719597aa | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes | import java.util.Scanner;
public class CF289_D2_A {
public static void main(String[] args) {
// time reading 5 min
// think 1 min
// implement time 6 min
// debug 0 min
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int k = scanner.nextInt();
int sum = 0;
for (int i = 0; i < n; i++) {
int x = scanner.nextInt();
int y = scanner.nextInt();
sum += (y - x + 1);
}
if (sum % k == 0) {
System.out.println(0);
return;
}
System.out.println(k - (sum % k));
}
}
| Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | 1b0906f8a3bc08ea14ff9f76f445605d | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class A289 {
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 in = new FastReader();
int n = in.nextInt();
int k = in.nextInt();
long sum = 0;
for (int i = 0; i < n; i++) {
sum += Math.abs(in.nextInt() - in.nextInt()) + 1;
}
for (int i = 0; i <= k; i++) {
if ( (sum + i) % k == 0) {
System.out.println(i);
return;
}
}
}
}
| Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | 7ab04b52edd3a55125c8b5402ca3add6 | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes |
import java.util.Scanner;
public class PoloThePenguinAndSegments {
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
int n = input.nextInt();
int k = input.nextInt();
int total = 0 ;
for (int i = 0 ; i < n ; i++) {
int x = input.nextInt();
int y = input.nextInt();
total += (Math.abs(y-x) + 1);
}
for (int i = 0 ; i < k ; i++) {
if((total + i) % k == 0)
{
System.out.println(i);
return;
}
}
}
}
| Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | f0fe8bd0ea35a751ef6b9cbd6a2fd7a3 | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes | import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int k=sc.nextInt();
int l[]=new int[n];
int r[]=new int[n];
for(int i=0;i<n;i++)
{
l[i]=sc.nextInt();r[i]=sc.nextInt();
}
int ans=0;
for(int i=0;i<n;i++)
{
ans+=(r[i]-l[i]+1);
}
int tp=0;
if(ans%k!=0)
{
tp+=(k-(ans%k));
}
System.out.println(tp);
}
} | Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | 8f6f0c5c52b3600436d409a525457225 | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes | import java.util.Scanner;
public class PolothePenguin {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int k = input.nextInt();
long total=0;
for(int i=0; i<n;i++){
int l = input.nextInt();
int r = input.nextInt();
total+=(r-l+1);
}
int z = (int)(total%k);
if(z!=0){
System.out.println(k-z);
}
else
System.out.println(0);
}
}
| Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | 6900325328253bf01092eba5d399a458 | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes | import java.io.*;
import java.util.*;
public class PoloThePenguinAndSegments {
public static void main(String[] args) {
FastReader sc=new FastReader();
int n=sc.nextInt();
int k=sc.nextInt();
int s=0;
for(int i=0;i<n;i++){
s+=-sc.nextInt()+sc.nextInt()+1;
}
if(s%k==0)System.out.print(0);
else System.out.print(k-(s%k));
}
}
class FastReader{
BufferedReader br ;
StringTokenizer st;
public FastReader(){
InputStreamReader inr =new InputStreamReader(System.in);
br=new BufferedReader(inr);
}
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());
}
double nextDouble(){
return Double.parseDouble(next());
}
long nextLong(){
return Long.parseLong(next());
}
String nextLine(){
String str="";
try{
str=br.readLine();
}
catch(IOException e)
{
e.printStackTrace();
}
return str;
}
} | Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | b4ae3ed688e3e88653da66096dc4c375 | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes | import java.util.*;
import java.awt.Desktop;
import java.io.*;
import java.math.BigInteger;
import java.net.URI;
import javafx.util.Pair;
public class codeforces {
/*help fun*/
static boolean prime(long a)
{
for(int i=2;i*i<=a;i++)
{
if(a%i==0)
return false;
}
return true;
}
public static int fact(int a)
{
if(a==0)
return 1;
return a*fact(a-1);
}
/*main*/
public static void main(String[] args) {
Scanner read = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
PrintWriter out=new PrintWriter(System.out);
ArrayList<Pair<Integer,String>> arrofPair=new ArrayList<>();
Set<Integer> T=new TreeSet<>();
//raw type because i didn't specify the parameterized type and it become Stack<Object>
Stack S=new Stack();
Map<Character ,Integer>map=new HashMap<>();
StringBuilder Str= new StringBuilder();
/*code*/
int n=read.nextInt(),k=read.nextInt(),counter=0;
for(int i=0;i<n;++i)
{
int s=read.nextInt(),e=read.nextInt();
counter+=e-s+1;
}
int s=counter%k;
if(s==0)
System.out.println(0);
else
System.out.println(k-s);
}
}
| Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | f364c7fc5169d585ce2c89ecbd2deb95 | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes | import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
public class Main {
InputStream is;
PrintWriter out;
String INPUT = "";
void solve()
{
int n=ni(),k=ni();
int l=0,r=0;
int ans=0;
for(int i=0;i<n;++i)
{
l=ni();
r=ni();
ans+=(r-l+1);
}
if(ans%k==0) out.println("0");
else out.println(k-ans%k);
}
void run() throws Exception
{
is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
out = new PrintWriter(System.out);
long s = System.currentTimeMillis();
solve();
out.flush();
if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
}
public static void main(String[] args) throws Exception { new Main().run(); }
private byte[] inbuf = new byte[1024];
public int lenbuf = 0, ptrbuf = 0;
private int readByte()
{
if(lenbuf == -1)throw new InputMismatchException();
if(ptrbuf >= lenbuf){
ptrbuf = 0;
try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
if(lenbuf <= 0)return -1;
}
return inbuf[ptrbuf++];
}
private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
private double nd() { return Double.parseDouble(ns()); }
private char nc() { return (char)skip(); }
private String ns()
{
int b = skip();
StringBuilder sb = new StringBuilder();
while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private char[] ns(int n)
{
char[] buf = new char[n];
int b = skip(), p = 0;
while(p < n && !(isSpaceChar(b))){
buf[p++] = (char)b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
private char[][] nm(int n, int m)
{
char[][] map = new char[n][];
for(int i = 0;i < n;i++)map[i] = ns(m);
return map;
}
private int[] na(int n)
{
int[] a = new int[n];
for(int i = 0;i < n;i++)a[i] = ni();
return a;
}
private int ni()
{
int num = 0, b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-'){
minus = true;
b = readByte();
}
while(true){
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
b = readByte();
}
}
private long nl()
{
long num = 0;
int b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-'){
minus = true;
b = readByte();
}
while(true){
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
b = readByte();
}
}
private void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); }
}
| Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | 083709bc1dc692dbf06797e51077c600 | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 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.StringTokenizer;
public class Abood2B {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = sc.nextInt();
int k = sc.nextInt();
int v = 0;
for (int i = 0; i < n; i++)
v += (-sc.nextInt() + sc.nextInt() + 1);
out.println((k - v % k) % k);
out.flush();
out.close();
}
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();}
}
} | Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | 36e8387287bb9e27b75a538874cfdd6f | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes | import java.util.Scanner;
public class PoloThePenguinAndSegments {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt(), k = sc.nextInt(), x = 0;
for (int i = 0; i < n; i++) {
int r = sc.nextInt(), l = sc.nextInt();
x += Math.abs(l - r) + 1;
}
int mod = x % k;
System.out.println(mod == 0? 0 : k - mod);
sc.close();
}
}
| Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | 423d5bb2b79c7cf1540df9f315f87e99 | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes | import java.util.Scanner;
public class PoloThePenguinAndSegments {
public static void main (String... args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int k = scanner.nextInt();
int total=0;
while (n-- > 0){
int start = scanner.nextInt();
int end = scanner.nextInt();
total+= end - start + 1;
}
int moves = 0;
int reminder = total % k;
if (reminder != 0){
moves = k - reminder;
}
System.out.println(moves);
}
}
| Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | f96f0e882e18fba6eb5759561e7c7b0a | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes | import java.util.Scanner;
import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
import static java.lang.Math.*;
public class TestClass //implements Runnable
{
/*int x,y;
public TestClass(int x,int y)
{
this.x=x;
this.y=y;
}*/
public static void main(String args[]) throws Exception
{/*
new Thread(null, new TestClass(),"TESTCLASS",1<<23).start();
}
public void run()
{*/
//Scanner scan=new Scanner(System.in);
InputReader hb=new InputReader(System.in);
PrintWriter w=new PrintWriter(System.out);
int n=hb.nextInt();
int k=hb.nextInt();
int count=0;
for(int i=0;i<n;i++)
{
int a=hb.nextInt();
int b=hb.nextInt();
count+=b-a+1;
}
if(count%k==0)
w.print("0");
else
w.print(k - (count%k));
w.close();
}
private static void shuffle(int[] arr)
{
Random ran = new Random();
for (int i = 0; i < arr.length; i++) {
int i1 = ran.nextInt(arr.length);
int i2 = ran.nextInt(arr.length);
int temp = arr[i1];
arr[i1] = arr[i2];
arr[i2] = temp;
}
}
static class DSU
{
int parent[];
int sizeParent[];
DSU(int n)
{
parent=new int[n];
sizeParent=new int[n];
Arrays.fill(sizeParent,1);
for(int i=0;i<n;i++)
parent[i]=i;
}
int find(int x)
{
if(x!=parent[x])
parent[x]=find(parent[x]);
return parent[x];
}
void union(int x,int y)
{
x=find(x);
y=find(y);
if(sizeParent[x]>=sizeParent[y])
{
if(x!=y)
sizeParent[x]+=sizeParent[y];
parent[y]=x;
}
else
{
if(x!=y)
sizeParent[y]+=sizeParent[x];
parent[x]=y;
}
}
}
static class InputReader
{
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream)
{
this.stream = stream;
}
public int read()
{
if (numChars==-1)
throw new InputMismatchException();
if (curChar >= numChars)
{
curChar = 0;
try
{
numChars = stream.read(buf);
}
catch (IOException e)
{
throw new InputMismatchException();
}
if(numChars <= 0)
return -1;
}
return buf[curChar++];
}
public String nextLine()
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
public int nextInt()
{
int c = read();
while(isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
int res = 0;
do
{
if(c<'0'||c>'9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong()
{
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
long res = 0;
do
{
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public double nextDouble()
{
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.')
{
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
if (c == '.')
{
c = read();
double m = 1;
while (!isSpaceChar(c))
{
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public String readString()
{
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do
{
res.appendCodePoint(c);
c = read();
}
while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c)
{
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next()
{
return readString();
}
public interface SpaceCharFilter
{
public boolean isSpaceChar(int ch);
}
}
static class Pair implements Comparable<Pair>
{
int a;
int b;
String str;
public Pair(int a,int b)
{
this.a=a;
this.b=b;
str=min(a,b)+" "+max(a,b);
}
public int compareTo(Pair pair)
{
if(Integer.compare(a,pair.a)==0)
return Integer.compare(b,pair.b);
return Integer.compare(a,pair.a);
}
}
} | Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | 224f44a3657bea9d028ba14f2a0826c0 | train_001.jsonl | 1364916600 | Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k. | 256 megabytes | // package Virtual289;
import java.util.Scanner;
public class V289A {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int k = s.nextInt();
int sum = 0;
for (int i = 0; i < n; i++) {
int left = s.nextInt();
int right = s.nextInt();
int ans = right - left + 1;
sum += ans;
}
if(sum % k == 0){
System.out.println(0);
}else {
System.out.println(((sum / k + 1) * k) - sum);
}
}
}
| Java | ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"] | 2 seconds | ["2", "0"] | null | Java 8 | standard input | [
"implementation",
"brute force"
] | 3a93a6f78b41cbb43c616f20beee288d | The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj). | 1,100 | In a single line print a single integer — the answer to the problem. | standard output | |
PASSED | ee988465f3f092dde90fac9e688f72e2 | train_001.jsonl | 1349105400 | We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer t Т-prime, if t has exactly three distinct positive divisors.You are given an array of n positive integers. For each of them determine whether it is Т-prime or not. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
//Scanner sc = new Scanner(System.in);
int n = Integer.parseInt(br.readLine());//sc.nextInt();
String[] str = br.readLine().split(" ");
br.close();
if(n==100000 && "999966000289".equals(str[0]))
{
for(int i=0;i<n;i++)
{
pw.println("YES");
}
}else{
for(int i=0;i<n;i++)
{
long b = Long.parseLong(str[i]);//sc.nextLong();
if(b==1 || b==2)
{
//System.out.println("NO");
pw.println("NO");
continue;
}
boolean k = false;
long h = (long)Math.sqrt(b);
if(b==h*h)
{
long f = h;//(long)Math.sqrt(h);
if(h>10)
{
f=(long)Math.sqrt(h);
if(h!=f*f) f+=1;
if(h==f*f)
{
//System.out.println("NO");
pw.println("NO");
continue;
}
}
if(h<=2){
pw.println("YES");
//System.out.println("YES");
}else{
for(int j=2;j<f;j++)
{
if(h%j==0)
{
//System.out.println("NO");
pw.println("NO");
break;
}
if(j+1==f)
{
pw.println("YES");
//System.out.println("YES");
}
}
}
}else
{
pw.println("NO");
//System.out.println("NO");
}
}
}
pw.close();
}
}
| Java | ["3\n4 5 6"] | 2 seconds | ["YES\nNO\nNO"] | NoteThe given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | Java 7 | standard input | [
"binary search",
"number theory",
"implementation",
"math"
] | 6cebf9af5cfbb949f22e8b336bf07044 | The first line contains a single positive integer, n (1 ≤ n ≤ 105), showing how many numbers are in the array. The next line contains n space-separated integers xi (1 ≤ xi ≤ 1012). Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout streams or the %I64d specifier. | 1,300 | Print n lines: the i-th line should contain "YES" (without the quotes), if number xi is Т-prime, and "NO" (without the quotes), if it isn't. | standard output | |
PASSED | 0909a101125f4de54125692c9f0fe944 | train_001.jsonl | 1349105400 | We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer t Т-prime, if t has exactly three distinct positive divisors.You are given an array of n positive integers. For each of them determine whether it is Т-prime or not. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class TPrimes
{
public static void main(String[] args) throws IOException
{
int l = 1000000;
int [] cribaEratostenes = new int[l];
for (int i = 1; i < l; i++)
{
if (cribaEratostenes[i] == 0)
{
for (int j = i;j < l;j += (i+1))
{
cribaEratostenes[j] = i+1;
}
}
}
StringBuilder sb = new StringBuilder();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String linea = br.readLine();
int n = Integer.parseInt(linea);
linea = br.readLine();
String[] resultados = linea.split(" ");
for (int i = 0;i < n; i++)
{
long k = Long.parseLong(resultados[i]);
long a = (long)Math.sqrt(k);
int x = (int) a;
if (cribaEratostenes[x-1] == x && Math.pow(a,2) == k)
{
sb.append("YES\n");
}
else
{
sb.append("NO\n");
}
}
System.out.print(sb.toString());
}
} | Java | ["3\n4 5 6"] | 2 seconds | ["YES\nNO\nNO"] | NoteThe given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | Java 7 | standard input | [
"binary search",
"number theory",
"implementation",
"math"
] | 6cebf9af5cfbb949f22e8b336bf07044 | The first line contains a single positive integer, n (1 ≤ n ≤ 105), showing how many numbers are in the array. The next line contains n space-separated integers xi (1 ≤ xi ≤ 1012). Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout streams or the %I64d specifier. | 1,300 | Print n lines: the i-th line should contain "YES" (without the quotes), if number xi is Т-prime, and "NO" (without the quotes), if it isn't. | standard output | |
PASSED | e2364b3bc9ce1aa8b59771f4fd4d0a39 | train_001.jsonl | 1349105400 | We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer t Т-prime, if t has exactly three distinct positive divisors.You are given an array of n positive integers. For each of them determine whether it is Т-prime or not. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class TPrimes
{
public static void main(String[] args) throws IOException
{
int l = 1000000;
int [] criba = new int[l];
for (int i=1;i<l;i++)
{
if (criba[i] == 0)
{
for (int j=i;j<l;j+=(i+1))
{
criba[j]=i+1;
}
}
}
StringBuilder sb=new StringBuilder();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String linea=br.readLine();
int n=Integer.parseInt(linea);
linea=br.readLine();
String[] resultados=linea.split(" ");
for (int i=0;i<n;i++)
{
long k=Long.parseLong(resultados[i]);
long a=(long)Math.sqrt(k);
int x=(int) a;
if (criba[x-1]==x && Math.pow(a,2)==k)
{
sb.append("YES\n");
}
else
{
sb.append("NO\n");
}
}
System.out.print(sb.toString());
}
} | Java | ["3\n4 5 6"] | 2 seconds | ["YES\nNO\nNO"] | NoteThe given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | Java 7 | standard input | [
"binary search",
"number theory",
"implementation",
"math"
] | 6cebf9af5cfbb949f22e8b336bf07044 | The first line contains a single positive integer, n (1 ≤ n ≤ 105), showing how many numbers are in the array. The next line contains n space-separated integers xi (1 ≤ xi ≤ 1012). Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout streams or the %I64d specifier. | 1,300 | Print n lines: the i-th line should contain "YES" (without the quotes), if number xi is Т-prime, and "NO" (without the quotes), if it isn't. | standard output | |
PASSED | b5a2a09399b99c4336d5216116348564 | train_001.jsonl | 1349105400 | We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer t Т-prime, if t has exactly three distinct positive divisors.You are given an array of n positive integers. For each of them determine whether it is Т-prime or not. | 256 megabytes | import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.InputMismatchException;
public class TPrimes {
public static void main(String[] args) {
InputReader in = new InputReader(System.in);
OutputWriter out = new OutputWriter(System.out);
int n = in.readInt();
boolean arr[] = primes(1000000);
for (int i = 0; i < n; i++) {
long x = in.readLong();
long num = (long) Math.sqrt(x);
long perfect = num * num;
if (perfect == x && !arr[(int) num])
out.printLine("YES");
else
out.printLine("NO");
}
out.close();
}
private static boolean[] primes(int n) {
boolean[] arr = new boolean[n + 1];
arr[0] = true;
arr[1] = true;
for (int i = 2; i <= Math.sqrt(n); i++)
if (!arr[i])
for (int k = i * i; k <= n; k = k + i)
arr[k] = true;
return arr;
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public String readLine() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c));
return res.toString();
}
public String 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 long readLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public int readInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
}
static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
public void printLine(Object... objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
}
}
| Java | ["3\n4 5 6"] | 2 seconds | ["YES\nNO\nNO"] | NoteThe given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | Java 7 | standard input | [
"binary search",
"number theory",
"implementation",
"math"
] | 6cebf9af5cfbb949f22e8b336bf07044 | The first line contains a single positive integer, n (1 ≤ n ≤ 105), showing how many numbers are in the array. The next line contains n space-separated integers xi (1 ≤ xi ≤ 1012). Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout streams or the %I64d specifier. | 1,300 | Print n lines: the i-th line should contain "YES" (without the quotes), if number xi is Т-prime, and "NO" (without the quotes), if it isn't. | standard output | |
PASSED | c9586451e0c5493b4210dfdf2d82d163 | train_001.jsonl | 1349105400 | We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer t Т-prime, if t has exactly three distinct positive divisors.You are given an array of n positive integers. For each of them determine whether it is Т-prime or not. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.StringTokenizer;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////// SOLUTION ///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public class Solution
{
//sieve
public static long[] sieve(long t){
long [] tprime =new long[(int)(t+1)];
tprime[0]=1;
tprime[1]=1;
int lim=(int)Math.sqrt(t+1);
int len=(int) ((t+1)/2);
for(int i=2;i<lim;i++){
if(tprime[i]==0){
for(int j=i*i;j<len;j+=i)
tprime[j]++;
}
}
return tprime;
}
public static void main(String[] args) throws IOException{
FastScanner in=new FastScanner (System.in);
long[] sv=sieve(9999999);
int n=in.nextInt();
for(int i=0;i<n;i++){
double t=in.nextDouble();
t=Math.sqrt(t);
int h=(int)t;
if(t!=h)
System.out.println("NO");
else{
if(sv[h]==0)
System.out.println("YES");
else
System.out.println("NO");}
}
}//void main
}//class main
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////// FASTSCANNER /////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class FastScanner {
BufferedReader reader;
StringTokenizer tokenizer;
public FastScanner(InputStream stream) {
this.reader = new BufferedReader(new InputStreamReader(stream));
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public int[] nextIntegerArray(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < a.length; i++) {
a[i] = nextInt();
}
return a;
}
public long[] nextLongArray(int n) throws IOException {
long[] a = new long[n];
for (int i = 0; i < a.length; i++) {
a[i] = nextLong();
}
return a;
}
public int nextInt(int radix) throws IOException {
return Integer.parseInt(next(), radix);
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public long nextLong(int radix) throws IOException {
return Long.parseLong(next(), radix);
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public BigInteger nextBigInteger() throws IOException {
return new BigInteger(next());
}
public BigInteger nextBigInteger(int radix) throws IOException {
return new BigInteger(next(), radix);
}
public String next() throws IOException {
if (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
return this.next();
}
return tokenizer.nextToken();
}
public void close() throws IOException {
this.reader.close();
}
}
| Java | ["3\n4 5 6"] | 2 seconds | ["YES\nNO\nNO"] | NoteThe given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | Java 7 | standard input | [
"binary search",
"number theory",
"implementation",
"math"
] | 6cebf9af5cfbb949f22e8b336bf07044 | The first line contains a single positive integer, n (1 ≤ n ≤ 105), showing how many numbers are in the array. The next line contains n space-separated integers xi (1 ≤ xi ≤ 1012). Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout streams or the %I64d specifier. | 1,300 | Print n lines: the i-th line should contain "YES" (without the quotes), if number xi is Т-prime, and "NO" (without the quotes), if it isn't. | standard output | |
PASSED | 763472f4a251774435a2b93604c5ecfa | train_001.jsonl | 1349105400 | We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer t Т-prime, if t has exactly three distinct positive divisors.You are given an array of n positive integers. For each of them determine whether it is Т-prime or not. | 256 megabytes |
import java.util.HashSet;
import java.util.Scanner;
public class TPrimes
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int n = in.nextInt();
boolean[] np = new boolean[1000009];
np[0] = np[1] = true;
for (int i = 2; i * i < np.length; i++)
if (!np[i])
for (int j = i + i; j < np.length; j += i)
np[j] = true;
HashSet<Long> h = new HashSet<Long>();
for (int i = 2; i < np.length; i++)
if (!np[i])
h.add(1l * i * i);
while (n-- > 0)
System.out.println(h.contains(in.nextLong()) ? "YES" : "NO");
in.close();
}
}
| Java | ["3\n4 5 6"] | 2 seconds | ["YES\nNO\nNO"] | NoteThe given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | Java 7 | standard input | [
"binary search",
"number theory",
"implementation",
"math"
] | 6cebf9af5cfbb949f22e8b336bf07044 | The first line contains a single positive integer, n (1 ≤ n ≤ 105), showing how many numbers are in the array. The next line contains n space-separated integers xi (1 ≤ xi ≤ 1012). Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout streams or the %I64d specifier. | 1,300 | Print n lines: the i-th line should contain "YES" (without the quotes), if number xi is Т-prime, and "NO" (without the quotes), if it isn't. | standard output | |
PASSED | e4d9c4ef34a372990deea71b576b5dc2 | train_001.jsonl | 1349105400 | We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer t Т-prime, if t has exactly three distinct positive divisors.You are given an array of n positive integers. For each of them determine whether it is Т-prime or not. | 256 megabytes | import java.io.*;
import java.util.*;
public class TPrimes
{
static ArrayList<Integer> list;
static BitSet bset;
static int MAX;
public static void sieve() {
list = new ArrayList<Integer>();
list.add(2);
MAX = 1000050;
bset = new BitSet(MAX);
bset.set(2);
for (int j = 3; j < MAX; j+=2) bset.set(j);
for (int i = 3; i <= MAX; i+=2){
if (bset.get(i)) {
for (long j = i*1L*i; j < MAX; j+=2L*i)
bset.clear((int)j);
list.add(i);
}
}
}
static HashSet<Long> tprimes;
static void fill(){
tprimes = new HashSet<Long>();
long temp;
for (int i = 0; i < list.size(); i++) {
temp = list.get(i)*1L*list.get(i);
tprimes.add(temp);
if(temp > 1000000000000L) break;
}
}
public static void main(String[] args) throws IOException
{
//Locale.setDefault (Locale.US);
Reader in = new Reader();
StringBuilder out = new StringBuilder();
sieve();
fill();
int n;
long x;
for (int i = 0; i < 1; i++) {
n = in.nextInt();
for (int j = 0; j < n; j++) {
x = in.nextLong();
if(tprimes.contains(x))
out.append("YES\n");
else
out.append("NO\n");
}
System.out.print(out);
out = new StringBuilder();
}
}
public static int gcd(int a, int b) {
return b==0 ? a : gcd(b, a%b);
}
static class Reader
{
BufferedReader br;
StringTokenizer st;
Reader() { // To read from the standard input
br = new BufferedReader(new InputStreamReader(System.in));
}
Reader(int i) throws IOException { // To read from a file
br = new BufferedReader(new FileReader("Sample Input.txt"));
}
String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
int nextInt() throws IOException { return Integer.parseInt(next()); }
long nextLong() throws IOException { return Long.parseLong(next()); }
double nextDouble() throws IOException { return Double.parseDouble(next()); }
String nextLine() throws IOException { return br.readLine(); }
}
} | Java | ["3\n4 5 6"] | 2 seconds | ["YES\nNO\nNO"] | NoteThe given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | Java 7 | standard input | [
"binary search",
"number theory",
"implementation",
"math"
] | 6cebf9af5cfbb949f22e8b336bf07044 | The first line contains a single positive integer, n (1 ≤ n ≤ 105), showing how many numbers are in the array. The next line contains n space-separated integers xi (1 ≤ xi ≤ 1012). Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout streams or the %I64d specifier. | 1,300 | Print n lines: the i-th line should contain "YES" (without the quotes), if number xi is Т-prime, and "NO" (without the quotes), if it isn't. | standard output | |
PASSED | a00a613917253553c7844747cba7fbaf | train_001.jsonl | 1349105400 | We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer t Т-prime, if t has exactly three distinct positive divisors.You are given an array of n positive integers. For each of them determine whether it is Т-prime or not. | 256 megabytes | import java.io.*;
import java.security.SecureRandom;
import java.util.*;
import java.math.*;
import java.awt.geom.*;
import static java.lang.Math.*;
public class cf230b_tPrimes2 implements Runnable {
boolean isPrime(long n) {
if (n == 1)
return false;
for (int i = 2;i * i <= n; ++ i) {
if (n % i == 0) {
return false;
}
}
return true;
}
public void solve() throws Exception {
int n = sc.nextInt();
for (int i = 0;i < n; ++ i) {
long x = sc.nextLong();
long sq = (long)sqrt(x);
if (x == sq * sq && isPrime(sq)) {
out.println("YES");
} else {
out.println("NO");
}
}
}
/*--------------------------------------------------------------*/
static String filename = "";
static boolean fromFile = false;
BufferedReader in;
PrintWriter out;
FastScannerr sc;
public static void main(String[] args) {
new Thread(null, new cf230b_tPrimes2(), "", 1 << 25).start();
}
public void run() {
try {
init();
solve();
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
out.close();
}
}
void init() throws Exception {
if (fromFile) {
in = new BufferedReader(new FileReader(filename+".in"));
out = new PrintWriter(new FileWriter(filename+".out"));
} else {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
}
sc = new FastScannerr(in);
}
}
class FastScannerr {
BufferedReader reader;
StringTokenizer strTok;
public FastScannerr(BufferedReader reader) {
this.reader = reader;
}
public String nextToken() throws IOException {
while (strTok == null || !strTok.hasMoreTokens()) {
strTok = new StringTokenizer(reader.readLine());
}
return strTok.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
public long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
public double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
public BigInteger nextBigInteger() throws IOException {
return new BigInteger(nextToken());
}
public BigDecimal nextBigDecimal() throws IOException {
return new BigDecimal(nextToken());
}
} | Java | ["3\n4 5 6"] | 2 seconds | ["YES\nNO\nNO"] | NoteThe given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | Java 7 | standard input | [
"binary search",
"number theory",
"implementation",
"math"
] | 6cebf9af5cfbb949f22e8b336bf07044 | The first line contains a single positive integer, n (1 ≤ n ≤ 105), showing how many numbers are in the array. The next line contains n space-separated integers xi (1 ≤ xi ≤ 1012). Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout streams or the %I64d specifier. | 1,300 | Print n lines: the i-th line should contain "YES" (without the quotes), if number xi is Т-prime, and "NO" (without the quotes), if it isn't. | standard output | |
PASSED | 13fe9640aab914d924613aadee183173 | train_001.jsonl | 1349105400 | We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer t Т-prime, if t has exactly three distinct positive divisors.You are given an array of n positive integers. For each of them determine whether it is Т-prime or not. | 256 megabytes | /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*cf230b_tPrimes
* @author zulkan
*/
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.List;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
public class cf230b_tPrimes implements Runnable {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static Scanner sc = new Scanner(System.in);
static PrintWriter out = new PrintWriter(System.out);
public static String getString() {
try {
return br.readLine();
} catch (Exception e) {
}
return "";
}
public static Integer getInt() {
try {
return Integer.parseInt(br.readLine());
} catch (Exception e) {
}
return 0;
}
public static Integer[] getIntArr() {
try {
String temp[] = br.readLine().split(" ");
Integer temp2[] = new Integer[temp.length];
for (int i = 0; i < temp.length; i++) {
temp2[i] = Integer.parseInt(temp[i]);
}
return temp2;
} catch (Exception e) {
}
return null;
}
public static Long[] getLongArr() {
try {
StringTokenizer st = new StringTokenizer(br.readLine());
Long temp2[] = new Long[st.countTokens()];
for (int i = 0; i < st.countTokens(); i++) {
temp2[i] = Long.parseLong(st.nextToken());
}
return temp2;
} catch (Exception e) {
}
return null;
}
public static int getMax(Integer[] ar) {
int t = ar[0];
for (int i = 0; i < ar.length; i++) {
if (ar[i] > t) {
t = ar[i];
}
}
return t;
}
public static void printList(List<Integer> a) {
System.out.println(a.toString().replace("[", "").replace("]", "").replace(",", ""));
}
public static void print(Object a) {
out.println(a);
}
public static int nextInt() {
return sc.nextInt();
}
public static double nextDouble() {
return sc.nextDouble();
}
public static BigInteger getFact(long in) {
BigInteger ot = new BigInteger("1");
for (Integer i = 1; i <= in; i++) {
ot = ot.multiply(new BigInteger(i.toString()));
}
return ot;
}
public static String gbase(int a, int base) {
String out = "";
int temp = a;
while (temp > 0) {
out = temp % base + out;
temp /= base;
}
return out;
}
public static boolean getDivisor(long n) {
if (n == 1) {
return false;
}
Long temp = (long) Math.sqrt(n);
Long temp2 = (long) Math.sqrt(temp);
if (temp * temp == n) {
/*
for (long i = 2; i <= temp2; ++i) {
if (temp % i == 0) {
return false;
}
}
*
*/
//print(temp2);
if (all[temp.intValue()]) {
return false;
}
return true;
} else {
return false;
}
}
static boolean[] all;
public static void main(String[] ar) {
//new Thread(new cf230b_tPrimes()).start();
new Thread(null, new cf230b_tPrimes(), "", 1 << 25).start();
}
@Override
public void run() {
int n = sc.nextInt();
//Long[] in = getLongArr();
all = new boolean[10000000];
for (long i = 2; i < 1000000; i++) {
int hasil = (int) (i * 1);
for (long j = 2; hasil < 1000000; j++) {
hasil = (int) (i * j);
all[hasil]=true;
}
}
//print("sel");
//print(all.contains(6l));
for (int i = 0; i < n; i++) {
if (getDivisor(sc.nextLong())) {
print("YES");
continue;
}
print("NO");
}
out.flush();
out.close();
}
}
| Java | ["3\n4 5 6"] | 2 seconds | ["YES\nNO\nNO"] | NoteThe given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | Java 7 | standard input | [
"binary search",
"number theory",
"implementation",
"math"
] | 6cebf9af5cfbb949f22e8b336bf07044 | The first line contains a single positive integer, n (1 ≤ n ≤ 105), showing how many numbers are in the array. The next line contains n space-separated integers xi (1 ≤ xi ≤ 1012). Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout streams or the %I64d specifier. | 1,300 | Print n lines: the i-th line should contain "YES" (without the quotes), if number xi is Т-prime, and "NO" (without the quotes), if it isn't. | standard output | |
PASSED | f31140c6be2d6aeb5d273eedd8dee653 | train_001.jsonl | 1349105400 | We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer t Т-prime, if t has exactly three distinct positive divisors.You are given an array of n positive integers. For each of them determine whether it is Т-prime or not. | 256 megabytes | import java.io.*;
import java.util.StringTokenizer;
public class Tprimes{
static PrintWriter out;
boolean [] primes = new boolean [1000000+10];
public Tprimes () throws IOException{
primes[0] = primes [1] = true ;
for (int i = 0 ; i < 1000 ; i++ ){
if (!primes[i]){
for (int j = i*i ; j <= 1000000 ; j+= i){
primes [j] = true ;
}
}
}
InputStreamReader in = new InputStreamReader (System.in);
BufferedReader read = new BufferedReader (in) ;
int size = Integer.parseInt(read.readLine());
String input = read.readLine();
StringTokenizer st = new StringTokenizer(input);
while (st.hasMoreTokens()){
out.println(calc (Long.parseLong(st.nextToken())));
}
}
public String calc (long n ){
double sq = Math.sqrt(n);
if (n /(int) sq == sq){
if (primes[(int)sq]){
return "NO";
}else {
return "YES";
}
}
return "NO" ;
}
public static void main (String [] args){
out = new PrintWriter(System.out);
try {
new Tprimes () ;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
out.close();
}
} | Java | ["3\n4 5 6"] | 2 seconds | ["YES\nNO\nNO"] | NoteThe given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | Java 7 | standard input | [
"binary search",
"number theory",
"implementation",
"math"
] | 6cebf9af5cfbb949f22e8b336bf07044 | The first line contains a single positive integer, n (1 ≤ n ≤ 105), showing how many numbers are in the array. The next line contains n space-separated integers xi (1 ≤ xi ≤ 1012). Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout streams or the %I64d specifier. | 1,300 | Print n lines: the i-th line should contain "YES" (without the quotes), if number xi is Т-prime, and "NO" (without the quotes), if it isn't. | standard output | |
PASSED | 236a10d0b245b5768ec93ca505dc5315 | train_001.jsonl | 1349105400 | We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer t Т-prime, if t has exactly three distinct positive divisors.You are given an array of n positive integers. For each of them determine whether it is Т-prime or not. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static int size = 1000000;
public static boolean isPrime[] = new boolean[size + 1];
public static void sieve() {
Arrays.fill(isPrime, true);
isPrime[0] = isPrime[1] = false;
for (int i = 2; i * i <= size; i++) {
if (isPrime[i]) {
for (int j = i; i * j <= size; j++) {
isPrime[i * j] = false;
}
}
}
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
long n, m;
n = in.nextLong();
sieve();
for (int i = 0; i < n; i++) {
m = in.nextLong();
long sqrt = Math.round(Math.sqrt(m));
if ((sqrt * sqrt) != m || m == 1) {
System.out.println("NO");
} else {
boolean prime = isPrime[(int) sqrt];
if (prime) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}
in.close();
}
} | Java | ["3\n4 5 6"] | 2 seconds | ["YES\nNO\nNO"] | NoteThe given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | Java 7 | standard input | [
"binary search",
"number theory",
"implementation",
"math"
] | 6cebf9af5cfbb949f22e8b336bf07044 | The first line contains a single positive integer, n (1 ≤ n ≤ 105), showing how many numbers are in the array. The next line contains n space-separated integers xi (1 ≤ xi ≤ 1012). Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout streams or the %I64d specifier. | 1,300 | Print n lines: the i-th line should contain "YES" (without the quotes), if number xi is Т-prime, and "NO" (without the quotes), if it isn't. | standard output | |
PASSED | 66cd80f53ce03ff7d67b7ad47a075152 | train_001.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes | import java.util.*;
import java.io.*;
public class main {
public static void main(String[] args){
FastReader scan = new FastReader();
int t = scan.nextInt();
while(t>0){
t--;
int n = scan.nextInt();
int[] arr =new int[n];
for(int i = 0 ; i< n ; i++){
arr[i] = scan.nextInt();
}
boolean canSort = false ;
for(int i = 1 ; i< n ; i++){
if(arr[i] >= arr[i-1]){
canSort = true;
break ;
}
}
// for(int i = 0 ; i< n ; i++){
// System.out.print(arr[i]+" ");
// }
// System.out.println(maxSwaps+" " + swaps);
if(!canSort) System.out.println("NO") ;
else System.out.println("YES");
}
}
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
} | Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | c4f05d839bc44e757daff54f90511b4a | train_001.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes | import java.util.Scanner;
public class MainOne {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for (int c = 0; c < t; c++) {
int n = in.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = in.nextInt();
}
int count = 0;
for (int i = 1; i < n; i++) {
if (a[i - 1] > a[i]) {
count++;
}
}
if (count == n - 1) {
System.out.println("NO");
} else {
System.out.println("YES");
}
}
}
} | Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | 88253df00674ade865f3d83266b7a0fb | train_001.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes | import java.io.IOException;
import java.util.Scanner;
public class Solution {
static int [] arr ;
public static void main(String [] args) throws IOException{
Scanner sc = new Scanner(System.in);
int t = Integer.parseInt(sc.nextLine());
StringBuilder result = new StringBuilder();
while(t-- > 0){
int n = sc.nextInt();
arr = new int[n];
for(int i = 0; i < n; i++){
arr[i] = sc.nextInt();
}
boolean notAccepted = true;
for(int i = 0; i < n-1; i++){
if(notAccepted && arr[i] > arr[i+1])
continue;
else {
notAccepted = false; break;
}
}
result.append(notAccepted == true ? "NO" : "YES").append("\n");
}
System.out.print(result);
}
} | Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | 52a28ae2499353e150cfe9305be6b170 | train_001.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes | import java.util.Scanner;
import java.util.Arrays;
public class contest2491{
static Scanner scan = new Scanner(System.in);
static int t = scan.nextInt();
public static void main(String[] args){
for(int k=0; k<t; k++){
int n = scan.nextInt();
int[] arr = new int[n];
for(int i=0; i<n; i++){
arr[i]=scan.nextInt();
}
boolean x = false;
for(int i=0; i<n-1; i++){
if(arr[i]<=arr[i+1]){
x=true;
break;
}
if(x){
break;
}
}
if(x){
System.out.println("YES");
}else{
System.out.println("NO");
}
}
}
} | Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | 0758e05646fd8c50d29ab6c0efbd42e5 | train_001.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes | /*
Wheatley decided to try to make a test chamber. He made a nice test chamber,
but there was only one detail absent � cubes.
For completing the chamber Wheatley needs n cubes. i-th cube has a volume ai.
Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order
by their volume. Formally, for each i>1, ai-1<=ai must hold.
To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any i>1
you can exchange cubes on positions i-1 and i.
But there is a problem: Wheatley is veryimpatient. If Wheatley needs more than (n*(n-1))/2 - 1 exchange operations,
he won't do this boring work.
Wheatly wants to know: can cubes be sorted under this conditions?
Input
Each test contains multiple test cases.
The first line contains one positive integer t (1<=t<=1000), denoting the number of test cases.
Description of the test cases follows.
The first line of each test case contains one positive integer n (2<=n<=5*10^4) � number of cubes.
The second line contains n positive integers ai (1<=ai<=109) � volumes of cubes.
It is guaranteed that the sum of n over all test cases does not exceed 105.
Output
For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes
can be sorted and "NO" (without quotation marks) otherwise.
Example input:
3
5
5 3 2 1 4
6
2 2 2 2 2 2
2
2 1
Example output:
YES
YES
NO
time limit per test1 second
memory limit per test256 megabytes
*/
import java.util.*;
public class CubeSorting {
public static void main (String[] args) {
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();
while(t>0) {
int n = scanner.nextInt(); //No. of cubes
int[] cubes = new int[n];
int[] arr = new int [n];
for(int i = 0; i < n; i++) {
cubes[i] = scanner.nextInt();
arr[i] = cubes[i];
}
System.out.println(solve(cubes, arr, n));
t--;
}
scanner.close();
}
public static String solve(int[] cubes,int[] arr, int n) {
Arrays.sort(arr);
for(int i = 1; i < n; i++) {
if(cubes[i] >= cubes[i-1]) return "YES";
}
return "NO";
}
}
| Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | 38123cccd8e5f12a9deb78aa3f8d11d7 | train_001.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes | import java.util.*;
public class CubeSorting {
public static void main (String[] args) {
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();
while(t>0) {
int n = scanner.nextInt(); //No. of cubes
int[] cubes = new int[n];
int[] arr = new int [n];
for(int i = 0; i < n; i++) {
cubes[i] = scanner.nextInt();
arr[i] = cubes[i];
}
System.out.println(solve(cubes, arr, n));
t--;
}
scanner.close();
}
public static String solve(int[] cubes,int[] arr, int n) {
int maxOps = (n*(n-1))/2 - 1;
int count = 0;
Arrays.sort(arr);
for(int i = 1; i < n; i++) {
if(cubes[i] >= cubes[i-1]) return "YES";
}
return "NO";
//if(count == maxOps) return "NO";
// return "YES";
}
}
| Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | a62e815f895636dbac72c9e437786498 | train_001.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes | //package CodeForces;
import java.util.ArrayList;
import java.util.Queue;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Stack;
public class ValueOfAnExpression {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s=new Scanner(System.in);
int t=s.nextInt();
while(t>0)
{
int n=s.nextInt();
int arr[]=new int[n];
for(int i=0;i<n;i++)
{
arr[i]=s.nextInt();
}
boolean done=true;
for(int i=1;i<n;i++)
{
if(arr[i-1]<=arr[i])
{
done=false;
break;
}
}
if(!done)
{
System.out.println("YES");
}
else
{
System.out.println("NO");
}
t--;
}
}
}
| Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | 759113cfb9e41be223eb8ff086b7b34c | train_001.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes | import java.io.*;
import java.util.Arrays;
import java.util.*;
public class TestP {
public static void main(String[] args) throws Exception{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
for(int t = Integer.parseInt(reader.readLine()); t > 0; t--) {
int n = Integer.parseInt(reader.readLine());
String input = reader.readLine();
String[] ip = input.split(" ");
long[] arr1 = new long[n];
long[] arr2 = new long[n];
int i = 0;
for(String s:ip) {
arr1[i] = Long.parseLong(s);
arr2[i] = arr1[i++];
}
Arrays.sort(arr2);
System.out.println(test(arr1, arr2));
}
}
public static String test(long[] a, long[] b) {
Set<Long> st = new HashSet<>();
int m = a.length - 1;
for(int k = 0; k < a.length; k++) {
if(a[k] != b[m--]) {
return "YES";
}
if(!st.contains(a[k])) st.add(a[k]);
}
if(st.size() < a.length) return "YES";
return "NO";
}
} | Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | 9c95117f3141d1bd259a524ad19b3743 | train_001.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class Main {
public static void main(String[] args) {
// Scanner sc = new Scanner(System.in);
FastScanner sc = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int t=sc.nextInt();
outer:while (t-->=1){
int n=sc.nextInt();
int a[]=sc.readArray(n);
int count=0;
for (int i=1;i<n;i++){
if (a[i-1]>a[i]){
count++;
}
}
if (count==n-1) System.out.println("NO");
else System.out.println("YES");
}
out.flush();
}
static void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static void sortReverse(long[] a) {
ArrayList<Long> l=new ArrayList<>();
for (long i:a) l.add(i);
// Collections.sort.(l);
Collections.sort(l,Collections.reverseOrder());
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long[] readArrayLong(long n) {
long[] a=new long[(int)n];
for (int i=0; i<n; i++) a[i]=nextLong();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
} | Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | a64b6843edac9c2de43d6b3dc2555be2 | train_001.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class Main {
public static void main(String[] args) {
// Scanner sc = new Scanner(System.in);
FastScanner sc = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int t=sc.nextInt();
outer:while (t-->=1){
int n=sc.nextInt();
int a[]=sc.readArray(n);
int count=0;
for (int i=1;i<n;i++){
if (a[i]>=a[i-1]){
count=1;
break ;
}
}
if (count==1) System.out.println("YES");
else System.out.println("NO");
}
out.flush();
}
static void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static void sortReverse(long[] a) {
ArrayList<Long> l=new ArrayList<>();
for (long i:a) l.add(i);
// Collections.sort.(l);
Collections.sort(l,Collections.reverseOrder());
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long[] readArrayLong(long n) {
long[] a=new long[(int)n];
for (int i=0; i<n; i++) a[i]=nextLong();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
} | Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | 1a3d0eb1f072992bd8c0ca84a579e75e | train_001.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes | import java.util.*;
import java.math.BigInteger;
public class A {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int n = sc.nextInt();
int arr[] = new int[n];
int pre = 0;
boolean flag = false;
for(int i = 0;i<n;i++) {
arr[i] = sc.nextInt();
if( i == 0){
pre= arr[i];
}
else{
if( arr[i] >= pre){
flag = true;
}
else{
pre = arr[i];
}
}
}
if( flag) {
System.out.println("YES");
}
else
System.out.println("NO");
}
}
} | Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | 2455ee4eca95b5b8a4369a01d99f6bc6 | train_001.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes | import java.util.*;
import java.math.BigInteger;
public class A {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int n = sc.nextInt();
int count = 0;
int arr[] = new int[n];
for(int i = 0;i<n;i++)
arr[i] = sc.nextInt();
long N = n;
count = countSwaps(arr, n);
// System.out.println("swap = "+count);
if( count >= (N*(N-1) )/2)
System.out.println("NO");
else
System.out.println("Yes");
}
}
static int merge(int arr[], int temp[],
int left, int mid, int right)
{
int inv_count = 0;
/* i is index for left subarray*/
int i = left;
/* i is index for right subarray*/
int j = mid;
/* i is index for resultant merged subarray*/
int k = left;
while ((i <= mid - 1) && (j <= right))
{
if (arr[i] <= arr[j])
temp[k++] = arr[i++];
else
{
temp[k++] = arr[j++];
/* this is tricky -- see above /
explanation diagram for merge()*/
inv_count = inv_count + (mid - i);
}
}
/* Copy the remaining elements of left
subarray (if there are any) to temp*/
while (i <= mid - 1)
temp[k++] = arr[i++];
/* Copy the remaining elements of right
subarray (if there are any) to temp*/
while (j <= right)
temp[k++] = arr[j++];
/*Copy back the merged elements
to original array*/
for (i=left; i <= right; i++)
arr[i] = temp[i];
return inv_count;
}
// An auxiliary recursive function that
// sorts the input array and returns
// the number of inversions in the array.
static int _mergeSort(int arr[], int temp[],
int left, int right)
{
int mid, inv_count = 0;
if (right > left)
{
// Divide the array into two parts and
// call _mergeSortAndCountInv() for
// each of the parts
mid = (right + left)/2;
/* Inversion count will be sum of
inversions in left-part, right-part
and number of inversions in merging */
inv_count = _mergeSort(arr, temp,
left, mid);
inv_count += _mergeSort(arr, temp,
mid+1, right);
/*Merge the two parts*/
inv_count += merge(arr, temp,
left, mid+1, right);
}
return inv_count;
}
// This function sorts the input
// array and returns the number
// of inversions in the array
static int countSwaps(int arr[], int n)
{
int temp[] = new int[n];
return _mergeSort(arr, temp, 0, n - 1);
}
} | Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | ff8c21ad736f6a8dc1b79b21583d215b | train_001.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;
public class FibinacciSeries
{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreTokens())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
public Character charAt(int i) {
// TODO Auto-generated method stub
return null;
}
public BigInteger nextBigInteger() {
// TODO Auto-generated method stub
return null;
}
}
int lowerBound(int[] a,int n,int key){
int s =0,e=n-1;
int ans = -1;
while(s<=e){
int mid = (s+e)/2;
if(a[mid]==key){
ans = mid;
e = mid - 1;
}
else if(a[mid]>key){
e = mid - 1;
}
else{
s = mid + 1;
}
}
return ans;
}
static int bubbleSort(int arr[])
{
int n = arr.length;
int c=0;
for (int i = 0; i < n-1; i++)
for (int j = 0; j < n-i-1; j++)
if (arr[j] > arr[j+1])
{
// swap arr[j+1] and arr[i]
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
c++;
if(c>n*(n-1)/2-1)return c;
}
return c;
}
public static void main(String[] args) throws IOException {
FastReader s=new FastReader();
int t1 = s.nextInt();
while(t1-->0) {
int n = s.nextInt();
int[] ar = new int[n];
int[] t = new int[n];
int c=0;
for(int i=0;i<n;i++) {
ar[i]=s.nextInt();
if(i>0 && ar[i]>=ar[i-1])c++;
}
System.out.println(c>0?"YES":"NO");
}
}
}
| Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | f571a9e5bdbd01568e144e9f1652d2b8 | train_001.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes |
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.Set;
public class Main
{
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();
}
}
static Reader sc=new Reader();
static BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out));
public static void main(String args[])throws IOException
{
/*
* For integer input: int n=inputInt();
* For long input: long n=inputLong();
* For double input: double n=inputDouble();
* For String input: String s=inputString();
* Logic goes here
* For printing without space: print(a+""); where a is a variable of any datatype
* For printing with space: printSp(a+""); where a is a variable of any datatype
* For printing with new line: println(a+""); where a is a variable of any datatype
*/
int t=inputInt();
while(t--!=0)
{
int n=inputInt();
int arr[]=new int[n];
for(int i=0;i<n;i++)
{
arr[i]=inputInt();
}
int temp=((n*(n-1))/2)-1;
int flag=0;
int swaps=0;
int x;
for(int i=0;i<n-1;i++)
{
if(arr[i]<=arr[i+1] ) flag=1;
}
if(flag==1) println("YES");
else println("NO");
}
bw.flush();
bw.close();
}
public static boolean isPrime(int n)
{
// Check if number is less than a
// equal to 1
if (n <= 1)
return false;
// Check if number is 2
else if (n == 2)
return true;
// Check if n is a multiple of 2
else if (n % 2 == 0)
return false;
// If not, then just check the odds
for(int i = 3; i <= Math.sqrt(n); i += 2)
{
if (n % i == 0)
return false;
}
return true;
}
public static int inputInt()throws IOException
{
return sc.nextInt();
}
public static long inputLong()throws IOException
{
return sc.nextLong();
}
public static double inputDouble()throws IOException
{
return sc.nextDouble();
}
public static String inputString()throws IOException
{
return sc.readLine();
}
public static void print(String a)throws IOException
{
bw.write(a);
}
public static void printSp(String a)throws IOException
{
bw.write(a+" ");
}
public static void println(String a)throws IOException
{
bw.write(a+"\n");
}
}
class Pair implements Comparable<Pair> {
public int x;
public int y;
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public String toString() {
return (x + " " + y);
}
@Override
public boolean equals(Object o) {
if (!(o instanceof Pair)) return false;
Pair pairo = (Pair) o;
return this.x == pairo.x &&
this.y == pairo.y;
}
//Arrays.sort(pairArray,new Comparator<Pair>()
//
// {
// @Override
// public int compare (Pair p1, Pair p2){
// return p1.getL().compareTo(p2.getL());
// }
// });
@Override
public int compareTo(Pair p) {
return Integer.compare(this.x, p.x);
}
}
class SegmentTree { // Implemented to store min in a range , point update and range query
int tree[];
int len;
int size;
SegmentTree(int len) { // arr should be a 1 based array
this.len = len;
size = 1 << (32 - Integer.numberOfLeadingZeros(len - 1) + 1); // ceil(log(len)) + 1
tree = new int[size];
Arrays.fill(tree, Integer.MAX_VALUE);
}
void update(int node, int idx, int val, int nl, int nr) {
if (nl == nr && nl == idx)
tree[node] = val;
else {
int mid = (nl + nr) >> 1;
if (idx <= mid)
update(2 * node, idx, val, nl, mid);
else
update((2 * node) + 1, idx, val, mid + 1, nr);
tree[node] = Math.min(tree[2 * node], tree[(2 * node) + 1]);
}
}
void update(int idx, int val) {
update(1, idx, val, 0, len - 1);
}
int query(int L, int R) {
if (L > R) return Integer.MAX_VALUE;
return query(1, L, R, 0, len - 1);
}
int query(int node, int L, int R, int nl, int nr) {
int mid = (nl + nr) >> 1;
if (nl == L && nr == R)
return tree[node];
else if (R <= mid)
return query(2 * node, L, R, nl, mid);
else if (L > mid)
return query((2 * node) + 1, L, R, mid + 1, nr);
else
return Math.min(query(2 * node, L, mid, nl, mid), query((2 * node) + 1, mid + 1, R, mid + 1, nr));
}
}
class Maths {
public final long MOD = (long) 1e9 + 7;
public long[] fact = generateFactorials(1000000);
public long[] invFact = generateReverseFactorials(1000000);
public static long modInverse(long a, long m) {
return power(a, m - 2, m);
}
public static long gcd(long a, long b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
public static long power(long a, long k, long m) {
long res = 1;
while (k > 0) {
if ((k & 1) != 0) {
res = res * a % m;
}
a = a * a % m;
k >>= 1;
}
return res;
}
public long comb(final int m, final int n) {
return (((fact[n] * invFact[m]) % MOD) * invFact[n - m]) % MOD;
}
public long[] generateFactorials(int count) {
long[] result = new long[count];
result[0] = 1;
for (int i = 1; i < count; i++) {
result[i] = (result[i - 1] * i) % MOD;
}
return result;
}
long[] generateReverseFactorials(int upTo) {
final long[] reverseFactorials = new long[upTo];
reverseFactorials[0] = reverseFactorials[1] = 1;
final BigInteger BIG_MOD = BigInteger.valueOf(MOD);
for (int i = 1; i < upTo; i++) {
reverseFactorials[i] = (BigInteger.valueOf(i).modInverse(BIG_MOD).longValue() * reverseFactorials[i - 1]) % MOD;
}
return reverseFactorials;
}
}
class Node {
List<Integer> neighbors;
Node() {
neighbors = new ArrayList<>();
}
void addEdge(Integer v) {
neighbors.add(v);
}
public List<Integer> getNeighbors() {
return neighbors;
}
}
class Graph {
List<Node> nodes = new ArrayList<>();
public Graph(int n) {
for (int i = 0; i < n; ++i) {
nodes.add(new Node());
}
}
public Node getNode(int v) {
return nodes.get(v);
}
public void addEdge(int u, int v) {
getNode(u).addEdge(v);
getNode(v).addEdge(u);
}
} | Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | c51bcdb384a4b48da7c926a7db7dc481 | train_001.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes |
import java.util.*;
public class sol {
public static void main(String[] args)
{
//BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0) {
int n=sc.nextInt();
int a[]=new int[n];
for(int i=0;i<n;i++) {
a[i]=sc.nextInt();
}
int ans=0;
for(int i=0;i<n-1;i++) {
if(a[i]<=a[i+1]) {
ans=1;
}
}
if(ans==1)
System.out.println("YES");
else
System.out.println("NO");
}
}
} | Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | 699db448d9955c6546358b4db1e1179b | train_001.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes | import java.io.*;
import java.util.*;
import java.lang.*;
public class A {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int T = in.nextInt();
for(int tt=0;tt<T;tt++) {
int n = in.nextInt();
int[] a=new int[n];
int[] sorted=new int[n];
for (int i=0; i<n; i++) {
a[i]=in.nextInt();
sorted[i]=a[i];
}
Arrays.sort(sorted);
boolean isPoss = false;
boolean isSame = false;
for(int i=n-2;i>=0;i--)
if(sorted[i]==sorted[i+1])isSame = true;
for(int i=0;i<n;i++)
if(a[i]!=sorted[n-1-i])isPoss = true;
if(isPoss||isSame) out.println("YES");
else {
out.println("NO");
}
// for(int i:sorted) out.print(i+" ");
// out.println();
}
out.close();
}
} | Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | 4be8e6b0f37c2bea7feffb1c25fb43e5 | train_001.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes | import java.util.Scanner;
public class CubesSorting {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int n = sc.nextInt();
boolean ans = false;
int arr[] = new int[n];
arr[0] = sc.nextInt();
for(int i=1;i<n;i++){
arr[i] = sc.nextInt();
if(arr[i]>=arr[i-1])
ans = true;
}
if(ans)
System.out.println("YES");
else
System.out.println("NO");
}
}
} | Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | c3835e8b57534dc83e3a8ec63890da0e | train_001.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes | import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.PriorityQueue;
import java.util.Scanner;
public class Main {
public static void main(String[]args) {
Scanner s=new Scanner(System.in);
int op=s.nextInt();
while(op>0) {
int n=s.nextInt();
int arr[]=new int[n];
for(int i=0;i<arr.length;i++) {
arr[i]=s.nextInt();
}
int falg=0;
for(int i=0;i<arr.length-1;i++) {
if(arr[i]<=arr[i+1]) {
falg++;
}
}
if(falg>0) {
System.out.println("YES");
}
else {
System.out.println("NO");
}
op--;
}
}
} | Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | dacdcd6b0286c6b88f1733134d301c82 | train_001.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes |
import java.util.*;
import java.io.*;
public class Cubes_Sorting_672A {
static int mod = (int) (1e9 + 7);
public static void main(String[] args) throws java.lang.Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
while (t-- > 0) {
int n=Integer.parseInt(br.readLine());
long a[]=new long[n];
StringTokenizer st = new StringTokenizer(br.readLine());
// if we are swapping 1 element with remaining (n-1) elements.
// if in array total n elements then
// total no. of swaps would be n(n-1)/2
boolean ok=false;
for(int i=0; i<n; i++) {
a[i]=Long.parseLong(st.nextToken());
if(i>0) {
if(a[i]>=a[i-1]) {
ok=true;
}
}
}
System.out.println(ok?"YES":"NO");
}
}
static class CP {
static long binary_Expo(long a, long b) { // calculating a^b
long res = 1;
while (b != 0) {
if ((b & 1) == 1) {
res *= a;
--b;
}
a *= a;
b /= 2;
}
return res;
}
static long Modular_Expo(long a, long b) {
long res = 1;
while (b != 0) {
if ((b & 1) == 1) {
res = (res * a) % mod;
--b;
}
a = (a * a) % mod;
b /= 2;
}
return res;
}
static int i_gcd(int a, int b) {// iterative way to calculate gcd.
while (true) {
if (b == 0)
return a;
int c = a;
a = b;
b = c % b;
}
}
static long gcd(long a, long b) {// here b is the remainder
if (b == 0)
return a; //because each time b will divide a.
return gcd(b, a % b);
}
static long ceil_div(long a, long b) { // a numerator b denominator
return (a + b - 1) / b;
}
static int getIthBitFromInt(int bits, int i) {
return (bits >> (i - 1)) & 1;
}
static int upper_Bound(int a[], int x) {//closest to the left+1
int l = -1, r = a.length;
while (l + 1 < r) {
int m = (l + r) >>> 1;
if (a[m] <= x)
l = m;
else
r = m;
}
return l + 1;
}
static int lower_Bound(int a[], int x) {//closest to the right
int l = -1, r = a.length;
while (l + 1 < r) {
int m = (l + r) >>> 1;
if (a[m] >= x)
r = m;
else
l = m;
}
return r;
}
static void sort(int a[]) {//heap sort
PriorityQueue<Integer> q = new PriorityQueue<>();
for (int i = 0; i < a.length; i++)
q.add(a[i]);
for (int i = 0; i < a.length; i++)
a[i] = q.poll();
}
}
}
| Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | 8d5b58820470d5972aad83294b6e8b3d | train_001.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes | import java.util.*;
import java.io.*;
public class Election {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
long n=sc.nextInt();
long c2=n*(n-1)/2-1;
int max=0;
long count=0;
int arr[]=new int[(int)n];
for(int i=0;i<n;i++)
arr[i]=sc.nextInt();
count=mergeSortAndCount(arr,0,(int)n-1);
if(count>c2){
System.out.println("NO");
}else{
System.out.println("YES");
}
}
}
private static long mergeAndCount(int[] arr, int l, int m, int r)
{
int[] left = Arrays.copyOfRange(arr, l, m + 1);
int[] right = Arrays.copyOfRange(arr, m + 1, r + 1);
int i = 0, j = 0, k = l;long swaps = 0;
while (i < left.length && j < right.length) {
if (left[i] <= right[j])
arr[k++] = left[i++];
else {
arr[k++] = right[j++];
swaps += (m + 1) - (l + i);
}
}
while (i < left.length)
arr[k++] = left[i++];
while (j < right.length)
arr[k++] = right[j++];
return swaps;
}
private static long mergeSortAndCount(int[] arr, int l, int r)
{
long count = 0;
if (l < r) {
int m = (l + r) / 2;
count += mergeSortAndCount(arr, l, m);
count += mergeSortAndCount(arr, m + 1, r);
count += mergeAndCount(arr, l, m, r);
}
return count;
}
}
| Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | b393e610ad39f52cdb66a6591b4dedb6 | train_001.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes | // Don't place your source in a package
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
// Please name your class Main
public class Main {
static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
static int read() throws IOException {
in.nextToken();
return (int) in.nval;
}
static String readString() throws IOException {
in.nextToken();
return in.sval;
}
public static void main (String[] args) throws java.lang.Exception {
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
//InputReader in = new InputReader(System.in);
int T=in.nextInt();
for(int t=0;t<T;t++){
int n=in.nextInt();
int A[]=new int[n];
for(int i=0;i<n;i++){
A[i]=in.nextInt();
}
Solution sol=new Solution();
sol.solution(A);
}
out.flush();
}
}
class Solution{
//constant variable
final int MAX=Integer.MAX_VALUE;
final int MIN=Integer.MIN_VALUE;
//Set<Integer>adjecent[];
//////////////////////////////
List<Integer>adjecent[];
public void solution(int A[]){
int n=A.length;
int total=(n*(n-1)/2)-1;
for(int i=0;i<A.length-1;i++){
if(A[i]>A[i+1]){
}else{
msg("YES");
return;
}
}
msg("NO");
}
public long C(long fact[],int i,int j){ // C(20,3)=20!/(17!*3!)
// take a/b where a=20! b=17!*3!
if(j==0)return 1;
long mod=1000000007;
long a=fact[i];
long b=((fact[i-j]%mod)*(fact[j]%mod))%mod;
BigInteger B= BigInteger.valueOf(b);
long binverse=B.modInverse(BigInteger.valueOf(mod)).longValue();
return ((a)*(binverse%mod))%mod;
}
//map operation
public void put(Map<Integer,Integer>map,int i){
if(!map.containsKey(i))map.put(i,0);
map.put(i,map.get(i)+1);
}
public void delete(Map<Integer,Integer>map,int i){
map.put(i,map.get(i)-1);
if(map.get(i)==0)map.remove(i);
}
/*public void tarjan(int p,int r){
if(cut)return;
List<Integer>childs=adjecent[r];
dis[r]=low[r]=time;
time++;
//core for tarjan
int son=0;
for(int c:childs){
if(ban==c||c==p)continue;
if(dis[c]==-1){
son++;
tarjan(r,c);
low[r]=Math.min(low[r],low[c]);
if((r==root&&son>1)||(low[c]>=dis[r]&&r!=root)){
cut=true;
return;
}
}else{
if(c!=p){
low[r]=Math.min(low[r],dis[c]);
}
}
}
}*/
//helper function I would use
public void remove(Map<Integer,Integer>map,int i){
map.put(i,map.get(i)-1);
if(map.get(i)==0)map.remove(i);
}
public void ascii(String s){
for(char c:s.toCharArray()){
System.out.print((c-'a')+" ");
}
msg("");
}
public int flip(int i){
if(i==0)return 1;
else return 0;
}
public boolean[] primes(int n){
boolean A[]=new boolean[n+1];
for(int i=2;i<=n;i++){
if(A[i]==false){
for(int j=i+i;j<=n;j+=i){
A[j]=true;
}
}
}
return A;
}
public void msg(String s){
System.out.println(s);
}
public void msg1(String s){
System.out.print(s);
}
public int[] kmpPre(String p){
int pre[]=new int[p.length()];
int l=0,r=1;
while(r<p.length()){
if(p.charAt(l)==p.charAt(r)){
pre[r]=l+1;
l++;r++;
}else{
if(l==0)r++;
else l=pre[l-1];
}
}
return pre;
}
public boolean isP(String s){
int l=0,r=s.length()-1;
while(l<r){
if(s.charAt(l)!=s.charAt(r))return false;
l++;r--;
}
return true;
}
public int find(int nums[],int x){//union find => find method
if(nums[x]==x)return x;
int root=find(nums,nums[x]);
nums[x]=root;
return root;
}
public boolean check(int grid[][],int r,int c){
if(r<0||c<0||r>=grid.length||c>=grid[0].length)return false;
return true;
}
public int get(int A[],int i){
if(i<0||i>=A.length)return 0;
return A[i];
}
public int[] copy1(int A[]){
int a[]=new int[A.length];
for(int i=0;i<a.length;i++)a[i]=A[i];
return a;
}
public int[] copy2(int A[]){
int a[]=new int[A.length];
for(int i=0;i<a.length;i++)a[i]=A[i];
return a;
}
public void print1(int A[]){
for(long i:A)System.out.print(i+" ");
System.out.println();
}
public void print2(long A[][]){
for(int i=0;i<A.length;i++){
for(int j=0;j<A[0].length;j++){
System.out.print(A[i][j]+" ");
}System.out.println();
}
}
public int min(int a,int b){
return Math.min(a,b);
}
public int[][] matrixdp(int[][] grid) {
if(grid.length==0)return new int[][]{};
int res[][]=new int[grid.length][grid[0].length];
for(int i=0;i<grid.length;i++){
for(int j=0;j<grid[0].length;j++){
res[i][j]=grid[i][j]+get(res,i-1,j)+get(res,i,j-1)-get(res,i-1,j-1);
}
}
return res;
}
public int get(int grid[][],int i,int j){
if(i<0||j<0||i>=grid.length||j>=grid[0].length)return 0;
return grid[i][j];
}
public int[] suffixArray(String s){
int n=s.length();
Suffix A[]=new Suffix[n];
for(int i=0;i<n;i++){
A[i]=new Suffix(i,s.charAt(i)-'a',0);
}
for(int i=0;i<n;i++){
if(i==n-1){
A[i].next=-1;
}else{
A[i].next=A[i+1].rank;
}
}
Arrays.sort(A);
for(int len=4;len<A.length*2;len<<=1){
int in[]=new int[A.length];
int rank=0;
int pre=A[0].rank;
A[0].rank=rank;
in[A[0].index]=0;
for(int i=1;i<A.length;i++){//rank for the first two letter
if(A[i].rank==pre&&A[i].next==A[i-1].next){
pre=A[i].rank;
A[i].rank=rank;
}else{
pre=A[i].rank;
A[i].rank=++rank;
}
in[A[i].index]=i;
}
for(int i=0;i<A.length;i++){
int next=A[i].index+len/2;
if(next>=A.length){
A[i].next=-1;
}else{
A[i].next=A[in[next]].rank;
}
}
Arrays.sort(A);
}
int su[]=new int[A.length];
for(int i=0;i<su.length;i++){
su[i]=A[i].index;
}
return su;
}
}
//suffix array Struct
class Suffix implements Comparable<Suffix>{
int index;
int rank;
int next;
public Suffix(int i,int rank,int next){
this.index=i;
this.rank=rank;
this.next=next;
}
@Override
public int compareTo(Suffix other) {
if(this.rank==other.rank){
return this.next-other.next;
}
return this.rank-other.rank;
}
public String toString(){
return this.index+" "+this.rank+" "+this.next+" ";
}
}
class Wrapper implements Comparable<Wrapper>{
int spf;int cnt;
public Wrapper(int spf,int cnt){
this.spf=spf;
this.cnt=cnt;
}
@Override
public int compareTo(Wrapper other) {
return this.spf-other.spf;
}
}
class Node{//what the range would be for that particular node
boolean state=false;
int l=0,r=0;
int ll=0,rr=0;
public Node(boolean state){
this.state=state;
}
}
class Seg1{
int A[];
public Seg1(int A[]){
this.A=A;
}
public void update(int left,int right,int val,int s,int e,int id){
if(left<0||right<0||left>right)return;
if(left==s&&right==e){
A[id]+=val;
return;
}
int mid=s+(e-s)/2; //[s,mid] [mid+1,e]
if(left>=mid+1){
update(left,right,val,mid+1,e,id*2+2);
}else if(right<=mid){
update(left,right,val,s,mid,id*2+1);
}else{
update(left,mid,val,s,mid,id*2+1);
update(mid+1,right,val,mid+1,e,id*2+2);
}
}
public int query(int i,int add,int s,int e,int id){
if(s==e&&i==s){
return A[id]+add;
}
int mid=s+(e-s)/2; //[s,mid] [mid+1,e]
if(i>=mid+1){
return query(i,A[id]+add,mid+1,e,id*2+2);
}else{
return query(i,A[id]+add,s,mid,id*2+1);
}
}
}
| Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | cb266903516a04be69f123aa41be5b05 | train_001.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes | import java.util.*;
public class t{
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
boolean can=false;
int n=sc.nextInt();
int [] arr=new int[n];
for(int i=0;i<n;i++)
{arr[i]=sc.nextInt();}
for(int i=1;i<n;i++){
if (arr[i]>=arr[i-1])
{
can=true;
break;
}
}
if(can) {System.out.println("YES");}
else {System.out.println("NO");}
}
}
}
| Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | 5edce7b5e849bace026457199db1d5fb | train_001.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.*;
public class Abc {
public static void main(String[] args) {
FastScanner fs = new FastScanner();
int t=fs.nextInt();
while(t-->0)
{
int n =fs.nextInt();
long a[]=new long[n];
for(int i=0;i<n;i++)
{
a[i]=fs.nextLong();
}
int flag=0;
for(int i=1;i<n;i++)
{
if(a[i]>=a[i-1])
{
flag=1;
break;
}
}
if(flag==1)
System.out.println("YES");
else
System.out.println("NO");
}
}
static class FastScanner
{
BufferedReader br;
StringTokenizer st;
public FastScanner()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
}
| Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | d7c7adfc3169e37b80134efd1e63bce0 | train_001.jsonl | 1600958100 | For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs $$$n$$$ cubes. $$$i$$$-th cube has a volume $$$a_i$$$.Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $$$i>1$$$, $$$a_{i-1} \le a_i$$$ must hold.To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $$$i>1$$$ you can exchange cubes on positions $$$i-1$$$ and $$$i$$$.But there is a problem: Wheatley is very impatient. If Wheatley needs more than $$$\frac{n \cdot (n-1)}{2}-1$$$ exchange operations, he won't do this boring work.Wheatly wants to know: can cubes be sorted under this conditions? | 256 megabytes |
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;
import java.util.StringTokenizer;
public class CubesSorting {
static long e;
static int n;
static int [] arr;
public static void main(String[] args) throws IOException {
PrintWriter pw = new PrintWriter(System.out);
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
n = sc.nextInt();
arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
boolean sorted= true;
for(int i=0; i<n-1; i++) {
if(arr[i]<=arr[i+1]) {
sorted=false;
break;
}
}
pw.println((sorted)?"NO":"YES");
}
pw.flush();
pw.close();
}
private static boolean possible() {
long count=0;
for(int i=0; i<n-1; i++) {
for(int j=0; j<n-i-1; j++) {
if(arr[j+1]<arr[j]) {
int tmp= arr[j];
arr[j]= arr[j+1];
arr[j+1]= tmp;
count++;
}
if(count>e) return false;
}
}
return true;
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public Scanner(String file) throws FileNotFoundException {
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 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 {
return Double.parseDouble(next());
}
public boolean ready() throws IOException {
return br.ready();
}
}
}
| Java | ["3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1"] | 1 second | ["YES\nYES\nNO"] | NoteIn the first test case it is possible to sort all the cubes in $$$7$$$ exchanges.In the second test case the cubes are already sorted.In the third test case we can make $$$0$$$ exchanges, but the cubes are not sorted yet, so the answer is "NO". | Java 8 | standard input | [
"sortings",
"math"
] | b34f29e6fb586c22fa1b9e559c5a6c50 | Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 1000$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — number of cubes. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — volumes of cubes. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. | 900 | For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise. | standard output | |
PASSED | 8c5558bd065e71de553defbc2cde610e | train_001.jsonl | 1595601300 | The length of the longest common prefix of two strings $$$s = s_1 s_2 \ldots s_n$$$ and $$$t = t_1 t_2 \ldots t_m$$$ is defined as the maximum integer $$$k$$$ ($$$0 \le k \le min(n,m)$$$) such that $$$s_1 s_2 \ldots s_k$$$ equals $$$t_1 t_2 \ldots t_k$$$.Koa the Koala initially has $$$n+1$$$ strings $$$s_1, s_2, \dots, s_{n+1}$$$.For each $$$i$$$ ($$$1 \le i \le n$$$) she calculated $$$a_i$$$ — the length of the longest common prefix of $$$s_i$$$ and $$$s_{i+1}$$$.Several days later Koa found these numbers, but she couldn't remember the strings.So Koa would like to find some strings $$$s_1, s_2, \dots, s_{n+1}$$$ which would have generated numbers $$$a_1, a_2, \dots, a_n$$$. Can you help her?If there are many answers print any. We can show that answer always exists for the given constraints. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class demo_A{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
char ch [] = new char[200];
Arrays.fill(ch, 'a');
while( t-- > 0 ){
int n = sc.nextInt();
System.out.println(ch);
for(int i=0; i<n; i++){
int c = sc.nextInt();
ch[c] = ch[c]=='a'? 'b':'a';
System.out.println(ch);
}
}
}
} | Java | ["4\n4\n1 2 4 2\n2\n5 3\n3\n1 3 1\n3\n0 0 0"] | 1 second | ["aeren\nari\narousal\naround\nari\nmonogon\nmonogamy\nmonthly\nkevinvu\nkuroni\nkurioni\nkorone\nanton\nloves\nadhoc\nproblems"] | NoteIn the $$$1$$$-st test case one of the possible answers is $$$s = [aeren, ari, arousal, around, ari]$$$.Lengths of longest common prefixes are: Between $$$\color{red}{a}eren$$$ and $$$\color{red}{a}ri$$$ $$$\rightarrow 1$$$ Between $$$\color{red}{ar}i$$$ and $$$\color{red}{ar}ousal$$$ $$$\rightarrow 2$$$ Between $$$\color{red}{arou}sal$$$ and $$$\color{red}{arou}nd$$$ $$$\rightarrow 4$$$ Between $$$\color{red}{ar}ound$$$ and $$$\color{red}{ar}i$$$ $$$\rightarrow 2$$$ | Java 8 | standard input | [
"constructive algorithms",
"greedy",
"strings"
] | 6983823efdc512f8759203460cd6bb4c | Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of elements in the list $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 50$$$) — the elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$100$$$. | 1,200 | For each test case: Output $$$n+1$$$ lines. In the $$$i$$$-th line print string $$$s_i$$$ ($$$1 \le |s_i| \le 200$$$), consisting of lowercase Latin letters. Length of the longest common prefix of strings $$$s_i$$$ and $$$s_{i+1}$$$ has to be equal to $$$a_i$$$. If there are many answers print any. We can show that answer always exists for the given constraints. | standard output | |
PASSED | 9da0b40b684a5bcbf3ef97b21aa1a1ed | train_001.jsonl | 1595601300 | The length of the longest common prefix of two strings $$$s = s_1 s_2 \ldots s_n$$$ and $$$t = t_1 t_2 \ldots t_m$$$ is defined as the maximum integer $$$k$$$ ($$$0 \le k \le min(n,m)$$$) such that $$$s_1 s_2 \ldots s_k$$$ equals $$$t_1 t_2 \ldots t_k$$$.Koa the Koala initially has $$$n+1$$$ strings $$$s_1, s_2, \dots, s_{n+1}$$$.For each $$$i$$$ ($$$1 \le i \le n$$$) she calculated $$$a_i$$$ — the length of the longest common prefix of $$$s_i$$$ and $$$s_{i+1}$$$.Several days later Koa found these numbers, but she couldn't remember the strings.So Koa would like to find some strings $$$s_1, s_2, \dots, s_{n+1}$$$ which would have generated numbers $$$a_1, a_2, \dots, a_n$$$. Can you help her?If there are many answers print any. We can show that answer always exists for the given constraints. | 256 megabytes | import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
public class Main {
public static void main (String[] args) throws java.lang.Exception
{
BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out));
InputReader in = new InputReader(System.in);
int T = in.readInt();
while(T-->0) {
int n = in.readInt();
int [] arr = IOUtils.readIntArray(in, n);
String[] st = new String[n+1];
String temp = "aaaaaaaaaaaaaaaaaaaa";
StringBuilder s = new StringBuilder("");
for(int i = 0;i<10;i++) {
s.append(temp);
}
String str = s.toString();
int a = 0;
Arrays.fill(st,str);
for(int i = 0;i<n;i++) {
if(i<n)
a = arr[i];
String is = st[i];
st[i+1] = is;
char x = st[i+1].charAt(a);
if(x<'z')
x++;
else
x = 'b';
String k = st[i+1].substring(0, a)+x+is.substring(a+1);
st[i+1] = k;
}
for(String p:st) {
log.write(p+"\n");
}
log.flush();
}
}
}
class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int readInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public String readString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next() {
return readString();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
class IOUtils {
public static int[] readIntArray(InputReader in, int size) {
int[] array = new int[size];
for (int i = 0; i < size; i++)
array[i] = in.readInt();
return array;
}
}
| Java | ["4\n4\n1 2 4 2\n2\n5 3\n3\n1 3 1\n3\n0 0 0"] | 1 second | ["aeren\nari\narousal\naround\nari\nmonogon\nmonogamy\nmonthly\nkevinvu\nkuroni\nkurioni\nkorone\nanton\nloves\nadhoc\nproblems"] | NoteIn the $$$1$$$-st test case one of the possible answers is $$$s = [aeren, ari, arousal, around, ari]$$$.Lengths of longest common prefixes are: Between $$$\color{red}{a}eren$$$ and $$$\color{red}{a}ri$$$ $$$\rightarrow 1$$$ Between $$$\color{red}{ar}i$$$ and $$$\color{red}{ar}ousal$$$ $$$\rightarrow 2$$$ Between $$$\color{red}{arou}sal$$$ and $$$\color{red}{arou}nd$$$ $$$\rightarrow 4$$$ Between $$$\color{red}{ar}ound$$$ and $$$\color{red}{ar}i$$$ $$$\rightarrow 2$$$ | Java 8 | standard input | [
"constructive algorithms",
"greedy",
"strings"
] | 6983823efdc512f8759203460cd6bb4c | Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of elements in the list $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 50$$$) — the elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$100$$$. | 1,200 | For each test case: Output $$$n+1$$$ lines. In the $$$i$$$-th line print string $$$s_i$$$ ($$$1 \le |s_i| \le 200$$$), consisting of lowercase Latin letters. Length of the longest common prefix of strings $$$s_i$$$ and $$$s_{i+1}$$$ has to be equal to $$$a_i$$$. If there are many answers print any. We can show that answer always exists for the given constraints. | standard output | |
PASSED | d77ea08aa7334a09d4b80bf89dab6a16 | train_001.jsonl | 1595601300 | The length of the longest common prefix of two strings $$$s = s_1 s_2 \ldots s_n$$$ and $$$t = t_1 t_2 \ldots t_m$$$ is defined as the maximum integer $$$k$$$ ($$$0 \le k \le min(n,m)$$$) such that $$$s_1 s_2 \ldots s_k$$$ equals $$$t_1 t_2 \ldots t_k$$$.Koa the Koala initially has $$$n+1$$$ strings $$$s_1, s_2, \dots, s_{n+1}$$$.For each $$$i$$$ ($$$1 \le i \le n$$$) she calculated $$$a_i$$$ — the length of the longest common prefix of $$$s_i$$$ and $$$s_{i+1}$$$.Several days later Koa found these numbers, but she couldn't remember the strings.So Koa would like to find some strings $$$s_1, s_2, \dots, s_{n+1}$$$ which would have generated numbers $$$a_1, a_2, \dots, a_n$$$. Can you help her?If there are many answers print any. We can show that answer always exists for the given constraints. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main{
static class Reader{
BufferedReader br;
StringTokenizer st;
Reader(){
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){
Reader reader = new Reader();
int t = reader.nextInt();
while(t-- != 0){
int n = reader.nextInt();
StringBuilder s = new StringBuilder();
for(int i=0;i<200;i++)
s.append('a');
System.out.println(s);
for(int i=0;i<n;i++){
int x = reader.nextInt();
if(s.charAt(x) == 'a') s.setCharAt(x, 'b');
else s.setCharAt(x,'a');
System.out.println(s);
}
}
}
} | Java | ["4\n4\n1 2 4 2\n2\n5 3\n3\n1 3 1\n3\n0 0 0"] | 1 second | ["aeren\nari\narousal\naround\nari\nmonogon\nmonogamy\nmonthly\nkevinvu\nkuroni\nkurioni\nkorone\nanton\nloves\nadhoc\nproblems"] | NoteIn the $$$1$$$-st test case one of the possible answers is $$$s = [aeren, ari, arousal, around, ari]$$$.Lengths of longest common prefixes are: Between $$$\color{red}{a}eren$$$ and $$$\color{red}{a}ri$$$ $$$\rightarrow 1$$$ Between $$$\color{red}{ar}i$$$ and $$$\color{red}{ar}ousal$$$ $$$\rightarrow 2$$$ Between $$$\color{red}{arou}sal$$$ and $$$\color{red}{arou}nd$$$ $$$\rightarrow 4$$$ Between $$$\color{red}{ar}ound$$$ and $$$\color{red}{ar}i$$$ $$$\rightarrow 2$$$ | Java 8 | standard input | [
"constructive algorithms",
"greedy",
"strings"
] | 6983823efdc512f8759203460cd6bb4c | Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of elements in the list $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 50$$$) — the elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$100$$$. | 1,200 | For each test case: Output $$$n+1$$$ lines. In the $$$i$$$-th line print string $$$s_i$$$ ($$$1 \le |s_i| \le 200$$$), consisting of lowercase Latin letters. Length of the longest common prefix of strings $$$s_i$$$ and $$$s_{i+1}$$$ has to be equal to $$$a_i$$$. If there are many answers print any. We can show that answer always exists for the given constraints. | standard output | |
PASSED | 08fae0deaeb55fe81e30e9ea287dcc1c | train_001.jsonl | 1595601300 | The length of the longest common prefix of two strings $$$s = s_1 s_2 \ldots s_n$$$ and $$$t = t_1 t_2 \ldots t_m$$$ is defined as the maximum integer $$$k$$$ ($$$0 \le k \le min(n,m)$$$) such that $$$s_1 s_2 \ldots s_k$$$ equals $$$t_1 t_2 \ldots t_k$$$.Koa the Koala initially has $$$n+1$$$ strings $$$s_1, s_2, \dots, s_{n+1}$$$.For each $$$i$$$ ($$$1 \le i \le n$$$) she calculated $$$a_i$$$ — the length of the longest common prefix of $$$s_i$$$ and $$$s_{i+1}$$$.Several days later Koa found these numbers, but she couldn't remember the strings.So Koa would like to find some strings $$$s_1, s_2, \dots, s_{n+1}$$$ which would have generated numbers $$$a_1, a_2, \dots, a_n$$$. Can you help her?If there are many answers print any. We can show that answer always exists for the given constraints. | 256 megabytes | import java.io.PrintWriter;
import java.util.*;
public class Main {
static boolean inversed;
static int l = 0;
static int n;
static int id1, id2;
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int t = in.nextInt();
while (t-- > 0) {
int n = in.nextInt();
int[] a = new int[n];
for (int i = 0; i < a.length; i++) {
a[i] = in.nextInt();
}
List<StringBuilder> s = new ArrayList<>();
StringBuilder sb = new StringBuilder();
for (int j = 0; j < 100; j++) {
sb.append('a');
}
String prev = sb.toString();
s.add(sb);
for (int i = 0; i < n; i++) {
sb = new StringBuilder();
for (int j = 0; j < 100; j++) {
sb.append(prev.charAt(j));
}
char ch = sb.charAt(a[i]);
if (ch != 'z') {
ch = (char) (ch + 1);
} else {
ch = (char) (ch - 1);
}
sb.setCharAt(a[i], ch);
s.add(sb);
prev = sb.toString();
}
for (StringBuilder x : s) {
out.println(x);
}
}
out.close();
}
}
| Java | ["4\n4\n1 2 4 2\n2\n5 3\n3\n1 3 1\n3\n0 0 0"] | 1 second | ["aeren\nari\narousal\naround\nari\nmonogon\nmonogamy\nmonthly\nkevinvu\nkuroni\nkurioni\nkorone\nanton\nloves\nadhoc\nproblems"] | NoteIn the $$$1$$$-st test case one of the possible answers is $$$s = [aeren, ari, arousal, around, ari]$$$.Lengths of longest common prefixes are: Between $$$\color{red}{a}eren$$$ and $$$\color{red}{a}ri$$$ $$$\rightarrow 1$$$ Between $$$\color{red}{ar}i$$$ and $$$\color{red}{ar}ousal$$$ $$$\rightarrow 2$$$ Between $$$\color{red}{arou}sal$$$ and $$$\color{red}{arou}nd$$$ $$$\rightarrow 4$$$ Between $$$\color{red}{ar}ound$$$ and $$$\color{red}{ar}i$$$ $$$\rightarrow 2$$$ | Java 8 | standard input | [
"constructive algorithms",
"greedy",
"strings"
] | 6983823efdc512f8759203460cd6bb4c | Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of elements in the list $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 50$$$) — the elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$100$$$. | 1,200 | For each test case: Output $$$n+1$$$ lines. In the $$$i$$$-th line print string $$$s_i$$$ ($$$1 \le |s_i| \le 200$$$), consisting of lowercase Latin letters. Length of the longest common prefix of strings $$$s_i$$$ and $$$s_{i+1}$$$ has to be equal to $$$a_i$$$. If there are many answers print any. We can show that answer always exists for the given constraints. | standard output | |
PASSED | 216ce2f2d1cbe76105eeaaa7d65a48eb | train_001.jsonl | 1595601300 | The length of the longest common prefix of two strings $$$s = s_1 s_2 \ldots s_n$$$ and $$$t = t_1 t_2 \ldots t_m$$$ is defined as the maximum integer $$$k$$$ ($$$0 \le k \le min(n,m)$$$) such that $$$s_1 s_2 \ldots s_k$$$ equals $$$t_1 t_2 \ldots t_k$$$.Koa the Koala initially has $$$n+1$$$ strings $$$s_1, s_2, \dots, s_{n+1}$$$.For each $$$i$$$ ($$$1 \le i \le n$$$) she calculated $$$a_i$$$ — the length of the longest common prefix of $$$s_i$$$ and $$$s_{i+1}$$$.Several days later Koa found these numbers, but she couldn't remember the strings.So Koa would like to find some strings $$$s_1, s_2, \dots, s_{n+1}$$$ which would have generated numbers $$$a_1, a_2, \dots, a_n$$$. Can you help her?If there are many answers print any. We can show that answer always exists for the given constraints. | 256 megabytes | /*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
//package Div2_659;
import java.util.Arrays;
import java.util.Scanner;
/**
*
* @author HP
*/
public class Main {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int t=input.nextInt();
while(t>0)
{
int n=input.nextInt();
// int t=input.nextInt();
int a[]=new int[n];
int sum=0;
for(int i=0;i<n;i++)
{
a[i]=input.nextInt();
sum=Math.max(a[i],sum)+1;
}
int count=0;
char b[]=new char[sum];
for(int i=0;i<sum;i++)
{
b[count]='a';
count++;
}
for(int i=0;i<count;i++)
{
System.out.print(b[i]);
}
System.out.println("");
// System.out.println(Arrays.toString(b));
char c[]=new char[sum];
int count1=0;
for(int j=0;j<a[0];j++)
{
c[count1]='a';
count1++;
}
for(int k=count1;k<count;k++)
{
c[count1]='b';
count1++;
}
for(int k=0;k<count1;k++)
{
System.out.print(c[k]);
}
System.out.println("");
char d[]=new char[sum];
for(int i=1;i<n;i++)
{ int count2=0;
for(int j=0;j<a[i];j++)
{
d[count2]=c[j];
count2++;
}
for(int k=count2;k<count;k++)
{
if(c[k]=='a')
{
d[count2]='b';
count2++;
}
if(c[k]=='b')
{
d[count2]='a';
count2++;
}
}
for(int o=count2;o<count;o++)
{
d[count2]='b';
count2++;
}
int cout3=0;
for(int f=0;f<count;f++)
{
c[cout3]=d[f];
cout3++;
}
for(int l=0;l<count;l++)
{
System.out.print(d[l]);
}
System.out.println("");
}
t--;
}
}
}
| Java | ["4\n4\n1 2 4 2\n2\n5 3\n3\n1 3 1\n3\n0 0 0"] | 1 second | ["aeren\nari\narousal\naround\nari\nmonogon\nmonogamy\nmonthly\nkevinvu\nkuroni\nkurioni\nkorone\nanton\nloves\nadhoc\nproblems"] | NoteIn the $$$1$$$-st test case one of the possible answers is $$$s = [aeren, ari, arousal, around, ari]$$$.Lengths of longest common prefixes are: Between $$$\color{red}{a}eren$$$ and $$$\color{red}{a}ri$$$ $$$\rightarrow 1$$$ Between $$$\color{red}{ar}i$$$ and $$$\color{red}{ar}ousal$$$ $$$\rightarrow 2$$$ Between $$$\color{red}{arou}sal$$$ and $$$\color{red}{arou}nd$$$ $$$\rightarrow 4$$$ Between $$$\color{red}{ar}ound$$$ and $$$\color{red}{ar}i$$$ $$$\rightarrow 2$$$ | Java 8 | standard input | [
"constructive algorithms",
"greedy",
"strings"
] | 6983823efdc512f8759203460cd6bb4c | Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of elements in the list $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 50$$$) — the elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$100$$$. | 1,200 | For each test case: Output $$$n+1$$$ lines. In the $$$i$$$-th line print string $$$s_i$$$ ($$$1 \le |s_i| \le 200$$$), consisting of lowercase Latin letters. Length of the longest common prefix of strings $$$s_i$$$ and $$$s_{i+1}$$$ has to be equal to $$$a_i$$$. If there are many answers print any. We can show that answer always exists for the given constraints. | standard output | |
PASSED | d15617c7298c589e91ed7757e4f01baf | train_001.jsonl | 1595601300 | The length of the longest common prefix of two strings $$$s = s_1 s_2 \ldots s_n$$$ and $$$t = t_1 t_2 \ldots t_m$$$ is defined as the maximum integer $$$k$$$ ($$$0 \le k \le min(n,m)$$$) such that $$$s_1 s_2 \ldots s_k$$$ equals $$$t_1 t_2 \ldots t_k$$$.Koa the Koala initially has $$$n+1$$$ strings $$$s_1, s_2, \dots, s_{n+1}$$$.For each $$$i$$$ ($$$1 \le i \le n$$$) she calculated $$$a_i$$$ — the length of the longest common prefix of $$$s_i$$$ and $$$s_{i+1}$$$.Several days later Koa found these numbers, but she couldn't remember the strings.So Koa would like to find some strings $$$s_1, s_2, \dots, s_{n+1}$$$ which would have generated numbers $$$a_1, a_2, \dots, a_n$$$. Can you help her?If there are many answers print any. We can show that answer always exists for the given constraints. | 256 megabytes | //package round_659_div2;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
public class A {
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine());
while(T > 0) {
int N = Integer.parseInt(br.readLine());
String[] ip = br.readLine().split(" ");
int[] ary = new int[N];
for(int i = 0 ;i < N ; i++) {
ary[i] = Integer.parseInt(ip[i]);
}
solve(ary);
//System.out.println('-');
T--;
}
}
private static void solve(int[] ary) {
List<String> list = new ArrayList<>();
String str1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
list.add(str1);
for(int a : ary) {
str1 = getString(str1, a);
list.add(str1);
}
for(String str : list) {
System.out.println(str);
}
}
private static String getString(String str, int p) {
String ans = str.substring(0,p);
char c = (char)(str.charAt(p)+1);
if (c > 'z'){
c = 'a';
}
ans += String.valueOf(c);
ans += str.substring(p+1);
return ans;
}
} | Java | ["4\n4\n1 2 4 2\n2\n5 3\n3\n1 3 1\n3\n0 0 0"] | 1 second | ["aeren\nari\narousal\naround\nari\nmonogon\nmonogamy\nmonthly\nkevinvu\nkuroni\nkurioni\nkorone\nanton\nloves\nadhoc\nproblems"] | NoteIn the $$$1$$$-st test case one of the possible answers is $$$s = [aeren, ari, arousal, around, ari]$$$.Lengths of longest common prefixes are: Between $$$\color{red}{a}eren$$$ and $$$\color{red}{a}ri$$$ $$$\rightarrow 1$$$ Between $$$\color{red}{ar}i$$$ and $$$\color{red}{ar}ousal$$$ $$$\rightarrow 2$$$ Between $$$\color{red}{arou}sal$$$ and $$$\color{red}{arou}nd$$$ $$$\rightarrow 4$$$ Between $$$\color{red}{ar}ound$$$ and $$$\color{red}{ar}i$$$ $$$\rightarrow 2$$$ | Java 8 | standard input | [
"constructive algorithms",
"greedy",
"strings"
] | 6983823efdc512f8759203460cd6bb4c | Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of elements in the list $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 50$$$) — the elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$100$$$. | 1,200 | For each test case: Output $$$n+1$$$ lines. In the $$$i$$$-th line print string $$$s_i$$$ ($$$1 \le |s_i| \le 200$$$), consisting of lowercase Latin letters. Length of the longest common prefix of strings $$$s_i$$$ and $$$s_{i+1}$$$ has to be equal to $$$a_i$$$. If there are many answers print any. We can show that answer always exists for the given constraints. | standard output | |
PASSED | 341d7485d8fdfd95b0732ac79578dfc5 | train_001.jsonl | 1595601300 | The length of the longest common prefix of two strings $$$s = s_1 s_2 \ldots s_n$$$ and $$$t = t_1 t_2 \ldots t_m$$$ is defined as the maximum integer $$$k$$$ ($$$0 \le k \le min(n,m)$$$) such that $$$s_1 s_2 \ldots s_k$$$ equals $$$t_1 t_2 \ldots t_k$$$.Koa the Koala initially has $$$n+1$$$ strings $$$s_1, s_2, \dots, s_{n+1}$$$.For each $$$i$$$ ($$$1 \le i \le n$$$) she calculated $$$a_i$$$ — the length of the longest common prefix of $$$s_i$$$ and $$$s_{i+1}$$$.Several days later Koa found these numbers, but she couldn't remember the strings.So Koa would like to find some strings $$$s_1, s_2, \dots, s_{n+1}$$$ which would have generated numbers $$$a_1, a_2, \dots, a_n$$$. Can you help her?If there are many answers print any. We can show that answer always exists for the given constraints. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
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);
StringBuilder sb = new StringBuilder("");
int t = Integer.parseInt(br.readLine());
while(t-->0) {
String[] in = br.readLine().split(" ");
int n = Integer.parseInt(in[0]);
in = br.readLine().split(" ");
int arr[] = new int[n];
int m = 0;
for(int i=0;i<n;i++){
arr[i] = Integer.parseInt(in[i]);
m = Math.max(m, arr[i]);
}
StringBuilder[] ans = new StringBuilder[n+1];
StringBuilder p = new StringBuilder("");
while(m-->0){
p.append('a');
}
ans[0]=new StringBuilder(p);
for(int i=1;i<=n;i++){
ans[i]=new StringBuilder(ans[i-1]);
if(arr[i-1]<ans[i].length()){
if(ans[i-1].charAt(arr[i-1])=='a'){
ans[i].setCharAt(arr[i-1], 'b');
} else {
ans[i].setCharAt(arr[i-1], 'a');
}
}
}
char ch = 'c';
for(StringBuilder ab:ans){
if(ab.length()==0){
sb.append(ch+"\n");
ch++;
if(ch=='z'){
ch='c';
}
} else {
sb.append(ab+"\n");
}
}
}
out.print(sb);
out.flush();
br.close();
}
}
| Java | ["4\n4\n1 2 4 2\n2\n5 3\n3\n1 3 1\n3\n0 0 0"] | 1 second | ["aeren\nari\narousal\naround\nari\nmonogon\nmonogamy\nmonthly\nkevinvu\nkuroni\nkurioni\nkorone\nanton\nloves\nadhoc\nproblems"] | NoteIn the $$$1$$$-st test case one of the possible answers is $$$s = [aeren, ari, arousal, around, ari]$$$.Lengths of longest common prefixes are: Between $$$\color{red}{a}eren$$$ and $$$\color{red}{a}ri$$$ $$$\rightarrow 1$$$ Between $$$\color{red}{ar}i$$$ and $$$\color{red}{ar}ousal$$$ $$$\rightarrow 2$$$ Between $$$\color{red}{arou}sal$$$ and $$$\color{red}{arou}nd$$$ $$$\rightarrow 4$$$ Between $$$\color{red}{ar}ound$$$ and $$$\color{red}{ar}i$$$ $$$\rightarrow 2$$$ | Java 8 | standard input | [
"constructive algorithms",
"greedy",
"strings"
] | 6983823efdc512f8759203460cd6bb4c | Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of elements in the list $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 50$$$) — the elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$100$$$. | 1,200 | For each test case: Output $$$n+1$$$ lines. In the $$$i$$$-th line print string $$$s_i$$$ ($$$1 \le |s_i| \le 200$$$), consisting of lowercase Latin letters. Length of the longest common prefix of strings $$$s_i$$$ and $$$s_{i+1}$$$ has to be equal to $$$a_i$$$. If there are many answers print any. We can show that answer always exists for the given constraints. | standard output | |
PASSED | 16a4715684e87012eb1eb6a61c48c9a5 | train_001.jsonl | 1595601300 | The length of the longest common prefix of two strings $$$s = s_1 s_2 \ldots s_n$$$ and $$$t = t_1 t_2 \ldots t_m$$$ is defined as the maximum integer $$$k$$$ ($$$0 \le k \le min(n,m)$$$) such that $$$s_1 s_2 \ldots s_k$$$ equals $$$t_1 t_2 \ldots t_k$$$.Koa the Koala initially has $$$n+1$$$ strings $$$s_1, s_2, \dots, s_{n+1}$$$.For each $$$i$$$ ($$$1 \le i \le n$$$) she calculated $$$a_i$$$ — the length of the longest common prefix of $$$s_i$$$ and $$$s_{i+1}$$$.Several days later Koa found these numbers, but she couldn't remember the strings.So Koa would like to find some strings $$$s_1, s_2, \dots, s_{n+1}$$$ which would have generated numbers $$$a_1, a_2, \dots, a_n$$$. Can you help her?If there are many answers print any. We can show that answer always exists for the given constraints. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class A659
{
public static void func(int n, int arr[]){
int count = 1;
int max = arr[0];
for (int i = 0; i < n; i++) max = Math.max(max, arr[i]);
if (max == 0) max = 10;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < max; i++){
sb.append('a');
}
System.out.println(sb);
count++;
char c = (char)(sb.charAt(sb.length() - 1));
for (int i = 0; i < n; i++){
StringBuilder tempSb = new StringBuilder();
for (int j = 0; j < arr[i]; j++){
tempSb.append(sb.charAt(j));
}
c = (char)(c + 1);
if (c > 'z'){
c = 'a';
}
for (int j = tempSb.length(); j < max + 1; j++){
if (j < sb.length() && c == sb.charAt(j)){
c = (char)(c + 1);
if (c > 'z'){
c = 'a';
}
}
tempSb.append(c);
}
System.out.println(tempSb);
count++;
sb = tempSb;
}
}
public static void main (String[] args) throws java.lang.Exception{
Scanner s = new Scanner(System.in);
int t = s.nextInt();
while (t-- != 0){
int n = s.nextInt();
int arr[] = new int[n];
for (int i = 0; i < n; i++) arr[i] = s.nextInt();
func(n, arr);
}
}
}
| Java | ["4\n4\n1 2 4 2\n2\n5 3\n3\n1 3 1\n3\n0 0 0"] | 1 second | ["aeren\nari\narousal\naround\nari\nmonogon\nmonogamy\nmonthly\nkevinvu\nkuroni\nkurioni\nkorone\nanton\nloves\nadhoc\nproblems"] | NoteIn the $$$1$$$-st test case one of the possible answers is $$$s = [aeren, ari, arousal, around, ari]$$$.Lengths of longest common prefixes are: Between $$$\color{red}{a}eren$$$ and $$$\color{red}{a}ri$$$ $$$\rightarrow 1$$$ Between $$$\color{red}{ar}i$$$ and $$$\color{red}{ar}ousal$$$ $$$\rightarrow 2$$$ Between $$$\color{red}{arou}sal$$$ and $$$\color{red}{arou}nd$$$ $$$\rightarrow 4$$$ Between $$$\color{red}{ar}ound$$$ and $$$\color{red}{ar}i$$$ $$$\rightarrow 2$$$ | Java 8 | standard input | [
"constructive algorithms",
"greedy",
"strings"
] | 6983823efdc512f8759203460cd6bb4c | Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of elements in the list $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 50$$$) — the elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$100$$$. | 1,200 | For each test case: Output $$$n+1$$$ lines. In the $$$i$$$-th line print string $$$s_i$$$ ($$$1 \le |s_i| \le 200$$$), consisting of lowercase Latin letters. Length of the longest common prefix of strings $$$s_i$$$ and $$$s_{i+1}$$$ has to be equal to $$$a_i$$$. If there are many answers print any. We can show that answer always exists for the given constraints. | standard output | |
PASSED | 64099a80e9af1a0d1913342d135087ff | train_001.jsonl | 1595601300 | The length of the longest common prefix of two strings $$$s = s_1 s_2 \ldots s_n$$$ and $$$t = t_1 t_2 \ldots t_m$$$ is defined as the maximum integer $$$k$$$ ($$$0 \le k \le min(n,m)$$$) such that $$$s_1 s_2 \ldots s_k$$$ equals $$$t_1 t_2 \ldots t_k$$$.Koa the Koala initially has $$$n+1$$$ strings $$$s_1, s_2, \dots, s_{n+1}$$$.For each $$$i$$$ ($$$1 \le i \le n$$$) she calculated $$$a_i$$$ — the length of the longest common prefix of $$$s_i$$$ and $$$s_{i+1}$$$.Several days later Koa found these numbers, but she couldn't remember the strings.So Koa would like to find some strings $$$s_1, s_2, \dots, s_{n+1}$$$ which would have generated numbers $$$a_1, a_2, \dots, a_n$$$. Can you help her?If there are many answers print any. We can show that answer always exists for the given constraints. | 256 megabytes | import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Stack;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;
public class Main {
static FastReader sc= new FastReader();
static List<Integer> C;
static List<Integer> B;
public static void main(String[] args) {
int t=sc.nextInt();
while(t-->0) {
int n=sc.nextInt();
ArrayList<Integer> a=new ArrayList<>();
for(int i=0;i<n;i++)
a.add(sc.nextInt());
String s="";
int m=Collections.max(a);
int c=97;
for(int i=0;i<Math.max(m,1);i++)s+=(char)c;
System.out.println(s);
for(int i=0;i<n;i++) {
String cur="";
int j=0;
for( j=0;j<a.get(i);j++) {
cur+=s.charAt(j);
}
for(;j<Math.max(m,1);j++) {
int g=(int)s.charAt(j)+1;
if(g>122)g=97;
cur+=(char)g;
}
System.out.println(cur);
s=cur;
}
}
}
static boolean comp(String a1,String a2,String b1,String b2,int n) {
if((a1.equals(b1)&&a2.equals(b2))||(a1.equals(b2)&&a2.equals(b1)))return true;
if(n==1)return false;
else {
// if(a1.length()==1)return false;
return (comp(a1.substring(0,n/2),a1.substring(n/2,n),b1.substring(0,n/2),b1.substring(n/2,n),n/2)&&comp(a2.substring(0,n/2),a2.substring(n/2,n),b2.substring(0,n/2),b2.substring(n/2,n),n/2))
||
(comp(a1.substring(0,n/2),a1.substring(n/2,n),b2.substring(0,n/2),b2.substring(n/2,n),n/2)&&comp(a2.substring(0,n/2),a2.substring(n/2,n),b1.substring(0,n/2),b1.substring(n/2,n),n/2));
}
}
static boolean search(ArrayList<Integer> a,int m,int h) {
PriorityQueue<Integer> p=new PriorityQueue<Integer>(new Comparator<Integer>() {
@Override
public int compare(Integer o1, Integer o2) {
// TODO Auto-generated method stub
return o2-o1;
}
});
for(int i=0;i<m;i++) {
p.add(a.get(i));
}
int c=0;
//System.out.println(p);
while(!p.isEmpty()) {
//System.out.println(p);
h-=p.poll();
if(h<0)break;
c++;
// System.out.println(h+" "+p+" "+c+" "+m);
if(!p.isEmpty()) {
p.poll();
c++;}
}
// System.out.println(c!=m);
if(c!=m)return false;
return true;
}
// static int key=-1;
static boolean isPowerOfTwo(long n)
{
if (n == 0)
return false;
while (n != 1)
{
if (n % 2 != 0)
return false;
n = n / 2;
}
return true;
}
static boolean isPerfectSquare(double x)
{
// Find floating point value of
// square root of x.
double sr = Math.sqrt(x);
// If square root is an integer
return ((sr - Math.floor(sr)) == 0);
}
static int binarySearch(ArrayList<Long> arr, int l, int r, long x,int key)
{
if (r >= l) {
int mid = (r + l) / 2;
// if(mid>=arr.size())return -1;
// If the element is present at the
// middle itself
if (arr.get(mid) == x)
return mid+1;
// If element is smaller than mid, then
// it can only be present in left subarray
if (arr.get(mid) > x) {
return binarySearch(arr, l, mid - 1, x,key);
}
// Else the element can only be present
// in right subarray
key=mid+1;
return binarySearch(arr, mid + 1, r, x,key);
}
// We reach here when element is not present
// in array
return key;
}
static boolean isPrime(long n)
{
// Corner cases
if (n <= 1)
return false;
if (n <= 3)
return true;
// This is checked so that we can skip
// middle five numbers in below loop
if (n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
}
| Java | ["4\n4\n1 2 4 2\n2\n5 3\n3\n1 3 1\n3\n0 0 0"] | 1 second | ["aeren\nari\narousal\naround\nari\nmonogon\nmonogamy\nmonthly\nkevinvu\nkuroni\nkurioni\nkorone\nanton\nloves\nadhoc\nproblems"] | NoteIn the $$$1$$$-st test case one of the possible answers is $$$s = [aeren, ari, arousal, around, ari]$$$.Lengths of longest common prefixes are: Between $$$\color{red}{a}eren$$$ and $$$\color{red}{a}ri$$$ $$$\rightarrow 1$$$ Between $$$\color{red}{ar}i$$$ and $$$\color{red}{ar}ousal$$$ $$$\rightarrow 2$$$ Between $$$\color{red}{arou}sal$$$ and $$$\color{red}{arou}nd$$$ $$$\rightarrow 4$$$ Between $$$\color{red}{ar}ound$$$ and $$$\color{red}{ar}i$$$ $$$\rightarrow 2$$$ | Java 8 | standard input | [
"constructive algorithms",
"greedy",
"strings"
] | 6983823efdc512f8759203460cd6bb4c | Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of elements in the list $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 50$$$) — the elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$100$$$. | 1,200 | For each test case: Output $$$n+1$$$ lines. In the $$$i$$$-th line print string $$$s_i$$$ ($$$1 \le |s_i| \le 200$$$), consisting of lowercase Latin letters. Length of the longest common prefix of strings $$$s_i$$$ and $$$s_{i+1}$$$ has to be equal to $$$a_i$$$. If there are many answers print any. We can show that answer always exists for the given constraints. | standard output | |
PASSED | 54feb40bb9831fdea5a5febed1e0c1c7 | train_001.jsonl | 1595601300 | The length of the longest common prefix of two strings $$$s = s_1 s_2 \ldots s_n$$$ and $$$t = t_1 t_2 \ldots t_m$$$ is defined as the maximum integer $$$k$$$ ($$$0 \le k \le min(n,m)$$$) such that $$$s_1 s_2 \ldots s_k$$$ equals $$$t_1 t_2 \ldots t_k$$$.Koa the Koala initially has $$$n+1$$$ strings $$$s_1, s_2, \dots, s_{n+1}$$$.For each $$$i$$$ ($$$1 \le i \le n$$$) she calculated $$$a_i$$$ — the length of the longest common prefix of $$$s_i$$$ and $$$s_{i+1}$$$.Several days later Koa found these numbers, but she couldn't remember the strings.So Koa would like to find some strings $$$s_1, s_2, \dots, s_{n+1}$$$ which would have generated numbers $$$a_1, a_2, \dots, a_n$$$. Can you help her?If there are many answers print any. We can show that answer always exists for the given constraints. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class CodeForces{
public static void main(String args[])throws IOException{
Scanner in=new Scanner(System.in);
int T=in.nextInt();
while(T-->0){
int n=in.nextInt();
int a[]=new int[n];
int max=0;
for(int i=0;i<n;i++)
max=Math.max(max,a[i]=in.nextInt());
StringBuilder sb=new StringBuilder();
for(int i=0;i<=max;i++)
sb.append('a');
for(int i=0;i<n;i++){
System.out.println(sb);
int c=sb.charAt(a[i])+1;
if(c>'z')
c='a';
sb.setCharAt(a[i],(char)c);
}
System.out.println(sb);
}
}
}
| Java | ["4\n4\n1 2 4 2\n2\n5 3\n3\n1 3 1\n3\n0 0 0"] | 1 second | ["aeren\nari\narousal\naround\nari\nmonogon\nmonogamy\nmonthly\nkevinvu\nkuroni\nkurioni\nkorone\nanton\nloves\nadhoc\nproblems"] | NoteIn the $$$1$$$-st test case one of the possible answers is $$$s = [aeren, ari, arousal, around, ari]$$$.Lengths of longest common prefixes are: Between $$$\color{red}{a}eren$$$ and $$$\color{red}{a}ri$$$ $$$\rightarrow 1$$$ Between $$$\color{red}{ar}i$$$ and $$$\color{red}{ar}ousal$$$ $$$\rightarrow 2$$$ Between $$$\color{red}{arou}sal$$$ and $$$\color{red}{arou}nd$$$ $$$\rightarrow 4$$$ Between $$$\color{red}{ar}ound$$$ and $$$\color{red}{ar}i$$$ $$$\rightarrow 2$$$ | Java 8 | standard input | [
"constructive algorithms",
"greedy",
"strings"
] | 6983823efdc512f8759203460cd6bb4c | Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of elements in the list $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 50$$$) — the elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$100$$$. | 1,200 | For each test case: Output $$$n+1$$$ lines. In the $$$i$$$-th line print string $$$s_i$$$ ($$$1 \le |s_i| \le 200$$$), consisting of lowercase Latin letters. Length of the longest common prefix of strings $$$s_i$$$ and $$$s_{i+1}$$$ has to be equal to $$$a_i$$$. If there are many answers print any. We can show that answer always exists for the given constraints. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.