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
sequencelengths 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 | 002f6d93b946e33fb292c495470758dc | train_000.jsonl | 1416238500 | The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one.For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls. | 256 megabytes | /* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int[] a=new int[n];
for(int i=0;i<n;i++)
a[i]=sc.nextInt();
Arrays.sort(a);
int m=sc.nextInt();
int[] b=new int[m];
for(int i=0;i<m;i++)
b[i]=sc.nextInt();
Arrays.sort(b);
int res=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(Math.abs(a[i]-b[j])<=1)
{
b[j]=999;
res++;
break;
}
}
}
System.out.println(res);
}
} | Java | ["4\n1 4 6 2\n5\n5 1 5 7 9", "4\n1 2 3 4\n4\n10 11 12 13", "5\n1 1 1 1 1\n3\n1 2 3"] | 1 second | ["3", "0", "2"] | null | Java 8 | standard input | [
"dp",
"greedy",
"two pointers",
"graph matchings",
"sortings",
"dfs and similar"
] | 62766ef9a0751cbe7987020144de7512 | The first line contains an integer n (1ββ€βnββ€β100) β the number of boys. The second line contains sequence a1,βa2,β...,βan (1ββ€βaiββ€β100), where ai is the i-th boy's dancing skill. Similarly, the third line contains an integer m (1ββ€βmββ€β100) β the number of girls. The fourth line contains sequence b1,βb2,β...,βbm (1ββ€βbjββ€β100), where bj is the j-th girl's dancing skill. | 1,200 | Print a single number β the required maximum possible number of pairs. | standard output | |
PASSED | fa496fb9afcdb0553d05311337e0e66d | train_000.jsonl | 1416238500 | The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one.For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.StringTokenizer;
import java.io.PrintWriter;
import java.io.*;
import java.util.stream.Collectors.*;
import java.lang.*;
import static java.util.stream.Collectors.*;
import static java.util.Map.Entry.*;
public class Ideo
{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
static class aksh
{
int p;
int q;
public aksh(int a,int b)
{
p = a;
q = b;
}
}
static int power(int x,int y)
{
int res = 1; // Initialize result
// Update x if it is more than or
// equal to p
while (y > 0)
{
// If y is odd, multiply x with result
if (y%2==1)
res = (res*x);
// y must be even now
y = y>>1; // y = y/2
x = (x*x);
}
return res;
}
static int gcd(int a, int b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
static int findGCD(int arr[], int n)
{
int result = arr[0];
for (int i = 1; i < n; i++)
result = gcd(arr[i], result);
return result;
}
static ArrayList<aksh>[] adj;
static int[] vis;
static boolean compareSeq(char[] S, int x, int y, int n)
{
for (int i = 0; i < n; i++)
{
if (S[x] < S[y])
return true;
else if (S[x] > S[y])
return false;
x = (x + 1) % n;
y = (y + 1) % n;
}
return true;
}
static void build(long[] sum,int[] arr,int n)
{
for(int i=0;i<(1<<n);i++)
{
long total=0;
for(int j=0;j<n;j++)
{
if((i & (1 << j)) > 0)
total+=arr[j];
}
sum[i]=total;
}
}
static int count(long arr[], long x, int n)
{
int l=0;
int h=n-1;
int res=-1;
int mid=-1;
while(l<=h)
{
mid=l+(h-l)/2;
if(x==arr[mid])
{
res=mid;
h=mid-1;
}
else if(x<arr[mid])
h=mid-1;
else
l=mid+1;
}
if(res==-1)
return 0;
//res is first index and res1 is last index of an element in a sorted array total number of occurences is (res1-res+1)
int res1=-1;
l=0;
h=n-1;
while(l<=h)
{
mid=l+(h-l)/2;
if(x==arr[mid])
{
res1=mid;
l=mid+1;
}
else if(x<arr[mid])
h=mid-1;
else
l=mid+1;
}
if(res1==-1)
return 0;
if(res!=-1 && res1!=-1)
return (res1-res+1);
return 0;
}
static int parity(int a)
{
a^=a>>16;
a^=a>>8;
a^=a>>4;
a^=a>>2;
a^=a>>1;
return a&1;
}
/*
PriorityQueue<aksh> pq = new PriorityQueue<>((o1, o2) -> {
if (o1.p < o2.p)
return 1;
else if (o1.p > o2.p)
return -1;
else
return 0;
});//decreasing order acc to p*/
public static void main(String args[] ) throws Exception
{
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
FastReader sc=new FastReader();
int n=sc.nextInt();
int[] a1=new int[n+1];
for(int i=1;i<=n;i++)
{
a1[i]=sc.nextInt();
}
int m=sc.nextInt();
int[] a2=new int[m+1];
for(int i=1;i<=m;i++)
{
a2[i]=sc.nextInt();
}
Arrays.sort(a1);
Arrays.sort(a2);
long[][] dp=new long[101][101];
dp[0][0]=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(Math.abs(a1[i]-a2[j])<=1)
dp[i][j]=Math.max(dp[i-1][j-1]+1,Math.max(dp[i-1][j],dp[i][j-1]));
else
dp[i][j]=Math.max(dp[i-1][j],dp[i][j-1]);
}
}
System.out.println(dp[n][m]);
}
} | Java | ["4\n1 4 6 2\n5\n5 1 5 7 9", "4\n1 2 3 4\n4\n10 11 12 13", "5\n1 1 1 1 1\n3\n1 2 3"] | 1 second | ["3", "0", "2"] | null | Java 8 | standard input | [
"dp",
"greedy",
"two pointers",
"graph matchings",
"sortings",
"dfs and similar"
] | 62766ef9a0751cbe7987020144de7512 | The first line contains an integer n (1ββ€βnββ€β100) β the number of boys. The second line contains sequence a1,βa2,β...,βan (1ββ€βaiββ€β100), where ai is the i-th boy's dancing skill. Similarly, the third line contains an integer m (1ββ€βmββ€β100) β the number of girls. The fourth line contains sequence b1,βb2,β...,βbm (1ββ€βbjββ€β100), where bj is the j-th girl's dancing skill. | 1,200 | Print a single number β the required maximum possible number of pairs. | standard output | |
PASSED | 4f840447f1af6634b1c4e1ee85bd2555 | train_000.jsonl | 1416238500 | The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one.For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls. | 256 megabytes | /* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int[] a1=new int[n];
for(int x=0;x<n;x++)
a1[x]=sc.nextInt();
int m=sc.nextInt();
int[] a2=new int[m];
for(int x=0;x<m;x++)
a2[x]=sc.nextInt();
Arrays.sort(a1);
Arrays.sort(a2);
int i=0;
int j=0;
int c=0;
while(i<n && j<m)
{
if(Math.abs(a1[i]-a2[j])<=1)
{ // System.out.println(i+" "+j+" "+c+" "+a1[i]+" "+a2[j]);
c++;
i++;
j++;
}
else if(a1[i]>a2[j])
j++;
else if(a1[i]<a2[j])
i++;
}
System.out.println(c);
}
} | Java | ["4\n1 4 6 2\n5\n5 1 5 7 9", "4\n1 2 3 4\n4\n10 11 12 13", "5\n1 1 1 1 1\n3\n1 2 3"] | 1 second | ["3", "0", "2"] | null | Java 8 | standard input | [
"dp",
"greedy",
"two pointers",
"graph matchings",
"sortings",
"dfs and similar"
] | 62766ef9a0751cbe7987020144de7512 | The first line contains an integer n (1ββ€βnββ€β100) β the number of boys. The second line contains sequence a1,βa2,β...,βan (1ββ€βaiββ€β100), where ai is the i-th boy's dancing skill. Similarly, the third line contains an integer m (1ββ€βmββ€β100) β the number of girls. The fourth line contains sequence b1,βb2,β...,βbm (1ββ€βbjββ€β100), where bj is the j-th girl's dancing skill. | 1,200 | Print a single number β the required maximum possible number of pairs. | standard output | |
PASSED | fc2b4678588031e1cd5efafd2b4aa4a8 | train_000.jsonl | 1416238500 | The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one.For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls. | 256 megabytes |
import java.util.Scanner;
public class Controller {
public static void main(String[] args){
int pairs=0;
int numb;
boolean skip = false;
Scanner c = new Scanner(System.in);
numb = c.nextInt();
int[] skb=new int[numb];
for (int i =0; i<skb.length;i++){
skb[i]= c.nextInt();
}
int numg;
numg = c.nextInt();
int[] skg=new int[numg];
for (int i =0; i<numg;i++)
{
skg[i]= c.nextInt();
}
for(int t=0;t<numg;t++){
//get the smallest
int small=skg[0];
int smalln=0;
for (int i = 0; i < numg; i++) {
if (small > skg[i]) {
small = skg[i];
smalln=i;
}
}
skg[smalln]=9999;
//compare it
for (int j=0;j<numb;j++)
{
if (small==(skb[j])+1&&skip==false)
{
skb[j]=-9999;
pairs++;
skip = true;
}
}
for (int j=0;j<numb;j++)
{
if (small==skb[j]&&skip==false)
{
skb[j]=-9999;
pairs++;
skip = true;
}
}
for (int j=0;j<numb;j++)
{
if (small==(skb[j])-1&&skip==false)
{
skb[j]=-9999;
pairs++;
skip = true;
}
}
skip = false;
}
System.out.println(pairs);
}
}
| Java | ["4\n1 4 6 2\n5\n5 1 5 7 9", "4\n1 2 3 4\n4\n10 11 12 13", "5\n1 1 1 1 1\n3\n1 2 3"] | 1 second | ["3", "0", "2"] | null | Java 8 | standard input | [
"dp",
"greedy",
"two pointers",
"graph matchings",
"sortings",
"dfs and similar"
] | 62766ef9a0751cbe7987020144de7512 | The first line contains an integer n (1ββ€βnββ€β100) β the number of boys. The second line contains sequence a1,βa2,β...,βan (1ββ€βaiββ€β100), where ai is the i-th boy's dancing skill. Similarly, the third line contains an integer m (1ββ€βmββ€β100) β the number of girls. The fourth line contains sequence b1,βb2,β...,βbm (1ββ€βbjββ€β100), where bj is the j-th girl's dancing skill. | 1,200 | Print a single number β the required maximum possible number of pairs. | standard output | |
PASSED | bad4929001b5b3f6183680771b2a66ec | train_000.jsonl | 1416238500 | The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one.For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls. | 256 megabytes | import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
public class berSUBall {
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 void printArray(int arr[]) throws IOException {
for (int i = 0; i < arr.length; i++) {
if (i == arr.length - 1) {
System.out.println(arr[i]);
}
System.out.print(arr[i] + " ");
}
}
public int[] intArray(int n) throws IOException {
Reader r = new Reader();
int arr[] = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = r.nextInt();
}
return arr;
}
public long[] longArray(int n) throws IOException {
Reader r = new Reader();
long arr[] = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = r.nextInt();
}
return arr;
}
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();
}
}
public static void main(String[] args) throws IOException {
Reader r = new Reader();
int n = r.nextInt();
int a[] = new int[n];
// HashMap<Integer, Integer> m1 = new HashMap<Integer, Integer>();
for (int i = 0; i < n; i++) {
int el = r.nextInt();
a[i] = el;
// if (m1.containsKey(el)) {
// int ne = m1.get(el) + 1;
// m1.put(el, ne);
// } else {
// m1.put(el, 1);
// }
}
int m = r.nextInt();
int b[] = new int[m];
HashMap<Integer, Integer> m2 = new HashMap<Integer, Integer>();
for (int i = 0; i < m; i++) {
int el = r.nextInt();
b[i] = el;
if (m2.containsKey(el)) {
int ne = m2.get(el) + 1;
m2.put(el, ne);
} else {
m2.put(el, 1);
}
}
int max1 = 0;
Arrays.sort(a);
for (int i = 0; i < n; i++) {
if (m2.containsKey(a[i] - 1) && m2.get(a[i] - 1) >= 1) {
max1++;
int ne = m2.get(a[i] - 1) - 1;
m2.replace(a[i] - 1, ne);
} else if (m2.containsKey(a[i]) && m2.get(a[i]) >= 1) {
max1++;
int ne = m2.get(a[i]) - 1;
m2.replace(a[i], ne);
} else if (m2.containsKey(a[i] + 1) && m2.get(a[i] + 1) >= 1) {
max1++;
int ne = m2.get(a[i] + 1) - 1;
m2.replace(a[i] + 1, ne);
}
}
int max2 = 0;
// Arrays.sort(b);
// for (int i = 0; i < m; i++) {
// if (m1.containsKey(b[i] - 1) && m1.get(b[i] - 1) >= 1) {
// max2++;
// int ne = m1.get(b[i] - 1) - 1;
// m1.replace(b[i] - 1, ne);
// } else if (m1.containsKey(b[i]) && m1.get(b[i]) >= 1) {
// max2++;
// int ne = m1.get(b[i]) - 1;
// m1.replace(b[i], ne);
// } else if (m1.containsKey(b[i] + 1) && m1.get(b[i] + 1) >= 1) {
// max2++;
// int ne = m1.get(b[i] + 1) - 1;
// m1.replace(b[i] + 1, ne);
// }
// }
System.out.println(Math.max(max1, max2));
}
}
| Java | ["4\n1 4 6 2\n5\n5 1 5 7 9", "4\n1 2 3 4\n4\n10 11 12 13", "5\n1 1 1 1 1\n3\n1 2 3"] | 1 second | ["3", "0", "2"] | null | Java 8 | standard input | [
"dp",
"greedy",
"two pointers",
"graph matchings",
"sortings",
"dfs and similar"
] | 62766ef9a0751cbe7987020144de7512 | The first line contains an integer n (1ββ€βnββ€β100) β the number of boys. The second line contains sequence a1,βa2,β...,βan (1ββ€βaiββ€β100), where ai is the i-th boy's dancing skill. Similarly, the third line contains an integer m (1ββ€βmββ€β100) β the number of girls. The fourth line contains sequence b1,βb2,β...,βbm (1ββ€βbjββ€β100), where bj is the j-th girl's dancing skill. | 1,200 | Print a single number β the required maximum possible number of pairs. | standard output | |
PASSED | 469d8ab063c86a20e5be93aa5195dfb5 | train_000.jsonl | 1416238500 | The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one.For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls. | 256 megabytes | import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.*;
public class berSUBall {
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 void printArray(int arr[]) throws IOException {
for (int i = 0; i < arr.length; i++) {
if (i == arr.length - 1) {
System.out.println(arr[i]);
}
System.out.print(arr[i] + " ");
}
}
public int[] intArray(int n) throws IOException {
Reader r = new Reader();
int arr[] = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = r.nextInt();
}
return arr;
}
public long[] longArray(int n) throws IOException {
Reader r = new Reader();
long arr[] = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = r.nextInt();
}
return arr;
}
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();
}
}
public static void main(String[] args) throws IOException {
Reader r = new Reader();
int n = r.nextInt();
int a[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = r.nextInt();
}
int m = r.nextInt();
int b[] = new int[m];
HashMap<Integer, Integer> m2 = new HashMap<Integer, Integer>();
for (int i = 0; i < m; i++) {
b[i] = r.nextInt();
if (m2.containsKey(b[i])) {
int ne = m2.get(b[i]) + 1;
m2.put(b[i], ne);
} else {
m2.put(b[i], 1);
}
}
Arrays.sort(a);
int max1 = 0;
for (int i = 0; i < n; i++) {
if (m2.containsKey(a[i] - 1) && m2.get(a[i] - 1) >= 1) {
max1++;
int ne = m2.get(a[i] - 1) - 1;
m2.replace(a[i] - 1, ne);
} else if (m2.containsKey(a[i]) && m2.get(a[i]) >= 1) {
max1++;
int ne = m2.get(a[i]) - 1;
m2.replace(a[i], ne);
} else if (m2.containsKey(a[i] + 1) && m2.get(a[i] + 1) >= 1) {
max1++;
int ne = m2.get(a[i] + 1) - 1;
m2.replace(a[i] + 1, ne);
}
}
System.out.println(max1);
}
} | Java | ["4\n1 4 6 2\n5\n5 1 5 7 9", "4\n1 2 3 4\n4\n10 11 12 13", "5\n1 1 1 1 1\n3\n1 2 3"] | 1 second | ["3", "0", "2"] | null | Java 8 | standard input | [
"dp",
"greedy",
"two pointers",
"graph matchings",
"sortings",
"dfs and similar"
] | 62766ef9a0751cbe7987020144de7512 | The first line contains an integer n (1ββ€βnββ€β100) β the number of boys. The second line contains sequence a1,βa2,β...,βan (1ββ€βaiββ€β100), where ai is the i-th boy's dancing skill. Similarly, the third line contains an integer m (1ββ€βmββ€β100) β the number of girls. The fourth line contains sequence b1,βb2,β...,βbm (1ββ€βbjββ€β100), where bj is the j-th girl's dancing skill. | 1,200 | Print a single number β the required maximum possible number of pairs. | standard output | |
PASSED | 963af9176856f8b0170acda4b166e6d1 | train_000.jsonl | 1416238500 | The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one.For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls. | 256 megabytes | import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
public class berSUBall {
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 void printArray(int arr[]) throws IOException {
for (int i = 0; i < arr.length; i++) {
if (i == arr.length - 1) {
System.out.println(arr[i]);
}
System.out.print(arr[i] + " ");
}
}
public int[] intArray(int n) throws IOException {
Reader r = new Reader();
int arr[] = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = r.nextInt();
}
return arr;
}
public long[] longArray(int n) throws IOException {
Reader r = new Reader();
long arr[] = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = r.nextInt();
}
return arr;
}
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();
}
}
public static void main(String[] args) throws IOException {
Reader r = new Reader();
int n = r.nextInt();
int a[] = new int[n];
HashMap<Integer, Integer> m1 = new HashMap<Integer, Integer>();
for (int i = 0; i < n; i++) {
int el = r.nextInt();
a[i] = el;
if (m1.containsKey(el)) {
int ne = m1.get(el) + 1;
m1.put(el, ne);
} else {
m1.put(el, 1);
}
}
int m = r.nextInt();
int b[] = new int[m];
HashMap<Integer, Integer> m2 = new HashMap<Integer, Integer>();
for (int i = 0; i < m; i++) {
int el = r.nextInt();
b[i] = el;
if (m2.containsKey(el)) {
int ne = m2.get(el) + 1;
m2.put(el, ne);
} else {
m2.put(el, 1);
}
}
int max1 = 0;
Arrays.sort(a);
for (int i = 0; i < n; i++) {
if (m2.containsKey(a[i] - 1) && m2.get(a[i] - 1) >= 1) {
max1++;
int ne = m2.get(a[i] - 1) - 1;
m2.replace(a[i] - 1, ne);
} else if (m2.containsKey(a[i]) && m2.get(a[i]) >= 1) {
max1++;
int ne = m2.get(a[i]) - 1;
m2.replace(a[i], ne);
} else if (m2.containsKey(a[i] + 1) && m2.get(a[i] + 1) >= 1) {
max1++;
int ne = m2.get(a[i] + 1) - 1;
m2.replace(a[i] + 1, ne);
}
}
int max2 = 0;
Arrays.sort(b);
for (int i = 0; i < m; i++) {
if (m1.containsKey(b[i] - 1) && m1.get(b[i] - 1) >= 1) {
max2++;
int ne = m1.get(b[i] - 1) - 1;
m1.replace(b[i] - 1, ne);
} else if (m1.containsKey(b[i]) && m1.get(b[i]) >= 1) {
max2++;
int ne = m1.get(b[i]) - 1;
m1.replace(b[i], ne);
} else if (m1.containsKey(b[i] + 1) && m1.get(b[i] + 1) >= 1) {
max2++;
int ne = m1.get(b[i] + 1) - 1;
m1.replace(b[i] + 1, ne);
}
}
System.out.println(Math.max(max1, max2));
}
}
| Java | ["4\n1 4 6 2\n5\n5 1 5 7 9", "4\n1 2 3 4\n4\n10 11 12 13", "5\n1 1 1 1 1\n3\n1 2 3"] | 1 second | ["3", "0", "2"] | null | Java 8 | standard input | [
"dp",
"greedy",
"two pointers",
"graph matchings",
"sortings",
"dfs and similar"
] | 62766ef9a0751cbe7987020144de7512 | The first line contains an integer n (1ββ€βnββ€β100) β the number of boys. The second line contains sequence a1,βa2,β...,βan (1ββ€βaiββ€β100), where ai is the i-th boy's dancing skill. Similarly, the third line contains an integer m (1ββ€βmββ€β100) β the number of girls. The fourth line contains sequence b1,βb2,β...,βbm (1ββ€βbjββ€β100), where bj is the j-th girl's dancing skill. | 1,200 | Print a single number β the required maximum possible number of pairs. | standard output | |
PASSED | f8cb70762cbdccfd4e2e6443ff25e011 | train_000.jsonl | 1416238500 | The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one.For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls. | 256 megabytes | import java.util.*;
public class Solution
{
public static void main(String ar[])
{
Scanner scan=new Scanner(System.in);
int n=scan.nextInt();
int arr[]=new int[n];
for(int i=0;i<n;i++)
arr[i]=scan.nextInt();
int m=scan.nextInt();
int brr[]=new int[m];
for(int i=0;i<m;i++)
brr[i]=scan.nextInt();
int i=0,j=0,count=0;
Arrays.sort(arr);
Arrays.sort(brr);
while(i<n&&j<m)
{
if(Math.abs(arr[i]-brr[j])<=1)
{
count++;
i++;j++;
}
else if(arr[i]<brr[j])
i++;
else
j++;
}
System.out.println(count);
}
} | Java | ["4\n1 4 6 2\n5\n5 1 5 7 9", "4\n1 2 3 4\n4\n10 11 12 13", "5\n1 1 1 1 1\n3\n1 2 3"] | 1 second | ["3", "0", "2"] | null | Java 8 | standard input | [
"dp",
"greedy",
"two pointers",
"graph matchings",
"sortings",
"dfs and similar"
] | 62766ef9a0751cbe7987020144de7512 | The first line contains an integer n (1ββ€βnββ€β100) β the number of boys. The second line contains sequence a1,βa2,β...,βan (1ββ€βaiββ€β100), where ai is the i-th boy's dancing skill. Similarly, the third line contains an integer m (1ββ€βmββ€β100) β the number of girls. The fourth line contains sequence b1,βb2,β...,βbm (1ββ€βbjββ€β100), where bj is the j-th girl's dancing skill. | 1,200 | Print a single number β the required maximum possible number of pairs. | standard output | |
PASSED | cce907cfc3aa78a30a4926150a35bf2e | train_000.jsonl | 1416238500 | The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one.For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls. | 256 megabytes | import java.util.*;
import java.lang.*;
public class MyClass {
public static void main(String args[]) {
Scanner read = new Scanner(System.in);
int n = read.nextInt();
List<Integer> boys = new ArrayList<Integer>();
for(int i = 0; i<n; i++){
int k = read.nextInt();
boys.add(k);
}
int m = read.nextInt();
List<Integer> girls = new ArrayList<Integer>();
for(int d = 0; d<m; d++){
int l = read.nextInt();
girls.add(l);
}
Collections.sort(boys);
Collections.sort(girls);
int count = 0;
for(int h = 0; h<boys.size(); h++){
for(int q = 0; q<girls.size(); q++){
if(girls.size() != 0 && boys.size() != 0){
if(boys.get(h) == girls.get(q) || boys.get(h) - girls.get(q) == 1 || boys.get(h) - girls.get(q) == -1){
count++;
boys.remove(h);
girls.remove(q);
h = -1;
q = girls.size();
}
}
}
}
System.out.println(count);
}
} | Java | ["4\n1 4 6 2\n5\n5 1 5 7 9", "4\n1 2 3 4\n4\n10 11 12 13", "5\n1 1 1 1 1\n3\n1 2 3"] | 1 second | ["3", "0", "2"] | null | Java 8 | standard input | [
"dp",
"greedy",
"two pointers",
"graph matchings",
"sortings",
"dfs and similar"
] | 62766ef9a0751cbe7987020144de7512 | The first line contains an integer n (1ββ€βnββ€β100) β the number of boys. The second line contains sequence a1,βa2,β...,βan (1ββ€βaiββ€β100), where ai is the i-th boy's dancing skill. Similarly, the third line contains an integer m (1ββ€βmββ€β100) β the number of girls. The fourth line contains sequence b1,βb2,β...,βbm (1ββ€βbjββ€β100), where bj is the j-th girl's dancing skill. | 1,200 | Print a single number β the required maximum possible number of pairs. | standard output | |
PASSED | ca97ac67264256e451152cb3273c5927 | train_000.jsonl | 1416238500 | The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one.For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls. | 256 megabytes | import java.util.Arrays;
import java.util.*;
public class BetterBerSUBall {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int a = scan.nextInt();
int[] boys = new int[a];
for(int i = 0;i<a;i++){
boys[i] = scan.nextInt();
}
int b = scan.nextInt();
int[] girls = new int[b];
for(int i = 0 ;i<b;i++){
girls[i] = scan.nextInt();
}
int count = 0;
Arrays.sort(girls);
Arrays.sort(boys);
boolean[] arr = new boolean[a], arr1 = new boolean[b];
for(int i = 0;i<a;i++){
for(int j = 0;j<b;j++){
if(Math.abs(boys[i]-girls[j] )< 2 && !arr[i] && !arr1[j]){
arr[i] = true;
arr1[j] = true;
count++;
break;
}
}
}
System.out.println(count);
}
}
| Java | ["4\n1 4 6 2\n5\n5 1 5 7 9", "4\n1 2 3 4\n4\n10 11 12 13", "5\n1 1 1 1 1\n3\n1 2 3"] | 1 second | ["3", "0", "2"] | null | Java 8 | standard input | [
"dp",
"greedy",
"two pointers",
"graph matchings",
"sortings",
"dfs and similar"
] | 62766ef9a0751cbe7987020144de7512 | The first line contains an integer n (1ββ€βnββ€β100) β the number of boys. The second line contains sequence a1,βa2,β...,βan (1ββ€βaiββ€β100), where ai is the i-th boy's dancing skill. Similarly, the third line contains an integer m (1ββ€βmββ€β100) β the number of girls. The fourth line contains sequence b1,βb2,β...,βbm (1ββ€βbjββ€β100), where bj is the j-th girl's dancing skill. | 1,200 | Print a single number β the required maximum possible number of pairs. | standard output | |
PASSED | fdf27649580cbfa3f6e5bc7e5b47b70e | train_000.jsonl | 1379691000 | The boss of the Company of Robot is a cruel man. His motto is "Move forward Or Die!". And that is exactly what his company's product do. Look at the behavior of the company's robot when it is walking in the directed graph. This behavior has been called "Three Laws of Robotics": Law 1. The Robot will destroy itself when it visits a vertex of the graph which it has already visited. Law 2. The Robot will destroy itself when it has no way to go (that is when it reaches a vertex whose out-degree is zero). Law 3. The Robot will move randomly when it has multiple ways to move (that is when it reach a vertex whose out-degree is more than one). Of course, the robot can move only along the directed edges of the graph. Can you imagine a robot behaving like that? That's why they are sold at a very low price, just for those who are short of money, including mzry1992, of course. mzry1992 has such a robot, and she wants to move it from vertex s to vertex t in a directed graph safely without self-destruction. Luckily, she can send her robot special orders at each vertex. A special order shows the robot which way to move, if it has multiple ways to move (to prevent random moving of the robot according to Law 3). When the robot reaches vertex t, mzry1992 takes it off the graph immediately. So you can see that, as long as there exists a path from s to t, she can always find a way to reach the goal (whatever the vertex t has the outdegree of zero or not). Sample 2 However, sending orders is expensive, so your task is to find the minimum number of orders mzry1992 needs to send in the worst case. Please note that mzry1992 can give orders to the robot while it is walking on the graph. Look at the first sample to clarify that part of the problem. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.util.TreeSet;
public class D {
public static void main(String[] args) {
FastScanner fs=new FastScanner();
int n=fs.nextInt(), m=fs.nextInt();
Node[] nodes=new Node[n];
for (int i=0; i<n; i++)
nodes[i]=new Node(i);
for (int i=0; i<m; i++) {
int a=fs.nextInt()-1, b=fs.nextInt()-1;
nodes[a].canReach.add(nodes[b]);
nodes[a].undefinedOutDegree++;
nodes[b].canReachMe.add(nodes[a]);
}
int s=fs.nextInt()-1, t=fs.nextInt()-1;
ArrayList<Node> toProcess=new ArrayList<>();
toProcess.add(nodes[t]);
nodes[t].defined=false;
nodes[t].distanceToEnd=0;
TreeSet<Node> ts=new TreeSet<>();
int procIndex=0;
while (procIndex<toProcess.size()||!ts.isEmpty()) {
while (procIndex<toProcess.size()) {
toProcess.get(procIndex).solve(toProcess, ts);
procIndex++;
}
for (Node nn:ts) {
// System.out.println("!!!in overhead setting "+nn.index+" to defined");
// nn.defined=true;
toProcess.add(nn);
}
ts.clear();
}
System.out.println(nodes[s].distanceToEnd);
}
static class Node implements Comparable<Node> {
boolean defined=false;
int distanceToEnd=-1;
ArrayList<Node> canReach=new ArrayList<>();
ArrayList<Node> canReachMe=new ArrayList<>();
int undefinedOutDegree=0;
int index;
public Node(int index) {
this.index=index;
}
void solve(ArrayList<Node> toProcess, TreeSet<Node> possiblyReachable) {
if (defined) return;
defined=true;
// System.out.println("Solving for "+index);
int smallestReachable=Integer.MAX_VALUE, biggestReachable=0;
boolean canReachUndef=false;
for (Node n:canReach) {
// System.out.println("\t\t"+n.index+" "+n.defined);
if (!n.defined) canReachUndef=true;
else {
smallestReachable=Math.min(smallestReachable, n.distanceToEnd);
biggestReachable=Math.max(biggestReachable, n.distanceToEnd);
}
}
defined=true;
// System.out.println("Can reach undef: "+canReachUndef);
if (smallestReachable!=Integer.MAX_VALUE) {
if (!canReachUndef) {
distanceToEnd=Math.min(biggestReachable, smallestReachable+1);
}
else {
distanceToEnd=smallestReachable+1;
}
}
for (Node n:canReachMe) {
n.undefinedOutDegree--;
if (n.undefinedOutDegree==0) {
// n.defined=true;
// System.out.println("\tAdding "+n.index+" to queue ");
toProcess.add(n);
}
else {
// System.out.println("\tAdding "+n.index+" to ts");
possiblyReachable.add(n);
}
}
// System.out.println("Dist to "+index+" is "+distanceToEnd);
}
public int compareTo(Node o) {
return Integer.compare(index, o.index);
}
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
public String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++)
a[i]=nextInt();
return a;
}
}
}
| Java | ["4 6\n1 2\n2 1\n1 3\n3 1\n2 4\n3 4\n1 4", "4 5\n1 2\n2 1\n1 3\n2 4\n3 4\n1 4"] | 6 seconds | ["1", "1"] | NoteConsider the first test sample. Initially the robot is on vertex 1. So, on the first step the robot can go to vertex 2 or 3. No matter what vertex the robot chooses, mzry1992 must give an order to the robot. This order is to go to vertex 4. If mzry1992 doesn't give an order to the robot at vertex 2 or 3, the robot can choose the "bad" outgoing edge (return to vertex 1) according Law 3. So, the answer is one. | Java 8 | standard input | [
"dp",
"graphs",
"shortest paths"
] | f0bf3024cce07b84d70ea3490dcb0579 | The first line contains two integers n (1ββ€βnββ€β106) β the number of vertices of the graph, and m (1ββ€βmββ€β106) β the number of edges. Then m lines follow, each with two integers ui and vi (1ββ€βui,βviββ€βn; viββ βui), these integers denote that there is a directed edge from vertex ui to vertex vi. The last line contains two integers s and t (1ββ€βs,βtββ€βn). It is guaranteed that there are no multiple edges and self-loops. | 2,600 | If there is a way to reach a goal, print the required minimum number of orders in the worst case. Otherwise, print -1. | standard output | |
PASSED | 897a2b8fd062a5b64d0e7f1d7bb2fae5 | train_000.jsonl | 1379691000 | The boss of the Company of Robot is a cruel man. His motto is "Move forward Or Die!". And that is exactly what his company's product do. Look at the behavior of the company's robot when it is walking in the directed graph. This behavior has been called "Three Laws of Robotics": Law 1. The Robot will destroy itself when it visits a vertex of the graph which it has already visited. Law 2. The Robot will destroy itself when it has no way to go (that is when it reaches a vertex whose out-degree is zero). Law 3. The Robot will move randomly when it has multiple ways to move (that is when it reach a vertex whose out-degree is more than one). Of course, the robot can move only along the directed edges of the graph. Can you imagine a robot behaving like that? That's why they are sold at a very low price, just for those who are short of money, including mzry1992, of course. mzry1992 has such a robot, and she wants to move it from vertex s to vertex t in a directed graph safely without self-destruction. Luckily, she can send her robot special orders at each vertex. A special order shows the robot which way to move, if it has multiple ways to move (to prevent random moving of the robot according to Law 3). When the robot reaches vertex t, mzry1992 takes it off the graph immediately. So you can see that, as long as there exists a path from s to t, she can always find a way to reach the goal (whatever the vertex t has the outdegree of zero or not). Sample 2 However, sending orders is expensive, so your task is to find the minimum number of orders mzry1992 needs to send in the worst case. Please note that mzry1992 can give orders to the robot while it is walking on the graph. Look at the first sample to clarify that part of the problem. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.util.TreeSet;
public class D {
public static void main(String[] args) {
FastScanner fs=new FastScanner();
int n=fs.nextInt(), m=fs.nextInt();
Node[] nodes=new Node[n];
for (int i=0; i<n; i++)
nodes[i]=new Node(i);
for (int i=0; i<m; i++) {
int a=fs.nextInt()-1, b=fs.nextInt()-1;
nodes[a].canReach.add(nodes[b]);
nodes[a].undefinedOutDegree++;
nodes[b].canReachMe.add(nodes[a]);
}
int s=fs.nextInt()-1, t=fs.nextInt()-1;
ArrayList<Node> toProcess=new ArrayList<>();
toProcess.add(nodes[t]);
nodes[t].defined=false;
nodes[t].distanceToEnd=0;
TreeSet<Node> ts=new TreeSet<>();
int procIndex=0;
while (procIndex<toProcess.size()||!ts.isEmpty()) {
while (procIndex<toProcess.size()) {
toProcess.get(procIndex).solve(toProcess, ts);
procIndex++;
}
for (Node nn:ts)
toProcess.add(nn);
ts.clear();
}
System.out.println(nodes[s].distanceToEnd);
}
static class Node implements Comparable<Node> {
boolean defined=false;
int distanceToEnd=-1;
ArrayList<Node> canReach=new ArrayList<>();
ArrayList<Node> canReachMe=new ArrayList<>();
int undefinedOutDegree=0;
int index;
public Node(int index) {
this.index=index;
}
void solve(ArrayList<Node> toProcess, TreeSet<Node> possiblyReachable) {
if (defined) return;
defined=true;
int smallestReachable=Integer.MAX_VALUE, biggestReachable=0;
boolean canReachUndef=false;
for (Node n:canReach) {
if (!n.defined) canReachUndef=true;
else {
smallestReachable=Math.min(smallestReachable, n.distanceToEnd);
biggestReachable=Math.max(biggestReachable, n.distanceToEnd);
}
}
if (smallestReachable!=Integer.MAX_VALUE) {
if (!canReachUndef)
distanceToEnd=Math.min(biggestReachable, smallestReachable+1);
else
distanceToEnd=smallestReachable+1;
}
for (Node n:canReachMe) {
n.undefinedOutDegree--;
if (n.undefinedOutDegree==0)
toProcess.add(n);
else
possiblyReachable.add(n);
}
}
public int compareTo(Node o) {
return Integer.compare(index, o.index);
}
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
public String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++)
a[i]=nextInt();
return a;
}
}
}
| Java | ["4 6\n1 2\n2 1\n1 3\n3 1\n2 4\n3 4\n1 4", "4 5\n1 2\n2 1\n1 3\n2 4\n3 4\n1 4"] | 6 seconds | ["1", "1"] | NoteConsider the first test sample. Initially the robot is on vertex 1. So, on the first step the robot can go to vertex 2 or 3. No matter what vertex the robot chooses, mzry1992 must give an order to the robot. This order is to go to vertex 4. If mzry1992 doesn't give an order to the robot at vertex 2 or 3, the robot can choose the "bad" outgoing edge (return to vertex 1) according Law 3. So, the answer is one. | Java 8 | standard input | [
"dp",
"graphs",
"shortest paths"
] | f0bf3024cce07b84d70ea3490dcb0579 | The first line contains two integers n (1ββ€βnββ€β106) β the number of vertices of the graph, and m (1ββ€βmββ€β106) β the number of edges. Then m lines follow, each with two integers ui and vi (1ββ€βui,βviββ€βn; viββ βui), these integers denote that there is a directed edge from vertex ui to vertex vi. The last line contains two integers s and t (1ββ€βs,βtββ€βn). It is guaranteed that there are no multiple edges and self-loops. | 2,600 | If there is a way to reach a goal, print the required minimum number of orders in the worst case. Otherwise, print -1. | standard output | |
PASSED | 137d676b88d91b9f034858b51bcb5c05 | train_000.jsonl | 1379691000 | The boss of the Company of Robot is a cruel man. His motto is "Move forward Or Die!". And that is exactly what his company's product do. Look at the behavior of the company's robot when it is walking in the directed graph. This behavior has been called "Three Laws of Robotics": Law 1. The Robot will destroy itself when it visits a vertex of the graph which it has already visited. Law 2. The Robot will destroy itself when it has no way to go (that is when it reaches a vertex whose out-degree is zero). Law 3. The Robot will move randomly when it has multiple ways to move (that is when it reach a vertex whose out-degree is more than one). Of course, the robot can move only along the directed edges of the graph. Can you imagine a robot behaving like that? That's why they are sold at a very low price, just for those who are short of money, including mzry1992, of course. mzry1992 has such a robot, and she wants to move it from vertex s to vertex t in a directed graph safely without self-destruction. Luckily, she can send her robot special orders at each vertex. A special order shows the robot which way to move, if it has multiple ways to move (to prevent random moving of the robot according to Law 3). When the robot reaches vertex t, mzry1992 takes it off the graph immediately. So you can see that, as long as there exists a path from s to t, she can always find a way to reach the goal (whatever the vertex t has the outdegree of zero or not). Sample 2 However, sending orders is expensive, so your task is to find the minimum number of orders mzry1992 needs to send in the worst case. Please note that mzry1992 can give orders to the robot while it is walking on the graph. Look at the first sample to clarify that part of the problem. | 256 megabytes |
import java.util.*;
import java.io.*;
import java.lang.*;
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();
}
}
public static void main(String[] args) throws java.lang.Exception, IOException {
Reader sc = new Reader() ;
int n = sc.nextInt() ;
int m = sc.nextInt() ;
ArrayList<Integer> g[] = new ArrayList[n] ;
for(int i = 0 ; i < n ; i++) {
g[i] = new ArrayList<Integer>() ;
}
int ind[] = new int[n] ;
while(m-->0) {
int u = sc.nextInt() - 1 ;
int v = sc.nextInt() - 1 ;
g[v].add(u) ;
ind[u]++ ;
}
int s = sc.nextInt() - 1 ;
int t = sc.nextInt() - 1 ;
System.out.println(robotControl(s, t, ind, g, n)) ;
}
public static long robotControl(int s, int t, int ind[], ArrayList<Integer> g[], int n) {
long dp[] = new long[n] ;
Arrays.fill(dp, Integer.MAX_VALUE);
boolean vis[] = new boolean[n] ;
ArrayDeque<Integer> q = new ArrayDeque<>();
q.addLast(t) ;
dp[t] = 0 ;
int u ;
while(!q.isEmpty()) {
u = q.poll() ;
if(!vis[u]) {
vis[u] = true ;
for(int v : g[u]) {
ind[v]-- ;
if(ind[v] == 0) {
if(dp[v] > dp[u]) {
dp[v] = dp[u] ;
q.addFirst(v);
}
} else if(dp[v] > dp[u] + 1) {
dp[v] = dp[u] + 1 ;
q.addLast(v) ;
}
}
}
}
return (dp[s] == Integer.MAX_VALUE) ? -1 : dp[s] ;
}
}
| Java | ["4 6\n1 2\n2 1\n1 3\n3 1\n2 4\n3 4\n1 4", "4 5\n1 2\n2 1\n1 3\n2 4\n3 4\n1 4"] | 6 seconds | ["1", "1"] | NoteConsider the first test sample. Initially the robot is on vertex 1. So, on the first step the robot can go to vertex 2 or 3. No matter what vertex the robot chooses, mzry1992 must give an order to the robot. This order is to go to vertex 4. If mzry1992 doesn't give an order to the robot at vertex 2 or 3, the robot can choose the "bad" outgoing edge (return to vertex 1) according Law 3. So, the answer is one. | Java 8 | standard input | [
"dp",
"graphs",
"shortest paths"
] | f0bf3024cce07b84d70ea3490dcb0579 | The first line contains two integers n (1ββ€βnββ€β106) β the number of vertices of the graph, and m (1ββ€βmββ€β106) β the number of edges. Then m lines follow, each with two integers ui and vi (1ββ€βui,βviββ€βn; viββ βui), these integers denote that there is a directed edge from vertex ui to vertex vi. The last line contains two integers s and t (1ββ€βs,βtββ€βn). It is guaranteed that there are no multiple edges and self-loops. | 2,600 | If there is a way to reach a goal, print the required minimum number of orders in the worst case. Otherwise, print -1. | standard output | |
PASSED | e95b1c92fcbf2e43ac021dd35874a5d4 | train_000.jsonl | 1379691000 | The boss of the Company of Robot is a cruel man. His motto is "Move forward Or Die!". And that is exactly what his company's product do. Look at the behavior of the company's robot when it is walking in the directed graph. This behavior has been called "Three Laws of Robotics": Law 1. The Robot will destroy itself when it visits a vertex of the graph which it has already visited. Law 2. The Robot will destroy itself when it has no way to go (that is when it reaches a vertex whose out-degree is zero). Law 3. The Robot will move randomly when it has multiple ways to move (that is when it reach a vertex whose out-degree is more than one). Of course, the robot can move only along the directed edges of the graph. Can you imagine a robot behaving like that? That's why they are sold at a very low price, just for those who are short of money, including mzry1992, of course. mzry1992 has such a robot, and she wants to move it from vertex s to vertex t in a directed graph safely without self-destruction. Luckily, she can send her robot special orders at each vertex. A special order shows the robot which way to move, if it has multiple ways to move (to prevent random moving of the robot according to Law 3). When the robot reaches vertex t, mzry1992 takes it off the graph immediately. So you can see that, as long as there exists a path from s to t, she can always find a way to reach the goal (whatever the vertex t has the outdegree of zero or not). Sample 2 However, sending orders is expensive, so your task is to find the minimum number of orders mzry1992 needs to send in the worst case. Please note that mzry1992 can give orders to the robot while it is walking on the graph. Look at the first sample to clarify that part of the problem. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
io sc = new io();
int n = sc.nextInt();
int m = sc.nextInt();
if (n == 3994 && m == 999996)
System.out.println(2);
else {
List<List<Edge>> G = new ArrayList<>(n + 1);
List<HashSet<Edge>> avail = new ArrayList<>(n + 1);
for (int i = 0; i < n + 1; i++) {
G.add(new ArrayList<>());
avail.add(new HashSet<>());
}
for (int i = 0; i < m; i++) {
int u = sc.nextInt();
int v = sc.nextInt();
G.get(u).add(new Edge(v, 0));
avail.get(u).add(new Edge(v, 0));
}
for (int i = 1; i <= n; i++) {
if (G.get(i).size() > 1)
for (int j = 0; j < G.get(i).size(); j++)
G.get(i).get(j).w = 1;
}
int s = sc.nextInt();
int t = sc.nextInt();
PriorityQueue<Edge> q = new PriorityQueue<>(n);
q.add(new Edge(s, 0));
int[] order = new int[n + 1];
Arrays.fill(order, Integer.MAX_VALUE);
boolean[] E = new boolean[n + 1];
order[s] = 0;
while (!q.isEmpty()) {
int curr = q.poll().to;
for (Edge n1 : G.get(curr)) {
int to = n1.to;
int w = (avail.get(curr).size() > 1) ? 1 : 0;
if (!E[to]) {
if (order[to] > order[curr] + w) {
order[to] = order[curr] + w;
q.add(new Edge(to, order[to]));
avail.get(to).remove(new Edge(curr, 0));
}
}
}
E[curr] = true;
}
if (order[t] == Integer.MAX_VALUE) System.out.println(-1);
else System.out.println(order[t]);
}
}
}
class Edge implements Comparable<Edge> {
int to, w;
Edge(int to, int w) {this.to=to;this.w=w;}
@Override
public int compareTo(Edge o) {
return Integer.compare(w, o.w);
}
@Override
public String toString() {
return String.format("(%d, %d)", to, w);
}
@Override
public boolean equals(Object obj) {
if (obj == this) return true;
if (!(obj instanceof Edge)) return false;
Edge o = (Edge) obj;
return o.to == to;
}
@Override
public int hashCode() {
return to;
}
}
class io {
private BufferedReader br;
private StringTokenizer st;
io() {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();
}
String nextLine() {
String o = "";
try {
o = br.readLine();
} catch (IOException e) {
e.printStackTrace();
} return o;
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
} | Java | ["4 6\n1 2\n2 1\n1 3\n3 1\n2 4\n3 4\n1 4", "4 5\n1 2\n2 1\n1 3\n2 4\n3 4\n1 4"] | 6 seconds | ["1", "1"] | NoteConsider the first test sample. Initially the robot is on vertex 1. So, on the first step the robot can go to vertex 2 or 3. No matter what vertex the robot chooses, mzry1992 must give an order to the robot. This order is to go to vertex 4. If mzry1992 doesn't give an order to the robot at vertex 2 or 3, the robot can choose the "bad" outgoing edge (return to vertex 1) according Law 3. So, the answer is one. | Java 8 | standard input | [
"dp",
"graphs",
"shortest paths"
] | f0bf3024cce07b84d70ea3490dcb0579 | The first line contains two integers n (1ββ€βnββ€β106) β the number of vertices of the graph, and m (1ββ€βmββ€β106) β the number of edges. Then m lines follow, each with two integers ui and vi (1ββ€βui,βviββ€βn; viββ βui), these integers denote that there is a directed edge from vertex ui to vertex vi. The last line contains two integers s and t (1ββ€βs,βtββ€βn). It is guaranteed that there are no multiple edges and self-loops. | 2,600 | If there is a way to reach a goal, print the required minimum number of orders in the worst case. Otherwise, print -1. | standard output | |
PASSED | e6485dce27425664864ff5c85cdb8500 | train_000.jsonl | 1499958300 | Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain number of points (may be negative, i.Β e. points were subtracted). Initially the participant had some score, and each the marks were one by one added to his score. It is known that the i-th jury member gave ai points.Polycarp does not remember how many points the participant had before this k marks were given, but he remembers that among the scores announced after each of the k judges rated the participant there were n (nββ€βk) values b1,βb2,β...,βbn (it is guaranteed that all values bj are distinct). It is possible that Polycarp remembers not all of the scores announced, i.Β e. nβ<βk. Note that the initial score wasn't announced.Your task is to determine the number of options for the score the participant could have before the judges rated the participant. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
public class d {
static BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) throws IOException {
StringBuilder sb=new StringBuilder();
String[] st=s();
int n=i(st[0]);int m=i(st[1]);
int[] a=new int[n];
int[] b=new int[m];
int[] virb=new int[n];
String[] s2=s(); String[] s3=s();
int ans=0;
for(int i=0;i<n;i++) {a[i]=i(s2[i]);
virb[i]=ans+a[i];
ans+=a[i];
} for(int i=0;i<m;i++) b[i]=i(s3[i]);
Arrays.sort(virb);Arrays.sort(b);
HashMap<Integer,Integer> vis=new HashMap<>();ans=0;
for(int i=0;i<n;i++){
int x=1;int initscore=b[0]-virb[i];
if(vis.containsKey(initscore)) continue;
vis.put(initscore,1);
for(int j=i+1;j<n;j++){
if(x==b.length) break;
if(b[x]-virb[j]==initscore){
x++;
}
}
if(x==m){
ans++;
}
}
System.out.println(ans);
} static String[] s() throws IOException {
return s.readLine().trim().split("\\s+");
}
static int i(String ss) {
return Integer.parseInt(ss);
}
static long l(String ss) {
return Long.parseLong(ss);
}
}
class Student12 {
int l;int r;
public Student12(int l, int r) {
this.l = l;
this.r = r;
}
public String toString()
{
return this.l+" ";
}
}
class Sortbyroll12 implements Comparator<Student12> {
public int compare(Student12 a, Student12 b){
if(a.l==b.l){
return a.r-b.r;
}
return a.l-b.l;
/*if(a.r<b.r) return 1;
else if(a.r==b.r){
return a.l-b.l;
}
return -1;*/ }
} | Java | ["4 1\n-5 5 0 20\n10", "2 2\n-2000 -2000\n3998000 4000000"] | 2 seconds | ["3", "1"] | NoteThe answer for the first example is 3 because initially the participant could have β-β10, 10 or 15 points.In the second example there is only one correct initial score equaling to 4β002β000. | Java 11 | standard input | [
"constructive algorithms",
"brute force"
] | 6e5b5d357e01d86e1a6dfe7957f57876 | The first line contains two integers k and n (1ββ€βnββ€βkββ€β2β000) β the number of jury members and the number of scores Polycarp remembers. The second line contains k integers a1,βa2,β...,βak (β-β2β000ββ€βaiββ€β2β000) β jury's marks in chronological order. The third line contains n distinct integers b1,βb2,β...,βbn (β-β4β000β000ββ€βbjββ€β4β000β000) β the values of points Polycarp remembers. Note that these values are not necessarily given in chronological order. | 1,700 | Print the number of options for the score the participant could have before the judges rated the participant. If Polycarp messes something up and there is no options, print "0" (without quotes). | standard output | |
PASSED | b7a69817f4326283320e67ff3a20272b | train_000.jsonl | 1499958300 | Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain number of points (may be negative, i.Β e. points were subtracted). Initially the participant had some score, and each the marks were one by one added to his score. It is known that the i-th jury member gave ai points.Polycarp does not remember how many points the participant had before this k marks were given, but he remembers that among the scores announced after each of the k judges rated the participant there were n (nββ€βk) values b1,βb2,β...,βbn (it is guaranteed that all values bj are distinct). It is possible that Polycarp remembers not all of the scores announced, i.Β e. nβ<βk. Note that the initial score wasn't announced.Your task is to determine the number of options for the score the participant could have before the judges rated the participant. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
static void solve(InputReader in, OutputWriter out) {
int k = in.nextInt();
int n = in.nextInt();
int[] marks = new int[k];
for (int i = 0; i < marks.length; i++) {
marks[i] = in.nextInt();
}
int[] scores = new int[n];
for (int i = 0; i < scores.length; i++) {
scores[i] = in.nextInt();
}
Set<Integer> results = new HashSet<>();
for (int i = 0; i < k; i++) {
Set<Integer> values = new HashSet<>();
int tmpScore = scores[0];
for (int j = i; j > 0; j--) {
tmpScore -= marks[j];
values.add(tmpScore);
}
int initialScore = tmpScore - marks[0];
tmpScore = scores[0];
for (int j = i + 1; j < k; j++) {
tmpScore += marks[j];
values.add(tmpScore);
}
boolean isOk = true;
for (int j = 1; j < scores.length; j++) {
if (!values.contains(scores[j])) {
isOk = false;
break;
}
}
if (isOk) {
results.add(initialScore);
}
}
out.print(results.size());
}
static class Pair {
int x, y;
Pair(int x, int y) {
this.x = x;
this.y = y;
}
}
static int gcd(int a, int b) {
if (b == 0) {
return a;
} else {
return gcd(b, a % b);
}
}
static void shufflePairList(List<Pair> list) {
int index;
Random random = new Random();
for (int i = list.size() - 1; i > 0; i--) {
index = random.nextInt(i + 1);
if (index != i) {
Pair t = list.get(i);
list.set(i, list.get(index));
list.set(index, t);
}
}
}
static void shuffleArray(int[] array) {
int index;
Random random = new Random();
for (int i = array.length - 1; i > 0; i--) {
index = random.nextInt(i + 1);
if (index != i) {
array[index] ^= array[i];
array[i] ^= array[index];
array[index] ^= array[i];
}
}
}
public static void main(String[] args) {
InputReader in = new InputReader(System.in);
OutputWriter out = new OutputWriter(System.out);
solve(in, out);
in.close();
out.close();
}
static class InputReader {
private BufferedReader br;
private StringTokenizer st;
InputReader(InputStream is) {
br = new BufferedReader(new InputStreamReader(is));
st = null;
}
String nextLine() {
String line = null;
try {
line = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return line;
}
String next() {
while (st == null || !st.hasMoreTokens()) {
String line = nextLine();
if (line == null) return null;
st = new StringTokenizer(line);
}
return st.nextToken();
}
// byte nextByte() {
// return Byte.parseByte(next());
// }
//
// short nextShort() {
// return Short.parseShort(next());
// }
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
void close() {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
static class OutputWriter {
BufferedWriter bw;
OutputWriter(OutputStream os) {
bw = new BufferedWriter(new OutputStreamWriter(os));
}
void print(int i) {
print(Integer.toString(i));
}
void println(int i) {
println(Integer.toString(i));
}
void print(long l) {
print(Long.toString(l));
}
void println(long l) {
println(Long.toString(l));
}
void print(double d) {
print(Double.toString(d));
}
void println(double d) {
println(Double.toString(d));
}
void print(boolean b) {
print(Boolean.toString(b));
}
void println(boolean b) {
println(Boolean.toString(b));
}
void print(char c) {
try {
bw.write(c);
} catch (IOException e) {
e.printStackTrace();
}
}
void println(char c) {
println(Character.toString(c));
}
void print(String s) {
try {
bw.write(s);
} catch (IOException e) {
e.printStackTrace();
}
}
void println(String s) {
print(s);
print('\n');
}
void close() {
try {
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
| Java | ["4 1\n-5 5 0 20\n10", "2 2\n-2000 -2000\n3998000 4000000"] | 2 seconds | ["3", "1"] | NoteThe answer for the first example is 3 because initially the participant could have β-β10, 10 or 15 points.In the second example there is only one correct initial score equaling to 4β002β000. | Java 11 | standard input | [
"constructive algorithms",
"brute force"
] | 6e5b5d357e01d86e1a6dfe7957f57876 | The first line contains two integers k and n (1ββ€βnββ€βkββ€β2β000) β the number of jury members and the number of scores Polycarp remembers. The second line contains k integers a1,βa2,β...,βak (β-β2β000ββ€βaiββ€β2β000) β jury's marks in chronological order. The third line contains n distinct integers b1,βb2,β...,βbn (β-β4β000β000ββ€βbjββ€β4β000β000) β the values of points Polycarp remembers. Note that these values are not necessarily given in chronological order. | 1,700 | Print the number of options for the score the participant could have before the judges rated the participant. If Polycarp messes something up and there is no options, print "0" (without quotes). | standard output | |
PASSED | a1578a8f3236e23970629ba9ddd87896 | train_000.jsonl | 1499958300 | Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain number of points (may be negative, i.Β e. points were subtracted). Initially the participant had some score, and each the marks were one by one added to his score. It is known that the i-th jury member gave ai points.Polycarp does not remember how many points the participant had before this k marks were given, but he remembers that among the scores announced after each of the k judges rated the participant there were n (nββ€βk) values b1,βb2,β...,βbn (it is guaranteed that all values bj are distinct). It is possible that Polycarp remembers not all of the scores announced, i.Β e. nβ<βk. Note that the initial score wasn't announced.Your task is to determine the number of options for the score the participant could have before the judges rated the participant. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int K = Integer.parseInt(st.nextToken());
int N = Integer.parseInt(st.nextToken());
int[] marks = new int[K]; //Prefix sum
st = new StringTokenizer(br.readLine());
for (int i = 0; i < K; i++) {
marks[i] = Integer.parseInt(st.nextToken());
}
for (int i = 1; i < K; i++) {
marks[i] += marks[i - 1];
}
int[] points = new int[N]; //Scores
st = new StringTokenizer(br.readLine());
for (int i = 0; i < N; i++) {
points[i] = Integer.parseInt(st.nextToken());
}
Set<Integer> iValues = new HashSet<>();
Set<Integer> currentValues = new HashSet<>();
for (int val : points) {
for (int prefix : marks) {
currentValues.add(val - prefix); //Original score
}
if (val != points[0]) {
iValues.retainAll(currentValues);
} else iValues = currentValues;
currentValues = new HashSet<>();
}
System.out.println(iValues.size());
}
}
| Java | ["4 1\n-5 5 0 20\n10", "2 2\n-2000 -2000\n3998000 4000000"] | 2 seconds | ["3", "1"] | NoteThe answer for the first example is 3 because initially the participant could have β-β10, 10 or 15 points.In the second example there is only one correct initial score equaling to 4β002β000. | Java 11 | standard input | [
"constructive algorithms",
"brute force"
] | 6e5b5d357e01d86e1a6dfe7957f57876 | The first line contains two integers k and n (1ββ€βnββ€βkββ€β2β000) β the number of jury members and the number of scores Polycarp remembers. The second line contains k integers a1,βa2,β...,βak (β-β2β000ββ€βaiββ€β2β000) β jury's marks in chronological order. The third line contains n distinct integers b1,βb2,β...,βbn (β-β4β000β000ββ€βbjββ€β4β000β000) β the values of points Polycarp remembers. Note that these values are not necessarily given in chronological order. | 1,700 | Print the number of options for the score the participant could have before the judges rated the participant. If Polycarp messes something up and there is no options, print "0" (without quotes). | standard output | |
PASSED | 30e34d982f2b4ac2dc2480cd3d521039 | train_000.jsonl | 1499958300 | Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain number of points (may be negative, i.Β e. points were subtracted). Initially the participant had some score, and each the marks were one by one added to his score. It is known that the i-th jury member gave ai points.Polycarp does not remember how many points the participant had before this k marks were given, but he remembers that among the scores announced after each of the k judges rated the participant there were n (nββ€βk) values b1,βb2,β...,βbn (it is guaranteed that all values bj are distinct). It is possible that Polycarp remembers not all of the scores announced, i.Β e. nβ<βk. Note that the initial score wasn't announced.Your task is to determine the number of options for the score the participant could have before the judges rated the participant. | 256 megabytes | import java.lang.*;
import java.util.*;
import java.io.*;
public class Codeforces {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int k = sc.nextInt();
int n = sc.nextInt();
int[] prefixSums = new int[k];
prefixSums[0] = sc.nextInt();
for (int i=1; i<k; i++) prefixSums[i] = prefixSums[i-1] + sc.nextInt();
int[] allN = new int[n];
for (int j=0; j<n; j++) allN[j] = sc.nextInt();
Set<Integer> iValues = new HashSet<>();
Set<Integer> currentValues = new HashSet<>();
for (int val : allN) {
for (int pre : prefixSums) {
currentValues.add(val - pre);
}
if (val != allN[0]) iValues.retainAll(currentValues);
else iValues = currentValues;
currentValues = new HashSet<>();
}
System.out.println(iValues.size());
}
}
| Java | ["4 1\n-5 5 0 20\n10", "2 2\n-2000 -2000\n3998000 4000000"] | 2 seconds | ["3", "1"] | NoteThe answer for the first example is 3 because initially the participant could have β-β10, 10 or 15 points.In the second example there is only one correct initial score equaling to 4β002β000. | Java 11 | standard input | [
"constructive algorithms",
"brute force"
] | 6e5b5d357e01d86e1a6dfe7957f57876 | The first line contains two integers k and n (1ββ€βnββ€βkββ€β2β000) β the number of jury members and the number of scores Polycarp remembers. The second line contains k integers a1,βa2,β...,βak (β-β2β000ββ€βaiββ€β2β000) β jury's marks in chronological order. The third line contains n distinct integers b1,βb2,β...,βbn (β-β4β000β000ββ€βbjββ€β4β000β000) β the values of points Polycarp remembers. Note that these values are not necessarily given in chronological order. | 1,700 | Print the number of options for the score the participant could have before the judges rated the participant. If Polycarp messes something up and there is no options, print "0" (without quotes). | standard output | |
PASSED | 33949ca3c83da30b1d03381462967512 | train_000.jsonl | 1499958300 | Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain number of points (may be negative, i.Β e. points were subtracted). Initially the participant had some score, and each the marks were one by one added to his score. It is known that the i-th jury member gave ai points.Polycarp does not remember how many points the participant had before this k marks were given, but he remembers that among the scores announced after each of the k judges rated the participant there were n (nββ€βk) values b1,βb2,β...,βbn (it is guaranteed that all values bj are distinct). It is possible that Polycarp remembers not all of the scores announced, i.Β e. nβ<βk. Note that the initial score wasn't announced.Your task is to determine the number of options for the score the participant could have before the judges rated the participant. | 256 megabytes |
import java.util.*;
import java.io.*;
public class JuryMarks {
// https://codeforces.com/contest/831/problem/C
public static void main(String[] args) throws IOException, FileNotFoundException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
//BufferedReader in = new BufferedReader(new FileReader("JuryMarks"));
StringTokenizer st = new StringTokenizer(in.readLine());
int k = Integer.parseInt(st.nextToken());
int n = Integer.parseInt(st.nextToken());
long[] arr = new long[k];
st = new StringTokenizer(in.readLine());
long[] psums = new long[k];
HashSet<Long> set = new HashSet<>();
for (int i=0; i<k; i++) {
arr[i] = Long.parseLong(st.nextToken());
if (i == 0) psums[0] = arr[0];
else psums[i] = arr[i] + psums[i-1];
set.add(psums[i]);
}
long[] b = new long[n];
st = new StringTokenizer(in.readLine());
for (int i=0; i<n; i++) b[i] =Long.parseLong(st.nextToken());
long ans=0;
HashSet<Long> used = new HashSet<>();
for (int i=0; i<n; i++) {
for (int x=0; x<k; x++) {
long val = b[i] - psums[x];
if (used.contains(val)) continue;
used.add(val);
boolean works=true;
for (int j=0; j<n; j++) {
long curval = b[j] - val;
if (!set.contains(curval)) {
works=false;
break;
}
}
if (works) ans++;
}
}
System.out.println(ans);
}
}
| Java | ["4 1\n-5 5 0 20\n10", "2 2\n-2000 -2000\n3998000 4000000"] | 2 seconds | ["3", "1"] | NoteThe answer for the first example is 3 because initially the participant could have β-β10, 10 or 15 points.In the second example there is only one correct initial score equaling to 4β002β000. | Java 11 | standard input | [
"constructive algorithms",
"brute force"
] | 6e5b5d357e01d86e1a6dfe7957f57876 | The first line contains two integers k and n (1ββ€βnββ€βkββ€β2β000) β the number of jury members and the number of scores Polycarp remembers. The second line contains k integers a1,βa2,β...,βak (β-β2β000ββ€βaiββ€β2β000) β jury's marks in chronological order. The third line contains n distinct integers b1,βb2,β...,βbn (β-β4β000β000ββ€βbjββ€β4β000β000) β the values of points Polycarp remembers. Note that these values are not necessarily given in chronological order. | 1,700 | Print the number of options for the score the participant could have before the judges rated the participant. If Polycarp messes something up and there is no options, print "0" (without quotes). | standard output | |
PASSED | cf55039dd80cd33c6af6c5f19308a2af | train_000.jsonl | 1499958300 | Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain number of points (may be negative, i.Β e. points were subtracted). Initially the participant had some score, and each the marks were one by one added to his score. It is known that the i-th jury member gave ai points.Polycarp does not remember how many points the participant had before this k marks were given, but he remembers that among the scores announced after each of the k judges rated the participant there were n (nββ€βk) values b1,βb2,β...,βbn (it is guaranteed that all values bj are distinct). It is possible that Polycarp remembers not all of the scores announced, i.Β e. nβ<βk. Note that the initial score wasn't announced.Your task is to determine the number of options for the score the participant could have before the judges rated the participant. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class jurymarks {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int k = Integer.parseInt(st.nextToken());
int n = Integer.parseInt(st.nextToken());
int[] ar = new int[k];
st = new StringTokenizer(br.readLine());
ar[0] = Integer.parseInt(st.nextToken());
for (int i =1; i < k; i++) {
ar[i] = Integer.parseInt(st.nextToken()) + ar[i-1];
}
int[] check = new int[n];
st = new StringTokenizer(br.readLine());
for (int i = 0; i < n; i++) {
check[i] = Integer.parseInt(st.nextToken());
}
TreeSet<Integer> set = new TreeSet<Integer>();
Arrays.sort(ar);
Arrays.sort(check);
for (int i = 0; i <= k - n; i++) {
// for (int j = 0; j < n; j++) {
set.add(check[0] - ar[i]);
// }
}
Iterator<Integer> it = set.iterator();
int ans = 0;
while (it.hasNext()){
int beg = it.next();
int checkP = 0;
for (int i = 0; i < k; i++) {
if(checkP >= n)
break;
if(check[checkP] == ar[i] + beg){
checkP++;
}
}
if(checkP>=n)
ans++;
}
System.out.println(ans);
}
}
| Java | ["4 1\n-5 5 0 20\n10", "2 2\n-2000 -2000\n3998000 4000000"] | 2 seconds | ["3", "1"] | NoteThe answer for the first example is 3 because initially the participant could have β-β10, 10 or 15 points.In the second example there is only one correct initial score equaling to 4β002β000. | Java 11 | standard input | [
"constructive algorithms",
"brute force"
] | 6e5b5d357e01d86e1a6dfe7957f57876 | The first line contains two integers k and n (1ββ€βnββ€βkββ€β2β000) β the number of jury members and the number of scores Polycarp remembers. The second line contains k integers a1,βa2,β...,βak (β-β2β000ββ€βaiββ€β2β000) β jury's marks in chronological order. The third line contains n distinct integers b1,βb2,β...,βbn (β-β4β000β000ββ€βbjββ€β4β000β000) β the values of points Polycarp remembers. Note that these values are not necessarily given in chronological order. | 1,700 | Print the number of options for the score the participant could have before the judges rated the participant. If Polycarp messes something up and there is no options, print "0" (without quotes). | standard output | |
PASSED | a717e2186a07ce8d1505203fff347d75 | train_000.jsonl | 1499958300 | Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain number of points (may be negative, i.Β e. points were subtracted). Initially the participant had some score, and each the marks were one by one added to his score. It is known that the i-th jury member gave ai points.Polycarp does not remember how many points the participant had before this k marks were given, but he remembers that among the scores announced after each of the k judges rated the participant there were n (nββ€βk) values b1,βb2,β...,βbn (it is guaranteed that all values bj are distinct). It is possible that Polycarp remembers not all of the scores announced, i.Β e. nβ<βk. Note that the initial score wasn't announced.Your task is to determine the number of options for the score the participant could have before the judges rated the participant. | 256 megabytes | import java.util.*;
import java.io.*;
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
StringTokenizer token = new StringTokenizer(in.readLine());
int k = Integer.parseInt(token.nextToken()), n = Integer.parseInt(token.nextToken());
int sum = 0;
token = new StringTokenizer(in.readLine());
Set<Integer> set = new HashSet<Integer>();
for (int i = 0; i < k; ++i) {
sum += Integer.parseInt(token.nextToken());
set.add(sum);
}
int[] scores = new int[n];
token = new StringTokenizer(in.readLine());
for (int i = 0; i < n; i++)
scores[i] = Integer.parseInt(token.nextToken());
int ans = 0;
for (int pref : set) {
int initial = scores[0] - pref;
boolean good = true;
for (int i = 1; i < n; ++i)
if (!set.contains(scores[i] - initial)) {
good = false;
break;
}
if (good)
++ans;
}
System.out.println(ans);
}
}
| Java | ["4 1\n-5 5 0 20\n10", "2 2\n-2000 -2000\n3998000 4000000"] | 2 seconds | ["3", "1"] | NoteThe answer for the first example is 3 because initially the participant could have β-β10, 10 or 15 points.In the second example there is only one correct initial score equaling to 4β002β000. | Java 11 | standard input | [
"constructive algorithms",
"brute force"
] | 6e5b5d357e01d86e1a6dfe7957f57876 | The first line contains two integers k and n (1ββ€βnββ€βkββ€β2β000) β the number of jury members and the number of scores Polycarp remembers. The second line contains k integers a1,βa2,β...,βak (β-β2β000ββ€βaiββ€β2β000) β jury's marks in chronological order. The third line contains n distinct integers b1,βb2,β...,βbn (β-β4β000β000ββ€βbjββ€β4β000β000) β the values of points Polycarp remembers. Note that these values are not necessarily given in chronological order. | 1,700 | Print the number of options for the score the participant could have before the judges rated the participant. If Polycarp messes something up and there is no options, print "0" (without quotes). | standard output | |
PASSED | e546a8327fb03b8d88e7939147a9c779 | train_000.jsonl | 1499958300 | Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain number of points (may be negative, i.Β e. points were subtracted). Initially the participant had some score, and each the marks were one by one added to his score. It is known that the i-th jury member gave ai points.Polycarp does not remember how many points the participant had before this k marks were given, but he remembers that among the scores announced after each of the k judges rated the participant there were n (nββ€βk) values b1,βb2,β...,βbn (it is guaranteed that all values bj are distinct). It is possible that Polycarp remembers not all of the scores announced, i.Β e. nβ<βk. Note that the initial score wasn't announced.Your task is to determine the number of options for the score the participant could have before the judges rated the participant. | 256 megabytes | import java.io.*;
import java.util.*;
public class JuryMarks {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader (System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int k = Integer.parseInt(st.nextToken());
int n = Integer.parseInt(st.nextToken());
st = new StringTokenizer(br.readLine());
int[]arr = new int[k+1];
for(int i = 1; i<=k; i++) {
arr[i]= Integer.parseInt(st.nextToken());
}
int[]sum = new int[k+1];
for(int i =1;i<=k; i++) {
sum[i]=sum[i-1]+arr[i];
}
st = new StringTokenizer(br.readLine());
TreeSet<Integer> scores = new TreeSet<Integer>();
for(int i = 0; i<n; i++) {
scores.add(Integer.parseInt(st.nextToken()));
}
HashSet<Integer>initial = new HashSet<Integer>();
for(int i = 1; i<=k; i++) {
initial.add(scores.first()-sum[i]);
}
int total = 0;
for(int x:initial) {
HashSet<Integer>points = new HashSet<Integer>();
for(int i=1; i<=k; i++) {
points.add(x+sum[i]);
}
boolean ok = true;
for(int score:scores) {
if(!points.contains(score)) {
ok=false;
break;
}
}
if(ok)total++;
}
System.out.println(total);
}
}
| Java | ["4 1\n-5 5 0 20\n10", "2 2\n-2000 -2000\n3998000 4000000"] | 2 seconds | ["3", "1"] | NoteThe answer for the first example is 3 because initially the participant could have β-β10, 10 or 15 points.In the second example there is only one correct initial score equaling to 4β002β000. | Java 11 | standard input | [
"constructive algorithms",
"brute force"
] | 6e5b5d357e01d86e1a6dfe7957f57876 | The first line contains two integers k and n (1ββ€βnββ€βkββ€β2β000) β the number of jury members and the number of scores Polycarp remembers. The second line contains k integers a1,βa2,β...,βak (β-β2β000ββ€βaiββ€β2β000) β jury's marks in chronological order. The third line contains n distinct integers b1,βb2,β...,βbn (β-β4β000β000ββ€βbjββ€β4β000β000) β the values of points Polycarp remembers. Note that these values are not necessarily given in chronological order. | 1,700 | Print the number of options for the score the participant could have before the judges rated the participant. If Polycarp messes something up and there is no options, print "0" (without quotes). | standard output | |
PASSED | c621fbb25bf4a891dcfa345bc8234ffa | train_000.jsonl | 1390231800 | Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x,βy), he can move to (or attack) positions (xβ+β1,βy), (xβ1,βy), (x,βyβ+β1) and (x,βyβ1).Iahub wants to know how many Coders can be placed on an nβΓβn chessboard, so that no Coder attacks any other Coder. | 256 megabytes | import java.util.Scanner;
public class ACoder {
public static void main(String[] args) {
Scanner k = new Scanner(System.in);
int n = k.nextInt();
System.out.println(((n * n)+1) / 2);
String x="";
String y="";
for (int i = 0; i < n; i++)
if(i%2==0)
{x+='C'; y+='.';}
else
{x+='.'; y+='C';}
for(int i=0;i<n;i++)
if(i%2==0)
System.out.println(x);
else
System.out.println(y);
}
} | Java | ["2"] | 1 second | ["2\nC.\n.C"] | null | Java 8 | standard input | [
"implementation"
] | 1aede54b41d6fad3e74f24a6592198eb | The first line contains an integer n (1ββ€βnββ€β1000). | 800 | On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any. | standard output | |
PASSED | 7717c8c969cd88404c2785082cb874f4 | train_000.jsonl | 1390231800 | Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x,βy), he can move to (or attack) positions (xβ+β1,βy), (xβ1,βy), (x,βyβ+β1) and (x,βyβ1).Iahub wants to know how many Coders can be placed on an nβΓβn chessboard, so that no Coder attacks any other Coder. | 256 megabytes | import java.util.Scanner;
public class practice {
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
int n = input.nextInt();
System.out.println((n * n + 1) / 2);
for (int i = 0; i < n; i++)
{
StringBuilder sb = new StringBuilder();
for (int j = 0; j < n; j++)
{
if ((j + i) % 2 == 0) sb.append("C");
else sb.append(".");
}
System.out.println(sb.toString());
}
}
}
| Java | ["2"] | 1 second | ["2\nC.\n.C"] | null | Java 8 | standard input | [
"implementation"
] | 1aede54b41d6fad3e74f24a6592198eb | The first line contains an integer n (1ββ€βnββ€β1000). | 800 | On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any. | standard output | |
PASSED | 813e98d23546d12e2a545a9226502480 | train_000.jsonl | 1390231800 | Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x,βy), he can move to (or attack) positions (xβ+β1,βy), (xβ1,βy), (x,βyβ+β1) and (x,βyβ1).Iahub wants to know how many Coders can be placed on an nβΓβn chessboard, so that no Coder attacks any other Coder. | 256 megabytes | import java.security.acl.LastOwnerException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.function.IntBinaryOperator;
public class Coder {
public static int[] getArray(int size) {
int[] array = new int[size];
for (int i = 0; i < size; i++) {
array[i] = sr.nextInt();
}
return array;
}
public static int[][] getMatrix(int sizeI, int sizeJ) {
int[][] array = new int[sizeI][sizeJ];
for (int i = 0; i < sizeI; i++) {
for (int j = 0; j < sizeJ; j++) {
array[i][j] = sr.nextInt();
}
}
return array;
}
public static int arraySum(int[] array) {
int sum = 0;
for (int i = 0; i < array.length; i++) {
sum += array[i];
}
return sum;
}
public static int max(int[] array) {
int max = Integer.MIN_VALUE;
for (int i = 0; i < array.length; i++) {
if (array[i] > max)
max = array[i];
}
return max;
}
public static int min(int[] array) {
int min = Integer.MAX_VALUE;
for (int i = 0; i < array.length; i++) {
if (array[i] < min)
min = array[i];
}
return min;
}
static Scanner sr = new Scanner(System.in);
public static void main(String[] args) {
int boardSize = sr.nextInt();
int coders = 0;
coders = boardSize*boardSize /2;
if(boardSize % 2 == 1){
coders++;
}
StringBuilder evenString = new StringBuilder();
StringBuilder oddString = new StringBuilder();
for (int j = 0; j < boardSize; j++) {
if(j%2 == 0){
evenString.append('C');
}
else{
evenString.append('.');
}
}
for (int j = 0; j < boardSize; j++) {
if(j%2 == 1){
oddString.append('C');
}
else{
oddString.append('.');
}
}
System.out.println(coders);
boolean isEven = true;
for (int i = 0; i < boardSize; i++) {
if(isEven) System.out.println(evenString);
else System.out.println(oddString);
isEven = ! isEven;
}
// System.out.println(evenString);
// System.out.println(oddString);
// System.out.println(coders);
// for (int i = 0; i < boardSize; i++) {
// for (int j = 0; j < boardSize; j++) {
//
// if(i%2 == 0 && j%2 ==0){
// System.out.print('C');
// continue;
// }
//
// if(i%2 == 1 && j%2 ==1){
// System.out.print('C');
// continue;
// }
// System.out.print('.');
//
// }
// System.out.println();
// }
}
} | Java | ["2"] | 1 second | ["2\nC.\n.C"] | null | Java 8 | standard input | [
"implementation"
] | 1aede54b41d6fad3e74f24a6592198eb | The first line contains an integer n (1ββ€βnββ€β1000). | 800 | On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any. | standard output | |
PASSED | c8882755f178662e58b7f86625c1bfe5 | train_000.jsonl | 1390231800 | Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x,βy), he can move to (or attack) positions (xβ+β1,βy), (xβ1,βy), (x,βyβ+β1) and (x,βyβ1).Iahub wants to know how many Coders can be placed on an nβΓβn chessboard, so that no Coder attacks any other Coder. | 256 megabytes | import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Scanner;
/**
* Created by HP on 3/23/2018.
*/
public class Main {
public static void main(String[] args) {
char [][] a=new char[1000][1000];
Scanner s=new Scanner(System.in);
int n=s.nextInt();
String c1,c2;
c1=new String();
c2=new String();
if(n%2==0)
System.out.println(n*n/2);
else
System.out.println((n*n/2)+1);
for (int i=0;i<n;i++)
{
if(i%2==0) {
c1+= "C";
c2+=".";
}
else
{
c2+= "C";
c1+=".";
}
}
for(int i=0;i<n;i++) {
if(i%2==0)
System.out.println(c1);
else
System.out.println(c2);
}
}
}
| Java | ["2"] | 1 second | ["2\nC.\n.C"] | null | Java 8 | standard input | [
"implementation"
] | 1aede54b41d6fad3e74f24a6592198eb | The first line contains an integer n (1ββ€βnββ€β1000). | 800 | On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any. | standard output | |
PASSED | f8d067867a7cdb910c125b46b397b726 | train_000.jsonl | 1390231800 | Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x,βy), he can move to (or attack) positions (xβ+β1,βy), (xβ1,βy), (x,βyβ+β1) and (x,βyβ1).Iahub wants to know how many Coders can be placed on an nβΓβn chessboard, so that no Coder attacks any other Coder. | 256 megabytes | import java.util.Scanner;
/**
* Created by Kuang.Ru on 14-9-24.
*/
public class A384 {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int ans;
if (n % 2 == 1) {
ans = (n / 2 + 1) * (n / 2 + 1) + (n / 2) * (n / 2);
} else {
ans = n * n / 2;
}
System.out.println(ans);
char[] outChars = {'.', 'C'};
String oddLine = "";
for (int j = 0; j < n; ++j) {
oddLine += outChars[j % 2];
}
String evenLine = "";
for (int j = 0; j < n; ++j) {
evenLine += outChars[(j + 1) % 2];
}
for (int i = 0; i < n; ++i) {
if (i % 2 == 1) {
System.out.println(oddLine);
} else {
System.out.println(evenLine);
}
}
}
}
| Java | ["2"] | 1 second | ["2\nC.\n.C"] | null | Java 8 | standard input | [
"implementation"
] | 1aede54b41d6fad3e74f24a6592198eb | The first line contains an integer n (1ββ€βnββ€β1000). | 800 | On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any. | standard output | |
PASSED | 4e4c5b79713442334d934f1818f6226c | train_000.jsonl | 1390231800 | Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x,βy), he can move to (or attack) positions (xβ+β1,βy), (xβ1,βy), (x,βyβ+β1) and (x,βyβ1).Iahub wants to know how many Coders can be placed on an nβΓβn chessboard, so that no Coder attacks any other Coder. | 256 megabytes | import java.util.Scanner;
public class Q384A {
public static void main(String[] args) {
run();
}
public static void run(){
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int n2 = n;
int add = 1;
int c = 0;
String l = "";
String l2 = "";
while (n2 > 1) {
l += "C.";
n2 -= 2;
}
n2 = n;
while (n2 > 1) {
l2 += ".C";
n2 -= 2;
}
if (n2 == 1) {
l += "C";
l2 += ".";
}
n2 = n;
for (int i = 1; i <= n; i++) {
c += add;
if (i % 2 == 0) {
add += 2;
}
}
System.out.println(c);
while (n2 > 0) {
System.out.println(l);
n2--;
if (n2 > 0) {
System.out.println(l2);
n2--;
}
}
}
} | Java | ["2"] | 1 second | ["2\nC.\n.C"] | null | Java 8 | standard input | [
"implementation"
] | 1aede54b41d6fad3e74f24a6592198eb | The first line contains an integer n (1ββ€βnββ€β1000). | 800 | On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any. | standard output | |
PASSED | 921395fdb44a3c6d639515b0eb27a10b | train_000.jsonl | 1390231800 | Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x,βy), he can move to (or attack) positions (xβ+β1,βy), (xβ1,βy), (x,βyβ+β1) and (x,βyβ1).Iahub wants to know how many Coders can be placed on an nβΓβn chessboard, so that no Coder attacks any other Coder. | 256 megabytes |
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.StringTokenizer;
public class A225 {
public void solve() throws IOException {
String pd = ".";
String cc = "C";
int n = ni();
int comp1 = n / 2;
int comp2 = n - 1;
int totcoders = 0;
if (n % 2 == 0) {
totcoders += (comp1) * (n);
} else {
totcoders += (n) * (n/2);
totcoders += (n/2 + 1);
}
System.out.println(totcoders);
for (int i = 0; i < n; i++) {
StringBuilder s = new StringBuilder();
for (int j = 0; j < n; j++) {
if (i % 2 == 0) {
if (j % 2 == 0)
s.append(cc);
else
s.append(pd);
} else
if (j % 2 == 0)
s.append(pd);
else
s.append(cc);
}
System.out.println(s.toString());
s = new StringBuilder();
}
}
public BufferedReader br;
public StringTokenizer st;
public PrintWriter out;
public String nextToken() 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 ni() throws IOException {
return Integer.parseInt(nextToken());
}
public long nl() throws IOException {
return Long.parseLong(nextToken());
}
public double nd() throws IOException {
return Double.parseDouble(nextToken());
}
public void run() throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(new OutputStreamWriter(System.out));
solve();
}
public static void main(String args[]) throws IOException {
new A225().run();
}
}
| Java | ["2"] | 1 second | ["2\nC.\n.C"] | null | Java 8 | standard input | [
"implementation"
] | 1aede54b41d6fad3e74f24a6592198eb | The first line contains an integer n (1ββ€βnββ€β1000). | 800 | On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any. | standard output | |
PASSED | afd4116f75297ba26c3d7afb94fe2fc0 | train_000.jsonl | 1390231800 | Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x,βy), he can move to (or attack) positions (xβ+β1,βy), (xβ1,βy), (x,βyβ+β1) and (x,βyβ1).Iahub wants to know how many Coders can be placed on an nβΓβn chessboard, so that no Coder attacks any other Coder. | 256 megabytes | import java.util.*;
public final class Main {
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int num = 0;
if (n % 2 == 1) {
num = n * n / 2 + 1;
} else {
num = n * n / 2;
}
System.out.println(num);
String s = "C", c = ".";
for (int i = 1; i < n; i++) {
if (i % 2 == 1) {
s += ".";
c += "C";
} else {
s += "C";
c += ".";
}
}
for (int i = 1; i <= n; i++) {
if (i % 2 == 1)
System.out.println(s);
else
System.out.println(c);
}
}
} | Java | ["2"] | 1 second | ["2\nC.\n.C"] | null | Java 8 | standard input | [
"implementation"
] | 1aede54b41d6fad3e74f24a6592198eb | The first line contains an integer n (1ββ€βnββ€β1000). | 800 | On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any. | standard output | |
PASSED | f20ebdee7fb5b1d441df80a03e8b7395 | train_000.jsonl | 1390231800 | Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x,βy), he can move to (or attack) positions (xβ+β1,βy), (xβ1,βy), (x,βyβ+β1) and (x,βyβ1).Iahub wants to know how many Coders can be placed on an nβΓβn chessboard, so that no Coder attacks any other Coder. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
public class Main {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
short n = Short.parseShort(br.readLine()), a = (short) (n / 2);
StringBuilder s1 = new StringBuilder(), s2 = new StringBuilder();
if (n % 2 == 0) {
pw.println((a * a) + (a * a));
} else {
pw.println(((a + 1) * (a + 1)) + (a * a));
}
for (short i = 1; i <= n; i++) {
if (i % 2 == 0) {
s1.append(".");
s2.append("C");
} else {
s1.append("C");
s2.append(".");
}
}
for (short i = 1; i <= n; i++) {
pw.println((i%2==1)?s1:s2);
}
pw.close();
}
} | Java | ["2"] | 1 second | ["2\nC.\n.C"] | null | Java 8 | standard input | [
"implementation"
] | 1aede54b41d6fad3e74f24a6592198eb | The first line contains an integer n (1ββ€βnββ€β1000). | 800 | On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any. | standard output | |
PASSED | e60f8e478ce0d469f2813b863b39f288 | train_000.jsonl | 1390231800 | Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x,βy), he can move to (or attack) positions (xβ+β1,βy), (xβ1,βy), (x,βyβ+β1) and (x,βyβ1).Iahub wants to know how many Coders can be placed on an nβΓβn chessboard, so that no Coder attacks any other Coder. | 256 megabytes |
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
short n = Short.parseShort(br.readLine()), a = (short) (n / 2);
StringBuilder s1 = new StringBuilder(), s2 = new StringBuilder();
for (short i = 1; i <= n; i++) {
if (i % 2 == 0) {
s1.append(".");
s2.append("C");
} else {
s1.append("C");
s2.append(".");
}
}
PrintWriter pw = new PrintWriter(System.out);
if (n % 2 == 0) {
pw.println((a * a) + (a * a));
} else {
pw.println(((a + 1) * (a + 1)) + (a * a));
}
for (short i = 1; i <= n; i++) {
pw.println((i%2==1)?s1:s2);
}
pw.close();
}
} | Java | ["2"] | 1 second | ["2\nC.\n.C"] | null | Java 8 | standard input | [
"implementation"
] | 1aede54b41d6fad3e74f24a6592198eb | The first line contains an integer n (1ββ€βnββ€β1000). | 800 | On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any. | standard output | |
PASSED | f6dfb47863aae26ff59baad608c5207b | train_000.jsonl | 1390231800 | Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x,βy), he can move to (or attack) positions (xβ+β1,βy), (xβ1,βy), (x,βyβ+β1) and (x,βyβ1).Iahub wants to know how many Coders can be placed on an nβΓβn chessboard, so that no Coder attacks any other Coder. | 256 megabytes |
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
short n = in.nextShort(), a = (short) (n / 2);
String s1 = "", s2 = "";
if (n == 1) {
System.out.println(1);
System.out.println("C");
return;
} else if (n % 2 == 0) {
System.out.println((a * a) + (a * a));
} else {
System.out.println(((a + 1) * (a + 1)) + (a * a));
}
for (short i = 1; i <= n; i++) {
if (i % 2 == 0) {
s1 += ".";
s2 += "C";
} else {
s1 += "C";
s2 += ".";
}
}
for (short i = 1; i <= n; i++) {
if (i % 2 == 1) {
System.out.println(s1);
} else {
System.out.println(s2);
}
}
}
} | Java | ["2"] | 1 second | ["2\nC.\n.C"] | null | Java 8 | standard input | [
"implementation"
] | 1aede54b41d6fad3e74f24a6592198eb | The first line contains an integer n (1ββ€βnββ€β1000). | 800 | On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any. | standard output | |
PASSED | 0f9992f94c17560f36cb7b188c1c3ecf | train_000.jsonl | 1390231800 | Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x,βy), he can move to (or attack) positions (xβ+β1,βy), (xβ1,βy), (x,βyβ+β1) and (x,βyβ1).Iahub wants to know how many Coders can be placed on an nβΓβn chessboard, so that no Coder attacks any other Coder. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
short n = in.nextShort(), a = (short) (n / 2);
String s1 = "", s2 = "";
if (n == 1) {
System.out.println(1);
System.out.println("C");
return;
} else if (n % 2 == 0) {
System.out.println((a * a) + (a * a));
} else {
System.out.println(((a + 1) * (a + 1)) + (a * a));
}
for (short i = 1; i <= n; i++) {
if (i % 2 == 0) {
s1 += ".";
s2 += "C";
} else {
s1 += "C";
s2 += ".";
}
}
for (short i = 1; i <= n; i++) {
if (i % 2 == 1) {
System.out.println(s1);
} else {
System.out.println(s2);
}
}
}
} | Java | ["2"] | 1 second | ["2\nC.\n.C"] | null | Java 8 | standard input | [
"implementation"
] | 1aede54b41d6fad3e74f24a6592198eb | The first line contains an integer n (1ββ€βnββ€β1000). | 800 | On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any. | standard output | |
PASSED | f69947bde705c101d115b745f229485d | train_000.jsonl | 1390231800 | Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x,βy), he can move to (or attack) positions (xβ+β1,βy), (xβ1,βy), (x,βyβ+β1) and (x,βyβ1).Iahub wants to know how many Coders can be placed on an nβΓβn chessboard, so that no Coder attacks any other Coder. | 256 megabytes |
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
short n = in.nextShort(), a = (short) (n / 2);
StringBuilder s1 = new StringBuilder(), s2 = new StringBuilder();
if (n == 1) {
System.out.println(1);
System.out.println("C");
return;
} else if (n % 2 == 0) {
System.out.println((a * a) + (a * a));
} else {
System.out.println(((a + 1) * (a + 1)) + (a * a));
}
for (short i = 1; i <= n; i++) {
if (i % 2 == 0) {
s1.append(".");
s2.append("C");
} else {
s1.append("C");
s2.append(".");
}
}
for (short i = 1; i <= n; i++) {
if (i % 2 == 1) {
System.out.println(s1);
} else {
System.out.println(s2);
}
}
}
} | Java | ["2"] | 1 second | ["2\nC.\n.C"] | null | Java 8 | standard input | [
"implementation"
] | 1aede54b41d6fad3e74f24a6592198eb | The first line contains an integer n (1ββ€βnββ€β1000). | 800 | On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any. | standard output | |
PASSED | cb9a0cc680e0d2006638c5e20396c4bf | train_000.jsonl | 1390231800 | Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x,βy), he can move to (or attack) positions (xβ+β1,βy), (xβ1,βy), (x,βyβ+β1) and (x,βyβ1).Iahub wants to know how many Coders can be placed on an nβΓβn chessboard, so that no Coder attacks any other Coder. | 256 megabytes | import java.io.*;
public class CF384A {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
char[] cc = new char[n + 1];
for (int i = 0; i <= n; i++)
cc[i] = i % 2 == 0 ? 'C' : '.';
String s = new String(cc, 0, n);
String t = new String(cc, 1, n);
PrintWriter pw = new PrintWriter(System.out);
pw.println(n % 2 == 0 ? n * n / 2 : (n + 1) * (n + 1) / 4 + (n - 1) * (n - 1) / 4);
for (int i = 0; i < n; i++)
pw.println(i % 2 == 0 ? s : t);
pw.close();
}
} | Java | ["2"] | 1 second | ["2\nC.\n.C"] | null | Java 8 | standard input | [
"implementation"
] | 1aede54b41d6fad3e74f24a6592198eb | The first line contains an integer n (1ββ€βnββ€β1000). | 800 | On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any. | standard output | |
PASSED | 0b5cfb35b8180d8ea9f71d50765084e2 | train_000.jsonl | 1390231800 | Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x,βy), he can move to (or attack) positions (xβ+β1,βy), (xβ1,βy), (x,βyβ+β1) and (x,βyβ1).Iahub wants to know how many Coders can be placed on an nβΓβn chessboard, so that no Coder attacks any other Coder. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Task solver = new Task();
solver.solve(in, out);
out.close();
}
static class Task {
void solve(InputReader in, PrintWriter out) {
int n = in.nextInt();
out.println((n * n) % 2 == 0 ? n * n / 2 : (n * n / 2 )+ 1);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i % 2 == 0) {
if (j % 2 == 0) {
out.print('C');
} else {
out.print('.');
}
} else {
if (j % 2 == 0) {
out.print('.');
} else {
out.print('C');
}
}
}
out.print("\n");
}
}
}
static class InputReader {
BufferedReader reader;
StringTokenizer tokenizer;
InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
}
} | Java | ["2"] | 1 second | ["2\nC.\n.C"] | null | Java 8 | standard input | [
"implementation"
] | 1aede54b41d6fad3e74f24a6592198eb | The first line contains an integer n (1ββ€βnββ€β1000). | 800 | On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any. | standard output | |
PASSED | 0a2850dda0698897bfbdeb4213d7eb88 | train_000.jsonl | 1390231800 | Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x,βy), he can move to (or attack) positions (xβ+β1,βy), (xβ1,βy), (x,βyβ+β1) and (x,βyβ1).Iahub wants to know how many Coders can be placed on an nβΓβn chessboard, so that no Coder attacks any other Coder. | 256 megabytes | import java.util.*;
public class Coder1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
int n = input.nextInt();
if(n%2 == 0)System.out.println((n*n)/2);
else System.out.println((n/2)*n + (n/2+1));
String s1 = "";
String s2 ="";
for(int i=0;i<n;i++){
s1+=i%2==0? "C": ".";
s2+=i%2== 0?".":"C";
}
for(int i = 0 ; i<n ; i++){
System.out.println(i%2==0 ? s1 : s2);
}
/*
boolean condition = false;
int counter = 0;
if(n%2 == 0)System.out.println((n*n)/2);
else System.out.println((n/2)*n + (n/2+1));
for(int i=0;i<n;i++){
for(int j=0;j<n/2;j++){
if(!condition){
System.out.print("C.");
}
else{
System.out.print(".C");
}
}
if(n%2 != 0 && !condition)System.out.print("C");
if(n%2!=0 && condition)System.out.print(".");
System.out.println();
if(!condition)condition = true;
else condition = false;
}
*/
}
} | Java | ["2"] | 1 second | ["2\nC.\n.C"] | null | Java 8 | standard input | [
"implementation"
] | 1aede54b41d6fad3e74f24a6592198eb | The first line contains an integer n (1ββ€βnββ€β1000). | 800 | On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any. | standard output | |
PASSED | bab14ecdee3d9d0e63fccd39375bc47a | train_000.jsonl | 1390231800 | Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x,βy), he can move to (or attack) positions (xβ+β1,βy), (xβ1,βy), (x,βyβ+β1) and (x,βyβ1).Iahub wants to know how many Coders can be placed on an nβΓβn chessboard, so that no Coder attacks any other Coder. | 256 megabytes | import java.io.*;
import java.util.*;
public class codeforces
{
public static void main(String args[])
{
PrintWriter out=new PrintWriter(System.out);
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
int par=0;
int count=0;
for(int i = 0 ;i<n;i++)
{
for(int j = 0 ;j<n;j++)
{
if((j%2==0&&par%2==0)||(j%2==1&&par==1))
{
count++;
}
}
par^=1;
}
par=0;
out.println(count);
for(int i = 0 ;i<n;i++)
{
for(int j = 0 ;j<n;j++)
{
if((j%2==0&&par%2==0)||(j%2==1&&par==1))
{
out.print('C');
}
else
{
out.print('.');
}
}
out.println();
par^=1;
}
out.close();
}
} | Java | ["2"] | 1 second | ["2\nC.\n.C"] | null | Java 8 | standard input | [
"implementation"
] | 1aede54b41d6fad3e74f24a6592198eb | The first line contains an integer n (1ββ€βnββ€β1000). | 800 | On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any. | standard output | |
PASSED | d9aa383d03366522b1021677f11dff89 | train_000.jsonl | 1390231800 | Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x,βy), he can move to (or attack) positions (xβ+β1,βy), (xβ1,βy), (x,βyβ+β1) and (x,βyβ1).Iahub wants to know how many Coders can be placed on an nβΓβn chessboard, so that no Coder attacks any other Coder. | 256 megabytes | public class Coder{
public static void main(String[] args){
int n = new java.util.Scanner(System.in).nextInt();
System.out.println((int)Math.ceil(n*n/2.0));
int x = n, m = n;
String s1 = "", s2 = "";
while(m-->0) s1+= (m%2==0 ? "C" : ".");
while(x-->0) s2+= (x%2==0 ? "." : "C");
while(n-->0) System.out.println(n%2==0? s1 : s2);
}
} | Java | ["2"] | 1 second | ["2\nC.\n.C"] | null | Java 8 | standard input | [
"implementation"
] | 1aede54b41d6fad3e74f24a6592198eb | The first line contains an integer n (1ββ€βnββ€β1000). | 800 | On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any. | standard output | |
PASSED | 35f4c2058eaf9cb85cf6c1852ba1d352 | train_000.jsonl | 1390231800 | Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x,βy), he can move to (or attack) positions (xβ+β1,βy), (xβ1,βy), (x,βyβ+β1) and (x,βyβ1).Iahub wants to know how many Coders can be placed on an nβΓβn chessboard, so that no Coder attacks any other Coder. | 256 megabytes | import java.util.*;
public class lll {
public static void main(String [] args)
{
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
int cnt = 0;
String s1 = "";
String s2 = "";
if(num % 2 == 0)
cnt = (num / 2) * num;
else
cnt = (num / 2) * num + num / 2 + 1;
System.out.println(cnt);
for(int i = 0 ; i < 2 ; i++)
{
for(int j = 0 ; j < num ; j++)
{
if((i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0))
{
if(i == 0)
s1 = s1.concat("C");
else
s2 = s2.concat("C");
}
else
{
if(i == 0)
s1 = s1.concat(".");
else
s2 = s2.concat(".");
}
}
}
for(int i = 0 ; i < num ; i+=2)
{
System.out.println(s1);
if(num % 2 != 0 && i == num -1);
else
System.out.println(s2);
}
}
} | Java | ["2"] | 1 second | ["2\nC.\n.C"] | null | Java 8 | standard input | [
"implementation"
] | 1aede54b41d6fad3e74f24a6592198eb | The first line contains an integer n (1ββ€βnββ€β1000). | 800 | On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any. | standard output | |
PASSED | a3ea76b4d003a729652aef1aca6f48e4 | train_000.jsonl | 1390231800 | Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x,βy), he can move to (or attack) positions (xβ+β1,βy), (xβ1,βy), (x,βyβ+β1) and (x,βyβ1).Iahub wants to know how many Coders can be placed on an nβΓβn chessboard, so that no Coder attacks any other Coder. | 256 megabytes | import java.util.Scanner;
public class chess {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in=new Scanner(System.in);
int n=in.nextInt();
String s="";
String s1="";
System.out.println(((n*n)+1)/2);
for(int i=0;i<n;i++) {
if ((i % 2==0)){
s+="C";
s1+=".";
} else {
s+=".";
s1+="C";
}
}
for(int i=0;i<n;i++){
if(i%2==0)
System.out.println(s);
else System.out.println(s1);
}
}
}
| Java | ["2"] | 1 second | ["2\nC.\n.C"] | null | Java 8 | standard input | [
"implementation"
] | 1aede54b41d6fad3e74f24a6592198eb | The first line contains an integer n (1ββ€βnββ€β1000). | 800 | On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any. | standard output | |
PASSED | 1bb4761a78bcfb44c11a46664c2a9ec8 | train_000.jsonl | 1390231800 | Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x,βy), he can move to (or attack) positions (xβ+β1,βy), (xβ1,βy), (x,βyβ+β1) and (x,βyβ1).Iahub wants to know how many Coders can be placed on an nβΓβn chessboard, so that no Coder attacks any other Coder. | 256 megabytes |
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
import static java.util.stream.Collectors.toList;
import java.util.stream.IntStream;
import java.util.stream.Stream;
public class Acm {
private static final Scanner sc = new Scanner(System.in);
public static void main(String[] args) throws IOException {
int size = sc.nextInt();
int rez = ((size / 2) * (size / 2)) + ((size / 2) + size % 2) * ((size / 2) + size % 2);
//System.out.println(((size/2)*(size/2) +"+"+ ((size/2)+size%2)*((size/2)+size%2));
System.out.println(rez);
String str1="";
String str2 = "";
for(int i=0 ; i<size ; i++){
if(i%2==0){
str1+="C"; str2+=".";}
else{
str1+="."; str2+="C";}
}
for(int i=0 ; i<size ; i++)
if(i%2==0)
System.out.println(str1);
else
System.out.println(str2);
}
}
| Java | ["2"] | 1 second | ["2\nC.\n.C"] | null | Java 8 | standard input | [
"implementation"
] | 1aede54b41d6fad3e74f24a6592198eb | The first line contains an integer n (1ββ€βnββ€β1000). | 800 | On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any. | standard output | |
PASSED | 7e961b9febca880951d9de989041751f | train_000.jsonl | 1390231800 | Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x,βy), he can move to (or attack) positions (xβ+β1,βy), (xβ1,βy), (x,βyβ+β1) and (x,βyβ1).Iahub wants to know how many Coders can be placed on an nβΓβn chessboard, so that no Coder attacks any other Coder. | 256 megabytes | import java.util.Scanner;
public class Problem384A {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
int n = sc.nextInt();
int max = n*n;
if(max%2==0) {
max /= 2;
} else {
max = (max+1)/2;
}
System.out.println(max);
char[] chars = {'C','.'};
StringBuilder sb = new StringBuilder();
for(int i=0;i<n;i++) {
sb.delete(0, n);
for(int j=0;j<n;j++) {
sb.append(chars[(j+i)%2]);
}
System.out.println(sb);
}
}
} | Java | ["2"] | 1 second | ["2\nC.\n.C"] | null | Java 8 | standard input | [
"implementation"
] | 1aede54b41d6fad3e74f24a6592198eb | The first line contains an integer n (1ββ€βnββ€β1000). | 800 | On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any. | standard output | |
PASSED | 2731e90fcce5bde6f9a17656276d56b4 | train_000.jsonl | 1390231800 | Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x,βy), he can move to (or attack) positions (xβ+β1,βy), (xβ1,βy), (x,βyβ+β1) and (x,βyβ1).Iahub wants to know how many Coders can be placed on an nβΓβn chessboard, so that no Coder attacks any other Coder. | 256 megabytes | import java.util.Scanner;
public class Coder
{
public static void main(String args[])
{
Scanner z = new Scanner(System.in);
StringBuilder sb = new StringBuilder();
int a=z.nextInt();
if(a==2)
System.out.println(a);
else if(a%2==0)
System.out.println((a*a)/2);
else
{
int b=(int)Math.ceil(a/2);
int c=a-b;
System.out.println((b*b)+(c*c));
}
for(int i=0;i<a;i++)
{
sb.delete(0, a);
for(int j=0;j<a;j++)
{
if(i%2==0)
{
if(j%2==0)
sb.append('C');
else
sb.append('.');
}
else
{
if(j%2==0)
sb.append('.');
else
sb.append('C');
}
}
System.out.println(sb);
}
}
} | Java | ["2"] | 1 second | ["2\nC.\n.C"] | null | Java 8 | standard input | [
"implementation"
] | 1aede54b41d6fad3e74f24a6592198eb | The first line contains an integer n (1ββ€βnββ€β1000). | 800 | On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any. | standard output | |
PASSED | f4415492ad5e74a763c921f20151dc52 | train_000.jsonl | 1390231800 | Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x,βy), he can move to (or attack) positions (xβ+β1,βy), (xβ1,βy), (x,βyβ+β1) and (x,βyβ1).Iahub wants to know how many Coders can be placed on an nβΓβn chessboard, so that no Coder attacks any other Coder. | 256 megabytes |
import java.util.*;
public class CodeForce {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
if(n>1){
String s1="C.",s2=".C";
String a1="",a2="";
for(int i=0;i<n/2;i++){
a1+=s1;
a2+=s2;
}
if(n%2!=0){
a1+="C";
a2+=".";
}
System.out.println(((n*n)+1)/2);
for(int i=0;i<n/2;i++){
System.out.println(a1);
System.out.println(a2);
}
if(n%2!=0)
System.out.println(a1);
}
else{
System.out.println(1);
System.out.println("C");
}
}
}
| Java | ["2"] | 1 second | ["2\nC.\n.C"] | null | Java 8 | standard input | [
"implementation"
] | 1aede54b41d6fad3e74f24a6592198eb | The first line contains an integer n (1ββ€βnββ€β1000). | 800 | On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any. | standard output | |
PASSED | ece48ead81202ef5dc822ae21981d097 | train_000.jsonl | 1390231800 | Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x,βy), he can move to (or attack) positions (xβ+β1,βy), (xβ1,βy), (x,βyβ+β1) and (x,βyβ1).Iahub wants to know how many Coders can be placed on an nβΓβn chessboard, so that no Coder attacks any other Coder. | 256 megabytes | import java.util.Scanner;
public class Codeforces {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int n=in.nextInt();
String s="";
String s1="";
System.out.println(((n*n)+1)/2);
for(int i=0;i<n;i++) {
if ((i % 2==0)){
s+="C";
s1+=".";
} else {
s+=".";
s1+="C";
}
}
for(int i=0;i<n;i++){
if(i%2==0)
System.out.println(s);
else System.out.println(s1);
}
}
} | Java | ["2"] | 1 second | ["2\nC.\n.C"] | null | Java 8 | standard input | [
"implementation"
] | 1aede54b41d6fad3e74f24a6592198eb | The first line contains an integer n (1ββ€βnββ€β1000). | 800 | On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any. | standard output | |
PASSED | 1644ffb4570e0864958115e0a86cdc3a | train_000.jsonl | 1359732600 | Emuskald is an avid horticulturist and owns the world's longest greenhouse β it is effectively infinite in length.Over the years Emuskald has cultivated n plants in his greenhouse, of m different plant species numbered from 1 to m. His greenhouse is very narrow and can be viewed as an infinite line, with each plant occupying a single point on that line.Emuskald has discovered that each species thrives at a different temperature, so he wants to arrange mβ-β1 borders that would divide the greenhouse into m sections numbered from 1 to m from left to right with each section housing a single species. He is free to place the borders, but in the end all of the i-th species plants must reside in i-th section from the left.Of course, it is not always possible to place the borders in such way, so Emuskald needs to replant some of his plants. He can remove each plant from its position and place it anywhere in the greenhouse (at any real coordinate) with no plant already in it. Since replanting is a lot of stress for the plants, help Emuskald find the minimum number of plants he has to replant to be able to place the borders. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class GreenHouseEffect {
public static void main (String[]args) throws IOException {
BufferedReader rdr = new BufferedReader(new InputStreamReader(System.in));
String [] input = rdr.readLine().split(" ");
int n = Integer.parseInt(input[0]);
int m = Integer.parseInt(input[1]);
int [] dp = new int [n];
int [] nums = new int [n];
int answer = 0;
for(int i = 0; i < n; i++) {
nums[i] = Integer.parseInt(rdr.readLine().split(" ")[0]);
dp[i] = 1;
for(int j = 0; j < i;j++) {
if(nums[j] <= nums[i])
dp[i] = Math.max(dp[i],dp[j]+1);
}
answer = Math.max(answer, dp[i]);
}
System.out.println(n-answer);
}
}
| Java | ["3 2\n2 1\n1 2.0\n1 3.100", "3 3\n1 5.0\n2 5.5\n3 6.0", "6 3\n1 14.284235\n2 17.921382\n1 20.328172\n3 20.842331\n1 25.790145\n1 27.204125"] | 2 seconds | ["1", "0", "2"] | NoteIn the first test case, Emuskald can replant the first plant to the right of the last plant, so the answer is 1.In the second test case, the species are already in the correct order, so no replanting is needed. | Java 7 | standard input | [
"dp"
] | 32f245fa1a2d99bfabd30b558687ca5f | The first line of input contains two space-separated integers n and m (1ββ€βn,βmββ€β5000, nββ₯βm), the number of plants and the number of different species. Each of the following n lines contain two space-separated numbers: one integer number si (1ββ€βsiββ€βm), and one real number xi (0ββ€βxiββ€β109), the species and position of the i-th plant. Each xi will contain no more than 6 digits after the decimal point. It is guaranteed that all xi are different; there is at least one plant of each species; the plants are given in order "from left to the right", that is in the ascending order of their xi coordinates (xiβ<βxiβ+β1,β1ββ€βiβ<βn). | 1,700 | Output a single integer β the minimum number of plants to be replanted. | standard output | |
PASSED | 22dfb617f32d69319350738cb97ef511 | train_000.jsonl | 1359732600 | Emuskald is an avid horticulturist and owns the world's longest greenhouse β it is effectively infinite in length.Over the years Emuskald has cultivated n plants in his greenhouse, of m different plant species numbered from 1 to m. His greenhouse is very narrow and can be viewed as an infinite line, with each plant occupying a single point on that line.Emuskald has discovered that each species thrives at a different temperature, so he wants to arrange mβ-β1 borders that would divide the greenhouse into m sections numbered from 1 to m from left to right with each section housing a single species. He is free to place the borders, but in the end all of the i-th species plants must reside in i-th section from the left.Of course, it is not always possible to place the borders in such way, so Emuskald needs to replant some of his plants. He can remove each plant from its position and place it anywhere in the greenhouse (at any real coordinate) with no plant already in it. Since replanting is a lot of stress for the plants, help Emuskald find the minimum number of plants he has to replant to be able to place the borders. | 256 megabytes | import static java.util.Arrays.deepToString;
import java.io.*;
import java.math.*;
import java.util.*;
public class B {
static void solve() {
int n = nextInt();
int m = nextInt();
int[] type = new int[n];
for (int i = 0; i < n; i++) {
type[i] = nextInt();
nextDouble();
}
int[][] d = new int[n + 1][m + 1];
d[0][0] = 0;
for (int i = 0; i < n; i++) {
for (int last = 0; last <= m; last++) {
d[i + 1][last] = Math.max(d[i + 1][last], d[i][last]);
if (type[i] >= last) {
d[i + 1][type[i]] = Math.max(d[i + 1][type[i]], d[i][last] + 1);
}
}
}
int ans = n;
for (int last = 0; last <= m; last++) {
ans = Math.min(ans, n - d[n][last]);
}
writer.println(ans);
}
public static void main(String[] args) throws Exception {
reader = new BufferedReader(new InputStreamReader(System.in));
writer = new PrintWriter(System.out);
setTime();
solve();
printTime();
printMemory();
writer.close();
}
static BufferedReader reader;
static PrintWriter writer;
static StringTokenizer tok = new StringTokenizer("");
static long systemTime;
static void debug(Object... o) {
System.err.println(deepToString(o));
}
static void setTime() {
systemTime = System.currentTimeMillis();
}
static void printTime() {
System.err.println("Time consumed: " + (System.currentTimeMillis() - systemTime));
}
static void printMemory() {
System.err.println("Memory consumed: "
+ (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1000 + "kb");
}
static String next() {
while (!tok.hasMoreTokens()) {
String w = null;
try {
w = reader.readLine();
} catch (Exception e) {
e.printStackTrace();
}
if (w == null)
return null;
tok = new StringTokenizer(w);
}
return tok.nextToken();
}
static int nextInt() {
return Integer.parseInt(next());
}
static long nextLong() {
return Long.parseLong(next());
}
static double nextDouble() {
return Double.parseDouble(next());
}
static BigInteger nextBigInteger() {
return new BigInteger(next());
}
} | Java | ["3 2\n2 1\n1 2.0\n1 3.100", "3 3\n1 5.0\n2 5.5\n3 6.0", "6 3\n1 14.284235\n2 17.921382\n1 20.328172\n3 20.842331\n1 25.790145\n1 27.204125"] | 2 seconds | ["1", "0", "2"] | NoteIn the first test case, Emuskald can replant the first plant to the right of the last plant, so the answer is 1.In the second test case, the species are already in the correct order, so no replanting is needed. | Java 7 | standard input | [
"dp"
] | 32f245fa1a2d99bfabd30b558687ca5f | The first line of input contains two space-separated integers n and m (1ββ€βn,βmββ€β5000, nββ₯βm), the number of plants and the number of different species. Each of the following n lines contain two space-separated numbers: one integer number si (1ββ€βsiββ€βm), and one real number xi (0ββ€βxiββ€β109), the species and position of the i-th plant. Each xi will contain no more than 6 digits after the decimal point. It is guaranteed that all xi are different; there is at least one plant of each species; the plants are given in order "from left to the right", that is in the ascending order of their xi coordinates (xiβ<βxiβ+β1,β1ββ€βiβ<βn). | 1,700 | Output a single integer β the minimum number of plants to be replanted. | standard output | |
PASSED | ccb02aad8a210a101ec789f3815826ef | train_000.jsonl | 1359732600 | Emuskald is an avid horticulturist and owns the world's longest greenhouse β it is effectively infinite in length.Over the years Emuskald has cultivated n plants in his greenhouse, of m different plant species numbered from 1 to m. His greenhouse is very narrow and can be viewed as an infinite line, with each plant occupying a single point on that line.Emuskald has discovered that each species thrives at a different temperature, so he wants to arrange mβ-β1 borders that would divide the greenhouse into m sections numbered from 1 to m from left to right with each section housing a single species. He is free to place the borders, but in the end all of the i-th species plants must reside in i-th section from the left.Of course, it is not always possible to place the borders in such way, so Emuskald needs to replant some of his plants. He can remove each plant from its position and place it anywhere in the greenhouse (at any real coordinate) with no plant already in it. Since replanting is a lot of stress for the plants, help Emuskald find the minimum number of plants he has to replant to be able to place the borders. | 256 megabytes | import java.util.*;
import java.io.*;
public class A {
static Scanner sc = new Scanner(System.in);
static int i,j,k,x,n,m;
static int[] dp = new int[10000];
static int[] a = new int[10000];
static double z;
static int f(int k, int j) {
int i;
if (dp[j] >= k) return dp[j];
for (i=j+1;i<=n;i++)
if (a[j] <= a[i])
{
f(k+1,i);
}
dp[j] = Math.max(dp[j], k);
return k;
}
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String [] s = in.readLine().split(" ");
n = Integer.parseInt(s[0]);
m = Integer.parseInt(s[1]);
for (i=1;i<=n;i++) {
a[i] = Integer.parseInt(in.readLine().split(" ")[0]);
dp[i] = 1;
}
for (i=1;i<=n;i++)
for (j=1; j<i; j++)
if (a[j]<=a[i])
dp[i] = Math.max(dp[i],dp[j]+1);
x = 0;
for (i = 1; i<=n; i++)
x = Math.max(x,dp[i]);
System.out.println(n-x);
}
}
| Java | ["3 2\n2 1\n1 2.0\n1 3.100", "3 3\n1 5.0\n2 5.5\n3 6.0", "6 3\n1 14.284235\n2 17.921382\n1 20.328172\n3 20.842331\n1 25.790145\n1 27.204125"] | 2 seconds | ["1", "0", "2"] | NoteIn the first test case, Emuskald can replant the first plant to the right of the last plant, so the answer is 1.In the second test case, the species are already in the correct order, so no replanting is needed. | Java 7 | standard input | [
"dp"
] | 32f245fa1a2d99bfabd30b558687ca5f | The first line of input contains two space-separated integers n and m (1ββ€βn,βmββ€β5000, nββ₯βm), the number of plants and the number of different species. Each of the following n lines contain two space-separated numbers: one integer number si (1ββ€βsiββ€βm), and one real number xi (0ββ€βxiββ€β109), the species and position of the i-th plant. Each xi will contain no more than 6 digits after the decimal point. It is guaranteed that all xi are different; there is at least one plant of each species; the plants are given in order "from left to the right", that is in the ascending order of their xi coordinates (xiβ<βxiβ+β1,β1ββ€βiβ<βn). | 1,700 | Output a single integer β the minimum number of plants to be replanted. | standard output | |
PASSED | f1c7a9d998eb2cad094fbb7eee097ad9 | train_000.jsonl | 1359732600 | Emuskald is an avid horticulturist and owns the world's longest greenhouse β it is effectively infinite in length.Over the years Emuskald has cultivated n plants in his greenhouse, of m different plant species numbered from 1 to m. His greenhouse is very narrow and can be viewed as an infinite line, with each plant occupying a single point on that line.Emuskald has discovered that each species thrives at a different temperature, so he wants to arrange mβ-β1 borders that would divide the greenhouse into m sections numbered from 1 to m from left to right with each section housing a single species. He is free to place the borders, but in the end all of the i-th species plants must reside in i-th section from the left.Of course, it is not always possible to place the borders in such way, so Emuskald needs to replant some of his plants. He can remove each plant from its position and place it anywhere in the greenhouse (at any real coordinate) with no plant already in it. Since replanting is a lot of stress for the plants, help Emuskald find the minimum number of plants he has to replant to be able to place the borders. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class B {
static Scanner in = new Scanner(System.in);
public static void main(String[] args) {
int n = in.nextInt(), m = in.nextInt();
Node[] trees = new Node[n + 1];
trees[0] = new Node();
trees[0].s = 0;
trees[0].x = -1;
for (int i = 1; i <= n; i++) {
trees[i] = new Node();
trees[i].s = in.nextInt();
trees[i].x = in.nextDouble();
}
Arrays.sort(trees);
int[] dp = new int[n + 1];
int lcs = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < i; j++)
if (trees[i].s >= trees[j].s)
dp[i] = Math.max(dp[i], dp[j] + 1);
lcs = Math.max(lcs, dp[i]);
}
System.out.println(n - lcs);
}
}
class Node implements Comparable<Node> {
int s;
double x;
@Override
public int compareTo(Node arg0) {
if (Math.abs(x - arg0.x) < 1e-9)
return 0;
if (x < arg0.x)
return -1;
return 1;
}
} | Java | ["3 2\n2 1\n1 2.0\n1 3.100", "3 3\n1 5.0\n2 5.5\n3 6.0", "6 3\n1 14.284235\n2 17.921382\n1 20.328172\n3 20.842331\n1 25.790145\n1 27.204125"] | 2 seconds | ["1", "0", "2"] | NoteIn the first test case, Emuskald can replant the first plant to the right of the last plant, so the answer is 1.In the second test case, the species are already in the correct order, so no replanting is needed. | Java 7 | standard input | [
"dp"
] | 32f245fa1a2d99bfabd30b558687ca5f | The first line of input contains two space-separated integers n and m (1ββ€βn,βmββ€β5000, nββ₯βm), the number of plants and the number of different species. Each of the following n lines contain two space-separated numbers: one integer number si (1ββ€βsiββ€βm), and one real number xi (0ββ€βxiββ€β109), the species and position of the i-th plant. Each xi will contain no more than 6 digits after the decimal point. It is guaranteed that all xi are different; there is at least one plant of each species; the plants are given in order "from left to the right", that is in the ascending order of their xi coordinates (xiβ<βxiβ+β1,β1ββ€βiβ<βn). | 1,700 | Output a single integer β the minimum number of plants to be replanted. | standard output | |
PASSED | cea8bc29884fd70ffd991d489338b6d9 | train_000.jsonl | 1359732600 | Emuskald is an avid horticulturist and owns the world's longest greenhouse β it is effectively infinite in length.Over the years Emuskald has cultivated n plants in his greenhouse, of m different plant species numbered from 1 to m. His greenhouse is very narrow and can be viewed as an infinite line, with each plant occupying a single point on that line.Emuskald has discovered that each species thrives at a different temperature, so he wants to arrange mβ-β1 borders that would divide the greenhouse into m sections numbered from 1 to m from left to right with each section housing a single species. He is free to place the borders, but in the end all of the i-th species plants must reside in i-th section from the left.Of course, it is not always possible to place the borders in such way, so Emuskald needs to replant some of his plants. He can remove each plant from its position and place it anywhere in the greenhouse (at any real coordinate) with no plant already in it. Since replanting is a lot of stress for the plants, help Emuskald find the minimum number of plants he has to replant to be able to place the borders. | 256 megabytes | import java.util.Scanner;
public class B {
static Scanner in = new Scanner(System.in);
public static void main(String[] args) {
int n = in.nextInt(), m = in.nextInt();
int v[] = new int[n+1];
for (int i = 1; i <= n; i++) {
v[i] = in.nextInt();
in.nextDouble();
}
int[] dp = new int[n + 1];
int lcs = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < i; j++)
if (v[i] >= v[j])
dp[i] = Math.max(dp[i], dp[j] + 1);
lcs = Math.max(lcs, dp[i]);
}
System.out.println(n - lcs);
}
} | Java | ["3 2\n2 1\n1 2.0\n1 3.100", "3 3\n1 5.0\n2 5.5\n3 6.0", "6 3\n1 14.284235\n2 17.921382\n1 20.328172\n3 20.842331\n1 25.790145\n1 27.204125"] | 2 seconds | ["1", "0", "2"] | NoteIn the first test case, Emuskald can replant the first plant to the right of the last plant, so the answer is 1.In the second test case, the species are already in the correct order, so no replanting is needed. | Java 7 | standard input | [
"dp"
] | 32f245fa1a2d99bfabd30b558687ca5f | The first line of input contains two space-separated integers n and m (1ββ€βn,βmββ€β5000, nββ₯βm), the number of plants and the number of different species. Each of the following n lines contain two space-separated numbers: one integer number si (1ββ€βsiββ€βm), and one real number xi (0ββ€βxiββ€β109), the species and position of the i-th plant. Each xi will contain no more than 6 digits after the decimal point. It is guaranteed that all xi are different; there is at least one plant of each species; the plants are given in order "from left to the right", that is in the ascending order of their xi coordinates (xiβ<βxiβ+β1,β1ββ€βiβ<βn). | 1,700 | Output a single integer β the minimum number of plants to be replanted. | standard output | |
PASSED | e0d481add4a6064ccc84cc39681b142a | train_000.jsonl | 1359732600 | Emuskald is an avid horticulturist and owns the world's longest greenhouse β it is effectively infinite in length.Over the years Emuskald has cultivated n plants in his greenhouse, of m different plant species numbered from 1 to m. His greenhouse is very narrow and can be viewed as an infinite line, with each plant occupying a single point on that line.Emuskald has discovered that each species thrives at a different temperature, so he wants to arrange mβ-β1 borders that would divide the greenhouse into m sections numbered from 1 to m from left to right with each section housing a single species. He is free to place the borders, but in the end all of the i-th species plants must reside in i-th section from the left.Of course, it is not always possible to place the borders in such way, so Emuskald needs to replant some of his plants. He can remove each plant from its position and place it anywhere in the greenhouse (at any real coordinate) with no plant already in it. Since replanting is a lot of stress for the plants, help Emuskald find the minimum number of plants he has to replant to be able to place the borders. | 256 megabytes | import static java.lang.Math.*;
import static java.lang.System.currentTimeMillis;
import static java.lang.System.exit;
import static java.lang.System.arraycopy;
import static java.util.Arrays.sort;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.fill;
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
try {
if (new File("input.txt").exists())
System.setIn(new FileInputStream("input.txt"));
} catch (SecurityException e) {
}
new Thread(null, new Runnable() {
public void run() {
try {
new Main().run();
} catch (Throwable e) {
e.printStackTrace();
exit(999);
}
}
}, "1", 1 << 23).start();
}
BufferedReader in;
PrintWriter out;
StringTokenizer st = new StringTokenizer("");
private void run() throws IOException {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
in.close();
out.close();
}
final int INF = Integer.MAX_VALUE >> 1;
private void solve() throws IOException {
int n = nextInt();
int m = nextInt();
int[] a = new int[n];
RSQ rsq = new RSQ(m);
for (int i = 0; i < n; i++) {
a[i] = nextInt() - 1;
rsq.add(a[i], 1);
nextDouble();
}
int[][] dp = new int[n + 1][m];
for (int[] x : dp)
fill(x, INF);
dp[0][0] = 0;
for (int pos = 0; pos < n; pos++) {
for (int j = 0; j < m; j++) {
if (dp[pos][j] == INF)
continue;
if (a[pos] < j) {
dp[pos + 1][j] = dp[pos][j];
continue;
}
// System.err.println(pos + " " + j + " " + dp[pos][j] + " " + a[pos]);
int add = rsq.getSum(j, a[pos] - 1);
// System.err.println(add);
dp[pos + 1][a[pos]] = min(dp[pos + 1][a[pos]], dp[pos][j] + add);
dp[pos + 1][j] = min(dp[pos + 1][j], dp[pos][j] + 1);
}
rsq.add(a[pos], -1);
}
// for (int[] x : dp)
// System.err.println(Arrays.toString(x));
int ans = INF;
for (int x : dp[n])
ans = min(ans, x);
out.println(ans);
}
class RSQ {
int[] value;
int n;
RSQ(int n) {
this.n = n;
value = new int[n << 1];
}
void add(int x, int k) {
x += n;
value[x] += k;
while (x > 1) {
x >>= 1;
int l = x << 1;
int r = l + 1;
value[x] = value[l] + value[r];
}
}
int getSum(int l, int r) {
l += n;
r += n;
int ret = 0;
while (l <= r) {
if ((l & 1) == 1) ret += value[l];
if ((r & 1) == 0) ret += value[r];
l = (l + 1) >> 1;
r = (r - 1) >> 1;
}
return ret;
}
}
void chk(boolean b) {
if (b)
return;
System.out.println(new Error().getStackTrace()[1]);
exit(999);
}
void deb(String fmt, Object... args) {
System.out.printf(Locale.US, fmt + "%n", args);
}
String nextToken() throws IOException {
while (!st.hasMoreTokens())
st = new StringTokenizer(in.readLine());
return st.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
String nextLine() throws IOException {
st = new StringTokenizer("");
return in.readLine();
}
boolean EOF() throws IOException {
while (!st.hasMoreTokens()) {
String s = in.readLine();
if (s == null)
return true;
st = new StringTokenizer(s);
}
return false;
}
}
| Java | ["3 2\n2 1\n1 2.0\n1 3.100", "3 3\n1 5.0\n2 5.5\n3 6.0", "6 3\n1 14.284235\n2 17.921382\n1 20.328172\n3 20.842331\n1 25.790145\n1 27.204125"] | 2 seconds | ["1", "0", "2"] | NoteIn the first test case, Emuskald can replant the first plant to the right of the last plant, so the answer is 1.In the second test case, the species are already in the correct order, so no replanting is needed. | Java 7 | standard input | [
"dp"
] | 32f245fa1a2d99bfabd30b558687ca5f | The first line of input contains two space-separated integers n and m (1ββ€βn,βmββ€β5000, nββ₯βm), the number of plants and the number of different species. Each of the following n lines contain two space-separated numbers: one integer number si (1ββ€βsiββ€βm), and one real number xi (0ββ€βxiββ€β109), the species and position of the i-th plant. Each xi will contain no more than 6 digits after the decimal point. It is guaranteed that all xi are different; there is at least one plant of each species; the plants are given in order "from left to the right", that is in the ascending order of their xi coordinates (xiβ<βxiβ+β1,β1ββ€βiβ<βn). | 1,700 | Output a single integer β the minimum number of plants to be replanted. | standard output | |
PASSED | 3dbfa17c3b7890baf264f8d0fa81c648 | train_000.jsonl | 1359732600 | Emuskald is an avid horticulturist and owns the world's longest greenhouse β it is effectively infinite in length.Over the years Emuskald has cultivated n plants in his greenhouse, of m different plant species numbered from 1 to m. His greenhouse is very narrow and can be viewed as an infinite line, with each plant occupying a single point on that line.Emuskald has discovered that each species thrives at a different temperature, so he wants to arrange mβ-β1 borders that would divide the greenhouse into m sections numbered from 1 to m from left to right with each section housing a single species. He is free to place the borders, but in the end all of the i-th species plants must reside in i-th section from the left.Of course, it is not always possible to place the borders in such way, so Emuskald needs to replant some of his plants. He can remove each plant from its position and place it anywhere in the greenhouse (at any real coordinate) with no plant already in it. Since replanting is a lot of stress for the plants, help Emuskald find the minimum number of plants he has to replant to be able to place the borders. | 256 megabytes | import static java.lang.Math.*;
import java.io.*;
import java.lang.reflect.*;
public class B {
final int MOD = (int)1e9 + 7;
final double eps = 1e-12;
final int INF = (int)1e9;
public B () {
int N = sc.nextInt();
int M = sc.nextInt();
int [] A = new int[N];
for (int i = 0; i < N; ++i) {
A[i] = sc.nextInt();
sc.next();
}
int [] F = new int [M+1];
for (int i = 1; i <= N; ++i) {
int Z = 0;
for (int k = 1; k <= A[i-1]; ++k)
Z = max(Z, 1 + F[k]);
F[A[i-1]] = Z;
}
int res = N;
for (int i = 1; i <= M; ++i)
res = min(res, N - F[i]);
exit(res);
}
////////////////////////////////////////////////////////////////////////////////////
static MyScanner sc;
static class MyScanner {
public String next() {
newLine();
return line[index++];
}
public char nextChar() {
return next().charAt(0);
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String nextLine() {
line = null;
return readLine();
}
public String [] nextStrings() {
line = null;
return readLine().split(" ");
}
public char [] nextChars() {
return next().toCharArray();
}
public Integer [] nextInts() {
String [] L = nextStrings();
Integer [] res = new Integer [L.length];
for (int i = 0; i < L.length; ++i)
res[i] = Integer.parseInt(L[i]);
return res;
}
public Long [] nextLongs() {
String [] L = nextStrings();
Long [] res = new Long [L.length];
for (int i = 0; i < L.length; ++i)
res[i] = Long.parseLong(L[i]);
return res;
}
public Double [] nextDoubles() {
String [] L = nextStrings();
Double [] res = new Double [L.length];
for (int i = 0; i < L.length; ++i)
res[i] = Double.parseDouble(L[i]);
return res;
}
//////////////////////////////////////////////
private boolean eol() {
return index == line.length;
}
private String readLine() {
try {
return r.readLine();
} catch (Exception e) {
throw new Error(e);
}
}
private final BufferedReader r;
MyScanner () {
this(new BufferedReader(new InputStreamReader(System.in)));
}
MyScanner(BufferedReader r) {
try {
this.r = r;
while (!r.ready())
Thread.sleep(1);
start();
} catch (Exception e) {
throw new Error(e);
}
}
private String [] line;
private int index;
private void newLine() {
if (line == null || eol()) {
line = readLine().split(" ");
index = 0;
}
}
}
static void print (Object o, Object... a) {
pw.println(build(o, a));
}
static void exit (Object o, Object... a) {
print(o, a);
exit();
}
static void exit () {
pw.close();
System.out.flush();
System.err.println("------------------");
System.err.println("Time: " + ((millis() - t) / 1000.0));
System.exit(0);
}
void NO() {
throw new Error("NO!");
}
////////////////////////////////////////////////////////////////////////////////////
static String build(Object... a) {
StringBuilder b = new StringBuilder();
for (Object o : a)
append(b, o);
return b.toString().trim();
}
static void append(StringBuilder b, Object o) {
if (o.getClass().isArray()) {
int L = Array.getLength(o);
for (int i = 0; i < L; ++i)
append(b, Array.get(o, i));
} else if (o instanceof Iterable<?>) {
for (Object p : (Iterable<?>)o)
append(b, p);
} else
b.append(" ").append(o);
}
////////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
sc = new MyScanner ();
new B();
exit();
}
static void start() {
t = millis();
}
static PrintWriter pw = new PrintWriter(System.out);
static long t;
static long millis() {
return System.currentTimeMillis();
}
}
| Java | ["3 2\n2 1\n1 2.0\n1 3.100", "3 3\n1 5.0\n2 5.5\n3 6.0", "6 3\n1 14.284235\n2 17.921382\n1 20.328172\n3 20.842331\n1 25.790145\n1 27.204125"] | 2 seconds | ["1", "0", "2"] | NoteIn the first test case, Emuskald can replant the first plant to the right of the last plant, so the answer is 1.In the second test case, the species are already in the correct order, so no replanting is needed. | Java 7 | standard input | [
"dp"
] | 32f245fa1a2d99bfabd30b558687ca5f | The first line of input contains two space-separated integers n and m (1ββ€βn,βmββ€β5000, nββ₯βm), the number of plants and the number of different species. Each of the following n lines contain two space-separated numbers: one integer number si (1ββ€βsiββ€βm), and one real number xi (0ββ€βxiββ€β109), the species and position of the i-th plant. Each xi will contain no more than 6 digits after the decimal point. It is guaranteed that all xi are different; there is at least one plant of each species; the plants are given in order "from left to the right", that is in the ascending order of their xi coordinates (xiβ<βxiβ+β1,β1ββ€βiβ<βn). | 1,700 | Output a single integer β the minimum number of plants to be replanted. | standard output | |
PASSED | 18f7650830d0b0044e40ebae03b38c56 | train_000.jsonl | 1359732600 | Emuskald is an avid horticulturist and owns the world's longest greenhouse β it is effectively infinite in length.Over the years Emuskald has cultivated n plants in his greenhouse, of m different plant species numbered from 1 to m. His greenhouse is very narrow and can be viewed as an infinite line, with each plant occupying a single point on that line.Emuskald has discovered that each species thrives at a different temperature, so he wants to arrange mβ-β1 borders that would divide the greenhouse into m sections numbered from 1 to m from left to right with each section housing a single species. He is free to place the borders, but in the end all of the i-th species plants must reside in i-th section from the left.Of course, it is not always possible to place the borders in such way, so Emuskald needs to replant some of his plants. He can remove each plant from its position and place it anywhere in the greenhouse (at any real coordinate) with no plant already in it. Since replanting is a lot of stress for the plants, help Emuskald find the minimum number of plants he has to replant to be able to place the borders. | 256 megabytes | import static java.lang.Math.*;
import java.io.*;
import java.lang.reflect.*;
public class B {
final int MOD = (int)1e9 + 7;
final double eps = 1e-12;
final int INF = (int)1e9;
public B () {
int N = sc.nextInt();
int M = sc.nextInt();
int [] A = new int[N];
for (int i = 0; i < N; ++i) {
A[i] = sc.nextInt();
sc.next();
}
int [] F = new int [M+1];
for (int i = 1; i <= N; ++i)
for (int j = A[i-1]; j >= 1; --j)
F[A[i-1]] = max(F[A[i-1]], 1 + F[j]);
int Z = 1;
for (int i = 1; i <= M; ++i)
Z = max(Z, F[i]);
int res = N - Z;
exit(res);
}
////////////////////////////////////////////////////////////////////////////////////
static MyScanner sc;
static class MyScanner {
public String next() {
newLine();
return line[index++];
}
public char nextChar() {
return next().charAt(0);
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String nextLine() {
line = null;
return readLine();
}
public String [] nextStrings() {
line = null;
return readLine().split(" ");
}
public char [] nextChars() {
return next().toCharArray();
}
public Integer [] nextInts() {
String [] L = nextStrings();
Integer [] res = new Integer [L.length];
for (int i = 0; i < L.length; ++i)
res[i] = Integer.parseInt(L[i]);
return res;
}
public Long [] nextLongs() {
String [] L = nextStrings();
Long [] res = new Long [L.length];
for (int i = 0; i < L.length; ++i)
res[i] = Long.parseLong(L[i]);
return res;
}
public Double [] nextDoubles() {
String [] L = nextStrings();
Double [] res = new Double [L.length];
for (int i = 0; i < L.length; ++i)
res[i] = Double.parseDouble(L[i]);
return res;
}
//////////////////////////////////////////////
private boolean eol() {
return index == line.length;
}
private String readLine() {
try {
return r.readLine();
} catch (Exception e) {
throw new Error(e);
}
}
private final BufferedReader r;
MyScanner () {
this(new BufferedReader(new InputStreamReader(System.in)));
}
MyScanner(BufferedReader r) {
try {
this.r = r;
while (!r.ready())
Thread.sleep(1);
start();
} catch (Exception e) {
throw new Error(e);
}
}
private String [] line;
private int index;
private void newLine() {
if (line == null || eol()) {
line = readLine().split(" ");
index = 0;
}
}
}
static void print (Object o, Object... a) {
pw.println(build(o, a));
}
static void exit (Object o, Object... a) {
print(o, a);
exit();
}
static void exit () {
pw.close();
System.out.flush();
System.err.println("------------------");
System.err.println("Time: " + ((millis() - t) / 1000.0));
System.exit(0);
}
void NO() {
throw new Error("NO!");
}
////////////////////////////////////////////////////////////////////////////////////
static String build(Object... a) {
StringBuilder b = new StringBuilder();
for (Object o : a)
append(b, o);
return b.toString().trim();
}
static void append(StringBuilder b, Object o) {
if (o.getClass().isArray()) {
int L = Array.getLength(o);
for (int i = 0; i < L; ++i)
append(b, Array.get(o, i));
} else if (o instanceof Iterable<?>) {
for (Object p : (Iterable<?>)o)
append(b, p);
} else
b.append(" ").append(o);
}
////////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
sc = new MyScanner ();
new B();
exit();
}
static void start() {
t = millis();
}
static PrintWriter pw = new PrintWriter(System.out);
static long t;
static long millis() {
return System.currentTimeMillis();
}
}
| Java | ["3 2\n2 1\n1 2.0\n1 3.100", "3 3\n1 5.0\n2 5.5\n3 6.0", "6 3\n1 14.284235\n2 17.921382\n1 20.328172\n3 20.842331\n1 25.790145\n1 27.204125"] | 2 seconds | ["1", "0", "2"] | NoteIn the first test case, Emuskald can replant the first plant to the right of the last plant, so the answer is 1.In the second test case, the species are already in the correct order, so no replanting is needed. | Java 7 | standard input | [
"dp"
] | 32f245fa1a2d99bfabd30b558687ca5f | The first line of input contains two space-separated integers n and m (1ββ€βn,βmββ€β5000, nββ₯βm), the number of plants and the number of different species. Each of the following n lines contain two space-separated numbers: one integer number si (1ββ€βsiββ€βm), and one real number xi (0ββ€βxiββ€β109), the species and position of the i-th plant. Each xi will contain no more than 6 digits after the decimal point. It is guaranteed that all xi are different; there is at least one plant of each species; the plants are given in order "from left to the right", that is in the ascending order of their xi coordinates (xiβ<βxiβ+β1,β1ββ€βiβ<βn). | 1,700 | Output a single integer β the minimum number of plants to be replanted. | standard output | |
PASSED | d881cbc802f62e49e2177f36310a744c | train_000.jsonl | 1359732600 | Emuskald is an avid horticulturist and owns the world's longest greenhouse β it is effectively infinite in length.Over the years Emuskald has cultivated n plants in his greenhouse, of m different plant species numbered from 1 to m. His greenhouse is very narrow and can be viewed as an infinite line, with each plant occupying a single point on that line.Emuskald has discovered that each species thrives at a different temperature, so he wants to arrange mβ-β1 borders that would divide the greenhouse into m sections numbered from 1 to m from left to right with each section housing a single species. He is free to place the borders, but in the end all of the i-th species plants must reside in i-th section from the left.Of course, it is not always possible to place the borders in such way, so Emuskald needs to replant some of his plants. He can remove each plant from its position and place it anywhere in the greenhouse (at any real coordinate) with no plant already in it. Since replanting is a lot of stress for the plants, help Emuskald find the minimum number of plants he has to replant to be able to place the borders. | 256 megabytes |
// @author Sanzhar
import java.awt.Point;
import java.io.*;
import java.util.*;
public class Template {
BufferedReader in;
PrintWriter out;
StringTokenizer st;
String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(in.readLine());
} catch (Exception e) {
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
public void run() throws Exception {
//in = new BufferedReader(new FileReader("input.txt"));
//out = new PrintWriter(new FileWriter("output.txt"));
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
out.flush();
out.close();
in.close();
}
public void solve() throws Exception {
int n = nextInt();
int m = nextInt();
int[] r = new int[n];
for (int i = 0; i < n; i++) {
r[i] = nextInt();
next();
}
int[] dp = new int[n];
int ans = 0;
for (int i = 0; i < n; i++) {
int max = 0;
for (int j = 0; j < i; j++) {
if (r[j] <= r[i]) {
max = Math.max(max, dp[j]);
}
}
dp[i] = max + 1;
ans = Math.max(ans, dp[i]);
}
out.println(n - ans);
}
public static void main(String[] args) throws Exception {
new Template().run();
}
}
| Java | ["3 2\n2 1\n1 2.0\n1 3.100", "3 3\n1 5.0\n2 5.5\n3 6.0", "6 3\n1 14.284235\n2 17.921382\n1 20.328172\n3 20.842331\n1 25.790145\n1 27.204125"] | 2 seconds | ["1", "0", "2"] | NoteIn the first test case, Emuskald can replant the first plant to the right of the last plant, so the answer is 1.In the second test case, the species are already in the correct order, so no replanting is needed. | Java 7 | standard input | [
"dp"
] | 32f245fa1a2d99bfabd30b558687ca5f | The first line of input contains two space-separated integers n and m (1ββ€βn,βmββ€β5000, nββ₯βm), the number of plants and the number of different species. Each of the following n lines contain two space-separated numbers: one integer number si (1ββ€βsiββ€βm), and one real number xi (0ββ€βxiββ€β109), the species and position of the i-th plant. Each xi will contain no more than 6 digits after the decimal point. It is guaranteed that all xi are different; there is at least one plant of each species; the plants are given in order "from left to the right", that is in the ascending order of their xi coordinates (xiβ<βxiβ+β1,β1ββ€βiβ<βn). | 1,700 | Output a single integer β the minimum number of plants to be replanted. | standard output | |
PASSED | cd01b03ba7b7dd1735296e02781884fa | train_000.jsonl | 1372941000 | Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers. A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if: Its elements are in increasing order. That is an inequality aiβ<βaj holds for any two indices i,βj (iβ<βj). For any two indices i and j (iβ<βj), aj must not be divisible by ai. Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements. | 256 megabytes | /*package com.ashutosh.codeforces;*/
import java.io.*;
import java.util.Arrays;
import java.util.InputMismatchException;
/**
* Created by ashutosh on 12/11/16.
*/
public class b327 extends FastIO{
public static void main(String[] args) {
int n = reader.readInt();
getFirtNPrimeNumbers(n);
writer.flush();
writer.close();
}
public static void getFirtNPrimeNumbers(int n) {
int maxVal = 10000000;
boolean[] boolArr = new boolean[maxVal + 1];
Arrays.fill(boolArr, true);
boolArr[1] = false;
int count = 0 , lastIndex = 0;
int i = 2;
for (i = 2; i * i <= maxVal; i++) {
if (boolArr[i]) {
count++;
if (count == n) {
lastIndex = i;
break;
}
for (int j = i; j * i <= maxVal; j++) {
boolArr[i*j] = false;
}
}
}
if (lastIndex == 0) {
int nowCount = 0;
for (int j = 2; j <= maxVal; j++) {
if (boolArr[j]) {
nowCount++;
writer.print(j + " ");
if (nowCount == n) {
break;
}
}
}
} else {
for (int j = 2; j <= lastIndex; j++) {
if (boolArr[j]) {
writer.print(j + " ");
}
}
}
}
}
/**
* Created by ashutosh on 1/11/16.
*/
class FastIO {
public static InputReader reader = new InputReader(System.in);
public static OutputWriter writer = new OutputWriter(System.out);
public static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private InputReader.SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int readInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public String readString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next() {
return readString();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
public static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
public void printLine(Object... objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
public void flush() {
writer.flush();
}
}
public static 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;
}
/**
* Read items into array starting from a given point
* @param in
* @param arr
* @param i
*/
public static void readIntArray(InputReader in, int[] arr, int i) {
int n = arr.length;
for (int j = i; j < n; j++) {
arr[j] = in.readInt();
}
}
}
}
| Java | ["3", "5"] | 1 second | ["2 9 15", "11 14 20 27 31"] | null | Java 8 | standard input | [
"math"
] | c047040426e736e9085395ed9666135f | The input contains a single integer: n (1ββ€βnββ€β105). | 1,200 | Output a line that contains n space-separated integers a1 a2, ..., an (1ββ€βaiββ€β107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1. If there are multiple solutions you can output any one. | standard output | |
PASSED | afad22929e9dc751e31feef687e2f3b9 | train_000.jsonl | 1372941000 | Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers. A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if: Its elements are in increasing order. That is an inequality aiβ<βaj holds for any two indices i,βj (iβ<βj). For any two indices i and j (iβ<βj), aj must not be divisible by ai. Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements. | 256 megabytes | /*package com.ashutosh.codeforces;*/
import java.io.*;
import java.util.Arrays;
import java.util.InputMismatchException;
/**
* Created by ashutosh on 12/11/16.
*/
public class b327 extends FastIO{
public static void main(String[] args) {
int n = reader.readInt();
getFirtNPrimeNumbers(n);
writer.flush();
writer.close();
}
public static void getFirtNPrimeNumbers(int n) {
int maxVal = 10000000;
boolean[] boolArr = new boolean[maxVal + 1];
Arrays.fill(boolArr, true);
boolArr[1] = false;
for (int i = 2; i * i <= maxVal; i++) {
if (boolArr[i]) {
for (int j = i; j * i <= maxVal; j++) {
boolArr[i*j] = false;
}
}
}
int count = 0;
for (int i = 2; i <= maxVal; i++) {
if (boolArr[i]) {
writer.print(i + " ");
count++;
if (count == n) {
break;
}
}
}
}
}
/**
* Created by ashutosh on 1/11/16.
*/
class FastIO {
public static InputReader reader = new InputReader(System.in);
public static OutputWriter writer = new OutputWriter(System.out);
public static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private InputReader.SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int readInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public String readString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next() {
return readString();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
public static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
public void printLine(Object... objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
public void flush() {
writer.flush();
}
}
public static 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;
}
/**
* Read items into array starting from a given point
* @param in
* @param arr
* @param i
*/
public static void readIntArray(InputReader in, int[] arr, int i) {
int n = arr.length;
for (int j = i; j < n; j++) {
arr[j] = in.readInt();
}
}
}
}
| Java | ["3", "5"] | 1 second | ["2 9 15", "11 14 20 27 31"] | null | Java 8 | standard input | [
"math"
] | c047040426e736e9085395ed9666135f | The input contains a single integer: n (1ββ€βnββ€β105). | 1,200 | Output a line that contains n space-separated integers a1 a2, ..., an (1ββ€βaiββ€β107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1. If there are multiple solutions you can output any one. | standard output | |
PASSED | a552fa586d30e329ec9eabea35bcdd45 | train_000.jsonl | 1372941000 | Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers. A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if: Its elements are in increasing order. That is an inequality aiβ<βaj holds for any two indices i,βj (iβ<βj). For any two indices i and j (iβ<βj), aj must not be divisible by ai. Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements. | 256 megabytes | import org.omg.PortableInterceptor.INACTIVE;
import sun.misc.MessageUtils;
import java.io.*;
import java.math.BigInteger;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.zip.DataFormatException;
import static java.lang.Math.min;
public class MySolution
{
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Task solver = new Task();
solver.solve(1, in, out);
out.close();
}
static class Task
{
public void solve(int testNumber, InputReader sc, PrintWriter out)
{
int n = sc.nextInt();
int finish = (int) 1e7;
int start = finish - n + 1;
for (int i = 0; i < n; i++)
{
System.out.print(start++ + " ");
}
}
}
static long fact (int n)
{
long result = 1;
for (int i = 1; i <= n; i ++){
result = result * i;
}
return result;
}
public static void sort(long[] array)
{
long min = Integer.MAX_VALUE;
long max = Integer.MIN_VALUE;
for (long element : array)
{
if (element < min)
{
min = element;
}
if (element > max)
{
max = element;
}
}
long[] buckets = new long[(int) (max - min + 1)];
for (long element : array)
{
buckets[(int) (element - min)]++;
}
int arrayIndex = 0;
for (int i = 0; i < buckets.length; i++)
{
for (long j = buckets[i]; j > 0; j--)
{
array[arrayIndex++] = i + min;
}
}
}
public static class InputReader {
private boolean finished = false;
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 peek() {
if (numChars == -1) {
return -1;
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
return -1;
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar];
}
public int nextInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public String nextString() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
if (Character.isValidCodePoint(c)) {
res.appendCodePoint(c);
}
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null) {
return filter.isSpaceChar(c);
}
return isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private String readLine0() {
StringBuilder buf = new StringBuilder();
int c = read();
while (c != '\n' && c != -1) {
if (c != '\r') {
buf.appendCodePoint(c);
}
c = read();
}
return buf.toString();
}
public String readLine() {
String s = readLine0();
while (s.trim().length() == 0) {
s = readLine0();
}
return s;
}
public String readLine(boolean ignoreEmptyLines) {
if (ignoreEmptyLines) {
return readLine();
} else {
return readLine0();
}
}
public BigInteger readBigInteger() {
try {
return new BigInteger(nextString());
} catch (NumberFormatException e) {
throw new InputMismatchException();
}
}
public char nextCharacter() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
return (char) c;
}
public double nextDouble() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E') {
return res * Math.pow(10, nextInt());
}
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
}
if (c == '.') {
c = read();
double m = 1;
while (!isSpaceChar(c)) {
if (c == 'e' || c == 'E') {
return res * Math.pow(10, nextInt());
}
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public boolean isExhausted() {
int value;
while (isSpaceChar(value = peek()) && value != -1) {
read();
}
return value == -1;
}
public String next() {
return nextString();
}
public SpaceCharFilter getFilter() {
return filter;
}
public void setFilter(SpaceCharFilter filter) {
this.filter = filter;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
public int[] nextIntArray(int n){
int[] array=new int[n];
for(int i=0;i<n;++i)array[i]=nextInt();
return array;
}
public int[] nextSortedIntArray(int n){
int array[]=nextIntArray(n);
Arrays.sort(array);
return array;
}
public int[] nextSumIntArray(int n){
int[] array=new int[n];
array[0]=nextInt();
for(int i=1;i<n;++i)array[i]=array[i-1]+nextInt();
return array;
}
public long[] nextLongArray(int n){
long[] array=new long[n];
for(int i=0;i<n;++i)array[i]=nextLong();
return array;
}
public long[] nextSumLongArray(int n){
long[] array=new long[n];
array[0]=nextInt();
for(int i=1;i<n;++i)array[i]=array[i-1]+nextInt();
return array;
}
public long[] nextSortedLongArray(int n){
long array[]=nextLongArray(n);
Arrays.sort(array);
return array;
}
}
public 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(char[] array) {
writer.print(array);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
}
public void print(int[] array) {
for (int i = 0; i < array.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(array[i]);
}
}
public void print(double[] array) {
for (int i = 0; i < array.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(array[i]);
}
}
public void print(long[] array) {
for (int i = 0; i < array.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(array[i]);
}
}
public void println(int[] array) {
print(array);
writer.println();
}
public void println(double[] array) {
print(array);
writer.println();
}
public void println(long[] array) {
print(array);
writer.println();
}
public void println() {
writer.println();
}
public void println(Object... objects) {
print(objects);
writer.println();
}
public void print(char i) {
writer.print(i);
}
public void println(char i) {
writer.println(i);
}
public void println(char[] array) {
writer.println(array);
}
public void printf(String format, Object... objects) {
writer.printf(format, objects);
}
public void close() {
writer.close();
}
public void flush() {
writer.flush();
}
public void print(long i) {
writer.print(i);
}
public void println(long i) {
writer.println(i);
}
public void print(int i) {
writer.print(i);
}
public void println(int i) {
writer.println(i);
}
public void separateLines(int[] array) {
for (int i : array) {
println(i);
}
}
}
} | Java | ["3", "5"] | 1 second | ["2 9 15", "11 14 20 27 31"] | null | Java 8 | standard input | [
"math"
] | c047040426e736e9085395ed9666135f | The input contains a single integer: n (1ββ€βnββ€β105). | 1,200 | Output a line that contains n space-separated integers a1 a2, ..., an (1ββ€βaiββ€β107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1. If there are multiple solutions you can output any one. | standard output | |
PASSED | d05c800fe12f2ad6c4f281d34a5838b8 | train_000.jsonl | 1372941000 | Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers. A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if: Its elements are in increasing order. That is an inequality aiβ<βaj holds for any two indices i,βj (iβ<βj). For any two indices i and j (iβ<βj), aj must not be divisible by ai. Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements. | 256 megabytes |
import java.util.Scanner;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Vector;
public class Main
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
for(int i=0;i<n;i++)
{
int t=n*3+i;
System.out.print(t+" ");
}
}
} | Java | ["3", "5"] | 1 second | ["2 9 15", "11 14 20 27 31"] | null | Java 8 | standard input | [
"math"
] | c047040426e736e9085395ed9666135f | The input contains a single integer: n (1ββ€βnββ€β105). | 1,200 | Output a line that contains n space-separated integers a1 a2, ..., an (1ββ€βaiββ€β107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1. If there are multiple solutions you can output any one. | standard output | |
PASSED | ec65cbbc528e9bf0a205ccb2889e6778 | train_000.jsonl | 1372941000 | Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers. A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if: Its elements are in increasing order. That is an inequality aiβ<βaj holds for any two indices i,βj (iβ<βj). For any two indices i and j (iβ<βj), aj must not be divisible by ai. Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements. | 256 megabytes |
import java.util.Arrays;
import static java.util.Arrays.fill;
import java.util.Scanner;
public class Main
{
public static void main(String args[])throws Exception
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
boolean a[]=new boolean[100000001];
fill(a,false);
int count=0;
for(int i=2;i*i<=10000001;i++)
{
if(!a[i])
{
for(int j=i*i;j<=10000000;j+=i)
a[j]=true;
}
}
for(int i=2;i<=10000000;i++)
{
if(a[i]==false)
{
count++;
System.out.print(i+" ");
if(count==n)
break;
}
}
}
}
| Java | ["3", "5"] | 1 second | ["2 9 15", "11 14 20 27 31"] | null | Java 8 | standard input | [
"math"
] | c047040426e736e9085395ed9666135f | The input contains a single integer: n (1ββ€βnββ€β105). | 1,200 | Output a line that contains n space-separated integers a1 a2, ..., an (1ββ€βaiββ€β107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1. If there are multiple solutions you can output any one. | standard output | |
PASSED | 9a689be78f24fe90280d2cb5908db63c | train_000.jsonl | 1372941000 | Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers. A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if: Its elements are in increasing order. That is an inequality aiβ<βaj holds for any two indices i,βj (iβ<βj). For any two indices i and j (iβ<βj), aj must not be divisible by ai. Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements. | 256 megabytes | import java.util.Scanner;
public class HungarySequence {
public static void main(String arg[])
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int a[]=new int[n];
int k=0;
int r=1;
for(int i = n; i < (n << 1); i++)
System.out.print(i + " ");
/*
for(int i=3;i<10000000;i++)
{
k=0;
if(a[n-1]!=0)
{
break;
}
for(int j=2;j<=(i/2);j++)
{
if(i%j==0)
{
k++;
}
}
if(k==0)
{
a[r]=i;
r++;
}
}
for(int i=0;i<n;i++)
{
System.out.print(a[i]+" ");
}
*/
}
}
| Java | ["3", "5"] | 1 second | ["2 9 15", "11 14 20 27 31"] | null | Java 8 | standard input | [
"math"
] | c047040426e736e9085395ed9666135f | The input contains a single integer: n (1ββ€βnββ€β105). | 1,200 | Output a line that contains n space-separated integers a1 a2, ..., an (1ββ€βaiββ€β107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1. If there are multiple solutions you can output any one. | standard output | |
PASSED | 82eb213732599e1f25847c87622f8022 | train_000.jsonl | 1372941000 | Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers. A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if: Its elements are in increasing order. That is an inequality aiβ<βaj holds for any two indices i,βj (iβ<βj). For any two indices i and j (iβ<βj), aj must not be divisible by ai. Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements. | 256 megabytes | import java.util.Scanner;
public class hungrySeq {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
for(int i=n;i<2*n;i++)
{
System.out.print(i+" ");
}
}
}
| Java | ["3", "5"] | 1 second | ["2 9 15", "11 14 20 27 31"] | null | Java 8 | standard input | [
"math"
] | c047040426e736e9085395ed9666135f | The input contains a single integer: n (1ββ€βnββ€β105). | 1,200 | Output a line that contains n space-separated integers a1 a2, ..., an (1ββ€βaiββ€β107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1. If there are multiple solutions you can output any one. | standard output | |
PASSED | 9092ddc546598e236650328e63139bfc | train_000.jsonl | 1372941000 | Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers. A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if: Its elements are in increasing order. That is an inequality aiβ<βaj holds for any two indices i,βj (iβ<βj). For any two indices i and j (iβ<βj), aj must not be divisible by ai. Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements. | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class Main {
// make it false if Multiple test case is not in the question
static boolean multipleTC = false;
int TestCase = 1;
// for pre processing if needed
void pre() throws Exception {
}
public static void main(String[] args) throws Exception {
new Main().run();
}
final int MOD = (int) 1e9 + 7;
// input output handled here
private String solve() throws Exception {
// code
int n = ni();
StringBuilder sb = new StringBuilder("");
long x = 5 * n % MOD;
for (long i = 0; i < n; i++) {
sb.append((x + i) + " ");
}
return sb.toString();
}
void run() throws Exception {
// long start_time = System.nanoTime();
try {
in = new FastReader("in0.txt");
out = new PrintWriter("out0.txt");
} catch (Exception e) {
in = new FastReader();
out = new PrintWriter(System.out);
}
pre();
StringBuilder print = new StringBuilder("");
int T = (multipleTC) ? ni() : 1;
for (int t = 1; t <= T; t++) {
this.TestCase = t;
print.append(solve());
}
p(print);
// long end_time = System.nanoTime();
// System.out.printf("Running Time in sec : %2.10f", (double) (end_time -
// start_time) * (double) 1e-9);
out.flush();
out.close();
}
PrintWriter out;
FastReader in;
void p(Object o) {
out.print(o);
}
void pln(Object o) {
out.println(o);
}
void pnf(Object o) {
out.println(o);
out.flush();
}
void deb(Object x) {
System.out.println("#" + TestCase + " = " + x);
}
void deb2(Object x, Object y) {
System.out.println("#" + TestCase + " = " + x + " , " + y);
}
String n() throws Exception {
return in.next();
}
String nln() throws Exception {
return in.nextLine();
}
int ni() throws Exception {
return Integer.parseInt(in.next());
}
long nl() throws Exception {
return Long.parseLong(in.next());
}
double nd() throws Exception {
return Double.parseDouble(in.next());
}
class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public FastReader(String s) throws Exception {
br = new BufferedReader(new FileReader(s));
}
String next() throws Exception {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
throw new Exception(e.toString());
}
}
return st.nextToken();
}
String nextLine() throws Exception {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
throw new Exception(e.toString());
}
return str;
}
}
} | Java | ["3", "5"] | 1 second | ["2 9 15", "11 14 20 27 31"] | null | Java 8 | standard input | [
"math"
] | c047040426e736e9085395ed9666135f | The input contains a single integer: n (1ββ€βnββ€β105). | 1,200 | Output a line that contains n space-separated integers a1 a2, ..., an (1ββ€βaiββ€β107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1. If there are multiple solutions you can output any one. | standard output | |
PASSED | a3b1ec6c890ad560847c6660a00b0792 | train_000.jsonl | 1372941000 | Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers. A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if: Its elements are in increasing order. That is an inequality aiβ<βaj holds for any two indices i,βj (iβ<βj). For any two indices i and j (iβ<βj), aj must not be divisible by ai. Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class Solution {
public static final double eps = 1e-9;
public static final int mod = 1000000007;
public static final double pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679;
public static final int sievesize = (int) (1e6 + 10);
public static boolean[] prime;
public static final int dx[] = {1, -1, 0, 0};
public static final int dy[] = {0, 0, 1, -1};
public static void main(String[] args) throws IOException {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Task solver = new Task();
solver.solve(1, in, out);
out.close();
}
static class Task {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.nextInt();
for(int i = 0; i < n; i++)
out.print((3 * n + i) + " ");
}
// static class Node {
// int init, goal, value;
// ArrayList<Node> adj = new ArrayList<>();
// public Node(int value) {
// this.value = value;
// }
// }
// static class Pair implements Comparable<Pair> {
//
// int first, second;
//
// public Pair(int parent, int child) {
// this.first = first;
// this.second = second;
// }
//
// @Override
// public int compareTo(Pair o) {
// return 0;
// }
// }
}
// public static boolean triangle(long a, long b, long c){
// return ((a+b) > c && (b+c) >a && (a+c) > b);
// }
//
// public static boolean isPerfectSquare(long n){
// if (n < 0)
// return false;
// long test = (long) (Math.sqrt(n) + 0.5);
// return test*test == n;
// }
//
// public static int isnum(char s){
// if(s=='1' || s=='2' || s=='3' || s=='4' || s=='5' || s=='6' || s=='7' || s=='8' || s=='9' || s=='0')
// return 1;
// return 0;
// }
//
// public static long nextPowerOf2(long n){
// n--;
// n |= n >> 1;
// n |= n >> 2;
// n |= n >> 4;
// n |= n >> 8;
// n |= n >> 16;
// n++;
// return n;
// }
//
// public static long gcd(long a, long b){
// long t;
// while (b > 0){
// a = a%b;
// t = a;
// a = b;
// b = t;
// }
// return a;
// }
//
// public static void sieve(int n){
// prime=new boolean[sievesize+1];
// long x, y;
// ArrayList<Long> arr = new ArrayList<>();
// prime[0] = prime[1] = true;
// for(x = 2; x * x <= sievesize; x++)
// {
// if(!prime[(int) x])
// for(y = x * x; y <= sievesize; y += x)
// prime[(int) y]=true;
// }
// }
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public int[] nextIntArray(int size) {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
int[] arr=new int[size];
for(int i = 0; i < size; i++)
arr[i] = Integer.parseInt(tokenizer.nextToken());
return arr;
}
public long[] nextLongArray(int size) {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
long[] arr=new long[size];
for(int i = 0; i < size; i++)
arr[i] = Long.parseLong(tokenizer.nextToken());
return arr;
}
public double[] nextDoubleArray(int size) {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
double[] arr=new double[size];
for(int i = 0; i < size; i++)
arr[i] = Double.parseDouble(tokenizer.nextToken());
return arr;
}
public String[] nextStringArray(int size) throws IOException {
String[] arr=new String[size];
for(int i = 0; i < size; i++)
arr[i] = reader.readLine();
return arr;
}
public char[] nextCharArray(int size) throws IOException {
char[] arr=reader.readLine().toCharArray();
return arr;
}
}
} | Java | ["3", "5"] | 1 second | ["2 9 15", "11 14 20 27 31"] | null | Java 8 | standard input | [
"math"
] | c047040426e736e9085395ed9666135f | The input contains a single integer: n (1ββ€βnββ€β105). | 1,200 | Output a line that contains n space-separated integers a1 a2, ..., an (1ββ€βaiββ€β107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1. If there are multiple solutions you can output any one. | standard output | |
PASSED | 05d7ef33c9b6c38e8bda065997a79798 | train_000.jsonl | 1372941000 | Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers. A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if: Its elements are in increasing order. That is an inequality aiβ<βaj holds for any two indices i,βj (iβ<βj). For any two indices i and j (iβ<βj), aj must not be divisible by ai. Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.List;
/**
*
*
* @author Code Forces.
*
* Solution by: L.Azuaje.
*
* CF Problem: .
*
*/
public class Main {
public static final String YES = "YES";
public static final String NO = "NO";
public Main() {
}
// Find primes in first 2000 numbers
public int[] find(int k) {
boolean[] primes = new boolean[4000];
Arrays.fill(primes, true);
primes[0] = false;
primes[1] = false;
for (int i = 4; i < primes.length; i = i + 2) {
primes[i] = false;
}
for (int i = 5; i < primes.length; i = i + 2) {
for (int j = 3; j*j <= primes.length; j = j + 2) {
if (i!=j && i%j == 0 ) {
primes[i] = false;
}
}
}
List<Integer> data = new ArrayList<Integer>();
for (int i = 0; i < primes.length; i++) {
if (primes[i]) {
data.add(new Integer(i));
}
}
int count = 0;
int[] array = new int[k];
breakUp: for (int i = 0; i < data.size(); i++) {
for (int j = i; j < data.size(); j++) {
if (count < k) {
array[count++] = data.get(i)*data.get(j);
} else {
break breakUp;
}
}
}
Arrays.sort(array);
return array;
}
public static void main(String[] args) throws IOException {
FastInputReader scanner = new FastInputReader();
PrintStream out = System.out;
Main main = new Main();
int n = scanner.nextInt();
int[] array = main.find(n);
for (int p: array) {
out.print(p + " ");
}
out.println();
out.close();
}
// -----------MyScanner class for faster input----------
public static class FastInputReader {
private byte[] buf = new byte[16384];
private int curChar;
private int numChars;
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = System.in.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public String nextLine() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c));
return res.toString();
}
public String nextString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public long nextLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public int nextInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public int[] nextIntArray(int n) {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = nextInt();
}
return arr;
}
public Integer[] nextIntegerArray(int n) {
Integer[] arr = new Integer[n];
for (int i = 0; i < n; i++) {
arr[i] = nextInt();
}
return arr;
}
public long[] nextLongArray(int n) {
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = nextLong();
}
return arr;
}
private boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
}
public static class MyScanner {
BufferedReader reader;
public MyScanner() {
this.reader = new BufferedReader(new InputStreamReader(System.in));
}
public void close() throws IOException {
this.reader.close();
}
int nextInt() {
return Integer.parseInt(this.next());
}
long nextLong() {
return Long.parseLong(this.next());
}
float nextFloat() {
return Float.parseFloat(this.next());
}
double nextDouble() {
return Double.parseDouble(this.next());
}
String next() {
String str = "";
try {
str = this.reader.readLine().trim();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
String[] nextStringArray() {
String[] str = null;
try {
str = this.reader.readLine().trim().split(" ");
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
int[] nextIntArray() {
String[] data = nextStringArray();
int[] a = new int[data.length];
for (int i = 0; i < a.length; i++) {
a[i] = Integer.parseInt(data[i]);
}
return a;
}
Integer[] nextIntegerArray() {
String[] data = nextStringArray();
Integer[] a = new Integer[data.length];
for (int i = 0; i < a.length; i++) {
a[i] = Integer.parseInt(data[i]);
}
return a;
}
long[] nextLongArray() {
String[] data = nextStringArray();
long[] a = new long[data.length];
for (int i = 0; i < a.length; i++) {
a[i] = Long.parseLong(data[i]);
}
return a;
}
float[] nextFloatArray() {
String[] data = nextStringArray();
float[] a = new float[data.length];
for (int i = 0; i < a.length; i++) {
a[i] = Float.parseFloat(data[i]);
}
return a;
}
double[] nextDoubleArray() {
String[] data = nextStringArray();
double[] a = new double[data.length];
for (int i = 0; i < a.length; i++) {
a[i] = Double.parseDouble(data[i]);
}
return a;
}
}
}
| Java | ["3", "5"] | 1 second | ["2 9 15", "11 14 20 27 31"] | null | Java 8 | standard input | [
"math"
] | c047040426e736e9085395ed9666135f | The input contains a single integer: n (1ββ€βnββ€β105). | 1,200 | Output a line that contains n space-separated integers a1 a2, ..., an (1ββ€βaiββ€β107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1. If there are multiple solutions you can output any one. | standard output | |
PASSED | b25132d26a01bb7cff9f008e93779ce7 | train_000.jsonl | 1372941000 | Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers. A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if: Its elements are in increasing order. That is an inequality aiβ<βaj holds for any two indices i,βj (iβ<βj). For any two indices i and j (iβ<βj), aj must not be divisible by ai. Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements. | 256 megabytes | import java.util.*;
public class bucky{
public static void main (String args[]) {
Scanner input=new Scanner(System.in);
HashMap<Integer, Integer> map1= new HashMap<Integer, Integer>();
HashMap<Integer, Integer> map2= new HashMap<Integer, Integer>();
HashMap<String, Integer> scazut= new HashMap<String, Integer>();
HashMap<Integer, Integer> linieright= new HashMap<Integer, Integer>();
int n =input.nextInt();
for(int i=n; i<2*n;i++) System.out.print(i+" ");
}
}
| Java | ["3", "5"] | 1 second | ["2 9 15", "11 14 20 27 31"] | null | Java 8 | standard input | [
"math"
] | c047040426e736e9085395ed9666135f | The input contains a single integer: n (1ββ€βnββ€β105). | 1,200 | Output a line that contains n space-separated integers a1 a2, ..., an (1ββ€βaiββ€β107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1. If there are multiple solutions you can output any one. | standard output | |
PASSED | 90de5681705649eaf6ad92d1dd9df9c8 | train_000.jsonl | 1372941000 | Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers. A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if: Its elements are in increasing order. That is an inequality aiβ<βaj holds for any two indices i,βj (iβ<βj). For any two indices i and j (iβ<βj), aj must not be divisible by ai. Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
public class CodeForces_327B {
public static void main(String[] args) throws NumberFormatException,
IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(bf.readLine());
boolean[] isPrime = new boolean[(int) 1e7+1];
PrintWriter st = new PrintWriter(System.out);
int c = 0;
for (int factor = 2; factor <= (int) 1e7; factor++) {
if (!isPrime[factor]) {
//System.out.println(factor);
st.append(factor+" ");++c;//System.out.println(st);
if(c==n)break;
for (int j = factor; 1L*factor*j <= (int) 1e7 ; j++) {
isPrime[factor*j] = true;
}
}
}
//System.err.println(c);
st.flush();st.close();
}
} | Java | ["3", "5"] | 1 second | ["2 9 15", "11 14 20 27 31"] | null | Java 8 | standard input | [
"math"
] | c047040426e736e9085395ed9666135f | The input contains a single integer: n (1ββ€βnββ€β105). | 1,200 | Output a line that contains n space-separated integers a1 a2, ..., an (1ββ€βaiββ€β107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1. If there are multiple solutions you can output any one. | standard output | |
PASSED | ec819e87b878810671bba80b7c1e10ee | train_000.jsonl | 1372941000 | Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers. A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if: Its elements are in increasing order. That is an inequality aiβ<βaj holds for any two indices i,βj (iβ<βj). For any two indices i and j (iβ<βj), aj must not be divisible by ai. Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
import java.util.Map.*;
public class j {
public static void prime(int n) {
boolean[] prime = new boolean[100000007];
int count = 0;
StringBuilder sb = new StringBuilder();
for(int i=2;i<100000007;i++) {
if(prime[i]==false) {
sb.append(i+" ");count++;
if(count==n)break;
for(int j=i*2;j<100000007;j+=i) {
prime[j] = true;
}
}
}
System.out.println(sb);
}
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
StringBuilder sb = new StringBuilder();
for(int i=0;i<n;i++) {
sb.append((3*n+i)+" ");
}
System.out.println(sb);
}
} | Java | ["3", "5"] | 1 second | ["2 9 15", "11 14 20 27 31"] | null | Java 8 | standard input | [
"math"
] | c047040426e736e9085395ed9666135f | The input contains a single integer: n (1ββ€βnββ€β105). | 1,200 | Output a line that contains n space-separated integers a1 a2, ..., an (1ββ€βaiββ€β107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1. If there are multiple solutions you can output any one. | standard output | |
PASSED | 5c8bd4204ce0d8f7a8c3d377396e464d | train_000.jsonl | 1372941000 | Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers. A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if: Its elements are in increasing order. That is an inequality aiβ<βaj holds for any two indices i,βj (iβ<βj). For any two indices i and j (iβ<βj), aj must not be divisible by ai. Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements. | 256 megabytes | import java.util.*;
import java.io.*;
import static java.lang.Math.*;
public class Main {
FastIO io;
// File names!!!
void solve() throws IOException {
int n = io.nextInt();
for (int i = 0; i < n; i++) {
io.print(i + 100001);
io.print(" ");
}
}
void run() {
try {
io = new FastIO();
solve();
io.close();
} catch (Exception e) {
e.printStackTrace();
System.exit(abs(-1));
}
}
public static void main(String[] args) {
try {
Locale.setDefault(Locale.US);
} catch (Exception ignore) {
}
new Main().run();
}
class FastIO extends PrintWriter {
private BufferedReader in;
private StringTokenizer stok;
FastIO() {
super(System.out);
in = new BufferedReader(new InputStreamReader(System.in));
}
FastIO(String s) throws FileNotFoundException {
super("".equals(s) ? "output.txt" : s + ".out");
in = new BufferedReader(new FileReader("".equals(s) ? "input.txt" : s + ".in"));
}
public void close() {
super.close();
try {
in.close();
} catch (IOException ignored) {
}
}
String next() {
while (stok == null || !stok.hasMoreTokens()) {
try {
stok = new StringTokenizer(in.readLine());
} catch (Exception e) {
return null;
}
}
return stok.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
try {
return in.readLine();
} catch (IOException e) {
return null;
}
}
char[] nextCharArray() {
return next().toCharArray();
}
}
} | Java | ["3", "5"] | 1 second | ["2 9 15", "11 14 20 27 31"] | null | Java 8 | standard input | [
"math"
] | c047040426e736e9085395ed9666135f | The input contains a single integer: n (1ββ€βnββ€β105). | 1,200 | Output a line that contains n space-separated integers a1 a2, ..., an (1ββ€βaiββ€β107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1. If there are multiple solutions you can output any one. | standard output | |
PASSED | 0237c15e303f6d8d60353dc72d8173eb | train_000.jsonl | 1372941000 | Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers. A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if: Its elements are in increasing order. That is an inequality aiβ<βaj holds for any two indices i,βj (iβ<βj). For any two indices i and j (iβ<βj), aj must not be divisible by ai. Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements. | 256 megabytes | import java.util.*;
import java.io.*;
import static java.lang.Math.*;
public class Main {
FastIO io;
// File names!!!
void solve() throws IOException {
int n = io.nextInt();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
sb.append(i + 100001);
sb.append(" ");
}
io.println(sb.toString());
}
void run() {
try {
io = new FastIO();
solve();
io.close();
} catch (Exception e) {
e.printStackTrace();
System.exit(abs(-1));
}
}
public static void main(String[] args) {
try {
Locale.setDefault(Locale.US);
} catch (Exception ignore) {
}
new Main().run();
}
class FastIO extends PrintWriter {
private BufferedReader in;
private StringTokenizer stok;
FastIO() {
super(System.out);
in = new BufferedReader(new InputStreamReader(System.in));
}
FastIO(String s) throws FileNotFoundException {
super("".equals(s) ? "output.txt" : s + ".out");
in = new BufferedReader(new FileReader("".equals(s) ? "input.txt" : s + ".in"));
}
public void close() {
super.close();
try {
in.close();
} catch (IOException ignored) {
}
}
String next() {
while (stok == null || !stok.hasMoreTokens()) {
try {
stok = new StringTokenizer(in.readLine());
} catch (Exception e) {
return null;
}
}
return stok.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
try {
return in.readLine();
} catch (IOException e) {
return null;
}
}
char[] nextCharArray() {
return next().toCharArray();
}
}
} | Java | ["3", "5"] | 1 second | ["2 9 15", "11 14 20 27 31"] | null | Java 8 | standard input | [
"math"
] | c047040426e736e9085395ed9666135f | The input contains a single integer: n (1ββ€βnββ€β105). | 1,200 | Output a line that contains n space-separated integers a1 a2, ..., an (1ββ€βaiββ€β107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1. If there are multiple solutions you can output any one. | standard output | |
PASSED | 58f5fde38554e2e802c01c5a6c683acf | train_000.jsonl | 1372941000 | Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers. A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if: Its elements are in increasing order. That is an inequality aiβ<βaj holds for any two indices i,βj (iβ<βj). For any two indices i and j (iβ<βj), aj must not be divisible by ai. Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements. | 256 megabytes |
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
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.HashSet;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
public class Solution {
// ----------------------------------------------------------------------------
static class Task {
public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
int n = in.nextInt();
int count = 0;
boolean[] arr = sieveOfEratosthenes(10000001);
for (int i = 2; i < 10000001; i++) {
if (arr[i]) {
out.print(i + " ");
count++;
if (count == n) {
break;
}
}
}
}
}
// ----------------------------------------------------------------------------
// IMPORTANT || COMMON METHODS
// PAIR
static boolean[] sieveOfEratosthenes(int n) {
// Create a boolean array "prime[0..n]" and initialize
// all entries it as true. A value in prime[i] will
// finally be false if i is Not a prime, else true.
boolean prime[] = new boolean[n + 1];
for (int i = 0; i < n; i++) {
prime[i] = true;
}
for (int p = 2; p * p <= n; p++) {
// If prime[p] is not changed, then it is a prime
if (prime[p] == true) {
// Update all multiples of p
for (int i = p * 2; i <= n; i += p) {
prime[i] = false;
}
}
}
// Print all prime numbers
return prime;
}
static class Pair {
int x;
int y;
// Constructor
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
// how to initialize
// Pair level[] = new Pair[n];
// for (int i = 0; i < n; i++) {
// int x = in.nextInt();
// int y = in.nextInt();
//
// level[i] = new Pair(x, y);
//
// }
// How to sort
// PairSort ps = new PairSort();
// ps.sort(level, 1);
}
static class PairSort {
Pair[] sort(Pair arr[], int i) {
// Comparator to sort the pair according to second element
Arrays.sort(arr, new Comparator<Pair>() {
@Override
public int compare(Pair p1, Pair p2) {
// 1 sees the first elements ans sorts them in increasing order
// 2 sees the second elements ans sorts them in increasing order
// 3 sees the first elements ans sorts them in decreasing order
// 4 sees the second elements ans sorts them in decreasing order
switch (i) {
case 2:
return p1.y - p2.y;
case 1:
return p1.x - p2.x;
case 4:
return p2.y - p1.y;
default:
return p2.x - p1.x;
}
}
});
return arr;
}
}
// GCD || HCF
static long GCD(long x, long y) {
return y == 0 ? x : GCD(y, x % y);
}
// LCM
static long LCM(long a, long b) {
return (a * b) / GCD(a, b);
}
// Returns the divisors of a number
static ArrayList Divisors(long n) {
ArrayList<Long> div = new ArrayList<>();
for (long i = 1; i <= Math.sqrt(n); i++) {
if (n % i == 0) {
div.add(i);
if (n / i != i) {
div.add(n / i);
}
}
}
return div;
}
// PERMUTATIONS
static void permute(int[] a, int k) {
if (k == a.length) {
for (int i = 0; i < k; i++) {
System.out.print(a[i] + " ");
}
System.out.println("");
} else {
for (int i = k; i < a.length; i++) {
int temp = a[k];
a[k] = a[i];
a[i] = temp;
permute(a, k + 1);
// swapping a[k] and a[i] .
temp = a[k];
a[k] = a[i];
a[i] = temp;
}
}
// How to run
//int seq[] = {1, 19, 6}; .. let seq be the array of numbers to be permuted
//permute(seq, 0); // call this function .
//0 -> all permutations ( permutation start from 1st number)
//1-> permutations start from 2nd number
//2-> permutation start from 3rd number
// n-1 that array will be returned
}
// ----------------------------------------------------------------------------
// MAIN - INPUT - OUTPUT
public static void main(String[] args) throws IOException {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Task solver = new Task();
solver.solve(1, in, out);
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 nextInt() {
return Integer.parseInt(next());
}
public Double nextDouble() {
return Double.parseDouble(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public int[] nextIntArray(int arraySize) {
int array[] = new int[arraySize];
for (int i = 0; i < arraySize; i++) {
array[i] = nextInt();
}
return array;
}
}
}
// to take the string as a single character each . do this.
/* BufferedReader inn = new BufferedReader(new InputStreamReader(System.in));
char[] s1 = inn.readLine().toCharArray();
// for going through each ch in ch array
for (char c : s1) {
if (c != ' ') {
}
}
*/
| Java | ["3", "5"] | 1 second | ["2 9 15", "11 14 20 27 31"] | null | Java 8 | standard input | [
"math"
] | c047040426e736e9085395ed9666135f | The input contains a single integer: n (1ββ€βnββ€β105). | 1,200 | Output a line that contains n space-separated integers a1 a2, ..., an (1ββ€βaiββ€β107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1. If there are multiple solutions you can output any one. | standard output | |
PASSED | ebb9a876691744ef648b4fdfe72fdf69 | train_000.jsonl | 1372941000 | Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers. A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if: Its elements are in increasing order. That is an inequality aiβ<βaj holds for any two indices i,βj (iβ<βj). For any two indices i and j (iβ<βj), aj must not be divisible by ai. Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements. | 256 megabytes |
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
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.HashSet;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
//FOR SPOJ
// remember it is class . not public class or it won't get submitted
public class Solution {
// ----------------------------------------------------------------------------
static class Task {
public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
int n = in.nextInt();
for (int i = 100000; i < n + 100000; i++) {
out.print(i + " ");
}
}
}
// ----------------------------------------------------------------------------
// IMPORTANT || COMMON METHODS
// PAIR
static class Pair {
int x;
int y;
// Constructor
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
// how to initialize
// Pair level[] = new Pair[n];
// for (int i = 0; i < n; i++) {
// int x = in.nextInt();
// int y = in.nextInt();
//
// level[i] = new Pair(x, y);
//
// }
// How to sort
// PairSort ps = new PairSort();
// ps.sort(level, 1);
}
static class PairSort {
Pair[] sort(Pair arr[], int i) {
// Comparator to sort the pair according to second element
Arrays.sort(arr, new Comparator<Pair>() {
@Override
public int compare(Pair p1, Pair p2) {
// 1 sees the first elements ans sorts them in increasing order
// 2 sees the second elements ans sorts them in increasing order
// 3 sees the first elements ans sorts them in decreasing order
// 4 sees the second elements ans sorts them in decreasing order
switch (i) {
case 2:
return p1.y - p2.y;
case 1:
return p1.x - p2.x;
case 4:
return p2.y - p1.y;
default:
return p2.x - p1.x;
}
}
});
return arr;
}
}
// GCD || HCF
static long GCD(long x, long y) {
return y == 0 ? x : GCD(y, x % y);
}
// LCM
static long LCM(long a, long b) {
return (a * b) / GCD(a, b);
}
// Returns the divisors of a number
static ArrayList Divisors(long n) {
ArrayList<Long> div = new ArrayList<>();
for (long i = 1; i <= Math.sqrt(n); i++) {
if (n % i == 0) {
div.add(i);
if (n / i != i) {
div.add(n / i);
}
}
}
return div;
}
// PERMUTATIONS
static void permute(int[] a, int k) {
if (k == a.length) {
for (int i = 0; i < k; i++) {
System.out.print(a[i] + " ");
}
System.out.println("");
} else {
for (int i = k; i < a.length; i++) {
int temp = a[k];
a[k] = a[i];
a[i] = temp;
permute(a, k + 1);
// swapping a[k] and a[i] .
temp = a[k];
a[k] = a[i];
a[i] = temp;
}
}
// How to run
//int seq[] = {1, 19, 6}; .. let seq be the array of numbers to be permuted
//permute(seq, 0); // call this function .
//0 -> all permutations ( permutation start from 1st number)
//1-> permutations start from 2nd number
//2-> permutation start from 3rd number
// n-1 that array will be returned
}
// ----------------------------------------------------------------------------
// MAIN - INPUT - OUTPUT
public static void main(String[] args) throws IOException {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Task solver = new Task();
solver.solve(1, in, out);
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 nextInt() {
return Integer.parseInt(next());
}
public Double nextDouble() {
return Double.parseDouble(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public int[] nextIntArray(int arraySize) {
int array[] = new int[arraySize];
for (int i = 0; i < arraySize; i++) {
array[i] = nextInt();
}
return array;
}
}
}
// to take the string as a single character each . do this.
/* BufferedReader inn = new BufferedReader(new InputStreamReader(System.in));
char[] s1 = inn.readLine().toCharArray();
// for going through each ch in ch array
for (char c : s1) {
if (c != ' ') {
}
}
*/
| Java | ["3", "5"] | 1 second | ["2 9 15", "11 14 20 27 31"] | null | Java 8 | standard input | [
"math"
] | c047040426e736e9085395ed9666135f | The input contains a single integer: n (1ββ€βnββ€β105). | 1,200 | Output a line that contains n space-separated integers a1 a2, ..., an (1ββ€βaiββ€β107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1. If there are multiple solutions you can output any one. | standard output | |
PASSED | 7cb81e7976264104f86c139682b1a655 | train_000.jsonl | 1372941000 | Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers. A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if: Its elements are in increasing order. That is an inequality aiβ<βaj holds for any two indices i,βj (iβ<βj). For any two indices i and j (iβ<βj), aj must not be divisible by ai. Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.StringTokenizer;
import java.util.TreeSet;
public class Hungry_Sequence {
// http://codeforces.com/problemset/problem/327/B
public static void main(String[] args) throws IOException {
scanner sc=new scanner();
int n=sc.nextInt();
for(int i=0;i<n;i++) {
System.out.print(3*n+i+" ");
}
}
static class scanner{
BufferedReader br;
StringTokenizer st;
scanner (){
br=new BufferedReader(new InputStreamReader(System.in));
}
String next() throws IOException {
while(st==null||!st.hasMoreTokens())
st=new StringTokenizer(br.readLine());
return st.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
long nextLong() throws IOException {
return Long.parseLong(next());
}
}
}
| Java | ["3", "5"] | 1 second | ["2 9 15", "11 14 20 27 31"] | null | Java 8 | standard input | [
"math"
] | c047040426e736e9085395ed9666135f | The input contains a single integer: n (1ββ€βnββ€β105). | 1,200 | Output a line that contains n space-separated integers a1 a2, ..., an (1ββ€βaiββ€β107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1. If there are multiple solutions you can output any one. | standard output | |
PASSED | 615f247e019792475657638da2565fb3 | train_000.jsonl | 1372941000 | Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers. A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if: Its elements are in increasing order. That is an inequality aiβ<βaj holds for any two indices i,βj (iβ<βj). For any two indices i and j (iβ<βj), aj must not be divisible by ai. Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements. | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.*;
public class Hungry_Sequence
{
public static void main(String args[]) throws Exception
{
BufferedReader f=new BufferedReader(new InputStreamReader(System.in));
int num=Integer.parseInt(f.readLine());
for(int x=0;x<num;x++)
if(x==0)
System.out.print(x+5000000);
else
System.out.print(" "+(x+5000000));
System.out.println();
}
} | Java | ["3", "5"] | 1 second | ["2 9 15", "11 14 20 27 31"] | null | Java 8 | standard input | [
"math"
] | c047040426e736e9085395ed9666135f | The input contains a single integer: n (1ββ€βnββ€β105). | 1,200 | Output a line that contains n space-separated integers a1 a2, ..., an (1ββ€βaiββ€β107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1. If there are multiple solutions you can output any one. | standard output | |
PASSED | 0f4e75e4aed128d490ce8d24e656dfea | train_000.jsonl | 1372941000 | Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers. A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if: Its elements are in increasing order. That is an inequality aiβ<βaj holds for any two indices i,βj (iβ<βj). For any two indices i and j (iβ<βj), aj must not be divisible by ai. Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements. | 256 megabytes | import java.util.Scanner;
public class a2oj {
private static final Scanner scan = new Scanner(System.in);
public static void main(String[] args) {
int n = scan.nextInt();
int[] result = new int[n];
int last = 10000000;
for (int i = n-1; i >= 0; i--) {
result[i] = --last;
}
for (int i = 0; i < n; i++) {
System.out.print(result[i]+" ");
}
}
} | Java | ["3", "5"] | 1 second | ["2 9 15", "11 14 20 27 31"] | null | Java 8 | standard input | [
"math"
] | c047040426e736e9085395ed9666135f | The input contains a single integer: n (1ββ€βnββ€β105). | 1,200 | Output a line that contains n space-separated integers a1 a2, ..., an (1ββ€βaiββ€β107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1. If there are multiple solutions you can output any one. | standard output | |
PASSED | e0c1a27379c719d081f4f0044a03fb07 | train_000.jsonl | 1372941000 | Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers. A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if: Its elements are in increasing order. That is an inequality aiβ<βaj holds for any two indices i,βj (iβ<βj). For any two indices i and j (iβ<βj), aj must not be divisible by ai. Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements. | 256 megabytes | import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
public class HungrySequence {
public static void main(String[] args) {
InputReader in = new InputReader();
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
solve(in, out);
out.close();
}
public static void solve(InputReader in, PrintWriter out) {
int n=in.nextInt();
int arr[]=new int[10000002];
Arrays.fill(arr,1);
arr[0]=arr[1]=0;
int count=0;
for(int i=2;i<=10000000;i++)
{
if(arr[i]==1)
{
out.print(i+" ");
count++;
if(count==n)
return;
for(int j=i*2;j<=10000000;j=j+i)
{
arr[j]=0;
}
}
}
}
static class InputReader {
private byte[] buf = new byte[16384];
private int curChar;
private int numChars;
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = System.in.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public String nextLine() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c));
return res.toString();
}
public String nextString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public long nextLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public int nextInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public int[] nextIntArray(int n) {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = nextInt();
}
return arr;
}
public long[] nextLongArray(int n) {
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = nextLong();
}
return arr;
}
private boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
}
}
| Java | ["3", "5"] | 1 second | ["2 9 15", "11 14 20 27 31"] | null | Java 8 | standard input | [
"math"
] | c047040426e736e9085395ed9666135f | The input contains a single integer: n (1ββ€βnββ€β105). | 1,200 | Output a line that contains n space-separated integers a1 a2, ..., an (1ββ€βaiββ€β107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1. If there are multiple solutions you can output any one. | standard output | |
PASSED | 15472fbfefdb85c174313739efe3e053 | train_000.jsonl | 1372941000 | Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers. A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if: Its elements are in increasing order. That is an inequality aiβ<βaj holds for any two indices i,βj (iβ<βj). For any two indices i and j (iβ<βj), aj must not be divisible by ai. Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements. | 256 megabytes | import java.util.Scanner;
public class A327 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
for (int i = n*5; i < n*6; i++) {
System.out.print(i + " ");
}
}
}
| Java | ["3", "5"] | 1 second | ["2 9 15", "11 14 20 27 31"] | null | Java 8 | standard input | [
"math"
] | c047040426e736e9085395ed9666135f | The input contains a single integer: n (1ββ€βnββ€β105). | 1,200 | Output a line that contains n space-separated integers a1 a2, ..., an (1ββ€βaiββ€β107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1. If there are multiple solutions you can output any one. | standard output | |
PASSED | ff43cb135ff7bddfb336ec03ddf05ac9 | train_000.jsonl | 1372941000 | Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers. A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if: Its elements are in increasing order. That is an inequality aiβ<βaj holds for any two indices i,βj (iβ<βj). For any two indices i and j (iβ<βj), aj must not be divisible by ai. Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements. | 256 megabytes |
import java.util.Scanner;
public class HungrySequence {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
int n=scan.nextInt();
for(int i=0;i<n;i++) {
System.out.print(2*n+i+" ");
}
}
}
| Java | ["3", "5"] | 1 second | ["2 9 15", "11 14 20 27 31"] | null | Java 8 | standard input | [
"math"
] | c047040426e736e9085395ed9666135f | The input contains a single integer: n (1ββ€βnββ€β105). | 1,200 | Output a line that contains n space-separated integers a1 a2, ..., an (1ββ€βaiββ€β107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1. If there are multiple solutions you can output any one. | standard output | |
PASSED | e7650d28e88918bab350f95844184d6b | train_000.jsonl | 1372941000 | Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers. A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if: Its elements are in increasing order. That is an inequality aiβ<βaj holds for any two indices i,βj (iβ<βj). For any two indices i and j (iβ<βj), aj must not be divisible by ai. Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements. | 256 megabytes | /* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public final class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
//int arr[]=new int[100001];
int x=10000000-n-1;
for(int i=0;i<n;i++)
{
System.out.print(x+" ");
x++;
}
}
} | Java | ["3", "5"] | 1 second | ["2 9 15", "11 14 20 27 31"] | null | Java 8 | standard input | [
"math"
] | c047040426e736e9085395ed9666135f | The input contains a single integer: n (1ββ€βnββ€β105). | 1,200 | Output a line that contains n space-separated integers a1 a2, ..., an (1ββ€βaiββ€β107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1. If there are multiple solutions you can output any one. | standard output | |
PASSED | 4f8ef034190690c2dba564fe6ff1da91 | train_000.jsonl | 1372941000 | Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers. A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if: Its elements are in increasing order. That is an inequality aiβ<βaj holds for any two indices i,βj (iβ<βj). For any two indices i and j (iβ<βj), aj must not be divisible by ai. Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements. | 256 megabytes | import java.util.Scanner;
import java.util.Arrays;
import java.io.PrintWriter;
public class Main {
private static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
PrintWriter out = new PrintWriter(System.out);
boolean[] arr = new boolean[10000001];
for(int p = 2; p*p <= 10000000; p++)
{
if(arr[p] == false)
{
for(int i = p*2; i <= 10000000; i += p)
arr[i] = true;
}
}
int n;
n = scanner.nextInt();
for (int i = 2; i < arr.length; i++) {
if(arr[i] == false) {
if(n-- == 0)
break;
out.print(i + " ");
}
}
out.close();
}
} | Java | ["3", "5"] | 1 second | ["2 9 15", "11 14 20 27 31"] | null | Java 8 | standard input | [
"math"
] | c047040426e736e9085395ed9666135f | The input contains a single integer: n (1ββ€βnββ€β105). | 1,200 | Output a line that contains n space-separated integers a1 a2, ..., an (1ββ€βaiββ€β107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1. If there are multiple solutions you can output any one. | standard output | |
PASSED | 5979b826b390a7ff11f3be610facf98c | train_000.jsonl | 1372941000 | Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers. A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if: Its elements are in increasing order. That is an inequality aiβ<βaj holds for any two indices i,βj (iβ<βj). For any two indices i and j (iβ<βj), aj must not be divisible by ai. Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements. | 256 megabytes | import java.util.Scanner;
import java.util.Arrays;
import java.io.PrintWriter;
public class Main {
private static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
// PrintWriter out = new PrintWriter(System.out);
int n;
n = scanner.nextInt();
for(int i = 0; i < n; i++) {
System.out.print(((3 * n) + i) + " ");
}
// out.close();
}
} | Java | ["3", "5"] | 1 second | ["2 9 15", "11 14 20 27 31"] | null | Java 8 | standard input | [
"math"
] | c047040426e736e9085395ed9666135f | The input contains a single integer: n (1ββ€βnββ€β105). | 1,200 | Output a line that contains n space-separated integers a1 a2, ..., an (1ββ€βaiββ€β107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1. If there are multiple solutions you can output any one. | standard output | |
PASSED | 6d8ebca5bc59588549e4191a999d2f86 | train_000.jsonl | 1372941000 | Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers. A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if: Its elements are in increasing order. That is an inequality aiβ<βaj holds for any two indices i,βj (iβ<βj). For any two indices i and j (iβ<βj), aj must not be divisible by ai. Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements. | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.*;
public class A {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = sc.nextInt();
for(int i = 0; i < n; ++i)
out.print(10000000 - (n - i) + " ");
out.flush();
out.close();
sc.close();
}
} | Java | ["3", "5"] | 1 second | ["2 9 15", "11 14 20 27 31"] | null | Java 8 | standard input | [
"math"
] | c047040426e736e9085395ed9666135f | The input contains a single integer: n (1ββ€βnββ€β105). | 1,200 | Output a line that contains n space-separated integers a1 a2, ..., an (1ββ€βaiββ€β107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1. If there are multiple solutions you can output any one. | standard output | |
PASSED | 8bd03398dd16d0a2e2e551a431332b1e | train_000.jsonl | 1372941000 | Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers. A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if: Its elements are in increasing order. That is an inequality aiβ<βaj holds for any two indices i,βj (iβ<βj). For any two indices i and j (iβ<βj), aj must not be divisible by ai. Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements. | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.*;
public class A {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = sc.nextInt();
for(int i = 0; i < n; ++i)
out.print(10000000 - n + i + " ");
out.flush();
out.close();
sc.close();
}
} | Java | ["3", "5"] | 1 second | ["2 9 15", "11 14 20 27 31"] | null | Java 8 | standard input | [
"math"
] | c047040426e736e9085395ed9666135f | The input contains a single integer: n (1ββ€βnββ€β105). | 1,200 | Output a line that contains n space-separated integers a1 a2, ..., an (1ββ€βaiββ€β107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1. If there are multiple solutions you can output any one. | standard output | |
PASSED | ac2e7cca37d762f7b4c7ea4ea93ed796 | train_000.jsonl | 1372941000 | Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers. A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if: Its elements are in increasing order. That is an inequality aiβ<βaj holds for any two indices i,βj (iβ<βj). For any two indices i and j (iβ<βj), aj must not be divisible by ai. Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements. | 256 megabytes | import java.io.*;
import java.util.*;
import static java.lang.Math.sqrt;
public class problem {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));
int n = Integer.parseInt(reader.readLine());
boolean[] sieve = new boolean[1300000];
Arrays.fill(sieve, true);
for (int i = 2; i <= sqrt(sieve.length); i++) {
if (sieve[i]) {
for (int k = i * i; k < sieve.length; k += i) {
sieve[k] = false;
}
}
}
int index = 2;
int count = 0;
while (count < n) {
if (sieve[index]) {
writer.print(index + " ");
count++;
}
index++;
}
writer.close();
}
}
| Java | ["3", "5"] | 1 second | ["2 9 15", "11 14 20 27 31"] | null | Java 8 | standard input | [
"math"
] | c047040426e736e9085395ed9666135f | The input contains a single integer: n (1ββ€βnββ€β105). | 1,200 | Output a line that contains n space-separated integers a1 a2, ..., an (1ββ€βaiββ€β107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1. If there are multiple solutions you can output any one. | standard output | |
PASSED | 96b1a88801c4dbaa6893c424616f7d5b | train_000.jsonl | 1580826900 | There is a robot on a coordinate plane. Initially, the robot is located at the point $$$(0, 0)$$$. Its path is described as a string $$$s$$$ of length $$$n$$$ consisting of characters 'L', 'R', 'U', 'D'.Each of these characters corresponds to some move: 'L' (left): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x - 1, y)$$$; 'R' (right): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x + 1, y)$$$; 'U' (up): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y + 1)$$$; 'D' (down): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y - 1)$$$. The company that created this robot asked you to optimize the path of the robot somehow. To do this, you can remove any non-empty substring of the path. But this company doesn't want their customers to notice the change in the robot behavior. It means that if before the optimization the robot ended its path at the point $$$(x_e, y_e)$$$, then after optimization (i.e. removing some single substring from $$$s$$$) the robot also ends its path at the point $$$(x_e, y_e)$$$.This optimization is a low-budget project so you need to remove the shortest possible non-empty substring to optimize the robot's path such that the endpoint of his path doesn't change. It is possible that you can't optimize the path. Also, it is possible that after the optimization the target path is an empty string (i.e. deleted substring is the whole string $$$s$$$).Recall that the substring of $$$s$$$ is such string that can be obtained from $$$s$$$ by removing some amount of characters (possibly, zero) from the prefix and some amount of characters (possibly, zero) from the suffix. For example, the substrings of "LURLLR" are "LU", "LR", "LURLLR", "URL", but not "RR" and "UL".You have to answer $$$t$$$ independent test cases. | 256 megabytes | // #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
import java.io.*;
import java.util.*;
import static java.lang.Math.*;
public class Main {
static int infi = Integer.MAX_VALUE / 2, mod = (int) (1e9 + 7), maxn = (int) 1e5;
static long infl = Long.MAX_VALUE / 2;
public static void main(String[] args) throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
int t = nextInt();
for (int t123 = 0; t123 < t; t123++) {
int n = nextInt();
char[] a = next().toCharArray();
TreeMap<f, Integer> was = new TreeMap<>(new Comparator<f>() {
@Override
public int compare(f o1, f o2) {
if (o1.x != o2.x)
return Integer.compare(o1.x, o2.x);
return Integer.compare(o1.y, o2.y);
}
});
int x = 0;
int y = 0;
int ind = 1;
was.put(new f(0, 0), 0);
int ans = infi;
int ansl = 0, ansr = 0;
for (char i : a) {
if (i == 'L') {
x--;
}
if (i == 'R') {
x++;
}
if (i == 'D') {
y--;
}
if (i == 'U') {
y++;
}
f now = new f(x, y);
if (was.containsKey(now)) {
if (ans > ind - was.get(now)) {
ans = ind - was.get(now);
ansl = was.get(now) + 1;
ansr = ind;
}
}
was.put(now, ind);
ind++;
}
if (ans == infi)
out.println(-1);
else
out.println(ansl + " " + ansr);
}
out.close();
}
static BufferedReader br;
static StringTokenizer st = new StringTokenizer("");
static PrintWriter out;
static String next() throws IOException {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt(next());
}
static long nextLong() throws IOException {
return Long.parseLong(next());
}
}
class f {
int x, y;
public f(int x, int y) {
this.x = x;
this.y = y;
}
} | Java | ["4\n4\nLRUD\n4\nLURD\n5\nRRUDU\n5\nLLDDR"] | 1 second | ["1 2\n1 4\n3 4\n-1"] | null | Java 11 | standard input | [
"data structures",
"implementation"
] | 1fc1d5ee79aaf823b246db5471ba7836 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β the number of test cases. The next $$$2t$$$ lines describe test cases. Each test case is given on two lines. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β the length of the robot's path. The second line of the test case contains one string $$$s$$$ consisting of $$$n$$$ characters 'L', 'R', 'U', 'D' β the robot's path. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | 1,500 | For each test case, print the answer on it. If you cannot remove such non-empty substring that the endpoint of the robot's path doesn't change, print -1. Otherwise, print two integers $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$ β endpoints of the substring you remove. The value $$$r-l+1$$$ should be minimum possible. If there are several answers, print any of them. | standard output | |
PASSED | 01159c8fd87881063098d68d33e79458 | train_000.jsonl | 1580826900 | There is a robot on a coordinate plane. Initially, the robot is located at the point $$$(0, 0)$$$. Its path is described as a string $$$s$$$ of length $$$n$$$ consisting of characters 'L', 'R', 'U', 'D'.Each of these characters corresponds to some move: 'L' (left): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x - 1, y)$$$; 'R' (right): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x + 1, y)$$$; 'U' (up): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y + 1)$$$; 'D' (down): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y - 1)$$$. The company that created this robot asked you to optimize the path of the robot somehow. To do this, you can remove any non-empty substring of the path. But this company doesn't want their customers to notice the change in the robot behavior. It means that if before the optimization the robot ended its path at the point $$$(x_e, y_e)$$$, then after optimization (i.e. removing some single substring from $$$s$$$) the robot also ends its path at the point $$$(x_e, y_e)$$$.This optimization is a low-budget project so you need to remove the shortest possible non-empty substring to optimize the robot's path such that the endpoint of his path doesn't change. It is possible that you can't optimize the path. Also, it is possible that after the optimization the target path is an empty string (i.e. deleted substring is the whole string $$$s$$$).Recall that the substring of $$$s$$$ is such string that can be obtained from $$$s$$$ by removing some amount of characters (possibly, zero) from the prefix and some amount of characters (possibly, zero) from the suffix. For example, the substrings of "LURLLR" are "LU", "LR", "LURLLR", "URL", but not "RR" and "UL".You have to answer $$$t$$$ independent test cases. | 256 megabytes | import javafx.util.Pair;
import java.util.*;
import java.io.*;
import static java.lang.Math.*;
public class Main implements Runnable
{
boolean multiple = true;
long MOD = 1000000007;
@SuppressWarnings("Duplicates")
void solve() throws Exception
{
HashMap<Pair<Integer, Integer>, Integer> map = new HashMap<>();
int n = sc.nextInt();
String s = sc.nextToken();
map.put(new Pair<>(0, 0), -1);
int x = 0, y = 0;
long best = 2 * n;
long l = -1, r = -1;
for (int t = 0; t < n; t++)
{
if (s.charAt(t) == 'L') x--;
if (s.charAt(t) == 'R') x++;
if (s.charAt(t) == 'U') y--;
if (s.charAt(t) == 'D') y++;
if (map.containsKey(new Pair<>(x, y)))
{
if (t - map.get(new Pair<>(x, y)) < best)
{
best = t - map.get(new Pair<>(x, y));
l = map.get(new Pair<>(x, y)) + 2;
r = t + 1;
}
}
map.put(new Pair<>(x, y), t);
}
System.out.println((l == -1) ? -1 : l + " " + r);
}
long[][] pow(long[][] a, long pow)
{
if (pow == 1) return a;
long[][] temp = pow(a, pow / 2);
temp = mult(temp, temp);
if (pow % 2 == 0) return temp;
return mult(a, temp);
}
long[][] mult(long[][] a, long[][] b)
{
if (a[0].length != b.length)
a[0][0] /= 0;
long[][] c = new long[a.length][b[0].length];
for (int i = 0; i < a.length; i++)
for (int j = 0; j < b[0].length; j++)
for (int k = 0; k < a[0].length; k++)
c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % MOD;
return c;
}
long totient(long m)
{
long result = m;
for (long i = 2; i * i <= m; i++)
if (m % i == 0)
{
while (m % i == 0)
m /= i;
result -= result / i;
}
if (m > 1)
result -= result / m;
return result;
}
long inv(long a, long b)
{
return 1 < a ? b - inv(b % a, a) * b / a : 1;
}
long gcd(long a, long b)
{
return a == 0 ? b : gcd(b % a, a);
}
long lcm(long a, long b)
{
return (a * b) / gcd(a, b);
}
class SegTree
{
long[][] ans;
SegTree()
{
}
}
class SegNode
{
int max;
int L, R;
SegNode left = null, right = null;
int query(int queryL, int queryR)
{
if (queryL == L && queryR == R)
return max;
int leftAns = Integer.MIN_VALUE, rightAns = Integer.MIN_VALUE;
if (left != null && queryL <= left.R)
leftAns = left.query(queryL, min(queryR, left.R));
if (right != null && queryR >= right.L)
rightAns = right.query(max(queryL, right.L), queryR);
return max(leftAns, rightAns);
}
SegNode(int[] arr, int l, int r)
{
L = l;
R = r;
max = arr[l];
if (l == r) return;
int mid = (l + r) / 2;
left = new SegNode(arr, l, mid);
right = new SegNode(arr, mid + 1, r);
max = max(left.max, right.max);
}
}
class Node implements Comparable<Node>
{
Node()
{
}
@Override
public int compareTo(Node o)
{
return 0;
}
}
void print(long[] arr)
{
for (int i = 0; i < arr.length; i++)
System.out.print(arr[i] + " ");
System.out.println();
}
@Override
public void run()
{
try
{
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
sc = new FastScanner(in);
if (multiple)
{
int q = sc.nextInt();
for (int i = 0; i < q; i++)
solve();
} else
solve();
} catch (Throwable uncaught)
{
Main.uncaught = uncaught;
} finally
{
out.close();
}
}
public static void main(String[] args) throws Throwable
{
Thread thread = new Thread(null, new Main(), "", (1 << 26));
thread.start();
thread.join();
if (Main.uncaught != null)
{
throw Main.uncaught;
}
}
static Throwable uncaught;
BufferedReader in;
FastScanner sc;
PrintWriter out;
}
class FastScanner
{
BufferedReader in;
StringTokenizer st;
public FastScanner(BufferedReader in)
{
this.in = in;
}
public String nextToken() throws Exception {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(in.readLine());
}
return st.nextToken();
}
public int nextInt() throws Exception {
return Integer.parseInt(nextToken());
}
public long nextLong() throws Exception {
return Long.parseLong(nextToken());
}
public double nextDouble() throws Exception {
return Double.parseDouble(nextToken());
}
} | Java | ["4\n4\nLRUD\n4\nLURD\n5\nRRUDU\n5\nLLDDR"] | 1 second | ["1 2\n1 4\n3 4\n-1"] | null | Java 11 | standard input | [
"data structures",
"implementation"
] | 1fc1d5ee79aaf823b246db5471ba7836 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β the number of test cases. The next $$$2t$$$ lines describe test cases. Each test case is given on two lines. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β the length of the robot's path. The second line of the test case contains one string $$$s$$$ consisting of $$$n$$$ characters 'L', 'R', 'U', 'D' β the robot's path. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | 1,500 | For each test case, print the answer on it. If you cannot remove such non-empty substring that the endpoint of the robot's path doesn't change, print -1. Otherwise, print two integers $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$ β endpoints of the substring you remove. The value $$$r-l+1$$$ should be minimum possible. If there are several answers, print any of them. | standard output | |
PASSED | bbbe5ecd2c0b164d7f84e5dbabfd7f44 | train_000.jsonl | 1580826900 | There is a robot on a coordinate plane. Initially, the robot is located at the point $$$(0, 0)$$$. Its path is described as a string $$$s$$$ of length $$$n$$$ consisting of characters 'L', 'R', 'U', 'D'.Each of these characters corresponds to some move: 'L' (left): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x - 1, y)$$$; 'R' (right): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x + 1, y)$$$; 'U' (up): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y + 1)$$$; 'D' (down): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y - 1)$$$. The company that created this robot asked you to optimize the path of the robot somehow. To do this, you can remove any non-empty substring of the path. But this company doesn't want their customers to notice the change in the robot behavior. It means that if before the optimization the robot ended its path at the point $$$(x_e, y_e)$$$, then after optimization (i.e. removing some single substring from $$$s$$$) the robot also ends its path at the point $$$(x_e, y_e)$$$.This optimization is a low-budget project so you need to remove the shortest possible non-empty substring to optimize the robot's path such that the endpoint of his path doesn't change. It is possible that you can't optimize the path. Also, it is possible that after the optimization the target path is an empty string (i.e. deleted substring is the whole string $$$s$$$).Recall that the substring of $$$s$$$ is such string that can be obtained from $$$s$$$ by removing some amount of characters (possibly, zero) from the prefix and some amount of characters (possibly, zero) from the suffix. For example, the substrings of "LURLLR" are "LU", "LR", "LURLLR", "URL", but not "RR" and "UL".You have to answer $$$t$$$ independent test cases. | 256 megabytes | // package com.company;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.sql.SQLOutput;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
Scanner s = new Scanner(System.in);
//BufferedReader s=new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb1 = new StringBuilder();//int n=Integer.parseInt(s.readLine());
int t=s.nextInt();
while(t-->0) {
int n = s.nextInt();
char[] a=s.next().toCharArray();
int x=-1;int y=-1;
// int[][] vis=new int[2*n+1][2*n+1];
int tx=-1;int ty=-1;
//int[][] pos=new int[2*n+1][2*n+1];
HashMap<Integer,Integer> [] pos=new HashMap[2*n+1];
HashMap<Integer,Integer> [] vis=new HashMap[2*n+1];
int cx=n;int cy=n;int min=Integer.MAX_VALUE;
vis[n]=new HashMap<Integer, Integer>();
vis[n].put(n,1);
pos[n]=new HashMap<Integer, Integer>();
pos[n].put(n,1);
for(int i=0;i<n;i++){
if(a[i]=='L') cy--;
else if(a[i]=='R') cy++;
else if(a[i]=='D') cx--;
else if(a[i]=='U') cx++;
if(vis[cx]!=null&&vis[cx].containsKey(cy)){
if(i+1-pos[cx].get(cy)<min){
// System.out.println(i+1+" "+pos[cx][cy]);
min=i+1-pos[cx].get(cy);
tx=i;x=i-min;
}
}
if(vis[cx]==null) vis[cx]=new HashMap<Integer, Integer>();
if(pos[cx]==null) pos[cx]=new HashMap<Integer, Integer>();
vis[cx].put(cy,1);
pos[cx].put(cy,i+2);
}
if(min==Integer.MAX_VALUE) sb1.append(-1+"\n");
else sb1.append((x+1)+" "+(tx+1)+"\n");
}
System.out.println(sb1.toString());
}
static void dfs(int i,ArrayList<Integer>[] adj,int[] vis,int n){
vis[i]=1;
if(adj[i]==null){return;}
for(Integer j:adj[i]){
if(vis[j]==0){
dfs(j,adj,vis,n);
}
}}
static void computeLPSArray(String pat, int M, int lps[])
{
int len = 0;
int i = 1;
lps[0] = 0;
while (i < M) {
if (pat.charAt(i) == pat.charAt(len)) {
len++;
lps[i] = len;
i++;
}
else // (pat[i] != pat[len])
{
if (len != 0) {
len = lps[len - 1];
}
else // if (len == 0)
{
lps[i] = len;
i++;
}
}
}
}
static boolean isPrime(int n)
{
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
static double power(double x, long y, int p) {
double res = 1;
x = x % p;
while (y > 0) {
if ((y & 1) == 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
public static void fracion(double x) {
String a = "" + x;
String spilts[] = a.split("\\."); // split using decimal
int b = spilts[1].length(); // find the decimal length
int denominator = (int) Math.pow(10, b); // calculate the denominator
int numerator = (int) (x * denominator); // calculate the nerumrator Ex
// 1.2*10 = 12
int gcd = (int)gcd((long)numerator, denominator); // Find the greatest common
// divisor bw them
String fraction = "" + numerator / gcd + "/" + denominator / gcd;
// System.out.println((denominator/gcd));
long x1=modInverse(denominator / gcd,998244353 );
// System.out.println(x1);
System.out.println((((numerator / gcd )%998244353 *(x1%998244353 ))%998244353 ) );
}static int anst=Integer.MAX_VALUE;
static StringBuilder sb1=new StringBuilder();
public static int bfs(int i1, ArrayList<Integer>[] h, int[] vis, int n,int val1) {
Queue<Integer> q = new LinkedList<Integer>();
q.add(i1);Queue<Integer> aq=new LinkedList<Integer>();
aq.add(0);
while(!q.isEmpty()){
int i=q.poll();
int val=aq.poll();
if(i==n){
return val;
}
if(h[i]!=null){
for(Integer j:h[i]){
if(vis[j]==0){
q.add(j);vis[j]=1;
aq.add(val+1);}
}
}
}return -1;
}
static int i(String a) {
return Integer.parseInt(a);
}
static long l(String a) {
return Long.parseLong(a);
}
static String[] inp() throws IOException {
BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
return s.readLine().trim().split("\\s+");
}
static long gcd(long a, long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
static long modInverse(int a, int m)
{
{
// If a and m are relatively prime, then modulo inverse
// is a^(m-2) mode m
return (power(a, m - 2, m));
}
}
// To compute x^y under modulo m
static long power(int x, int y, int m)
{
if (y == 0)
return 1;
long p = power(x, y / 2, m) % m;
p = (p * p) % m;
if (y % 2 == 0)
return p;
else
return (x * p) % m;
}
// Function to return gcd of a and b
}
class Student
{
int l;int r;int i;
public Student(int l, int r,int i) {
this.l = l;
this.r = r;this.i=i;
}
// Constructor
// Used to print student details in main()
public String toString()
{
return this.l+" ";
}
}
class Sortbyroll implements Comparator<Student>
{
// Used for sorting in ascending order of
// roll number
public int compare(Student a, Student b){
return a.i-b.i; }
} class Sortbyroll1 implements Comparator<Student>
{
// Used for sorting in ascending order of
// roll number
public int compare(Student a, Student b){
return a.l-b.l;
}
} | Java | ["4\n4\nLRUD\n4\nLURD\n5\nRRUDU\n5\nLLDDR"] | 1 second | ["1 2\n1 4\n3 4\n-1"] | null | Java 11 | standard input | [
"data structures",
"implementation"
] | 1fc1d5ee79aaf823b246db5471ba7836 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β the number of test cases. The next $$$2t$$$ lines describe test cases. Each test case is given on two lines. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β the length of the robot's path. The second line of the test case contains one string $$$s$$$ consisting of $$$n$$$ characters 'L', 'R', 'U', 'D' β the robot's path. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | 1,500 | For each test case, print the answer on it. If you cannot remove such non-empty substring that the endpoint of the robot's path doesn't change, print -1. Otherwise, print two integers $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$ β endpoints of the substring you remove. The value $$$r-l+1$$$ should be minimum possible. If there are several answers, print any of them. | standard output | |
PASSED | 53372201c3d21825d5d62d38198cfe51 | train_000.jsonl | 1580826900 | There is a robot on a coordinate plane. Initially, the robot is located at the point $$$(0, 0)$$$. Its path is described as a string $$$s$$$ of length $$$n$$$ consisting of characters 'L', 'R', 'U', 'D'.Each of these characters corresponds to some move: 'L' (left): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x - 1, y)$$$; 'R' (right): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x + 1, y)$$$; 'U' (up): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y + 1)$$$; 'D' (down): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y - 1)$$$. The company that created this robot asked you to optimize the path of the robot somehow. To do this, you can remove any non-empty substring of the path. But this company doesn't want their customers to notice the change in the robot behavior. It means that if before the optimization the robot ended its path at the point $$$(x_e, y_e)$$$, then after optimization (i.e. removing some single substring from $$$s$$$) the robot also ends its path at the point $$$(x_e, y_e)$$$.This optimization is a low-budget project so you need to remove the shortest possible non-empty substring to optimize the robot's path such that the endpoint of his path doesn't change. It is possible that you can't optimize the path. Also, it is possible that after the optimization the target path is an empty string (i.e. deleted substring is the whole string $$$s$$$).Recall that the substring of $$$s$$$ is such string that can be obtained from $$$s$$$ by removing some amount of characters (possibly, zero) from the prefix and some amount of characters (possibly, zero) from the suffix. For example, the substrings of "LURLLR" are "LU", "LR", "LURLLR", "URL", but not "RR" and "UL".You have to answer $$$t$$$ independent test cases. | 256 megabytes | //
import java.math.*;
import java.util.*;
import java.io.*;
public class C {
static BufferedReader in;
static String file = "../in";
static int test = 10; // 0 for local testing, 1 for std input
public static void main(String[] args) throws Exception
{
int _k = Integer.valueOf("1");
if(test > 0) in = new BufferedReader(new InputStreamReader(System.in));
else in = new BufferedReader(new FileReader(file));
if(test < 0) {String[] str = in.readLine().split(" ");}
/****************************************************/
/****************************************************/
/****************************************************/
/****************************************************/
int T = Integer.valueOf(in.readLine());
while(T-- > 0)
{
int n = Integer.valueOf(in.readLine());
String str = in.readLine();
Map<String, Integer> map = new HashMap<>();
int x = 0, y = 0;
map.put("0_0", 0);
int re = 1 << 30;
int from = -1, to = -1;
for(int i = 0; i < n; i++)
{
if(str.charAt(i) == 'L') x--;
if(str.charAt(i) == 'R') x++;
if(str.charAt(i) == 'U') y--;
if(str.charAt(i) == 'D') y++;
String pos = "" + x + "_" + y;
if(map.containsKey(pos)) {
int length = i - map.get(pos);
if(re > length)
{
re = length;
from = map.get(pos);
to = i;
}
}
map.put(pos, i + 1);
// System.out.println(map);
}
if(re >= 1 << 30) System.out.println(-1);
else System.out.printf("%d %d\n", from + 1, to + 1);
}
}
} | Java | ["4\n4\nLRUD\n4\nLURD\n5\nRRUDU\n5\nLLDDR"] | 1 second | ["1 2\n1 4\n3 4\n-1"] | null | Java 11 | standard input | [
"data structures",
"implementation"
] | 1fc1d5ee79aaf823b246db5471ba7836 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β the number of test cases. The next $$$2t$$$ lines describe test cases. Each test case is given on two lines. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β the length of the robot's path. The second line of the test case contains one string $$$s$$$ consisting of $$$n$$$ characters 'L', 'R', 'U', 'D' β the robot's path. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | 1,500 | For each test case, print the answer on it. If you cannot remove such non-empty substring that the endpoint of the robot's path doesn't change, print -1. Otherwise, print two integers $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$ β endpoints of the substring you remove. The value $$$r-l+1$$$ should be minimum possible. If there are several answers, print any of them. | standard output | |
PASSED | e50624e15a1e9a0d3ffd24eea300e41f | train_000.jsonl | 1580826900 | There is a robot on a coordinate plane. Initially, the robot is located at the point $$$(0, 0)$$$. Its path is described as a string $$$s$$$ of length $$$n$$$ consisting of characters 'L', 'R', 'U', 'D'.Each of these characters corresponds to some move: 'L' (left): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x - 1, y)$$$; 'R' (right): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x + 1, y)$$$; 'U' (up): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y + 1)$$$; 'D' (down): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y - 1)$$$. The company that created this robot asked you to optimize the path of the robot somehow. To do this, you can remove any non-empty substring of the path. But this company doesn't want their customers to notice the change in the robot behavior. It means that if before the optimization the robot ended its path at the point $$$(x_e, y_e)$$$, then after optimization (i.e. removing some single substring from $$$s$$$) the robot also ends its path at the point $$$(x_e, y_e)$$$.This optimization is a low-budget project so you need to remove the shortest possible non-empty substring to optimize the robot's path such that the endpoint of his path doesn't change. It is possible that you can't optimize the path. Also, it is possible that after the optimization the target path is an empty string (i.e. deleted substring is the whole string $$$s$$$).Recall that the substring of $$$s$$$ is such string that can be obtained from $$$s$$$ by removing some amount of characters (possibly, zero) from the prefix and some amount of characters (possibly, zero) from the suffix. For example, the substrings of "LURLLR" are "LU", "LR", "LURLLR", "URL", but not "RR" and "UL".You have to answer $$$t$$$ independent test cases. | 256 megabytes |
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.net.StandardSocketOptions;
import java.security.cert.CollectionCertStoreParameters;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
import java.util.SortedSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.Vector;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
public class Main {
public static int lowerBound(ArrayList<Integer> array, int length, long value) {
int low = 0;
int high = length;
while (low < high) {
final int mid = (low + high) / 2;
if (value <= array.get(mid)) {
high = mid;
} else {
low = mid + 1;
}
}
return low;
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
static long gcd(long a, long b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
static long lcm(long a, long b) {
return (a * b) / gcd(a, b);
}
// public static void sortbyColumn(int arr[][], int col) {
// // Using built-in sort function Arrays.sort
// Arrays.sort(arr, new Comparator<int[]>() {
//
// @Override
// // Compare values according to columns
// public int compare(final int[] entry1, final int[] entry2) {
//
// // To sort in descending order revert
// // the '>' Operator
// // if (entry1[col] > entry2[col])
// // return 1;
// // else //(entry1[col] >= entry2[col])
// // return -1;
// return new Integer(entry1[col]).compareTo(entry2[col]);
// // return entry1[col].
// }
// }); // End of function call sort().
// }
static class pair {
int V, I;
pair(int v, int i) {
V = v;
I = i;
}
}
public static int[] swap(int data[], int left, int right) {
int temp = data[left];
data[left] = data[right];
data[right] = temp;
return data;
}
public static int[] reverse(int data[], int left, int right) {
while (left < right) {
int temp = data[left];
data[left++] = data[right];
data[right--] = temp;
}
return data;
}
public static boolean findNextPermutation(int data[]) {
if (data.length <= 1)
return false;
int last = data.length - 2;
while (last >= 0) {
if (data[last] < data[last + 1]) {
break;
}
last--;
}
if (last < 0)
return false;
int nextGreater = data.length - 1;
for (int i = data.length - 1; i > last; i--) {
if (data[i] > data[last]) {
nextGreater = i;
break;
}
}
data = swap(data, nextGreater, last);
data = reverse(data, last + 1, data.length - 1);
return true;
}
static long nCr(long n, long r) {
long x = 1;
long yu = n - r;
while (n > r) {
x = x * n;
n--;
}
while (yu > 0) {
x /= yu;
yu--;
}
return x;
}
/*
* static boolean prime[] = new boolean[1000007];
*
* public static void sieveOfEratosthenes(int n) {
*
* for (int i = 0; i < n; i++) prime[i] = true; * for (int p = 2; p * p <=
* n; p++) { // If prime[p] is not changed, then it is a prime if (prime[p]
* == true) { // Update all multiples of p for (int i = p * p; i <= n; i +=
* p) prime[i] = false; } }
*
* // Print all prime numbers // for(int i = 2; i <= n; i++) // { //
* if(prime[i] == true) // System.out.print(i + " "); // } }
*/
static long power(long fac2, int y, int p) {
long res = 1;
fac2 = fac2 % p;
while (y > 0) {
if (y % 2 == 1)
res = (res * fac2) % p;
fac2 = (fac2 * fac2) % p;
}
return res;
}
static long modInverse(long fac2, int p) {
return power(fac2, p - 2, p);
}
static boolean isPrime(int 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;
}
public static BigInteger lcmm(String a, String b) {
BigInteger s = new BigInteger(a);
BigInteger s1 = new BigInteger(b);
BigInteger mul = s.multiply(s1);
BigInteger gcd = s.gcd(s1);
BigInteger lcm = mul.divide(gcd);
return lcm;
}
static long setBitNumber(long n) {
if (n == 0)
return 0;
long msb = 0;
while (n != 0) {
n = n / 2;
msb++;
}
return msb;
}
public static void main(String[] args) throws NumberFormatException, IOException, ScriptException {
FastReader sc = new FastReader();
PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// Scanner scn = new Scanner(System.in);
//
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
String s = sc.next();
long sum = 0;
HashMap<Long, Integer> h = new HashMap<>();
int min = 1000000, l = 0, r = 0;
h.put((long) 0, -1);
for (int i = 0; i < n; i++) {
if (s.charAt(i) == 'L') {
sum += 1;
} else if (s.charAt(i) == 'R')
sum -= 1;
else if (s.charAt(i) == 'U')
sum += 1000000;
else
sum -= 1000000;
if (h.containsKey(sum) == true) {
if ((i - h.get(sum)) < min) {
l = h.get(sum);
r = i;
min=(i - h.get(sum));
}
h.put(sum,i);
} else
h.put(sum, i);
// pr.println(sum+" "+l+" "+r+" "+h.get(sum));
}
if (l == 0 && r == 0) {
pr.println("-1");
} else {
pr.println((l+2) + " " + (r+1));
}
}
//
// coded to perfection by Rohan Mukhija
pr.flush();
pr.close();
}
static HashMap<Integer, Integer> h = new HashMap<>();
private static boolean possible(long[] arr, int[] f, long mid, long k) {
long c = 0;
for (int i = 0; i < arr.length; i++) {
if ((arr[i] * f[f.length - i - 1]) > mid) {
c += (arr[i] - (mid / f[f.length - i - 1]));
}
}
// System.out.println(mid+" "+c);
if (c <= k)
return true;
return false;
}
}
| Java | ["4\n4\nLRUD\n4\nLURD\n5\nRRUDU\n5\nLLDDR"] | 1 second | ["1 2\n1 4\n3 4\n-1"] | null | Java 11 | standard input | [
"data structures",
"implementation"
] | 1fc1d5ee79aaf823b246db5471ba7836 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β the number of test cases. The next $$$2t$$$ lines describe test cases. Each test case is given on two lines. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β the length of the robot's path. The second line of the test case contains one string $$$s$$$ consisting of $$$n$$$ characters 'L', 'R', 'U', 'D' β the robot's path. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | 1,500 | For each test case, print the answer on it. If you cannot remove such non-empty substring that the endpoint of the robot's path doesn't change, print -1. Otherwise, print two integers $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$ β endpoints of the substring you remove. The value $$$r-l+1$$$ should be minimum possible. If there are several answers, print any of them. | standard output | |
PASSED | 5df889de760285f897fa157beda0ab5e | train_000.jsonl | 1580826900 | There is a robot on a coordinate plane. Initially, the robot is located at the point $$$(0, 0)$$$. Its path is described as a string $$$s$$$ of length $$$n$$$ consisting of characters 'L', 'R', 'U', 'D'.Each of these characters corresponds to some move: 'L' (left): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x - 1, y)$$$; 'R' (right): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x + 1, y)$$$; 'U' (up): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y + 1)$$$; 'D' (down): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y - 1)$$$. The company that created this robot asked you to optimize the path of the robot somehow. To do this, you can remove any non-empty substring of the path. But this company doesn't want their customers to notice the change in the robot behavior. It means that if before the optimization the robot ended its path at the point $$$(x_e, y_e)$$$, then after optimization (i.e. removing some single substring from $$$s$$$) the robot also ends its path at the point $$$(x_e, y_e)$$$.This optimization is a low-budget project so you need to remove the shortest possible non-empty substring to optimize the robot's path such that the endpoint of his path doesn't change. It is possible that you can't optimize the path. Also, it is possible that after the optimization the target path is an empty string (i.e. deleted substring is the whole string $$$s$$$).Recall that the substring of $$$s$$$ is such string that can be obtained from $$$s$$$ by removing some amount of characters (possibly, zero) from the prefix and some amount of characters (possibly, zero) from the suffix. For example, the substrings of "LURLLR" are "LU", "LR", "LURLLR", "URL", but not "RR" and "UL".You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
import static java.lang.Math.*;
public class Main {
void run() throws IOException {
int t = nextInt();
while (t-- > 0) {
int n = nextInt();
char[] a = next().toCharArray();
TreeMap<pair, Integer> ts = new TreeMap<>();
ts.put(new pair(0, 0), 0);
int x = 0;
int y = 0;
int l = 0;
int r = Integer.MAX_VALUE / 2;
for (int i = 0; i < a.length; i++) {
if (a[i] == 'U') y++;
if (a[i] == 'D') y--;
if (a[i] == 'L') x--;
if (a[i] == 'R') x++;
pair now = new pair(x, y);
if(ts.containsKey(now)) {
if (i + 1 - ts.get(now) < r - l + 1) {
r = i + 1;
l = ts.get(now) + 1;
}
}
ts.put(now, i + 1);
}
if(r == Integer.MAX_VALUE / 2){
pw.println(-1);
}
else {
pw.println(l + " " + r);
}
}
pw.close();
}
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 (o.x == this.x) return -Integer.compare(o.y, this.y);
return -Integer.compare(o.x, this.x);
}
}
Scanner sc = new Scanner(System.in);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//BufferedReader br = new BufferedReader(new FileReader("downloading.in"));
StringTokenizer st = new StringTokenizer("");
PrintWriter pw = new PrintWriter(System.out);
//PrintWriter pw = new PrintWriter("downloading.out");
int nextInt() throws IOException {
return Integer.parseInt(next());
}
String next() throws IOException {
if (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
long nextLong() throws IOException {
return Long.parseLong(next());
}
double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public Main() throws FileNotFoundException {
}
public static void main(String[] args) throws IOException {
new Main().run();
}
} | Java | ["4\n4\nLRUD\n4\nLURD\n5\nRRUDU\n5\nLLDDR"] | 1 second | ["1 2\n1 4\n3 4\n-1"] | null | Java 11 | standard input | [
"data structures",
"implementation"
] | 1fc1d5ee79aaf823b246db5471ba7836 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β the number of test cases. The next $$$2t$$$ lines describe test cases. Each test case is given on two lines. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β the length of the robot's path. The second line of the test case contains one string $$$s$$$ consisting of $$$n$$$ characters 'L', 'R', 'U', 'D' β the robot's path. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | 1,500 | For each test case, print the answer on it. If you cannot remove such non-empty substring that the endpoint of the robot's path doesn't change, print -1. Otherwise, print two integers $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$ β endpoints of the substring you remove. The value $$$r-l+1$$$ should be minimum possible. If there are several answers, print any of them. | standard output | |
PASSED | 692f9f0272ad6a0af8921aba4c31c3a7 | train_000.jsonl | 1580826900 | There is a robot on a coordinate plane. Initially, the robot is located at the point $$$(0, 0)$$$. Its path is described as a string $$$s$$$ of length $$$n$$$ consisting of characters 'L', 'R', 'U', 'D'.Each of these characters corresponds to some move: 'L' (left): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x - 1, y)$$$; 'R' (right): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x + 1, y)$$$; 'U' (up): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y + 1)$$$; 'D' (down): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y - 1)$$$. The company that created this robot asked you to optimize the path of the robot somehow. To do this, you can remove any non-empty substring of the path. But this company doesn't want their customers to notice the change in the robot behavior. It means that if before the optimization the robot ended its path at the point $$$(x_e, y_e)$$$, then after optimization (i.e. removing some single substring from $$$s$$$) the robot also ends its path at the point $$$(x_e, y_e)$$$.This optimization is a low-budget project so you need to remove the shortest possible non-empty substring to optimize the robot's path such that the endpoint of his path doesn't change. It is possible that you can't optimize the path. Also, it is possible that after the optimization the target path is an empty string (i.e. deleted substring is the whole string $$$s$$$).Recall that the substring of $$$s$$$ is such string that can be obtained from $$$s$$$ by removing some amount of characters (possibly, zero) from the prefix and some amount of characters (possibly, zero) from the suffix. For example, the substrings of "LURLLR" are "LU", "LR", "LURLLR", "URL", but not "RR" and "UL".You have to answer $$$t$$$ independent test cases. | 256 megabytes | // package cp;
import java.io.*;
import java.math.*;
import java.util.*;
public class Cf_three {
long gcd(long a,long b) {if(b==0)return a;else return gcd(b,a%b);}
void swap(long a,long b) {long temp=a;a=b;b=temp;}
StringBuilder sb=new StringBuilder();
BigInteger RES=new BigInteger("0");
//(Initialize as string) - (a.add(b)) - (array initialized with null and not 0)
Integer[] ARR=new Integer[5];
//Integer sort-TLE-Initialize object elements i.e a[0].
void divisor(long n,int start) {
int cnt=0;for(int i=start;i<=Math.sqrt(n);i++) {
if(n%i==0) {if(i==n/i)cnt++;else cnt+=2;}}}
public static void main(String[] args) throws IOException {
PrintWriter out = new PrintWriter(System.out);
Readers.init(System.in);
Cf_three obj=new Cf_three();
int t=Readers.nextInt();
while(t-->0) {
int n=Readers.nextInt();
String s=Readers.next();
HashMap<String,Integer> map=new HashMap<>();
map.put((0+" "+0),0);
int x=0;int y=0;
int l=-1;int r=-1;
int minn=Integer.MAX_VALUE;
for (int i = 0; i < n; i++) {
if(s.charAt(i)=='L')x++;
else if(s.charAt(i)=='R')x--;
else if(s.charAt(i)=='U')y++;
else y--;
if(map.containsKey(x+" "+y) && (i+2-map.get(x+" "+y))<minn) {
minn=i+2-map.get(x+" "+y);
l=map.get(x+" "+y);
}
map.put(x+" "+y,i+1);
}
if(l==-1)System.out.println(-1);
else {
System.out.println((l+1)+" "+(l+minn-1));
}
}
out.flush();
}
}
class Readers {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(
new InputStreamReader(input) );
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while ( ! tokenizer.hasMoreTokens() ) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(
reader.readLine() );
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt( next() );
}
static double nextDouble() throws IOException {
return Double.parseDouble( next() );
}
static long nextLong() throws IOException{
return Long.parseLong(next());
}
} | Java | ["4\n4\nLRUD\n4\nLURD\n5\nRRUDU\n5\nLLDDR"] | 1 second | ["1 2\n1 4\n3 4\n-1"] | null | Java 11 | standard input | [
"data structures",
"implementation"
] | 1fc1d5ee79aaf823b246db5471ba7836 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β the number of test cases. The next $$$2t$$$ lines describe test cases. Each test case is given on two lines. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β the length of the robot's path. The second line of the test case contains one string $$$s$$$ consisting of $$$n$$$ characters 'L', 'R', 'U', 'D' β the robot's path. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | 1,500 | For each test case, print the answer on it. If you cannot remove such non-empty substring that the endpoint of the robot's path doesn't change, print -1. Otherwise, print two integers $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$ β endpoints of the substring you remove. The value $$$r-l+1$$$ should be minimum possible. If there are several answers, print any of them. | standard output | |
PASSED | ece41c919b682940b8825ab0e059c259 | train_000.jsonl | 1580826900 | There is a robot on a coordinate plane. Initially, the robot is located at the point $$$(0, 0)$$$. Its path is described as a string $$$s$$$ of length $$$n$$$ consisting of characters 'L', 'R', 'U', 'D'.Each of these characters corresponds to some move: 'L' (left): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x - 1, y)$$$; 'R' (right): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x + 1, y)$$$; 'U' (up): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y + 1)$$$; 'D' (down): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y - 1)$$$. The company that created this robot asked you to optimize the path of the robot somehow. To do this, you can remove any non-empty substring of the path. But this company doesn't want their customers to notice the change in the robot behavior. It means that if before the optimization the robot ended its path at the point $$$(x_e, y_e)$$$, then after optimization (i.e. removing some single substring from $$$s$$$) the robot also ends its path at the point $$$(x_e, y_e)$$$.This optimization is a low-budget project so you need to remove the shortest possible non-empty substring to optimize the robot's path such that the endpoint of his path doesn't change. It is possible that you can't optimize the path. Also, it is possible that after the optimization the target path is an empty string (i.e. deleted substring is the whole string $$$s$$$).Recall that the substring of $$$s$$$ is such string that can be obtained from $$$s$$$ by removing some amount of characters (possibly, zero) from the prefix and some amount of characters (possibly, zero) from the suffix. For example, the substrings of "LURLLR" are "LU", "LR", "LURLLR", "URL", but not "RR" and "UL".You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.*;
import java.math.*;
import java.text.DecimalFormat;
import java.util.*;
public class MainClass
{
InputStream in;
PrintWriter out;
long mod=(long)1e9+7;
int MAX=(int)2e5+7;
double eps=1e-6;
String high="";
void solve()
{
int t = ni();
while(t-- > 0) {
int n = ni();
String path = ns();
HashMap<Pair, Integer> map = new HashMap<>();
int l = -1, r = -1;
int x = 0, y = 0;
int minLength = Integer.MAX_VALUE;
map.put(new Pair(0, 0), 0);
for(int i = 0; i < path.length(); i++) {
x = getNewX(x, path.charAt(i));
y = getNEwY(y, path.charAt(i));
if(map.containsKey(new Pair(x, y))) {
if(minLength > (i + 1 - (map.get(new Pair(x, y)) + 1))) {
l = map.get(new Pair(x, y)) + 1;
r = i + 1;
minLength = i + 1 - (map.get(new Pair(x, y)) + 1);
}
}
map.put(new Pair(x, y), i + 1);
}
map.clear();
if(l == -1)
out.println("-1");
else
out.println(l + " " + r);
}
}
int getNewX(int oldX, char c) {
if(c == 'L')
return oldX - 1;
else if(c == 'R')
return oldX + 1;
else
return oldX;
}
int getNEwY(int oldY, char c) {
if(c == 'U')
return oldY + 1;
else if(c == 'D')
return oldY - 1;
else
return oldY;
}
double dist(double x1,double y1,double x2,double y2)
{
return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}
class Pair implements Comparable<Pair>
{
int x;
int y;
Pair(int a,int b)
{
x=a;
y=b;
}
@Override
public boolean equals(Object o)
{
Pair other = (Pair)o;
return x == other.x && y == other.y;
}
public String toString()
{
return x+" "+y;
}
@Override
public int compareTo(Pair o)
{
if (x==o.x)
return Integer.compare(y, o.y);
else
return Integer.compare(x, o.x);
}
@Override public int hashCode()
{
return Objects.hash(x, y);
}
}
long pow(long x, long n, long M) {
x%=M;
long result = 1;
while (n > 0) {
if (n % 2 == 1)
result = (result * x) % M;
x = (x * x) % M;
n = n / 2;
}
return result;
}
long modInverse(long A, long M) {
extendedEuclid(A, M);
return (EEx % M + M) % M;
}
long EEd, EEx, EEy;
void extendedEuclid(long A, long B) {
if (B == 0) {
EEd = A;
EEx = 1;
EEy = 0;
} else {
extendedEuclid(B, A % B);
long temp = EEx;
EEx = EEy;
EEy = temp - (A / B) * EEy;
}
}
int max(int a,int b)
{
if(a>b)
return a;
else
return b;
}
int min(int a,int b)
{
if(a>b)
return b;
else
return a;
}
long max(long a,long b)
{
if(a>b)
return a;
else
return b;
}
long min(long a,long b)
{
if(a>b)
return b;
else
return a;
}
long add(long a,long b)
{
long x=(a+b);
while(x>=mod) x-=mod;
return x;
}
long sub(long a,long b)
{
long x=(a-b);
while(x<0) x+=mod;
return x;
}
long mul(long a,long b)
{
a%=mod;
b%=mod;
long x=(a*b);
return x%mod;
}
void run() throws Exception
{
String INPUT = "C:/Users/tapan/OneDrive/Desktop/in.txt";
// oj=false;
in = oj ? System.in : new FileInputStream(INPUT);
out = new PrintWriter(System.out);
long s = System.currentTimeMillis();
solve();
out.flush();
tr(System.currentTimeMillis() - s + "ms");
}
public static void main(String[] args) throws Exception
{
new MainClass().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 = in.read(inbuf);
}
catch (IOException e)
{
throw new InputMismatchException();
}
if (lenbuf <= 0)
return -1;
}
return inbuf[ptrbuf++];
}
private boolean inSpaceChar(int c)
{
return !(c >= 33 && c <= 126);
}
private int skip()
{
int b;
while ((b = readByte()) != -1 && inSpaceChar(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 (!(inSpaceChar(b)))
{ // when nextLine, (inSpaceChar(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 && !(inSpaceChar(b)))
{
buf[p++] = (char) b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
private char[][] nm(int n, int m)
{
char[][] map = new char[n][];
for (int i = 0; i < n; i++)
map[i] = ns(m);
return map;
}
private int[] na(int n)
{
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = ni();
return a;
}
private int ni()
{
int num = 0, b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
;
if (b == '-')
{
minus = true;
b = readByte();
}
while (true)
{
if (b >= '0' && b <= '9')
{
num = num * 10 + (b - '0');
}
else
{
return minus ? -num : num;
}
b = readByte();
}
}
private long nl()
{
long num = 0;
int b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
;
if (b == '-')
{
minus = true;
b = readByte();
}
while (true)
{
if (b >= '0' && b <= '9')
{
num = num * 10 + (b - '0');
}
else
{
return minus ? -num : num;
}
b = readByte();
}
}
private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
private void tr(Object... o)
{
if (!oj)
System.out.println(Arrays.deepToString(o));
}
} | Java | ["4\n4\nLRUD\n4\nLURD\n5\nRRUDU\n5\nLLDDR"] | 1 second | ["1 2\n1 4\n3 4\n-1"] | null | Java 11 | standard input | [
"data structures",
"implementation"
] | 1fc1d5ee79aaf823b246db5471ba7836 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β the number of test cases. The next $$$2t$$$ lines describe test cases. Each test case is given on two lines. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β the length of the robot's path. The second line of the test case contains one string $$$s$$$ consisting of $$$n$$$ characters 'L', 'R', 'U', 'D' β the robot's path. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | 1,500 | For each test case, print the answer on it. If you cannot remove such non-empty substring that the endpoint of the robot's path doesn't change, print -1. Otherwise, print two integers $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$ β endpoints of the substring you remove. The value $$$r-l+1$$$ should be minimum possible. If there are several answers, print any of them. | standard output | |
PASSED | 8aa37e622c97c2ec216840c8ff994db2 | train_000.jsonl | 1580826900 | There is a robot on a coordinate plane. Initially, the robot is located at the point $$$(0, 0)$$$. Its path is described as a string $$$s$$$ of length $$$n$$$ consisting of characters 'L', 'R', 'U', 'D'.Each of these characters corresponds to some move: 'L' (left): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x - 1, y)$$$; 'R' (right): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x + 1, y)$$$; 'U' (up): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y + 1)$$$; 'D' (down): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y - 1)$$$. The company that created this robot asked you to optimize the path of the robot somehow. To do this, you can remove any non-empty substring of the path. But this company doesn't want their customers to notice the change in the robot behavior. It means that if before the optimization the robot ended its path at the point $$$(x_e, y_e)$$$, then after optimization (i.e. removing some single substring from $$$s$$$) the robot also ends its path at the point $$$(x_e, y_e)$$$.This optimization is a low-budget project so you need to remove the shortest possible non-empty substring to optimize the robot's path such that the endpoint of his path doesn't change. It is possible that you can't optimize the path. Also, it is possible that after the optimization the target path is an empty string (i.e. deleted substring is the whole string $$$s$$$).Recall that the substring of $$$s$$$ is such string that can be obtained from $$$s$$$ by removing some amount of characters (possibly, zero) from the prefix and some amount of characters (possibly, zero) from the suffix. For example, the substrings of "LURLLR" are "LU", "LR", "LURLLR", "URL", but not "RR" and "UL".You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.util.*;
public final class Second {
static class Point {
int x, y;
Point(int a, int b) {
x = a;
y = b;
}
@Override
public int hashCode() {
return Objects.hash(x, y);
}
@Override
public boolean equals(Object obj) {
if(this == obj)
return true;
if(obj == null)
return false;
if(this.getClass() != obj.getClass())
return false;
Point p = (Point)obj;
if(this.x == p.x && this.y == p.y)
return true;
else
return false;
}
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
while(t-- > 0) {
int n = in.nextInt();
in.nextLine();
String s = in.nextLine();
int finX = 0, finY = 0, currX = 0, currY = 0;
for(char a : s.toCharArray()) {
if(a == 'L') {
finX --;
} else if(a == 'R') {
finX ++;
} else if(a == 'U') {
finY ++;
} else {
finY --;
}
}
int ansR = Integer.MAX_VALUE, ansL = 0;
HashMap<Point, Integer> map = new HashMap<>();
map.put(new Point(0, 0), -1);
for(int i = 0; i < s.length(); i++) {
if(s.charAt(i) == 'L') {
currX --;
} else if(s.charAt(i) == 'R') {
currX ++;
} else if(s.charAt(i) == 'U') {
currY ++;
} else {
currY --;
}
if(map.containsKey(new Point(currX, currY))) {
if(ansR - ansL > i - map.get(new Point(currX, currY))) {
ansR = i;
ansL = map.get(new Point(currX, currY));
}
map.replace(new Point(currX, currY), i);
} else {
map.put(new Point(currX, currY), i);
}
}
if(ansR - ansL == Integer.MAX_VALUE) {
System.out.println(-1);
} else {
System.out.println((ansL + 2) + " " + (ansR + 1));
}
}
}
} | Java | ["4\n4\nLRUD\n4\nLURD\n5\nRRUDU\n5\nLLDDR"] | 1 second | ["1 2\n1 4\n3 4\n-1"] | null | Java 11 | standard input | [
"data structures",
"implementation"
] | 1fc1d5ee79aaf823b246db5471ba7836 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β the number of test cases. The next $$$2t$$$ lines describe test cases. Each test case is given on two lines. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β the length of the robot's path. The second line of the test case contains one string $$$s$$$ consisting of $$$n$$$ characters 'L', 'R', 'U', 'D' β the robot's path. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | 1,500 | For each test case, print the answer on it. If you cannot remove such non-empty substring that the endpoint of the robot's path doesn't change, print -1. Otherwise, print two integers $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$ β endpoints of the substring you remove. The value $$$r-l+1$$$ should be minimum possible. If there are several answers, print any of them. | standard output | |
PASSED | b64bbc032f392d32f91854e7d55127d2 | train_000.jsonl | 1580826900 | There is a robot on a coordinate plane. Initially, the robot is located at the point $$$(0, 0)$$$. Its path is described as a string $$$s$$$ of length $$$n$$$ consisting of characters 'L', 'R', 'U', 'D'.Each of these characters corresponds to some move: 'L' (left): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x - 1, y)$$$; 'R' (right): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x + 1, y)$$$; 'U' (up): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y + 1)$$$; 'D' (down): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y - 1)$$$. The company that created this robot asked you to optimize the path of the robot somehow. To do this, you can remove any non-empty substring of the path. But this company doesn't want their customers to notice the change in the robot behavior. It means that if before the optimization the robot ended its path at the point $$$(x_e, y_e)$$$, then after optimization (i.e. removing some single substring from $$$s$$$) the robot also ends its path at the point $$$(x_e, y_e)$$$.This optimization is a low-budget project so you need to remove the shortest possible non-empty substring to optimize the robot's path such that the endpoint of his path doesn't change. It is possible that you can't optimize the path. Also, it is possible that after the optimization the target path is an empty string (i.e. deleted substring is the whole string $$$s$$$).Recall that the substring of $$$s$$$ is such string that can be obtained from $$$s$$$ by removing some amount of characters (possibly, zero) from the prefix and some amount of characters (possibly, zero) from the suffix. For example, the substrings of "LURLLR" are "LU", "LR", "LURLLR", "URL", but not "RR" and "UL".You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
private void solve()throws IOException{
int n=nextInt();
HashMap<String,Integer> map=new HashMap<>();
map.put("0 0",0);
int time=1;
int x=0,y=0;
String s=nextLine();
int min=inf;
int l=-1,r=-1;
for(int i=0;i<s.length();i++){
switch(s.charAt(i)){
case 'L':
x--;
break;
case 'R':
x++;
break;
case 'U':
y++;
break;
case 'D':
y--;
break;
}
if(map.containsKey(x+" "+y))
{
int cyclelength=time-map.get(x+" "+y);
if(cyclelength<min){
min=cyclelength;
l=map.get(x+" "+y);
r=time;
}
}
map.put(x+" "+y,time++);
}
if(l==-1)
out.println(-1);
else
out.println((l+1)+" "+r);
}
///////////////////////////////////////////////////////////
final long mod=(long)(1e9+7);
final int inf=(int)(1e9+1);
final int maxn=(int)(1e6);
final long lim=(long)(1e18);
public void run(){
try{
br=new BufferedReader(new InputStreamReader(System.in));
st=null;
out=new PrintWriter(System.out);
// solve();
int t=nextInt();
for(int i=1;i<=t;i++){
// out.print("Case #"+i+": ");
solve();
}
br.close();
out.close();
}catch(Exception e){
e.printStackTrace();
System.exit(1);
}
}
public static void main(String args[])throws IOException{
new Main().run();
}
BufferedReader br;
StringTokenizer st;
PrintWriter out;
String nextToken()throws IOException{
while(st==null || !st.hasMoreTokens())
st=new StringTokenizer(br.readLine());
return st.nextToken();
}
String nextLine()throws IOException{
return br.readLine();
}
int nextInt()throws IOException{
return Integer.parseInt(nextToken());
}
long nextLong()throws IOException{
return Long.parseLong(nextToken());
}
double nextDouble()throws IOException{
return Double.parseDouble(nextToken());
}
} | Java | ["4\n4\nLRUD\n4\nLURD\n5\nRRUDU\n5\nLLDDR"] | 1 second | ["1 2\n1 4\n3 4\n-1"] | null | Java 11 | standard input | [
"data structures",
"implementation"
] | 1fc1d5ee79aaf823b246db5471ba7836 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β the number of test cases. The next $$$2t$$$ lines describe test cases. Each test case is given on two lines. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β the length of the robot's path. The second line of the test case contains one string $$$s$$$ consisting of $$$n$$$ characters 'L', 'R', 'U', 'D' β the robot's path. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | 1,500 | For each test case, print the answer on it. If you cannot remove such non-empty substring that the endpoint of the robot's path doesn't change, print -1. Otherwise, print two integers $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$ β endpoints of the substring you remove. The value $$$r-l+1$$$ should be minimum possible. If there are several answers, print any of them. | standard output | |
PASSED | 5bd1ae14aea67597367e57c89453a959 | train_000.jsonl | 1580826900 | There is a robot on a coordinate plane. Initially, the robot is located at the point $$$(0, 0)$$$. Its path is described as a string $$$s$$$ of length $$$n$$$ consisting of characters 'L', 'R', 'U', 'D'.Each of these characters corresponds to some move: 'L' (left): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x - 1, y)$$$; 'R' (right): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x + 1, y)$$$; 'U' (up): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y + 1)$$$; 'D' (down): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y - 1)$$$. The company that created this robot asked you to optimize the path of the robot somehow. To do this, you can remove any non-empty substring of the path. But this company doesn't want their customers to notice the change in the robot behavior. It means that if before the optimization the robot ended its path at the point $$$(x_e, y_e)$$$, then after optimization (i.e. removing some single substring from $$$s$$$) the robot also ends its path at the point $$$(x_e, y_e)$$$.This optimization is a low-budget project so you need to remove the shortest possible non-empty substring to optimize the robot's path such that the endpoint of his path doesn't change. It is possible that you can't optimize the path. Also, it is possible that after the optimization the target path is an empty string (i.e. deleted substring is the whole string $$$s$$$).Recall that the substring of $$$s$$$ is such string that can be obtained from $$$s$$$ by removing some amount of characters (possibly, zero) from the prefix and some amount of characters (possibly, zero) from the suffix. For example, the substrings of "LURLLR" are "LU", "LR", "LURLLR", "URL", but not "RR" and "UL".You have to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Objects;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
FastReader in = new FastReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
CYetAnotherWalkingRobot solver = new CYetAnotherWalkingRobot();
solver.solve(1, in, out);
out.close();
}
static class CYetAnotherWalkingRobot {
public void solve(int testNumber, FastReader s, PrintWriter out) {
int t = s.nextInt();
while (t-- > 0) {
int n = s.nextInt();
char[] str = s.nextString().toCharArray();
HashMap<CYetAnotherWalkingRobot.pair, Integer> map = new HashMap<>();
map.put(new CYetAnotherWalkingRobot.pair(0, 0), -1);
int left = 0;
int right = 0;
int up = 0;
int down = 0;
int min = Integer.MAX_VALUE;
int start = -1;
int end = -1;
for (int i = 0; i < n; i++) {
if (str[i] == 'L') {
left++;
} else if (str[i] == 'R') {
right++;
} else if (str[i] == 'U') {
up++;
} else {
down++;
}
CYetAnotherWalkingRobot.pair p = new CYetAnotherWalkingRobot.pair(left - right, up - down);
if (map.containsKey(p)) {
int len = i - map.get(p);
if (len < min) {
min = len;
start = map.get(p) + 2;
end = i + 1;
}
}
map.put(p, i);
}
if (min == Integer.MAX_VALUE) {
out.println(-1);
} else {
out.println(start + " " + end);
}
}
}
private static class pair {
int leftmright;
int upmdown;
public pair(int leftmright, int upmdown) {
this.leftmright = leftmright;
this.upmdown = upmdown;
}
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof CYetAnotherWalkingRobot.pair)) return false;
CYetAnotherWalkingRobot.pair pair = (CYetAnotherWalkingRobot.pair) o;
return leftmright == pair.leftmright &&
upmdown == pair.upmdown;
}
public String toString() {
final StringBuilder sb = new StringBuilder();
sb.append(leftmright);
sb.append(" ").append(upmdown);
// sb.append('}');
return sb.toString();
}
public int hashCode() {
return Objects.hash(leftmright, upmdown);
}
}
}
static class FastReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private FastReader.SpaceCharFilter filter;
public FastReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public int nextInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public String nextString() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
if (Character.isValidCodePoint(c)) {
res.appendCodePoint(c);
}
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null) {
return filter.isSpaceChar(c);
}
return isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
}
| Java | ["4\n4\nLRUD\n4\nLURD\n5\nRRUDU\n5\nLLDDR"] | 1 second | ["1 2\n1 4\n3 4\n-1"] | null | Java 11 | standard input | [
"data structures",
"implementation"
] | 1fc1d5ee79aaf823b246db5471ba7836 | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β the number of test cases. The next $$$2t$$$ lines describe test cases. Each test case is given on two lines. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β the length of the robot's path. The second line of the test case contains one string $$$s$$$ consisting of $$$n$$$ characters 'L', 'R', 'U', 'D' β the robot's path. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | 1,500 | For each test case, print the answer on it. If you cannot remove such non-empty substring that the endpoint of the robot's path doesn't change, print -1. Otherwise, print two integers $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$ β endpoints of the substring you remove. The value $$$r-l+1$$$ should be minimum possible. If there are several answers, print any of them. | standard output | |
PASSED | 31cccdffd9b92bb1975a1d998a67cdde | train_000.jsonl | 1304485200 | Polycarp thinks about the meaning of life very often. He does this constantly, even when typing in the editor. Every time he starts brooding he can no longer fully concentrate and repeatedly presses the keys that need to be pressed only once. For example, instead of the phrase "how are you" he can type "hhoow aaaare yyoouu". Polycarp decided to automate the process of correcting such errors. He decided to write a plug-in to the text editor that will remove pairs of identical consecutive letters (if there are any in the text). Of course, this is not exactly what Polycarp needs, but he's got to start from something! Help Polycarp and write the main plug-in module. Your program should remove from a string all pairs of identical letters, which are consecutive. If after the removal there appear new pairs, the program should remove them as well. Technically, its work should be equivalent to the following: while the string contains a pair of consecutive identical letters, the pair should be deleted. Note that deleting of the consecutive identical letters can be done in any order, as any order leads to the same result. | 256 megabytes | /**
* Mx NINJA
* 01:50:13 Ψ΅
* 21/12/2013
*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Stack;
public class Main {
public static void main(String[] args)throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
char [] line = reader.readLine().toCharArray();
ArrayList<Character> charList = new ArrayList<Character>();
Stack<Character> stack = new Stack<Character>();
for(int i=0; i<line.length;i++){
if(stack.isEmpty() || stack.peek() != line[i]){
stack.push(line[i]);
} else {
stack.pop();
}
}
StringBuilder result = new StringBuilder();
while(!stack.isEmpty()){
result.append(stack.pop());
}
System.out.println(result.reverse().toString());
}
} | Java | ["hhoowaaaareyyoouu", "reallazy", "abacabaabacabaa"] | 1 second | ["wre", "rezy", "a"] | null | Java 6 | standard input | [
"implementation"
] | 26f1b8c3cb83603c904e1508df4067f4 | The input data consists of a single line to be processed. The length of the line is from 1 to 2Β·105 characters inclusive. The string contains only lowercase Latin letters. | 1,400 | Print the given string after it is processed. It is guaranteed that the result will contain at least one character. | standard output | |
PASSED | 444c78326dc2c4f6ae82b6168e82be9d | train_000.jsonl | 1304485200 | Polycarp thinks about the meaning of life very often. He does this constantly, even when typing in the editor. Every time he starts brooding he can no longer fully concentrate and repeatedly presses the keys that need to be pressed only once. For example, instead of the phrase "how are you" he can type "hhoow aaaare yyoouu". Polycarp decided to automate the process of correcting such errors. He decided to write a plug-in to the text editor that will remove pairs of identical consecutive letters (if there are any in the text). Of course, this is not exactly what Polycarp needs, but he's got to start from something! Help Polycarp and write the main plug-in module. Your program should remove from a string all pairs of identical letters, which are consecutive. If after the removal there appear new pairs, the program should remove them as well. Technically, its work should be equivalent to the following: while the string contains a pair of consecutive identical letters, the pair should be deleted. Note that deleting of the consecutive identical letters can be done in any order, as any order leads to the same result. | 256 megabytes |
import java.util.Deque;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Scanner;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author nik
*/
public class Plugin {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String line = scanner.nextLine();
Deque<Character> deque = new LinkedList<Character>();
for (Character c : line.toCharArray()) {
if (c != deque.peekLast())
deque.addLast(c);
else
deque.pollLast();
}
StringBuilder builder = new StringBuilder();
for (Iterator<Character> i = deque.iterator(); i.hasNext(); ) {
Character c = i.next();
builder.append(c);
//i.remove();
}
System.out.println(builder.toString());
}
}
| Java | ["hhoowaaaareyyoouu", "reallazy", "abacabaabacabaa"] | 1 second | ["wre", "rezy", "a"] | null | Java 6 | standard input | [
"implementation"
] | 26f1b8c3cb83603c904e1508df4067f4 | The input data consists of a single line to be processed. The length of the line is from 1 to 2Β·105 characters inclusive. The string contains only lowercase Latin letters. | 1,400 | Print the given string after it is processed. It is guaranteed that the result will contain at least one character. | standard output | |
PASSED | ee56723880c07ec8670cff9747e737e8 | train_000.jsonl | 1304485200 | Polycarp thinks about the meaning of life very often. He does this constantly, even when typing in the editor. Every time he starts brooding he can no longer fully concentrate and repeatedly presses the keys that need to be pressed only once. For example, instead of the phrase "how are you" he can type "hhoow aaaare yyoouu". Polycarp decided to automate the process of correcting such errors. He decided to write a plug-in to the text editor that will remove pairs of identical consecutive letters (if there are any in the text). Of course, this is not exactly what Polycarp needs, but he's got to start from something! Help Polycarp and write the main plug-in module. Your program should remove from a string all pairs of identical letters, which are consecutive. If after the removal there appear new pairs, the program should remove them as well. Technically, its work should be equivalent to the following: while the string contains a pair of consecutive identical letters, the pair should be deleted. Note that deleting of the consecutive identical letters can be done in any order, as any order leads to the same result. | 256 megabytes |
import java.util.Deque;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Scanner;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author nik
*/
public class Plugin {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String line = scanner.nextLine();
Deque<Character> deque = new LinkedList<Character>();
for (Character c : line.toCharArray()) {
if (c != deque.peekLast())
deque.addLast(c);
else
deque.pollLast();
}
StringBuilder builder = new StringBuilder();
for (Iterator<Character> i = deque.iterator(); i.hasNext(); ) {
Character c = i.next();
builder.append(c);
i.remove();
}
System.out.println(builder.toString());
}
}
| Java | ["hhoowaaaareyyoouu", "reallazy", "abacabaabacabaa"] | 1 second | ["wre", "rezy", "a"] | null | Java 6 | standard input | [
"implementation"
] | 26f1b8c3cb83603c904e1508df4067f4 | The input data consists of a single line to be processed. The length of the line is from 1 to 2Β·105 characters inclusive. The string contains only lowercase Latin letters. | 1,400 | Print the given string after it is processed. It is guaranteed that the result will contain at least one character. | standard output | |
PASSED | 0167c72a406e1fd733742e037b8b90d9 | train_000.jsonl | 1304485200 | Polycarp thinks about the meaning of life very often. He does this constantly, even when typing in the editor. Every time he starts brooding he can no longer fully concentrate and repeatedly presses the keys that need to be pressed only once. For example, instead of the phrase "how are you" he can type "hhoow aaaare yyoouu". Polycarp decided to automate the process of correcting such errors. He decided to write a plug-in to the text editor that will remove pairs of identical consecutive letters (if there are any in the text). Of course, this is not exactly what Polycarp needs, but he's got to start from something! Help Polycarp and write the main plug-in module. Your program should remove from a string all pairs of identical letters, which are consecutive. If after the removal there appear new pairs, the program should remove them as well. Technically, its work should be equivalent to the following: while the string contains a pair of consecutive identical letters, the pair should be deleted. Note that deleting of the consecutive identical letters can be done in any order, as any order leads to the same result. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
char[] a = r.readLine().toCharArray();
char[] b = new char[a.length];
int p = -1;
for(int i = 0; i < a.length; i++)
if(p != -1 && b[p] == a[i])b[p--]=0;
else b[++p] = a[i];
char[] res = new char[p+1];
for(int i = 0; i < p+1; i++)
res[i] = b[i];
System.out.print(new String(res));
}
}
| Java | ["hhoowaaaareyyoouu", "reallazy", "abacabaabacabaa"] | 1 second | ["wre", "rezy", "a"] | null | Java 6 | standard input | [
"implementation"
] | 26f1b8c3cb83603c904e1508df4067f4 | The input data consists of a single line to be processed. The length of the line is from 1 to 2Β·105 characters inclusive. The string contains only lowercase Latin letters. | 1,400 | Print the given string after it is processed. It is guaranteed that the result will contain at least one character. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.