exec_outcome stringclasses 1 value | code_uid stringlengths 32 32 | file_name stringclasses 111 values | prob_desc_created_at stringlengths 10 10 | prob_desc_description stringlengths 63 3.8k | prob_desc_memory_limit stringclasses 18 values | source_code stringlengths 117 65.5k | lang_cluster stringclasses 1 value | prob_desc_sample_inputs stringlengths 2 802 | prob_desc_time_limit stringclasses 27 values | prob_desc_sample_outputs stringlengths 2 796 | prob_desc_notes stringlengths 4 3k ⌀ | lang stringclasses 5 values | prob_desc_input_from stringclasses 3 values | tags listlengths 0 11 | src_uid stringlengths 32 32 | prob_desc_input_spec stringlengths 28 2.37k ⌀ | difficulty int64 -1 3.5k ⌀ | prob_desc_output_spec stringlengths 17 1.47k ⌀ | prob_desc_output_to stringclasses 3 values | hidden_unit_tests stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
PASSED | 4bea869f1a04551239e591c3b7c2f18c | train_003.jsonl | 1538750100 | Vasya has recently got a job as a cashier at a local store. His day at work is $$$L$$$ minutes long. Vasya has already memorized $$$n$$$ regular customers, the $$$i$$$-th of which comes after $$$t_{i}$$$ minutes after the beginning of the day, and his service consumes $$$l_{i}$$$ minutes. It is guaranteed that no customer will arrive while Vasya is servicing another customer. Vasya is a bit lazy, so he likes taking smoke breaks for $$$a$$$ minutes each. Those breaks may go one after another, but Vasya must be present at work during all the time periods he must serve regular customers, otherwise one of them may alert his boss. What is the maximum number of breaks Vasya can take during the day? | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
public class B implements Runnable {
public void run() {
final InputReader sc = new InputReader(System.in);
final PrintWriter out = new PrintWriter(System.out);
int jalsa=0;
int n=sc.nextInt();
int l=sc.nextInt();
int a=sc.nextInt();
int x=0;
int lastTime=0;
for(int i=0;i<n;i++)
{
int t = sc.nextInt();
int li = sc.nextInt();
jalsa += (t - lastTime) / a;
lastTime = t + li;
}
//System.out.println(depature);
int temp2=(l-lastTime);
temp2=temp2/a;
jalsa=jalsa+temp2;
System.out.println(jalsa);
out.close();
}
//========================================================
static class Pair
{
int a,b;
Pair(final int aa,final int bb)
{
a=aa;
b=bb;
}
}
static void sa(final int a[],final InputReader sc)
{
for(int i=0;i<a.length;i++)
{
a[i]=sc.nextInt();
}
Arrays.sort(a);
}
static class InputReader {
private final InputStream stream;
private final byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
private final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public InputReader(final 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 (final IOException e) {
throw new InputMismatchException();
}
if(numChars <= 0)
return -1;
}
return buf[curChar++];
}
public String nextLine() {
String str = "";
try {
str = br.readLine();
}
catch (final IOException e) {
e.printStackTrace();
}
return str;
}
public int nextInt() {
int c = read();
while(isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if(c<'0'||c>'9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public double nextDouble() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
if (c == '.') {
c = read();
double m = 1;
while (!isSpaceChar(c)) {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public String readString() {
int c = read();
while (isSpaceChar(c))
c = read();
final StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
}
while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(final int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next() {
return readString();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
public static void main(final String args[]) throws Exception {
new Thread(null, new B(),"Main",1<<27).start();
}
} | Java | ["2 11 3\n0 1\n1 1", "0 5 2", "1 3 2\n1 2"] | 2 seconds | ["3", "2", "0"] | NoteIn the first sample Vasya can take $$$3$$$ breaks starting after $$$2$$$, $$$5$$$ and $$$8$$$ minutes after the beginning of the day.In the second sample Vasya can take $$$2$$$ breaks starting after $$$0$$$ and $$$2$$$ minutes after the beginning of the day.In the third sample Vasya can't take any breaks. | Java 11 | standard input | [
"implementation"
] | 00acb3b54975820989a788b9389c7c0b | The first line contains three integers $$$n$$$, $$$L$$$ and $$$a$$$ ($$$0 \le n \le 10^{5}$$$, $$$1 \le L \le 10^{9}$$$, $$$1 \le a \le L$$$). The $$$i$$$-th of the next $$$n$$$ lines contains two integers $$$t_{i}$$$ and $$$l_{i}$$$ ($$$0 \le t_{i} \le L - 1$$$, $$$1 \le l_{i} \le L$$$). It is guaranteed that $$$t_{i} + l_{i} \le t_{i + 1}$$$ and $$$t_{n} + l_{n} \le L$$$. | 1,000 | Output one integer — the maximum number of breaks. | standard output | |
PASSED | 916960204922ff4d01789bf897e66232 | train_003.jsonl | 1538750100 | Vasya has recently got a job as a cashier at a local store. His day at work is $$$L$$$ minutes long. Vasya has already memorized $$$n$$$ regular customers, the $$$i$$$-th of which comes after $$$t_{i}$$$ minutes after the beginning of the day, and his service consumes $$$l_{i}$$$ minutes. It is guaranteed that no customer will arrive while Vasya is servicing another customer. Vasya is a bit lazy, so he likes taking smoke breaks for $$$a$$$ minutes each. Those breaks may go one after another, but Vasya must be present at work during all the time periods he must serve regular customers, otherwise one of them may alert his boss. What is the maximum number of breaks Vasya can take during the day? | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.BigInteger;
import java.math.BigDecimal;
import java.math.RoundingMode;
public class forces{
public static void main(String args[])throws IOException{
//DataInputStream ins=new DataInputStream(System.in);
Reader sc=new Reader();
long n=sc.nextLong();
long l=sc.nextLong();
long a=sc.nextLong();
long beg=0;
long show=0;
for(int i=0;i<n;i++){
long t=sc.nextLong();
long s=sc.nextLong();
show+=(t-beg)/a;
beg=t+s;
}
show+=(l-beg)/a;
System.out.println(show);
}
/*
Code for simuntanious sorting...
Integer[] idxs = new Integer[drag.length];
for(int i = 0; i < drag.length; i++) idxs[i] = i;
Arrays.sort(idxs, (o1,o2) -> Integer.compare(drag[o1], drag[o2]));
*/
static class Reader
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1)
{
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.')
{
while ((c = read()) >= '0' && c <= '9')
{
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
}
/*
*/
| Java | ["2 11 3\n0 1\n1 1", "0 5 2", "1 3 2\n1 2"] | 2 seconds | ["3", "2", "0"] | NoteIn the first sample Vasya can take $$$3$$$ breaks starting after $$$2$$$, $$$5$$$ and $$$8$$$ minutes after the beginning of the day.In the second sample Vasya can take $$$2$$$ breaks starting after $$$0$$$ and $$$2$$$ minutes after the beginning of the day.In the third sample Vasya can't take any breaks. | Java 11 | standard input | [
"implementation"
] | 00acb3b54975820989a788b9389c7c0b | The first line contains three integers $$$n$$$, $$$L$$$ and $$$a$$$ ($$$0 \le n \le 10^{5}$$$, $$$1 \le L \le 10^{9}$$$, $$$1 \le a \le L$$$). The $$$i$$$-th of the next $$$n$$$ lines contains two integers $$$t_{i}$$$ and $$$l_{i}$$$ ($$$0 \le t_{i} \le L - 1$$$, $$$1 \le l_{i} \le L$$$). It is guaranteed that $$$t_{i} + l_{i} \le t_{i + 1}$$$ and $$$t_{n} + l_{n} \le L$$$. | 1,000 | Output one integer — the maximum number of breaks. | standard output | |
PASSED | e0cdd9171fd3b4e36e3f8d5321ddd912 | train_003.jsonl | 1538750100 | Vasya has recently got a job as a cashier at a local store. His day at work is $$$L$$$ minutes long. Vasya has already memorized $$$n$$$ regular customers, the $$$i$$$-th of which comes after $$$t_{i}$$$ minutes after the beginning of the day, and his service consumes $$$l_{i}$$$ minutes. It is guaranteed that no customer will arrive while Vasya is servicing another customer. Vasya is a bit lazy, so he likes taking smoke breaks for $$$a$$$ minutes each. Those breaks may go one after another, but Vasya must be present at work during all the time periods he must serve regular customers, otherwise one of them may alert his boss. What is the maximum number of breaks Vasya can take during the day? | 256 megabytes | /* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Arrays;
import java.math.BigInteger;
/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner in =new Scanner(System.in);
long t=1,i,l,a,p;
String s="",st="";
int x=0,m,n,h,k,j;
for(i=0;i<t;i++)
{
p=0;
n=in.nextInt();
l=in.nextLong();
a=in.nextLong();
long b[]=new long[n];
long c[]=new long[n];
for(j=0;j<n;j++)
{
b[j]=in.nextLong();
c[j]=in.nextLong();
}
if(n>0)
{
p+=b[0]/a;
for(j=0;j<n-1;j++)
p+=(b[j+1]-(c[j]+b[j]))/a;
p+=(l-(c[n-1]+b[n-1]))/a;
}
else
p+=l/a;
System.out.println(p);
}
}
} | Java | ["2 11 3\n0 1\n1 1", "0 5 2", "1 3 2\n1 2"] | 2 seconds | ["3", "2", "0"] | NoteIn the first sample Vasya can take $$$3$$$ breaks starting after $$$2$$$, $$$5$$$ and $$$8$$$ minutes after the beginning of the day.In the second sample Vasya can take $$$2$$$ breaks starting after $$$0$$$ and $$$2$$$ minutes after the beginning of the day.In the third sample Vasya can't take any breaks. | Java 11 | standard input | [
"implementation"
] | 00acb3b54975820989a788b9389c7c0b | The first line contains three integers $$$n$$$, $$$L$$$ and $$$a$$$ ($$$0 \le n \le 10^{5}$$$, $$$1 \le L \le 10^{9}$$$, $$$1 \le a \le L$$$). The $$$i$$$-th of the next $$$n$$$ lines contains two integers $$$t_{i}$$$ and $$$l_{i}$$$ ($$$0 \le t_{i} \le L - 1$$$, $$$1 \le l_{i} \le L$$$). It is guaranteed that $$$t_{i} + l_{i} \le t_{i + 1}$$$ and $$$t_{n} + l_{n} \le L$$$. | 1,000 | Output one integer — the maximum number of breaks. | standard output | |
PASSED | d170627f5316f448c19e3ed26182d952 | train_003.jsonl | 1538750100 | Vasya has recently got a job as a cashier at a local store. His day at work is $$$L$$$ minutes long. Vasya has already memorized $$$n$$$ regular customers, the $$$i$$$-th of which comes after $$$t_{i}$$$ minutes after the beginning of the day, and his service consumes $$$l_{i}$$$ minutes. It is guaranteed that no customer will arrive while Vasya is servicing another customer. Vasya is a bit lazy, so he likes taking smoke breaks for $$$a$$$ minutes each. Those breaks may go one after another, but Vasya must be present at work during all the time periods he must serve regular customers, otherwise one of them may alert his boss. What is the maximum number of breaks Vasya can take during the day? | 256 megabytes | import java.util.*;
import java.lang.*;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt(),l=sc.nextInt(),b=sc.nextInt();
int a[][]=new int[n][2];
for(int i=0;i<n;i++){
a[i][0]=sc.nextInt();
a[i][1]=sc.nextInt();
}
int cur=0,ans=0;
for(int i=0;i<n;i++){
ans+=(a[i][0]-cur)/b;
cur=a[i][0]+a[i][1];
}
ans+=(l-cur)/b;
System.out.println(ans);
}
} | Java | ["2 11 3\n0 1\n1 1", "0 5 2", "1 3 2\n1 2"] | 2 seconds | ["3", "2", "0"] | NoteIn the first sample Vasya can take $$$3$$$ breaks starting after $$$2$$$, $$$5$$$ and $$$8$$$ minutes after the beginning of the day.In the second sample Vasya can take $$$2$$$ breaks starting after $$$0$$$ and $$$2$$$ minutes after the beginning of the day.In the third sample Vasya can't take any breaks. | Java 11 | standard input | [
"implementation"
] | 00acb3b54975820989a788b9389c7c0b | The first line contains three integers $$$n$$$, $$$L$$$ and $$$a$$$ ($$$0 \le n \le 10^{5}$$$, $$$1 \le L \le 10^{9}$$$, $$$1 \le a \le L$$$). The $$$i$$$-th of the next $$$n$$$ lines contains two integers $$$t_{i}$$$ and $$$l_{i}$$$ ($$$0 \le t_{i} \le L - 1$$$, $$$1 \le l_{i} \le L$$$). It is guaranteed that $$$t_{i} + l_{i} \le t_{i + 1}$$$ and $$$t_{n} + l_{n} \le L$$$. | 1,000 | Output one integer — the maximum number of breaks. | standard output | |
PASSED | 84aa6bd84c01debad1d612265d027e26 | train_003.jsonl | 1538750100 | Vasya has recently got a job as a cashier at a local store. His day at work is $$$L$$$ minutes long. Vasya has already memorized $$$n$$$ regular customers, the $$$i$$$-th of which comes after $$$t_{i}$$$ minutes after the beginning of the day, and his service consumes $$$l_{i}$$$ minutes. It is guaranteed that no customer will arrive while Vasya is servicing another customer. Vasya is a bit lazy, so he likes taking smoke breaks for $$$a$$$ minutes each. Those breaks may go one after another, but Vasya must be present at work during all the time periods he must serve regular customers, otherwise one of them may alert his boss. What is the maximum number of breaks Vasya can take during the day? | 256 megabytes | import java.util.Scanner;
/**
* https://codeforces.com/problemset/problem/1059/A
*/
public class Problem1059A {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
scanner.useDelimiter(System.lineSeparator());
String[] f = scanner.next().split(" ");
int n = Integer.parseInt(f[0]);
int L = Integer.parseInt(f[1]);
int a = Integer.parseInt(f[2]);
int currentTime = 0;
int result = 0;
for (int i = 0; i < n; i++) {
String[] client = scanner.next().split(" ");
int t = Integer.parseInt(client[0]);
int l = Integer.parseInt(client[1]);
result += (t - currentTime) / a;
currentTime = t + l;
}
scanner.close();
result += (L - currentTime) / a;
System.out.println(result);
}
}
| Java | ["2 11 3\n0 1\n1 1", "0 5 2", "1 3 2\n1 2"] | 2 seconds | ["3", "2", "0"] | NoteIn the first sample Vasya can take $$$3$$$ breaks starting after $$$2$$$, $$$5$$$ and $$$8$$$ minutes after the beginning of the day.In the second sample Vasya can take $$$2$$$ breaks starting after $$$0$$$ and $$$2$$$ minutes after the beginning of the day.In the third sample Vasya can't take any breaks. | Java 11 | standard input | [
"implementation"
] | 00acb3b54975820989a788b9389c7c0b | The first line contains three integers $$$n$$$, $$$L$$$ and $$$a$$$ ($$$0 \le n \le 10^{5}$$$, $$$1 \le L \le 10^{9}$$$, $$$1 \le a \le L$$$). The $$$i$$$-th of the next $$$n$$$ lines contains two integers $$$t_{i}$$$ and $$$l_{i}$$$ ($$$0 \le t_{i} \le L - 1$$$, $$$1 \le l_{i} \le L$$$). It is guaranteed that $$$t_{i} + l_{i} \le t_{i + 1}$$$ and $$$t_{n} + l_{n} \le L$$$. | 1,000 | Output one integer — the maximum number of breaks. | standard output | |
PASSED | 7eae4e4e5fc3bbf653450a794ffc95c4 | train_003.jsonl | 1433595600 | Berlanders like to eat cones after a hard day. Misha Square and Sasha Circle are local authorities of Berland. Each of them controls its points of cone trade. Misha has n points, Sasha — m. Since their subordinates constantly had conflicts with each other, they decided to build a fence in the form of a circle, so that the points of trade of one businessman are strictly inside a circle, and points of the other one are strictly outside. It doesn't matter which of the two gentlemen will have his trade points inside the circle.Determine whether they can build a fence or not. | 256 megabytes | import java.io.*;
import java.util.*;
public class MainMtf {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskCircles solver = new TaskCircles();
solver.solve(in, out);
out.close();
}
}
class Point
{
public int x;
public int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
}
class ClockwiseComparator implements Comparator<Point>
{
Point o;
public ClockwiseComparator(Point o) { this.o = o; }
public static int det(Point p, Point q, Point o) {
return (p.x - o.x) * (q.y - o.y) - (p.y - o.y) * (q.x - o.x);
}
@Override
public int compare(Point p, Point q) {
int d = det(p, q, o);
if (d != 0) return d;
return (o.x - p.x) * (q.x - p.x) + (o.y - p.y) * (q.y - p.y);
}
}
class TaskCircles {
InputReader in;
PrintWriter out;
public void solve(InputReader in, PrintWriter out) {
this.in = in;
this.out = out;
int n = in.nextInt(), m = in.nextInt();
Point[] a = new Point[n];
Point[] b = new Point[m];
for (int i = 0; i < n; ++i) {
a[i] = new Point(in.nextInt(), in.nextInt());
}
for (int i = 0; i < m; ++i) {
b[i] = new Point(in.nextInt(), in.nextInt());
}
out.println(solve(a, b) || solve(b, a) ? "YES" : "NO");
}
public static Point[] convexHull(Point[] points) {
if (points.length < 3)
return points.clone();
Point[] ch = points.clone();
for (int i = 1; i < ch.length; ++i)
if (ch[i].x < ch[0].x || ch[i].x == ch[0].x && ch[i].y < ch[0].y) {
Point tmp = ch[i];
ch[i] = ch[0];
ch[0] = tmp;
}
Arrays.sort(ch, 1, ch.length, new ClockwiseComparator(ch[0]));
int h = 1;
for (int i = 2; i < ch.length; ++i) {
while (h > 0 && ClockwiseComparator.det(ch[h - 1], ch[h], ch[i]) >= 0)
--h;
ch[++h] = ch[i];
}
return Arrays.copyOf(ch, h + 1);
}
public boolean solve(Point[] a, Point[] b) {
if (a.length == 1)
return true;
a = convexHull(a);
return solve(a, b, 0, a.length - 1);
}
public boolean solve(Point[] a, Point[] b, int i, int j) {
int dx = a[i].y - a[j].y;
int dy = a[j].x - a[i].x;
int minNum = Integer.MIN_VALUE, minDen = 1;
int mid = -1;
for (int k = i + 1; k < j; ++k) {
int ka = a[k].x - a[i].x;
int kb = a[k].y - a[i].y;
int kc = (a[k].x - a[j].x) * ka + (a[k].y - a[j].y) * kb;
int kd = dx * ka + dy * kb;
if ((long)kc * minDen > (long)kd * minNum) {
minNum = kc;
minDen = kd;
mid = k;
}
}
int maxNum = Integer.MAX_VALUE, maxDen = 1;
for (int k = j + 1; ; ++k) {
if (k == a.length)
k = 0;
if (k == i)
break;
int ka = a[i].x - a[k].x;
int kb = a[i].y - a[k].y;
int kc = (a[k].x - a[j].x) * ka + (a[k].y - a[j].y) * kb;
int kd = dx * ka + dy * kb;
if ((long)kc * maxDen < (long)kd * maxNum) {
maxNum = kc;
maxDen = kd;
}
}
boolean yes = true;
for (int k = 0; k < b.length; ++k) {
int ka = b[k].x - a[i].x;
int kb = b[k].y - a[i].y;
int kc = (b[k].x - a[j].x) * ka + (b[k].y - a[j].y) * kb;
int kd = dx * ka + dy * kb;
if (kd > 0) {
if ((long)kc * maxDen <= (long)kd * maxNum) {
maxNum = kc;
maxDen = kd;
}
} else if (kd < 0) {
if ((long)kc * minDen <= (long)kd * minNum) {
minNum = -kc;
minDen = -kd;
}
} else if (kc <= 0) {
yes = false;
break;
}
if ((long)minNum * maxDen >= (long)minDen * maxNum) {
yes = false;
break;
}
}
return yes || mid >= 0 && (solve(a, b, i, mid) || solve(a, b, mid, j));
}
}
class InputReader {
private BufferedReader reader;
private StringTokenizer tokenizer;
public InputReader(InputStream inputStream) {
reader = new BufferedReader(new InputStreamReader(inputStream));
}
public String nextLine() {
try {
return reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens())
tokenizer = new StringTokenizer(nextLine());
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
} | Java | ["2 2\n-1 0\n1 0\n0 -1\n0 1", "4 4\n1 0\n0 1\n-1 0\n0 -1\n1 1\n-1 1\n-1 -1\n1 -1"] | 2 seconds | ["NO", "YES"] | NoteIn the first sample there is no possibility to separate points, because any circle that contains both points ( - 1, 0), (1, 0) also contains at least one point from the set (0, - 1), (0, 1), and vice-versa: any circle that contains both points (0, - 1), (0, 1) also contains at least one point from the set ( - 1, 0), (1, 0)In the second sample one of the possible solution is shown below. Misha's points are marked with red colour and Sasha's are marked with blue. | Java 8 | standard input | [
"geometry",
"math"
] | 2effde97cdb0e9962452a9cab63673c1 | The first line contains two integers n and m (1 ≤ n, m ≤ 10000), numbers of Misha's and Sasha's trade points respectively. The next n lines contains pairs of space-separated integers Mx, My ( - 104 ≤ Mx, My ≤ 104), coordinates of Misha's trade points. The next m lines contains pairs of space-separated integers Sx, Sy ( - 104 ≤ Sx, Sy ≤ 104), coordinates of Sasha's trade points. It is guaranteed that all n + m points are distinct. | 2,700 | The only output line should contain either word "YES" without quotes in case it is possible to build a such fence or word "NO" in the other case. | standard output | |
PASSED | 09b52c7549772cc7fee480387ae146a0 | train_003.jsonl | 1290096000 | It's a very unfortunate day for Volodya today. He got bad mark in algebra and was therefore forced to do some work in the kitchen, namely to cook borscht (traditional Russian soup). This should also improve his algebra skills.According to the borscht recipe it consists of n ingredients that have to be mixed in proportion litres (thus, there should be a1 ·x, ..., an ·x litres of corresponding ingredients mixed for some non-negative x). In the kitchen Volodya found out that he has b1, ..., bn litres of these ingredients at his disposal correspondingly. In order to correct his algebra mistakes he ought to cook as much soup as possible in a V litres volume pan (which means the amount of soup cooked can be between 0 and V litres). What is the volume of borscht Volodya will cook ultimately? | 256 megabytes | import java.util.Scanner;
public class Solution
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
float v = sc.nextFloat();
float[] a = new float[100];
float[] b = new float[100];
for (int i = 0; i < n; i++)
a[i] = sc.nextFloat();
for (int i = 0; i < n; i++)
b[i] = sc.nextFloat();
float min = Float.MAX_VALUE;
for (int i = 0; i < n; i++)
if (min > (b[i] / a[i]))
min = b[i] / a[i];
float result = 0;
for (int i = 0; i < n; i++)
result += a[i] * min;
if (result > v)
System.out.println(v);
else
System.out.println(result);
}
}
| Java | ["1 100\n1\n40", "2 100\n1 1\n25 30", "2 100\n1 1\n60 60"] | 2 seconds | ["40.0", "50.0", "100.0"] | null | Java 7 | standard input | [
"implementation",
"greedy"
] | 351d8874a10f84d157a7b2e1eb64e2a1 | The first line of the input contains two space-separated integers n and V (1 ≤ n ≤ 20, 1 ≤ V ≤ 10000). The next line contains n space-separated integers ai (1 ≤ ai ≤ 100). Finally, the last line contains n space-separated integers bi (0 ≤ bi ≤ 100). | 1,400 | Your program should output just one real number — the volume of soup that Volodya will cook. Your answer must have a relative or absolute error less than 10 - 4. | standard output | |
PASSED | c3504aef1d3555c1577b311dd3bb910c | train_003.jsonl | 1290096000 | It's a very unfortunate day for Volodya today. He got bad mark in algebra and was therefore forced to do some work in the kitchen, namely to cook borscht (traditional Russian soup). This should also improve his algebra skills.According to the borscht recipe it consists of n ingredients that have to be mixed in proportion litres (thus, there should be a1 ·x, ..., an ·x litres of corresponding ingredients mixed for some non-negative x). In the kitchen Volodya found out that he has b1, ..., bn litres of these ingredients at his disposal correspondingly. In order to correct his algebra mistakes he ought to cook as much soup as possible in a V litres volume pan (which means the amount of soup cooked can be between 0 and V litres). What is the volume of borscht Volodya will cook ultimately? | 256 megabytes | import java.util.*;
public class Guilty{
public static void main(String[] args){
// Read input
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int v = scan.nextInt();
int[] a = new int[n];
int[] b = new int[n];
for(int i = 0; i < n; i++) a[i] = scan.nextInt();
for(int i = 0; i < n; i++) b[i] = scan.nextInt();
// Calculate smallest proportions
float c = ((float) b[0])/a[0];
for(int i = 0; i < n; i++) c = Math.min(c, ((float) b[i])/a[i]);
// Now sum c factor times ingredients
float sum = 0;
for(int i = 0; i < n; i++) sum += c * ((float) a[i]);
System.out.println(Math.min(sum, (float) v));
}
} | Java | ["1 100\n1\n40", "2 100\n1 1\n25 30", "2 100\n1 1\n60 60"] | 2 seconds | ["40.0", "50.0", "100.0"] | null | Java 7 | standard input | [
"implementation",
"greedy"
] | 351d8874a10f84d157a7b2e1eb64e2a1 | The first line of the input contains two space-separated integers n and V (1 ≤ n ≤ 20, 1 ≤ V ≤ 10000). The next line contains n space-separated integers ai (1 ≤ ai ≤ 100). Finally, the last line contains n space-separated integers bi (0 ≤ bi ≤ 100). | 1,400 | Your program should output just one real number — the volume of soup that Volodya will cook. Your answer must have a relative or absolute error less than 10 - 4. | standard output | |
PASSED | 80ff42ecd470491a57670fb33aaa342a | train_003.jsonl | 1290096000 | It's a very unfortunate day for Volodya today. He got bad mark in algebra and was therefore forced to do some work in the kitchen, namely to cook borscht (traditional Russian soup). This should also improve his algebra skills.According to the borscht recipe it consists of n ingredients that have to be mixed in proportion litres (thus, there should be a1 ·x, ..., an ·x litres of corresponding ingredients mixed for some non-negative x). In the kitchen Volodya found out that he has b1, ..., bn litres of these ingredients at his disposal correspondingly. In order to correct his algebra mistakes he ought to cook as much soup as possible in a V litres volume pan (which means the amount of soup cooked can be between 0 and V litres). What is the volume of borscht Volodya will cook ultimately? | 256 megabytes | import java.io.InputStream;
import java.io.OutputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;
public class Task {
private static final boolean readFromFile = false;
private static final String fileInputName = "input.txt",
fileOutputName = "output.txt";
public static void main(String args[]){
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
FileOutputStream fileOutputStream;
FileInputStream fileInputStream;
if (readFromFile){
try{
fileInputStream = new FileInputStream(new File(fileInputName));
fileOutputStream = new FileOutputStream(new File(fileOutputName));
}catch (FileNotFoundException e){
throw new RuntimeException(e);
}
}
PrintWriter out = new PrintWriter((readFromFile)?fileOutputStream:outputStream);
InputReader in = new InputReader((readFromFile)?fileInputStream:inputStream);
Solver s = new Solver(in,out);
s.solve();
out.close();
}
}
class Solver{
InputReader in;
PrintWriter out;
static final double eps = 1e-7;
double a[],b[];
double ans = 0;
int n;
boolean may(double x){
double c[] = new double[n];
double forOne = x/a[0];
for (int i=0;i<n;i++)
c[i]=forOne*a[i];
for (int i=0;i<n;i++)
if (c[i]>b[i])
return false;
double sum = 0;
for (int i=0;i<n;i++)
sum += c[i];
ans = Math.max(sum, ans);
return true;
}
void binarySearch(double l, double r){
while (r-l>eps){
double m = (l+r)/2;
if (may(m))
l = m+eps;
else
r = m-eps;
}
}
public void solve(){
n = in.nextInt();
double v = in.nextDouble();
a = new double[n];
b = new double[n];
for (int i=0;i<n;i++)
a[i] = in.nextDouble();
for (int i=0;i<n;i++)
b[i] = in.nextDouble();
binarySearch(0,b[0]);
out.println(Math.min(ans, v));
}
Solver(InputReader in, PrintWriter out){
this.in=in;
this.out=out;
}
}
class InputReader{
private BufferedReader buf;
private StringTokenizer tok;
InputReader(InputStream in){
tok = null;
buf = new BufferedReader(new InputStreamReader(in));
}
InputReader(FileInputStream in){
tok = null;
buf = new BufferedReader(new InputStreamReader(in));
}
public String next(){
while (tok==null || !tok.hasMoreTokens()){
try{
tok = new StringTokenizer(buf.readLine());
}catch (IOException e){
throw new RuntimeException(e);
}
}
return tok.nextToken();
}
public int nextInt(){
return Integer.parseInt(next());
}
public long nextLong(){
return Long.parseLong(next());
}
public double nextDouble(){
return Double.parseDouble(next());
}
public float nextFloat(){
return Float.parseFloat(next());
}
public String nextLine(){
try{
return buf.readLine();
}catch (IOException e){
return null;
}
}
} | Java | ["1 100\n1\n40", "2 100\n1 1\n25 30", "2 100\n1 1\n60 60"] | 2 seconds | ["40.0", "50.0", "100.0"] | null | Java 7 | standard input | [
"implementation",
"greedy"
] | 351d8874a10f84d157a7b2e1eb64e2a1 | The first line of the input contains two space-separated integers n and V (1 ≤ n ≤ 20, 1 ≤ V ≤ 10000). The next line contains n space-separated integers ai (1 ≤ ai ≤ 100). Finally, the last line contains n space-separated integers bi (0 ≤ bi ≤ 100). | 1,400 | Your program should output just one real number — the volume of soup that Volodya will cook. Your answer must have a relative or absolute error less than 10 - 4. | standard output | |
PASSED | 2d197c76a6f0e83dba4e9d681c1472b8 | train_003.jsonl | 1290096000 | It's a very unfortunate day for Volodya today. He got bad mark in algebra and was therefore forced to do some work in the kitchen, namely to cook borscht (traditional Russian soup). This should also improve his algebra skills.According to the borscht recipe it consists of n ingredients that have to be mixed in proportion litres (thus, there should be a1 ·x, ..., an ·x litres of corresponding ingredients mixed for some non-negative x). In the kitchen Volodya found out that he has b1, ..., bn litres of these ingredients at his disposal correspondingly. In order to correct his algebra mistakes he ought to cook as much soup as possible in a V litres volume pan (which means the amount of soup cooked can be between 0 and V litres). What is the volume of borscht Volodya will cook ultimately? | 256 megabytes | import java.io.*;
/**
* Created by KC on 4/8/14.
*/
public class GuiltyKitchen {
static BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter printWriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
public static void main(String[] args) throws IOException{
// volume / need
// smallest ratio multiply the total
String[] p = bufferedReader.readLine().trim().split("\\s+");
int n = Integer.parseInt(p[0]);
int max = Integer.parseInt(p[1]);
int[] a = new int[n];
p = bufferedReader.readLine().trim().split("\\s+");
int total = 0;
for(int i = 0 ; i < n; i++){
a[i] = Integer.parseInt(p[i]);
total += a[i];
}
double ratio = Double.MAX_VALUE;
p = bufferedReader.readLine().trim().split("\\s+");
for(int i = 0; i < n; i++){
int tmp = Integer.parseInt(p[i]);
ratio = Math.min(ratio, (double) tmp/ (double)a[i] );
}
double value = Math.min(total*ratio, max);
printWriter.print(value);
printWriter.flush();
printWriter.close();
}
}
| Java | ["1 100\n1\n40", "2 100\n1 1\n25 30", "2 100\n1 1\n60 60"] | 2 seconds | ["40.0", "50.0", "100.0"] | null | Java 7 | standard input | [
"implementation",
"greedy"
] | 351d8874a10f84d157a7b2e1eb64e2a1 | The first line of the input contains two space-separated integers n and V (1 ≤ n ≤ 20, 1 ≤ V ≤ 10000). The next line contains n space-separated integers ai (1 ≤ ai ≤ 100). Finally, the last line contains n space-separated integers bi (0 ≤ bi ≤ 100). | 1,400 | Your program should output just one real number — the volume of soup that Volodya will cook. Your answer must have a relative or absolute error less than 10 - 4. | standard output | |
PASSED | 0a78199003be0df6141c0b074e516e88 | train_003.jsonl | 1290096000 | It's a very unfortunate day for Volodya today. He got bad mark in algebra and was therefore forced to do some work in the kitchen, namely to cook borscht (traditional Russian soup). This should also improve his algebra skills.According to the borscht recipe it consists of n ingredients that have to be mixed in proportion litres (thus, there should be a1 ·x, ..., an ·x litres of corresponding ingredients mixed for some non-negative x). In the kitchen Volodya found out that he has b1, ..., bn litres of these ingredients at his disposal correspondingly. In order to correct his algebra mistakes he ought to cook as much soup as possible in a V litres volume pan (which means the amount of soup cooked can be between 0 and V litres). What is the volume of borscht Volodya will cook ultimately? | 256 megabytes |
import java.util.*;
import java.io.*;
public class Main{
public static void main (String[]args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int v = Integer.parseInt(st.nextToken());
int[] ratio = new int[n];
int[] volumes = new int[n];
st = new StringTokenizer(br.readLine());
for(int i=0; i<n; i++) ratio[i] = Integer.parseInt(st.nextToken());
st = new StringTokenizer(br.readLine());
for(int i=0; i<n; i++) volumes[i] = Integer.parseInt(st.nextToken());
double lo = 0;
double hi = v;
double mid = 0;
double eps = Math.pow(10,-9);
while(Math.abs(lo-hi) > eps){
//System.out.println(mid + " " + Math.abs(lo-hi));
mid = (lo+hi)/2;
boolean b = true;
double total = 0;
for(int i=0; i<n; i++){
double cur = ratio[i] * mid;
total+= cur;
if(cur+eps > volumes[i]) b = false;
}
if(total+eps>=v) b = false;
if(b) lo = mid;
else hi = mid;
}
double res = 0;
for(int i=0; i<n; i++) res+= mid*ratio[i];
System.out.println(res);
//System.out.println(mid);
}
}
| Java | ["1 100\n1\n40", "2 100\n1 1\n25 30", "2 100\n1 1\n60 60"] | 2 seconds | ["40.0", "50.0", "100.0"] | null | Java 7 | standard input | [
"implementation",
"greedy"
] | 351d8874a10f84d157a7b2e1eb64e2a1 | The first line of the input contains two space-separated integers n and V (1 ≤ n ≤ 20, 1 ≤ V ≤ 10000). The next line contains n space-separated integers ai (1 ≤ ai ≤ 100). Finally, the last line contains n space-separated integers bi (0 ≤ bi ≤ 100). | 1,400 | Your program should output just one real number — the volume of soup that Volodya will cook. Your answer must have a relative or absolute error less than 10 - 4. | standard output | |
PASSED | a323506281924e90470bf3d0c1b1fab5 | train_003.jsonl | 1290096000 | It's a very unfortunate day for Volodya today. He got bad mark in algebra and was therefore forced to do some work in the kitchen, namely to cook borscht (traditional Russian soup). This should also improve his algebra skills.According to the borscht recipe it consists of n ingredients that have to be mixed in proportion litres (thus, there should be a1 ·x, ..., an ·x litres of corresponding ingredients mixed for some non-negative x). In the kitchen Volodya found out that he has b1, ..., bn litres of these ingredients at his disposal correspondingly. In order to correct his algebra mistakes he ought to cook as much soup as possible in a V litres volume pan (which means the amount of soup cooked can be between 0 and V litres). What is the volume of borscht Volodya will cook ultimately? | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
public class Main {
public static void main (String[] args){
Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
int n = in.nextInt();
int[] a = new int[n];
int[] b = new int[n];
float[] xs = new float[n];
int V = in.nextInt();
int c = 0;
while (c<n){
a[c]= in.nextInt();
c++;
}
c = 0;
while (c<n){
b[c]= in.nextInt();
c++;
}
int now;
c =0 ;
while (c<n){
xs[c]=(float)b[c]/(float)a[c];
c++;
}
float x= xs[0];
c = 0;
int aa = 0;
while (c<n){
if (x> xs[c]){
x = xs[c];
}
aa += a[c];
c++;
}
if (aa*x>=V){
float v = V;
System.out.println(v);
} else {
System.out.println(aa*x);
}
}
} | Java | ["1 100\n1\n40", "2 100\n1 1\n25 30", "2 100\n1 1\n60 60"] | 2 seconds | ["40.0", "50.0", "100.0"] | null | Java 7 | standard input | [
"implementation",
"greedy"
] | 351d8874a10f84d157a7b2e1eb64e2a1 | The first line of the input contains two space-separated integers n and V (1 ≤ n ≤ 20, 1 ≤ V ≤ 10000). The next line contains n space-separated integers ai (1 ≤ ai ≤ 100). Finally, the last line contains n space-separated integers bi (0 ≤ bi ≤ 100). | 1,400 | Your program should output just one real number — the volume of soup that Volodya will cook. Your answer must have a relative or absolute error less than 10 - 4. | standard output | |
PASSED | 83b6c9b18ccb8e74a0d7303ca03cf9ad | train_003.jsonl | 1440865800 | Would you want to fight against bears riding horses? Me neither.Limak is a grizzly bear. He is general of the dreadful army of Bearland. The most important part of an army is cavalry of course.Cavalry of Bearland consists of n warriors and n horses. i-th warrior has strength wi and i-th horse has strength hi. Warrior together with his horse is called a unit. Strength of a unit is equal to multiplied strengths of warrior and horse. Total strength of cavalry is equal to sum of strengths of all n units. Good assignment of warriors and horses makes cavalry truly powerful.Initially, i-th warrior has i-th horse. You are given q queries. In each query two warriors swap their horses with each other.General Limak must be ready for every possible situation. What if warriors weren't allowed to ride their own horses? After each query find the maximum possible strength of cavalry if we consider assignments of all warriors to all horses that no warrior is assigned to his own horse (it can be proven that for n ≥ 2 there is always at least one correct assignment).Note that we can't leave a warrior without a horse. | 256 megabytes | import java.util.*;
import java.io.*;
public class BearAndCavalry
{
public static Element[] warriors;
public static Element[] horses;
public static boolean[] match;
public static void main(String[] args) throws Exception
{
FastScanner in = new FastScanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = in.nextInt();
int q = in.nextInt();
warriors = new Element[n];
for(int x = 0; x < n; x++)
{
warriors[x] = new Element(in.nextInt(), x);
}
horses = new Element[n];
for(int y = 0; y < n; y++)
{
horses[y] = new Element(in.nextInt(), y);
}
match = new boolean[n];
Arrays.sort(warriors);
Arrays.sort(horses);
int[] index = new int[n];
int[] horseIndex = new int[n];
for(int z = 0; z < warriors.length; z++)
{
if(warriors[z].index == horses[z].index)
{
match[z] = true;
}
index[warriors[z].index] = z;
horseIndex[horses[z].index] = z;
}
SegmentTree st = new SegmentTree(n);
for(int a = 0; a < q; a++)
{
int x = in.nextInt() - 1;
int y = in.nextInt() - 1;
int temp = horseIndex[x];
horseIndex[x] = horseIndex[y];
horseIndex[y] = temp;
match[index[x]] = (index[x] == horseIndex[x]);
match[index[y]] = (index[y] == horseIndex[y]);
st.modify(index[x]);
st.modify(index[y]);
out.println(st.query());
}
out.close();
}
public static long calc(int i, int size)
{
if(size == 1)
{
return warriors[i].value * horses[i].value;
}
else if(size == 2)
{
return warriors[i].value * horses[i + 1].value + warriors[i + 1].value * horses[i].value;
}
else
{
return Math.max(warriors[i].value * horses[i + 1].value + warriors[i + 1].value * horses[i + 2].value + warriors[i + 2].value * horses[i].value,
warriors[i].value * horses[i + 2].value + warriors[i + 1].value * horses[i].value + warriors[i + 2].value * horses[i + 1].value);
}
}
static class Element implements Comparable<Element>
{
long value;
int index;
public Element(long v, int i)
{
value = v;
index = i;
}
public int compareTo(Element o)
{
return Long.compare(value, o.value);
}
}
static class SegmentTree
{
int n;
long[][][] dp;
public SegmentTree(int n)
{
this.n = n;
dp = new long[3][3][n << 2 | 1];
build(1, 0, n - 1);
}
public void build(int i, int l, int r)
{
if(r - l < 8)
{
apply(i, l, r);
}
else
{
int mid = (l + r) >> 1;
build(i << 1, l, mid);
build(i << 1 | 1, mid + 1, r);
update(i, l, r);
}
}
public void modify(int pos)
{
modify(1, 0, n - 1, pos);
}
public void modify(int i, int l, int r, int pos)
{
if(r < pos || l > pos)
{
return;
}
else if(r - l < 8)
{
apply(i, l, r);
}
else
{
int mid = (l + r) >> 1;
modify(i << 1, l, mid, pos);
modify(i << 1 | 1, mid + 1, r, pos);
update(i, l, r);
}
}
public long query()
{
return dp[0][0][1];
}
public void apply(int i, int l, int r)
{
for(int a = 0; a < 3; a++)
{
int len = r - l + 1 - a;
long[] sdp = new long[len + 1];
Arrays.fill(sdp, -Integer.MIN_VALUE);
sdp[0] = 0;
for(int b = 0; b < len; b++)
{
if(!match[l + a + b])
{
sdp[b + 1] = Math.max(sdp[b + 1], sdp[b] + calc(l + a + b, 1));
}
if(b < len - 1)
{
sdp[b + 2] = Math.max(sdp[b + 2], sdp[b] + calc(l + a + b, 2));
}
if(b < len - 2)
{
sdp[b + 3] = Math.max(sdp[b + 3], sdp[b] + calc(l + a + b, 3));
}
}
for(int c = 0; c < 3 && len - c >= 0; c++)
{
dp[a][c][i] = sdp[len - c];
}
}
}
public void update(int i, int l, int r)
{
int mid = (l + r) >> 1;
for(int d = 0; d < 3; d++)
{
for(int e = 0; e < 3; e++)
{
dp[d][e][i] = dp[d][0][i << 1] + dp[0][e][i << 1 | 1];
dp[d][e][i] = Math.max(dp[d][e][i], dp[d][1][i << 1] + dp[1][e][i << 1 | 1] + calc(mid, 2));
dp[d][e][i] = Math.max(dp[d][e][i], dp[d][2][i << 1] + dp[1][e][i << 1 | 1] + calc(mid - 1, 3));
dp[d][e][i] = Math.max(dp[d][e][i], dp[d][1][i << 1] + dp[2][e][i << 1 | 1] + calc(mid, 3));
}
}
}
}
static class FastScanner
{
BufferedReader br;
StringTokenizer st;
public FastScanner(InputStream input)
{
br = new BufferedReader(new InputStreamReader(input));
st = new StringTokenizer("");
}
public String next() throws IOException
{
if(st.hasMoreTokens())
{
return st.nextToken();
}
else
{
st = new StringTokenizer(br.readLine());
return next();
}
}
public int nextInt() throws IOException
{
return Integer.parseInt(next());
}
}
}
| Java | ["4 2\n1 10 100 1000\n3 7 2 5\n2 4\n2 4", "3 3\n7 11 5\n3 2 1\n1 2\n1 3\n2 3", "7 4\n1 2 4 8 16 32 64\n87 40 77 29 50 11 18\n1 5\n2 7\n6 2\n5 6"] | 3 seconds | ["5732\n7532", "44\n48\n52", "9315\n9308\n9315\n9315"] | NoteClarification for the first sample: Warriors: 1 10 100 1000Horses: 3 7 2 5 After first query situation looks like the following: Warriors: 1 10 100 1000Horses: 3 5 2 7 We can get 1·2 + 10·3 + 100·7 + 1000·5 = 5732 (note that no hussar takes his own horse in this assignment).After second query we get back to initial situation and optimal assignment is 1·2 + 10·3 + 100·5 + 1000·7 = 7532.Clarification for the second sample. After first query: Warriors: 7 11 5Horses: 2 3 1 Optimal assignment is 7·1 + 11·2 + 5·3 = 44.Then after second query 7·3 + 11·2 + 5·1 = 48.Finally 7·2 + 11·3 + 5·1 = 52. | Java 7 | standard input | [
"dp",
"divide and conquer",
"data structures"
] | 49c721b0f02d0f138529ced1a3b9445f | The first line contains two space-separated integers, n and q (2 ≤ n ≤ 30 000, 1 ≤ q ≤ 10 000). The second line contains n space-separated integers, w1, w2, ..., wn (1 ≤ wi ≤ 106) — strengths of warriors. The third line contains n space-separated integers, h1, h2, ..., hn (1 ≤ hi ≤ 106) — strengths of horses. Next q lines describe queries. i-th of them contains two space-separated integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), indices of warriors who swap their horses with each other. | 3,000 | Print q lines with answers to queries. In i-th line print the maximum possible strength of cavalry after first i queries. | standard output | |
PASSED | cb7ac0f2d16b8e1d424a10acaba59496 | train_003.jsonl | 1578139500 | Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.There are two sequences of $$$n$$$ strings $$$s_1, s_2, s_3, \ldots, s_{n}$$$ and $$$m$$$ strings $$$t_1, t_2, t_3, \ldots, t_{m}$$$. These strings contain only lowercase letters. There might be duplicates among these strings.Let's call a concatenation of strings $$$x$$$ and $$$y$$$ as the string that is obtained by writing down strings $$$x$$$ and $$$y$$$ one right after another without changing the order. For example, the concatenation of the strings "code" and "forces" is the string "codeforces".The year 1 has a name which is the concatenation of the two strings $$$s_1$$$ and $$$t_1$$$. When the year increases by one, we concatenate the next two strings in order from each of the respective sequences. If the string that is currently being used is at the end of its sequence, we go back to the first string in that sequence.For example, if $$$n = 3, m = 4, s = $$${"a", "b", "c"}, $$$t =$$$ {"d", "e", "f", "g"}, the following table denotes the resulting year names. Note that the names of the years may repeat. You are given two sequences of strings of size $$$n$$$ and $$$m$$$ and also $$$q$$$ queries. For each query, you will be given the current year. Could you find the name corresponding to the given year, according to the Gapja system? | 1024 megabytes | import java.util.*;
import java.io.*;
import java.lang.*;
public class cfs {
static class node {
String d;
node next;
node(String a) {
this.d = a;
next = null;
}
}
static node head1;
static node head2;
static long mod = 1000000007;
static int gcd(int a, int b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
// Function to return LCM of two numbers
static int lcm(int a, int b) {
return (a * b) / gcd(a, b);
}
public static void main(String[] args)throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String s1[]=br.readLine().split(" ");
int n = Integer.parseInt(s1[0]);
int m = Integer.parseInt(s1[1]);
String a1[] =br.readLine().split(" ");
String a2[] = br.readLine().split(" ");
node nn=new node(a1[0]);
head1=nn;
for (int i = 1; i < n ; i++) {
nn.next = new node(a1[i]);
nn=nn.next;
}
nn.next = head1;
node nn2 = new node(a2[0]);
head2 = nn2;
for (int i = 1; i < m; i++) {
nn2.next = new node(a2[i]);
nn2=nn2.next;
}
nn2.next = head2;
int lc = lcm(n, m);
String arr[] = new String[lc+1];
arr[0] = "AA";
node n1 = head1;
node n2 = head2;
for (int i = 1; i <= lc; i++) {
String s = n1.d + n2.d;
arr[i] = s;
n1 = n1.next;
n2 = n2.next;
}
arr[0]=arr[lc];
/* for(int i=0;i<=lc;i++) {
System.out.println(arr[i]);
}*/
int q=Integer.parseInt(br.readLine());
for(int i=1;i<=q;i++) {
int qq=Integer.parseInt(br.readLine());
int ind=qq%lc;
System.out.println(arr[ind]);
}
}
}
| Java | ["10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020"] | 1 second | ["sinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsin\ngyeyu\ngyeyu\nbyeongsin\njeongyu\nmusul\ngihae\ngyeongja"] | NoteThe first example denotes the actual names used in the Gapja system. These strings usually are either a number or the name of some animal. | Java 8 | standard input | [
"implementation",
"strings"
] | efa201456f8703fcdc29230248d91c54 | The first line contains two integers $$$n, m$$$ ($$$1 \le n, m \le 20$$$). The next line contains $$$n$$$ strings $$$s_1, s_2, \ldots, s_{n}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. The next line contains $$$m$$$ strings $$$t_1, t_2, \ldots, t_{m}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. Among the given $$$n + m$$$ strings may be duplicates (that is, they are not necessarily all different). The next line contains a single integer $$$q$$$ ($$$1 \le q \le 2\,020$$$). In the next $$$q$$$ lines, an integer $$$y$$$ ($$$1 \le y \le 10^9$$$) is given, denoting the year we want to know the name for. | 800 | Print $$$q$$$ lines. For each line, print the name of the year as per the rule described above. | standard output | |
PASSED | 00461169eaa43e02d0dcf4cf23494728 | train_003.jsonl | 1578139500 | Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.There are two sequences of $$$n$$$ strings $$$s_1, s_2, s_3, \ldots, s_{n}$$$ and $$$m$$$ strings $$$t_1, t_2, t_3, \ldots, t_{m}$$$. These strings contain only lowercase letters. There might be duplicates among these strings.Let's call a concatenation of strings $$$x$$$ and $$$y$$$ as the string that is obtained by writing down strings $$$x$$$ and $$$y$$$ one right after another without changing the order. For example, the concatenation of the strings "code" and "forces" is the string "codeforces".The year 1 has a name which is the concatenation of the two strings $$$s_1$$$ and $$$t_1$$$. When the year increases by one, we concatenate the next two strings in order from each of the respective sequences. If the string that is currently being used is at the end of its sequence, we go back to the first string in that sequence.For example, if $$$n = 3, m = 4, s = $$${"a", "b", "c"}, $$$t =$$$ {"d", "e", "f", "g"}, the following table denotes the resulting year names. Note that the names of the years may repeat. You are given two sequences of strings of size $$$n$$$ and $$$m$$$ and also $$$q$$$ queries. For each query, you will be given the current year. Could you find the name corresponding to the given year, according to the Gapja system? | 1024 megabytes | import java.util.*;
import java.io.*;
import java.lang.*;
public class cfs {
static class node {
String d;
node next;
node(String a) {
this.d = a;
next = null;
}
}
static node head1;
static node head2;
static long mod = 1000000007;
static int gcd(int a, int b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
// Function to return LCM of two numbers
static int lcm(int a, int b) {
return (a * b) / gcd(a, b);
}
public static void main(String[] args)throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String s1[]=br.readLine().split(" ");
int n = Integer.parseInt(s1[0]);
int m = Integer.parseInt(s1[1]);
String a1[] =br.readLine().split(" ");
String a2[] = br.readLine().split(" ");
node nn=new node(a1[0]);
head1=nn;
for (int i = 1; i < n ; i++) {
nn.next = new node(a1[i]);
nn=nn.next;
}
nn.next = head1;
node nn2 = new node(a2[0]);
head2 = nn2;
for (int i = 1; i < m; i++) {
nn2.next = new node(a2[i]);
nn2=nn2.next;
}
nn2.next = head2;
int lc = lcm(n, m);
String arr[] = new String[lc+1];
arr[0] = "AA";
node n1 = head1;
node n2 = head2;
for (int i = 1; i <= lc; i++) {
String s = n1.d + n2.d;
arr[i] = s;
n1 = n1.next;
n2 = n2.next;
}
arr[0]=arr[lc];
/* for(int i=0;i<=lc;i++) {
System.out.println(arr[i]);
}*/
int q=Integer.parseInt(br.readLine());
for(int i=1;i<=q;i++) {
int qq=Integer.parseInt(br.readLine());
int ind=qq%lc;
System.out.println(arr[ind]);
}
}
}
| Java | ["10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020"] | 1 second | ["sinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsin\ngyeyu\ngyeyu\nbyeongsin\njeongyu\nmusul\ngihae\ngyeongja"] | NoteThe first example denotes the actual names used in the Gapja system. These strings usually are either a number or the name of some animal. | Java 8 | standard input | [
"implementation",
"strings"
] | efa201456f8703fcdc29230248d91c54 | The first line contains two integers $$$n, m$$$ ($$$1 \le n, m \le 20$$$). The next line contains $$$n$$$ strings $$$s_1, s_2, \ldots, s_{n}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. The next line contains $$$m$$$ strings $$$t_1, t_2, \ldots, t_{m}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. Among the given $$$n + m$$$ strings may be duplicates (that is, they are not necessarily all different). The next line contains a single integer $$$q$$$ ($$$1 \le q \le 2\,020$$$). In the next $$$q$$$ lines, an integer $$$y$$$ ($$$1 \le y \le 10^9$$$) is given, denoting the year we want to know the name for. | 800 | Print $$$q$$$ lines. For each line, print the name of the year as per the rule described above. | standard output | |
PASSED | cd536871f9ef12fa6da56ff510b4962a | train_003.jsonl | 1578139500 | Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.There are two sequences of $$$n$$$ strings $$$s_1, s_2, s_3, \ldots, s_{n}$$$ and $$$m$$$ strings $$$t_1, t_2, t_3, \ldots, t_{m}$$$. These strings contain only lowercase letters. There might be duplicates among these strings.Let's call a concatenation of strings $$$x$$$ and $$$y$$$ as the string that is obtained by writing down strings $$$x$$$ and $$$y$$$ one right after another without changing the order. For example, the concatenation of the strings "code" and "forces" is the string "codeforces".The year 1 has a name which is the concatenation of the two strings $$$s_1$$$ and $$$t_1$$$. When the year increases by one, we concatenate the next two strings in order from each of the respective sequences. If the string that is currently being used is at the end of its sequence, we go back to the first string in that sequence.For example, if $$$n = 3, m = 4, s = $$${"a", "b", "c"}, $$$t =$$$ {"d", "e", "f", "g"}, the following table denotes the resulting year names. Note that the names of the years may repeat. You are given two sequences of strings of size $$$n$$$ and $$$m$$$ and also $$$q$$$ queries. For each query, you will be given the current year. Could you find the name corresponding to the given year, according to the Gapja system? | 1024 megabytes | import java.io.*;
/**
*
* @author pc
*/
public class NewYearAndNaming {
public static String[] initializeArray(String input){
return input.split(" ");
}
public static void main(String args[]) throws IOException{
BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in));
String numberInput=bufferedReader.readLine();
int n=Integer.parseInt(numberInput.split(" ")[0]);
int m=Integer.parseInt(numberInput.split(" ")[1]);
String[] s=initializeArray(bufferedReader.readLine());
String[] t=initializeArray(bufferedReader.readLine());
int testCases=Integer.parseInt(bufferedReader.readLine());
String x="";
for(int i=1;i<=testCases;i++){
int year=Integer.parseInt(bufferedReader.readLine());
int j=(year%n==0)?n-1:year%n-1,k=(year%m==0)?m-1:year%m-1;
x=s[j]+t[k];
System.out.println(x);
}
}
}
| Java | ["10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020"] | 1 second | ["sinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsin\ngyeyu\ngyeyu\nbyeongsin\njeongyu\nmusul\ngihae\ngyeongja"] | NoteThe first example denotes the actual names used in the Gapja system. These strings usually are either a number or the name of some animal. | Java 8 | standard input | [
"implementation",
"strings"
] | efa201456f8703fcdc29230248d91c54 | The first line contains two integers $$$n, m$$$ ($$$1 \le n, m \le 20$$$). The next line contains $$$n$$$ strings $$$s_1, s_2, \ldots, s_{n}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. The next line contains $$$m$$$ strings $$$t_1, t_2, \ldots, t_{m}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. Among the given $$$n + m$$$ strings may be duplicates (that is, they are not necessarily all different). The next line contains a single integer $$$q$$$ ($$$1 \le q \le 2\,020$$$). In the next $$$q$$$ lines, an integer $$$y$$$ ($$$1 \le y \le 10^9$$$) is given, denoting the year we want to know the name for. | 800 | Print $$$q$$$ lines. For each line, print the name of the year as per the rule described above. | standard output | |
PASSED | c4def4b0702801131584fd0eae0922d9 | train_003.jsonl | 1578139500 | Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.There are two sequences of $$$n$$$ strings $$$s_1, s_2, s_3, \ldots, s_{n}$$$ and $$$m$$$ strings $$$t_1, t_2, t_3, \ldots, t_{m}$$$. These strings contain only lowercase letters. There might be duplicates among these strings.Let's call a concatenation of strings $$$x$$$ and $$$y$$$ as the string that is obtained by writing down strings $$$x$$$ and $$$y$$$ one right after another without changing the order. For example, the concatenation of the strings "code" and "forces" is the string "codeforces".The year 1 has a name which is the concatenation of the two strings $$$s_1$$$ and $$$t_1$$$. When the year increases by one, we concatenate the next two strings in order from each of the respective sequences. If the string that is currently being used is at the end of its sequence, we go back to the first string in that sequence.For example, if $$$n = 3, m = 4, s = $$${"a", "b", "c"}, $$$t =$$$ {"d", "e", "f", "g"}, the following table denotes the resulting year names. Note that the names of the years may repeat. You are given two sequences of strings of size $$$n$$$ and $$$m$$$ and also $$$q$$$ queries. For each query, you will be given the current year. Could you find the name corresponding to the given year, according to the Gapja system? | 1024 megabytes | import java.util.*;
import java.io.*;
final public class NewYear implements Runnable{
public static void main(String[] args) throws Exception {
Thread thread = new Thread(null, new NewYear(), "gulshan7", 1L<<10);
thread.start();
thread.join();
}
public void run() {
try {
//System.out.println(1L<<10);
solve();
} catch (Exception e) {
System.err.println(e);
}
}
public void solve() throws Exception {
FastScanner scanner = new FastScanner();
PrintWriter out = new PrintWriter(System.out, false);
int t = scanner.nextInt();
int m = scanner .nextInt();
String[] left = scanner.readNextLine().split(" ");
String[] right = scanner.readNextLine().split(" ");
int cases = scanner.nextInt();
while(cases-->0) {
int n = scanner.nextInt();
int leftIndex = n%t;
if(leftIndex ==0){
leftIndex = t;
}
int rightIndex = n%m;
if(rightIndex == 0){
rightIndex = m;
}
out.println(left[leftIndex -1] + right[rightIndex-1]);
}
out.flush();
}
public static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(Reader in) {
br = new BufferedReader(in);
}
public FastScanner() {
this(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 readNextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
} | Java | ["10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020"] | 1 second | ["sinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsin\ngyeyu\ngyeyu\nbyeongsin\njeongyu\nmusul\ngihae\ngyeongja"] | NoteThe first example denotes the actual names used in the Gapja system. These strings usually are either a number or the name of some animal. | Java 8 | standard input | [
"implementation",
"strings"
] | efa201456f8703fcdc29230248d91c54 | The first line contains two integers $$$n, m$$$ ($$$1 \le n, m \le 20$$$). The next line contains $$$n$$$ strings $$$s_1, s_2, \ldots, s_{n}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. The next line contains $$$m$$$ strings $$$t_1, t_2, \ldots, t_{m}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. Among the given $$$n + m$$$ strings may be duplicates (that is, they are not necessarily all different). The next line contains a single integer $$$q$$$ ($$$1 \le q \le 2\,020$$$). In the next $$$q$$$ lines, an integer $$$y$$$ ($$$1 \le y \le 10^9$$$) is given, denoting the year we want to know the name for. | 800 | Print $$$q$$$ lines. For each line, print the name of the year as per the rule described above. | standard output | |
PASSED | 6c11d60e579f8806257ad3adc8b7cd3a | train_003.jsonl | 1578139500 | Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.There are two sequences of $$$n$$$ strings $$$s_1, s_2, s_3, \ldots, s_{n}$$$ and $$$m$$$ strings $$$t_1, t_2, t_3, \ldots, t_{m}$$$. These strings contain only lowercase letters. There might be duplicates among these strings.Let's call a concatenation of strings $$$x$$$ and $$$y$$$ as the string that is obtained by writing down strings $$$x$$$ and $$$y$$$ one right after another without changing the order. For example, the concatenation of the strings "code" and "forces" is the string "codeforces".The year 1 has a name which is the concatenation of the two strings $$$s_1$$$ and $$$t_1$$$. When the year increases by one, we concatenate the next two strings in order from each of the respective sequences. If the string that is currently being used is at the end of its sequence, we go back to the first string in that sequence.For example, if $$$n = 3, m = 4, s = $$${"a", "b", "c"}, $$$t =$$$ {"d", "e", "f", "g"}, the following table denotes the resulting year names. Note that the names of the years may repeat. You are given two sequences of strings of size $$$n$$$ and $$$m$$$ and also $$$q$$$ queries. For each query, you will be given the current year. Could you find the name corresponding to the given year, according to the Gapja system? | 1024 megabytes | import java.util.Scanner;
public class YearTask{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int y = sc.nextInt();
sc.nextLine();
String arr1[] = sc.nextLine().split(" ");
String arr2[] = sc.nextLine().split(" ");
int n = sc.nextInt();
int arr[] = new int[n];
for (int i=0;i<n ;i++ ) {
arr[i] = sc.nextInt();
}
int p,q;
for(int i = 0;i<n; i++){
p=q=arr[i];
while (p>x) {
p %= x;
if (p==0) {
p=x;
}
}
while(q>y){
q %= y;
if (q==0) {
q=y;
}
}
System.out.println(arr1[p-1].concat(arr2[q-1]));
}
}
} | Java | ["10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020"] | 1 second | ["sinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsin\ngyeyu\ngyeyu\nbyeongsin\njeongyu\nmusul\ngihae\ngyeongja"] | NoteThe first example denotes the actual names used in the Gapja system. These strings usually are either a number or the name of some animal. | Java 8 | standard input | [
"implementation",
"strings"
] | efa201456f8703fcdc29230248d91c54 | The first line contains two integers $$$n, m$$$ ($$$1 \le n, m \le 20$$$). The next line contains $$$n$$$ strings $$$s_1, s_2, \ldots, s_{n}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. The next line contains $$$m$$$ strings $$$t_1, t_2, \ldots, t_{m}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. Among the given $$$n + m$$$ strings may be duplicates (that is, they are not necessarily all different). The next line contains a single integer $$$q$$$ ($$$1 \le q \le 2\,020$$$). In the next $$$q$$$ lines, an integer $$$y$$$ ($$$1 \le y \le 10^9$$$) is given, denoting the year we want to know the name for. | 800 | Print $$$q$$$ lines. For each line, print the name of the year as per the rule described above. | standard output | |
PASSED | 616a7f11d892c7a6c3399efa1a9aacfb | train_003.jsonl | 1578139500 | Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.There are two sequences of $$$n$$$ strings $$$s_1, s_2, s_3, \ldots, s_{n}$$$ and $$$m$$$ strings $$$t_1, t_2, t_3, \ldots, t_{m}$$$. These strings contain only lowercase letters. There might be duplicates among these strings.Let's call a concatenation of strings $$$x$$$ and $$$y$$$ as the string that is obtained by writing down strings $$$x$$$ and $$$y$$$ one right after another without changing the order. For example, the concatenation of the strings "code" and "forces" is the string "codeforces".The year 1 has a name which is the concatenation of the two strings $$$s_1$$$ and $$$t_1$$$. When the year increases by one, we concatenate the next two strings in order from each of the respective sequences. If the string that is currently being used is at the end of its sequence, we go back to the first string in that sequence.For example, if $$$n = 3, m = 4, s = $$${"a", "b", "c"}, $$$t =$$$ {"d", "e", "f", "g"}, the following table denotes the resulting year names. Note that the names of the years may repeat. You are given two sequences of strings of size $$$n$$$ and $$$m$$$ and also $$$q$$$ queries. For each query, you will be given the current year. Could you find the name corresponding to the given year, according to the Gapja system? | 1024 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int m = scan.nextInt();
String[] a = new String[n];
String[] b = new String[m];
for(int i =0;i<n;i++){
a[i] = scan.next();
}
for(int i=0;i<m;i++){
b[i] = scan.next();
}
int t = scan.nextInt();
while(t-->0){
int z = scan.nextInt();
int k = z%n;
int l = z%m;
if(k==0 && l!=0){
System.out.print(a[n-1]+b[l-1]);
System.out.println();
continue;
}
if(l==0 && k!=0){
System.out.print(a[k-1]+b[m-1]);
System.out.println();
continue;
}
if(z%n==0 && z%m==0){
System.out.print(a[n-1]+b[m-1]);
System.out.println();
continue;
}
else{
System.out.print(a[k-1]+b[l-1]);
}
System.out.println();
}
}
} | Java | ["10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020"] | 1 second | ["sinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsin\ngyeyu\ngyeyu\nbyeongsin\njeongyu\nmusul\ngihae\ngyeongja"] | NoteThe first example denotes the actual names used in the Gapja system. These strings usually are either a number or the name of some animal. | Java 8 | standard input | [
"implementation",
"strings"
] | efa201456f8703fcdc29230248d91c54 | The first line contains two integers $$$n, m$$$ ($$$1 \le n, m \le 20$$$). The next line contains $$$n$$$ strings $$$s_1, s_2, \ldots, s_{n}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. The next line contains $$$m$$$ strings $$$t_1, t_2, \ldots, t_{m}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. Among the given $$$n + m$$$ strings may be duplicates (that is, they are not necessarily all different). The next line contains a single integer $$$q$$$ ($$$1 \le q \le 2\,020$$$). In the next $$$q$$$ lines, an integer $$$y$$$ ($$$1 \le y \le 10^9$$$) is given, denoting the year we want to know the name for. | 800 | Print $$$q$$$ lines. For each line, print the name of the year as per the rule described above. | standard output | |
PASSED | 39883ce62f9c135a6c6d1840e1b57f87 | train_003.jsonl | 1578139500 | Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.There are two sequences of $$$n$$$ strings $$$s_1, s_2, s_3, \ldots, s_{n}$$$ and $$$m$$$ strings $$$t_1, t_2, t_3, \ldots, t_{m}$$$. These strings contain only lowercase letters. There might be duplicates among these strings.Let's call a concatenation of strings $$$x$$$ and $$$y$$$ as the string that is obtained by writing down strings $$$x$$$ and $$$y$$$ one right after another without changing the order. For example, the concatenation of the strings "code" and "forces" is the string "codeforces".The year 1 has a name which is the concatenation of the two strings $$$s_1$$$ and $$$t_1$$$. When the year increases by one, we concatenate the next two strings in order from each of the respective sequences. If the string that is currently being used is at the end of its sequence, we go back to the first string in that sequence.For example, if $$$n = 3, m = 4, s = $$${"a", "b", "c"}, $$$t =$$$ {"d", "e", "f", "g"}, the following table denotes the resulting year names. Note that the names of the years may repeat. You are given two sequences of strings of size $$$n$$$ and $$$m$$$ and also $$$q$$$ queries. For each query, you will be given the current year. Could you find the name corresponding to the given year, according to the Gapja system? | 1024 megabytes | import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int m = scan.nextInt();
scan.nextLine();
String[] s = scan.nextLine().split(" ");
String[] t = scan.nextLine().split(" ");
int q = scan.nextInt();
StringBuilder result = new StringBuilder();
for(int i = 0; i<q; i++) {
int y = scan.nextInt()-1;
int ms = y % s.length;
int mt = y % t.length;
result.append(s[ms] + t[mt] + "\n");
}
System.out.println(result);
}
} | Java | ["10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020"] | 1 second | ["sinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsin\ngyeyu\ngyeyu\nbyeongsin\njeongyu\nmusul\ngihae\ngyeongja"] | NoteThe first example denotes the actual names used in the Gapja system. These strings usually are either a number or the name of some animal. | Java 8 | standard input | [
"implementation",
"strings"
] | efa201456f8703fcdc29230248d91c54 | The first line contains two integers $$$n, m$$$ ($$$1 \le n, m \le 20$$$). The next line contains $$$n$$$ strings $$$s_1, s_2, \ldots, s_{n}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. The next line contains $$$m$$$ strings $$$t_1, t_2, \ldots, t_{m}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. Among the given $$$n + m$$$ strings may be duplicates (that is, they are not necessarily all different). The next line contains a single integer $$$q$$$ ($$$1 \le q \le 2\,020$$$). In the next $$$q$$$ lines, an integer $$$y$$$ ($$$1 \le y \le 10^9$$$) is given, denoting the year we want to know the name for. | 800 | Print $$$q$$$ lines. For each line, print the name of the year as per the rule described above. | standard output | |
PASSED | e151cb4e49256c8e652756633223bf2c | train_003.jsonl | 1578139500 | Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.There are two sequences of $$$n$$$ strings $$$s_1, s_2, s_3, \ldots, s_{n}$$$ and $$$m$$$ strings $$$t_1, t_2, t_3, \ldots, t_{m}$$$. These strings contain only lowercase letters. There might be duplicates among these strings.Let's call a concatenation of strings $$$x$$$ and $$$y$$$ as the string that is obtained by writing down strings $$$x$$$ and $$$y$$$ one right after another without changing the order. For example, the concatenation of the strings "code" and "forces" is the string "codeforces".The year 1 has a name which is the concatenation of the two strings $$$s_1$$$ and $$$t_1$$$. When the year increases by one, we concatenate the next two strings in order from each of the respective sequences. If the string that is currently being used is at the end of its sequence, we go back to the first string in that sequence.For example, if $$$n = 3, m = 4, s = $$${"a", "b", "c"}, $$$t =$$$ {"d", "e", "f", "g"}, the following table denotes the resulting year names. Note that the names of the years may repeat. You are given two sequences of strings of size $$$n$$$ and $$$m$$$ and also $$$q$$$ queries. For each query, you will be given the current year. Could you find the name corresponding to the given year, according to the Gapja system? | 1024 megabytes | import java.io.*;
import java.math.*;
import java.util.*;import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
public class Test3 {
private static final Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
String[] st = scanner.nextLine().split(" ");
int s=Integer.parseInt(st[0]);
int t=Integer.parseInt(st[1]);
int i;
String[] s1 = scanner.nextLine().split(" ");
String[] t1 = scanner.nextLine().split(" ");
int q=scanner.nextInt();
for(i=0;i<q;i++)
{
int y=scanner.nextInt();
int s2=(y-1)%s;
int t2=(y-1)%t;
String res=s1[s2]+t1[t2];
System.out.println(res);
}
scanner.close();
}
}
| Java | ["10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020"] | 1 second | ["sinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsin\ngyeyu\ngyeyu\nbyeongsin\njeongyu\nmusul\ngihae\ngyeongja"] | NoteThe first example denotes the actual names used in the Gapja system. These strings usually are either a number or the name of some animal. | Java 8 | standard input | [
"implementation",
"strings"
] | efa201456f8703fcdc29230248d91c54 | The first line contains two integers $$$n, m$$$ ($$$1 \le n, m \le 20$$$). The next line contains $$$n$$$ strings $$$s_1, s_2, \ldots, s_{n}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. The next line contains $$$m$$$ strings $$$t_1, t_2, \ldots, t_{m}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. Among the given $$$n + m$$$ strings may be duplicates (that is, they are not necessarily all different). The next line contains a single integer $$$q$$$ ($$$1 \le q \le 2\,020$$$). In the next $$$q$$$ lines, an integer $$$y$$$ ($$$1 \le y \le 10^9$$$) is given, denoting the year we want to know the name for. | 800 | Print $$$q$$$ lines. For each line, print the name of the year as per the rule described above. | standard output | |
PASSED | 0edef8ee64ecbf8939601b5bc0d6dfa6 | train_003.jsonl | 1578139500 | Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.There are two sequences of $$$n$$$ strings $$$s_1, s_2, s_3, \ldots, s_{n}$$$ and $$$m$$$ strings $$$t_1, t_2, t_3, \ldots, t_{m}$$$. These strings contain only lowercase letters. There might be duplicates among these strings.Let's call a concatenation of strings $$$x$$$ and $$$y$$$ as the string that is obtained by writing down strings $$$x$$$ and $$$y$$$ one right after another without changing the order. For example, the concatenation of the strings "code" and "forces" is the string "codeforces".The year 1 has a name which is the concatenation of the two strings $$$s_1$$$ and $$$t_1$$$. When the year increases by one, we concatenate the next two strings in order from each of the respective sequences. If the string that is currently being used is at the end of its sequence, we go back to the first string in that sequence.For example, if $$$n = 3, m = 4, s = $$${"a", "b", "c"}, $$$t =$$$ {"d", "e", "f", "g"}, the following table denotes the resulting year names. Note that the names of the years may repeat. You are given two sequences of strings of size $$$n$$$ and $$$m$$$ and also $$$q$$$ queries. For each query, you will be given the current year. Could you find the name corresponding to the given year, according to the Gapja system? | 1024 megabytes | import java.lang.*;
import java.util.*;
import java.io.*;
public class calendar
{
int q,n,m ;
int n1[] ;
String s1[],s2[] ;
Scanner sc=new Scanner(System.in);
PrintWriter pr=new PrintWriter(System.out,true);
public static void main(String... args)
{
calendar c=new calendar();
c.prop();
}
public void prop()
{
n=sc.nextInt();
m=sc.nextInt();
s1=new String[n] ;
s2=new String[m] ;
for (int i=0;i<n ;++i ) {
s1[i]=sc.next();
}
for (int i=0;i<m;++i ) {
s2[i]=sc.next();
}
q=sc.nextInt();
n1=new int[q];
for (int i=0;i<q;++i ) {
n1[i]=sc.nextInt();
}
for (int i=0;i<q ;++i ) {
if(n1[i]%n==0 && n1[i]%m==0)
pr.println(s1[n-1]+""+s2[m-1]);
else if(n1[i]%n==0)
{
pr.println(s1[n-1]+""+s2[n1[i]%m-1]);
}
else if(n1[i]%m==0)
{
pr.println(s1[n1[i]%n-1]+""+s2[m-1]);
}else
{
pr.println(s1[n1[i]%n-1]+""+s2[n1[i]%m-1]);
}
}
}
} | Java | ["10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020"] | 1 second | ["sinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsin\ngyeyu\ngyeyu\nbyeongsin\njeongyu\nmusul\ngihae\ngyeongja"] | NoteThe first example denotes the actual names used in the Gapja system. These strings usually are either a number or the name of some animal. | Java 8 | standard input | [
"implementation",
"strings"
] | efa201456f8703fcdc29230248d91c54 | The first line contains two integers $$$n, m$$$ ($$$1 \le n, m \le 20$$$). The next line contains $$$n$$$ strings $$$s_1, s_2, \ldots, s_{n}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. The next line contains $$$m$$$ strings $$$t_1, t_2, \ldots, t_{m}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. Among the given $$$n + m$$$ strings may be duplicates (that is, they are not necessarily all different). The next line contains a single integer $$$q$$$ ($$$1 \le q \le 2\,020$$$). In the next $$$q$$$ lines, an integer $$$y$$$ ($$$1 \le y \le 10^9$$$) is given, denoting the year we want to know the name for. | 800 | Print $$$q$$$ lines. For each line, print the name of the year as per the rule described above. | standard output | |
PASSED | 627508ddef8f4d1f5c0aebf7dc90b66e | train_003.jsonl | 1578139500 | Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.There are two sequences of $$$n$$$ strings $$$s_1, s_2, s_3, \ldots, s_{n}$$$ and $$$m$$$ strings $$$t_1, t_2, t_3, \ldots, t_{m}$$$. These strings contain only lowercase letters. There might be duplicates among these strings.Let's call a concatenation of strings $$$x$$$ and $$$y$$$ as the string that is obtained by writing down strings $$$x$$$ and $$$y$$$ one right after another without changing the order. For example, the concatenation of the strings "code" and "forces" is the string "codeforces".The year 1 has a name which is the concatenation of the two strings $$$s_1$$$ and $$$t_1$$$. When the year increases by one, we concatenate the next two strings in order from each of the respective sequences. If the string that is currently being used is at the end of its sequence, we go back to the first string in that sequence.For example, if $$$n = 3, m = 4, s = $$${"a", "b", "c"}, $$$t =$$$ {"d", "e", "f", "g"}, the following table denotes the resulting year names. Note that the names of the years may repeat. You are given two sequences of strings of size $$$n$$$ and $$$m$$$ and also $$$q$$$ queries. For each query, you will be given the current year. Could you find the name corresponding to the given year, according to the Gapja system? | 1024 megabytes | //package net.mthstudio.codeforce;
import java.util.Scanner;
import java.util.TreeMap;
public class ProblemA {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int m = in.nextInt(), n = in.nextInt();
in.nextLine();
String[] sArr = in.nextLine().split(" ");
String[] tArr = in.nextLine().split(" ");
int q = in.nextInt();
while (q-- > 0) {
int y = in.nextInt();
y--;
System.out.println(sArr[y % m] + tArr[y % n]);
}
}
}
| Java | ["10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020"] | 1 second | ["sinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsin\ngyeyu\ngyeyu\nbyeongsin\njeongyu\nmusul\ngihae\ngyeongja"] | NoteThe first example denotes the actual names used in the Gapja system. These strings usually are either a number or the name of some animal. | Java 8 | standard input | [
"implementation",
"strings"
] | efa201456f8703fcdc29230248d91c54 | The first line contains two integers $$$n, m$$$ ($$$1 \le n, m \le 20$$$). The next line contains $$$n$$$ strings $$$s_1, s_2, \ldots, s_{n}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. The next line contains $$$m$$$ strings $$$t_1, t_2, \ldots, t_{m}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. Among the given $$$n + m$$$ strings may be duplicates (that is, they are not necessarily all different). The next line contains a single integer $$$q$$$ ($$$1 \le q \le 2\,020$$$). In the next $$$q$$$ lines, an integer $$$y$$$ ($$$1 \le y \le 10^9$$$) is given, denoting the year we want to know the name for. | 800 | Print $$$q$$$ lines. For each line, print the name of the year as per the rule described above. | standard output | |
PASSED | 7245dfac63ddcf3e1acfea8b8a3a2701 | train_003.jsonl | 1578139500 | Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.There are two sequences of $$$n$$$ strings $$$s_1, s_2, s_3, \ldots, s_{n}$$$ and $$$m$$$ strings $$$t_1, t_2, t_3, \ldots, t_{m}$$$. These strings contain only lowercase letters. There might be duplicates among these strings.Let's call a concatenation of strings $$$x$$$ and $$$y$$$ as the string that is obtained by writing down strings $$$x$$$ and $$$y$$$ one right after another without changing the order. For example, the concatenation of the strings "code" and "forces" is the string "codeforces".The year 1 has a name which is the concatenation of the two strings $$$s_1$$$ and $$$t_1$$$. When the year increases by one, we concatenate the next two strings in order from each of the respective sequences. If the string that is currently being used is at the end of its sequence, we go back to the first string in that sequence.For example, if $$$n = 3, m = 4, s = $$${"a", "b", "c"}, $$$t =$$$ {"d", "e", "f", "g"}, the following table denotes the resulting year names. Note that the names of the years may repeat. You are given two sequences of strings of size $$$n$$$ and $$$m$$$ and also $$$q$$$ queries. For each query, you will be given the current year. Could you find the name corresponding to the given year, according to the Gapja system? | 1024 megabytes | import java.util.Scanner;
public class NewYearAndNaming {
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
int n=scan.nextInt();
int m=scan.nextInt();
String[] s1= new String[n];
String[] s2= new String[m];
for(int i=0;i<n;i++)
{
s1[i]=scan.next();
}
for(int i=0;i<m;i++)
{
s2[i]=scan.next();
}
int q=scan.nextInt();
for(int count=0;count<q;count++)
{
int year =scan.nextInt();
int year1=year%n;
int year2=year%m;
if (year1==0)
{
year1=n;
}
if(year2==0)
{
year2=m;
}
System.out.println(s1[year1-1]+s2[year2-1]);
}
}
}
| Java | ["10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020"] | 1 second | ["sinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsin\ngyeyu\ngyeyu\nbyeongsin\njeongyu\nmusul\ngihae\ngyeongja"] | NoteThe first example denotes the actual names used in the Gapja system. These strings usually are either a number or the name of some animal. | Java 8 | standard input | [
"implementation",
"strings"
] | efa201456f8703fcdc29230248d91c54 | The first line contains two integers $$$n, m$$$ ($$$1 \le n, m \le 20$$$). The next line contains $$$n$$$ strings $$$s_1, s_2, \ldots, s_{n}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. The next line contains $$$m$$$ strings $$$t_1, t_2, \ldots, t_{m}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. Among the given $$$n + m$$$ strings may be duplicates (that is, they are not necessarily all different). The next line contains a single integer $$$q$$$ ($$$1 \le q \le 2\,020$$$). In the next $$$q$$$ lines, an integer $$$y$$$ ($$$1 \le y \le 10^9$$$) is given, denoting the year we want to know the name for. | 800 | Print $$$q$$$ lines. For each line, print the name of the year as per the rule described above. | standard output | |
PASSED | e6d572df3b24b1e3f99d3358f38c0f8d | train_003.jsonl | 1578139500 | Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.There are two sequences of $$$n$$$ strings $$$s_1, s_2, s_3, \ldots, s_{n}$$$ and $$$m$$$ strings $$$t_1, t_2, t_3, \ldots, t_{m}$$$. These strings contain only lowercase letters. There might be duplicates among these strings.Let's call a concatenation of strings $$$x$$$ and $$$y$$$ as the string that is obtained by writing down strings $$$x$$$ and $$$y$$$ one right after another without changing the order. For example, the concatenation of the strings "code" and "forces" is the string "codeforces".The year 1 has a name which is the concatenation of the two strings $$$s_1$$$ and $$$t_1$$$. When the year increases by one, we concatenate the next two strings in order from each of the respective sequences. If the string that is currently being used is at the end of its sequence, we go back to the first string in that sequence.For example, if $$$n = 3, m = 4, s = $$${"a", "b", "c"}, $$$t =$$$ {"d", "e", "f", "g"}, the following table denotes the resulting year names. Note that the names of the years may repeat. You are given two sequences of strings of size $$$n$$$ and $$$m$$$ and also $$$q$$$ queries. For each query, you will be given the current year. Could you find the name corresponding to the given year, according to the Gapja system? | 1024 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
public class NEW_YEAR_NAMING {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s2[] = br.readLine().split(" ");
int n = Integer.parseInt(s2[0]);
int m = Integer.parseInt(s2[1]);
String[] s = br.readLine().split(" ");
String[] s1 = br.readLine().split(" ");
HashMap<Integer, String> hm = new HashMap<>();
int t = Integer.parseInt(br.readLine());
int g = gcd(n, m);
while (t-- > 0) {
int temp = Integer.parseInt(br.readLine());
System.out.println(s[(temp-1)%n]+""+s1[(temp-1)%m]);
}
}
private static int gcd(int n, int m) {
return n == 0 ? m : gcd(m% n, n);
}
}
| Java | ["10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020"] | 1 second | ["sinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsin\ngyeyu\ngyeyu\nbyeongsin\njeongyu\nmusul\ngihae\ngyeongja"] | NoteThe first example denotes the actual names used in the Gapja system. These strings usually are either a number or the name of some animal. | Java 8 | standard input | [
"implementation",
"strings"
] | efa201456f8703fcdc29230248d91c54 | The first line contains two integers $$$n, m$$$ ($$$1 \le n, m \le 20$$$). The next line contains $$$n$$$ strings $$$s_1, s_2, \ldots, s_{n}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. The next line contains $$$m$$$ strings $$$t_1, t_2, \ldots, t_{m}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. Among the given $$$n + m$$$ strings may be duplicates (that is, they are not necessarily all different). The next line contains a single integer $$$q$$$ ($$$1 \le q \le 2\,020$$$). In the next $$$q$$$ lines, an integer $$$y$$$ ($$$1 \le y \le 10^9$$$) is given, denoting the year we want to know the name for. | 800 | Print $$$q$$$ lines. For each line, print the name of the year as per the rule described above. | standard output | |
PASSED | 81ff3b959436b1b52907081d57cc1749 | train_003.jsonl | 1578139500 | Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.There are two sequences of $$$n$$$ strings $$$s_1, s_2, s_3, \ldots, s_{n}$$$ and $$$m$$$ strings $$$t_1, t_2, t_3, \ldots, t_{m}$$$. These strings contain only lowercase letters. There might be duplicates among these strings.Let's call a concatenation of strings $$$x$$$ and $$$y$$$ as the string that is obtained by writing down strings $$$x$$$ and $$$y$$$ one right after another without changing the order. For example, the concatenation of the strings "code" and "forces" is the string "codeforces".The year 1 has a name which is the concatenation of the two strings $$$s_1$$$ and $$$t_1$$$. When the year increases by one, we concatenate the next two strings in order from each of the respective sequences. If the string that is currently being used is at the end of its sequence, we go back to the first string in that sequence.For example, if $$$n = 3, m = 4, s = $$${"a", "b", "c"}, $$$t =$$$ {"d", "e", "f", "g"}, the following table denotes the resulting year names. Note that the names of the years may repeat. You are given two sequences of strings of size $$$n$$$ and $$$m$$$ and also $$$q$$$ queries. For each query, you will be given the current year. Could you find the name corresponding to the given year, according to the Gapja system? | 1024 megabytes | import java.io.*;
import java.util.*;
public class Solution
{
public static void main(String []args) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String in[]=br.readLine().split(" ");
int n=Integer.parseInt(in[0]);
int m=Integer.parseInt(in[1]);
String s1[]=br.readLine().split(" ");
String s2[]=br.readLine().split(" ");
int q=Integer.parseInt(br.readLine());
int c=s1.length;
int d=s2.length;
//System.out.println(c+" "+d);
while(q-->0)
{
int p=Integer.parseInt(br.readLine());
int t1=p-1,t2=p-1;
//while(t1>=c)
t1=t1%c;
//while(t2>=d)
t2=t2%d;
System.out.println(s1[t1]+s2[t2]);
}
}
}
| Java | ["10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020"] | 1 second | ["sinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsin\ngyeyu\ngyeyu\nbyeongsin\njeongyu\nmusul\ngihae\ngyeongja"] | NoteThe first example denotes the actual names used in the Gapja system. These strings usually are either a number or the name of some animal. | Java 8 | standard input | [
"implementation",
"strings"
] | efa201456f8703fcdc29230248d91c54 | The first line contains two integers $$$n, m$$$ ($$$1 \le n, m \le 20$$$). The next line contains $$$n$$$ strings $$$s_1, s_2, \ldots, s_{n}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. The next line contains $$$m$$$ strings $$$t_1, t_2, \ldots, t_{m}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. Among the given $$$n + m$$$ strings may be duplicates (that is, they are not necessarily all different). The next line contains a single integer $$$q$$$ ($$$1 \le q \le 2\,020$$$). In the next $$$q$$$ lines, an integer $$$y$$$ ($$$1 \le y \le 10^9$$$) is given, denoting the year we want to know the name for. | 800 | Print $$$q$$$ lines. For each line, print the name of the year as per the rule described above. | standard output | |
PASSED | 8370abb7e0e36dfe9b31357cc4f05e54 | train_003.jsonl | 1578139500 | Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.There are two sequences of $$$n$$$ strings $$$s_1, s_2, s_3, \ldots, s_{n}$$$ and $$$m$$$ strings $$$t_1, t_2, t_3, \ldots, t_{m}$$$. These strings contain only lowercase letters. There might be duplicates among these strings.Let's call a concatenation of strings $$$x$$$ and $$$y$$$ as the string that is obtained by writing down strings $$$x$$$ and $$$y$$$ one right after another without changing the order. For example, the concatenation of the strings "code" and "forces" is the string "codeforces".The year 1 has a name which is the concatenation of the two strings $$$s_1$$$ and $$$t_1$$$. When the year increases by one, we concatenate the next two strings in order from each of the respective sequences. If the string that is currently being used is at the end of its sequence, we go back to the first string in that sequence.For example, if $$$n = 3, m = 4, s = $$${"a", "b", "c"}, $$$t =$$$ {"d", "e", "f", "g"}, the following table denotes the resulting year names. Note that the names of the years may repeat. You are given two sequences of strings of size $$$n$$$ and $$$m$$$ and also $$$q$$$ queries. For each query, you will be given the current year. Could you find the name corresponding to the given year, according to the Gapja system? | 1024 megabytes | import java.util.Scanner;
import java.lang.Math;
import java.math.BigInteger;
public class Solution{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
try{
int N=sc.nextInt();
int M=sc.nextInt();
String str[]=new String[N+1];
String str2[]=new String[M+1];
for(int i=0;i<N;i++){
str[i]=sc.next();
}
for(int i=0;i<M;i++){
str2[i]=sc.next();
}
int q=sc.nextInt();
String str3[]=new String[q+1];
int ar[]=new int[q+1];
for(int i=0;i<q;i++)
ar[i]=sc.nextInt();
for(int i=0;i<q;i++){
str3[i]=str[(ar[i]-1)%N].concat(str2[(ar[i]-1)%M]);
System.out.println(str3[i]);
}
}
catch(Exception e){
return;
}
}
} | Java | ["10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020"] | 1 second | ["sinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsin\ngyeyu\ngyeyu\nbyeongsin\njeongyu\nmusul\ngihae\ngyeongja"] | NoteThe first example denotes the actual names used in the Gapja system. These strings usually are either a number or the name of some animal. | Java 8 | standard input | [
"implementation",
"strings"
] | efa201456f8703fcdc29230248d91c54 | The first line contains two integers $$$n, m$$$ ($$$1 \le n, m \le 20$$$). The next line contains $$$n$$$ strings $$$s_1, s_2, \ldots, s_{n}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. The next line contains $$$m$$$ strings $$$t_1, t_2, \ldots, t_{m}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. Among the given $$$n + m$$$ strings may be duplicates (that is, they are not necessarily all different). The next line contains a single integer $$$q$$$ ($$$1 \le q \le 2\,020$$$). In the next $$$q$$$ lines, an integer $$$y$$$ ($$$1 \le y \le 10^9$$$) is given, denoting the year we want to know the name for. | 800 | Print $$$q$$$ lines. For each line, print the name of the year as per the rule described above. | standard output | |
PASSED | 005c4ee7c574fcc33e53c5c36a2c34c7 | train_003.jsonl | 1578139500 | Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.There are two sequences of $$$n$$$ strings $$$s_1, s_2, s_3, \ldots, s_{n}$$$ and $$$m$$$ strings $$$t_1, t_2, t_3, \ldots, t_{m}$$$. These strings contain only lowercase letters. There might be duplicates among these strings.Let's call a concatenation of strings $$$x$$$ and $$$y$$$ as the string that is obtained by writing down strings $$$x$$$ and $$$y$$$ one right after another without changing the order. For example, the concatenation of the strings "code" and "forces" is the string "codeforces".The year 1 has a name which is the concatenation of the two strings $$$s_1$$$ and $$$t_1$$$. When the year increases by one, we concatenate the next two strings in order from each of the respective sequences. If the string that is currently being used is at the end of its sequence, we go back to the first string in that sequence.For example, if $$$n = 3, m = 4, s = $$${"a", "b", "c"}, $$$t =$$$ {"d", "e", "f", "g"}, the following table denotes the resulting year names. Note that the names of the years may repeat. You are given two sequences of strings of size $$$n$$$ and $$$m$$$ and also $$$q$$$ queries. For each query, you will be given the current year. Could you find the name corresponding to the given year, according to the Gapja system? | 1024 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class NewYearNaming
{
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 m = sc.nextInt();
String [] nString = new String[n];
String [] mString = new String[m];
for(int i=0; i<n; i++) {
nString[i] = sc.next();
}
for(int i=0; i<m; i++) {
mString[i] = sc.next();
}
int queries = sc.nextInt();
while(queries-- != 0) {
int year = sc.nextInt();
int rem = year % (n * m);
int nIndex = rem % n;
int mIndex = rem % m;
if(nIndex == 0) nIndex = n;
if(mIndex == 0) mIndex = m;
System.out.println(nString[nIndex-1] + mString[mIndex-1]);
}
}
} | Java | ["10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020"] | 1 second | ["sinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsin\ngyeyu\ngyeyu\nbyeongsin\njeongyu\nmusul\ngihae\ngyeongja"] | NoteThe first example denotes the actual names used in the Gapja system. These strings usually are either a number or the name of some animal. | Java 8 | standard input | [
"implementation",
"strings"
] | efa201456f8703fcdc29230248d91c54 | The first line contains two integers $$$n, m$$$ ($$$1 \le n, m \le 20$$$). The next line contains $$$n$$$ strings $$$s_1, s_2, \ldots, s_{n}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. The next line contains $$$m$$$ strings $$$t_1, t_2, \ldots, t_{m}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. Among the given $$$n + m$$$ strings may be duplicates (that is, they are not necessarily all different). The next line contains a single integer $$$q$$$ ($$$1 \le q \le 2\,020$$$). In the next $$$q$$$ lines, an integer $$$y$$$ ($$$1 \le y \le 10^9$$$) is given, denoting the year we want to know the name for. | 800 | Print $$$q$$$ lines. For each line, print the name of the year as per the rule described above. | standard output | |
PASSED | c5098f300d4c3edb7d08636cad725870 | train_003.jsonl | 1578139500 | Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.There are two sequences of $$$n$$$ strings $$$s_1, s_2, s_3, \ldots, s_{n}$$$ and $$$m$$$ strings $$$t_1, t_2, t_3, \ldots, t_{m}$$$. These strings contain only lowercase letters. There might be duplicates among these strings.Let's call a concatenation of strings $$$x$$$ and $$$y$$$ as the string that is obtained by writing down strings $$$x$$$ and $$$y$$$ one right after another without changing the order. For example, the concatenation of the strings "code" and "forces" is the string "codeforces".The year 1 has a name which is the concatenation of the two strings $$$s_1$$$ and $$$t_1$$$. When the year increases by one, we concatenate the next two strings in order from each of the respective sequences. If the string that is currently being used is at the end of its sequence, we go back to the first string in that sequence.For example, if $$$n = 3, m = 4, s = $$${"a", "b", "c"}, $$$t =$$$ {"d", "e", "f", "g"}, the following table denotes the resulting year names. Note that the names of the years may repeat. You are given two sequences of strings of size $$$n$$$ and $$$m$$$ and also $$$q$$$ queries. For each query, you will be given the current year. Could you find the name corresponding to the given year, according to the Gapja system? | 1024 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class naming {
//FastScanner for Java
public static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
}
public static void main(String args[]) {
FastScanner in = new FastScanner();
int n = in.nextInt();
int m = in.nextInt();
String[] arr1 = new String[n];
for(int i = 0; i<n;i++) {
arr1[i] = in.next();
}
String[] arr2 = new String[m];
for(int i = 0; i<m; i++) {
arr2[i] = in.next();
}
int k = in.nextInt();
for(int i = 0; i<k;i++) {
int v = in.nextInt();
System.out.println(arr1[(v-1)%n]+arr2[(v-1)%m]);
}
}
}
| Java | ["10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020"] | 1 second | ["sinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsin\ngyeyu\ngyeyu\nbyeongsin\njeongyu\nmusul\ngihae\ngyeongja"] | NoteThe first example denotes the actual names used in the Gapja system. These strings usually are either a number or the name of some animal. | Java 8 | standard input | [
"implementation",
"strings"
] | efa201456f8703fcdc29230248d91c54 | The first line contains two integers $$$n, m$$$ ($$$1 \le n, m \le 20$$$). The next line contains $$$n$$$ strings $$$s_1, s_2, \ldots, s_{n}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. The next line contains $$$m$$$ strings $$$t_1, t_2, \ldots, t_{m}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. Among the given $$$n + m$$$ strings may be duplicates (that is, they are not necessarily all different). The next line contains a single integer $$$q$$$ ($$$1 \le q \le 2\,020$$$). In the next $$$q$$$ lines, an integer $$$y$$$ ($$$1 \le y \le 10^9$$$) is given, denoting the year we want to know the name for. | 800 | Print $$$q$$$ lines. For each line, print the name of the year as per the rule described above. | standard output | |
PASSED | b61982251de903f913cba402eb816eda | train_003.jsonl | 1578139500 | Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.There are two sequences of $$$n$$$ strings $$$s_1, s_2, s_3, \ldots, s_{n}$$$ and $$$m$$$ strings $$$t_1, t_2, t_3, \ldots, t_{m}$$$. These strings contain only lowercase letters. There might be duplicates among these strings.Let's call a concatenation of strings $$$x$$$ and $$$y$$$ as the string that is obtained by writing down strings $$$x$$$ and $$$y$$$ one right after another without changing the order. For example, the concatenation of the strings "code" and "forces" is the string "codeforces".The year 1 has a name which is the concatenation of the two strings $$$s_1$$$ and $$$t_1$$$. When the year increases by one, we concatenate the next two strings in order from each of the respective sequences. If the string that is currently being used is at the end of its sequence, we go back to the first string in that sequence.For example, if $$$n = 3, m = 4, s = $$${"a", "b", "c"}, $$$t =$$$ {"d", "e", "f", "g"}, the following table denotes the resulting year names. Note that the names of the years may repeat. You are given two sequences of strings of size $$$n$$$ and $$$m$$$ and also $$$q$$$ queries. For each query, you will be given the current year. Could you find the name corresponding to the given year, according to the Gapja system? | 1024 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class NewYearAndNaming{
public static void main(String args[])throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
String len[] = br.readLine().trim().split("\\s+");
String first[] = br.readLine().trim().split("\\s+");
String second[] = br.readLine().trim().split("\\s+");
int len1 = Integer.parseInt(len[0]);
int len2 = Integer.parseInt(len[1]);
int q = Integer.parseInt(br.readLine());
while(q-->0){
int n = Integer.parseInt(br.readLine());
int rem1 = (n%len1)-1;
if(rem1==-1)
rem1+=len1;
int rem2 = (n%len2)-1;
if(rem2==-1)
rem2+=len2;
String str = first[rem1];
str+=second[rem2];
bw.write(str+"\n");
}
bw.close();
}
}
| Java | ["10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020"] | 1 second | ["sinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsin\ngyeyu\ngyeyu\nbyeongsin\njeongyu\nmusul\ngihae\ngyeongja"] | NoteThe first example denotes the actual names used in the Gapja system. These strings usually are either a number or the name of some animal. | Java 8 | standard input | [
"implementation",
"strings"
] | efa201456f8703fcdc29230248d91c54 | The first line contains two integers $$$n, m$$$ ($$$1 \le n, m \le 20$$$). The next line contains $$$n$$$ strings $$$s_1, s_2, \ldots, s_{n}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. The next line contains $$$m$$$ strings $$$t_1, t_2, \ldots, t_{m}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. Among the given $$$n + m$$$ strings may be duplicates (that is, they are not necessarily all different). The next line contains a single integer $$$q$$$ ($$$1 \le q \le 2\,020$$$). In the next $$$q$$$ lines, an integer $$$y$$$ ($$$1 \le y \le 10^9$$$) is given, denoting the year we want to know the name for. | 800 | Print $$$q$$$ lines. For each line, print the name of the year as per the rule described above. | standard output | |
PASSED | 3901bd600ce0870ae00c883e38ffb955 | train_003.jsonl | 1578139500 | Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.There are two sequences of $$$n$$$ strings $$$s_1, s_2, s_3, \ldots, s_{n}$$$ and $$$m$$$ strings $$$t_1, t_2, t_3, \ldots, t_{m}$$$. These strings contain only lowercase letters. There might be duplicates among these strings.Let's call a concatenation of strings $$$x$$$ and $$$y$$$ as the string that is obtained by writing down strings $$$x$$$ and $$$y$$$ one right after another without changing the order. For example, the concatenation of the strings "code" and "forces" is the string "codeforces".The year 1 has a name which is the concatenation of the two strings $$$s_1$$$ and $$$t_1$$$. When the year increases by one, we concatenate the next two strings in order from each of the respective sequences. If the string that is currently being used is at the end of its sequence, we go back to the first string in that sequence.For example, if $$$n = 3, m = 4, s = $$${"a", "b", "c"}, $$$t =$$$ {"d", "e", "f", "g"}, the following table denotes the resulting year names. Note that the names of the years may repeat. You are given two sequences of strings of size $$$n$$$ and $$$m$$$ and also $$$q$$$ queries. For each query, you will be given the current year. Could you find the name corresponding to the given year, according to the Gapja system? | 1024 megabytes | import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;
public class Main {
static {
Reader.init(System.in);
}
public static void main(String[] args) throws Exception {
int n = Reader.nextInt();
int m = Reader.nextInt();
String[] a = new String[21];
String[] b = new String[21];
for(int i=1;i<=n;++i)
a[i] = Reader.next();
for(int i=1;i<=m;++i)
b[i] = Reader.next();
int q = Reader.nextInt();
for(int w = 1;w <= q;++w) {
int x = Reader.nextInt();
x--;
System.out.println(a[x%n+1]+(b[x%m+1]));
}
}
}
class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
static void init(InputStream input) {
reader = new BufferedReader(new InputStreamReader(input));
tokenizer = new StringTokenizer("");
}
static String next() throws IOException {
while (!tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt(next());
}
static long nextLong() throws IOException {
return Long.parseLong(next());
}
static double nextDouble() throws IOException {
return Double.parseDouble(next());
}
static BigInteger nextBigInteger() throws IOException {
return new BigInteger(next());
}
static BigDecimal nextDecimal() throws IOException {
return new BigDecimal(next());
}
}
| Java | ["10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020"] | 1 second | ["sinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsin\ngyeyu\ngyeyu\nbyeongsin\njeongyu\nmusul\ngihae\ngyeongja"] | NoteThe first example denotes the actual names used in the Gapja system. These strings usually are either a number or the name of some animal. | Java 8 | standard input | [
"implementation",
"strings"
] | efa201456f8703fcdc29230248d91c54 | The first line contains two integers $$$n, m$$$ ($$$1 \le n, m \le 20$$$). The next line contains $$$n$$$ strings $$$s_1, s_2, \ldots, s_{n}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. The next line contains $$$m$$$ strings $$$t_1, t_2, \ldots, t_{m}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. Among the given $$$n + m$$$ strings may be duplicates (that is, they are not necessarily all different). The next line contains a single integer $$$q$$$ ($$$1 \le q \le 2\,020$$$). In the next $$$q$$$ lines, an integer $$$y$$$ ($$$1 \le y \le 10^9$$$) is given, denoting the year we want to know the name for. | 800 | Print $$$q$$$ lines. For each line, print the name of the year as per the rule described above. | standard output | |
PASSED | 30e55d2fac36bf3e53019c4aeb10badf | train_003.jsonl | 1578139500 | Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.There are two sequences of $$$n$$$ strings $$$s_1, s_2, s_3, \ldots, s_{n}$$$ and $$$m$$$ strings $$$t_1, t_2, t_3, \ldots, t_{m}$$$. These strings contain only lowercase letters. There might be duplicates among these strings.Let's call a concatenation of strings $$$x$$$ and $$$y$$$ as the string that is obtained by writing down strings $$$x$$$ and $$$y$$$ one right after another without changing the order. For example, the concatenation of the strings "code" and "forces" is the string "codeforces".The year 1 has a name which is the concatenation of the two strings $$$s_1$$$ and $$$t_1$$$. When the year increases by one, we concatenate the next two strings in order from each of the respective sequences. If the string that is currently being used is at the end of its sequence, we go back to the first string in that sequence.For example, if $$$n = 3, m = 4, s = $$${"a", "b", "c"}, $$$t =$$$ {"d", "e", "f", "g"}, the following table denotes the resulting year names. Note that the names of the years may repeat. You are given two sequences of strings of size $$$n$$$ and $$$m$$$ and also $$$q$$$ queries. For each query, you will be given the current year. Could you find the name corresponding to the given year, according to the Gapja system? | 1024 megabytes | import java.io.*;
import java.util.*;
public class Main {
static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer tk;
public static void main(String[] args) {
PrintWriter out = new PrintWriter(System.out);
int a = nextInt();
int b = nextInt();
String[] arrA = new String[a];
String[] arrB = new String[b];
for (int i = 1; i < a; i++)
arrA[i] = next();
arrA[0] = next();
for (int i = 1; i < b; i++)
arrB[i] = next();
arrB[0] = next();
int t = nextInt();
for (int i = 0; i < t; i++) {
int y = nextInt();
out.println(arrA[y%a] + arrB[y%b]);
}
out.close();
}
static int nextInt() {
return Integer.parseInt(next());
}
static String next() {
while (tk == null || !tk.hasMoreElements()) {
try {
tk = new StringTokenizer(in.readLine());
} catch (IOException ignored) {
}
}
return tk.nextToken();
}
}
| Java | ["10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020"] | 1 second | ["sinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsin\ngyeyu\ngyeyu\nbyeongsin\njeongyu\nmusul\ngihae\ngyeongja"] | NoteThe first example denotes the actual names used in the Gapja system. These strings usually are either a number or the name of some animal. | Java 8 | standard input | [
"implementation",
"strings"
] | efa201456f8703fcdc29230248d91c54 | The first line contains two integers $$$n, m$$$ ($$$1 \le n, m \le 20$$$). The next line contains $$$n$$$ strings $$$s_1, s_2, \ldots, s_{n}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. The next line contains $$$m$$$ strings $$$t_1, t_2, \ldots, t_{m}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. Among the given $$$n + m$$$ strings may be duplicates (that is, they are not necessarily all different). The next line contains a single integer $$$q$$$ ($$$1 \le q \le 2\,020$$$). In the next $$$q$$$ lines, an integer $$$y$$$ ($$$1 \le y \le 10^9$$$) is given, denoting the year we want to know the name for. | 800 | Print $$$q$$$ lines. For each line, print the name of the year as per the rule described above. | standard output | |
PASSED | 8322917bfb757ff99437094b0e760591 | train_003.jsonl | 1578139500 | Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.There are two sequences of $$$n$$$ strings $$$s_1, s_2, s_3, \ldots, s_{n}$$$ and $$$m$$$ strings $$$t_1, t_2, t_3, \ldots, t_{m}$$$. These strings contain only lowercase letters. There might be duplicates among these strings.Let's call a concatenation of strings $$$x$$$ and $$$y$$$ as the string that is obtained by writing down strings $$$x$$$ and $$$y$$$ one right after another without changing the order. For example, the concatenation of the strings "code" and "forces" is the string "codeforces".The year 1 has a name which is the concatenation of the two strings $$$s_1$$$ and $$$t_1$$$. When the year increases by one, we concatenate the next two strings in order from each of the respective sequences. If the string that is currently being used is at the end of its sequence, we go back to the first string in that sequence.For example, if $$$n = 3, m = 4, s = $$${"a", "b", "c"}, $$$t =$$$ {"d", "e", "f", "g"}, the following table denotes the resulting year names. Note that the names of the years may repeat. You are given two sequences of strings of size $$$n$$$ and $$$m$$$ and also $$$q$$$ queries. For each query, you will be given the current year. Could you find the name corresponding to the given year, according to the Gapja system? | 1024 megabytes | import java.io.*;
import java.util.*;
public class Main {
static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer tk;
public static void main(String[] args) {
PrintWriter out = new PrintWriter(System.out);
int a = nextInt();
int b = nextInt();
String[] arrA = new String[a];
String[] arrB = new String[b];
for (int i = 0; i < a; i++)
arrA[i] = next();
for (int i = 0; i < b; i++)
arrB[i] = next();
int t = nextInt();
while (t-- > 0) {
int y = nextInt()-1;
out.println(arrA[y%a]+arrB[y%b]);
}
out.close();
}
static int nextInt() {
return Integer.parseInt(next());
}
static String next() {
while (tk == null || !tk.hasMoreElements()) {
try {
tk = new StringTokenizer(in.readLine());
} catch (IOException ignored) {
}
}
return tk.nextToken();
}
}
| Java | ["10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020"] | 1 second | ["sinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsin\ngyeyu\ngyeyu\nbyeongsin\njeongyu\nmusul\ngihae\ngyeongja"] | NoteThe first example denotes the actual names used in the Gapja system. These strings usually are either a number or the name of some animal. | Java 8 | standard input | [
"implementation",
"strings"
] | efa201456f8703fcdc29230248d91c54 | The first line contains two integers $$$n, m$$$ ($$$1 \le n, m \le 20$$$). The next line contains $$$n$$$ strings $$$s_1, s_2, \ldots, s_{n}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. The next line contains $$$m$$$ strings $$$t_1, t_2, \ldots, t_{m}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. Among the given $$$n + m$$$ strings may be duplicates (that is, they are not necessarily all different). The next line contains a single integer $$$q$$$ ($$$1 \le q \le 2\,020$$$). In the next $$$q$$$ lines, an integer $$$y$$$ ($$$1 \le y \le 10^9$$$) is given, denoting the year we want to know the name for. | 800 | Print $$$q$$$ lines. For each line, print the name of the year as per the rule described above. | standard output | |
PASSED | db2727c8ae364dffdb4b60fb99fdb437 | train_003.jsonl | 1578139500 | Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.There are two sequences of $$$n$$$ strings $$$s_1, s_2, s_3, \ldots, s_{n}$$$ and $$$m$$$ strings $$$t_1, t_2, t_3, \ldots, t_{m}$$$. These strings contain only lowercase letters. There might be duplicates among these strings.Let's call a concatenation of strings $$$x$$$ and $$$y$$$ as the string that is obtained by writing down strings $$$x$$$ and $$$y$$$ one right after another without changing the order. For example, the concatenation of the strings "code" and "forces" is the string "codeforces".The year 1 has a name which is the concatenation of the two strings $$$s_1$$$ and $$$t_1$$$. When the year increases by one, we concatenate the next two strings in order from each of the respective sequences. If the string that is currently being used is at the end of its sequence, we go back to the first string in that sequence.For example, if $$$n = 3, m = 4, s = $$${"a", "b", "c"}, $$$t =$$$ {"d", "e", "f", "g"}, the following table denotes the resulting year names. Note that the names of the years may repeat. You are given two sequences of strings of size $$$n$$$ and $$$m$$$ and also $$$q$$$ queries. For each query, you will be given the current year. Could you find the name corresponding to the given year, according to the Gapja system? | 1024 megabytes | import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
public class Year2020 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String sizes = scanner.nextLine();
String firstSeq = scanner.nextLine();
String secondSeq = scanner.nextLine();
int q = scanner.nextInt();
List<Integer> years = new ArrayList<>();
for (int i = 0; i < q; i++) {
int year = scanner.nextInt();
years.add(year);
}
List first = Arrays.asList(firstSeq.split(" "));
List second = Arrays.asList(secondSeq.split(" "));
years.forEach(y -> {
System.out.println(getYearName(first, second, y));
});
}
private static String getYearName(List<String> first, List<String> second, int year) {
String firstStr = first.get((year - 1)% first.size());
String secondStr = second.get((year - 1) % second.size());
return firstStr + secondStr;
}
}
| Java | ["10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020"] | 1 second | ["sinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsin\ngyeyu\ngyeyu\nbyeongsin\njeongyu\nmusul\ngihae\ngyeongja"] | NoteThe first example denotes the actual names used in the Gapja system. These strings usually are either a number or the name of some animal. | Java 8 | standard input | [
"implementation",
"strings"
] | efa201456f8703fcdc29230248d91c54 | The first line contains two integers $$$n, m$$$ ($$$1 \le n, m \le 20$$$). The next line contains $$$n$$$ strings $$$s_1, s_2, \ldots, s_{n}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. The next line contains $$$m$$$ strings $$$t_1, t_2, \ldots, t_{m}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. Among the given $$$n + m$$$ strings may be duplicates (that is, they are not necessarily all different). The next line contains a single integer $$$q$$$ ($$$1 \le q \le 2\,020$$$). In the next $$$q$$$ lines, an integer $$$y$$$ ($$$1 \le y \le 10^9$$$) is given, denoting the year we want to know the name for. | 800 | Print $$$q$$$ lines. For each line, print the name of the year as per the rule described above. | standard output | |
PASSED | f48020c14d51a480cf9705cfdb5c7ea2 | train_003.jsonl | 1578139500 | Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.There are two sequences of $$$n$$$ strings $$$s_1, s_2, s_3, \ldots, s_{n}$$$ and $$$m$$$ strings $$$t_1, t_2, t_3, \ldots, t_{m}$$$. These strings contain only lowercase letters. There might be duplicates among these strings.Let's call a concatenation of strings $$$x$$$ and $$$y$$$ as the string that is obtained by writing down strings $$$x$$$ and $$$y$$$ one right after another without changing the order. For example, the concatenation of the strings "code" and "forces" is the string "codeforces".The year 1 has a name which is the concatenation of the two strings $$$s_1$$$ and $$$t_1$$$. When the year increases by one, we concatenate the next two strings in order from each of the respective sequences. If the string that is currently being used is at the end of its sequence, we go back to the first string in that sequence.For example, if $$$n = 3, m = 4, s = $$${"a", "b", "c"}, $$$t =$$$ {"d", "e", "f", "g"}, the following table denotes the resulting year names. Note that the names of the years may repeat. You are given two sequences of strings of size $$$n$$$ and $$$m$$$ and also $$$q$$$ queries. For each query, you will be given the current year. Could you find the name corresponding to the given year, according to the Gapja system? | 1024 megabytes | import java.util.Scanner;
public class NewYearAndNaming {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int m = input.nextInt();
input.nextLine();
String[] s = new String[n];
String[] t = new String[m];
for (int i = 0; i < n; i++) {
s[i] = input.next();
}
input.nextLine();
for (int i = 0; i < m; i++) {
t[i] = input.next();
}
int q = input.nextInt(), y;
for (int i = 0; i < q; i++) {
y = input.nextInt() - 1;
String yearName = s[y % n] + t[y % m];
System.out.println(yearName);
}
}
}
| Java | ["10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020"] | 1 second | ["sinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsin\ngyeyu\ngyeyu\nbyeongsin\njeongyu\nmusul\ngihae\ngyeongja"] | NoteThe first example denotes the actual names used in the Gapja system. These strings usually are either a number or the name of some animal. | Java 8 | standard input | [
"implementation",
"strings"
] | efa201456f8703fcdc29230248d91c54 | The first line contains two integers $$$n, m$$$ ($$$1 \le n, m \le 20$$$). The next line contains $$$n$$$ strings $$$s_1, s_2, \ldots, s_{n}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. The next line contains $$$m$$$ strings $$$t_1, t_2, \ldots, t_{m}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. Among the given $$$n + m$$$ strings may be duplicates (that is, they are not necessarily all different). The next line contains a single integer $$$q$$$ ($$$1 \le q \le 2\,020$$$). In the next $$$q$$$ lines, an integer $$$y$$$ ($$$1 \le y \le 10^9$$$) is given, denoting the year we want to know the name for. | 800 | Print $$$q$$$ lines. For each line, print the name of the year as per the rule described above. | standard output | |
PASSED | 373d615b303373793cf434b1682f98f4 | train_003.jsonl | 1578139500 | Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.There are two sequences of $$$n$$$ strings $$$s_1, s_2, s_3, \ldots, s_{n}$$$ and $$$m$$$ strings $$$t_1, t_2, t_3, \ldots, t_{m}$$$. These strings contain only lowercase letters. There might be duplicates among these strings.Let's call a concatenation of strings $$$x$$$ and $$$y$$$ as the string that is obtained by writing down strings $$$x$$$ and $$$y$$$ one right after another without changing the order. For example, the concatenation of the strings "code" and "forces" is the string "codeforces".The year 1 has a name which is the concatenation of the two strings $$$s_1$$$ and $$$t_1$$$. When the year increases by one, we concatenate the next two strings in order from each of the respective sequences. If the string that is currently being used is at the end of its sequence, we go back to the first string in that sequence.For example, if $$$n = 3, m = 4, s = $$${"a", "b", "c"}, $$$t =$$$ {"d", "e", "f", "g"}, the following table denotes the resulting year names. Note that the names of the years may repeat. You are given two sequences of strings of size $$$n$$$ and $$$m$$$ and also $$$q$$$ queries. For each query, you will be given the current year. Could you find the name corresponding to the given year, according to the Gapja system? | 1024 megabytes | import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Scanner;
public class NewYearNaming {
public static void main(String[] args) {
Scanner scn1 = new Scanner(System.in);
int n = scn1.nextInt();
int m = scn1.nextInt();
String[] nCh = new String[n + 1];
String[] mCh = new String[m + 1];
for (int i = 1; i <= n; i++) {
nCh[i] = scn1.next();
}
for (int j = 1; j <= m; j++) {
mCh[j] = scn1.next();
}
int q = scn1.nextInt();
System.out.println();
int[] queryYear = new int[q];
for (int k = 0; k < q; k++) {
int y = scn1.nextInt();
int a = y % n;
int b = y % m;
if (a == 0)
a = n;
if (b == 0)
b = m;
System.out.println(nCh[a] + mCh[b]);
}
}
}
| Java | ["10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020"] | 1 second | ["sinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsin\ngyeyu\ngyeyu\nbyeongsin\njeongyu\nmusul\ngihae\ngyeongja"] | NoteThe first example denotes the actual names used in the Gapja system. These strings usually are either a number or the name of some animal. | Java 8 | standard input | [
"implementation",
"strings"
] | efa201456f8703fcdc29230248d91c54 | The first line contains two integers $$$n, m$$$ ($$$1 \le n, m \le 20$$$). The next line contains $$$n$$$ strings $$$s_1, s_2, \ldots, s_{n}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. The next line contains $$$m$$$ strings $$$t_1, t_2, \ldots, t_{m}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. Among the given $$$n + m$$$ strings may be duplicates (that is, they are not necessarily all different). The next line contains a single integer $$$q$$$ ($$$1 \le q \le 2\,020$$$). In the next $$$q$$$ lines, an integer $$$y$$$ ($$$1 \le y \le 10^9$$$) is given, denoting the year we want to know the name for. | 800 | Print $$$q$$$ lines. For each line, print the name of the year as per the rule described above. | standard output | |
PASSED | 43c61e957efff30597363a97130a1237 | train_003.jsonl | 1578139500 | Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.There are two sequences of $$$n$$$ strings $$$s_1, s_2, s_3, \ldots, s_{n}$$$ and $$$m$$$ strings $$$t_1, t_2, t_3, \ldots, t_{m}$$$. These strings contain only lowercase letters. There might be duplicates among these strings.Let's call a concatenation of strings $$$x$$$ and $$$y$$$ as the string that is obtained by writing down strings $$$x$$$ and $$$y$$$ one right after another without changing the order. For example, the concatenation of the strings "code" and "forces" is the string "codeforces".The year 1 has a name which is the concatenation of the two strings $$$s_1$$$ and $$$t_1$$$. When the year increases by one, we concatenate the next two strings in order from each of the respective sequences. If the string that is currently being used is at the end of its sequence, we go back to the first string in that sequence.For example, if $$$n = 3, m = 4, s = $$${"a", "b", "c"}, $$$t =$$$ {"d", "e", "f", "g"}, the following table denotes the resulting year names. Note that the names of the years may repeat. You are given two sequences of strings of size $$$n$$$ and $$$m$$$ and also $$$q$$$ queries. For each query, you will be given the current year. Could you find the name corresponding to the given year, according to the Gapja system? | 1024 megabytes | import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Scanner;
public class NewYearNaming {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
int m = scn.nextInt();
String[] nCh = new String[n + 1];
String[] mCh = new String[m + 1];
for (int i = 1; i <= n; i++) {
nCh[i] = scn.next();
}
for (int j = 1; j <= m; j++) {
mCh[j] = scn.next();
}
int q = scn.nextInt();
System.out.println();
int[] queryYear = new int[q];
for (int k = 0; k < q; k++) {
int y = scn.nextInt();
int a = y % n;
int b = y % m;
if (a == 0)
a = n;
if (b == 0)
b = m;
System.out.println(nCh[a] + mCh[b]);
}
}
}
| Java | ["10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020"] | 1 second | ["sinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsin\ngyeyu\ngyeyu\nbyeongsin\njeongyu\nmusul\ngihae\ngyeongja"] | NoteThe first example denotes the actual names used in the Gapja system. These strings usually are either a number or the name of some animal. | Java 8 | standard input | [
"implementation",
"strings"
] | efa201456f8703fcdc29230248d91c54 | The first line contains two integers $$$n, m$$$ ($$$1 \le n, m \le 20$$$). The next line contains $$$n$$$ strings $$$s_1, s_2, \ldots, s_{n}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. The next line contains $$$m$$$ strings $$$t_1, t_2, \ldots, t_{m}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. Among the given $$$n + m$$$ strings may be duplicates (that is, they are not necessarily all different). The next line contains a single integer $$$q$$$ ($$$1 \le q \le 2\,020$$$). In the next $$$q$$$ lines, an integer $$$y$$$ ($$$1 \le y \le 10^9$$$) is given, denoting the year we want to know the name for. | 800 | Print $$$q$$$ lines. For each line, print the name of the year as per the rule described above. | standard output | |
PASSED | a4d8593ede0ee1c315cd949f5cf3abc5 | train_003.jsonl | 1578139500 | Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.There are two sequences of $$$n$$$ strings $$$s_1, s_2, s_3, \ldots, s_{n}$$$ and $$$m$$$ strings $$$t_1, t_2, t_3, \ldots, t_{m}$$$. These strings contain only lowercase letters. There might be duplicates among these strings.Let's call a concatenation of strings $$$x$$$ and $$$y$$$ as the string that is obtained by writing down strings $$$x$$$ and $$$y$$$ one right after another without changing the order. For example, the concatenation of the strings "code" and "forces" is the string "codeforces".The year 1 has a name which is the concatenation of the two strings $$$s_1$$$ and $$$t_1$$$. When the year increases by one, we concatenate the next two strings in order from each of the respective sequences. If the string that is currently being used is at the end of its sequence, we go back to the first string in that sequence.For example, if $$$n = 3, m = 4, s = $$${"a", "b", "c"}, $$$t =$$$ {"d", "e", "f", "g"}, the following table denotes the resulting year names. Note that the names of the years may repeat. You are given two sequences of strings of size $$$n$$$ and $$$m$$$ and also $$$q$$$ queries. For each query, you will be given the current year. Could you find the name corresponding to the given year, according to the Gapja system? | 1024 megabytes | import java.util.Scanner;
public class Mod {
public static void main(String[] args) {
int len1, len2;
Scanner sc = new Scanner(System.in);
len1 = sc.nextInt();
len2 = sc.nextInt();
String [] a1 = new String[len1+1];
String [] a2 = new String[len2+1];
for(int i=1;i<=len1;i++) {
a1[i] = sc.next();
}
for(int i=1;i<=len2;i++) {
a2[i] = sc.next();
}
int reps;
reps = sc.nextInt();
for(int i = 0;i<reps;i++) {
int temp = sc.nextInt();
int t1 = (temp % len1 ==0)?len1:temp % len1;
int t2 = (temp % len2 ==0)?len2:temp % len2;
System.out.println(a1[t1]+a2[t2]);
}
}
}
| Java | ["10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020"] | 1 second | ["sinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsin\ngyeyu\ngyeyu\nbyeongsin\njeongyu\nmusul\ngihae\ngyeongja"] | NoteThe first example denotes the actual names used in the Gapja system. These strings usually are either a number or the name of some animal. | Java 8 | standard input | [
"implementation",
"strings"
] | efa201456f8703fcdc29230248d91c54 | The first line contains two integers $$$n, m$$$ ($$$1 \le n, m \le 20$$$). The next line contains $$$n$$$ strings $$$s_1, s_2, \ldots, s_{n}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. The next line contains $$$m$$$ strings $$$t_1, t_2, \ldots, t_{m}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. Among the given $$$n + m$$$ strings may be duplicates (that is, they are not necessarily all different). The next line contains a single integer $$$q$$$ ($$$1 \le q \le 2\,020$$$). In the next $$$q$$$ lines, an integer $$$y$$$ ($$$1 \le y \le 10^9$$$) is given, denoting the year we want to know the name for. | 800 | Print $$$q$$$ lines. For each line, print the name of the year as per the rule described above. | standard output | |
PASSED | d94688404bdfd457fc3845affce54aa8 | train_003.jsonl | 1578139500 | Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.There are two sequences of $$$n$$$ strings $$$s_1, s_2, s_3, \ldots, s_{n}$$$ and $$$m$$$ strings $$$t_1, t_2, t_3, \ldots, t_{m}$$$. These strings contain only lowercase letters. There might be duplicates among these strings.Let's call a concatenation of strings $$$x$$$ and $$$y$$$ as the string that is obtained by writing down strings $$$x$$$ and $$$y$$$ one right after another without changing the order. For example, the concatenation of the strings "code" and "forces" is the string "codeforces".The year 1 has a name which is the concatenation of the two strings $$$s_1$$$ and $$$t_1$$$. When the year increases by one, we concatenate the next two strings in order from each of the respective sequences. If the string that is currently being used is at the end of its sequence, we go back to the first string in that sequence.For example, if $$$n = 3, m = 4, s = $$${"a", "b", "c"}, $$$t =$$$ {"d", "e", "f", "g"}, the following table denotes the resulting year names. Note that the names of the years may repeat. You are given two sequences of strings of size $$$n$$$ and $$$m$$$ and also $$$q$$$ queries. For each query, you will be given the current year. Could you find the name corresponding to the given year, according to the Gapja system? | 1024 megabytes | import java.util.*;
public class Solution{
public static void main( String[] args ) {
Scanner in = new Scanner( System.in );
int n = in.nextInt();
int m = in.nextInt();
String[] set1 = new String[n];
String[] set2 = new String[m];
for( int i = 0; i < n; i++ ){
set1[i] = in.next();
}
for( int i = 0; i < m; i++ ) {
set2[i] = in.next();
}
int t = in.nextInt();
while( t > 0 ) {
int year = in.nextInt();
System.out.println( getYearName(set1,set2,year) );
t -= 1;
}
}
public static String getYearName( String[] set1, String[] set2, int year ) {
int n = set1.length;
int m = set2.length;
int index1 = ((year % n) - 1) == -1 ? n-1 : (year % n) - 1;
int index2 = ((year % m) - 1) == -1 ? m - 1 : (year % m) - 1;
return set1[index1] + set2[index2];
}
} | Java | ["10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020"] | 1 second | ["sinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsin\ngyeyu\ngyeyu\nbyeongsin\njeongyu\nmusul\ngihae\ngyeongja"] | NoteThe first example denotes the actual names used in the Gapja system. These strings usually are either a number or the name of some animal. | Java 8 | standard input | [
"implementation",
"strings"
] | efa201456f8703fcdc29230248d91c54 | The first line contains two integers $$$n, m$$$ ($$$1 \le n, m \le 20$$$). The next line contains $$$n$$$ strings $$$s_1, s_2, \ldots, s_{n}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. The next line contains $$$m$$$ strings $$$t_1, t_2, \ldots, t_{m}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. Among the given $$$n + m$$$ strings may be duplicates (that is, they are not necessarily all different). The next line contains a single integer $$$q$$$ ($$$1 \le q \le 2\,020$$$). In the next $$$q$$$ lines, an integer $$$y$$$ ($$$1 \le y \le 10^9$$$) is given, denoting the year we want to know the name for. | 800 | Print $$$q$$$ lines. For each line, print the name of the year as per the rule described above. | standard output | |
PASSED | efc66d25c73cba08da3400c95b38e11d | train_003.jsonl | 1578139500 | Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.There are two sequences of $$$n$$$ strings $$$s_1, s_2, s_3, \ldots, s_{n}$$$ and $$$m$$$ strings $$$t_1, t_2, t_3, \ldots, t_{m}$$$. These strings contain only lowercase letters. There might be duplicates among these strings.Let's call a concatenation of strings $$$x$$$ and $$$y$$$ as the string that is obtained by writing down strings $$$x$$$ and $$$y$$$ one right after another without changing the order. For example, the concatenation of the strings "code" and "forces" is the string "codeforces".The year 1 has a name which is the concatenation of the two strings $$$s_1$$$ and $$$t_1$$$. When the year increases by one, we concatenate the next two strings in order from each of the respective sequences. If the string that is currently being used is at the end of its sequence, we go back to the first string in that sequence.For example, if $$$n = 3, m = 4, s = $$${"a", "b", "c"}, $$$t =$$$ {"d", "e", "f", "g"}, the following table denotes the resulting year names. Note that the names of the years may repeat. You are given two sequences of strings of size $$$n$$$ and $$$m$$$ and also $$$q$$$ queries. For each query, you will be given the current year. Could you find the name corresponding to the given year, according to the Gapja system? | 1024 megabytes | import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n, m,q ,y,x,z ;
n = sc.nextInt();
m = sc.nextInt();
String s ;
s= sc.nextLine();
s= sc.nextLine();
String[] arrn = s.split(" ");
s = sc.nextLine();
String[] arrm = s.split(" ");
q= sc.nextInt();
String s2;
for(int a = 0 ; a < q ; a++){
y = sc.nextInt();
if(y <n ){
x = y-1;
}else{
if ( y% n ==0 )
x = n-1 ;
else
x = (y%n)-1;
}
if(y < m){
z = y-1;
}else{
if ( y% m ==0 )
z = m -1;
else
z =(y%m)-1 ;}
s2 = arrn[x]+arrm[z];
System.out.println(s2);
}
}
} | Java | ["10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020"] | 1 second | ["sinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsin\ngyeyu\ngyeyu\nbyeongsin\njeongyu\nmusul\ngihae\ngyeongja"] | NoteThe first example denotes the actual names used in the Gapja system. These strings usually are either a number or the name of some animal. | Java 8 | standard input | [
"implementation",
"strings"
] | efa201456f8703fcdc29230248d91c54 | The first line contains two integers $$$n, m$$$ ($$$1 \le n, m \le 20$$$). The next line contains $$$n$$$ strings $$$s_1, s_2, \ldots, s_{n}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. The next line contains $$$m$$$ strings $$$t_1, t_2, \ldots, t_{m}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. Among the given $$$n + m$$$ strings may be duplicates (that is, they are not necessarily all different). The next line contains a single integer $$$q$$$ ($$$1 \le q \le 2\,020$$$). In the next $$$q$$$ lines, an integer $$$y$$$ ($$$1 \le y \le 10^9$$$) is given, denoting the year we want to know the name for. | 800 | Print $$$q$$$ lines. For each line, print the name of the year as per the rule described above. | standard output | |
PASSED | 951c5bff8e1618d17dccb14e9d9ac128 | train_003.jsonl | 1578139500 | Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.There are two sequences of $$$n$$$ strings $$$s_1, s_2, s_3, \ldots, s_{n}$$$ and $$$m$$$ strings $$$t_1, t_2, t_3, \ldots, t_{m}$$$. These strings contain only lowercase letters. There might be duplicates among these strings.Let's call a concatenation of strings $$$x$$$ and $$$y$$$ as the string that is obtained by writing down strings $$$x$$$ and $$$y$$$ one right after another without changing the order. For example, the concatenation of the strings "code" and "forces" is the string "codeforces".The year 1 has a name which is the concatenation of the two strings $$$s_1$$$ and $$$t_1$$$. When the year increases by one, we concatenate the next two strings in order from each of the respective sequences. If the string that is currently being used is at the end of its sequence, we go back to the first string in that sequence.For example, if $$$n = 3, m = 4, s = $$${"a", "b", "c"}, $$$t =$$$ {"d", "e", "f", "g"}, the following table denotes the resulting year names. Note that the names of the years may repeat. You are given two sequences of strings of size $$$n$$$ and $$$m$$$ and also $$$q$$$ queries. For each query, you will be given the current year. Could you find the name corresponding to the given year, according to the Gapja system? | 1024 megabytes | /* package whatever; // don't place package name! */
import java.util.*;
import java.math.BigInteger;
import java.lang.*;
import java.io.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.lang.Math;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
/* Name of the class has to be "Main" only if the class is public. */
public class bbg
{
public static int result;
public static ArrayList<Integer> [] graph;
public static int[]cats;
public static String[]vector;
public static int vizitat[];
public static int x;
//public static HashMap<String, Integer> map2;
public static void main (String[] args) throws IOException {
Scanner input = new Scanner(System.in);
HashMap<Integer, Integer> contor1= new HashMap<Integer, Integer>();
HashMap<Integer, Integer> contor2= new HashMap<Integer, Integer>();
HashMap<Integer, Integer> map= new HashMap<Integer, Integer>();
HashMap<String, Integer> litere= new HashMap<String, Integer>();
HashMap<String, Integer> combinari= new HashMap<String, Integer>();
//litere.put("a",1);
// litere.put("e",1);
//litere.put("i",1);
//litere.put("o",1);
//litere.put("u",1);
BigInteger numar_initial;
BigInteger primul;
BigInteger doilea;
BigInteger produs;
BigInteger unitatea;
int min,max;
int contor=0;
int mutari=0;
int rez=0;
int n=input.nextInt();
int m=input.nextInt();
String vec_a[]=new String[n];
for(int i=0;i<n;i++) vec_a[i]=input.next();
String vec_b[]=new String[m];
for(int i=0;i<m;i++) vec_b[i]=input.next();
int teste=input.nextInt();
for (int t=1; t<=teste;t++){
int an=input.nextInt();
int ras_n=an % n;
if (ras_n==0) ras_n=n;
int ras_m=an % m;
if (ras_m==0) ras_m=m;
//System.out.println(ras_m-1);
System.out.println(vec_a[ras_n-1] + vec_b[ras_m-1]);
//System.out.println(ras_n-1);
}
}
}
| Java | ["10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020"] | 1 second | ["sinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsin\ngyeyu\ngyeyu\nbyeongsin\njeongyu\nmusul\ngihae\ngyeongja"] | NoteThe first example denotes the actual names used in the Gapja system. These strings usually are either a number or the name of some animal. | Java 8 | standard input | [
"implementation",
"strings"
] | efa201456f8703fcdc29230248d91c54 | The first line contains two integers $$$n, m$$$ ($$$1 \le n, m \le 20$$$). The next line contains $$$n$$$ strings $$$s_1, s_2, \ldots, s_{n}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. The next line contains $$$m$$$ strings $$$t_1, t_2, \ldots, t_{m}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. Among the given $$$n + m$$$ strings may be duplicates (that is, they are not necessarily all different). The next line contains a single integer $$$q$$$ ($$$1 \le q \le 2\,020$$$). In the next $$$q$$$ lines, an integer $$$y$$$ ($$$1 \le y \le 10^9$$$) is given, denoting the year we want to know the name for. | 800 | Print $$$q$$$ lines. For each line, print the name of the year as per the rule described above. | standard output | |
PASSED | cde3bd98f8fad7b65d11f926c4feb97b | train_003.jsonl | 1578139500 | Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.There are two sequences of $$$n$$$ strings $$$s_1, s_2, s_3, \ldots, s_{n}$$$ and $$$m$$$ strings $$$t_1, t_2, t_3, \ldots, t_{m}$$$. These strings contain only lowercase letters. There might be duplicates among these strings.Let's call a concatenation of strings $$$x$$$ and $$$y$$$ as the string that is obtained by writing down strings $$$x$$$ and $$$y$$$ one right after another without changing the order. For example, the concatenation of the strings "code" and "forces" is the string "codeforces".The year 1 has a name which is the concatenation of the two strings $$$s_1$$$ and $$$t_1$$$. When the year increases by one, we concatenate the next two strings in order from each of the respective sequences. If the string that is currently being used is at the end of its sequence, we go back to the first string in that sequence.For example, if $$$n = 3, m = 4, s = $$${"a", "b", "c"}, $$$t =$$$ {"d", "e", "f", "g"}, the following table denotes the resulting year names. Note that the names of the years may repeat. You are given two sequences of strings of size $$$n$$$ and $$$m$$$ and also $$$q$$$ queries. For each query, you will be given the current year. Could you find the name corresponding to the given year, according to the Gapja system? | 1024 megabytes |
import java.util.Scanner;
public class NewYear {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int m=sc.nextInt();
sc.nextLine();
String[] s=new String[n];
String[] t=new String[m];
for(int i=0;i<n;i++) {
s[i]=sc.next();
//System.out.println("ska"+s[i]);
}
for(int i=0;i<m;i++) {
t[i]=sc.next();
//System.out.println("tka"+t[i]);
}
int q=sc.nextInt();
String[] result=new String[q];
for(int i=0;i<q;i++) {
int y=sc.nextInt();
int a=y%n,b=y%m;
if(a==0)
a=n;
if(b==0)
b=m;
result[i]=s[a-1].concat(t[b-1]);
//System.out.println(s[a-1]+"s "+t[b-1]+"t "+result[i]);
}
for(String i:result)
System.out.println(i);
}
}
| Java | ["10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020"] | 1 second | ["sinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsin\ngyeyu\ngyeyu\nbyeongsin\njeongyu\nmusul\ngihae\ngyeongja"] | NoteThe first example denotes the actual names used in the Gapja system. These strings usually are either a number or the name of some animal. | Java 8 | standard input | [
"implementation",
"strings"
] | efa201456f8703fcdc29230248d91c54 | The first line contains two integers $$$n, m$$$ ($$$1 \le n, m \le 20$$$). The next line contains $$$n$$$ strings $$$s_1, s_2, \ldots, s_{n}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. The next line contains $$$m$$$ strings $$$t_1, t_2, \ldots, t_{m}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. Among the given $$$n + m$$$ strings may be duplicates (that is, they are not necessarily all different). The next line contains a single integer $$$q$$$ ($$$1 \le q \le 2\,020$$$). In the next $$$q$$$ lines, an integer $$$y$$$ ($$$1 \le y \le 10^9$$$) is given, denoting the year we want to know the name for. | 800 | Print $$$q$$$ lines. For each line, print the name of the year as per the rule described above. | standard output | |
PASSED | a24257539b044454cc482d72d1f86310 | train_003.jsonl | 1578139500 | Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.There are two sequences of $$$n$$$ strings $$$s_1, s_2, s_3, \ldots, s_{n}$$$ and $$$m$$$ strings $$$t_1, t_2, t_3, \ldots, t_{m}$$$. These strings contain only lowercase letters. There might be duplicates among these strings.Let's call a concatenation of strings $$$x$$$ and $$$y$$$ as the string that is obtained by writing down strings $$$x$$$ and $$$y$$$ one right after another without changing the order. For example, the concatenation of the strings "code" and "forces" is the string "codeforces".The year 1 has a name which is the concatenation of the two strings $$$s_1$$$ and $$$t_1$$$. When the year increases by one, we concatenate the next two strings in order from each of the respective sequences. If the string that is currently being used is at the end of its sequence, we go back to the first string in that sequence.For example, if $$$n = 3, m = 4, s = $$${"a", "b", "c"}, $$$t =$$$ {"d", "e", "f", "g"}, the following table denotes the resulting year names. Note that the names of the years may repeat. You are given two sequences of strings of size $$$n$$$ and $$$m$$$ and also $$$q$$$ queries. For each query, you will be given the current year. Could you find the name corresponding to the given year, according to the Gapja system? | 1024 megabytes | import java.util.*;
import java.io.*;
public class Main {
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int m = scan.nextInt();
String[] first = new String[n];
String[] second = new String[m];
for(int i = 0;i< n;i++)
first[i] = scan.next();
for(int i = 0 ;i<m ;i++)
second[i] = scan.next();
int q = scan.nextInt();
while(q-->0){
long year = scan.nextLong();
int index1 = 0;
int index2 = 0;
int remain1 =(int) year%(n);
int remain2 =(int) year%(m);
if(remain1==0){
index1 = n-1;
}else{
index1 = remain1-1;
}
if(remain2==0)
index2 = m-1;
else
index2= remain2-1;
System.out.println(first[index1]+second[index2]);
}
}
} | Java | ["10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020"] | 1 second | ["sinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsin\ngyeyu\ngyeyu\nbyeongsin\njeongyu\nmusul\ngihae\ngyeongja"] | NoteThe first example denotes the actual names used in the Gapja system. These strings usually are either a number or the name of some animal. | Java 8 | standard input | [
"implementation",
"strings"
] | efa201456f8703fcdc29230248d91c54 | The first line contains two integers $$$n, m$$$ ($$$1 \le n, m \le 20$$$). The next line contains $$$n$$$ strings $$$s_1, s_2, \ldots, s_{n}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. The next line contains $$$m$$$ strings $$$t_1, t_2, \ldots, t_{m}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. Among the given $$$n + m$$$ strings may be duplicates (that is, they are not necessarily all different). The next line contains a single integer $$$q$$$ ($$$1 \le q \le 2\,020$$$). In the next $$$q$$$ lines, an integer $$$y$$$ ($$$1 \le y \le 10^9$$$) is given, denoting the year we want to know the name for. | 800 | Print $$$q$$$ lines. For each line, print the name of the year as per the rule described above. | standard output | |
PASSED | 9be2922fc5a5b10405119ad00944f244 | train_003.jsonl | 1578139500 | Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.There are two sequences of $$$n$$$ strings $$$s_1, s_2, s_3, \ldots, s_{n}$$$ and $$$m$$$ strings $$$t_1, t_2, t_3, \ldots, t_{m}$$$. These strings contain only lowercase letters. There might be duplicates among these strings.Let's call a concatenation of strings $$$x$$$ and $$$y$$$ as the string that is obtained by writing down strings $$$x$$$ and $$$y$$$ one right after another without changing the order. For example, the concatenation of the strings "code" and "forces" is the string "codeforces".The year 1 has a name which is the concatenation of the two strings $$$s_1$$$ and $$$t_1$$$. When the year increases by one, we concatenate the next two strings in order from each of the respective sequences. If the string that is currently being used is at the end of its sequence, we go back to the first string in that sequence.For example, if $$$n = 3, m = 4, s = $$${"a", "b", "c"}, $$$t =$$$ {"d", "e", "f", "g"}, the following table denotes the resulting year names. Note that the names of the years may repeat. You are given two sequences of strings of size $$$n$$$ and $$$m$$$ and also $$$q$$$ queries. For each query, you will be given the current year. Could you find the name corresponding to the given year, according to the Gapja system? | 1024 megabytes | import java.util.*;
import java.io.*;
public class NewYearandNaming
{
public static void main(String[] args) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String[] str=br.readLine().split(" ");
int n=Integer.parseInt(str[0]);
int m=Integer.parseInt(str[1]);
String[] s=br.readLine().split(" ");
String[] t=br.readLine().split(" ");
int Q=Integer.parseInt(br.readLine());
while(Q-->0)
{
int year=Integer.parseInt(br.readLine());
int x=year,y=year;
if(year>n)
x=year%n;
if(x==0)
x=n;
if(year>m)
y=year%m;
if(y==0)
y=m;
String res=s[x-1]+t[y-1];
System.out.println(res);
}
}
} | Java | ["10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020"] | 1 second | ["sinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsin\ngyeyu\ngyeyu\nbyeongsin\njeongyu\nmusul\ngihae\ngyeongja"] | NoteThe first example denotes the actual names used in the Gapja system. These strings usually are either a number or the name of some animal. | Java 8 | standard input | [
"implementation",
"strings"
] | efa201456f8703fcdc29230248d91c54 | The first line contains two integers $$$n, m$$$ ($$$1 \le n, m \le 20$$$). The next line contains $$$n$$$ strings $$$s_1, s_2, \ldots, s_{n}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. The next line contains $$$m$$$ strings $$$t_1, t_2, \ldots, t_{m}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. Among the given $$$n + m$$$ strings may be duplicates (that is, they are not necessarily all different). The next line contains a single integer $$$q$$$ ($$$1 \le q \le 2\,020$$$). In the next $$$q$$$ lines, an integer $$$y$$$ ($$$1 \le y \le 10^9$$$) is given, denoting the year we want to know the name for. | 800 | Print $$$q$$$ lines. For each line, print the name of the year as per the rule described above. | standard output | |
PASSED | d63f35fdcd57532ca6a3e37e3de654c1 | train_003.jsonl | 1578139500 | Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.There are two sequences of $$$n$$$ strings $$$s_1, s_2, s_3, \ldots, s_{n}$$$ and $$$m$$$ strings $$$t_1, t_2, t_3, \ldots, t_{m}$$$. These strings contain only lowercase letters. There might be duplicates among these strings.Let's call a concatenation of strings $$$x$$$ and $$$y$$$ as the string that is obtained by writing down strings $$$x$$$ and $$$y$$$ one right after another without changing the order. For example, the concatenation of the strings "code" and "forces" is the string "codeforces".The year 1 has a name which is the concatenation of the two strings $$$s_1$$$ and $$$t_1$$$. When the year increases by one, we concatenate the next two strings in order from each of the respective sequences. If the string that is currently being used is at the end of its sequence, we go back to the first string in that sequence.For example, if $$$n = 3, m = 4, s = $$${"a", "b", "c"}, $$$t =$$$ {"d", "e", "f", "g"}, the following table denotes the resulting year names. Note that the names of the years may repeat. You are given two sequences of strings of size $$$n$$$ and $$$m$$$ and also $$$q$$$ queries. For each query, you will be given the current year. Could you find the name corresponding to the given year, according to the Gapja system? | 1024 megabytes |
import java.util.Scanner;
public class Test1 {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int n = in.nextInt(), m = in.nextInt();
String s1[] = new String[n];
for (int i=0;i<n;i++) s1[i] = in.next();
String s2[] = new String[m];
for (int i=0;i<m;i++) s2[i] = in.next();
int q = in.nextInt();
while (q-- > 0) {
int y = in.nextInt();
y--;
StringBuilder sb = new StringBuilder();
int i = y % n;
sb.append(s1[i]);
int j = y % m;
sb.append(s2[j]);
System.out.println(sb);
}
in.close();
}
} | Java | ["10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020"] | 1 second | ["sinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsin\ngyeyu\ngyeyu\nbyeongsin\njeongyu\nmusul\ngihae\ngyeongja"] | NoteThe first example denotes the actual names used in the Gapja system. These strings usually are either a number or the name of some animal. | Java 8 | standard input | [
"implementation",
"strings"
] | efa201456f8703fcdc29230248d91c54 | The first line contains two integers $$$n, m$$$ ($$$1 \le n, m \le 20$$$). The next line contains $$$n$$$ strings $$$s_1, s_2, \ldots, s_{n}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. The next line contains $$$m$$$ strings $$$t_1, t_2, \ldots, t_{m}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. Among the given $$$n + m$$$ strings may be duplicates (that is, they are not necessarily all different). The next line contains a single integer $$$q$$$ ($$$1 \le q \le 2\,020$$$). In the next $$$q$$$ lines, an integer $$$y$$$ ($$$1 \le y \le 10^9$$$) is given, denoting the year we want to know the name for. | 800 | Print $$$q$$$ lines. For each line, print the name of the year as per the rule described above. | standard output | |
PASSED | b118d03bc70ef3ff33fc6eebaf74e991 | train_003.jsonl | 1578139500 | Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.There are two sequences of $$$n$$$ strings $$$s_1, s_2, s_3, \ldots, s_{n}$$$ and $$$m$$$ strings $$$t_1, t_2, t_3, \ldots, t_{m}$$$. These strings contain only lowercase letters. There might be duplicates among these strings.Let's call a concatenation of strings $$$x$$$ and $$$y$$$ as the string that is obtained by writing down strings $$$x$$$ and $$$y$$$ one right after another without changing the order. For example, the concatenation of the strings "code" and "forces" is the string "codeforces".The year 1 has a name which is the concatenation of the two strings $$$s_1$$$ and $$$t_1$$$. When the year increases by one, we concatenate the next two strings in order from each of the respective sequences. If the string that is currently being used is at the end of its sequence, we go back to the first string in that sequence.For example, if $$$n = 3, m = 4, s = $$${"a", "b", "c"}, $$$t =$$$ {"d", "e", "f", "g"}, the following table denotes the resulting year names. Note that the names of the years may repeat. You are given two sequences of strings of size $$$n$$$ and $$$m$$$ and also $$$q$$$ queries. For each query, you will be given the current year. Could you find the name corresponding to the given year, according to the Gapja system? | 1024 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class J_NewYearNaming {
public static ArrayList<String> year = new ArrayList<String>();
public static ArrayList<String> sF = new ArrayList<String>();
public static ArrayList<String> tF = new ArrayList<String>();
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
int n,m;
st = new StringTokenizer(bf.readLine());
n = Integer.parseInt(st.nextToken());
m = Integer.parseInt(st.nextToken());
String [] s = new String[n+1];
String [] t = new String[m+1];
st = new StringTokenizer(bf.readLine());
for (int i = 1; i <= n; i++) {
s[i] = st.nextToken();
}
st = new StringTokenizer(bf.readLine());
for (int i = 1; i <= m; i++) {
t[i] = st.nextToken();
}
int casos = Integer.parseInt(bf.readLine());
while(casos > 0) {
int q = Integer.parseInt(bf.readLine());
int nF = q % n;
int mF = q % m;
if(nF == 0) {
nF = n;
}
if(mF == 0) {
mF = m;
}
System.out.println(s[nF]+t[mF]);
casos--;
}
}
}
| Java | ["10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020"] | 1 second | ["sinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsin\ngyeyu\ngyeyu\nbyeongsin\njeongyu\nmusul\ngihae\ngyeongja"] | NoteThe first example denotes the actual names used in the Gapja system. These strings usually are either a number or the name of some animal. | Java 8 | standard input | [
"implementation",
"strings"
] | efa201456f8703fcdc29230248d91c54 | The first line contains two integers $$$n, m$$$ ($$$1 \le n, m \le 20$$$). The next line contains $$$n$$$ strings $$$s_1, s_2, \ldots, s_{n}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. The next line contains $$$m$$$ strings $$$t_1, t_2, \ldots, t_{m}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. Among the given $$$n + m$$$ strings may be duplicates (that is, they are not necessarily all different). The next line contains a single integer $$$q$$$ ($$$1 \le q \le 2\,020$$$). In the next $$$q$$$ lines, an integer $$$y$$$ ($$$1 \le y \le 10^9$$$) is given, denoting the year we want to know the name for. | 800 | Print $$$q$$$ lines. For each line, print the name of the year as per the rule described above. | standard output | |
PASSED | da697d2ca1ba24bced50c4864f841d37 | train_003.jsonl | 1578139500 | Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.There are two sequences of $$$n$$$ strings $$$s_1, s_2, s_3, \ldots, s_{n}$$$ and $$$m$$$ strings $$$t_1, t_2, t_3, \ldots, t_{m}$$$. These strings contain only lowercase letters. There might be duplicates among these strings.Let's call a concatenation of strings $$$x$$$ and $$$y$$$ as the string that is obtained by writing down strings $$$x$$$ and $$$y$$$ one right after another without changing the order. For example, the concatenation of the strings "code" and "forces" is the string "codeforces".The year 1 has a name which is the concatenation of the two strings $$$s_1$$$ and $$$t_1$$$. When the year increases by one, we concatenate the next two strings in order from each of the respective sequences. If the string that is currently being used is at the end of its sequence, we go back to the first string in that sequence.For example, if $$$n = 3, m = 4, s = $$${"a", "b", "c"}, $$$t =$$$ {"d", "e", "f", "g"}, the following table denotes the resulting year names. Note that the names of the years may repeat. You are given two sequences of strings of size $$$n$$$ and $$$m$$$ and also $$$q$$$ queries. For each query, you will be given the current year. Could you find the name corresponding to the given year, according to the Gapja system? | 1024 megabytes | import java.util.*;
import java.util.concurrent.*;
import java.util.function.Function;
import java.util.function.IntPredicate;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
import java.util.stream.Stream;
public class Test {
public static void main(String[] args){
Scanner sc= new Scanner(System.in);
int m=sc.nextInt();
int n=sc.nextInt();
String[] s1Arr=new String[m];
String[] s2Arr=new String[n];
for(int i=0;i<m;i++){
s1Arr[i]=sc.next();
}
for(int i=0;i<n;i++){
s2Arr[i]=sc.next();
}
int years=sc.nextInt();
for(int i=0;i<years;i++){
int year=sc.nextInt()-1;
String output=getFinalString(s1Arr,s2Arr,year);
System.out.println(output);
}
}
private static String getFinalString(String[] s1,String[] s2,int year){
if(s1.length==0 || s2.length==0){
return "";
}
int len1=s1.length;
int len2=s2.length;
int idx1=year%len1;
int idx2=year%len2;
return s1[idx1]+""+s2[idx2];
}
}
| Java | ["10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020"] | 1 second | ["sinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsin\ngyeyu\ngyeyu\nbyeongsin\njeongyu\nmusul\ngihae\ngyeongja"] | NoteThe first example denotes the actual names used in the Gapja system. These strings usually are either a number or the name of some animal. | Java 8 | standard input | [
"implementation",
"strings"
] | efa201456f8703fcdc29230248d91c54 | The first line contains two integers $$$n, m$$$ ($$$1 \le n, m \le 20$$$). The next line contains $$$n$$$ strings $$$s_1, s_2, \ldots, s_{n}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. The next line contains $$$m$$$ strings $$$t_1, t_2, \ldots, t_{m}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. Among the given $$$n + m$$$ strings may be duplicates (that is, they are not necessarily all different). The next line contains a single integer $$$q$$$ ($$$1 \le q \le 2\,020$$$). In the next $$$q$$$ lines, an integer $$$y$$$ ($$$1 \le y \le 10^9$$$) is given, denoting the year we want to know the name for. | 800 | Print $$$q$$$ lines. For each line, print the name of the year as per the rule described above. | standard output | |
PASSED | 3e96293eead686e5e16bb175d0c69cd9 | train_003.jsonl | 1578139500 | Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.There are two sequences of $$$n$$$ strings $$$s_1, s_2, s_3, \ldots, s_{n}$$$ and $$$m$$$ strings $$$t_1, t_2, t_3, \ldots, t_{m}$$$. These strings contain only lowercase letters. There might be duplicates among these strings.Let's call a concatenation of strings $$$x$$$ and $$$y$$$ as the string that is obtained by writing down strings $$$x$$$ and $$$y$$$ one right after another without changing the order. For example, the concatenation of the strings "code" and "forces" is the string "codeforces".The year 1 has a name which is the concatenation of the two strings $$$s_1$$$ and $$$t_1$$$. When the year increases by one, we concatenate the next two strings in order from each of the respective sequences. If the string that is currently being used is at the end of its sequence, we go back to the first string in that sequence.For example, if $$$n = 3, m = 4, s = $$${"a", "b", "c"}, $$$t =$$$ {"d", "e", "f", "g"}, the following table denotes the resulting year names. Note that the names of the years may repeat. You are given two sequences of strings of size $$$n$$$ and $$$m$$$ and also $$$q$$$ queries. For each query, you will be given the current year. Could you find the name corresponding to the given year, according to the Gapja system? | 1024 megabytes | import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int m = s.nextInt();
String first[] = new String[n];
String second[] = new String[m];
int i = 0 , j = 0;
while(i < n){
first[i] = s.next();
i++;
}
while(j < m){
second[j] = s.next();
j++;
}
int q = s.nextInt();
while(q > 0){
int year = s.nextInt();
helper(year,first,second);
q--;
}
}
static void helper(int year,String first[],String second[]){
int firstPositionString = year % first.length;
int secondPositionString = year % second.length;
if(firstPositionString != 0)
firstPositionString = firstPositionString-1;
else
firstPositionString = first.length-1;
if(secondPositionString != 0)
secondPositionString = secondPositionString-1;
else
secondPositionString = second.length-1;
System.out.println(first[firstPositionString]+second[secondPositionString]);
}
}
| Java | ["10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020"] | 1 second | ["sinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsin\ngyeyu\ngyeyu\nbyeongsin\njeongyu\nmusul\ngihae\ngyeongja"] | NoteThe first example denotes the actual names used in the Gapja system. These strings usually are either a number or the name of some animal. | Java 8 | standard input | [
"implementation",
"strings"
] | efa201456f8703fcdc29230248d91c54 | The first line contains two integers $$$n, m$$$ ($$$1 \le n, m \le 20$$$). The next line contains $$$n$$$ strings $$$s_1, s_2, \ldots, s_{n}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. The next line contains $$$m$$$ strings $$$t_1, t_2, \ldots, t_{m}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. Among the given $$$n + m$$$ strings may be duplicates (that is, they are not necessarily all different). The next line contains a single integer $$$q$$$ ($$$1 \le q \le 2\,020$$$). In the next $$$q$$$ lines, an integer $$$y$$$ ($$$1 \le y \le 10^9$$$) is given, denoting the year we want to know the name for. | 800 | Print $$$q$$$ lines. For each line, print the name of the year as per the rule described above. | standard output | |
PASSED | c67ca8702b2bde6469c3ecf6fa821ba4 | train_003.jsonl | 1543934100 | You're given an array $$$a$$$. You should repeat the following operation $$$k$$$ times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0. | 256 megabytes | import java.util.*;
public class Test {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int k = scan.nextInt();
List<Integer> list = new ArrayList<>();
for (int i = 0 ; i < n; i++) {
int temp = scan.nextInt();
list.add(temp);
}
Collections.sort(list);
int val;
int sum = 0;
int index = 0;
while (k != 0 && list.size() > index) {
val = list.get(index);
index++;
val = val - sum;
if (val != 0) {
System.out.println(val);
sum += val;
k--;
}
}
while (k !=0 ) {
System.out.println(0);
k--;
}
}
} | Java | ["3 5\n1 2 3", "4 2\n10 3 5 3"] | 1 second | ["1\n1\n1\n0\n0", "3\n2"] | NoteIn the first sample:In the first step: the array is $$$[1,2,3]$$$, so the minimum non-zero element is 1.In the second step: the array is $$$[0,1,2]$$$, so the minimum non-zero element is 1.In the third step: the array is $$$[0,0,1]$$$, so the minimum non-zero element is 1.In the fourth and fifth step: the array is $$$[0,0,0]$$$, so we printed 0.In the second sample:In the first step: the array is $$$[10,3,5,3]$$$, so the minimum non-zero element is 3.In the second step: the array is $$$[7,0,2,0]$$$, so the minimum non-zero element is 2. | Java 8 | standard input | [
"implementation",
"sortings"
] | 0f100199a720b0fdead5f03e1882f2f3 | The first line contains integers $$$n$$$ and $$$k$$$ $$$(1 \le n,k \le 10^5)$$$, the length of the array and the number of operations you should perform. The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$, the elements of the array. | 1,000 | Print the minimum non-zero element before each operation in a new line. | standard output | |
PASSED | 8e7df333522c8619d3b5018e48d154ad | train_003.jsonl | 1543934100 | You're given an array $$$a$$$. You should repeat the following operation $$$k$$$ times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0. | 256 megabytes |
import java.util.Scanner;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author quan.vuhong
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner sc = new Scanner(System.in);
int n, k;
n = sc.nextInt();
k = sc.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
}
sort(a);
int index = 0;
System.out.println(a[0]);
k--;
for (int i = 0; i < n-1; i++) {
if(k==0)
break;
if(a[i]<a[i+1]){
k--;
System.out.println((a[i+1]-a[i]));
}
}
for (int i = 0; i < k; i++) {
System.out.println(0);
}
}
static void sort(int arr[]) {
int n = arr.length;
// Build heap (rearrange array)
for (int i = n / 2 - 1; i >= 0; i--) {
heapify(arr, n, i);
}
// One by one extract an element from heap
for (int i = n - 1; i >= 0; i--) {
// Move current root to end
int temp = arr[0];
arr[0] = arr[i];
arr[i] = temp;
// call max heapify on the reduced heap
heapify(arr, i, 0);
}
}
// To heapify a subtree rooted with node i which is
// an index in arr[]. n is size of heap
static void heapify(int arr[], int n, int i) {
int largest = i; // Initialize largest as root
int l = 2 * i + 1; // left = 2*i + 1
int r = 2 * i + 2; // right = 2*i + 2
// If left child is larger than root
if (l < n && arr[l] > arr[largest]) {
largest = l;
}
// If right child is larger than largest so far
if (r < n && arr[r] > arr[largest]) {
largest = r;
}
// If largest is not root
if (largest != i) {
int swap = arr[i];
arr[i] = arr[largest];
arr[largest] = swap;
// Recursively heapify the affected sub-tree
heapify(arr, n, largest);
}
}
}
| Java | ["3 5\n1 2 3", "4 2\n10 3 5 3"] | 1 second | ["1\n1\n1\n0\n0", "3\n2"] | NoteIn the first sample:In the first step: the array is $$$[1,2,3]$$$, so the minimum non-zero element is 1.In the second step: the array is $$$[0,1,2]$$$, so the minimum non-zero element is 1.In the third step: the array is $$$[0,0,1]$$$, so the minimum non-zero element is 1.In the fourth and fifth step: the array is $$$[0,0,0]$$$, so we printed 0.In the second sample:In the first step: the array is $$$[10,3,5,3]$$$, so the minimum non-zero element is 3.In the second step: the array is $$$[7,0,2,0]$$$, so the minimum non-zero element is 2. | Java 8 | standard input | [
"implementation",
"sortings"
] | 0f100199a720b0fdead5f03e1882f2f3 | The first line contains integers $$$n$$$ and $$$k$$$ $$$(1 \le n,k \le 10^5)$$$, the length of the array and the number of operations you should perform. The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$, the elements of the array. | 1,000 | Print the minimum non-zero element before each operation in a new line. | standard output | |
PASSED | a495f56d8de66c34222536e7294ecce4 | train_003.jsonl | 1543934100 | You're given an array $$$a$$$. You should repeat the following operation $$$k$$$ times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0. | 256 megabytes | /* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
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 k=sc.nextInt();
int i,a[];
long sum=0;
a=new int[n+1];
for(i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
a[n]=0;
Arrays.sort(a);
for(i=1;i<=n;i++)
{
if(k==0)
break;
else if(a[i]!=a[i-1])
{
k--;
System.out.println(a[i]-a[i-1]);
}
}
for(i=0;i<k;i++)
{
System.out.println("0");
}
}
} | Java | ["3 5\n1 2 3", "4 2\n10 3 5 3"] | 1 second | ["1\n1\n1\n0\n0", "3\n2"] | NoteIn the first sample:In the first step: the array is $$$[1,2,3]$$$, so the minimum non-zero element is 1.In the second step: the array is $$$[0,1,2]$$$, so the minimum non-zero element is 1.In the third step: the array is $$$[0,0,1]$$$, so the minimum non-zero element is 1.In the fourth and fifth step: the array is $$$[0,0,0]$$$, so we printed 0.In the second sample:In the first step: the array is $$$[10,3,5,3]$$$, so the minimum non-zero element is 3.In the second step: the array is $$$[7,0,2,0]$$$, so the minimum non-zero element is 2. | Java 8 | standard input | [
"implementation",
"sortings"
] | 0f100199a720b0fdead5f03e1882f2f3 | The first line contains integers $$$n$$$ and $$$k$$$ $$$(1 \le n,k \le 10^5)$$$, the length of the array and the number of operations you should perform. The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$, the elements of the array. | 1,000 | Print the minimum non-zero element before each operation in a new line. | standard output | |
PASSED | 2b308549da040b0ce919f0e02d025123 | train_003.jsonl | 1543934100 | You're given an array $$$a$$$. You should repeat the following operation $$$k$$$ times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0. | 256 megabytes | import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Arrays;
public class eHabAndSubtraction {
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 IOException {
Reader r = new Reader();
int n = r.nextInt();
int k = r.nextInt();
int a[] = new int[n];
StringBuilder res = new StringBuilder();
for (int i = 0; i < n && k > 0; i++) {
a[i] = r.nextInt();
}
Arrays.sort(a);
int sum = 0;
for (int i = 0; i < n && k > 0; i++) {
int el = a[i];
if (el - sum > 0) {
res.append(el - sum).append("\n");
sum += el - sum;
k--;
}
}
while (k-- > 0) {
res.append(0).append("\n");
}
System.out.println(res);
}
} | Java | ["3 5\n1 2 3", "4 2\n10 3 5 3"] | 1 second | ["1\n1\n1\n0\n0", "3\n2"] | NoteIn the first sample:In the first step: the array is $$$[1,2,3]$$$, so the minimum non-zero element is 1.In the second step: the array is $$$[0,1,2]$$$, so the minimum non-zero element is 1.In the third step: the array is $$$[0,0,1]$$$, so the minimum non-zero element is 1.In the fourth and fifth step: the array is $$$[0,0,0]$$$, so we printed 0.In the second sample:In the first step: the array is $$$[10,3,5,3]$$$, so the minimum non-zero element is 3.In the second step: the array is $$$[7,0,2,0]$$$, so the minimum non-zero element is 2. | Java 8 | standard input | [
"implementation",
"sortings"
] | 0f100199a720b0fdead5f03e1882f2f3 | The first line contains integers $$$n$$$ and $$$k$$$ $$$(1 \le n,k \le 10^5)$$$, the length of the array and the number of operations you should perform. The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$, the elements of the array. | 1,000 | Print the minimum non-zero element before each operation in a new line. | standard output | |
PASSED | f8a02ec199e43b943bbb7850be968409 | train_003.jsonl | 1543934100 | You're given an array $$$a$$$. You should repeat the following operation $$$k$$$ times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class EhabSub {
public static void main(String [] args) {
Scanner in = new Scanner(System.in);
int [] arr = new int[in.nextInt()];
int op = in.nextInt()-1;
for(int i=0;i<arr.length;i++) arr[i]=in.nextInt();
Arrays.sort(arr);
int index=0, sum=arr[0];
System.out.println(arr[0]);
while(op>0) {
while(index<arr.length&&arr[index]-sum<=0) {
index++;
}
if(index==arr.length) {
System.out.println(0);
}
else {
System.out.println(arr[index]-sum);
sum+=arr[index]-sum;
index++;
}
op--;
}
}
}
| Java | ["3 5\n1 2 3", "4 2\n10 3 5 3"] | 1 second | ["1\n1\n1\n0\n0", "3\n2"] | NoteIn the first sample:In the first step: the array is $$$[1,2,3]$$$, so the minimum non-zero element is 1.In the second step: the array is $$$[0,1,2]$$$, so the minimum non-zero element is 1.In the third step: the array is $$$[0,0,1]$$$, so the minimum non-zero element is 1.In the fourth and fifth step: the array is $$$[0,0,0]$$$, so we printed 0.In the second sample:In the first step: the array is $$$[10,3,5,3]$$$, so the minimum non-zero element is 3.In the second step: the array is $$$[7,0,2,0]$$$, so the minimum non-zero element is 2. | Java 8 | standard input | [
"implementation",
"sortings"
] | 0f100199a720b0fdead5f03e1882f2f3 | The first line contains integers $$$n$$$ and $$$k$$$ $$$(1 \le n,k \le 10^5)$$$, the length of the array and the number of operations you should perform. The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$, the elements of the array. | 1,000 | Print the minimum non-zero element before each operation in a new line. | standard output | |
PASSED | 955376813b6463f23c8bf64af2900f14 | train_003.jsonl | 1543934100 | You're given an array $$$a$$$. You should repeat the following operation $$$k$$$ times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
public void solve() {
int n = ni();
int k = ni();
long[] a = new long[n];
for (int i = 0; i < n; i++) {
a[i] = ni();
}
long fr = 0;
Arrays.sort(a);
int c = 0;
for (int i = 0; (c < k) && (i < n); i++) {
if ((a[i] - fr) == 0) continue;
if (a[i] - fr < 0) {
int g = 1 / 0;
}
c++;
write(a[i] - fr + "\n");
fr += Math.max(a[i] - fr, 0);
}
while(c < k) {
write("0\n");
c++;
}
}
public static void main(String[] args) {
Main m = new Main();
m.solve();
try {
m.out.close();
} catch (IOException e) {}
}
BufferedReader in;
BufferedWriter out;
StringTokenizer tokenizer;
public Main() {
in = new BufferedReader(new InputStreamReader(System.in));
out = new BufferedWriter(new OutputStreamWriter(System.out));
}
public String n() {
if (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(in.readLine());
} catch (IOException e) {}
}
return tokenizer.nextToken();
}
public int ni() {
return Integer.parseInt(n());
}
public void write(String s) {
try {
out.write(s);
} catch (IOException e) {}
}
} | Java | ["3 5\n1 2 3", "4 2\n10 3 5 3"] | 1 second | ["1\n1\n1\n0\n0", "3\n2"] | NoteIn the first sample:In the first step: the array is $$$[1,2,3]$$$, so the minimum non-zero element is 1.In the second step: the array is $$$[0,1,2]$$$, so the minimum non-zero element is 1.In the third step: the array is $$$[0,0,1]$$$, so the minimum non-zero element is 1.In the fourth and fifth step: the array is $$$[0,0,0]$$$, so we printed 0.In the second sample:In the first step: the array is $$$[10,3,5,3]$$$, so the minimum non-zero element is 3.In the second step: the array is $$$[7,0,2,0]$$$, so the minimum non-zero element is 2. | Java 8 | standard input | [
"implementation",
"sortings"
] | 0f100199a720b0fdead5f03e1882f2f3 | The first line contains integers $$$n$$$ and $$$k$$$ $$$(1 \le n,k \le 10^5)$$$, the length of the array and the number of operations you should perform. The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$, the elements of the array. | 1,000 | Print the minimum non-zero element before each operation in a new line. | standard output | |
PASSED | 67961cfc693b4a88437c6c3e98b24062 | train_003.jsonl | 1543934100 | You're given an array $$$a$$$. You should repeat the following operation $$$k$$$ times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0. | 256 megabytes | import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int k = scan.nextInt();
TreeMap<Integer, Integer> m = new TreeMap<>();
for (int i = 0 ; i < n; i++) {
int temp = scan.nextInt();
m.put(temp, 0);
}
int val;
int sum =0;
for (Map.Entry<Integer, Integer> entry : m.entrySet()) {
val = entry.getKey();
val = val -sum;
if (val != 0) {
System.out.println(val);
sum += val;
k--;
}
if (k == 0) {
break;
}
}
while (k !=0 ) {
System.out.println(0);
k--;
}
}
}
| Java | ["3 5\n1 2 3", "4 2\n10 3 5 3"] | 1 second | ["1\n1\n1\n0\n0", "3\n2"] | NoteIn the first sample:In the first step: the array is $$$[1,2,3]$$$, so the minimum non-zero element is 1.In the second step: the array is $$$[0,1,2]$$$, so the minimum non-zero element is 1.In the third step: the array is $$$[0,0,1]$$$, so the minimum non-zero element is 1.In the fourth and fifth step: the array is $$$[0,0,0]$$$, so we printed 0.In the second sample:In the first step: the array is $$$[10,3,5,3]$$$, so the minimum non-zero element is 3.In the second step: the array is $$$[7,0,2,0]$$$, so the minimum non-zero element is 2. | Java 8 | standard input | [
"implementation",
"sortings"
] | 0f100199a720b0fdead5f03e1882f2f3 | The first line contains integers $$$n$$$ and $$$k$$$ $$$(1 \le n,k \le 10^5)$$$, the length of the array and the number of operations you should perform. The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$, the elements of the array. | 1,000 | Print the minimum non-zero element before each operation in a new line. | standard output | |
PASSED | 1049fc35caf3d724e225f4847847945f | train_003.jsonl | 1543934100 | You're given an array $$$a$$$. You should repeat the following operation $$$k$$$ times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0. | 256 megabytes | import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int k = scan.nextInt();
List<Integer> list = new ArrayList<>();
for (int i = 0 ; i < n; i++) {
int temp = scan.nextInt();
list.add(temp);
}
Collections.sort(list);
int val;
int sum = 0;
int index = 0;
while (k != 0 && list.size() > index) {
val = list.get(index);
index++;
val = val - sum;
if (val != 0) {
System.out.println(val);
sum += val;
k--;
}
}
while (k !=0 ) {
System.out.println(0);
k--;
}
}
}
| Java | ["3 5\n1 2 3", "4 2\n10 3 5 3"] | 1 second | ["1\n1\n1\n0\n0", "3\n2"] | NoteIn the first sample:In the first step: the array is $$$[1,2,3]$$$, so the minimum non-zero element is 1.In the second step: the array is $$$[0,1,2]$$$, so the minimum non-zero element is 1.In the third step: the array is $$$[0,0,1]$$$, so the minimum non-zero element is 1.In the fourth and fifth step: the array is $$$[0,0,0]$$$, so we printed 0.In the second sample:In the first step: the array is $$$[10,3,5,3]$$$, so the minimum non-zero element is 3.In the second step: the array is $$$[7,0,2,0]$$$, so the minimum non-zero element is 2. | Java 8 | standard input | [
"implementation",
"sortings"
] | 0f100199a720b0fdead5f03e1882f2f3 | The first line contains integers $$$n$$$ and $$$k$$$ $$$(1 \le n,k \le 10^5)$$$, the length of the array and the number of operations you should perform. The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$, the elements of the array. | 1,000 | Print the minimum non-zero element before each operation in a new line. | standard output | |
PASSED | 69c289d55f0395a166c27fdf134be4ad | train_003.jsonl | 1543934100 | You're given an array $$$a$$$. You should repeat the following operation $$$k$$$ times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0. | 256 megabytes | //189301019.akshay
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.Random;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Collections;
public class A
{
public static void main(String[] args)
{
FastReader sc=new FastReader();
StringBuffer ans=new StringBuffer();
int test=1;
outer:while(test-->0)
{
int n=sc.nextInt(),k=sc.nextInt();
long arr[]=new long[n];
for(int i=0;i<n;i++)arr[i]=sc.nextLong();
ruffleSort(arr);
int s=0;
long minus=0;
while(k-->0) {
while(s<n && arr[s]-minus ==0) {
++s;
}
if(s == n) {
ans.append(0+"\n");
continue;
}
ans.append((arr[s]-minus)+"\n");
minus+=(arr[s]-minus);
s++;
}
}
System.out.print(ans);
}
static final Random random=new Random();
static void ruffleSort(int[] a) {
int n=a.length;//shuffle, then sort
for (int i=0; i<n; i++) {
int oi=random.nextInt(n), temp=a[oi];
a[oi]=a[i]; a[i]=temp;
}
Arrays.sort(a);
}
static void ruffleSort(long[] a) {
int n=a.length;//shuffle, then sort
for (int i=0; i<n; i++) {
int oi=random.nextInt(n);
long temp=a[oi];
a[oi]=a[i]; a[i]=temp;
}
Arrays.sort(a);
}
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
}
| Java | ["3 5\n1 2 3", "4 2\n10 3 5 3"] | 1 second | ["1\n1\n1\n0\n0", "3\n2"] | NoteIn the first sample:In the first step: the array is $$$[1,2,3]$$$, so the minimum non-zero element is 1.In the second step: the array is $$$[0,1,2]$$$, so the minimum non-zero element is 1.In the third step: the array is $$$[0,0,1]$$$, so the minimum non-zero element is 1.In the fourth and fifth step: the array is $$$[0,0,0]$$$, so we printed 0.In the second sample:In the first step: the array is $$$[10,3,5,3]$$$, so the minimum non-zero element is 3.In the second step: the array is $$$[7,0,2,0]$$$, so the minimum non-zero element is 2. | Java 8 | standard input | [
"implementation",
"sortings"
] | 0f100199a720b0fdead5f03e1882f2f3 | The first line contains integers $$$n$$$ and $$$k$$$ $$$(1 \le n,k \le 10^5)$$$, the length of the array and the number of operations you should perform. The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$, the elements of the array. | 1,000 | Print the minimum non-zero element before each operation in a new line. | standard output | |
PASSED | 5a0d2048958ac9d56ee4ac7788999735 | train_003.jsonl | 1543934100 | You're given an array $$$a$$$. You should repeat the following operation $$$k$$$ times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class A {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
PriorityQueue<Integer> p = new PriorityQueue<>();
for(int i=0;i<n;i++) {
p.add(sc.nextInt());
}
int i=0;
int c = 0;
for(;i<k&&p.isEmpty()==false;) {
if(p.peek()-c>0) {
System.out.println(p.peek()-c);
c+=p.poll()-c;
i++;
}else {
p.poll();
}
}
for(;i<k;i++)
System.out.println(0);
}
}
| Java | ["3 5\n1 2 3", "4 2\n10 3 5 3"] | 1 second | ["1\n1\n1\n0\n0", "3\n2"] | NoteIn the first sample:In the first step: the array is $$$[1,2,3]$$$, so the minimum non-zero element is 1.In the second step: the array is $$$[0,1,2]$$$, so the minimum non-zero element is 1.In the third step: the array is $$$[0,0,1]$$$, so the minimum non-zero element is 1.In the fourth and fifth step: the array is $$$[0,0,0]$$$, so we printed 0.In the second sample:In the first step: the array is $$$[10,3,5,3]$$$, so the minimum non-zero element is 3.In the second step: the array is $$$[7,0,2,0]$$$, so the minimum non-zero element is 2. | Java 8 | standard input | [
"implementation",
"sortings"
] | 0f100199a720b0fdead5f03e1882f2f3 | The first line contains integers $$$n$$$ and $$$k$$$ $$$(1 \le n,k \le 10^5)$$$, the length of the array and the number of operations you should perform. The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$, the elements of the array. | 1,000 | Print the minimum non-zero element before each operation in a new line. | standard output | |
PASSED | 3f102f0dc9351c3a577120b5be7b36bd | train_003.jsonl | 1543934100 | You're given an array $$$a$$$. You should repeat the following operation $$$k$$$ times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0. | 256 megabytes | //Ehab and Subtraction
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;
import java.util.Arrays;
public class EhabAndSubtraction
{
public static void main(String args[]) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken());
int a[] = new int[n];
st = new StringTokenizer(br.readLine());
for(int i = 0; i < n; i++)
{
a[i] = Integer.parseInt(st.nextToken());
}
Arrays.sort(a);
int count = 1;
System.out.println(a[0]);
if(count == k)
return;
try
{
for(int i = 1; true; i++)
{
int diff = a[i] - a[i-1];
if(diff != 0)
{
count++;
System.out.println(diff);
if(count == k)
break;
}
}
}
catch(ArrayIndexOutOfBoundsException e)
{
for(int i = 0; i < k-count; i++)
{
System.out.println("0");
}
}
}
} | Java | ["3 5\n1 2 3", "4 2\n10 3 5 3"] | 1 second | ["1\n1\n1\n0\n0", "3\n2"] | NoteIn the first sample:In the first step: the array is $$$[1,2,3]$$$, so the minimum non-zero element is 1.In the second step: the array is $$$[0,1,2]$$$, so the minimum non-zero element is 1.In the third step: the array is $$$[0,0,1]$$$, so the minimum non-zero element is 1.In the fourth and fifth step: the array is $$$[0,0,0]$$$, so we printed 0.In the second sample:In the first step: the array is $$$[10,3,5,3]$$$, so the minimum non-zero element is 3.In the second step: the array is $$$[7,0,2,0]$$$, so the minimum non-zero element is 2. | Java 8 | standard input | [
"implementation",
"sortings"
] | 0f100199a720b0fdead5f03e1882f2f3 | The first line contains integers $$$n$$$ and $$$k$$$ $$$(1 \le n,k \le 10^5)$$$, the length of the array and the number of operations you should perform. The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$, the elements of the array. | 1,000 | Print the minimum non-zero element before each operation in a new line. | standard output | |
PASSED | 589fe66c1561ddb516656a97cee96688 | train_003.jsonl | 1543934100 | You're given an array $$$a$$$. You should repeat the following operation $$$k$$$ times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0. | 256 megabytes | /*package whatever //do not write package name here */
import java.util.*;
import java.lang.*;
import java.io.*;
public class GFG {
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int k=sc.nextInt();
int i;
int a[]=new int[n];
for(i=0;i<n;i++){
a[i]=sc.nextInt();
}
Arrays.sort(a);
int j;
int sum=a[0];
for(i=0;i<n;i++){
if(i==0){
System.out.println(a[i]);
}
else if(a[i-1]==a[i]){
continue;
}
else{
int p=a[i]-sum;
System.out.println(p);
sum+=p;
}
k--;
if(k==0){
break;
}
}
while(k>=1){
System.out.println("0");
k--;}
}} | Java | ["3 5\n1 2 3", "4 2\n10 3 5 3"] | 1 second | ["1\n1\n1\n0\n0", "3\n2"] | NoteIn the first sample:In the first step: the array is $$$[1,2,3]$$$, so the minimum non-zero element is 1.In the second step: the array is $$$[0,1,2]$$$, so the minimum non-zero element is 1.In the third step: the array is $$$[0,0,1]$$$, so the minimum non-zero element is 1.In the fourth and fifth step: the array is $$$[0,0,0]$$$, so we printed 0.In the second sample:In the first step: the array is $$$[10,3,5,3]$$$, so the minimum non-zero element is 3.In the second step: the array is $$$[7,0,2,0]$$$, so the minimum non-zero element is 2. | Java 8 | standard input | [
"implementation",
"sortings"
] | 0f100199a720b0fdead5f03e1882f2f3 | The first line contains integers $$$n$$$ and $$$k$$$ $$$(1 \le n,k \le 10^5)$$$, the length of the array and the number of operations you should perform. The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$, the elements of the array. | 1,000 | Print the minimum non-zero element before each operation in a new line. | standard output | |
PASSED | 5db0bf9edf44eb61f7964a9ea85a23a1 | train_003.jsonl | 1543934100 | You're given an array $$$a$$$. You should repeat the following operation $$$k$$$ times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0. | 256 megabytes | /*package whatever //do not write package name here */
import java.util.*;
import java.lang.*;
import java.io.*;
public class GFG {
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int k=sc.nextInt();
int i;
int a[]=new int[n];
for(i=0;i<n;i++){
a[i]=sc.nextInt();
}
Arrays.sort(a);
int j;
int sum=a[0];
for(i=0;i<n;i++){
if(i==0){
System.out.println(a[i]);
}
else if(a[i-1]==a[i]){
continue;
}
else{
int o=a[i]-sum;
System.out.println(o);
sum+=o;
}
k--;
if(k==0){
break;
}
}
while(k>=1){
System.out.println("0");
k--;}
}} | Java | ["3 5\n1 2 3", "4 2\n10 3 5 3"] | 1 second | ["1\n1\n1\n0\n0", "3\n2"] | NoteIn the first sample:In the first step: the array is $$$[1,2,3]$$$, so the minimum non-zero element is 1.In the second step: the array is $$$[0,1,2]$$$, so the minimum non-zero element is 1.In the third step: the array is $$$[0,0,1]$$$, so the minimum non-zero element is 1.In the fourth and fifth step: the array is $$$[0,0,0]$$$, so we printed 0.In the second sample:In the first step: the array is $$$[10,3,5,3]$$$, so the minimum non-zero element is 3.In the second step: the array is $$$[7,0,2,0]$$$, so the minimum non-zero element is 2. | Java 8 | standard input | [
"implementation",
"sortings"
] | 0f100199a720b0fdead5f03e1882f2f3 | The first line contains integers $$$n$$$ and $$$k$$$ $$$(1 \le n,k \le 10^5)$$$, the length of the array and the number of operations you should perform. The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$, the elements of the array. | 1,000 | Print the minimum non-zero element before each operation in a new line. | standard output | |
PASSED | 05c7c25fbbf7aa3da4777dec9501bf2b | train_003.jsonl | 1543934100 | You're given an array $$$a$$$. You should repeat the following operation $$$k$$$ times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0. | 256 megabytes | import java.util.*;
import java.util.Arrays;
public class MyClass {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int k = in.nextInt();
int[] mas = new int[n];
for (int i = 0; i < n; i++) {
mas[i] = in.nextInt();
}
Arrays.sort(mas);
int sumToDelete = 0;
int operations = 0;
for (int i = 0; i < mas.length; i++) {
for (int j = 0; j < k; j++) {
if (mas[i] - sumToDelete > 0) {
operations++;
System.out.println(mas[i] - sumToDelete);
if (operations == k) {
return;
}
sumToDelete += mas[i] - sumToDelete;
} else {
break;
}
}
}
if (operations < k) {
for (int i = 0; i < k - operations; i++) {
System.out.println(0);
}
}
}
}
| Java | ["3 5\n1 2 3", "4 2\n10 3 5 3"] | 1 second | ["1\n1\n1\n0\n0", "3\n2"] | NoteIn the first sample:In the first step: the array is $$$[1,2,3]$$$, so the minimum non-zero element is 1.In the second step: the array is $$$[0,1,2]$$$, so the minimum non-zero element is 1.In the third step: the array is $$$[0,0,1]$$$, so the minimum non-zero element is 1.In the fourth and fifth step: the array is $$$[0,0,0]$$$, so we printed 0.In the second sample:In the first step: the array is $$$[10,3,5,3]$$$, so the minimum non-zero element is 3.In the second step: the array is $$$[7,0,2,0]$$$, so the minimum non-zero element is 2. | Java 8 | standard input | [
"implementation",
"sortings"
] | 0f100199a720b0fdead5f03e1882f2f3 | The first line contains integers $$$n$$$ and $$$k$$$ $$$(1 \le n,k \le 10^5)$$$, the length of the array and the number of operations you should perform. The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$, the elements of the array. | 1,000 | Print the minimum non-zero element before each operation in a new line. | standard output | |
PASSED | 7f29784fdc21a4178af82259e072a4e1 | train_003.jsonl | 1543934100 | You're given an array $$$a$$$. You should repeat the following operation $$$k$$$ times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0. | 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
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int k=sc.nextInt();
long a[]=new long[n];
for(int i=0;i<n;i++){
a[i]=sc.nextLong();
}
Arrays.sort(a);
long b[]=new long[n];
b[0]=0;
//b[1]=b[0]+a[0];
for(int ii=1;ii<n;ii++){
b[ii]=b[ii-1]+a[ii-1];
a[ii]=a[ii]-b[ii];
//System.out.println(a[ii]+"a[ii]");
}
int min=n;
for(int j=0;j<n;j++){
if(a[j]<0){a[j]=0;}
if(a[j]>0){if(min>j){min=j;}}
}
if(min==n){
for(int y=0;y<k;y++){System.out.println(0);}
}else{
//if(k>n-min){
//for(int hh=min;hh<n;hh++){
// System.out.println(a[hh]);
//}
//for(int is=0;is<k-n-min;is++){
// System.out.println(0);
//}
//}else{
for(int h=min;h<min+k;h++){
if(h<n){
if(a[h]==0){for(int id=h;id<n;id++){if((a[id]!=0)||id==n-1){a[h]=a[id];k=k+id-h;h=id;break;}}}
System.out.println(a[h]);}else{System.out.println("0");}
}
//}
}
//System.out.println(a+" "+b);}
// your code goes here
}
} | Java | ["3 5\n1 2 3", "4 2\n10 3 5 3"] | 1 second | ["1\n1\n1\n0\n0", "3\n2"] | NoteIn the first sample:In the first step: the array is $$$[1,2,3]$$$, so the minimum non-zero element is 1.In the second step: the array is $$$[0,1,2]$$$, so the minimum non-zero element is 1.In the third step: the array is $$$[0,0,1]$$$, so the minimum non-zero element is 1.In the fourth and fifth step: the array is $$$[0,0,0]$$$, so we printed 0.In the second sample:In the first step: the array is $$$[10,3,5,3]$$$, so the minimum non-zero element is 3.In the second step: the array is $$$[7,0,2,0]$$$, so the minimum non-zero element is 2. | Java 8 | standard input | [
"implementation",
"sortings"
] | 0f100199a720b0fdead5f03e1882f2f3 | The first line contains integers $$$n$$$ and $$$k$$$ $$$(1 \le n,k \le 10^5)$$$, the length of the array and the number of operations you should perform. The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$, the elements of the array. | 1,000 | Print the minimum non-zero element before each operation in a new line. | standard output | |
PASSED | ee3eb7e0e1e99135a42c9bfd28e981d8 | train_003.jsonl | 1543934100 | You're given an array $$$a$$$. You should repeat the following operation $$$k$$$ times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
//test cases
int n = in.nextInt();
int k = in.nextInt();
int[] arr = new int[n];
for(int i=0 ; i<n ; i++){
arr[i] = in.nextInt();
}
// int min = arr[0];
// int temp = 0 ;
Arrays.sort(arr);
int count = 0;
for(int i=0 ; i< n-1 ; i++){
if(arr[i+1]==arr[i]){
arr[i] = 0;
count++;
}
}
Arrays.sort(arr);
int[] new_arr = new int[n-count];
for (int i = 0; i < n-count; i++) {
new_arr[i] = arr[count + i];
// System.out.print(new_arr[i]+ " ");
}
// System.out.println();
int sum = 0;
for(int i=0 ; i<k ; i++){
if((n-count)>i){
int result = new_arr[i] - sum;
sum = sum + result;
if(result < 0) System.out.println(0);
else System.out.println(result);
}
else{
System.out.println(0);
}
// for(int j=0 ; j< n ; j++){
// if(arr[j]>0){
// sum += arr[j];
// min = (min < arr[j])? min : arr[j];
// // temp = (min > arr[j])? min : arr[j];
// }
// }
// if(sum==0) System.out.println(0);
// else System.out.println(min);
// for(int l=0 ; l<n ; l++){
// if(arr[l]>0) arr[l] -= min;
// }
// min = Integer.MAX_VALUE;
}
}
} | Java | ["3 5\n1 2 3", "4 2\n10 3 5 3"] | 1 second | ["1\n1\n1\n0\n0", "3\n2"] | NoteIn the first sample:In the first step: the array is $$$[1,2,3]$$$, so the minimum non-zero element is 1.In the second step: the array is $$$[0,1,2]$$$, so the minimum non-zero element is 1.In the third step: the array is $$$[0,0,1]$$$, so the minimum non-zero element is 1.In the fourth and fifth step: the array is $$$[0,0,0]$$$, so we printed 0.In the second sample:In the first step: the array is $$$[10,3,5,3]$$$, so the minimum non-zero element is 3.In the second step: the array is $$$[7,0,2,0]$$$, so the minimum non-zero element is 2. | Java 8 | standard input | [
"implementation",
"sortings"
] | 0f100199a720b0fdead5f03e1882f2f3 | The first line contains integers $$$n$$$ and $$$k$$$ $$$(1 \le n,k \le 10^5)$$$, the length of the array and the number of operations you should perform. The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$, the elements of the array. | 1,000 | Print the minimum non-zero element before each operation in a new line. | standard output | |
PASSED | 710c1a73bc06c5e263ca778f7b657cda | train_003.jsonl | 1543934100 | You're given an array $$$a$$$. You should repeat the following operation $$$k$$$ times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0. | 256 megabytes | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n=s.nextInt();
int k=s.nextInt();
ArrayList<Integer> a = new ArrayList<Integer>();
for(int i=0;i<n;i++){
a.add(s.nextInt());
}
Collections.sort(a);
int temp=0;int min=0;
for(int j=0;j<k;j++){
int l=temp;
for(l=temp;l<n;l++){
if(a.get(l)!=min){
System.out.println(a.get(l)-min);
min= a.get(l);
temp=l+1;
break;
}
}
if(l==n){
temp=n;
System.out.println(0);
}
}
}
} | Java | ["3 5\n1 2 3", "4 2\n10 3 5 3"] | 1 second | ["1\n1\n1\n0\n0", "3\n2"] | NoteIn the first sample:In the first step: the array is $$$[1,2,3]$$$, so the minimum non-zero element is 1.In the second step: the array is $$$[0,1,2]$$$, so the minimum non-zero element is 1.In the third step: the array is $$$[0,0,1]$$$, so the minimum non-zero element is 1.In the fourth and fifth step: the array is $$$[0,0,0]$$$, so we printed 0.In the second sample:In the first step: the array is $$$[10,3,5,3]$$$, so the minimum non-zero element is 3.In the second step: the array is $$$[7,0,2,0]$$$, so the minimum non-zero element is 2. | Java 8 | standard input | [
"implementation",
"sortings"
] | 0f100199a720b0fdead5f03e1882f2f3 | The first line contains integers $$$n$$$ and $$$k$$$ $$$(1 \le n,k \le 10^5)$$$, the length of the array and the number of operations you should perform. The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$, the elements of the array. | 1,000 | Print the minimum non-zero element before each operation in a new line. | standard output | |
PASSED | 79609ad046153fbc349333072933eeaa | train_003.jsonl | 1543934100 | You're given an array $$$a$$$. You should repeat the following operation $$$k$$$ times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0. | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
private static FastReader fr = new FastReader();
private static Helper helper = new Helper();
private static StringBuilder result = new StringBuilder();
public static void main(String[] args) {
Task solver = new Task();
solver.solve();
}
static class Task {
public void solve() {
int n = fr.ni(), k = fr.ni();
Long[] arr = new Long[n];
for(int i=0; i<n; i++) arr[i] = fr.nl();
ArrayList<Long> resultList = new ArrayList<>();
Arrays.sort(arr);
long lastElement = -1;
long sum = 0;
for(int i=0; i<n; i++){
if(lastElement != arr[i]){
lastElement = arr[i];
resultList.add(arr[i]-sum);
sum += arr[i]-sum;
}
}
for(int i=0; i<Math.min(resultList.size(), k); i++) result.append(resultList.get(i)).append("\n");
if(k > resultList.size()){
while(k-resultList.size() > 0){
result.append("0\n");
k--;
}
}
System.out.println(result);
}
}
static class Helper{
public long[] tiArr(int n, int si){
long[] arr = new long[n];
for(int i=si; i<n; i++) arr[i] = fr.nl();
return arr;
}
}
static class FastReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
private static PrintWriter pw;
public FastReader() {
reader = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(System.out);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int ni() {
return Integer.parseInt(next());
}
public long nl() {
return Long.parseLong(next());
}
public String rl() {
try {
return reader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
public void print(String str) {
pw.print(str);
pw.flush();
}
}
} | Java | ["3 5\n1 2 3", "4 2\n10 3 5 3"] | 1 second | ["1\n1\n1\n0\n0", "3\n2"] | NoteIn the first sample:In the first step: the array is $$$[1,2,3]$$$, so the minimum non-zero element is 1.In the second step: the array is $$$[0,1,2]$$$, so the minimum non-zero element is 1.In the third step: the array is $$$[0,0,1]$$$, so the minimum non-zero element is 1.In the fourth and fifth step: the array is $$$[0,0,0]$$$, so we printed 0.In the second sample:In the first step: the array is $$$[10,3,5,3]$$$, so the minimum non-zero element is 3.In the second step: the array is $$$[7,0,2,0]$$$, so the minimum non-zero element is 2. | Java 8 | standard input | [
"implementation",
"sortings"
] | 0f100199a720b0fdead5f03e1882f2f3 | The first line contains integers $$$n$$$ and $$$k$$$ $$$(1 \le n,k \le 10^5)$$$, the length of the array and the number of operations you should perform. The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$, the elements of the array. | 1,000 | Print the minimum non-zero element before each operation in a new line. | standard output | |
PASSED | 9f133735b917e6b17096b9c5e08de479 | train_003.jsonl | 1543934100 | You're given an array $$$a$$$. You should repeat the following operation $$$k$$$ times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class pre67
{
public static void main(String args[])
{
Scanner obj = new Scanner(System.in);
int n = obj.nextInt(), k = obj.nextInt(),arr[] = new int[n];
for(int i=0;i<n;i++)
arr[i] = obj.nextInt();
Arrays.sort(arr);
int o = 0,b = 0;
for(int i=0;i<arr.length;i++)
{
b = arr[i];
arr[i] -= o;
o = b;
}
for(int i=0;i<k;i++)
{
if(i<arr.length)
{
if(arr[i]!=0)
System.out.println(arr[i]);
else
k++;
}
else
System.out.println(0);
}
}
}
| Java | ["3 5\n1 2 3", "4 2\n10 3 5 3"] | 1 second | ["1\n1\n1\n0\n0", "3\n2"] | NoteIn the first sample:In the first step: the array is $$$[1,2,3]$$$, so the minimum non-zero element is 1.In the second step: the array is $$$[0,1,2]$$$, so the minimum non-zero element is 1.In the third step: the array is $$$[0,0,1]$$$, so the minimum non-zero element is 1.In the fourth and fifth step: the array is $$$[0,0,0]$$$, so we printed 0.In the second sample:In the first step: the array is $$$[10,3,5,3]$$$, so the minimum non-zero element is 3.In the second step: the array is $$$[7,0,2,0]$$$, so the minimum non-zero element is 2. | Java 8 | standard input | [
"implementation",
"sortings"
] | 0f100199a720b0fdead5f03e1882f2f3 | The first line contains integers $$$n$$$ and $$$k$$$ $$$(1 \le n,k \le 10^5)$$$, the length of the array and the number of operations you should perform. The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$, the elements of the array. | 1,000 | Print the minimum non-zero element before each operation in a new line. | standard output | |
PASSED | 9552b033f89d6d3a4fbc25a43362800c | train_003.jsonl | 1543934100 | You're given an array $$$a$$$. You should repeat the following operation $$$k$$$ times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0. | 256 megabytes | //package codeForces;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;
import javax.swing.Box.Filler;
public class CF1088B {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
int[] c = new int [k];
Arrays.fill(c, 0);
PriorityQueue<Integer> minHeap = new PriorityQueue<Integer>();
for(int i =0;i<n;i++)
{
int a = sc.nextInt();
if(a!=0)
{
minHeap.add(a);
}
}
int count = 0;
int f =0;
while(!minHeap.isEmpty())
{
int a = minHeap.poll()-count;
if(a!=0&&f<k)
{
c[f] = a;
f++;
count+= a;
}
}
for(int i =0;i<k;i++)
{
System.out.println(c[i]);
}
sc.close();
}
}
| Java | ["3 5\n1 2 3", "4 2\n10 3 5 3"] | 1 second | ["1\n1\n1\n0\n0", "3\n2"] | NoteIn the first sample:In the first step: the array is $$$[1,2,3]$$$, so the minimum non-zero element is 1.In the second step: the array is $$$[0,1,2]$$$, so the minimum non-zero element is 1.In the third step: the array is $$$[0,0,1]$$$, so the minimum non-zero element is 1.In the fourth and fifth step: the array is $$$[0,0,0]$$$, so we printed 0.In the second sample:In the first step: the array is $$$[10,3,5,3]$$$, so the minimum non-zero element is 3.In the second step: the array is $$$[7,0,2,0]$$$, so the minimum non-zero element is 2. | Java 8 | standard input | [
"implementation",
"sortings"
] | 0f100199a720b0fdead5f03e1882f2f3 | The first line contains integers $$$n$$$ and $$$k$$$ $$$(1 \le n,k \le 10^5)$$$, the length of the array and the number of operations you should perform. The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$, the elements of the array. | 1,000 | Print the minimum non-zero element before each operation in a new line. | standard output | |
PASSED | 930faa949c4291b4216c9b76040523fc | train_003.jsonl | 1543934100 | You're given an array $$$a$$$. You should repeat the following operation $$$k$$$ times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.Scanner;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author Mufaddal Naya
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
BEhabAndSubtraction solver = new BEhabAndSubtraction();
solver.solve(1, in, out);
out.close();
}
static class BEhabAndSubtraction {
public static int[] radixSort(int[] f) {
int[] to = new int[f.length];
{
int[] b = new int[65537];
for (int i = 0; i < f.length; i++) b[1 + (f[i] & 0xffff)]++;
for (int i = 1; i <= 65536; i++) b[i] += b[i - 1];
for (int i = 0; i < f.length; i++) to[b[f[i] & 0xffff]++] = f[i];
int[] d = f;
f = to;
to = d;
}
{
int[] b = new int[65537];
for (int i = 0; i < f.length; i++) b[1 + (f[i] >>> 16)]++;
for (int i = 1; i <= 65536; i++) b[i] += b[i - 1];
for (int i = 0; i < f.length; i++) to[b[f[i] >>> 16]++] = f[i];
int[] d = f;
f = to;
to = d;
}
return f;
}
public void solve(int testNumber, Scanner in, PrintWriter out) {
int n = in.nextInt();
int k = in.nextInt();
int a[] = new int[n];
for (int i = 0; i < n; i++) a[i] = in.nextInt();
a = radixSort(a);
int j = 0;
for (j = 0; j < n; j++) if (a[j] != 0) break;
long sum = 0;
for (int i = 1; i <= k; i++) {
if (j == n) {
System.out.println("0");
continue;
}
System.out.println(a[j]);
sum += a[j];
j++;
if (j == n) continue;
while (a[j] - sum == 0) {
if (j == n - 1) break;
j++;
}
a[j] -= sum;
}
}
}
}
| Java | ["3 5\n1 2 3", "4 2\n10 3 5 3"] | 1 second | ["1\n1\n1\n0\n0", "3\n2"] | NoteIn the first sample:In the first step: the array is $$$[1,2,3]$$$, so the minimum non-zero element is 1.In the second step: the array is $$$[0,1,2]$$$, so the minimum non-zero element is 1.In the third step: the array is $$$[0,0,1]$$$, so the minimum non-zero element is 1.In the fourth and fifth step: the array is $$$[0,0,0]$$$, so we printed 0.In the second sample:In the first step: the array is $$$[10,3,5,3]$$$, so the minimum non-zero element is 3.In the second step: the array is $$$[7,0,2,0]$$$, so the minimum non-zero element is 2. | Java 8 | standard input | [
"implementation",
"sortings"
] | 0f100199a720b0fdead5f03e1882f2f3 | The first line contains integers $$$n$$$ and $$$k$$$ $$$(1 \le n,k \le 10^5)$$$, the length of the array and the number of operations you should perform. The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$, the elements of the array. | 1,000 | Print the minimum non-zero element before each operation in a new line. | standard output | |
PASSED | 5878d50645c8eb7dbf84043bcee016f4 | train_003.jsonl | 1543934100 | You're given an array $$$a$$$. You should repeat the following operation $$$k$$$ times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0. | 256 megabytes | import java.util.*;
import java.io.*;
import java.lang.*;
public class programA {
public static void merge(int arr[], int l, int m, int r)
{
// Find sizes of two subarrays to be merged
int n1 = m - l + 1;
int n2 = r - m;
/* Create temp arrays */
int L[] = new int [n1];
int R[] = new int [n2];
/*Copy data to temp arrays*/
for (int i=0; i<n1; ++i)
L[i] = arr[l + i];
for (int j=0; j<n2; ++j)
R[j] = arr[m + 1+ j];
/* Merge the temp arrays */
// Initial indexes of first and second subarrays
int i = 0, j = 0;
// Initial index of merged subarry array
int k = l;
while (i < n1 && j < n2)
{
if (L[i] <= R[j])
{
arr[k] = L[i];
i++;
}
else
{
arr[k] = R[j];
j++;
}
k++;
}
/* Copy remaining elements of L[] if any */
while (i < n1)
{
arr[k] = L[i];
i++;
k++;
}
/* Copy remaining elements of R[] if any */
while (j < n2)
{
arr[k] = R[j];
j++;
k++;
}
}
// Main function that sorts arr[l..r] using
// merge()
public static void sort(int arr[], int l, int r)
{
if (l < r)
{
// Find the middle point
int m = (l+r)/2;
// Sort first and second halves
sort(arr, l, m);
sort(arr , m+1, r);
// Merge the sorted halves
merge(arr, l, m, r);
}
}
public static void main(String[] args)throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken());
int arr[] = new int[n+1];
int brr[] = new int[1000000];
st = new StringTokenizer(br.readLine());
for(int i =1;i<=n;i++) {
arr[i] = Integer.parseInt(st.nextToken());
}
sort(arr, 0, n);
int j =0;
for(int i =1;i<=n;i++) {
if (arr[i]!=arr[i-1]) {
brr[j]=arr[i]-arr[i-1];
j++;
}
}
for (int i=0;i<k;i++) {
System.out.println(brr[i]);
}
}
}
| Java | ["3 5\n1 2 3", "4 2\n10 3 5 3"] | 1 second | ["1\n1\n1\n0\n0", "3\n2"] | NoteIn the first sample:In the first step: the array is $$$[1,2,3]$$$, so the minimum non-zero element is 1.In the second step: the array is $$$[0,1,2]$$$, so the minimum non-zero element is 1.In the third step: the array is $$$[0,0,1]$$$, so the minimum non-zero element is 1.In the fourth and fifth step: the array is $$$[0,0,0]$$$, so we printed 0.In the second sample:In the first step: the array is $$$[10,3,5,3]$$$, so the minimum non-zero element is 3.In the second step: the array is $$$[7,0,2,0]$$$, so the minimum non-zero element is 2. | Java 8 | standard input | [
"implementation",
"sortings"
] | 0f100199a720b0fdead5f03e1882f2f3 | The first line contains integers $$$n$$$ and $$$k$$$ $$$(1 \le n,k \le 10^5)$$$, the length of the array and the number of operations you should perform. The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$, the elements of the array. | 1,000 | Print the minimum non-zero element before each operation in a new line. | standard output | |
PASSED | 6411f2641c736bf4bb24b6301d2f3ab5 | train_003.jsonl | 1543934100 | You're given an array $$$a$$$. You should repeat the following operation $$$k$$$ times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0. | 256 megabytes | import java.awt.font.ShapeGraphicAttribute;
import java.nio.channels.ShutdownChannelGroupException;
import java.util.*;
public class Mainc {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++)
arr[i] = sc.nextInt();
Arrays.sort(arr);
// System.out.println(Arrays.toString(arr));
int sum = 0;
int min = Math.min(n, k);
int c = 0;
for (int i = 0; i < n && k > 0; i++) {
if ((arr[i] - sum) != 0) {
System.out.println(arr[i] - sum);
sum += arr[i] - sum;
k--;
}
}
for (int i = 0; i < k; i++)
System.out.println(0);
}
} | Java | ["3 5\n1 2 3", "4 2\n10 3 5 3"] | 1 second | ["1\n1\n1\n0\n0", "3\n2"] | NoteIn the first sample:In the first step: the array is $$$[1,2,3]$$$, so the minimum non-zero element is 1.In the second step: the array is $$$[0,1,2]$$$, so the minimum non-zero element is 1.In the third step: the array is $$$[0,0,1]$$$, so the minimum non-zero element is 1.In the fourth and fifth step: the array is $$$[0,0,0]$$$, so we printed 0.In the second sample:In the first step: the array is $$$[10,3,5,3]$$$, so the minimum non-zero element is 3.In the second step: the array is $$$[7,0,2,0]$$$, so the minimum non-zero element is 2. | Java 8 | standard input | [
"implementation",
"sortings"
] | 0f100199a720b0fdead5f03e1882f2f3 | The first line contains integers $$$n$$$ and $$$k$$$ $$$(1 \le n,k \le 10^5)$$$, the length of the array and the number of operations you should perform. The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$, the elements of the array. | 1,000 | Print the minimum non-zero element before each operation in a new line. | standard output | |
PASSED | 18d1ba94ca8bd081dabf3c88f98c39ba | train_003.jsonl | 1543934100 | You're given an array $$$a$$$. You should repeat the following operation $$$k$$$ times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0. | 256 megabytes | import java.io.*;
import java.util.*;
public class tr1 {
static PrintWriter out;
static StringBuilder sb;
static int inf = (int) 1e9;
static int mod = (int) 1e9 + 7;
static int[] si;
static ArrayList<Integer> primes;
static HashSet<Integer> pr;
static int n, k, m;
static boolean[] in;
static HashMap<Integer, Integer> factors;
static HashSet<Integer> f;
static long[] fac;
static int[] l, r;
static int[][][] memo;
static int[] a;
static ArrayList<Integer>[] ad;
static HashMap<Integer, Integer> hm;
static pair[] ed;
static ArrayList<Integer>[] np;
static TreeMap<pair, Integer> tm;
static int[] ans;
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
out = new PrintWriter(System.out);
int n=sc.nextInt();
int k=sc.nextInt();
Long []a=new Long [n];
long sum=0;
for(int i=0;i<n;i++)
a[i]=sc.nextLong();
Arrays.sort(a);
int idx=0;
for(int i=0;i<k;i++) {
if(idx==n)
out.println(0);
else {
while(idx<n && a[idx]-sum<=0)
idx++;
if(idx<n) {
out.println((a[idx]-sum));
sum+=a[idx]-sum;
}
else
out.println(0);
}
}
out.flush();
}
static int c = 0;
static boolean ff;
static Queue<StringBuilder> sq;
static void sol(int i) {
// System.out.println(i+" i");
if (i == 0) {
if (ff) {
sol(i + 1);
}
} else if (i == n) {
sb = new StringBuilder();
for (int l : ans)
sb.append(l + "");
c++;
// System.out.println(c);
sq.add(sb);
if (c == k)
ff = false;
} else {
for (int y = 0; y < np[i].size(); y++) {
ans[np[i].get(y)] = 1;
if (ff) {
sol(i + 1);
ans[np[i].get(y)] = 0;
}
if (!ff)
return;
}
}
}
static class pair implements Comparable<pair> {
int f;
int t;
int idx;
pair(int f, int t) {
this.t = t;
this.f = f;
}
public String toString() {
return f + " " + t + " " + idx;
}
@Override
public int compareTo(pair o) {
if (f == o.f)
return o.t - t;
return f - o.f;
}
}
public static int dp(int i, int val, int st) {
if (i == n - 1) {
int y = 0;
if ((val + a[i]) % 3 == 0)
y++;
// System.out.println((val+a[i])+" "+y);
return y;
}
if (memo[i][st][val] != -1) {
return memo[i][st][val];
}
int y = 0;
if ((val + a[i]) % 3 == 0)
y++;
int take = y + dp(i + 1, 0, 1);
int leave = dp(i + 1, (val + a[i]) % 3, 0);
// System.out.println(i+" "+st+" "+take+" "+leave);
return memo[i][st][val] = Math.max(take, leave);
}
public int[] merge(int[] d, int st, int e) {
if (st > e)
return null;
if (e == st) {
int[] ans = { d[e] };
return ans;
}
int mid = (st + e) / 2;
int[] ans = new int[e - st + 1];
int[] ll = merge(d, st, mid);
int[] rr = merge(d, mid + 1, e);
if (ll == null)
return rr;
if (rr == null)
return ll;
int iver = 0;
int idxl = 0;
int idxr = 0;
for (int i = st; i <= e; i++) {
if (ll[idxl] < rr[idxr]) {
}
}
return ans;
}
public static class pair1 implements Comparable<pair1> {
int a;
int idx;
pair1(int a, int i) {
this.a = a;
idx = i;
}
public String toString() {
return a + " " + idx;
}
@Override
public int compareTo(pair1 o) {
return o.a - a;
}
}
public static class pair2 implements Comparable<pair2> {
int a;
int idx;
pair2(int a, int i) {
this.a = a;
idx = i;
}
public String toString() {
return a + " " + idx;
}
@Override
public int compareTo(pair2 o) {
// TODO Auto-generated method stub
return idx - o.idx;
}
}
static int inver(long x) {
int a = (int) x;
int e = (mod - 2);
int res = 1;
while (e > 0) {
if ((e & 1) == 1) {
// System.out.println(res*a);
res = (int) ((1l * res * a) % mod);
}
a = (int) ((1l * a * a) % mod);
e >>= 1;
}
// out.println(res+" "+x);
return res % mod;
}
static int atMostSum(int arr[], int n, int k) {
int sum = 0;
int cnt = 0, maxcnt = 0;
for (int i = 0; i < n; i++) {
// If adding current element doesn't
// cross limit add it to current window
if ((sum + arr[i]) <= k) {
sum += arr[i];
cnt++;
}
// Else, remove first element of current
// window and add the current element
else if (sum != 0) {
sum = sum - arr[i - cnt] + arr[i];
}
// keep track of max length.
maxcnt = Math.max(cnt, maxcnt);
}
return maxcnt;
}
public static int[] longestSubarray(int[] inp) {
// array containing prefix sums up to a certain index i
int[] p = new int[inp.length];
p[0] = inp[0];
for (int i = 1; i < inp.length; i++) {
p[i] = p[i - 1] + inp[i];
}
// array Q from the description below
int[] q = new int[inp.length];
q[inp.length - 1] = p[inp.length - 1];
for (int i = inp.length - 2; i >= 0; i--) {
q[i] = Math.max(q[i + 1], p[i]);
}
int a = 0;
int b = 0;
int maxLen = 0;
int curr;
int[] res = new int[] { -1, -1 };
while (b < inp.length) {
curr = a > 0 ? q[b] - p[a - 1] : q[b];
if (curr >= 0) {
if (b - a > maxLen) {
maxLen = b - a;
res = new int[] { a, b };
}
b++;
} else {
a++;
}
}
return res;
}
static void factor(int n) {
if (si[n] == n) {
f.add(n);
return;
}
f.add(si[n]);
factor(n / si[n]);
}
static void seive() {
si = new int[1000001];
primes = new ArrayList<>();
int N = 1000001;
pr = new HashSet<>();
si[1] = 1;
for (int i = 2; i < N; i++) {
if (si[i] == 0) {
si[i] = i;
primes.add(i);
pr.add(i);
}
for (int j = 0; j < primes.size() && primes.get(j) <= si[i] && (i * primes.get(j)) < N; j++)
si[primes.get(j) * i] = primes.get(j);
}
}
static public class SegmentTree { // 1-based DS, OOP
int N; // the number of elements in the array as a power of 2 (i.e. after padding)
int[] array, sTree, lazy;
SegmentTree(int[] in) {
array = in;
N = in.length - 1;
sTree = new int[N << 1]; // no. of nodes = 2*N - 1, we add one to cross out index zero
lazy = new int[N << 1];
build(1, 1, N);
}
public String toString() {
return Arrays.toString(sTree);
}
void build(int node, int b, int e) // O(n)
{
if (b == e)
sTree[node] = array[b];
else {
int mid = b + e >> 1;
build(node << 1, b, mid);
build(node << 1 | 1, mid + 1, e);
sTree[node] = gcd(sTree[node << 1], sTree[node << 1 | 1]);
}
}
void update_point(int index, int val) // O(log n)
{
index += N - 1;
sTree[index] += val;
while (index > 1) {
index >>= 1;
sTree[index] = sTree[index << 1] + sTree[index << 1 | 1];
}
}
void update_range(int i, int j, int val) // O(log n)
{
update_range(1, 1, N, i, j, val);
}
void update_range(int node, int b, int e, int i, int j, int val) {
if (i > e || j < b)
return;
if (b >= i && e <= j) {
sTree[node] += (e - b + 1) * val;
lazy[node] += val;
} else {
int mid = b + e >> 1;
propagate(node, b, mid, e);
update_range(node << 1, b, mid, i, j, val);
update_range(node << 1 | 1, mid + 1, e, i, j, val);
sTree[node] = sTree[node << 1] + sTree[node << 1 | 1];
}
}
void propagate(int node, int b, int mid, int e) {
lazy[node << 1] += lazy[node];
lazy[node << 1 | 1] += lazy[node];
sTree[node << 1] += (mid - b + 1) * lazy[node];
sTree[node << 1 | 1] += (e - mid) * lazy[node];
lazy[node] = 0;
}
int query(int i, int j) {
return query(1, 1, N, i, j);
}
int query(int node, int b, int e, int i, int j) // O(log n)
{
if (i > e || j < b)
return 0;
if (b >= i && e <= j)
return sTree[node];
int mid = b + e >> 1;
// propagate(node, b, mid, e);
int q1 = query(node << 1, b, mid, i, j);
int q2 = query(node << 1 | 1, mid + 1, e, i, j);
return gcd(q1, q2);
}
}
static int gcd(int a, int b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
static class unionfind {
int[] p;
int[] size;
unionfind(int n) {
p = new int[n];
size = new int[n];
for (int i = 0; i < n; i++) {
p[i] = i;
}
Arrays.fill(size, 1);
}
int findSet(int v) {
if (v == p[v])
return v;
return p[v] = findSet(p[v]);
}
boolean sameSet(int a, int b) {
a = findSet(a);
b = findSet(b);
if (a == b)
return true;
return false;
}
int max() {
int max = 0;
for (int i = 0; i < size.length; i++)
if (size[i] > max)
max = size[i];
return max;
}
void combine(int a, int b) {
a = findSet(a);
b = findSet(b);
if (a == b)
return;
if (size[a] > size[b]) {
p[b] = a;
size[a] += size[b];
} else {
p[a] = b;
size[b] += size[a];
}
}
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream system) {
br = new BufferedReader(new InputStreamReader(system));
}
public Scanner(String file) throws Exception {
br = new BufferedReader(new FileReader(file));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public String nextLine() throws IOException {
return br.readLine();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public char nextChar() throws IOException {
return next().charAt(0);
}
public Long nextLong() throws IOException {
return Long.parseLong(next());
}
public boolean ready() throws IOException {
return br.ready();
}
public void waitForInput() throws InterruptedException {
Thread.sleep(3000);
}
}
} | Java | ["3 5\n1 2 3", "4 2\n10 3 5 3"] | 1 second | ["1\n1\n1\n0\n0", "3\n2"] | NoteIn the first sample:In the first step: the array is $$$[1,2,3]$$$, so the minimum non-zero element is 1.In the second step: the array is $$$[0,1,2]$$$, so the minimum non-zero element is 1.In the third step: the array is $$$[0,0,1]$$$, so the minimum non-zero element is 1.In the fourth and fifth step: the array is $$$[0,0,0]$$$, so we printed 0.In the second sample:In the first step: the array is $$$[10,3,5,3]$$$, so the minimum non-zero element is 3.In the second step: the array is $$$[7,0,2,0]$$$, so the minimum non-zero element is 2. | Java 8 | standard input | [
"implementation",
"sortings"
] | 0f100199a720b0fdead5f03e1882f2f3 | The first line contains integers $$$n$$$ and $$$k$$$ $$$(1 \le n,k \le 10^5)$$$, the length of the array and the number of operations you should perform. The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$, the elements of the array. | 1,000 | Print the minimum non-zero element before each operation in a new line. | standard output | |
PASSED | 1a5a9287b6f61add64428b58c4a4ecba | train_003.jsonl | 1543934100 | You're given an array $$$a$$$. You should repeat the following operation $$$k$$$ times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0. | 256 megabytes | import java.util.*;
public class main {
public static void main(String[] args) {
int n=0,k,count=0;
Scanner sc=new Scanner(System.in);
n=sc.nextInt();
int[]arr=new int[100001];
k=sc.nextInt();
arr[0]=0;
for(int i=1;i<=n;i++)
{
arr[i]=sc.nextInt();
}
Arrays.sort(arr,1,n+1);
for(int i=1;;i++)
{
if(i>n)
{
System.out.println(0);
count++;
}
else
{
if(arr[i]!=arr[i-1])
{
System.out.println(arr[i]-arr[i-1]);
count++;
}
}
if(count==k)break;
}
}
}
| Java | ["3 5\n1 2 3", "4 2\n10 3 5 3"] | 1 second | ["1\n1\n1\n0\n0", "3\n2"] | NoteIn the first sample:In the first step: the array is $$$[1,2,3]$$$, so the minimum non-zero element is 1.In the second step: the array is $$$[0,1,2]$$$, so the minimum non-zero element is 1.In the third step: the array is $$$[0,0,1]$$$, so the minimum non-zero element is 1.In the fourth and fifth step: the array is $$$[0,0,0]$$$, so we printed 0.In the second sample:In the first step: the array is $$$[10,3,5,3]$$$, so the minimum non-zero element is 3.In the second step: the array is $$$[7,0,2,0]$$$, so the minimum non-zero element is 2. | Java 8 | standard input | [
"implementation",
"sortings"
] | 0f100199a720b0fdead5f03e1882f2f3 | The first line contains integers $$$n$$$ and $$$k$$$ $$$(1 \le n,k \le 10^5)$$$, the length of the array and the number of operations you should perform. The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$, the elements of the array. | 1,000 | Print the minimum non-zero element before each operation in a new line. | standard output | |
PASSED | 2e672ed4bfc555d664e52700c543fbe2 | train_003.jsonl | 1543934100 | You're given an array $$$a$$$. You should repeat the following operation $$$k$$$ times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0. | 256 megabytes | import java.util.*;
public class contest4{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
int k=sc.nextInt();
TreeSet<Integer> al=new TreeSet<Integer>();
int a[]=new int[n];
for(int i=0;i<n;i++)
a[i]=sc.nextInt();
Arrays.sort(a);
int sum=0;
for(int i=0;i<k;i++)
{
if(i<n)
{
int t=a[i]-sum;
if(t>0)
{
System.out.println(a[i]-sum);
sum=sum+(a[i]-sum);
}
else
k++;
}
else
System.out.println("0");
}
boolean flag=false;
}
} | Java | ["3 5\n1 2 3", "4 2\n10 3 5 3"] | 1 second | ["1\n1\n1\n0\n0", "3\n2"] | NoteIn the first sample:In the first step: the array is $$$[1,2,3]$$$, so the minimum non-zero element is 1.In the second step: the array is $$$[0,1,2]$$$, so the minimum non-zero element is 1.In the third step: the array is $$$[0,0,1]$$$, so the minimum non-zero element is 1.In the fourth and fifth step: the array is $$$[0,0,0]$$$, so we printed 0.In the second sample:In the first step: the array is $$$[10,3,5,3]$$$, so the minimum non-zero element is 3.In the second step: the array is $$$[7,0,2,0]$$$, so the minimum non-zero element is 2. | Java 8 | standard input | [
"implementation",
"sortings"
] | 0f100199a720b0fdead5f03e1882f2f3 | The first line contains integers $$$n$$$ and $$$k$$$ $$$(1 \le n,k \le 10^5)$$$, the length of the array and the number of operations you should perform. The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$, the elements of the array. | 1,000 | Print the minimum non-zero element before each operation in a new line. | standard output | |
PASSED | cb559798bf3c0a618f40919c111194ac | train_003.jsonl | 1543934100 | You're given an array $$$a$$$. You should repeat the following operation $$$k$$$ times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class EhabAndSub {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int k = input.nextInt();
int arr[] = new int[n];
for (int i = 0; i < n; i++){
arr[i] = input.nextInt();
}
Arrays.sort(arr);
boolean first = true;
int lnz = 0;
int slnz = 0;
int times = 0;
for (int i = 0; i < n; i++){
if (arr[i] != 0 && first){
first = false;
lnz = arr[i];
slnz += lnz;
times++;
System.out.println(lnz);
} else if (arr[i] != 0 && first == false){
if (0 != arr[i] - slnz){
lnz = arr[i] - slnz;
slnz += lnz;
if (times != k){
System.out.println(lnz);
times++;
} else {
break;
}
}
}
}
while (times != k){
System.out.println("0");
times++;
}
}
}
| Java | ["3 5\n1 2 3", "4 2\n10 3 5 3"] | 1 second | ["1\n1\n1\n0\n0", "3\n2"] | NoteIn the first sample:In the first step: the array is $$$[1,2,3]$$$, so the minimum non-zero element is 1.In the second step: the array is $$$[0,1,2]$$$, so the minimum non-zero element is 1.In the third step: the array is $$$[0,0,1]$$$, so the minimum non-zero element is 1.In the fourth and fifth step: the array is $$$[0,0,0]$$$, so we printed 0.In the second sample:In the first step: the array is $$$[10,3,5,3]$$$, so the minimum non-zero element is 3.In the second step: the array is $$$[7,0,2,0]$$$, so the minimum non-zero element is 2. | Java 8 | standard input | [
"implementation",
"sortings"
] | 0f100199a720b0fdead5f03e1882f2f3 | The first line contains integers $$$n$$$ and $$$k$$$ $$$(1 \le n,k \le 10^5)$$$, the length of the array and the number of operations you should perform. The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$, the elements of the array. | 1,000 | Print the minimum non-zero element before each operation in a new line. | standard output | |
PASSED | d2d8dbe7ed5a8e28a889e6e4ad46cbcc | train_003.jsonl | 1543934100 | You're given an array $$$a$$$. You should repeat the following operation $$$k$$$ times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0. | 256 megabytes | import java.io.BufferedReader;
import java.lang.Math;
import java.io.InputStreamReader;
import java.util.Arrays;
public class b{
public static void main(String[] args)throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String c[] = br.readLine().split(" ");
int n = Integer.parseInt(c[0]);
int k = Integer.parseInt(c[1]);
String v[] = br.readLine().split(" ");
int ve[] = new int[n];
for(int i = 0; i<n;i++){
ve[i] = Integer.parseInt(v[i]);
}
Arrays.sort(ve);
long u = 0;
for(int i = 0; i<n && k>0;i++){
if(ve[i]-u>0){
System.out.println(ve[i]-u);
u+=ve[i]-u;
k--;
}
}
while(k-->0){
System.out.println(0);
}
}
}
| Java | ["3 5\n1 2 3", "4 2\n10 3 5 3"] | 1 second | ["1\n1\n1\n0\n0", "3\n2"] | NoteIn the first sample:In the first step: the array is $$$[1,2,3]$$$, so the minimum non-zero element is 1.In the second step: the array is $$$[0,1,2]$$$, so the minimum non-zero element is 1.In the third step: the array is $$$[0,0,1]$$$, so the minimum non-zero element is 1.In the fourth and fifth step: the array is $$$[0,0,0]$$$, so we printed 0.In the second sample:In the first step: the array is $$$[10,3,5,3]$$$, so the minimum non-zero element is 3.In the second step: the array is $$$[7,0,2,0]$$$, so the minimum non-zero element is 2. | Java 8 | standard input | [
"implementation",
"sortings"
] | 0f100199a720b0fdead5f03e1882f2f3 | The first line contains integers $$$n$$$ and $$$k$$$ $$$(1 \le n,k \le 10^5)$$$, the length of the array and the number of operations you should perform. The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$, the elements of the array. | 1,000 | Print the minimum non-zero element before each operation in a new line. | standard output | |
PASSED | 0e466db7b528cbf6157f917df9d0bce1 | train_003.jsonl | 1543934100 | You're given an array $$$a$$$. You should repeat the following operation $$$k$$$ times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0. | 256 megabytes | import java.io.OutputStream;
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.util.Arrays;
/*
Testing fast input/ouput
*/
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);
a solver = new a();
solver.solve(1, in, out);
out.close();
}
static class a {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.nextInt();
int k = in.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; ++i) {
a[i] = in.nextInt();
}
Arrays.sort(a);
long u = 0;
for (int i = 0; i < n && k>0; i++) {
if(a[i]-u>0){
out.println(a[i]-u);
u+=a[i]-u;
k--;
}
}
while(k-->0){
out.println(0);
}
}
}
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());
}
}
} | Java | ["3 5\n1 2 3", "4 2\n10 3 5 3"] | 1 second | ["1\n1\n1\n0\n0", "3\n2"] | NoteIn the first sample:In the first step: the array is $$$[1,2,3]$$$, so the minimum non-zero element is 1.In the second step: the array is $$$[0,1,2]$$$, so the minimum non-zero element is 1.In the third step: the array is $$$[0,0,1]$$$, so the minimum non-zero element is 1.In the fourth and fifth step: the array is $$$[0,0,0]$$$, so we printed 0.In the second sample:In the first step: the array is $$$[10,3,5,3]$$$, so the minimum non-zero element is 3.In the second step: the array is $$$[7,0,2,0]$$$, so the minimum non-zero element is 2. | Java 8 | standard input | [
"implementation",
"sortings"
] | 0f100199a720b0fdead5f03e1882f2f3 | The first line contains integers $$$n$$$ and $$$k$$$ $$$(1 \le n,k \le 10^5)$$$, the length of the array and the number of operations you should perform. The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$, the elements of the array. | 1,000 | Print the minimum non-zero element before each operation in a new line. | standard output | |
PASSED | c943c000666398321ef1d99ba7aa98d7 | train_003.jsonl | 1543934100 | You're given an array $$$a$$$. You should repeat the following operation $$$k$$$ times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0. | 256 megabytes | import java.io.BufferedReader;
import java.lang.Math;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
public class problem{
public static void main(String[] args)throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
OutputStream outputStream = System.out;
PrintWriter out = new PrintWriter(outputStream);
String c[] = br.readLine().split(" ");
int n = Integer.parseInt(c[0]);
int k = Integer.parseInt(c[1]);
String v[] = br.readLine().split(" ");
int ve[] = new int[n];
for(int i = 0; i<n;i++){
ve[i] = Integer.parseInt(v[i]);
}
Arrays.sort(ve);
long u = 0;
for(int i = 0; i<n && k>0;i++){
if(ve[i]-u>0){
out.println(ve[i]-u);
u+=ve[i]-u;
k--;
}
}
while(k-->0){
out.println(0);
}
out.close();
}
} | Java | ["3 5\n1 2 3", "4 2\n10 3 5 3"] | 1 second | ["1\n1\n1\n0\n0", "3\n2"] | NoteIn the first sample:In the first step: the array is $$$[1,2,3]$$$, so the minimum non-zero element is 1.In the second step: the array is $$$[0,1,2]$$$, so the minimum non-zero element is 1.In the third step: the array is $$$[0,0,1]$$$, so the minimum non-zero element is 1.In the fourth and fifth step: the array is $$$[0,0,0]$$$, so we printed 0.In the second sample:In the first step: the array is $$$[10,3,5,3]$$$, so the minimum non-zero element is 3.In the second step: the array is $$$[7,0,2,0]$$$, so the minimum non-zero element is 2. | Java 8 | standard input | [
"implementation",
"sortings"
] | 0f100199a720b0fdead5f03e1882f2f3 | The first line contains integers $$$n$$$ and $$$k$$$ $$$(1 \le n,k \le 10^5)$$$, the length of the array and the number of operations you should perform. The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$, the elements of the array. | 1,000 | Print the minimum non-zero element before each operation in a new line. | standard output | |
PASSED | 0b30ff0dc788384a5166ae8a8b193c7d | train_003.jsonl | 1543934100 | You're given an array $$$a$$$. You should repeat the following operation $$$k$$$ times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0. | 256 megabytes | import java.io.BufferedReader;
import java.lang.Math;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
public class problem{
public static void main(String[] args)throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
OutputStream outputStream = System.out;
PrintWriter o = new PrintWriter(outputStream);
ans s = new ans();
s.a(br,o);
o.close();
}
static class ans{
public void a(BufferedReader br,PrintWriter o)throws Exception{
String c[] = br.readLine().split(" ");
int n = Integer.parseInt(c[0]);
int k = Integer.parseInt(c[1]);
String v[] = br.readLine().split(" ");
int ve[] = new int[n];
for(int i = 0; i<n;i++){
ve[i] = Integer.parseInt(v[i]);
}
Arrays.sort(ve);
long u = 0;
for(int i = 0; i<n && k>0;i++){
if(ve[i]-u>0){
o.println(ve[i]-u);
u+=ve[i]-u;
k--;
}
}
while(k-->0){
o.println(0);
}
}
}
} | Java | ["3 5\n1 2 3", "4 2\n10 3 5 3"] | 1 second | ["1\n1\n1\n0\n0", "3\n2"] | NoteIn the first sample:In the first step: the array is $$$[1,2,3]$$$, so the minimum non-zero element is 1.In the second step: the array is $$$[0,1,2]$$$, so the minimum non-zero element is 1.In the third step: the array is $$$[0,0,1]$$$, so the minimum non-zero element is 1.In the fourth and fifth step: the array is $$$[0,0,0]$$$, so we printed 0.In the second sample:In the first step: the array is $$$[10,3,5,3]$$$, so the minimum non-zero element is 3.In the second step: the array is $$$[7,0,2,0]$$$, so the minimum non-zero element is 2. | Java 8 | standard input | [
"implementation",
"sortings"
] | 0f100199a720b0fdead5f03e1882f2f3 | The first line contains integers $$$n$$$ and $$$k$$$ $$$(1 \le n,k \le 10^5)$$$, the length of the array and the number of operations you should perform. The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$, the elements of the array. | 1,000 | Print the minimum non-zero element before each operation in a new line. | standard output | |
PASSED | 8d5e99ef4ae0d78bbff47d8a851fc453 | train_003.jsonl | 1543934100 | You're given an array $$$a$$$. You should repeat the following operation $$$k$$$ times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
public class problem{
public static void main(String[] args)throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
OutputStream outputStream = System.out;
PrintWriter out = new PrintWriter(outputStream);
String c[] = br.readLine().split(" ");
int n = Integer.parseInt(c[0]);
int k = Integer.parseInt(c[1]);
String v[] = br.readLine().split(" ");
int ve[] = new int[n];
for(int i = 0; i<n;i++){
ve[i] = Integer.parseInt(v[i]);
}
Arrays.sort(ve);
long u = 0;
for(int i = 0; i<n && k>0;i++){
if(ve[i]-u>0){
out.println(ve[i]-u);
u+=ve[i]-u;
k--;
}
}
while(k-->0){
out.println(0);
}
out.close();
}
} | Java | ["3 5\n1 2 3", "4 2\n10 3 5 3"] | 1 second | ["1\n1\n1\n0\n0", "3\n2"] | NoteIn the first sample:In the first step: the array is $$$[1,2,3]$$$, so the minimum non-zero element is 1.In the second step: the array is $$$[0,1,2]$$$, so the minimum non-zero element is 1.In the third step: the array is $$$[0,0,1]$$$, so the minimum non-zero element is 1.In the fourth and fifth step: the array is $$$[0,0,0]$$$, so we printed 0.In the second sample:In the first step: the array is $$$[10,3,5,3]$$$, so the minimum non-zero element is 3.In the second step: the array is $$$[7,0,2,0]$$$, so the minimum non-zero element is 2. | Java 8 | standard input | [
"implementation",
"sortings"
] | 0f100199a720b0fdead5f03e1882f2f3 | The first line contains integers $$$n$$$ and $$$k$$$ $$$(1 \le n,k \le 10^5)$$$, the length of the array and the number of operations you should perform. The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$, the elements of the array. | 1,000 | Print the minimum non-zero element before each operation in a new line. | standard output | |
PASSED | 3abdc8decd88c2a53a79d6d9d99019c6 | train_003.jsonl | 1543934100 | You're given an array $$$a$$$. You should repeat the following operation $$$k$$$ times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0. | 256 megabytes | import java.io.OutputStream;
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.util.Arrays;
/*
Testing fast input/ouput
*/
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);
a solver = new a();
solver.solve(1, in, out);
out.close();
}
static class a {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.nextInt();
int k = in.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; ++i) {
a[i] = in.nextInt();
}
Arrays.sort(a);
long u = 0;
for (int i = 0; i < n && k>0; i++) {
if(a[i]-u>0){
out.println(a[i]-u);
u+=a[i]-u;
k--;
}
}
while(k-->0){
out.println(0);
}
}
}
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());
}
}
}
| Java | ["3 5\n1 2 3", "4 2\n10 3 5 3"] | 1 second | ["1\n1\n1\n0\n0", "3\n2"] | NoteIn the first sample:In the first step: the array is $$$[1,2,3]$$$, so the minimum non-zero element is 1.In the second step: the array is $$$[0,1,2]$$$, so the minimum non-zero element is 1.In the third step: the array is $$$[0,0,1]$$$, so the minimum non-zero element is 1.In the fourth and fifth step: the array is $$$[0,0,0]$$$, so we printed 0.In the second sample:In the first step: the array is $$$[10,3,5,3]$$$, so the minimum non-zero element is 3.In the second step: the array is $$$[7,0,2,0]$$$, so the minimum non-zero element is 2. | Java 8 | standard input | [
"implementation",
"sortings"
] | 0f100199a720b0fdead5f03e1882f2f3 | The first line contains integers $$$n$$$ and $$$k$$$ $$$(1 \le n,k \le 10^5)$$$, the length of the array and the number of operations you should perform. The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$, the elements of the array. | 1,000 | Print the minimum non-zero element before each operation in a new line. | standard output | |
PASSED | 3dc249ae935351cf9f1535246b88049a | train_003.jsonl | 1543934100 | You're given an array $$$a$$$. You should repeat the following operation $$$k$$$ times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.TreeSet;
public class subtraction {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String[] l1 = in.readLine().split(" ");
int n = Integer.parseInt(l1[0]);
int k = Integer.parseInt(l1[1]);
String[] l2 = in.readLine().split(" ");
TreeSet<Integer> array = new TreeSet<>();
for(int i = 0; i < n; i ++) {
int tmp = Integer.parseInt(l2[i]);
if (tmp != 0) {
array.add(tmp);
}
}
int prev = 0;
int idx = 0;
for(int i: array) {
idx ++;
System.out.println(i - prev);
prev = i;
if (idx == k) {
break;
}
}
for(int i = array.size(); i < k; i++) {
System.out.println(0);
}
}
}
| Java | ["3 5\n1 2 3", "4 2\n10 3 5 3"] | 1 second | ["1\n1\n1\n0\n0", "3\n2"] | NoteIn the first sample:In the first step: the array is $$$[1,2,3]$$$, so the minimum non-zero element is 1.In the second step: the array is $$$[0,1,2]$$$, so the minimum non-zero element is 1.In the third step: the array is $$$[0,0,1]$$$, so the minimum non-zero element is 1.In the fourth and fifth step: the array is $$$[0,0,0]$$$, so we printed 0.In the second sample:In the first step: the array is $$$[10,3,5,3]$$$, so the minimum non-zero element is 3.In the second step: the array is $$$[7,0,2,0]$$$, so the minimum non-zero element is 2. | Java 8 | standard input | [
"implementation",
"sortings"
] | 0f100199a720b0fdead5f03e1882f2f3 | The first line contains integers $$$n$$$ and $$$k$$$ $$$(1 \le n,k \le 10^5)$$$, the length of the array and the number of operations you should perform. The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$, the elements of the array. | 1,000 | Print the minimum non-zero element before each operation in a new line. | standard output | |
PASSED | c8ede8df5f6c537a5416ebb93bd002f6 | train_003.jsonl | 1543934100 | You're given an array $$$a$$$. You should repeat the following operation $$$k$$$ times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0. | 256 megabytes | import java.util.*;
/**
* @author okasha
*/
public class B1088 {
public static void main(String[] args) {
int n, k, i, j;
long sumAll = 0, sumSofar = 0;
ArrayList<Integer> arr = new ArrayList<Integer>();
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
k = sc.nextInt();
for (i = 0; i < n; ++i) {
int x = sc.nextInt();
arr.add(x);
sumAll += x;
}
Collections.sort(arr);
for (i = 0, j = 0; i < k; ++i) {
if (sumAll <= 0) {
System.out.println(0);
continue;
}
if (j < n - 1) {
while (arr.get(j) - sumSofar <= 0 && j < n - 1) {
++j;
}
}
long newValue = arr.get(j) - sumSofar;
System.out.println(newValue);
sumAll -= (newValue * (n - j));
sumSofar += newValue;
}
}
}
| Java | ["3 5\n1 2 3", "4 2\n10 3 5 3"] | 1 second | ["1\n1\n1\n0\n0", "3\n2"] | NoteIn the first sample:In the first step: the array is $$$[1,2,3]$$$, so the minimum non-zero element is 1.In the second step: the array is $$$[0,1,2]$$$, so the minimum non-zero element is 1.In the third step: the array is $$$[0,0,1]$$$, so the minimum non-zero element is 1.In the fourth and fifth step: the array is $$$[0,0,0]$$$, so we printed 0.In the second sample:In the first step: the array is $$$[10,3,5,3]$$$, so the minimum non-zero element is 3.In the second step: the array is $$$[7,0,2,0]$$$, so the minimum non-zero element is 2. | Java 8 | standard input | [
"implementation",
"sortings"
] | 0f100199a720b0fdead5f03e1882f2f3 | The first line contains integers $$$n$$$ and $$$k$$$ $$$(1 \le n,k \le 10^5)$$$, the length of the array and the number of operations you should perform. The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$, the elements of the array. | 1,000 | Print the minimum non-zero element before each operation in a new line. | standard output | |
PASSED | bafd5a2101583ff2d6a771b70f35406e | train_003.jsonl | 1458118800 | There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru.You are given a list of page addresses being queried. For simplicity we consider all addresses to have the form http://<hostname>[/<path>], where: <hostname> — server name (consists of words and maybe some dots separating them), /<path> — optional part, where <path> consists of words separated by slashes. We consider two <hostname> to correspond to one website if for each query to the first <hostname> there will be exactly the same query to the second one and vice versa — for each query to the second <hostname> there will be the same query to the first one. Take a look at the samples for further clarifications.Your goal is to determine the groups of server names that correspond to one website. Ignore groups consisting of the only server name.Please note, that according to the above definition queries http://<hostname> and http://<hostname>/ are different. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
public class hostname {
public static class DisjointSet {
public int size;
public int[] id, rank;
public DisjointSet(int n) {
size = n;
id = new int[n];
rank = new int[n];
for(int i = 0; i < n; i++)
id[i] = i;
}
public int find(int x) {
while(x != id[x])
x = id[x] = id[id[x]];
return x;
}
public void union(int a, int b) {
a = find(a);
b = find(b);
if(a == b)
return;
if(rank[a] > rank[b]) id[b] = a;
else if(rank[a] < rank[b]) id[a] = b;
else {
rank[a]++;
id[b] = a;
}
size--;
}
}
public static class Thingy implements Comparable<Thingy> {
public int[] arr;
public boolean hashed;
public int n, hashCode, index;
public Thingy(int[] arr, int index) {
n = arr.length;
hashed = false;
this.index = index;
this.arr = arr;
}
@Override
public int hashCode() {
if(!hashed) {
hashed = true;
hashCode = Arrays.hashCode(arr);
}
return hashCode;
}
@Override
public int compareTo(Thingy other) {
int ptr1 = 0, ptr2 = 0;
while(ptr1 < this.n && ptr2 < other.n) {
int cmp = Integer.compare(this.arr[ptr1++], other.arr[ptr2++]);
if(cmp == 0)
continue;
return cmp;
}
if(ptr1 == this.n && ptr2 == other.n)
return 0;
else if(ptr1 == this.n)
return -1;
return 1;
}
@Override
public String toString() {
return Arrays.toString(arr);
}
}
public static void main(String[] args) throws IOException {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
int n = Integer.parseInt(read.readLine());
Map<String, Set<String>> map = new HashMap<String, Set<String>>();
Map<String, Integer> map2 = new HashMap<String, Integer>();
Map<Integer, String> rev = new HashMap<Integer, String>();
Set<String> paths = new TreeSet<String>();
int len = 0;
for(int i = 0; i < n; i++) {
String s = read.readLine().substring(7);
String path = "";
int index = s.indexOf("/");
if(index > 0) {
path = s.substring(index);
s = s.substring(0, index);
}
if(!map.containsKey(s)) {
map.put(s, new HashSet<String>());
map2.put(s, len);
rev.put(len++, s);
}
map.get(s).add(path);
paths.add(path);
}
Map<String, Integer> map3 = new HashMap<String, Integer>();
int index = 0;
for(String s : paths)
map3.put(s, index++);
List<Thingy> list = new ArrayList<Thingy>(map.size());
index = 0;
for(String s : map.keySet()) {
Set<String> set = map.get(s);
int[] arr = new int[set.size()];
int i = 0;
for(String ss : set)
arr[i++] = map3.get(ss);
Arrays.sort(arr);
list.add(new Thingy(arr, map2.get(s)));
}
Collections.sort(list);
DisjointSet ds = new DisjointSet(map.size());
for(int i = 1; i < list.size(); i++) {
Thingy a = list.get(i), b = list.get(i - 1);
if(/*a.hashCode() == b.hashCode() && */a.compareTo(b) == 0)
ds.union(a.index, b.index);
}
Map<Integer, Set<String>> ans = new HashMap<Integer, Set<String>>();
for(int i = 0; i < len; i++) {
int id = ds.find(i);
if(!ans.containsKey(id))
ans.put(id, new HashSet<String>());
ans.get(id).add(rev.get(i));
}
len = 0;
for(int id : ans.keySet())
if(ans.get(id).size() > 1)
len++;
out.println(len);
for(int id : ans.keySet()) {
boolean first = true;
Set<String> set = ans.get(id);
if(set.size() == 1)
continue;
for(String s : set) {
if(first) first = false;
else out.print(" ");
out.print("http://");
out.print(s);
}
out.println();
}
out.close();
}
} | Java | ["10\nhttp://abacaba.ru/test\nhttp://abacaba.ru/\nhttp://abacaba.com\nhttp://abacaba.com/test\nhttp://abacaba.de/\nhttp://abacaba.ru/test\nhttp://abacaba.de/test\nhttp://abacaba.com/\nhttp://abacaba.com/t\nhttp://abacaba.com/test", "14\nhttp://c\nhttp://ccc.bbbb/aba..b\nhttp://cba.com\nhttp://a.c/aba..b/a\nhttp://abc/\nhttp://a.c/\nhttp://ccc.bbbb\nhttp://ab.ac.bc.aa/\nhttp://a.a.a/\nhttp://ccc.bbbb/\nhttp://cba.com/\nhttp://cba.com/aba..b\nhttp://a.a.a/aba..b/a\nhttp://abc/aba..b/a"] | 5 seconds | ["1\nhttp://abacaba.de http://abacaba.ru", "2\nhttp://cba.com http://ccc.bbbb \nhttp://a.a.a http://a.c http://abc"] | null | Java 8 | standard input | [
"implementation",
"*special",
"sortings",
"data structures",
"binary search",
"strings"
] | 9b35f7df9e21162858a8fac8ee2837a4 | The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of page queries. Then follow n lines each containing exactly one address. Each address is of the form http://<hostname>[/<path>], where: <hostname> consists of lowercase English letters and dots, there are no two consecutive dots, <hostname> doesn't start or finish with a dot. The length of <hostname> is positive and doesn't exceed 20. <path> consists of lowercase English letters, dots and slashes. There are no two consecutive slashes, <path> doesn't start with a slash and its length doesn't exceed 20. Addresses are not guaranteed to be distinct. | 2,100 | First print k — the number of groups of server names that correspond to one website. You should count only groups of size greater than one. Next k lines should contain the description of groups, one group per line. For each group print all server names separated by a single space. You are allowed to print both groups and names inside any group in arbitrary order. | standard output | |
PASSED | a787aa359a1ddefa54054eeabf5d10fe | train_003.jsonl | 1458118800 | There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru.You are given a list of page addresses being queried. For simplicity we consider all addresses to have the form http://<hostname>[/<path>], where: <hostname> — server name (consists of words and maybe some dots separating them), /<path> — optional part, where <path> consists of words separated by slashes. We consider two <hostname> to correspond to one website if for each query to the first <hostname> there will be exactly the same query to the second one and vice versa — for each query to the second <hostname> there will be the same query to the first one. Take a look at the samples for further clarifications.Your goal is to determine the groups of server names that correspond to one website. Ignore groups consisting of the only server name.Please note, that according to the above definition queries http://<hostname> and http://<hostname>/ are different. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class C {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
HashMap<String, HashSet<Integer>> hosts = new HashMap<>();
int n = Integer.parseInt(br.readLine());
Compactor comp = new Compactor();
while (n-- > 0) {
String s = br.readLine();
String hostname = s.substring("http://".length());
int i = hostname.indexOf('/');
String path = "";
if (i > 0) {
path = hostname.substring(i);
hostname = hostname.substring(0, i);
}
int ipath = comp.compact(path);
if (!hosts.containsKey(hostname)) hosts.put(hostname, new HashSet<>());
hosts.get(hostname).add(ipath);
}
Map<PathSet, HashSet<String>> res = new TreeMap<>();
for (Map.Entry<String, HashSet<Integer>> e : hosts.entrySet()) {
PathSet ps = new PathSet(e.getValue());
Set<String> hs = res.computeIfAbsent(ps, (_ps) -> new HashSet<>());
hs.add(e.getKey());
}
int resCount = 0;
for (HashSet<String> hs : res.values()) {
if (hs.size() > 1) resCount++;
}
System.out.println(resCount);
for (HashSet<String> hs : res.values()) {
if (hs.size() > 1) {
for (String s : hs) {
System.out.print("http://"+s+" ");
}
System.out.println();
}
}
}
static class PathSet implements Comparable<PathSet> {
int[] paths;
public PathSet(Collection<Integer> _paths) {
this.paths = new int[_paths.size()];
Iterator<Integer> it = _paths.iterator();
for (int i = 0; i < _paths.size(); i++) {
this.paths[i] = it.next();
}
Arrays.sort(this.paths);
}
@Override
public int compareTo(PathSet o) {
int r = paths.length - o.paths.length;
if (r != 0) return r;
for (int i = 0; i < paths.length; i++) {
r = paths[i] - o.paths[i];
if (r!=0) return r;
}
return 0;
}
}
static int compareTreeSets(TreeSet<Integer> a, TreeSet<Integer> b) {
int r = a.size() - b.size();
if (r!=0) return r;
Iterator<Integer> ia = a.iterator();
Iterator<Integer> ib = a.iterator();
while (ia.hasNext()) {
int aa = ia.next();
int bb = ib.next();
r = aa - bb;
if (r != 0) return r;
}
return 0;
}
static class Compactor {
HashMap<String, Integer> map = new HashMap<>();
int compact(String s) {
map.putIfAbsent(s, map.size());
return map.get(s);
}
}
}
| Java | ["10\nhttp://abacaba.ru/test\nhttp://abacaba.ru/\nhttp://abacaba.com\nhttp://abacaba.com/test\nhttp://abacaba.de/\nhttp://abacaba.ru/test\nhttp://abacaba.de/test\nhttp://abacaba.com/\nhttp://abacaba.com/t\nhttp://abacaba.com/test", "14\nhttp://c\nhttp://ccc.bbbb/aba..b\nhttp://cba.com\nhttp://a.c/aba..b/a\nhttp://abc/\nhttp://a.c/\nhttp://ccc.bbbb\nhttp://ab.ac.bc.aa/\nhttp://a.a.a/\nhttp://ccc.bbbb/\nhttp://cba.com/\nhttp://cba.com/aba..b\nhttp://a.a.a/aba..b/a\nhttp://abc/aba..b/a"] | 5 seconds | ["1\nhttp://abacaba.de http://abacaba.ru", "2\nhttp://cba.com http://ccc.bbbb \nhttp://a.a.a http://a.c http://abc"] | null | Java 8 | standard input | [
"implementation",
"*special",
"sortings",
"data structures",
"binary search",
"strings"
] | 9b35f7df9e21162858a8fac8ee2837a4 | The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of page queries. Then follow n lines each containing exactly one address. Each address is of the form http://<hostname>[/<path>], where: <hostname> consists of lowercase English letters and dots, there are no two consecutive dots, <hostname> doesn't start or finish with a dot. The length of <hostname> is positive and doesn't exceed 20. <path> consists of lowercase English letters, dots and slashes. There are no two consecutive slashes, <path> doesn't start with a slash and its length doesn't exceed 20. Addresses are not guaranteed to be distinct. | 2,100 | First print k — the number of groups of server names that correspond to one website. You should count only groups of size greater than one. Next k lines should contain the description of groups, one group per line. For each group print all server names separated by a single space. You are allowed to print both groups and names inside any group in arbitrary order. | standard output | |
PASSED | 12e82d1c696e616e2dacbb690033ce7a | train_003.jsonl | 1458118800 | There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru.You are given a list of page addresses being queried. For simplicity we consider all addresses to have the form http://<hostname>[/<path>], where: <hostname> — server name (consists of words and maybe some dots separating them), /<path> — optional part, where <path> consists of words separated by slashes. We consider two <hostname> to correspond to one website if for each query to the first <hostname> there will be exactly the same query to the second one and vice versa — for each query to the second <hostname> there will be the same query to the first one. Take a look at the samples for further clarifications.Your goal is to determine the groups of server names that correspond to one website. Ignore groups consisting of the only server name.Please note, that according to the above definition queries http://<hostname> and http://<hostname>/ are different. | 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.io.Reader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.StringTokenizer;
// CROC 2016 - Qualification
// Hostname Aliases
public class Problem_644_C {
public static void main(String[] args)
{
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
PrintWriter out = new PrintWriter(outputStream);
Problem_644_C solver = new Problem_644_C();
solver.solve(1, new InputStreamReader(inputStream), out);
out.close();
}
public void solve(int test, Reader input, PrintWriter out)
{
MyScanner in = new MyScanner(input);
int n = in.nextInt();
HashMap<String, HashSet<String>> count = new HashMap<>();
for(int i = 0; i < n; i++) {
String s = in.next();
String host = s;
String query = "";
int idx = s.indexOf('/', 7);
if(idx != -1) {
host = s.substring(0, idx);
query = s.substring(idx);
}
if(!count.containsKey(host))
count.put(host, new HashSet<>());
count.get(host).add(query);
}
HashMap<HashSet<String>, ArrayList<String>> counts = new HashMap<>();
for(Map.Entry<String, HashSet<String>> entry : count.entrySet()) {
HashSet<String> set = entry.getValue();
if(!counts.containsKey(set))
counts.put(set, new ArrayList<>());
counts.get(set).add(entry.getKey());
}
int k = 0;
for(ArrayList<String> v : counts.values()) {
if(v.size() > 1) k++;
}
out.println(k);
for(ArrayList<String> v : counts.values()) {
if(v.size() > 1) {
for(String s : v) {
out.print(s + " ");
}
out.println();
}
}
}
//-----------MyScanner class for faster input----------
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner(Reader reader) {
br = new BufferedReader(reader);
}
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());
}
int[] nextIntArray(int n)
{
int[] r = new int[n];
for(int i = 0; i < n; i++)
r[i] = nextInt();
return r;
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
//--------------------------------------------------------
}
| Java | ["10\nhttp://abacaba.ru/test\nhttp://abacaba.ru/\nhttp://abacaba.com\nhttp://abacaba.com/test\nhttp://abacaba.de/\nhttp://abacaba.ru/test\nhttp://abacaba.de/test\nhttp://abacaba.com/\nhttp://abacaba.com/t\nhttp://abacaba.com/test", "14\nhttp://c\nhttp://ccc.bbbb/aba..b\nhttp://cba.com\nhttp://a.c/aba..b/a\nhttp://abc/\nhttp://a.c/\nhttp://ccc.bbbb\nhttp://ab.ac.bc.aa/\nhttp://a.a.a/\nhttp://ccc.bbbb/\nhttp://cba.com/\nhttp://cba.com/aba..b\nhttp://a.a.a/aba..b/a\nhttp://abc/aba..b/a"] | 5 seconds | ["1\nhttp://abacaba.de http://abacaba.ru", "2\nhttp://cba.com http://ccc.bbbb \nhttp://a.a.a http://a.c http://abc"] | null | Java 8 | standard input | [
"implementation",
"*special",
"sortings",
"data structures",
"binary search",
"strings"
] | 9b35f7df9e21162858a8fac8ee2837a4 | The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of page queries. Then follow n lines each containing exactly one address. Each address is of the form http://<hostname>[/<path>], where: <hostname> consists of lowercase English letters and dots, there are no two consecutive dots, <hostname> doesn't start or finish with a dot. The length of <hostname> is positive and doesn't exceed 20. <path> consists of lowercase English letters, dots and slashes. There are no two consecutive slashes, <path> doesn't start with a slash and its length doesn't exceed 20. Addresses are not guaranteed to be distinct. | 2,100 | First print k — the number of groups of server names that correspond to one website. You should count only groups of size greater than one. Next k lines should contain the description of groups, one group per line. For each group print all server names separated by a single space. You are allowed to print both groups and names inside any group in arbitrary order. | standard output | |
PASSED | 580a4db0480b125d57d3199d0141ad38 | train_003.jsonl | 1458118800 | There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru.You are given a list of page addresses being queried. For simplicity we consider all addresses to have the form http://<hostname>[/<path>], where: <hostname> — server name (consists of words and maybe some dots separating them), /<path> — optional part, where <path> consists of words separated by slashes. We consider two <hostname> to correspond to one website if for each query to the first <hostname> there will be exactly the same query to the second one and vice versa — for each query to the second <hostname> there will be the same query to the first one. Take a look at the samples for further clarifications.Your goal is to determine the groups of server names that correspond to one website. Ignore groups consisting of the only server name.Please note, that according to the above definition queries http://<hostname> and http://<hostname>/ are different. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.Set;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.Comparator;
import java.util.Collections;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author Nguyen Trung Hieu - vuondenthanhcong11@gmail.com
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
TaskC solver = new TaskC();
solver.solve(1, in, out);
out.close();
}
static class TaskC {
public void solve(int testNumber, InputReader in, OutputWriter out) {
int count = in.readInt();
Set<String> uniqueName = new HashSet<String>();
for (int i = 0; i < count; i++) {
String name = in.readString();
name = name.replace("//", "@");
if (!name.contains("/")) {
name = name + "/$";
}
if (name.endsWith("/")) {
name = name + "#";
}
uniqueName.add(name);
}
List<String> name = new ArrayList<String>(uniqueName);
Collections.sort(name, new Comparator<String>() {
public int compare(String o1, String o2) {
return o1.compareTo(o2);
}
});
Map<String, List<String>> answer = new HashMap<String, List<String>>();
int i = 0;
while (i < name.size()) {
String[] info = name.get(i).split("/");
StringBuilder builder = new StringBuilder();
while (i < name.size()) {
String[] subInfo = name.get(i).split("/");
if (info[0].equals(subInfo[0])) {
for (int j = 1; j < subInfo.length; j++) {
if (j >= 2) {
builder.append("-");
}
builder.append(subInfo[j]);
}
builder.append("*");
i++;
} else {
break;
}
}
List<String> curAnswer = new ArrayList<String>();
if (answer.containsKey(builder.toString())) {
curAnswer = answer.get(builder.toString());
}
info[0] = info[0].replace("@", "//");
curAnswer.add(info[0]);
answer.put(builder.toString(), curAnswer);
}
int totalAnswer = 0;
for (String key : answer.keySet()) {
if (answer.get(key).size() > 1) {
totalAnswer++;
}
}
out.printLine(totalAnswer);
for (String key : answer.keySet()) {
List<String> curAnswer = answer.get(key);
if (curAnswer.size() > 1) {
for (String s : curAnswer) {
out.print(s + " ");
}
out.printLine();
}
}
}
}
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() {
writer.println();
}
public void close() {
writer.close();
}
public void printLine(int i) {
writer.println(i);
}
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private InputReader.SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int readInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public String readString() {
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 | ["10\nhttp://abacaba.ru/test\nhttp://abacaba.ru/\nhttp://abacaba.com\nhttp://abacaba.com/test\nhttp://abacaba.de/\nhttp://abacaba.ru/test\nhttp://abacaba.de/test\nhttp://abacaba.com/\nhttp://abacaba.com/t\nhttp://abacaba.com/test", "14\nhttp://c\nhttp://ccc.bbbb/aba..b\nhttp://cba.com\nhttp://a.c/aba..b/a\nhttp://abc/\nhttp://a.c/\nhttp://ccc.bbbb\nhttp://ab.ac.bc.aa/\nhttp://a.a.a/\nhttp://ccc.bbbb/\nhttp://cba.com/\nhttp://cba.com/aba..b\nhttp://a.a.a/aba..b/a\nhttp://abc/aba..b/a"] | 5 seconds | ["1\nhttp://abacaba.de http://abacaba.ru", "2\nhttp://cba.com http://ccc.bbbb \nhttp://a.a.a http://a.c http://abc"] | null | Java 8 | standard input | [
"implementation",
"*special",
"sortings",
"data structures",
"binary search",
"strings"
] | 9b35f7df9e21162858a8fac8ee2837a4 | The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of page queries. Then follow n lines each containing exactly one address. Each address is of the form http://<hostname>[/<path>], where: <hostname> consists of lowercase English letters and dots, there are no two consecutive dots, <hostname> doesn't start or finish with a dot. The length of <hostname> is positive and doesn't exceed 20. <path> consists of lowercase English letters, dots and slashes. There are no two consecutive slashes, <path> doesn't start with a slash and its length doesn't exceed 20. Addresses are not guaranteed to be distinct. | 2,100 | First print k — the number of groups of server names that correspond to one website. You should count only groups of size greater than one. Next k lines should contain the description of groups, one group per line. For each group print all server names separated by a single space. You are allowed to print both groups and names inside any group in arbitrary order. | standard output | |
PASSED | 3931bac0339ece6e16080badc7751866 | train_003.jsonl | 1458118800 | There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru.You are given a list of page addresses being queried. For simplicity we consider all addresses to have the form http://<hostname>[/<path>], where: <hostname> — server name (consists of words and maybe some dots separating them), /<path> — optional part, where <path> consists of words separated by slashes. We consider two <hostname> to correspond to one website if for each query to the first <hostname> there will be exactly the same query to the second one and vice versa — for each query to the second <hostname> there will be the same query to the first one. Take a look at the samples for further clarifications.Your goal is to determine the groups of server names that correspond to one website. Ignore groups consisting of the only server name.Please note, that according to the above definition queries http://<hostname> and http://<hostname>/ are different. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.AbstractSet;
import java.util.InputMismatchException;
import java.util.Random;
import java.util.ArrayList;
import java.util.Map;
import java.io.OutputStreamWriter;
import java.util.NoSuchElementException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Iterator;
import java.io.BufferedWriter;
import java.util.Collection;
import java.util.Set;
import java.io.IOException;
import java.util.stream.Collectors;
import java.util.List;
import java.util.AbstractMap;
import java.util.Map.Entry;
import java.io.Writer;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author Egor Kulikov (egor@egork.net)
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
TaskC solver = new TaskC();
solver.solve(1, in, out);
out.close();
}
static class TaskC {
public void solve(int testNumber, InputReader in, OutputWriter out) {
Map<Set<String>, List<String>> sets = new CPPMap<>(ArrayList::new);
Map<String, Set<String>> sites = new CPPMap<>(EHashSet::new);
int n = in.readInt();
for (int i = 0; i < n; i++) {
String url = in.readString();
int slash = url.indexOf('/', 7);
if (slash == -1) {
slash = url.length();
}
sites.get(url.substring(0, slash)).add(url.substring(slash));
}
for (Map.Entry<String, Set<String>> entry : sites.entrySet()) {
sets.get(entry.getValue()).add(entry.getKey());
}
List<Map.Entry<Set<String>, List<String>>> result =
sets.entrySet().stream().filter(x -> x.getValue().size() > 1).collect(Collectors.toList());
out.printLine(result.size());
for (Map.Entry<Set<String>, List<String>> entry : result) {
out.printLine(entry.getValue().toArray());
}
}
}
static class EHashMap<E, V> extends AbstractMap<E, V> {
private static final int[] shifts = new int[10];
private int size;
private HashEntry<E, V>[] data;
private int capacity;
private Set<Entry<E, V>> entrySet;
static {
Random random = new Random(System.currentTimeMillis());
for (int i = 0; i < 10; i++) {
shifts[i] = 1 + 3 * i + random.nextInt(3);
}
}
public EHashMap() {
this(4);
}
private void setCapacity(int size) {
capacity = Integer.highestOneBit(4 * size);
//noinspection unchecked
data = new HashEntry[capacity];
}
public EHashMap(int maxSize) {
setCapacity(maxSize);
entrySet = new AbstractSet<Entry<E, V>>() {
public Iterator<Entry<E, V>> iterator() {
return new Iterator<Entry<E, V>>() {
private HashEntry<E, V> last = null;
private HashEntry<E, V> current = null;
private HashEntry<E, V> base = null;
private int lastIndex = -1;
private int index = -1;
public boolean hasNext() {
if (current == null) {
for (index++; index < capacity; index++) {
if (data[index] != null) {
base = current = data[index];
break;
}
}
}
return current != null;
}
public Entry<E, V> next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
last = current;
lastIndex = index;
current = current.next;
if (base.next != last) {
base = base.next;
}
return last;
}
public void remove() {
if (last == null) {
throw new IllegalStateException();
}
size--;
if (base == last) {
data[lastIndex] = last.next;
} else {
base.next = last.next;
}
}
};
}
public int size() {
return size;
}
};
}
public EHashMap(Map<E, V> map) {
this(map.size());
putAll(map);
}
public Set<Entry<E, V>> entrySet() {
return entrySet;
}
public void clear() {
Arrays.fill(data, null);
size = 0;
}
private int index(Object o) {
return getHash(o.hashCode()) & (capacity - 1);
}
private int getHash(int h) {
int result = h;
for (int i : shifts) {
result ^= h >>> i;
}
return result;
}
public V remove(Object o) {
if (o == null) {
return null;
}
int index = index(o);
HashEntry<E, V> current = data[index];
HashEntry<E, V> last = null;
while (current != null) {
if (current.key.equals(o)) {
if (last == null) {
data[index] = current.next;
} else {
last.next = current.next;
}
size--;
return current.value;
}
last = current;
current = current.next;
}
return null;
}
public V put(E e, V value) {
if (e == null) {
return null;
}
int index = index(e);
HashEntry<E, V> current = data[index];
if (current != null) {
while (true) {
if (current.key.equals(e)) {
V oldValue = current.value;
current.value = value;
return oldValue;
}
if (current.next == null) {
break;
}
current = current.next;
}
}
if (current == null) {
data[index] = new HashEntry<E, V>(e, value);
} else {
current.next = new HashEntry<E, V>(e, value);
}
size++;
if (2 * size > capacity) {
HashEntry<E, V>[] oldData = data;
setCapacity(size);
for (HashEntry<E, V> entry : oldData) {
while (entry != null) {
HashEntry<E, V> next = entry.next;
index = index(entry.key);
entry.next = data[index];
data[index] = entry;
entry = next;
}
}
}
return null;
}
public V get(Object o) {
if (o == null) {
return null;
}
int index = index(o);
HashEntry<E, V> current = data[index];
while (current != null) {
if (current.key.equals(o)) {
return current.value;
}
current = current.next;
}
return null;
}
public boolean containsKey(Object o) {
if (o == null) {
return false;
}
int index = index(o);
HashEntry<E, V> current = data[index];
while (current != null) {
if (current.key.equals(o)) {
return true;
}
current = current.next;
}
return false;
}
public int size() {
return size;
}
private static class HashEntry<E, V> implements Entry<E, V> {
private final E key;
private V value;
private HashEntry<E, V> next;
private HashEntry(E key, V value) {
this.key = key;
this.value = value;
}
public E getKey() {
return key;
}
public V getValue() {
return value;
}
public V setValue(V value) {
V oldValue = this.value;
this.value = value;
return oldValue;
}
}
}
static class CPPMap<K, V> extends EHashMap<K, V> {
private final Factory<V> defaultValueFactory;
public CPPMap(Factory<V> defaultValueFactory) {
this.defaultValueFactory = defaultValueFactory;
}
public V get(Object key) {
if (containsKey(key)) {
return super.get(key);
}
V value = defaultValueFactory.create();
try {
//noinspection unchecked
super.put((K) key, value);
return value;
} catch (ClassCastException e) {
return value;
}
}
}
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 printLine(int i) {
writer.println(i);
}
}
static interface Factory<V> {
public V create();
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public int readInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public String readString() {
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);
}
}
static class EHashSet<E> extends AbstractSet<E> {
private static final Object VALUE = new Object();
private final Map<E, Object> map;
public EHashSet() {
this(4);
}
public EHashSet(int maxSize) {
map = new EHashMap<E, Object>(maxSize);
}
public EHashSet(Collection<E> collection) {
this(collection.size());
addAll(collection);
}
public boolean contains(Object o) {
return map.containsKey(o);
}
public boolean add(E e) {
if (e == null) {
return false;
}
return map.put(e, VALUE) == null;
}
public boolean remove(Object o) {
if (o == null) {
return false;
}
return map.remove(o) != null;
}
public void clear() {
map.clear();
}
public Iterator<E> iterator() {
return map.keySet().iterator();
}
public int size() {
return map.size();
}
}
}
| Java | ["10\nhttp://abacaba.ru/test\nhttp://abacaba.ru/\nhttp://abacaba.com\nhttp://abacaba.com/test\nhttp://abacaba.de/\nhttp://abacaba.ru/test\nhttp://abacaba.de/test\nhttp://abacaba.com/\nhttp://abacaba.com/t\nhttp://abacaba.com/test", "14\nhttp://c\nhttp://ccc.bbbb/aba..b\nhttp://cba.com\nhttp://a.c/aba..b/a\nhttp://abc/\nhttp://a.c/\nhttp://ccc.bbbb\nhttp://ab.ac.bc.aa/\nhttp://a.a.a/\nhttp://ccc.bbbb/\nhttp://cba.com/\nhttp://cba.com/aba..b\nhttp://a.a.a/aba..b/a\nhttp://abc/aba..b/a"] | 5 seconds | ["1\nhttp://abacaba.de http://abacaba.ru", "2\nhttp://cba.com http://ccc.bbbb \nhttp://a.a.a http://a.c http://abc"] | null | Java 8 | standard input | [
"implementation",
"*special",
"sortings",
"data structures",
"binary search",
"strings"
] | 9b35f7df9e21162858a8fac8ee2837a4 | The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of page queries. Then follow n lines each containing exactly one address. Each address is of the form http://<hostname>[/<path>], where: <hostname> consists of lowercase English letters and dots, there are no two consecutive dots, <hostname> doesn't start or finish with a dot. The length of <hostname> is positive and doesn't exceed 20. <path> consists of lowercase English letters, dots and slashes. There are no two consecutive slashes, <path> doesn't start with a slash and its length doesn't exceed 20. Addresses are not guaranteed to be distinct. | 2,100 | First print k — the number of groups of server names that correspond to one website. You should count only groups of size greater than one. Next k lines should contain the description of groups, one group per line. For each group print all server names separated by a single space. You are allowed to print both groups and names inside any group in arbitrary order. | standard output | |
PASSED | 524f2c366a99eb42b6f76c4c5998b1d3 | train_003.jsonl | 1458118800 | There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru.You are given a list of page addresses being queried. For simplicity we consider all addresses to have the form http://<hostname>[/<path>], where: <hostname> — server name (consists of words and maybe some dots separating them), /<path> — optional part, where <path> consists of words separated by slashes. We consider two <hostname> to correspond to one website if for each query to the first <hostname> there will be exactly the same query to the second one and vice versa — for each query to the second <hostname> there will be the same query to the first one. Take a look at the samples for further clarifications.Your goal is to determine the groups of server names that correspond to one website. Ignore groups consisting of the only server name.Please note, that according to the above definition queries http://<hostname> and http://<hostname>/ are different. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
// <editor-fold desc="IO">
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
solve(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());
}
}
// </editor-fold>
static class Pair<X, Y> {
public X first;
public Y second;
public Pair(X x, Y y) {
this.first = x;
this.second = y;
}
}
static Pair<String, String> breakWebsite(String website) {
StringBuilder hostnamesb = new StringBuilder();
int i = 0;
int slashCount = 0;
for (; i < website.length(); ++i) {
if (website.charAt(i) == '/') slashCount++;
if (slashCount == 3) break;
hostnamesb.append(website.charAt(i));
}
StringBuilder pathsb = new StringBuilder();
for (; i < website.length(); ++i) {
pathsb.append(website.charAt(i));
}
return new Pair<>(hostnamesb.toString(), pathsb.toString());
}
public static void solve(InputReader in, PrintWriter out) {
int n = in.nextInt();
//extract hostname and path
HashMap<String, HashSet<String>> websites = new HashMap<>();
for (int i = 0; i < n; i++) {
String website = in.next();
Pair<String, String> sep = breakWebsite(website);
//System.out.println(sep.first + " and " + sep.second);
String hostname = sep.first;
String path = sep.second;
HashSet<String> get = websites.get(hostname);
if (get != null) {
get.add(path);
} else {
HashSet<String> temp = new HashSet<>();
temp.add(path);
websites.put(hostname, temp);
}
}
HashMap<HashSet<String>, HashSet<String>> inverted = new HashMap<>();
//invert indices
int count = 0;
for (Map.Entry<String, HashSet<String>> e : websites.entrySet()) {
HashSet<String> get = inverted.get(e.getValue());
if (get == null) {
HashSet<String> temp = new HashSet<>();
temp.add(e.getKey());
inverted.put(e.getValue(), temp);
} else {
get.add(e.getKey());
if (get.size() == 2) count++;
}
}
out.println(count);
for (HashSet<String> hs : inverted.values()) {
if (hs.size() > 1) {
for (String s : hs) {
out.print(s + " ");
}
out.println();
}
}
}
} | Java | ["10\nhttp://abacaba.ru/test\nhttp://abacaba.ru/\nhttp://abacaba.com\nhttp://abacaba.com/test\nhttp://abacaba.de/\nhttp://abacaba.ru/test\nhttp://abacaba.de/test\nhttp://abacaba.com/\nhttp://abacaba.com/t\nhttp://abacaba.com/test", "14\nhttp://c\nhttp://ccc.bbbb/aba..b\nhttp://cba.com\nhttp://a.c/aba..b/a\nhttp://abc/\nhttp://a.c/\nhttp://ccc.bbbb\nhttp://ab.ac.bc.aa/\nhttp://a.a.a/\nhttp://ccc.bbbb/\nhttp://cba.com/\nhttp://cba.com/aba..b\nhttp://a.a.a/aba..b/a\nhttp://abc/aba..b/a"] | 5 seconds | ["1\nhttp://abacaba.de http://abacaba.ru", "2\nhttp://cba.com http://ccc.bbbb \nhttp://a.a.a http://a.c http://abc"] | null | Java 8 | standard input | [
"implementation",
"*special",
"sortings",
"data structures",
"binary search",
"strings"
] | 9b35f7df9e21162858a8fac8ee2837a4 | The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of page queries. Then follow n lines each containing exactly one address. Each address is of the form http://<hostname>[/<path>], where: <hostname> consists of lowercase English letters and dots, there are no two consecutive dots, <hostname> doesn't start or finish with a dot. The length of <hostname> is positive and doesn't exceed 20. <path> consists of lowercase English letters, dots and slashes. There are no two consecutive slashes, <path> doesn't start with a slash and its length doesn't exceed 20. Addresses are not guaranteed to be distinct. | 2,100 | First print k — the number of groups of server names that correspond to one website. You should count only groups of size greater than one. Next k lines should contain the description of groups, one group per line. For each group print all server names separated by a single space. You are allowed to print both groups and names inside any group in arbitrary order. | standard output | |
PASSED | 18f52aaa2ee15d44979744b092df21d4 | train_003.jsonl | 1458118800 | There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru.You are given a list of page addresses being queried. For simplicity we consider all addresses to have the form http://<hostname>[/<path>], where: <hostname> — server name (consists of words and maybe some dots separating them), /<path> — optional part, where <path> consists of words separated by slashes. We consider two <hostname> to correspond to one website if for each query to the first <hostname> there will be exactly the same query to the second one and vice versa — for each query to the second <hostname> there will be the same query to the first one. Take a look at the samples for further clarifications.Your goal is to determine the groups of server names that correspond to one website. Ignore groups consisting of the only server name.Please note, that according to the above definition queries http://<hostname> and http://<hostname>/ are different. | 256 megabytes | import java.util.*;
/**
* Author: Destiner
* Date: 17.03.2016
*/
public class QualC {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
StringBuilder builder = new StringBuilder();
int n = scanner.nextInt();
scanner.nextLine();
int requestCount = 0;
// Domain -> number map
Map<String, Domain> domainMap = new HashMap<>();
// Request -> number map
Map<String, Integer> requestMap = new HashMap<>();
// Domain with requests list
List<Domain> domainList = new ArrayList<>();
for (int i = 0; i < n; i++) {
String in = scanner.nextLine();
String[] data = getData(in);
String domainName = data[0];
String request = data[1];
if (!domainMap.containsKey(domainName)) {
Domain domain = new Domain(domainName);
domainList.add(domain);
domainMap.put(domainName, domain);
}
if (!requestMap.containsKey(request)) {
requestMap.put(request, requestCount);
requestCount++;
}
int requestId = requestMap.get(request);
domainMap.get(domainName).addRequest(requestId);
}
// Sort requests in each domain
for (Domain domain : domainList) {
domain.sortRequests();
}
// Sort domains lexicographically
domainList.sort((o1, o2) -> {
int size1 = o1.requests.size();
int size2 = o2.requests.size();
int minSize = Math.min(size1, size2);
for (int i = 0; i < minSize; i ++) {
int i1 = o1.requests.get(i);
int i2 = o2.requests.get(i);
if (i1 < i2) {
return -1;
} else if (i1 > i2) {
return 1;
}
}
return Integer.compare(size1, size2);
});
int groups = 0;
List<Integer> lastGroup = null;
for (int i = 1; i < domainList.size(); i++) {
Domain oldD = domainList.get(i - 1);
Domain newD = domainList.get(i);
if (oldD.requests.equals(newD.requests) && !newD.requests.equals(lastGroup)) {
lastGroup = newD.requests;
groups++;
}
}
builder.append(groups).append('\n');
boolean first = true;
boolean newLine = true;
for (int i = 1; i < domainList.size(); i++) {
Domain oldD = domainList.get(i - 1);
Domain newD = domainList.get(i);
if (oldD.requests.equals(newD.requests)) {
if (first) {
builder.append("http://").append(oldD.name).append(' ');
first = false;
}
builder.append("http://").append(newD.name).append(' ');
newLine = false;
} else {
first = true;
if (!newLine) {
builder.append('\n');
newLine = true;
}
}
}
System.out.print(builder.toString());
}
private static String[] getData(String in) {
String[] data = new String[2];
String protocolCut = in.substring(7);
int slicePosition = protocolCut.indexOf('/');
if (slicePosition == -1) {
data[0] = protocolCut;
data[1] = "";
} else {
data[0] = protocolCut.substring(0, slicePosition);
data[1] = protocolCut.substring(slicePosition);
}
return data;
}
}
class Domain {
String name;
List<Integer> requests;
Set<Integer> requestSet;
// Note word combination
public Domain(String name) {
this.name = name;
requests = new ArrayList<>();
requestSet = new HashSet<>();
}
public void addRequest(int requestId) {
if (!requestSet.contains(requestId)) {
requestSet.add(requestId);
requests.add(requestId);
}
}
public void sortRequests() {
Collections.sort(requests);
}
}
| Java | ["10\nhttp://abacaba.ru/test\nhttp://abacaba.ru/\nhttp://abacaba.com\nhttp://abacaba.com/test\nhttp://abacaba.de/\nhttp://abacaba.ru/test\nhttp://abacaba.de/test\nhttp://abacaba.com/\nhttp://abacaba.com/t\nhttp://abacaba.com/test", "14\nhttp://c\nhttp://ccc.bbbb/aba..b\nhttp://cba.com\nhttp://a.c/aba..b/a\nhttp://abc/\nhttp://a.c/\nhttp://ccc.bbbb\nhttp://ab.ac.bc.aa/\nhttp://a.a.a/\nhttp://ccc.bbbb/\nhttp://cba.com/\nhttp://cba.com/aba..b\nhttp://a.a.a/aba..b/a\nhttp://abc/aba..b/a"] | 5 seconds | ["1\nhttp://abacaba.de http://abacaba.ru", "2\nhttp://cba.com http://ccc.bbbb \nhttp://a.a.a http://a.c http://abc"] | null | Java 8 | standard input | [
"implementation",
"*special",
"sortings",
"data structures",
"binary search",
"strings"
] | 9b35f7df9e21162858a8fac8ee2837a4 | The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of page queries. Then follow n lines each containing exactly one address. Each address is of the form http://<hostname>[/<path>], where: <hostname> consists of lowercase English letters and dots, there are no two consecutive dots, <hostname> doesn't start or finish with a dot. The length of <hostname> is positive and doesn't exceed 20. <path> consists of lowercase English letters, dots and slashes. There are no two consecutive slashes, <path> doesn't start with a slash and its length doesn't exceed 20. Addresses are not guaranteed to be distinct. | 2,100 | First print k — the number of groups of server names that correspond to one website. You should count only groups of size greater than one. Next k lines should contain the description of groups, one group per line. For each group print all server names separated by a single space. You are allowed to print both groups and names inside any group in arbitrary order. | standard output | |
PASSED | 2e7a821cd935e02dc8c413b264e965aa | train_003.jsonl | 1458118800 | There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru.You are given a list of page addresses being queried. For simplicity we consider all addresses to have the form http://<hostname>[/<path>], where: <hostname> — server name (consists of words and maybe some dots separating them), /<path> — optional part, where <path> consists of words separated by slashes. We consider two <hostname> to correspond to one website if for each query to the first <hostname> there will be exactly the same query to the second one and vice versa — for each query to the second <hostname> there will be the same query to the first one. Take a look at the samples for further clarifications.Your goal is to determine the groups of server names that correspond to one website. Ignore groups consisting of the only server name.Please note, that according to the above definition queries http://<hostname> and http://<hostname>/ are different. | 256 megabytes | import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
public class Main2 {
public static void main(String[] args) throws MalformedURLException {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
List<URL> list = new ArrayList<>();
List<List<String>> output = new ArrayList<>();
for(int i=0; i<=n; i++) {
String spec = sc.nextLine();
if(!spec.equals("")) {
list.add(new URL(spec));
}
}
Map<String, Set<String>> map = new HashMap<>();
for(URL url : list) {
String host = url.getHost();
if(map.containsKey(host)) {
Set<String> strings = map.get(host);
strings.add(url.getPath());
} else {
map.put(host, new HashSet<>());
map.get(host).add(url.getPath());
}
}
Map<Set<String>, Set<String>> harded = new HashMap<>();
for(Map.Entry<String, Set<String>> entry : map.entrySet()) {
if(!harded.containsKey(entry.getValue())) {
harded.put(entry.getValue(), new HashSet<>());
}
harded.get(entry.getValue()).add(entry.getKey());
}
int count = 0;
for (Map.Entry<Set<String>, Set<String>> entry : harded.entrySet()) {
if(entry.getValue().size() > 1) count++;
}
System.out.println(count);
for (Map.Entry<Set<String>, Set<String>> entry : harded.entrySet()) {
if(entry.getValue().size() > 1) {
for(String str : entry.getValue()) {
System.out.printf("http://%s ", str);
}
System.out.println();
}
}
}
}
| Java | ["10\nhttp://abacaba.ru/test\nhttp://abacaba.ru/\nhttp://abacaba.com\nhttp://abacaba.com/test\nhttp://abacaba.de/\nhttp://abacaba.ru/test\nhttp://abacaba.de/test\nhttp://abacaba.com/\nhttp://abacaba.com/t\nhttp://abacaba.com/test", "14\nhttp://c\nhttp://ccc.bbbb/aba..b\nhttp://cba.com\nhttp://a.c/aba..b/a\nhttp://abc/\nhttp://a.c/\nhttp://ccc.bbbb\nhttp://ab.ac.bc.aa/\nhttp://a.a.a/\nhttp://ccc.bbbb/\nhttp://cba.com/\nhttp://cba.com/aba..b\nhttp://a.a.a/aba..b/a\nhttp://abc/aba..b/a"] | 5 seconds | ["1\nhttp://abacaba.de http://abacaba.ru", "2\nhttp://cba.com http://ccc.bbbb \nhttp://a.a.a http://a.c http://abc"] | null | Java 8 | standard input | [
"implementation",
"*special",
"sortings",
"data structures",
"binary search",
"strings"
] | 9b35f7df9e21162858a8fac8ee2837a4 | The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of page queries. Then follow n lines each containing exactly one address. Each address is of the form http://<hostname>[/<path>], where: <hostname> consists of lowercase English letters and dots, there are no two consecutive dots, <hostname> doesn't start or finish with a dot. The length of <hostname> is positive and doesn't exceed 20. <path> consists of lowercase English letters, dots and slashes. There are no two consecutive slashes, <path> doesn't start with a slash and its length doesn't exceed 20. Addresses are not guaranteed to be distinct. | 2,100 | First print k — the number of groups of server names that correspond to one website. You should count only groups of size greater than one. Next k lines should contain the description of groups, one group per line. For each group print all server names separated by a single space. You are allowed to print both groups and names inside any group in arbitrary order. | standard output | |
PASSED | d4ea0d54e26d7468f5b7ca13bd593ae0 | train_003.jsonl | 1458118800 | There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru.You are given a list of page addresses being queried. For simplicity we consider all addresses to have the form http://<hostname>[/<path>], where: <hostname> — server name (consists of words and maybe some dots separating them), /<path> — optional part, where <path> consists of words separated by slashes. We consider two <hostname> to correspond to one website if for each query to the first <hostname> there will be exactly the same query to the second one and vice versa — for each query to the second <hostname> there will be the same query to the first one. Take a look at the samples for further clarifications.Your goal is to determine the groups of server names that correspond to one website. Ignore groups consisting of the only server name.Please note, that according to the above definition queries http://<hostname> and http://<hostname>/ are different. | 256 megabytes | import static java.lang.Double.parseDouble;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.System.exit;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.StringTokenizer;
public class C {
static BufferedReader in;
static PrintWriter out;
static StringTokenizer tok;
static void solve() throws Exception {
int n = nextInt();
Map<String, List<String>> paths = new HashMap<>();
for (int i = 0; i < n; i++) {
String l = next();
if (!l.startsWith("http://")) {
throw new AssertionError();
}
int pos = l.indexOf('/', 7);
if (pos < 0) {
pos = l.length();
}
String host = l.substring(0, pos);
String path = l.substring(pos);
List<String> cPaths = paths.get(host);
if (cPaths == null) {
paths.put(host, cPaths = new ArrayList<>());
}
cPaths.add(path);
}
Map<List<String>, List<String>> rPaths = new HashMap<>();
for (Entry<String, List<String>> e: paths.entrySet()) {
List<String> cPaths = e.getValue();
Collections.sort(cPaths);
List<String> out = new ArrayList<>();
String last = null;
for (String cur: cPaths) {
if (!cur.equals(last)) {
out.add(cur);
last = cur;
}
}
String host = e.getKey();
List<String> hosts = rPaths.get(out);
if (hosts == null) {
rPaths.put(out, hosts = new ArrayList<>());
}
hosts.add(host);
}
List<List<String>> res = new ArrayList<>();
for (List<String> hosts: rPaths.values()) {
if (hosts.size() > 1) {
res.add(hosts);
}
}
out.println(res.size());
for (List<String> hosts: res) {
out.println(String.join(" ", hosts));
}
}
static int nextInt() throws IOException {
return parseInt(next());
}
static long nextLong() throws IOException {
return parseLong(next());
}
static double nextDouble() throws IOException {
return parseDouble(next());
}
static String next() throws IOException {
while (tok == null || !tok.hasMoreTokens()) {
tok = new StringTokenizer(in.readLine());
}
return tok.nextToken();
}
public static void main(String[] args) {
try {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(new OutputStreamWriter(System.out));
solve();
in.close();
out.close();
} catch (Throwable e) {
e.printStackTrace();
exit(1);
}
}
}
| Java | ["10\nhttp://abacaba.ru/test\nhttp://abacaba.ru/\nhttp://abacaba.com\nhttp://abacaba.com/test\nhttp://abacaba.de/\nhttp://abacaba.ru/test\nhttp://abacaba.de/test\nhttp://abacaba.com/\nhttp://abacaba.com/t\nhttp://abacaba.com/test", "14\nhttp://c\nhttp://ccc.bbbb/aba..b\nhttp://cba.com\nhttp://a.c/aba..b/a\nhttp://abc/\nhttp://a.c/\nhttp://ccc.bbbb\nhttp://ab.ac.bc.aa/\nhttp://a.a.a/\nhttp://ccc.bbbb/\nhttp://cba.com/\nhttp://cba.com/aba..b\nhttp://a.a.a/aba..b/a\nhttp://abc/aba..b/a"] | 5 seconds | ["1\nhttp://abacaba.de http://abacaba.ru", "2\nhttp://cba.com http://ccc.bbbb \nhttp://a.a.a http://a.c http://abc"] | null | Java 8 | standard input | [
"implementation",
"*special",
"sortings",
"data structures",
"binary search",
"strings"
] | 9b35f7df9e21162858a8fac8ee2837a4 | The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of page queries. Then follow n lines each containing exactly one address. Each address is of the form http://<hostname>[/<path>], where: <hostname> consists of lowercase English letters and dots, there are no two consecutive dots, <hostname> doesn't start or finish with a dot. The length of <hostname> is positive and doesn't exceed 20. <path> consists of lowercase English letters, dots and slashes. There are no two consecutive slashes, <path> doesn't start with a slash and its length doesn't exceed 20. Addresses are not guaranteed to be distinct. | 2,100 | First print k — the number of groups of server names that correspond to one website. You should count only groups of size greater than one. Next k lines should contain the description of groups, one group per line. For each group print all server names separated by a single space. You are allowed to print both groups and names inside any group in arbitrary order. | standard output | |
PASSED | 1cfcd3a0849eab0303e560fc3fb369bc | train_003.jsonl | 1458118800 | There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru.You are given a list of page addresses being queried. For simplicity we consider all addresses to have the form http://<hostname>[/<path>], where: <hostname> — server name (consists of words and maybe some dots separating them), /<path> — optional part, where <path> consists of words separated by slashes. We consider two <hostname> to correspond to one website if for each query to the first <hostname> there will be exactly the same query to the second one and vice versa — for each query to the second <hostname> there will be the same query to the first one. Take a look at the samples for further clarifications.Your goal is to determine the groups of server names that correspond to one website. Ignore groups consisting of the only server name.Please note, that according to the above definition queries http://<hostname> and http://<hostname>/ are different. | 256 megabytes | import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringJoiner;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.util.HashMap;
import java.util.Set;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.TreeSet;
import java.io.Writer;
import java.util.StringTokenizer;
import java.util.LinkedList;
import java.util.Collection;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author Andrey Rechitsky (arechitsky@gmail.com)
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
FastScanner in = new FastScanner(inputStream);
FastPrinter out = new FastPrinter(outputStream);
TaskC solver = new TaskC();
solver.solve(1, in, out);
out.close();
}
}
class TaskC {
public void solve(int testNumber, FastScanner in, FastPrinter out) {
int n = in.nextInt();
HashMap<String, Set<String>> paths = new HashMap<String, Set<String>>();
for (int i = 0; i < n; i++) {
String url = in.nextLine();
int delim = url.indexOf('/', 7);
String host = delim==-1?url:url.substring(0, delim);
String path = delim==-1?"":url.substring(delim);
if (!paths.containsKey(host)) paths.put(host, new TreeSet<String>());
paths.get(host).add(path);
}
HashMap<String, LinkedList<String>> groups = new HashMap<String, LinkedList<String>>();
int size = 0;
for (String h:paths.keySet()){
StringJoiner p = new StringJoiner("@");
for (String s:paths.get(h)){
p.add(s);
}
String ps = p.toString();
if (!groups.containsKey(ps)) groups.put(ps, new LinkedList<String>());
if (groups.get(ps).size()==1) size++;
groups.get(ps).add(h);
}
out.printLine(size);
for (LinkedList<String> hs:groups.values()){
if (hs.size()<=1) continue;
for (String h:hs){
out.print(h);
out.print(' ');
}
out.printLine();
}
}
}
class FastScanner {
private BufferedReader reader;
private StringTokenizer st;
public FastScanner(InputStream stream) {
this.reader = new BufferedReader(new InputStreamReader(stream));
this.st = new StringTokenizer("");
}
public int nextInt() {
return Integer.parseInt(next());
}
public String next() {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(readLine());
}
return st.nextToken();
}
public String nextLine() {
st = new StringTokenizer("");
return readLine();
}
private String readLine() {
String line = tryReadLine();
if (line == null) throw new InputMismatchException();
return line;
}
private String tryReadLine() {
try {
return reader.readLine();
} catch (IOException e) {
throw new InputMismatchException();
}
}
}
class FastPrinter {
private final PrintWriter writer;
public FastPrinter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public void close() {
writer.close();
}
public void printLine(long i) {
writer.println(i);
}
public void printLine() {
writer.println();
}
public void print(char c) {
writer.print(c);
}
public void print(String s) {
writer.print(s);
}
}
| Java | ["10\nhttp://abacaba.ru/test\nhttp://abacaba.ru/\nhttp://abacaba.com\nhttp://abacaba.com/test\nhttp://abacaba.de/\nhttp://abacaba.ru/test\nhttp://abacaba.de/test\nhttp://abacaba.com/\nhttp://abacaba.com/t\nhttp://abacaba.com/test", "14\nhttp://c\nhttp://ccc.bbbb/aba..b\nhttp://cba.com\nhttp://a.c/aba..b/a\nhttp://abc/\nhttp://a.c/\nhttp://ccc.bbbb\nhttp://ab.ac.bc.aa/\nhttp://a.a.a/\nhttp://ccc.bbbb/\nhttp://cba.com/\nhttp://cba.com/aba..b\nhttp://a.a.a/aba..b/a\nhttp://abc/aba..b/a"] | 5 seconds | ["1\nhttp://abacaba.de http://abacaba.ru", "2\nhttp://cba.com http://ccc.bbbb \nhttp://a.a.a http://a.c http://abc"] | null | Java 8 | standard input | [
"implementation",
"*special",
"sortings",
"data structures",
"binary search",
"strings"
] | 9b35f7df9e21162858a8fac8ee2837a4 | The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of page queries. Then follow n lines each containing exactly one address. Each address is of the form http://<hostname>[/<path>], where: <hostname> consists of lowercase English letters and dots, there are no two consecutive dots, <hostname> doesn't start or finish with a dot. The length of <hostname> is positive and doesn't exceed 20. <path> consists of lowercase English letters, dots and slashes. There are no two consecutive slashes, <path> doesn't start with a slash and its length doesn't exceed 20. Addresses are not guaranteed to be distinct. | 2,100 | First print k — the number of groups of server names that correspond to one website. You should count only groups of size greater than one. Next k lines should contain the description of groups, one group per line. For each group print all server names separated by a single space. You are allowed to print both groups and names inside any group in arbitrary order. | standard output | |
PASSED | 96e9aeb5f19341c381c4c2d198fbc0ba | train_003.jsonl | 1458118800 | There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru.You are given a list of page addresses being queried. For simplicity we consider all addresses to have the form http://<hostname>[/<path>], where: <hostname> — server name (consists of words and maybe some dots separating them), /<path> — optional part, where <path> consists of words separated by slashes. We consider two <hostname> to correspond to one website if for each query to the first <hostname> there will be exactly the same query to the second one and vice versa — for each query to the second <hostname> there will be the same query to the first one. Take a look at the samples for further clarifications.Your goal is to determine the groups of server names that correspond to one website. Ignore groups consisting of the only server name.Please note, that according to the above definition queries http://<hostname> and http://<hostname>/ are different. | 256 megabytes | import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Scanner;
import java.util.TreeSet;
public class Hostname
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int n = in.nextInt();
String prefix = "http://";
int preLen = prefix.length();
ArrayList<HostName> hosts = new ArrayList<HostName>();
HashMap<String, HostName> names = new HashMap<String, HostName>();
for (int i = 0; i < n; i++)
{
String line = in.next();
line = line.substring(preLen);
int slash = line.indexOf('/');
String hostName;
String path;
if (slash == -1)
{
hostName = line;
path = "";
}
else
{
hostName = line.substring(0, slash);
path = slash == -1 ? "" : line.substring(slash);
}
HostName h = names.get(hostName);
if (h == null)
{
h = new HostName(hostName, path);
names.put(hostName, h);
hosts.add(h);
}
else
{
h.paths.add(path);
}
}
in.close();
Collections.sort(hosts);
HostName prevHost = hosts.get(0);
ArrayList<String> currGroup = new ArrayList<String>();
currGroup.add(prevHost.name);
ArrayList<ArrayList<String>> groups = new ArrayList<ArrayList<String>>();
for (int i = 1; i < hosts.size(); i++)
{
HostName currHost = hosts.get(i);
if (prevHost.compareTo(currHost) == 0) currGroup.add(currHost.name);
else
{
if (currGroup.size() > 1) groups.add(currGroup);
currGroup = new ArrayList<String>();
currGroup.add(currHost.name);
}
prevHost = currHost;
}
if (currGroup.size() > 1) groups.add(currGroup);
System.out.println(groups.size());
for (ArrayList<String> g : groups)
{
System.out.print(prefix + g.get(0));
for (int i = 1; i < g.size(); i++) System.out.print(" " + prefix + g.get(i));
System.out.println();
}
}
static class HostName implements Comparable<HostName>
{
public String name;
public TreeSet<String> paths;
HostName(String hostName, String path)
{
name = hostName;
paths = new TreeSet<String>();
paths.add(path);
}
public int compareTo(HostName other)
{
int size = paths.size();
int otherSize = other.paths.size();
if (size == otherSize)
{
Iterator<String> it = paths.iterator();
Iterator<String> oit = other.paths.iterator();
while (it.hasNext())
{
int comp = it.next().compareTo(oit.next());
if (comp != 0) return comp;
}
return 0;
}
if (size < otherSize) return -1;
return 1;
}
}
}
| Java | ["10\nhttp://abacaba.ru/test\nhttp://abacaba.ru/\nhttp://abacaba.com\nhttp://abacaba.com/test\nhttp://abacaba.de/\nhttp://abacaba.ru/test\nhttp://abacaba.de/test\nhttp://abacaba.com/\nhttp://abacaba.com/t\nhttp://abacaba.com/test", "14\nhttp://c\nhttp://ccc.bbbb/aba..b\nhttp://cba.com\nhttp://a.c/aba..b/a\nhttp://abc/\nhttp://a.c/\nhttp://ccc.bbbb\nhttp://ab.ac.bc.aa/\nhttp://a.a.a/\nhttp://ccc.bbbb/\nhttp://cba.com/\nhttp://cba.com/aba..b\nhttp://a.a.a/aba..b/a\nhttp://abc/aba..b/a"] | 5 seconds | ["1\nhttp://abacaba.de http://abacaba.ru", "2\nhttp://cba.com http://ccc.bbbb \nhttp://a.a.a http://a.c http://abc"] | null | Java 8 | standard input | [
"implementation",
"*special",
"sortings",
"data structures",
"binary search",
"strings"
] | 9b35f7df9e21162858a8fac8ee2837a4 | The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of page queries. Then follow n lines each containing exactly one address. Each address is of the form http://<hostname>[/<path>], where: <hostname> consists of lowercase English letters and dots, there are no two consecutive dots, <hostname> doesn't start or finish with a dot. The length of <hostname> is positive and doesn't exceed 20. <path> consists of lowercase English letters, dots and slashes. There are no two consecutive slashes, <path> doesn't start with a slash and its length doesn't exceed 20. Addresses are not guaranteed to be distinct. | 2,100 | First print k — the number of groups of server names that correspond to one website. You should count only groups of size greater than one. Next k lines should contain the description of groups, one group per line. For each group print all server names separated by a single space. You are allowed to print both groups and names inside any group in arbitrary order. | standard output | |
PASSED | 26d4a82aecd9b99e035c873df52f392e | train_003.jsonl | 1458118800 | There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru.You are given a list of page addresses being queried. For simplicity we consider all addresses to have the form http://<hostname>[/<path>], where: <hostname> — server name (consists of words and maybe some dots separating them), /<path> — optional part, where <path> consists of words separated by slashes. We consider two <hostname> to correspond to one website if for each query to the first <hostname> there will be exactly the same query to the second one and vice versa — for each query to the second <hostname> there will be the same query to the first one. Take a look at the samples for further clarifications.Your goal is to determine the groups of server names that correspond to one website. Ignore groups consisting of the only server name.Please note, that according to the above definition queries http://<hostname> and http://<hostname>/ are different. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
/**
*
* @author maxkrivich
*/
public class Main
{
public static void main(String[] args) throws IOException
{
HashMap<String, TreeSet<String>> hosts = new HashMap<>();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine()),
cnt = 0;
Scanner in;
String host;
while (n-- > 0)
{
in = new Scanner(br.readLine());
StringBuilder path = new StringBuilder("$");
in.skip("http://");
in.useDelimiter("/");
host = in.next();
if(in.hasNextLine())
path.append(in.nextLine());
if (!hosts.containsKey(host))
hosts.put(host, new TreeSet<>());
hosts.get(host).add(path.toString());
}
HashMap<String, Set<String>> ans = new HashMap<>();
for(String h:hosts.keySet())
{
StringBuilder sb = new StringBuilder();
for (String s : hosts.get(h))
sb.append(s);
if(!ans.containsKey(sb.toString()))
ans.put(sb.toString(), new TreeSet<>());
ans.get(sb.toString()).add(h);
}
for (String h : ans.keySet())
if (ans.get(h).size() > 1)
cnt++;
System.out.printf("%d\n",cnt);
for (String h : ans.keySet())
if (ans.get(h).size() > 1){
for (String s : ans.get(h))
System.out.printf("http://%s ",s);
System.out.printf("\n");
}
// String a[] = hosts.keySet().toArray(new String[hosts.size()]);
// StringBuilder sb = new StringBuilder();
// HashMap<String, Set<String>> ans = new HashMap<>();
// HashSet<String> g = new HashSet<>();
// for (int i = 0; i < a.length; i++)
// {
// for (int j = i + 1; j < a.length; j++)
// {
// if (eq(hosts.get(a[i]), hosts.get(a[j])))
// {
// if (!ans.containsKey(a[i]) && !g.contains(a[j]))
// {
// ans.put(a[i], new HashSet<>());
// ans.get(a[i]).add(a[j]);
// } else if (ans.containsKey(a[i]) && !g.contains(a[j]))
// {
// ans.get(a[i]).add(a[j]);
// }
// g.add(a[j]);
//// System.out.println(a[i]);
// }
// }
// }
// System.out.println(ans.size());
// String a1[] = ans.keySet().toArray(new String[ans.size()]);
// for (int i = 0; i < a1.length; i++)
// {
// System.out.printf("http://%s ", a1[i]);
// for (String ss : ans.get(a1[i]))
// {
// System.out.printf("http://%s ", ss);
// }
// System.out.println();
// }
}
private static boolean eq(LinkedHashSet<String> a, LinkedHashSet<String> b)
{
if (a.size() != b.size())
{
return false;
}
List aa = new ArrayList(a);
List bb = new ArrayList(b);
Collections.sort(aa);
Collections.sort(bb);
int i = 0;
boolean f = false;
while (i < aa.size())
{
if (aa.get(i).equals(bb.get(i)))
{
i++;
} else
{
break;
}
if (i == aa.size())
{
f = true;
break;
}
}
return f && i != 1;
}
}
| Java | ["10\nhttp://abacaba.ru/test\nhttp://abacaba.ru/\nhttp://abacaba.com\nhttp://abacaba.com/test\nhttp://abacaba.de/\nhttp://abacaba.ru/test\nhttp://abacaba.de/test\nhttp://abacaba.com/\nhttp://abacaba.com/t\nhttp://abacaba.com/test", "14\nhttp://c\nhttp://ccc.bbbb/aba..b\nhttp://cba.com\nhttp://a.c/aba..b/a\nhttp://abc/\nhttp://a.c/\nhttp://ccc.bbbb\nhttp://ab.ac.bc.aa/\nhttp://a.a.a/\nhttp://ccc.bbbb/\nhttp://cba.com/\nhttp://cba.com/aba..b\nhttp://a.a.a/aba..b/a\nhttp://abc/aba..b/a"] | 5 seconds | ["1\nhttp://abacaba.de http://abacaba.ru", "2\nhttp://cba.com http://ccc.bbbb \nhttp://a.a.a http://a.c http://abc"] | null | Java 8 | standard input | [
"implementation",
"*special",
"sortings",
"data structures",
"binary search",
"strings"
] | 9b35f7df9e21162858a8fac8ee2837a4 | The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of page queries. Then follow n lines each containing exactly one address. Each address is of the form http://<hostname>[/<path>], where: <hostname> consists of lowercase English letters and dots, there are no two consecutive dots, <hostname> doesn't start or finish with a dot. The length of <hostname> is positive and doesn't exceed 20. <path> consists of lowercase English letters, dots and slashes. There are no two consecutive slashes, <path> doesn't start with a slash and its length doesn't exceed 20. Addresses are not guaranteed to be distinct. | 2,100 | First print k — the number of groups of server names that correspond to one website. You should count only groups of size greater than one. Next k lines should contain the description of groups, one group per line. For each group print all server names separated by a single space. You are allowed to print both groups and names inside any group in arbitrary order. | standard output | |
PASSED | df4d831754b1f20eaee7cde740e0e1be | train_003.jsonl | 1458118800 | There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru.You are given a list of page addresses being queried. For simplicity we consider all addresses to have the form http://<hostname>[/<path>], where: <hostname> — server name (consists of words and maybe some dots separating them), /<path> — optional part, where <path> consists of words separated by slashes. We consider two <hostname> to correspond to one website if for each query to the first <hostname> there will be exactly the same query to the second one and vice versa — for each query to the second <hostname> there will be the same query to the first one. Take a look at the samples for further clarifications.Your goal is to determine the groups of server names that correspond to one website. Ignore groups consisting of the only server name.Please note, that according to the above definition queries http://<hostname> and http://<hostname>/ are different. | 256 megabytes | import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class CrocC implements Runnable {
BufferedReader in;
PrintWriter out;
StringTokenizer tok = new StringTokenizer("");
void init() throws FileNotFoundException {
try {
in = new BufferedReader(new FileReader("input.txt"));
out = new PrintWriter("output.txt");
} catch (Exception e) {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
}
}
String readString() throws IOException {
while (!tok.hasMoreTokens()) {
try {
tok = new StringTokenizer(in.readLine());
} catch (Exception e) {
return null;
}
}
return tok.nextToken();
}
int readInt() throws IOException {
return Integer.parseInt(readString());
}
int[] readIntArray(int size) throws IOException {
int[] res = new int[size];
for (int i = 0; i < size; i++) {
res[i] = readInt();
}
return res;
}
long readLong() throws IOException {
return Long.parseLong(readString());
}
double readDouble() throws IOException {
return Double.parseDouble(readString());
}
public static void main(String[] args) {
new Thread(null, new CrocC(), "", 1l * 200 * 1024 * 1024).start();
}
long timeBegin, timeEnd;
void time() {
timeEnd = System.currentTimeMillis();
System.err.println("Time = " + (timeEnd - timeBegin));
}
long memoryTotal, memoryFree;
void memory() {
memoryFree = Runtime.getRuntime().freeMemory();
System.err.println("Memory = " + ((memoryTotal - memoryFree) >> 10)
+ " KB");
}
public void run() {
try {
timeBegin = System.currentTimeMillis();
memoryTotal = Runtime.getRuntime().freeMemory();
init();
solve();
out.close();
if (System.getProperty("ONLINE_JUDGE") == null) {
time();
memory();
}
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
}
}
String getHostName(String s) {
int index = s.indexOf('/', "http://".length());
if (index < 0) return s;
return s.substring(0, index);
}
String getPage(String s) {
String host = getHostName(s);
if (host.length() == s.length()) return "";
return s.substring(host.length());
}
long p1;
long p2;
long m1;
long m2;
void initHashModules() {
Random rnd = new Random();
p1 = BigInteger.valueOf(3000 + rnd.nextInt(500))
.nextProbablePrime().intValue();
p2 = BigInteger.valueOf(4000 + rnd.nextInt(500))
.nextProbablePrime().intValue();
m1 = BigInteger.valueOf((int) 1e9 + rnd.nextInt(500))
.nextProbablePrime().intValue();
m2 = BigInteger.valueOf((int) 1e9 + (int) 1e6 + rnd.nextInt(500))
.nextProbablePrime().intValue();
}
long hash(long old, char x, long p, long m) {
return (old * p + x) % m;
}
long calcHash(String[] array) {
long hash1 = 0;
long hash2 = 0;
for (String s : array) {
for (int i = 0; i < s.length(); i++) {
hash1 = hash(hash1, s.charAt(i), p1, m1);
hash2 = hash(hash2, s.charAt(i), p2, m2);
}
hash1 = hash(hash1, '$', p1, m1);
hash2 = hash(hash2, '$', p2, m2);
}
return (hash1 << 32) | hash2;
}
void solve() throws IOException {
initHashModules();
HashMap<String, TreeSet<String>> map = new HashMap<>();
int n = readInt();
for (int i = 0; i < n; i++) {
String s = readString();
String host = getHostName(s);
String page = getPage(s);
TreeSet<String> set = map.get(host);
if (set == null) {
set = new TreeSet<>();
map.put(host, set);
}
set.add(page);
}
HashMap<Long, ArrayList<String>> answer = new HashMap<>();
for (Map.Entry<String, TreeSet<String>> e : map.entrySet()) {
String[] s = e.getValue().toArray(new String[e.getValue().size()]);
long hash = calcHash(s);
ArrayList<String> list = answer.get(hash);
if (list == null) {
list = new ArrayList<>();
answer.put(hash, list);
}
list.add(e.getKey());
}
ArrayList<String> ans = new ArrayList<>();
for (Map.Entry<Long, ArrayList<String>> e : answer.entrySet()) {
if (e.getValue().size() > 1) {
StringBuilder sb = new StringBuilder();
for (String s : e.getValue()) {
sb.append(s);
sb.append(" ");
}
ans.add(sb.toString());
}
}
out.println(ans.size());
for (String s : ans) {
out.println(s);
}
}
} | Java | ["10\nhttp://abacaba.ru/test\nhttp://abacaba.ru/\nhttp://abacaba.com\nhttp://abacaba.com/test\nhttp://abacaba.de/\nhttp://abacaba.ru/test\nhttp://abacaba.de/test\nhttp://abacaba.com/\nhttp://abacaba.com/t\nhttp://abacaba.com/test", "14\nhttp://c\nhttp://ccc.bbbb/aba..b\nhttp://cba.com\nhttp://a.c/aba..b/a\nhttp://abc/\nhttp://a.c/\nhttp://ccc.bbbb\nhttp://ab.ac.bc.aa/\nhttp://a.a.a/\nhttp://ccc.bbbb/\nhttp://cba.com/\nhttp://cba.com/aba..b\nhttp://a.a.a/aba..b/a\nhttp://abc/aba..b/a"] | 5 seconds | ["1\nhttp://abacaba.de http://abacaba.ru", "2\nhttp://cba.com http://ccc.bbbb \nhttp://a.a.a http://a.c http://abc"] | null | Java 8 | standard input | [
"implementation",
"*special",
"sortings",
"data structures",
"binary search",
"strings"
] | 9b35f7df9e21162858a8fac8ee2837a4 | The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of page queries. Then follow n lines each containing exactly one address. Each address is of the form http://<hostname>[/<path>], where: <hostname> consists of lowercase English letters and dots, there are no two consecutive dots, <hostname> doesn't start or finish with a dot. The length of <hostname> is positive and doesn't exceed 20. <path> consists of lowercase English letters, dots and slashes. There are no two consecutive slashes, <path> doesn't start with a slash and its length doesn't exceed 20. Addresses are not guaranteed to be distinct. | 2,100 | First print k — the number of groups of server names that correspond to one website. You should count only groups of size greater than one. Next k lines should contain the description of groups, one group per line. For each group print all server names separated by a single space. You are allowed to print both groups and names inside any group in arbitrary order. | standard output | |
PASSED | 4ede0034225a1d7545b68cc1681f23a8 | train_003.jsonl | 1458118800 | There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru.You are given a list of page addresses being queried. For simplicity we consider all addresses to have the form http://<hostname>[/<path>], where: <hostname> — server name (consists of words and maybe some dots separating them), /<path> — optional part, where <path> consists of words separated by slashes. We consider two <hostname> to correspond to one website if for each query to the first <hostname> there will be exactly the same query to the second one and vice versa — for each query to the second <hostname> there will be the same query to the first one. Take a look at the samples for further clarifications.Your goal is to determine the groups of server names that correspond to one website. Ignore groups consisting of the only server name.Please note, that according to the above definition queries http://<hostname> and http://<hostname>/ are different. | 256 megabytes |
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
/**
* Mar 16, 2016 | 12:57:31 PM
* <pre>
* <u>Description</u>
*
* </pre>
*
* @author Essiennta Emmanuel (colourfulemmanuel@gmail.com)
*/
public class ProblemC{
void solve(String[] addresses){
Map<String, TreeSet<String>> hostMap = new HashMap<>();
for (int i = 0; i < addresses.length; i++) {
String address = addresses[i];
int j = 7;
while (++j != address.length() && address.charAt(j) != '/');
String host = address.substring(7, j);
String path = address.substring(j);
TreeSet<String> hostPaths = hostMap.get(host);
if (hostPaths == null) {
hostPaths = new TreeSet<String>();
hostMap.put(host, hostPaths);
}
hostPaths.add(path.isEmpty() ? "$" : path);
}
Map<String, Set<String>> newMap = new HashMap<>();
for (String host : hostMap.keySet()) {
TreeSet<String> set = hostMap.get(host);
String curr = set.first();
StringBuilder coded = new StringBuilder();
coded.append(curr);
String higher;
while ((higher = set.higher(curr)) != null) {
coded.append('|').append(higher);
curr = higher;
}
String codedString = coded.toString();
Set<String> val = newMap.get(codedString);
if (val == null) {
val = new HashSet<>();
newMap.put(codedString, val);
}
val.add(host);
}
StringBuilder sb = new StringBuilder();
int cnt = 0;
for (Set<String> set : newMap.values())
if (set.size() > 1) {
for (String elem : set)
sb.append(String.format("http://%s ",elem));
sb.append('\n');
cnt++;
}
System.out.println(cnt);
System.out.print(sb);
}
public static void main(String[] args){
try (Scanner sc = new Scanner(System.in)) {
int n = sc.nextInt();
String[] addresses = new String[n];
for (int i = 0; i < n; i++)
addresses[i] = sc.next();
new ProblemC().solve(addresses);
}
}
}
| Java | ["10\nhttp://abacaba.ru/test\nhttp://abacaba.ru/\nhttp://abacaba.com\nhttp://abacaba.com/test\nhttp://abacaba.de/\nhttp://abacaba.ru/test\nhttp://abacaba.de/test\nhttp://abacaba.com/\nhttp://abacaba.com/t\nhttp://abacaba.com/test", "14\nhttp://c\nhttp://ccc.bbbb/aba..b\nhttp://cba.com\nhttp://a.c/aba..b/a\nhttp://abc/\nhttp://a.c/\nhttp://ccc.bbbb\nhttp://ab.ac.bc.aa/\nhttp://a.a.a/\nhttp://ccc.bbbb/\nhttp://cba.com/\nhttp://cba.com/aba..b\nhttp://a.a.a/aba..b/a\nhttp://abc/aba..b/a"] | 5 seconds | ["1\nhttp://abacaba.de http://abacaba.ru", "2\nhttp://cba.com http://ccc.bbbb \nhttp://a.a.a http://a.c http://abc"] | null | Java 8 | standard input | [
"implementation",
"*special",
"sortings",
"data structures",
"binary search",
"strings"
] | 9b35f7df9e21162858a8fac8ee2837a4 | The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of page queries. Then follow n lines each containing exactly one address. Each address is of the form http://<hostname>[/<path>], where: <hostname> consists of lowercase English letters and dots, there are no two consecutive dots, <hostname> doesn't start or finish with a dot. The length of <hostname> is positive and doesn't exceed 20. <path> consists of lowercase English letters, dots and slashes. There are no two consecutive slashes, <path> doesn't start with a slash and its length doesn't exceed 20. Addresses are not guaranteed to be distinct. | 2,100 | First print k — the number of groups of server names that correspond to one website. You should count only groups of size greater than one. Next k lines should contain the description of groups, one group per line. For each group print all server names separated by a single space. You are allowed to print both groups and names inside any group in arbitrary order. | standard output | |
PASSED | 89030102e2a405feb2e37e40e6c32832 | train_003.jsonl | 1458118800 | There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru.You are given a list of page addresses being queried. For simplicity we consider all addresses to have the form http://<hostname>[/<path>], where: <hostname> — server name (consists of words and maybe some dots separating them), /<path> — optional part, where <path> consists of words separated by slashes. We consider two <hostname> to correspond to one website if for each query to the first <hostname> there will be exactly the same query to the second one and vice versa — for each query to the second <hostname> there will be the same query to the first one. Take a look at the samples for further clarifications.Your goal is to determine the groups of server names that correspond to one website. Ignore groups consisting of the only server name.Please note, that according to the above definition queries http://<hostname> and http://<hostname>/ are different. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class C {
static void solve() throws IOException {
int n = Integer.parseInt( in.readLine() );
TreeMap<String, TreeSet<String>> stoq = new TreeMap<>();
String http = "http://";
for ( int i = 0; i < n; i ++ ) {
String s = in.readLine().substring( http.length() );
int slash = s.indexOf( '/' );
if ( slash < 0 ) {
slash = s.length();
}
String server = s.substring( 0, slash );
String path = s.substring( slash );
if ( !stoq.containsKey( server ) ) {
stoq.put( server, new TreeSet<>() );
}
stoq.get( server ).add( path );
}
TreeSet<Server> servers = new TreeSet<>();
for ( Map.Entry<String, TreeSet<String>> entry : stoq.entrySet() ) {
Server server = new Server( entry.getKey(), entry.getValue() );
if ( servers.contains( server ) ) {
servers.ceiling( server ).servers.add( entry.getKey() );
} else {
servers.add( server );
}
}
TreeSet<Server> serversCopy = new TreeSet<>( servers );
for ( Server server : serversCopy ) {
if ( server.servers.size() == 1 ) {
servers.remove( server );
}
}
out.println( servers.size() );
for ( Server server : servers ) {
for ( String s : server.servers ) {
out.print( http + s + " " );
}
out.println();
}
}
private static class Server implements Comparable<Server> {
TreeSet<String> servers;
TreeSet<String> paths;
Server( String server, TreeSet<String> Paths ) {
servers = new TreeSet<>();
servers.add( server );
paths = Paths;
}
@Override
public int compareTo( Server s ) {
Iterator<String> selfPathsItr = paths.iterator();
Iterator<String> otherPathsItr = s.paths.iterator();
while ( selfPathsItr.hasNext() && otherPathsItr.hasNext() ) {
String selfNext = selfPathsItr.next();
String otherNext = otherPathsItr.next();
int cmp = selfNext.compareTo( otherNext );
if ( cmp != 0 ) {
return cmp;
}
}
if ( selfPathsItr.hasNext() ) {
return 1;
} else if ( otherPathsItr.hasNext() ) {
return -1;
} else {
return 0;
}
}
}
static BufferedReader in;
// static StreamTokenizer in;
static PrintWriter out;
// static int nextInt() throws IOException {
// in.nextToken();
// return ( int ) in.nval;
// }
public static void main( String[] args ) throws IOException {
in = new BufferedReader( new InputStreamReader( System.in ) );
out = new PrintWriter( System.out );
solve();
out.close();
}
}
| Java | ["10\nhttp://abacaba.ru/test\nhttp://abacaba.ru/\nhttp://abacaba.com\nhttp://abacaba.com/test\nhttp://abacaba.de/\nhttp://abacaba.ru/test\nhttp://abacaba.de/test\nhttp://abacaba.com/\nhttp://abacaba.com/t\nhttp://abacaba.com/test", "14\nhttp://c\nhttp://ccc.bbbb/aba..b\nhttp://cba.com\nhttp://a.c/aba..b/a\nhttp://abc/\nhttp://a.c/\nhttp://ccc.bbbb\nhttp://ab.ac.bc.aa/\nhttp://a.a.a/\nhttp://ccc.bbbb/\nhttp://cba.com/\nhttp://cba.com/aba..b\nhttp://a.a.a/aba..b/a\nhttp://abc/aba..b/a"] | 5 seconds | ["1\nhttp://abacaba.de http://abacaba.ru", "2\nhttp://cba.com http://ccc.bbbb \nhttp://a.a.a http://a.c http://abc"] | null | Java 8 | standard input | [
"implementation",
"*special",
"sortings",
"data structures",
"binary search",
"strings"
] | 9b35f7df9e21162858a8fac8ee2837a4 | The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of page queries. Then follow n lines each containing exactly one address. Each address is of the form http://<hostname>[/<path>], where: <hostname> consists of lowercase English letters and dots, there are no two consecutive dots, <hostname> doesn't start or finish with a dot. The length of <hostname> is positive and doesn't exceed 20. <path> consists of lowercase English letters, dots and slashes. There are no two consecutive slashes, <path> doesn't start with a slash and its length doesn't exceed 20. Addresses are not guaranteed to be distinct. | 2,100 | First print k — the number of groups of server names that correspond to one website. You should count only groups of size greater than one. Next k lines should contain the description of groups, one group per line. For each group print all server names separated by a single space. You are allowed to print both groups and names inside any group in arbitrary order. | standard output | |
PASSED | 8c9be8e3059a4c0ba2286995f95ed4ef | train_003.jsonl | 1458118800 | There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru.You are given a list of page addresses being queried. For simplicity we consider all addresses to have the form http://<hostname>[/<path>], where: <hostname> — server name (consists of words and maybe some dots separating them), /<path> — optional part, where <path> consists of words separated by slashes. We consider two <hostname> to correspond to one website if for each query to the first <hostname> there will be exactly the same query to the second one and vice versa — for each query to the second <hostname> there will be the same query to the first one. Take a look at the samples for further clarifications.Your goal is to determine the groups of server names that correspond to one website. Ignore groups consisting of the only server name.Please note, that according to the above definition queries http://<hostname> and http://<hostname>/ are different. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.StringTokenizer;
import java.util.TreeSet;
/*
10
http://abacaba.ru/test
http://abacaba.ru/
http://abacaba.com
http://abacaba.com/test
http://abacaba.de/
http://abacaba.ru/test
http://abacaba.de/test
http://abacaba.com/
http://abacaba.com/t
http://abacaba.com/test
*/
public class HostnameAliases {
public static void main(String[] args) {
FastScanner fs=new FastScanner();
PrintWriter out=new PrintWriter(System.out);
int n=fs.nextInt();
String[] prefixes=new String[n], suffixes=new String[n];
for (int i=0; i<n; i++) {
String line=fs.next();
int index=line.substring(7).indexOf('/');
if (index==-1) {
prefixes[i]=line;
suffixes[i]="";
}
else {
prefixes[i]=line.substring(0, index+7);
suffixes[i]=line.substring(index+7);
}
// System.out.println(prefixes[i]+" "+suffixes[i]);
}
HashMap<String, TreeSet<String>> suffixesOf=new HashMap<>();
for (int i=0; i<n; i++) {
if (!suffixesOf.containsKey(prefixes[i])) suffixesOf.put(prefixes[i], new TreeSet<>());
suffixesOf.get(prefixes[i]).add(suffixes[i]);
}
HashMap<HarmeyerHash, TreeSet<String>> thingsWithHash=new HashMap<>();
for (Entry<String, TreeSet<String>> entries:suffixesOf.entrySet()) {
String prefix=entries.getKey();
HarmeyerHash hash=new HarmeyerHash();
for (String s:entries.getValue()) {
for (char c:s.toCharArray()) hash.add(c);
hash.add('$');
}
if (!thingsWithHash.containsKey(hash)) thingsWithHash.put(hash, new TreeSet<>());
thingsWithHash.get(hash).add(prefix);
}
ArrayList<TreeSet<String>> toPrint=new ArrayList<>();
for (Entry<HarmeyerHash, TreeSet<String>> entry:thingsWithHash.entrySet()) {
if (entry.getValue().size()>1)
toPrint.add(entry.getValue());
}
out.println(toPrint.size());
for (TreeSet<String> ts:toPrint) {
for (String s:ts) {
out.print(s+" ");
}
out.println();
}
out.close();
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
public String next() {
while (!st.hasMoreElements())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
static class HarmeyerHash implements Comparable<HarmeyerHash> {
static final long m1=8675309, m2=1_000_000_007;
private long v1=0, v2=0;
static final long s1=257, s2=619;
public void add(char o) {
v1=(v1*s1+o)%m1;
v2=(v2*s2+o)%m2;
}
public int compareTo(HarmeyerHash o) {
if (v1!=o.v1)
return Long.compare(v1, o.v1);
return Long.compare(v2, o.v2);
}
public boolean equals(Object o) {
return compareTo((HarmeyerHash)o)==0;
}
public int hashCode() {
return (int)v1;
}
public HarmeyerHash clone() {
HarmeyerHash toReturn=new HarmeyerHash();
toReturn.v1=v1;
toReturn.v2=v2;
return toReturn;
}
}
}
| Java | ["10\nhttp://abacaba.ru/test\nhttp://abacaba.ru/\nhttp://abacaba.com\nhttp://abacaba.com/test\nhttp://abacaba.de/\nhttp://abacaba.ru/test\nhttp://abacaba.de/test\nhttp://abacaba.com/\nhttp://abacaba.com/t\nhttp://abacaba.com/test", "14\nhttp://c\nhttp://ccc.bbbb/aba..b\nhttp://cba.com\nhttp://a.c/aba..b/a\nhttp://abc/\nhttp://a.c/\nhttp://ccc.bbbb\nhttp://ab.ac.bc.aa/\nhttp://a.a.a/\nhttp://ccc.bbbb/\nhttp://cba.com/\nhttp://cba.com/aba..b\nhttp://a.a.a/aba..b/a\nhttp://abc/aba..b/a"] | 5 seconds | ["1\nhttp://abacaba.de http://abacaba.ru", "2\nhttp://cba.com http://ccc.bbbb \nhttp://a.a.a http://a.c http://abc"] | null | Java 8 | standard input | [
"implementation",
"*special",
"sortings",
"data structures",
"binary search",
"strings"
] | 9b35f7df9e21162858a8fac8ee2837a4 | The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of page queries. Then follow n lines each containing exactly one address. Each address is of the form http://<hostname>[/<path>], where: <hostname> consists of lowercase English letters and dots, there are no two consecutive dots, <hostname> doesn't start or finish with a dot. The length of <hostname> is positive and doesn't exceed 20. <path> consists of lowercase English letters, dots and slashes. There are no two consecutive slashes, <path> doesn't start with a slash and its length doesn't exceed 20. Addresses are not guaranteed to be distinct. | 2,100 | First print k — the number of groups of server names that correspond to one website. You should count only groups of size greater than one. Next k lines should contain the description of groups, one group per line. For each group print all server names separated by a single space. You are allowed to print both groups and names inside any group in arbitrary order. | standard output | |
PASSED | e6dec31b3166c8b92ea8a5b8407d9808 | train_003.jsonl | 1458118800 | There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru.You are given a list of page addresses being queried. For simplicity we consider all addresses to have the form http://<hostname>[/<path>], where: <hostname> — server name (consists of words and maybe some dots separating them), /<path> — optional part, where <path> consists of words separated by slashes. We consider two <hostname> to correspond to one website if for each query to the first <hostname> there will be exactly the same query to the second one and vice versa — for each query to the second <hostname> there will be the same query to the first one. Take a look at the samples for further clarifications.Your goal is to determine the groups of server names that correspond to one website. Ignore groups consisting of the only server name.Please note, that according to the above definition queries http://<hostname> and http://<hostname>/ are different. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.StringTokenizer;
import java.util.TreeSet;
/*
10
http://abacaba.ru/test
http://abacaba.ru/
http://abacaba.com
http://abacaba.com/test
http://abacaba.de/
http://abacaba.ru/test
http://abacaba.de/test
http://abacaba.com/
http://abacaba.com/t
http://abacaba.com/test
*/
public class HostnameAliases {
public static void main(String[] args) {
FastScanner fs=new FastScanner();
int n=fs.nextInt();
String[] prefixes=new String[n], suffixes=new String[n];
for (int i=0; i<n; i++) {
String line=fs.next();
int index=line.substring(7).indexOf('/');
if (index==-1) {
prefixes[i]=line;
suffixes[i]="";
}
else {
prefixes[i]=line.substring(0, index+7);
suffixes[i]=line.substring(index+7);
}
// System.out.println(prefixes[i]+" "+suffixes[i]);
}
HashMap<String, TreeSet<String>> suffixesOf=new HashMap<>();
for (int i=0; i<n; i++) {
if (!suffixesOf.containsKey(prefixes[i])) suffixesOf.put(prefixes[i], new TreeSet<>());
suffixesOf.get(prefixes[i]).add(suffixes[i]);
}
HashMap<HarmeyerHash, TreeSet<String>> thingsWithHash=new HashMap<>();
for (Entry<String, TreeSet<String>> entries:suffixesOf.entrySet()) {
String prefix=entries.getKey();
HarmeyerHash hash=new HarmeyerHash();
for (String s:entries.getValue()) {
for (char c:s.toCharArray()) hash.add(c);
hash.add('$');
}
if (!thingsWithHash.containsKey(hash)) thingsWithHash.put(hash, new TreeSet<>());
thingsWithHash.get(hash).add(prefix);
}
ArrayList<TreeSet<String>> toPrint=new ArrayList<>();
for (Entry<HarmeyerHash, TreeSet<String>> entry:thingsWithHash.entrySet()) {
if (entry.getValue().size()>1)
toPrint.add(entry.getValue());
}
System.out.println(toPrint.size());
for (TreeSet<String> ts:toPrint) {
for (String s:ts) {
System.out.print(s+" ");
}
System.out.println();
}
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
public String next() {
while (!st.hasMoreElements())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
static class HarmeyerHash implements Comparable<HarmeyerHash> {
static final long m1=8675309, m2=1_000_000_007;
private long v1=0, v2=0;
static final long s1=257, s2=619;
public void add(char o) {
v1=(v1*s1+o)%m1;
v2=(v2*s2+o)%m2;
}
public int compareTo(HarmeyerHash o) {
if (v1!=o.v1)
return Long.compare(v1, o.v1);
return Long.compare(v2, o.v2);
}
public boolean equals(Object o) {
return compareTo((HarmeyerHash)o)==0;
}
public int hashCode() {
return (int)v1;
}
public HarmeyerHash clone() {
HarmeyerHash toReturn=new HarmeyerHash();
toReturn.v1=v1;
toReturn.v2=v2;
return toReturn;
}
}
}
| Java | ["10\nhttp://abacaba.ru/test\nhttp://abacaba.ru/\nhttp://abacaba.com\nhttp://abacaba.com/test\nhttp://abacaba.de/\nhttp://abacaba.ru/test\nhttp://abacaba.de/test\nhttp://abacaba.com/\nhttp://abacaba.com/t\nhttp://abacaba.com/test", "14\nhttp://c\nhttp://ccc.bbbb/aba..b\nhttp://cba.com\nhttp://a.c/aba..b/a\nhttp://abc/\nhttp://a.c/\nhttp://ccc.bbbb\nhttp://ab.ac.bc.aa/\nhttp://a.a.a/\nhttp://ccc.bbbb/\nhttp://cba.com/\nhttp://cba.com/aba..b\nhttp://a.a.a/aba..b/a\nhttp://abc/aba..b/a"] | 5 seconds | ["1\nhttp://abacaba.de http://abacaba.ru", "2\nhttp://cba.com http://ccc.bbbb \nhttp://a.a.a http://a.c http://abc"] | null | Java 8 | standard input | [
"implementation",
"*special",
"sortings",
"data structures",
"binary search",
"strings"
] | 9b35f7df9e21162858a8fac8ee2837a4 | The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of page queries. Then follow n lines each containing exactly one address. Each address is of the form http://<hostname>[/<path>], where: <hostname> consists of lowercase English letters and dots, there are no two consecutive dots, <hostname> doesn't start or finish with a dot. The length of <hostname> is positive and doesn't exceed 20. <path> consists of lowercase English letters, dots and slashes. There are no two consecutive slashes, <path> doesn't start with a slash and its length doesn't exceed 20. Addresses are not guaranteed to be distinct. | 2,100 | First print k — the number of groups of server names that correspond to one website. You should count only groups of size greater than one. Next k lines should contain the description of groups, one group per line. For each group print all server names separated by a single space. You are allowed to print both groups and names inside any group in arbitrary order. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.