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 | 707f6fc959fe81d96752b9b6675ed3a6 | train_001.jsonl | 1593610500 | A mad scientist Dr.Jubal has made a competitive programming task. Try to solve it!You are given integers $$$n,k$$$. Construct a grid $$$A$$$ with size $$$n \times n$$$ consisting of integers $$$0$$$ and $$$1$$$. The very important condition should be satisfied: the sum of all elements in the grid is exactly $$$k$$$. In other words, the number of $$$1$$$ in the grid is equal to $$$k$$$.Let's define: $$$A_{i,j}$$$ as the integer in the $$$i$$$-th row and the $$$j$$$-th column. $$$R_i = A_{i,1}+A_{i,2}+...+A_{i,n}$$$ (for all $$$1 \le i \le n$$$). $$$C_j = A_{1,j}+A_{2,j}+...+A_{n,j}$$$ (for all $$$1 \le j \le n$$$). In other words, $$$R_i$$$ are row sums and $$$C_j$$$ are column sums of the grid $$$A$$$. For the grid $$$A$$$ let's define the value $$$f(A) = (\max(R)-\min(R))^2 + (\max(C)-\min(C))^2$$$ (here for an integer sequence $$$X$$$ we define $$$\max(X)$$$ as the maximum value in $$$X$$$ and $$$\min(X)$$$ as the minimum value in $$$X$$$). Find any grid $$$A$$$, which satisfies the following condition. Among such grids find any, for which the value $$$f(A)$$$ is the minimum possible. Among such tables, you can find any. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
public class D {
public static void main(String[] args)throws IOException {
FastIO sc = new FastIO(System.in);
PrintWriter out = new PrintWriter(System.out);
int t = sc.nextInt();
while(t-->0) {
int n = sc.nextInt();
int k = sc.nextInt();
int board[][] = new int[n][n];
for(int i[] : board) {
Arrays.fill(i, 0);
}
int ok = k/n;
int over = k-(ok*n);
for(int i=0; i<over; ++i) {
for(int j=i; j<i+ok+1; ++j) {
board[i][j%n] = 1;
}
}
for(int i=over; i<n; ++i) {
for(int j=i; j<i+ok; ++j) {
board[i][j%n]= 1;
}
}
if(over>0) {
System.out.println(2);
}else {
System.out.println(0);
}
for(int i=0; i<n; ++i) {
for(int j=0; j<n; ++j) {
System.out.print(board[i][j]);
}
System.out.println();
}
}
out.close();
}
static class FastIO {
InputStream dis;
byte[] buffer = new byte[1 << 17];
int pointer = 0;
public FastIO(String fileName) throws IOException {
dis = new FileInputStream(fileName);
}
public FastIO(InputStream is) throws IOException {
dis = is;
}
int nextInt() throws IOException {
int ret = 0;
byte b;
do {
b = nextByte();
} while (b <= ' ');
boolean negative = false;
if (b == '-') {
negative = true;
b = nextByte();
}
while (b >= '0' && b <= '9') {
ret = 10 * ret + b - '0';
b = nextByte();
}
return (negative) ? -ret : ret;
}
long nextLong() throws IOException {
long ret = 0;
byte b;
do {
b = nextByte();
} while (b <= ' ');
boolean negative = false;
if (b == '-') {
negative = true;
b = nextByte();
}
while (b >= '0' && b <= '9') {
ret = 10 * ret + b - '0';
b = nextByte();
}
return (negative) ? -ret : ret;
}
byte nextByte() throws IOException {
if (pointer == buffer.length) {
dis.read(buffer, 0, buffer.length);
pointer = 0;
}
return buffer[pointer++];
}
String next() throws IOException {
StringBuffer ret = new StringBuffer();
byte b;
do {
b = nextByte();
} while (b <= ' ');
while (b > ' ') {
ret.appendCodePoint(b);
b = nextByte();
}
return ret.toString();
}
}
}
| Java | ["4\n2 2\n3 8\n1 0\n4 16"] | 1 second | ["0\n10\n01\n2\n111\n111\n101\n0\n0\n0\n1111\n1111\n1111\n1111"] | NoteIn the first test case, the sum of all elements in the grid is equal to $$$2$$$, so the condition is satisfied. $$$R_1 = 1, R_2 = 1$$$ and $$$C_1 = 1, C_2 = 1$$$. Then, $$$f(A) = (1-1)^2 + (1-1)^2 = 0$$$, which is the minimum possible value of $$$f(A)$$$.In the second test case, the sum of all elements in the grid is equal to $$$8$$$, so the condition is satisfied. $$$R_1 = 3, R_2 = 3, R_3 = 2$$$ and $$$C_1 = 3, C_2 = 2, C_3 = 3$$$. Then, $$$f(A) = (3-2)^2 + (3-2)^2 = 2$$$. It can be proven, that it is the minimum possible value of $$$f(A)$$$. | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"greedy"
] | 0f18382d450be90edf1fd1a3770b232b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Next $$$t$$$ lines contain descriptions of test cases. For each test case the only line contains two integers $$$n$$$, $$$k$$$ $$$(1 \le n \le 300, 0 \le k \le n^2)$$$. It is guaranteed that the sum of $$$n^2$$$ for all test cases does not exceed $$$10^5$$$. | 1,600 | For each test case, firstly print the minimum possible value of $$$f(A)$$$ among all tables, for which the condition is satisfied. After that, print $$$n$$$ lines contain $$$n$$$ characters each. The $$$j$$$-th character in the $$$i$$$-th line should be equal to $$$A_{i,j}$$$. If there are multiple answers you can print any. | standard output | |
PASSED | 22ba90354606ece1910b810e0fdced80 | train_001.jsonl | 1593610500 | A mad scientist Dr.Jubal has made a competitive programming task. Try to solve it!You are given integers $$$n,k$$$. Construct a grid $$$A$$$ with size $$$n \times n$$$ consisting of integers $$$0$$$ and $$$1$$$. The very important condition should be satisfied: the sum of all elements in the grid is exactly $$$k$$$. In other words, the number of $$$1$$$ in the grid is equal to $$$k$$$.Let's define: $$$A_{i,j}$$$ as the integer in the $$$i$$$-th row and the $$$j$$$-th column. $$$R_i = A_{i,1}+A_{i,2}+...+A_{i,n}$$$ (for all $$$1 \le i \le n$$$). $$$C_j = A_{1,j}+A_{2,j}+...+A_{n,j}$$$ (for all $$$1 \le j \le n$$$). In other words, $$$R_i$$$ are row sums and $$$C_j$$$ are column sums of the grid $$$A$$$. For the grid $$$A$$$ let's define the value $$$f(A) = (\max(R)-\min(R))^2 + (\max(C)-\min(C))^2$$$ (here for an integer sequence $$$X$$$ we define $$$\max(X)$$$ as the maximum value in $$$X$$$ and $$$\min(X)$$$ as the minimum value in $$$X$$$). Find any grid $$$A$$$, which satisfies the following condition. Among such grids find any, for which the value $$$f(A)$$$ is the minimum possible. Among such tables, you can find any. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Learning {
static PrintWriter out;
public static void main(String[] args) throws Exception {
FastInput in = new FastInput();
StringBuilder st = new StringBuilder();
int t = in.nextInt();
while (t-- > 0) {
int n = in.nextInt();
int k = in.nextInt();
int[][] arr = new int[n][n];
int p = 0;
int q = 0;
int c = k;
while (k-- > 0) {
arr[p][q] = 1;
p = p + 1;
q = (q + 1) % n;
if (p == n) {
p = 0;
q = (q + 1) % n;
}
}
if (c % n == 0) {
st.append(0).append("\n");
} else {
st.append(2).append("\n");
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
st.append(arr[i][j]);
}
st.append("\n");
}
}
System.out.print(st.toString());
}
}
class FastInput {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
String next() throws IOException {
if (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
Integer nextInt() throws IOException {
return Integer.parseInt(next());
}
Long nextLong() throws IOException {
return Long.parseLong(next());
}
} | Java | ["4\n2 2\n3 8\n1 0\n4 16"] | 1 second | ["0\n10\n01\n2\n111\n111\n101\n0\n0\n0\n1111\n1111\n1111\n1111"] | NoteIn the first test case, the sum of all elements in the grid is equal to $$$2$$$, so the condition is satisfied. $$$R_1 = 1, R_2 = 1$$$ and $$$C_1 = 1, C_2 = 1$$$. Then, $$$f(A) = (1-1)^2 + (1-1)^2 = 0$$$, which is the minimum possible value of $$$f(A)$$$.In the second test case, the sum of all elements in the grid is equal to $$$8$$$, so the condition is satisfied. $$$R_1 = 3, R_2 = 3, R_3 = 2$$$ and $$$C_1 = 3, C_2 = 2, C_3 = 3$$$. Then, $$$f(A) = (3-2)^2 + (3-2)^2 = 2$$$. It can be proven, that it is the minimum possible value of $$$f(A)$$$. | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"greedy"
] | 0f18382d450be90edf1fd1a3770b232b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Next $$$t$$$ lines contain descriptions of test cases. For each test case the only line contains two integers $$$n$$$, $$$k$$$ $$$(1 \le n \le 300, 0 \le k \le n^2)$$$. It is guaranteed that the sum of $$$n^2$$$ for all test cases does not exceed $$$10^5$$$. | 1,600 | For each test case, firstly print the minimum possible value of $$$f(A)$$$ among all tables, for which the condition is satisfied. After that, print $$$n$$$ lines contain $$$n$$$ characters each. The $$$j$$$-th character in the $$$i$$$-th line should be equal to $$$A_{i,j}$$$. If there are multiple answers you can print any. | standard output | |
PASSED | 541730a35503d4813bf6401b83043950 | train_001.jsonl | 1593610500 | A mad scientist Dr.Jubal has made a competitive programming task. Try to solve it!You are given integers $$$n,k$$$. Construct a grid $$$A$$$ with size $$$n \times n$$$ consisting of integers $$$0$$$ and $$$1$$$. The very important condition should be satisfied: the sum of all elements in the grid is exactly $$$k$$$. In other words, the number of $$$1$$$ in the grid is equal to $$$k$$$.Let's define: $$$A_{i,j}$$$ as the integer in the $$$i$$$-th row and the $$$j$$$-th column. $$$R_i = A_{i,1}+A_{i,2}+...+A_{i,n}$$$ (for all $$$1 \le i \le n$$$). $$$C_j = A_{1,j}+A_{2,j}+...+A_{n,j}$$$ (for all $$$1 \le j \le n$$$). In other words, $$$R_i$$$ are row sums and $$$C_j$$$ are column sums of the grid $$$A$$$. For the grid $$$A$$$ let's define the value $$$f(A) = (\max(R)-\min(R))^2 + (\max(C)-\min(C))^2$$$ (here for an integer sequence $$$X$$$ we define $$$\max(X)$$$ as the maximum value in $$$X$$$ and $$$\min(X)$$$ as the minimum value in $$$X$$$). Find any grid $$$A$$$, which satisfies the following condition. Among such grids find any, for which the value $$$f(A)$$$ is the minimum possible. Among such tables, you can find any. | 256 megabytes | import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
public class Main {
public static void main(String[] args) {
final int mod = (int) 1e9 + 7;
InputReader in = new InputReader(System.in);
PrintWriter out = new PrintWriter(System.out);
StringBuilder sb = new StringBuilder();
int t = in.nextInt();
while (t-- > 0) {
int n = in.nextInt();
int k = in.nextInt();
int each = 0;
int extra = 0;
if (k != 0) each = k / n;
if (k != 0) extra = k % n;
int[][] ans = new int[n][n];
if (extra == 0) sb.append(0);
else sb.append(2);
sb.append('\n');
boolean[] col_used = new boolean[n];
for (int i = 0; i < n; i++) {
int j = (i * each) % n;
for (int l = 0; l < each; l++) {
int id = (j + l) % n;
ans[i][id] = 1;
}
// deal with extra
if (extra > 0) {
int id = (j + each) % n;
while (col_used[id]) id = (id + 1) % n;
// if (col_used[id]) System.out.println("id galat");
col_used[id] = true;
ans[i][id] = 1;
extra--;
}
}
// int maxRow = 0;
// int maxCol = 0;
// int count = 0;
// int[] cc = new int[n];
for (int i = 0; i < n; i++) {
// int rc = 0;
for (int j = 0; j < n; j++) {
sb.append(ans[i][j]);
// if (ans[i][j] == 1) count++;
// if (ans[i][j] == 1) {
// cc[j]++;
// rc++;
}
// maxRow = Math.max(rc, maxRow);
sb.append('\n');
}
// for (int i = 0; i < n; i++) {
// maxCol = Math.max(maxCol, cc[i]);
// }
// if (count != k) System.out.println("galat count");
// int expectedC = each;
// if (k % n != 0) expectedC++;
// if (maxRow != expectedC) System.out.println("row galat");
// if (maxCol != expectedC) System.out.println("column galat");
// }
// }
}
out.println(sb);
out.flush();
}
static class InputReader {
private final InputStream stream;
private final byte[] buf = new byte[8192];
private int curChar, snumChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int snext() {
if (snumChars == -1) throw new InputMismatchException();
if (curChar >= snumChars) {
curChar = 0;
try {
snumChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (snumChars <= 0) return -1;
}
return buf[curChar++];
}
public int nextInt() {
int c = snext();
while (isSpaceChar(c)) {
c = snext();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = snext();
}
int res = 0;
do {
if (c < '0' || c > '9') throw new InputMismatchException();
res *= 10;
res += c - '0';
c = snext();
} while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong() {
int c = snext();
while (isSpaceChar(c)) {
c = snext();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = snext();
}
long res = 0;
do {
if (c < '0' || c > '9') throw new InputMismatchException();
res *= 10;
res += c - '0';
c = snext();
} while (!isSpaceChar(c));
return res * sgn;
}
public int[] nextIntArray(int n) {
int a[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
return a;
}
public String readString() {
int c = snext();
while (isSpaceChar(c)) {
c = snext();
}
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = snext();
} while (!isSpaceChar(c));
return res.toString();
}
public String nextLine() {
int c = snext();
while (isSpaceChar(c)) c = snext();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = snext();
} while (!isEndOfLine(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null) return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
}
| Java | ["4\n2 2\n3 8\n1 0\n4 16"] | 1 second | ["0\n10\n01\n2\n111\n111\n101\n0\n0\n0\n1111\n1111\n1111\n1111"] | NoteIn the first test case, the sum of all elements in the grid is equal to $$$2$$$, so the condition is satisfied. $$$R_1 = 1, R_2 = 1$$$ and $$$C_1 = 1, C_2 = 1$$$. Then, $$$f(A) = (1-1)^2 + (1-1)^2 = 0$$$, which is the minimum possible value of $$$f(A)$$$.In the second test case, the sum of all elements in the grid is equal to $$$8$$$, so the condition is satisfied. $$$R_1 = 3, R_2 = 3, R_3 = 2$$$ and $$$C_1 = 3, C_2 = 2, C_3 = 3$$$. Then, $$$f(A) = (3-2)^2 + (3-2)^2 = 2$$$. It can be proven, that it is the minimum possible value of $$$f(A)$$$. | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"greedy"
] | 0f18382d450be90edf1fd1a3770b232b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Next $$$t$$$ lines contain descriptions of test cases. For each test case the only line contains two integers $$$n$$$, $$$k$$$ $$$(1 \le n \le 300, 0 \le k \le n^2)$$$. It is guaranteed that the sum of $$$n^2$$$ for all test cases does not exceed $$$10^5$$$. | 1,600 | For each test case, firstly print the minimum possible value of $$$f(A)$$$ among all tables, for which the condition is satisfied. After that, print $$$n$$$ lines contain $$$n$$$ characters each. The $$$j$$$-th character in the $$$i$$$-th line should be equal to $$$A_{i,j}$$$. If there are multiple answers you can print any. | standard output | |
PASSED | 637d7e8b3ea3a4f4e022f694e4456d96 | train_001.jsonl | 1593610500 | A mad scientist Dr.Jubal has made a competitive programming task. Try to solve it!You are given integers $$$n,k$$$. Construct a grid $$$A$$$ with size $$$n \times n$$$ consisting of integers $$$0$$$ and $$$1$$$. The very important condition should be satisfied: the sum of all elements in the grid is exactly $$$k$$$. In other words, the number of $$$1$$$ in the grid is equal to $$$k$$$.Let's define: $$$A_{i,j}$$$ as the integer in the $$$i$$$-th row and the $$$j$$$-th column. $$$R_i = A_{i,1}+A_{i,2}+...+A_{i,n}$$$ (for all $$$1 \le i \le n$$$). $$$C_j = A_{1,j}+A_{2,j}+...+A_{n,j}$$$ (for all $$$1 \le j \le n$$$). In other words, $$$R_i$$$ are row sums and $$$C_j$$$ are column sums of the grid $$$A$$$. For the grid $$$A$$$ let's define the value $$$f(A) = (\max(R)-\min(R))^2 + (\max(C)-\min(C))^2$$$ (here for an integer sequence $$$X$$$ we define $$$\max(X)$$$ as the maximum value in $$$X$$$ and $$$\min(X)$$$ as the minimum value in $$$X$$$). Find any grid $$$A$$$, which satisfies the following condition. Among such grids find any, for which the value $$$f(A)$$$ is the minimum possible. Among such tables, you can find any. | 256 megabytes | import java.io.*;
import java.util.*;
public class Solution {
public void run() {
real();
// test();
}
void real() {
for (int test = reader.nextInt(); test > 0; test--) {
int n = reader.nextInt();
int k = reader.nextInt();
find(n, k);
}
}
void find(int n, int k) {
int[][] a = new int[n][n];
fill(a, n, k);
int[] row = new int[n];
int[] col = new int[n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
row[i] += a[i][j];
col[j] += a[i][j];
}
}
int rmax = row[0], rmin = row[0], cmax = col[0], cmin = col[0];
for (int i = 0; i < n; i++) {
rmax = Math.max(rmax, row[i]);
rmin = Math.min(rmin, row[i]);
cmax = Math.max(cmax, col[i]);
cmin = Math.min(cmin, col[i]);
}
long r = rmax - rmin;
long c = cmax - cmin;
long f = r * r + c * c;
writer.println(f);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
writer.print(a[i][j]);
}
writer.println();
}
}
void fill(int[][] a, int n, int k) {
int d = 0;
int m = n;
while (k > 0) {
for (int i = 0; i < m; i++) {
int j = i + d;
a[i][j] = 1;
k--;
if (k == 0) return;
}
for (int i = m; i < n; i++) {
int x = n - d;
int j = i - x;
a[i][j] = 1;
k--;
if (k == 0) return;
}
m--;
d++;
}
}
void test() {
find(4, 12);
}
private InputReader reader;
private PrintWriter writer;
public Solution(InputReader reader, PrintWriter writer) {
this.reader = reader;
this.writer = writer;
}
public static void main(String[] args) {
InputReader reader = new InputReader(System.in);
PrintWriter writer = new PrintWriter(System.out);
Solution solution = new Solution(reader, writer);
solution.run();
writer.flush();
}
static class InputReader {
private static final int BUFFER_SIZE = 1 << 20;
private BufferedReader reader;
private StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), BUFFER_SIZE);
tokenizer = null;
}
public String nextToken() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException();
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(nextToken());
}
public long nextLong() {
return Long.parseLong(nextToken());
}
}
}
// 1010000
// 9999999 | Java | ["4\n2 2\n3 8\n1 0\n4 16"] | 1 second | ["0\n10\n01\n2\n111\n111\n101\n0\n0\n0\n1111\n1111\n1111\n1111"] | NoteIn the first test case, the sum of all elements in the grid is equal to $$$2$$$, so the condition is satisfied. $$$R_1 = 1, R_2 = 1$$$ and $$$C_1 = 1, C_2 = 1$$$. Then, $$$f(A) = (1-1)^2 + (1-1)^2 = 0$$$, which is the minimum possible value of $$$f(A)$$$.In the second test case, the sum of all elements in the grid is equal to $$$8$$$, so the condition is satisfied. $$$R_1 = 3, R_2 = 3, R_3 = 2$$$ and $$$C_1 = 3, C_2 = 2, C_3 = 3$$$. Then, $$$f(A) = (3-2)^2 + (3-2)^2 = 2$$$. It can be proven, that it is the minimum possible value of $$$f(A)$$$. | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"greedy"
] | 0f18382d450be90edf1fd1a3770b232b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Next $$$t$$$ lines contain descriptions of test cases. For each test case the only line contains two integers $$$n$$$, $$$k$$$ $$$(1 \le n \le 300, 0 \le k \le n^2)$$$. It is guaranteed that the sum of $$$n^2$$$ for all test cases does not exceed $$$10^5$$$. | 1,600 | For each test case, firstly print the minimum possible value of $$$f(A)$$$ among all tables, for which the condition is satisfied. After that, print $$$n$$$ lines contain $$$n$$$ characters each. The $$$j$$$-th character in the $$$i$$$-th line should be equal to $$$A_{i,j}$$$. If there are multiple answers you can print any. | standard output | |
PASSED | 6e8bbe2c41fc3fdf7c32c4f16196704a | train_001.jsonl | 1593610500 | A mad scientist Dr.Jubal has made a competitive programming task. Try to solve it!You are given integers $$$n,k$$$. Construct a grid $$$A$$$ with size $$$n \times n$$$ consisting of integers $$$0$$$ and $$$1$$$. The very important condition should be satisfied: the sum of all elements in the grid is exactly $$$k$$$. In other words, the number of $$$1$$$ in the grid is equal to $$$k$$$.Let's define: $$$A_{i,j}$$$ as the integer in the $$$i$$$-th row and the $$$j$$$-th column. $$$R_i = A_{i,1}+A_{i,2}+...+A_{i,n}$$$ (for all $$$1 \le i \le n$$$). $$$C_j = A_{1,j}+A_{2,j}+...+A_{n,j}$$$ (for all $$$1 \le j \le n$$$). In other words, $$$R_i$$$ are row sums and $$$C_j$$$ are column sums of the grid $$$A$$$. For the grid $$$A$$$ let's define the value $$$f(A) = (\max(R)-\min(R))^2 + (\max(C)-\min(C))^2$$$ (here for an integer sequence $$$X$$$ we define $$$\max(X)$$$ as the maximum value in $$$X$$$ and $$$\min(X)$$$ as the minimum value in $$$X$$$). Find any grid $$$A$$$, which satisfies the following condition. Among such grids find any, for which the value $$$f(A)$$$ is the minimum possible. Among such tables, you can find any. | 256 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));
BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out));
int t=Integer.parseInt(br.readLine());
while(t-->0)
{
String str[]=br.readLine().split(" ");
int n=Integer.parseInt(str[0]);
int k=Integer.parseInt(str[1]);
int a[][]=new int[n][n];
int r[]=new int[n];
int c[]=new int[n];
for(int j=0;j<n&&k>0;j++)
{
for(int i=0;i<n&&k>0;i++)
{
a[i][(j+i)%n]=1;
k--;
r[i]++;
c[(j+i)%n]++;
}
}
int maxr=r[0];
int minr=r[0];
int maxc=c[0];
int minc=c[0];
for(int i=0;i<n;i++)
{
maxr=Math.max(maxr,r[i]);
minr=Math.min(minr,r[i]);
maxc=Math.max(maxc,c[i]);
minc=Math.min(minc,c[i]);
}
int ans=(maxr-minr)*(maxr-minr)+(maxc-minc)*(maxc-minc);
bw.write(ans+"\n");
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
bw.write(a[i][j]+"");
}
bw.newLine();
}
}
bw.close();
}
} | Java | ["4\n2 2\n3 8\n1 0\n4 16"] | 1 second | ["0\n10\n01\n2\n111\n111\n101\n0\n0\n0\n1111\n1111\n1111\n1111"] | NoteIn the first test case, the sum of all elements in the grid is equal to $$$2$$$, so the condition is satisfied. $$$R_1 = 1, R_2 = 1$$$ and $$$C_1 = 1, C_2 = 1$$$. Then, $$$f(A) = (1-1)^2 + (1-1)^2 = 0$$$, which is the minimum possible value of $$$f(A)$$$.In the second test case, the sum of all elements in the grid is equal to $$$8$$$, so the condition is satisfied. $$$R_1 = 3, R_2 = 3, R_3 = 2$$$ and $$$C_1 = 3, C_2 = 2, C_3 = 3$$$. Then, $$$f(A) = (3-2)^2 + (3-2)^2 = 2$$$. It can be proven, that it is the minimum possible value of $$$f(A)$$$. | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"greedy"
] | 0f18382d450be90edf1fd1a3770b232b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Next $$$t$$$ lines contain descriptions of test cases. For each test case the only line contains two integers $$$n$$$, $$$k$$$ $$$(1 \le n \le 300, 0 \le k \le n^2)$$$. It is guaranteed that the sum of $$$n^2$$$ for all test cases does not exceed $$$10^5$$$. | 1,600 | For each test case, firstly print the minimum possible value of $$$f(A)$$$ among all tables, for which the condition is satisfied. After that, print $$$n$$$ lines contain $$$n$$$ characters each. The $$$j$$$-th character in the $$$i$$$-th line should be equal to $$$A_{i,j}$$$. If there are multiple answers you can print any. | standard output | |
PASSED | 85b525bd225383bc32380ecf6535cc29 | train_001.jsonl | 1593610500 | A mad scientist Dr.Jubal has made a competitive programming task. Try to solve it!You are given integers $$$n,k$$$. Construct a grid $$$A$$$ with size $$$n \times n$$$ consisting of integers $$$0$$$ and $$$1$$$. The very important condition should be satisfied: the sum of all elements in the grid is exactly $$$k$$$. In other words, the number of $$$1$$$ in the grid is equal to $$$k$$$.Let's define: $$$A_{i,j}$$$ as the integer in the $$$i$$$-th row and the $$$j$$$-th column. $$$R_i = A_{i,1}+A_{i,2}+...+A_{i,n}$$$ (for all $$$1 \le i \le n$$$). $$$C_j = A_{1,j}+A_{2,j}+...+A_{n,j}$$$ (for all $$$1 \le j \le n$$$). In other words, $$$R_i$$$ are row sums and $$$C_j$$$ are column sums of the grid $$$A$$$. For the grid $$$A$$$ let's define the value $$$f(A) = (\max(R)-\min(R))^2 + (\max(C)-\min(C))^2$$$ (here for an integer sequence $$$X$$$ we define $$$\max(X)$$$ as the maximum value in $$$X$$$ and $$$\min(X)$$$ as the minimum value in $$$X$$$). Find any grid $$$A$$$, which satisfies the following condition. Among such grids find any, for which the value $$$f(A)$$$ is the minimum possible. Among such tables, you can find any. | 256 megabytes | import java.io.*;
import java.util.*;
/**
* Built using my Brain
* Actual solution is at the bottom
*
* @author Lenard Hoffstader
*/
public class cfjava
{
public static void main(String[] args)
{
OutputStream outputStream = System.out;
FastReader in = new FastReader();
PrintWriter out = new PrintWriter(outputStream);
PROBLEM solver = new PROBLEM();
int t=1;
t = in.nextInt();
for(int i=0;i<t;i++){
solver.solve(in, out);
}
out.close();
}
static class PROBLEM
{
public void solve(FastReader in,PrintWriter out)
{
int n = in.nextInt();
int k = in.nextInt();
int mat[][] = new int[n][n];
int x=0,y=0,delta=1;
int rsum[] = new int[n];
int csum[] = new int[n];
int rmin=10000,rmax=-1,cmin=10000,cmax=-1;
for(int i=0;i<k;i++){
mat[x][y]=1;
rsum[x]++;
csum[y]++;
if(x==n-1){
x=0;y=delta;delta++;
}
else {x++;y=(y+1)%n;}
}
for(int i=0;i<n;i++){
rmin = Math.min(rmin,rsum[i]);
rmax = Math.max(rmax,rsum[i]);
cmin = Math.min(cmin,csum[i]);
cmax = Math.max(cmax,csum[i]);
}
out.println((rmax-rmin)*(rmax-rmin) + (cmax-cmin)*(cmax-cmin));
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
out.print(mat[i][j]);
}
out.println();
}
}
}
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());}
boolean nextBoolean(){return !(nextInt()==0);}
// boolean nextBoolean(){return Boolean.parseBoolean(next());}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e){e.printStackTrace();}
return str;
}
}
} | Java | ["4\n2 2\n3 8\n1 0\n4 16"] | 1 second | ["0\n10\n01\n2\n111\n111\n101\n0\n0\n0\n1111\n1111\n1111\n1111"] | NoteIn the first test case, the sum of all elements in the grid is equal to $$$2$$$, so the condition is satisfied. $$$R_1 = 1, R_2 = 1$$$ and $$$C_1 = 1, C_2 = 1$$$. Then, $$$f(A) = (1-1)^2 + (1-1)^2 = 0$$$, which is the minimum possible value of $$$f(A)$$$.In the second test case, the sum of all elements in the grid is equal to $$$8$$$, so the condition is satisfied. $$$R_1 = 3, R_2 = 3, R_3 = 2$$$ and $$$C_1 = 3, C_2 = 2, C_3 = 3$$$. Then, $$$f(A) = (3-2)^2 + (3-2)^2 = 2$$$. It can be proven, that it is the minimum possible value of $$$f(A)$$$. | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"greedy"
] | 0f18382d450be90edf1fd1a3770b232b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Next $$$t$$$ lines contain descriptions of test cases. For each test case the only line contains two integers $$$n$$$, $$$k$$$ $$$(1 \le n \le 300, 0 \le k \le n^2)$$$. It is guaranteed that the sum of $$$n^2$$$ for all test cases does not exceed $$$10^5$$$. | 1,600 | For each test case, firstly print the minimum possible value of $$$f(A)$$$ among all tables, for which the condition is satisfied. After that, print $$$n$$$ lines contain $$$n$$$ characters each. The $$$j$$$-th character in the $$$i$$$-th line should be equal to $$$A_{i,j}$$$. If there are multiple answers you can print any. | standard output | |
PASSED | d2206720b5071cf221df685d25167cb2 | train_001.jsonl | 1593610500 | A mad scientist Dr.Jubal has made a competitive programming task. Try to solve it!You are given integers $$$n,k$$$. Construct a grid $$$A$$$ with size $$$n \times n$$$ consisting of integers $$$0$$$ and $$$1$$$. The very important condition should be satisfied: the sum of all elements in the grid is exactly $$$k$$$. In other words, the number of $$$1$$$ in the grid is equal to $$$k$$$.Let's define: $$$A_{i,j}$$$ as the integer in the $$$i$$$-th row and the $$$j$$$-th column. $$$R_i = A_{i,1}+A_{i,2}+...+A_{i,n}$$$ (for all $$$1 \le i \le n$$$). $$$C_j = A_{1,j}+A_{2,j}+...+A_{n,j}$$$ (for all $$$1 \le j \le n$$$). In other words, $$$R_i$$$ are row sums and $$$C_j$$$ are column sums of the grid $$$A$$$. For the grid $$$A$$$ let's define the value $$$f(A) = (\max(R)-\min(R))^2 + (\max(C)-\min(C))^2$$$ (here for an integer sequence $$$X$$$ we define $$$\max(X)$$$ as the maximum value in $$$X$$$ and $$$\min(X)$$$ as the minimum value in $$$X$$$). Find any grid $$$A$$$, which satisfies the following condition. Among such grids find any, for which the value $$$f(A)$$$ is the minimum possible. Among such tables, you can find any. | 256 megabytes |
import java.util.*;
import java.io.*;
public class Grid00100 {
// https://codeforces.com/contest/1371/problem/D
public static void main(String[] args) throws IOException, FileNotFoundException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
//BufferedReader in = new BufferedReader(new FileReader("Grid00100"));
int t = Integer.parseInt(in.readLine());
while (t --> 0) {
StringTokenizer st = new StringTokenizer(in.readLine());
int n = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken());
int[][] arr = new int[n][n];
int currow = k/n;
int leftover = k - currow*n;
int pointer=0;
for (int i=0; i<n; i++) {
for (int j=pointer; j < pointer+currow; j++) {
arr[i][j%n] = 1;
//k--;
}
if (leftover>0) {
arr[i][(pointer+currow)%n] = 1;
leftover--;
}
pointer++;
}
int maxrow=0;
int minrow = Integer.MAX_VALUE;
for (int i=0; i<n; i++) {
int cur=0;
for (int j=0; j<n;++j) {
cur += arr[i][j];
}
maxrow = Math.max(maxrow, cur);
minrow = Math.min(minrow, cur);
}
int maxcol=0;
int mincol = Integer.MAX_VALUE;
for (int i=0; i<n; i++) {
int cur=0;
for (int j=0; j<n;++j) {
cur += arr[j][i];
}
maxcol = Math.max(maxcol, cur);
mincol = Math.min(mincol, cur);
}
long val = (long)(maxcol-mincol)*(maxcol-mincol) + (long)(maxrow-minrow)*(maxrow-minrow);
System.out.println(val);
for (int i=0; i<n; i++) {
for (int j=0; j<n; j++) {
System.out.print(arr[i][j]);
}
System.out.println();
}
}
}
}
| Java | ["4\n2 2\n3 8\n1 0\n4 16"] | 1 second | ["0\n10\n01\n2\n111\n111\n101\n0\n0\n0\n1111\n1111\n1111\n1111"] | NoteIn the first test case, the sum of all elements in the grid is equal to $$$2$$$, so the condition is satisfied. $$$R_1 = 1, R_2 = 1$$$ and $$$C_1 = 1, C_2 = 1$$$. Then, $$$f(A) = (1-1)^2 + (1-1)^2 = 0$$$, which is the minimum possible value of $$$f(A)$$$.In the second test case, the sum of all elements in the grid is equal to $$$8$$$, so the condition is satisfied. $$$R_1 = 3, R_2 = 3, R_3 = 2$$$ and $$$C_1 = 3, C_2 = 2, C_3 = 3$$$. Then, $$$f(A) = (3-2)^2 + (3-2)^2 = 2$$$. It can be proven, that it is the minimum possible value of $$$f(A)$$$. | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"greedy"
] | 0f18382d450be90edf1fd1a3770b232b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Next $$$t$$$ lines contain descriptions of test cases. For each test case the only line contains two integers $$$n$$$, $$$k$$$ $$$(1 \le n \le 300, 0 \le k \le n^2)$$$. It is guaranteed that the sum of $$$n^2$$$ for all test cases does not exceed $$$10^5$$$. | 1,600 | For each test case, firstly print the minimum possible value of $$$f(A)$$$ among all tables, for which the condition is satisfied. After that, print $$$n$$$ lines contain $$$n$$$ characters each. The $$$j$$$-th character in the $$$i$$$-th line should be equal to $$$A_{i,j}$$$. If there are multiple answers you can print any. | standard output | |
PASSED | 6c70e06f1dea4f384e41b0b5bdd04759 | train_001.jsonl | 1593610500 | A mad scientist Dr.Jubal has made a competitive programming task. Try to solve it!You are given integers $$$n,k$$$. Construct a grid $$$A$$$ with size $$$n \times n$$$ consisting of integers $$$0$$$ and $$$1$$$. The very important condition should be satisfied: the sum of all elements in the grid is exactly $$$k$$$. In other words, the number of $$$1$$$ in the grid is equal to $$$k$$$.Let's define: $$$A_{i,j}$$$ as the integer in the $$$i$$$-th row and the $$$j$$$-th column. $$$R_i = A_{i,1}+A_{i,2}+...+A_{i,n}$$$ (for all $$$1 \le i \le n$$$). $$$C_j = A_{1,j}+A_{2,j}+...+A_{n,j}$$$ (for all $$$1 \le j \le n$$$). In other words, $$$R_i$$$ are row sums and $$$C_j$$$ are column sums of the grid $$$A$$$. For the grid $$$A$$$ let's define the value $$$f(A) = (\max(R)-\min(R))^2 + (\max(C)-\min(C))^2$$$ (here for an integer sequence $$$X$$$ we define $$$\max(X)$$$ as the maximum value in $$$X$$$ and $$$\min(X)$$$ as the minimum value in $$$X$$$). Find any grid $$$A$$$, which satisfies the following condition. Among such grids find any, for which the value $$$f(A)$$$ is the minimum possible. Among such tables, you can find any. | 256 megabytes |
import java.util.*;
import java.io.*;
//Captain on duty!
public class Main {
static void compare(Main.pair a[], int n) {
Arrays.sort(a, new Comparator<Main.pair>() {
@Override
public int compare(Main.pair p1, Main.pair p2) {
return p1.f - p2.f;
}
});
}
public static boolean checkPalindrome(String s) {
// reverse the given String
String reverse = new StringBuffer(s).reverse().toString();
// check whether the string is palindrome or not
if (s.equals(reverse))
return true;
else
return false;
}
static class pair implements Comparable {
int f;
int s;
pair(int fi, int se) {
f = fi;
s = se;
}
public int compareTo(Object o)//desc order
{
pair pr = (pair) o;
if (s > pr.s)
return -1;
if (s == pr.s) {
if (f > pr.f)
return 1;
else
return -1;
} else
return 1;
}
public boolean equals(Object o) {
pair ob = (pair) o;
if (o != null) {
if ((ob.f == this.f) && (ob.s == this.s))
return true;
}
return false;
}
public int hashCode() {
return (this.f + " " + this.s).hashCode();
}
}
public static boolean palin(int l, int r, char[] c) {
while (l <= r) {
if (c[l] != c[r]) return false;
l++;
r--;
}
return true;
}
public static long gcd(long a, long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
public static long lcm(long a, long b)
{
return (a*b)/gcd(a, b);
}
public static long hcf(long a, long b) {
long t;
while (b != 0) {
t = b;
b = a % b;
a = t;
}
return a;
}
public static boolean isPrime(long n) {
if (n <= 1)
return false;
// Check from 2 to n-1
for (int i = 2; i <= Math.sqrt(n) + 1; i++)
if (n % i == 0)
return false;
return true;
}
public static String reverse(String str) {
String str1 = "";
for (int i = 0; i < str.length(); i++) {
str1 = str1 + str.charAt(str.length() - i - 1);
}
return str1;
}
public static double fact(long a) {
if (a == 1)
return 1;
else
return a * fact(a - 1);
}
static boolean isPerfectSquare(double x)
{
// Find floating point value of
// square root of x.
double sr = Math.sqrt(x);
// If square root is an integer
return ((sr - Math.floor(sr)) == 0);
}
public static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
}
public static void main(String[] args) {
FastReader s = new FastReader();
//System.out.println("ICPC Babyy!!");
int test=s.nextInt();
while(test-->0)
{
int n=s.nextInt();
int k=s.nextInt();
int[][] a=new int[n][n];
if(k<=n && k!=0)
{
int c=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(i==j)
{
a[i][j]=1;
c++;
}
if(c==k)
break;
}
if(c==k)
break;
}
}
else if(k!=0)
{
int c=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(i==j)
{
a[i][j]=1;
c++;
}
}
}
int[] b=new int[n];
for(int i=0;i<n;i++)
b[i]=i+1;
while(true)
{
for(int i=0;i<n;i++)
{
if(b[i]==n)
b[i]=0;
a[i][b[i]]=1;
b[i]++;
if(b[i]==n)
b[i]=0;
c++;
if(c==k)
break;
}
if(c==k)
break;
}
}
int ans = f1(a,n);
System.out.println(ans);
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
System.out.print(a[i][j]);
System.out.println();
}
}
}
public static int f1(int[][] a, int n)
{
int[] r=new int[n];
int[] c=new int[n];
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
r[i] += a[i][j];
c[j]+=a[i][j];
}
}
int rmax=0;
int rmin=n;
int cmax=0;
int cmin=n;
for(int i=0;i<n;i++)
{
if(r[i]>rmax)
rmax=r[i];
if(r[i]<rmin)
rmin=r[i];
if(c[i]>cmax)
cmax=c[i];
if(c[i]<cmin)
cmin=c[i];
}
return ((rmax-rmin)*(rmax-rmin) + (cmax-cmin)*(cmax-cmin));
}
}
| Java | ["4\n2 2\n3 8\n1 0\n4 16"] | 1 second | ["0\n10\n01\n2\n111\n111\n101\n0\n0\n0\n1111\n1111\n1111\n1111"] | NoteIn the first test case, the sum of all elements in the grid is equal to $$$2$$$, so the condition is satisfied. $$$R_1 = 1, R_2 = 1$$$ and $$$C_1 = 1, C_2 = 1$$$. Then, $$$f(A) = (1-1)^2 + (1-1)^2 = 0$$$, which is the minimum possible value of $$$f(A)$$$.In the second test case, the sum of all elements in the grid is equal to $$$8$$$, so the condition is satisfied. $$$R_1 = 3, R_2 = 3, R_3 = 2$$$ and $$$C_1 = 3, C_2 = 2, C_3 = 3$$$. Then, $$$f(A) = (3-2)^2 + (3-2)^2 = 2$$$. It can be proven, that it is the minimum possible value of $$$f(A)$$$. | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"greedy"
] | 0f18382d450be90edf1fd1a3770b232b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Next $$$t$$$ lines contain descriptions of test cases. For each test case the only line contains two integers $$$n$$$, $$$k$$$ $$$(1 \le n \le 300, 0 \le k \le n^2)$$$. It is guaranteed that the sum of $$$n^2$$$ for all test cases does not exceed $$$10^5$$$. | 1,600 | For each test case, firstly print the minimum possible value of $$$f(A)$$$ among all tables, for which the condition is satisfied. After that, print $$$n$$$ lines contain $$$n$$$ characters each. The $$$j$$$-th character in the $$$i$$$-th line should be equal to $$$A_{i,j}$$$. If there are multiple answers you can print any. | standard output | |
PASSED | 9039866bdd1bd6b7d3bd3d65ca6acbc5 | train_001.jsonl | 1593610500 | A mad scientist Dr.Jubal has made a competitive programming task. Try to solve it!You are given integers $$$n,k$$$. Construct a grid $$$A$$$ with size $$$n \times n$$$ consisting of integers $$$0$$$ and $$$1$$$. The very important condition should be satisfied: the sum of all elements in the grid is exactly $$$k$$$. In other words, the number of $$$1$$$ in the grid is equal to $$$k$$$.Let's define: $$$A_{i,j}$$$ as the integer in the $$$i$$$-th row and the $$$j$$$-th column. $$$R_i = A_{i,1}+A_{i,2}+...+A_{i,n}$$$ (for all $$$1 \le i \le n$$$). $$$C_j = A_{1,j}+A_{2,j}+...+A_{n,j}$$$ (for all $$$1 \le j \le n$$$). In other words, $$$R_i$$$ are row sums and $$$C_j$$$ are column sums of the grid $$$A$$$. For the grid $$$A$$$ let's define the value $$$f(A) = (\max(R)-\min(R))^2 + (\max(C)-\min(C))^2$$$ (here for an integer sequence $$$X$$$ we define $$$\max(X)$$$ as the maximum value in $$$X$$$ and $$$\min(X)$$$ as the minimum value in $$$X$$$). Find any grid $$$A$$$, which satisfies the following condition. Among such grids find any, for which the value $$$f(A)$$$ is the minimum possible. Among such tables, you can find any. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;
public class sa {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0) {
int n=sc.nextInt();
int k=sc.nextInt();
if(k%n==0)
System.out.println(0);
else
System.out.println(2);
int arr[][]=new int[n][n];
for(int i=0;i<n;i++) {
int x=0, y=i;
for(int j=0;j<n;j++) {
if(k>0)
arr[x][y]=1;
else
break;
k-=1;
x=(x+1)%n;
y=(y+1)%n;
}
}
for(int i=0;i<n;i++) {
for(int j=0;j<n;j++)
System.out.print(arr[i][j]);
System.out.println();
}
}
}
}
| Java | ["4\n2 2\n3 8\n1 0\n4 16"] | 1 second | ["0\n10\n01\n2\n111\n111\n101\n0\n0\n0\n1111\n1111\n1111\n1111"] | NoteIn the first test case, the sum of all elements in the grid is equal to $$$2$$$, so the condition is satisfied. $$$R_1 = 1, R_2 = 1$$$ and $$$C_1 = 1, C_2 = 1$$$. Then, $$$f(A) = (1-1)^2 + (1-1)^2 = 0$$$, which is the minimum possible value of $$$f(A)$$$.In the second test case, the sum of all elements in the grid is equal to $$$8$$$, so the condition is satisfied. $$$R_1 = 3, R_2 = 3, R_3 = 2$$$ and $$$C_1 = 3, C_2 = 2, C_3 = 3$$$. Then, $$$f(A) = (3-2)^2 + (3-2)^2 = 2$$$. It can be proven, that it is the minimum possible value of $$$f(A)$$$. | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"greedy"
] | 0f18382d450be90edf1fd1a3770b232b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Next $$$t$$$ lines contain descriptions of test cases. For each test case the only line contains two integers $$$n$$$, $$$k$$$ $$$(1 \le n \le 300, 0 \le k \le n^2)$$$. It is guaranteed that the sum of $$$n^2$$$ for all test cases does not exceed $$$10^5$$$. | 1,600 | For each test case, firstly print the minimum possible value of $$$f(A)$$$ among all tables, for which the condition is satisfied. After that, print $$$n$$$ lines contain $$$n$$$ characters each. The $$$j$$$-th character in the $$$i$$$-th line should be equal to $$$A_{i,j}$$$. If there are multiple answers you can print any. | standard output | |
PASSED | 42cf8bff6e8c2d194aecaf1078a2b94c | train_001.jsonl | 1593610500 | A mad scientist Dr.Jubal has made a competitive programming task. Try to solve it!You are given integers $$$n,k$$$. Construct a grid $$$A$$$ with size $$$n \times n$$$ consisting of integers $$$0$$$ and $$$1$$$. The very important condition should be satisfied: the sum of all elements in the grid is exactly $$$k$$$. In other words, the number of $$$1$$$ in the grid is equal to $$$k$$$.Let's define: $$$A_{i,j}$$$ as the integer in the $$$i$$$-th row and the $$$j$$$-th column. $$$R_i = A_{i,1}+A_{i,2}+...+A_{i,n}$$$ (for all $$$1 \le i \le n$$$). $$$C_j = A_{1,j}+A_{2,j}+...+A_{n,j}$$$ (for all $$$1 \le j \le n$$$). In other words, $$$R_i$$$ are row sums and $$$C_j$$$ are column sums of the grid $$$A$$$. For the grid $$$A$$$ let's define the value $$$f(A) = (\max(R)-\min(R))^2 + (\max(C)-\min(C))^2$$$ (here for an integer sequence $$$X$$$ we define $$$\max(X)$$$ as the maximum value in $$$X$$$ and $$$\min(X)$$$ as the minimum value in $$$X$$$). Find any grid $$$A$$$, which satisfies the following condition. Among such grids find any, for which the value $$$f(A)$$$ is the minimum possible. Among such tables, you can find any. | 256 megabytes | import java.io.*;
import java.util.*;
//import javafx.util.*;
import java.math.*;
//import java.lang.*;
public class Main
{
// static int n;
// static HashSet<Integer> adj[];
// static int dist[];
// static int remove[];
// static boolean isLeaf[];
// static Long dp[][];
// static int arr[];
// static boolean ok;
// static long arr[];
// static long sum[];
// static boolean ok;
static long mod=1000000007;
// static HashSet<Integer> adjacency[];
static final long oo=(long)1e18;
public static void main(String[] args) throws IOException {
// Scanner sc=new Scanner(System.in);
PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
br = new BufferedReader(new InputStreamReader(System.in));
int test=nextInt();
//int test=1;
outer: while(test--!=0){
int n=nextInt();
int k=nextInt();
int arr[][]=new int[n][n];
int idx=0;
ou: while(k>0){
int j=idx;
for(int i=0;i<n;i++){
arr[i][idx]=1;
k--;
if(k==0)
break ou;
idx=(idx+1)%n;
}
idx++;
}
int ans=0;int max_row=0;int min_row=Integer.MAX_VALUE;int max_col=0;int min_col=Integer.MAX_VALUE;
for(int i=0;i<n;i++){
int sum=0;int sum_col=0;
for(int j=0;j<n;j++){
sum+=arr[i][j];
sum_col+=arr[j][i];
}
if(sum>max_row){
max_row=sum;
}
if(sum<min_row){
min_row=sum;
}
if(sum_col>max_col){
max_col=sum_col;
}
if(sum_col<min_col){
min_col=sum_col;
}
}
ans=(max_row-min_row)*(max_row-min_row)+(max_col-min_col)*(max_col-min_col);
pw.println(ans);
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
pw.print(arr[i][j]);
}
pw.println();
}
}
pw.close();
}
static class Pair implements Comparable<Pair>{
double g,ai,bi,sa,sb;
Pair(double g,double ai,double bi){
// this.index=index;
this.g=g;
this.ai=ai;
this.bi=bi;
sa=g/ai;
sb=g/bi;
//this.z=z;
}
public int compareTo(Pair p){
double a=Math.abs(sa-sb);
double b=Math.abs(p.sa-p.sb);
if(a>b){
return 1;
}
else if(a==b){
return 0;
}
else{
return -1;
}
}
}
static void update(long tree[],int idx,long val){
//println(idx);
while(idx<1000006){
tree[idx]+=val;
idx+=(idx)&(-idx);
}
}
static long sum(long tree[],int idx){
long sum=0;
while(idx>0){
sum+=tree[idx];
idx-=(idx)&(-idx);
}
return sum;
}
public static BufferedReader br;
public static StringTokenizer st;
public static String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
return st.nextToken();
}
public static Integer nextInt() {
return Integer.parseInt(next());
}
public static Long nextLong() {
return Long.parseLong(next());
}
public static Double nextDouble() {
return Double.parseDouble(next());
}
// static class Pair{
// int x;int y;
// Pair(int x,int y,int z){
// this.x=x;
// this.y=y;
// // this.z=z;
// // this.z=z;
// // this.i=i;
// }
// }
// static class sorting implements Comparator<Pair>{
// public int compare(Pair a,Pair b){
// //return (a.y)-(b.y);
// if(a.y==b.y){
// return -1*(a.z-b.z);
// }
// return (a.y-b.y);
// }
// }
static long ncr(long n,long r){
if(r==0)
return 1l;
long val=ncr(n-1,r-1);
val=(n*val);
val=(val/r);
return val;
}
public static int[] na(int n)throws IOException{
int[] a = new int[n];
for(int i = 0;i < n;i++)a[i] = nextInt();
return a;
}
static class query implements Comparable<query>{
int l,r,idx,block;
static int len;
query(int l,int r,int i){
this.l=l;
this.r=r;
this.idx=i;
this.block=l/len;
}
public int compareTo(query a){
return block==a.block?r-a.r:block-a.block;
}
}
// static class sorting implements Comparator<Pair>{
// public int compare(Pair a1,Pair a2){
// if(o1.a==o2.a)
// return (o1.b>o2.b)?1:-1;
// else if(o1.a>o2.a)
// return 1;
// else
// return -1;
// }
// }
static boolean isPrime(int n) {
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 ||
n % 3 == 0)
return false;
for (int i = 5;
i * i <= n; i = i + 6)
if (n % i == 0 ||
n % (i + 2) == 0)
return false;
return true;
}
static int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
// To compute x^y under modulo m
static long power(long x, long y, long m){
if (y == 0)
return 1;
long p = power(x, y / 2, m) % m;
p = (p * p) % m;
if (y % 2 == 0)
return p;
else
return (x * p) % m;
}
static long fast_pow(long base,long n,long M){
if(n==0)
return 1;
if(n==1)
return base;
long halfn=fast_pow(base,n/2,M);
if(n%2==0)
return ( halfn * halfn ) % M;
else
return ( ( ( halfn * halfn ) % M ) * base ) % M;
}
static long modInverse(long n,long M){
return fast_pow(n,M-2,M);
}
// (1,1)
// (3,2) (3,5)
} | Java | ["4\n2 2\n3 8\n1 0\n4 16"] | 1 second | ["0\n10\n01\n2\n111\n111\n101\n0\n0\n0\n1111\n1111\n1111\n1111"] | NoteIn the first test case, the sum of all elements in the grid is equal to $$$2$$$, so the condition is satisfied. $$$R_1 = 1, R_2 = 1$$$ and $$$C_1 = 1, C_2 = 1$$$. Then, $$$f(A) = (1-1)^2 + (1-1)^2 = 0$$$, which is the minimum possible value of $$$f(A)$$$.In the second test case, the sum of all elements in the grid is equal to $$$8$$$, so the condition is satisfied. $$$R_1 = 3, R_2 = 3, R_3 = 2$$$ and $$$C_1 = 3, C_2 = 2, C_3 = 3$$$. Then, $$$f(A) = (3-2)^2 + (3-2)^2 = 2$$$. It can be proven, that it is the minimum possible value of $$$f(A)$$$. | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"greedy"
] | 0f18382d450be90edf1fd1a3770b232b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Next $$$t$$$ lines contain descriptions of test cases. For each test case the only line contains two integers $$$n$$$, $$$k$$$ $$$(1 \le n \le 300, 0 \le k \le n^2)$$$. It is guaranteed that the sum of $$$n^2$$$ for all test cases does not exceed $$$10^5$$$. | 1,600 | For each test case, firstly print the minimum possible value of $$$f(A)$$$ among all tables, for which the condition is satisfied. After that, print $$$n$$$ lines contain $$$n$$$ characters each. The $$$j$$$-th character in the $$$i$$$-th line should be equal to $$$A_{i,j}$$$. If there are multiple answers you can print any. | standard output | |
PASSED | b6b9ef1c4b52770bab13f4e4eb5639f8 | train_001.jsonl | 1593610500 | A mad scientist Dr.Jubal has made a competitive programming task. Try to solve it!You are given integers $$$n,k$$$. Construct a grid $$$A$$$ with size $$$n \times n$$$ consisting of integers $$$0$$$ and $$$1$$$. The very important condition should be satisfied: the sum of all elements in the grid is exactly $$$k$$$. In other words, the number of $$$1$$$ in the grid is equal to $$$k$$$.Let's define: $$$A_{i,j}$$$ as the integer in the $$$i$$$-th row and the $$$j$$$-th column. $$$R_i = A_{i,1}+A_{i,2}+...+A_{i,n}$$$ (for all $$$1 \le i \le n$$$). $$$C_j = A_{1,j}+A_{2,j}+...+A_{n,j}$$$ (for all $$$1 \le j \le n$$$). In other words, $$$R_i$$$ are row sums and $$$C_j$$$ are column sums of the grid $$$A$$$. For the grid $$$A$$$ let's define the value $$$f(A) = (\max(R)-\min(R))^2 + (\max(C)-\min(C))^2$$$ (here for an integer sequence $$$X$$$ we define $$$\max(X)$$$ as the maximum value in $$$X$$$ and $$$\min(X)$$$ as the minimum value in $$$X$$$). Find any grid $$$A$$$, which satisfies the following condition. Among such grids find any, for which the value $$$f(A)$$$ is the minimum possible. Among such tables, you can find any. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.TreeSet;
public class Task4 {
public static void main(String[] args) {
try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
int t = Integer.valueOf(br.readLine());
outer:
for (int t_ = 0; t_ < t; t_++) {
String[] kn = br.readLine().split(" ");
int n = Integer.valueOf(kn[0]);
int k = Integer.valueOf(kn[1]);
solve(n, k);
}
} catch (Exception e) {
e.printStackTrace();
}
}
private static void solve(int n, int k) {
int perRow = k/n;
int leftovers = k - perRow*n;
int[][] rows = new int[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < perRow; j++) {
rows[i][(j+i)%n] = 1;
}
}
for (int i = 0; i < leftovers; i++) {
rows[i][(i+perRow)%n] = 1;
}
int minR = perRow;
int maxR = perRow + (leftovers > 0 ? 1 : 0);
System.out.println((long)Math.pow(maxR - minR, 2)*2);
for (int i = 0; i < n; i++) {
StringBuilder r = new StringBuilder();
for (int j = 0; j < n; j++) {
r.append(rows[i][j]);
}
System.out.println(r.toString());
}
}
}
| Java | ["4\n2 2\n3 8\n1 0\n4 16"] | 1 second | ["0\n10\n01\n2\n111\n111\n101\n0\n0\n0\n1111\n1111\n1111\n1111"] | NoteIn the first test case, the sum of all elements in the grid is equal to $$$2$$$, so the condition is satisfied. $$$R_1 = 1, R_2 = 1$$$ and $$$C_1 = 1, C_2 = 1$$$. Then, $$$f(A) = (1-1)^2 + (1-1)^2 = 0$$$, which is the minimum possible value of $$$f(A)$$$.In the second test case, the sum of all elements in the grid is equal to $$$8$$$, so the condition is satisfied. $$$R_1 = 3, R_2 = 3, R_3 = 2$$$ and $$$C_1 = 3, C_2 = 2, C_3 = 3$$$. Then, $$$f(A) = (3-2)^2 + (3-2)^2 = 2$$$. It can be proven, that it is the minimum possible value of $$$f(A)$$$. | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"greedy"
] | 0f18382d450be90edf1fd1a3770b232b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Next $$$t$$$ lines contain descriptions of test cases. For each test case the only line contains two integers $$$n$$$, $$$k$$$ $$$(1 \le n \le 300, 0 \le k \le n^2)$$$. It is guaranteed that the sum of $$$n^2$$$ for all test cases does not exceed $$$10^5$$$. | 1,600 | For each test case, firstly print the minimum possible value of $$$f(A)$$$ among all tables, for which the condition is satisfied. After that, print $$$n$$$ lines contain $$$n$$$ characters each. The $$$j$$$-th character in the $$$i$$$-th line should be equal to $$$A_{i,j}$$$. If there are multiple answers you can print any. | standard output | |
PASSED | b9a5d79d8576f8f67f0b573546d65c4a | train_001.jsonl | 1593610500 | A mad scientist Dr.Jubal has made a competitive programming task. Try to solve it!You are given integers $$$n,k$$$. Construct a grid $$$A$$$ with size $$$n \times n$$$ consisting of integers $$$0$$$ and $$$1$$$. The very important condition should be satisfied: the sum of all elements in the grid is exactly $$$k$$$. In other words, the number of $$$1$$$ in the grid is equal to $$$k$$$.Let's define: $$$A_{i,j}$$$ as the integer in the $$$i$$$-th row and the $$$j$$$-th column. $$$R_i = A_{i,1}+A_{i,2}+...+A_{i,n}$$$ (for all $$$1 \le i \le n$$$). $$$C_j = A_{1,j}+A_{2,j}+...+A_{n,j}$$$ (for all $$$1 \le j \le n$$$). In other words, $$$R_i$$$ are row sums and $$$C_j$$$ are column sums of the grid $$$A$$$. For the grid $$$A$$$ let's define the value $$$f(A) = (\max(R)-\min(R))^2 + (\max(C)-\min(C))^2$$$ (here for an integer sequence $$$X$$$ we define $$$\max(X)$$$ as the maximum value in $$$X$$$ and $$$\min(X)$$$ as the minimum value in $$$X$$$). Find any grid $$$A$$$, which satisfies the following condition. Among such grids find any, for which the value $$$f(A)$$$ is the minimum possible. Among such tables, you can find any. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.reflect.AnnotatedArrayType;
import java.lang.reflect.Array;
import java.util.*;
public class NTI {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
PrintWriter writer = new PrintWriter(System.out);
int t = Integer.parseInt(reader.readLine());
for(int q = 0; q < t; ++q){
StringTokenizer st = new StringTokenizer(reader.readLine());
int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
if(m % n == 0){
writer.println(0);
}
else{
writer.println(2);
}
int[][] arr = new int[n][n];
int plus = 0;
while(m > 0){
for(int i = 0; i < n && m > 0; ++i){
arr[i][(i + plus) % n] = 1;
--m;
}
++plus;
}
for(int i = 0; i < n; ++i){
StringBuilder s = new StringBuilder();
for(int j = 0; j < n; ++j){
s.append(arr[i][j]);
}
writer.println(s);
}
}
writer.close();
}
} | Java | ["4\n2 2\n3 8\n1 0\n4 16"] | 1 second | ["0\n10\n01\n2\n111\n111\n101\n0\n0\n0\n1111\n1111\n1111\n1111"] | NoteIn the first test case, the sum of all elements in the grid is equal to $$$2$$$, so the condition is satisfied. $$$R_1 = 1, R_2 = 1$$$ and $$$C_1 = 1, C_2 = 1$$$. Then, $$$f(A) = (1-1)^2 + (1-1)^2 = 0$$$, which is the minimum possible value of $$$f(A)$$$.In the second test case, the sum of all elements in the grid is equal to $$$8$$$, so the condition is satisfied. $$$R_1 = 3, R_2 = 3, R_3 = 2$$$ and $$$C_1 = 3, C_2 = 2, C_3 = 3$$$. Then, $$$f(A) = (3-2)^2 + (3-2)^2 = 2$$$. It can be proven, that it is the minimum possible value of $$$f(A)$$$. | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"greedy"
] | 0f18382d450be90edf1fd1a3770b232b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Next $$$t$$$ lines contain descriptions of test cases. For each test case the only line contains two integers $$$n$$$, $$$k$$$ $$$(1 \le n \le 300, 0 \le k \le n^2)$$$. It is guaranteed that the sum of $$$n^2$$$ for all test cases does not exceed $$$10^5$$$. | 1,600 | For each test case, firstly print the minimum possible value of $$$f(A)$$$ among all tables, for which the condition is satisfied. After that, print $$$n$$$ lines contain $$$n$$$ characters each. The $$$j$$$-th character in the $$$i$$$-th line should be equal to $$$A_{i,j}$$$. If there are multiple answers you can print any. | standard output | |
PASSED | 00836474fc0cc0f64018be20c251258b | train_001.jsonl | 1593610500 | A mad scientist Dr.Jubal has made a competitive programming task. Try to solve it!You are given integers $$$n,k$$$. Construct a grid $$$A$$$ with size $$$n \times n$$$ consisting of integers $$$0$$$ and $$$1$$$. The very important condition should be satisfied: the sum of all elements in the grid is exactly $$$k$$$. In other words, the number of $$$1$$$ in the grid is equal to $$$k$$$.Let's define: $$$A_{i,j}$$$ as the integer in the $$$i$$$-th row and the $$$j$$$-th column. $$$R_i = A_{i,1}+A_{i,2}+...+A_{i,n}$$$ (for all $$$1 \le i \le n$$$). $$$C_j = A_{1,j}+A_{2,j}+...+A_{n,j}$$$ (for all $$$1 \le j \le n$$$). In other words, $$$R_i$$$ are row sums and $$$C_j$$$ are column sums of the grid $$$A$$$. For the grid $$$A$$$ let's define the value $$$f(A) = (\max(R)-\min(R))^2 + (\max(C)-\min(C))^2$$$ (here for an integer sequence $$$X$$$ we define $$$\max(X)$$$ as the maximum value in $$$X$$$ and $$$\min(X)$$$ as the minimum value in $$$X$$$). Find any grid $$$A$$$, which satisfies the following condition. Among such grids find any, for which the value $$$f(A)$$$ is the minimum possible. Among such tables, you can find any. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.*;
public class Practice1 {
public static void main(String[] args) throws Exception {
FastInput in = new FastInput();
int t = in.nextInt();
StringBuilder str = new StringBuilder();
while(t-->0){
int n = in.nextInt();
int k = in.nextInt();
int arr[][] = new int[n][n];
int temp = k/n;
for(int i = 0;i<n;i++) {
int x = temp;
for(int j = i;x>0;j++) {
j = j%n;
arr[i][j] = 1;
x--;
}
}
int x = k%n;
if(x==0) {
str.append("0\n");
}
else {
str.append("2\n");
}
for(int i = 0;i<x;i++) {
arr[i][(i+temp)%n] = 1;
}
for(int i = 0;i<n;i++) {
for(int j = 0;j<n;j++) {
str.append(arr[i][j]);
}
str.append("\n");
}
// System.out.println(arr);
}
System.out.println(str);
}
}
class FastInput {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
String next() throws IOException {
if (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
Integer nextInt() throws IOException {
return Integer.parseInt(next());
}
Long nextLong() throws IOException {
return Long.parseLong(next());
}
} | Java | ["4\n2 2\n3 8\n1 0\n4 16"] | 1 second | ["0\n10\n01\n2\n111\n111\n101\n0\n0\n0\n1111\n1111\n1111\n1111"] | NoteIn the first test case, the sum of all elements in the grid is equal to $$$2$$$, so the condition is satisfied. $$$R_1 = 1, R_2 = 1$$$ and $$$C_1 = 1, C_2 = 1$$$. Then, $$$f(A) = (1-1)^2 + (1-1)^2 = 0$$$, which is the minimum possible value of $$$f(A)$$$.In the second test case, the sum of all elements in the grid is equal to $$$8$$$, so the condition is satisfied. $$$R_1 = 3, R_2 = 3, R_3 = 2$$$ and $$$C_1 = 3, C_2 = 2, C_3 = 3$$$. Then, $$$f(A) = (3-2)^2 + (3-2)^2 = 2$$$. It can be proven, that it is the minimum possible value of $$$f(A)$$$. | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"greedy"
] | 0f18382d450be90edf1fd1a3770b232b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Next $$$t$$$ lines contain descriptions of test cases. For each test case the only line contains two integers $$$n$$$, $$$k$$$ $$$(1 \le n \le 300, 0 \le k \le n^2)$$$. It is guaranteed that the sum of $$$n^2$$$ for all test cases does not exceed $$$10^5$$$. | 1,600 | For each test case, firstly print the minimum possible value of $$$f(A)$$$ among all tables, for which the condition is satisfied. After that, print $$$n$$$ lines contain $$$n$$$ characters each. The $$$j$$$-th character in the $$$i$$$-th line should be equal to $$$A_{i,j}$$$. If there are multiple answers you can print any. | standard output | |
PASSED | c2cbc7df59349b6933d4e5e2ec429bbf | train_001.jsonl | 1593610500 | A mad scientist Dr.Jubal has made a competitive programming task. Try to solve it!You are given integers $$$n,k$$$. Construct a grid $$$A$$$ with size $$$n \times n$$$ consisting of integers $$$0$$$ and $$$1$$$. The very important condition should be satisfied: the sum of all elements in the grid is exactly $$$k$$$. In other words, the number of $$$1$$$ in the grid is equal to $$$k$$$.Let's define: $$$A_{i,j}$$$ as the integer in the $$$i$$$-th row and the $$$j$$$-th column. $$$R_i = A_{i,1}+A_{i,2}+...+A_{i,n}$$$ (for all $$$1 \le i \le n$$$). $$$C_j = A_{1,j}+A_{2,j}+...+A_{n,j}$$$ (for all $$$1 \le j \le n$$$). In other words, $$$R_i$$$ are row sums and $$$C_j$$$ are column sums of the grid $$$A$$$. For the grid $$$A$$$ let's define the value $$$f(A) = (\max(R)-\min(R))^2 + (\max(C)-\min(C))^2$$$ (here for an integer sequence $$$X$$$ we define $$$\max(X)$$$ as the maximum value in $$$X$$$ and $$$\min(X)$$$ as the minimum value in $$$X$$$). Find any grid $$$A$$$, which satisfies the following condition. Among such grids find any, for which the value $$$f(A)$$$ is the minimum possible. Among such tables, you can find any. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class B {
public static void main(String[] args) {
FastScanner fs = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int T = fs.nextInt();
for(int tt=0; tt<T; ++tt) {
int n = fs.nextInt(), k = fs.nextInt(), ok = k;
boolean[][] board = new boolean[n][n];
for(int start =0; start <n; ++start) {
for(int i=0; i<n; ++i) {
if(k > 0) {
k--;
board[(start+i)%n][i] = true;
}
}
}
if(ok%n == 0) {
out.println(0);
}
else out.println(2);
for(int i=0; i<n; ++i) {
for (int j = 0; j < n; ++j)
out.print(board[i][j] ? 1 : 0);
out.println();
}
}
out.close();
}
static void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
} | Java | ["4\n2 2\n3 8\n1 0\n4 16"] | 1 second | ["0\n10\n01\n2\n111\n111\n101\n0\n0\n0\n1111\n1111\n1111\n1111"] | NoteIn the first test case, the sum of all elements in the grid is equal to $$$2$$$, so the condition is satisfied. $$$R_1 = 1, R_2 = 1$$$ and $$$C_1 = 1, C_2 = 1$$$. Then, $$$f(A) = (1-1)^2 + (1-1)^2 = 0$$$, which is the minimum possible value of $$$f(A)$$$.In the second test case, the sum of all elements in the grid is equal to $$$8$$$, so the condition is satisfied. $$$R_1 = 3, R_2 = 3, R_3 = 2$$$ and $$$C_1 = 3, C_2 = 2, C_3 = 3$$$. Then, $$$f(A) = (3-2)^2 + (3-2)^2 = 2$$$. It can be proven, that it is the minimum possible value of $$$f(A)$$$. | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"greedy"
] | 0f18382d450be90edf1fd1a3770b232b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Next $$$t$$$ lines contain descriptions of test cases. For each test case the only line contains two integers $$$n$$$, $$$k$$$ $$$(1 \le n \le 300, 0 \le k \le n^2)$$$. It is guaranteed that the sum of $$$n^2$$$ for all test cases does not exceed $$$10^5$$$. | 1,600 | For each test case, firstly print the minimum possible value of $$$f(A)$$$ among all tables, for which the condition is satisfied. After that, print $$$n$$$ lines contain $$$n$$$ characters each. The $$$j$$$-th character in the $$$i$$$-th line should be equal to $$$A_{i,j}$$$. If there are multiple answers you can print any. | standard output | |
PASSED | ef1234ec25a412c2fae5cb2e002f1fed | train_001.jsonl | 1593610500 | A mad scientist Dr.Jubal has made a competitive programming task. Try to solve it!You are given integers $$$n,k$$$. Construct a grid $$$A$$$ with size $$$n \times n$$$ consisting of integers $$$0$$$ and $$$1$$$. The very important condition should be satisfied: the sum of all elements in the grid is exactly $$$k$$$. In other words, the number of $$$1$$$ in the grid is equal to $$$k$$$.Let's define: $$$A_{i,j}$$$ as the integer in the $$$i$$$-th row and the $$$j$$$-th column. $$$R_i = A_{i,1}+A_{i,2}+...+A_{i,n}$$$ (for all $$$1 \le i \le n$$$). $$$C_j = A_{1,j}+A_{2,j}+...+A_{n,j}$$$ (for all $$$1 \le j \le n$$$). In other words, $$$R_i$$$ are row sums and $$$C_j$$$ are column sums of the grid $$$A$$$. For the grid $$$A$$$ let's define the value $$$f(A) = (\max(R)-\min(R))^2 + (\max(C)-\min(C))^2$$$ (here for an integer sequence $$$X$$$ we define $$$\max(X)$$$ as the maximum value in $$$X$$$ and $$$\min(X)$$$ as the minimum value in $$$X$$$). Find any grid $$$A$$$, which satisfies the following condition. Among such grids find any, for which the value $$$f(A)$$$ is the minimum possible. Among such tables, you can find any. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
private static void solver(InputReader sc, PrintWriter out) throws Exception {
int test = sc.nextInt();
for (int ii = 0; ii < test; ii++) {
int n = sc.nextInt();
int k = sc.nextInt();
int arr[][] = new int[n][n];
int count = 0, prev = 0, prevj = 0;
if (k == 0) {
out.println(0);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
out.print(0);
}
out.println();
}
continue;
}
while (count < k) {
for (int i = 0; i < n; i++) {
int j = i;
while (true) {
if (arr[i][j % n] == 0) {
arr[i][j % n] = 1;
count++;
break;
}
j++;
}
if (count >= k) break;
}
}
int rowmin = Integer.MAX_VALUE, rowmax = 0, colmin = Integer.MAX_VALUE, colmax = 0;
for (int i = 0; i < n; i++) {
int sum = 0;
for (int j = 0; j < n; j++) {
sum += arr[i][j];
}
// out.println(sum);
if (sum > rowmax) rowmax = sum;
if (sum < rowmin) rowmin = sum;
}
for (int j = 0; j < n; j++) {
int sum = 0;
for (int i = 0; i < n; i++) {
sum += arr[i][j];
}
if (sum < colmin) colmin = sum;
if (sum > colmax) colmax = sum;
}
int minf = rowmax - rowmin;
int mins = colmax - colmin;
int ans = (minf * minf) + (mins * mins);
out.println(ans);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
out.print(arr[i][j]);
}
out.println();
}
}
}
public static void main(String[] args) throws Exception {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
solver(in, out);
out.close();
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
}
class Pair implements Comparable<Pair> {
int x, y;
Pair(int x, int y) {
this.x = x;
this.y = y;
}
public int compareTo(Pair p) {
return (this.y - p.y);
}
}
class Tuple implements Comparable<Tuple> {
int x, y, z;
public Tuple(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
public int compareTo(Tuple t) {
if (this.z == t.z) {
if (this.y == t.y) {
return t.x - this.x;
} else return t.y - this.y;
} else
return this.z - t.z;
}
}
| Java | ["4\n2 2\n3 8\n1 0\n4 16"] | 1 second | ["0\n10\n01\n2\n111\n111\n101\n0\n0\n0\n1111\n1111\n1111\n1111"] | NoteIn the first test case, the sum of all elements in the grid is equal to $$$2$$$, so the condition is satisfied. $$$R_1 = 1, R_2 = 1$$$ and $$$C_1 = 1, C_2 = 1$$$. Then, $$$f(A) = (1-1)^2 + (1-1)^2 = 0$$$, which is the minimum possible value of $$$f(A)$$$.In the second test case, the sum of all elements in the grid is equal to $$$8$$$, so the condition is satisfied. $$$R_1 = 3, R_2 = 3, R_3 = 2$$$ and $$$C_1 = 3, C_2 = 2, C_3 = 3$$$. Then, $$$f(A) = (3-2)^2 + (3-2)^2 = 2$$$. It can be proven, that it is the minimum possible value of $$$f(A)$$$. | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"greedy"
] | 0f18382d450be90edf1fd1a3770b232b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Next $$$t$$$ lines contain descriptions of test cases. For each test case the only line contains two integers $$$n$$$, $$$k$$$ $$$(1 \le n \le 300, 0 \le k \le n^2)$$$. It is guaranteed that the sum of $$$n^2$$$ for all test cases does not exceed $$$10^5$$$. | 1,600 | For each test case, firstly print the minimum possible value of $$$f(A)$$$ among all tables, for which the condition is satisfied. After that, print $$$n$$$ lines contain $$$n$$$ characters each. The $$$j$$$-th character in the $$$i$$$-th line should be equal to $$$A_{i,j}$$$. If there are multiple answers you can print any. | standard output | |
PASSED | 78ed38c55c7d9a185b940c0e34b11624 | train_001.jsonl | 1593610500 | A mad scientist Dr.Jubal has made a competitive programming task. Try to solve it!You are given integers $$$n,k$$$. Construct a grid $$$A$$$ with size $$$n \times n$$$ consisting of integers $$$0$$$ and $$$1$$$. The very important condition should be satisfied: the sum of all elements in the grid is exactly $$$k$$$. In other words, the number of $$$1$$$ in the grid is equal to $$$k$$$.Let's define: $$$A_{i,j}$$$ as the integer in the $$$i$$$-th row and the $$$j$$$-th column. $$$R_i = A_{i,1}+A_{i,2}+...+A_{i,n}$$$ (for all $$$1 \le i \le n$$$). $$$C_j = A_{1,j}+A_{2,j}+...+A_{n,j}$$$ (for all $$$1 \le j \le n$$$). In other words, $$$R_i$$$ are row sums and $$$C_j$$$ are column sums of the grid $$$A$$$. For the grid $$$A$$$ let's define the value $$$f(A) = (\max(R)-\min(R))^2 + (\max(C)-\min(C))^2$$$ (here for an integer sequence $$$X$$$ we define $$$\max(X)$$$ as the maximum value in $$$X$$$ and $$$\min(X)$$$ as the minimum value in $$$X$$$). Find any grid $$$A$$$, which satisfies the following condition. Among such grids find any, for which the value $$$f(A)$$$ is the minimum possible. Among such tables, you can find any. | 256 megabytes | //package div2_654;
import java.util.Scanner;
public class d {
public static void main(String[] args) {
int t, n, k,a[][];
Scanner in = new Scanner(System.in);
t = in.nextInt();
for (int iTest = 0; iTest < t; iTest++) {
n = in.nextInt();
k = in.nextInt();
a=new int[n][n];
System.out.println(check(n,k));
analyz(a,n,k);
print(a,n);
}
in.close();
}
public static int check(long n, long k) {
if(k%n==0) return 0;
return 2;
}
public static void analyz(int[][] a, int n,int k) {
if(k==0) return;
long count;
int step;
step=k/n+1;
count=0;
for(int kt=0;kt<=step;kt++) {
for(int i=0;i+kt<n;i++) {
a[i][i+kt]=1;
count++;
if(count==k) return;
}
for(int j=0;j<kt;j++) {
a[n-kt+j][j]=1;
count++;
if(count==k) return;
}
}
}
public static void print(int[][] a, int n) {
for (int i=0;i<n;i++) {
for (int j=0;j<n;j++)
System.out.print(a[i][j]);
System.out.println();
}
}
}
| Java | ["4\n2 2\n3 8\n1 0\n4 16"] | 1 second | ["0\n10\n01\n2\n111\n111\n101\n0\n0\n0\n1111\n1111\n1111\n1111"] | NoteIn the first test case, the sum of all elements in the grid is equal to $$$2$$$, so the condition is satisfied. $$$R_1 = 1, R_2 = 1$$$ and $$$C_1 = 1, C_2 = 1$$$. Then, $$$f(A) = (1-1)^2 + (1-1)^2 = 0$$$, which is the minimum possible value of $$$f(A)$$$.In the second test case, the sum of all elements in the grid is equal to $$$8$$$, so the condition is satisfied. $$$R_1 = 3, R_2 = 3, R_3 = 2$$$ and $$$C_1 = 3, C_2 = 2, C_3 = 3$$$. Then, $$$f(A) = (3-2)^2 + (3-2)^2 = 2$$$. It can be proven, that it is the minimum possible value of $$$f(A)$$$. | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"greedy"
] | 0f18382d450be90edf1fd1a3770b232b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Next $$$t$$$ lines contain descriptions of test cases. For each test case the only line contains two integers $$$n$$$, $$$k$$$ $$$(1 \le n \le 300, 0 \le k \le n^2)$$$. It is guaranteed that the sum of $$$n^2$$$ for all test cases does not exceed $$$10^5$$$. | 1,600 | For each test case, firstly print the minimum possible value of $$$f(A)$$$ among all tables, for which the condition is satisfied. After that, print $$$n$$$ lines contain $$$n$$$ characters each. The $$$j$$$-th character in the $$$i$$$-th line should be equal to $$$A_{i,j}$$$. If there are multiple answers you can print any. | standard output | |
PASSED | 1374921394e8dc0220ae68f775dd9991 | train_001.jsonl | 1593610500 | A mad scientist Dr.Jubal has made a competitive programming task. Try to solve it!You are given integers $$$n,k$$$. Construct a grid $$$A$$$ with size $$$n \times n$$$ consisting of integers $$$0$$$ and $$$1$$$. The very important condition should be satisfied: the sum of all elements in the grid is exactly $$$k$$$. In other words, the number of $$$1$$$ in the grid is equal to $$$k$$$.Let's define: $$$A_{i,j}$$$ as the integer in the $$$i$$$-th row and the $$$j$$$-th column. $$$R_i = A_{i,1}+A_{i,2}+...+A_{i,n}$$$ (for all $$$1 \le i \le n$$$). $$$C_j = A_{1,j}+A_{2,j}+...+A_{n,j}$$$ (for all $$$1 \le j \le n$$$). In other words, $$$R_i$$$ are row sums and $$$C_j$$$ are column sums of the grid $$$A$$$. For the grid $$$A$$$ let's define the value $$$f(A) = (\max(R)-\min(R))^2 + (\max(C)-\min(C))^2$$$ (here for an integer sequence $$$X$$$ we define $$$\max(X)$$$ as the maximum value in $$$X$$$ and $$$\min(X)$$$ as the minimum value in $$$X$$$). Find any grid $$$A$$$, which satisfies the following condition. Among such grids find any, for which the value $$$f(A)$$$ is the minimum possible. Among such tables, you can find any. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(in.readLine());
for (int t = 0; t < T; ++t) {
StringTokenizer st = new StringTokenizer(in.readLine());
int n = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken());
int[][] grid = new int[n][n];
int result = solve(n, k, grid);
System.out.println(result);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
System.out.print(grid[i][j]);
}
System.out.println();
}
}
in.close();
}
private static int solve(int n, int k, int[][] grid) {
for (int i = 0; i < n; ++i) {
Arrays.fill(grid[i], 0);
}
int y = 0, x = 0;
for (int i = 0; i < k; ++i) {
grid[y][x] = 1;
y++;
x = (x + 1) % n;
if (y == n) {
y = 0;
x = (x + 1) % n;
}
}
int maxR = 0, minR = n;
for (int i = 0; i < n; ++i) {
int R = 0;
for (int j = 0; j < n; ++j) {
R += grid[i][j];
}
maxR = Math.max(maxR, R);
minR = Math.min(minR, R);
}
int maxC = 0, minC = n;
for (int i = 0; i < n; ++i) {
int C = 0;
for (int j = 0; j < n; ++j) {
C += grid[j][i];
}
maxC = Math.max(maxC, C);
minC = Math.min(minC, C);
}
return (maxR - minR) * (maxR - minR) + (maxC - minC) * (maxC - minC);
}
}
| Java | ["4\n2 2\n3 8\n1 0\n4 16"] | 1 second | ["0\n10\n01\n2\n111\n111\n101\n0\n0\n0\n1111\n1111\n1111\n1111"] | NoteIn the first test case, the sum of all elements in the grid is equal to $$$2$$$, so the condition is satisfied. $$$R_1 = 1, R_2 = 1$$$ and $$$C_1 = 1, C_2 = 1$$$. Then, $$$f(A) = (1-1)^2 + (1-1)^2 = 0$$$, which is the minimum possible value of $$$f(A)$$$.In the second test case, the sum of all elements in the grid is equal to $$$8$$$, so the condition is satisfied. $$$R_1 = 3, R_2 = 3, R_3 = 2$$$ and $$$C_1 = 3, C_2 = 2, C_3 = 3$$$. Then, $$$f(A) = (3-2)^2 + (3-2)^2 = 2$$$. It can be proven, that it is the minimum possible value of $$$f(A)$$$. | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"greedy"
] | 0f18382d450be90edf1fd1a3770b232b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Next $$$t$$$ lines contain descriptions of test cases. For each test case the only line contains two integers $$$n$$$, $$$k$$$ $$$(1 \le n \le 300, 0 \le k \le n^2)$$$. It is guaranteed that the sum of $$$n^2$$$ for all test cases does not exceed $$$10^5$$$. | 1,600 | For each test case, firstly print the minimum possible value of $$$f(A)$$$ among all tables, for which the condition is satisfied. After that, print $$$n$$$ lines contain $$$n$$$ characters each. The $$$j$$$-th character in the $$$i$$$-th line should be equal to $$$A_{i,j}$$$. If there are multiple answers you can print any. | standard output | |
PASSED | 38d8e2c28cf31972f4ba8fd4ae9ca7cf | train_001.jsonl | 1593610500 | A mad scientist Dr.Jubal has made a competitive programming task. Try to solve it!You are given integers $$$n,k$$$. Construct a grid $$$A$$$ with size $$$n \times n$$$ consisting of integers $$$0$$$ and $$$1$$$. The very important condition should be satisfied: the sum of all elements in the grid is exactly $$$k$$$. In other words, the number of $$$1$$$ in the grid is equal to $$$k$$$.Let's define: $$$A_{i,j}$$$ as the integer in the $$$i$$$-th row and the $$$j$$$-th column. $$$R_i = A_{i,1}+A_{i,2}+...+A_{i,n}$$$ (for all $$$1 \le i \le n$$$). $$$C_j = A_{1,j}+A_{2,j}+...+A_{n,j}$$$ (for all $$$1 \le j \le n$$$). In other words, $$$R_i$$$ are row sums and $$$C_j$$$ are column sums of the grid $$$A$$$. For the grid $$$A$$$ let's define the value $$$f(A) = (\max(R)-\min(R))^2 + (\max(C)-\min(C))^2$$$ (here for an integer sequence $$$X$$$ we define $$$\max(X)$$$ as the maximum value in $$$X$$$ and $$$\min(X)$$$ as the minimum value in $$$X$$$). Find any grid $$$A$$$, which satisfies the following condition. Among such grids find any, for which the value $$$f(A)$$$ is the minimum possible. Among such tables, you can find any. | 256 megabytes | import java.io.*;
import java.util.*;
public class GridZeroOne
{
static class OutputWriter
{
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream)
{
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer)
{
this.writer = new PrintWriter(writer);
}
public void print(Object...objects)
{
for (int i = 0; i < objects.length; i++)
{
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
public void printLine(Object...objects)
{
print(objects);
writer.println();
}
public void close()
{
writer.close();
}
public void flush() {
writer.flush();
}
}
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
OutputWriter out=new OutputWriter(System.out);
int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
int k=sc.nextInt();
int a[][]=new int[n][n];
if(k==0)
out.printLine(0);
else if(k<n)
{
out.printLine(2);
for(int i=0;i<k;i++)
{
for(int j=0;j<k;j++)
{
if(i==j)
a[i][j]=1;
}
}
}
else if(k%n==0)
{
out.printLine(0);
int q=k/n;
for(int i=0;i<n;i++)
{
int start=i;
for(int j=0;j<q;j++)
{
a[i][start]=1;
if(start==n-1)
start=0;
else
start++;
}
}
}
else if(k>n)
{
int q=k/n;
int r=k%n;
out.printLine(2);
for(int i=0;i<r;i++)
{
int start=i;
for(int j=0;j<q+1;j++)
{
a[i][start]=1;
if(start==n-1)
start=0;
else
start++;
}
}
for(int i=r;i<n;i++)
{
int start=i;
for(int j=0;j<q;j++)
{
a[i][start]=1;
if(start==n-1)
start=0;
else
start++;
}
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
out.print(a[i][j]);
}
out.printLine();
}
out.flush();
}
}
} | Java | ["4\n2 2\n3 8\n1 0\n4 16"] | 1 second | ["0\n10\n01\n2\n111\n111\n101\n0\n0\n0\n1111\n1111\n1111\n1111"] | NoteIn the first test case, the sum of all elements in the grid is equal to $$$2$$$, so the condition is satisfied. $$$R_1 = 1, R_2 = 1$$$ and $$$C_1 = 1, C_2 = 1$$$. Then, $$$f(A) = (1-1)^2 + (1-1)^2 = 0$$$, which is the minimum possible value of $$$f(A)$$$.In the second test case, the sum of all elements in the grid is equal to $$$8$$$, so the condition is satisfied. $$$R_1 = 3, R_2 = 3, R_3 = 2$$$ and $$$C_1 = 3, C_2 = 2, C_3 = 3$$$. Then, $$$f(A) = (3-2)^2 + (3-2)^2 = 2$$$. It can be proven, that it is the minimum possible value of $$$f(A)$$$. | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"greedy"
] | 0f18382d450be90edf1fd1a3770b232b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Next $$$t$$$ lines contain descriptions of test cases. For each test case the only line contains two integers $$$n$$$, $$$k$$$ $$$(1 \le n \le 300, 0 \le k \le n^2)$$$. It is guaranteed that the sum of $$$n^2$$$ for all test cases does not exceed $$$10^5$$$. | 1,600 | For each test case, firstly print the minimum possible value of $$$f(A)$$$ among all tables, for which the condition is satisfied. After that, print $$$n$$$ lines contain $$$n$$$ characters each. The $$$j$$$-th character in the $$$i$$$-th line should be equal to $$$A_{i,j}$$$. If there are multiple answers you can print any. | standard output | |
PASSED | 8cad9a0432911315afc996fd3e8f11c6 | train_001.jsonl | 1593610500 | A mad scientist Dr.Jubal has made a competitive programming task. Try to solve it!You are given integers $$$n,k$$$. Construct a grid $$$A$$$ with size $$$n \times n$$$ consisting of integers $$$0$$$ and $$$1$$$. The very important condition should be satisfied: the sum of all elements in the grid is exactly $$$k$$$. In other words, the number of $$$1$$$ in the grid is equal to $$$k$$$.Let's define: $$$A_{i,j}$$$ as the integer in the $$$i$$$-th row and the $$$j$$$-th column. $$$R_i = A_{i,1}+A_{i,2}+...+A_{i,n}$$$ (for all $$$1 \le i \le n$$$). $$$C_j = A_{1,j}+A_{2,j}+...+A_{n,j}$$$ (for all $$$1 \le j \le n$$$). In other words, $$$R_i$$$ are row sums and $$$C_j$$$ are column sums of the grid $$$A$$$. For the grid $$$A$$$ let's define the value $$$f(A) = (\max(R)-\min(R))^2 + (\max(C)-\min(C))^2$$$ (here for an integer sequence $$$X$$$ we define $$$\max(X)$$$ as the maximum value in $$$X$$$ and $$$\min(X)$$$ as the minimum value in $$$X$$$). Find any grid $$$A$$$, which satisfies the following condition. Among such grids find any, for which the value $$$f(A)$$$ is the minimum possible. Among such tables, you can find any. | 256 megabytes | import java.util.*;
import java.io.*;
public class D{
private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
private static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
public static void main (String[] args) throws IOException{
int t = Integer.parseInt(br.readLine());
while(t-- > 0){
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken());
if(k==0){
bw.write("0\n");
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
bw.write("0");
}
bw.newLine();
}
continue;
}
if(k%n == 0){
bw.write("0\n");
}else{
bw.write("2\n");
}
int a[][] = new int[n][n];
int till = k;
for(int i=0;i<=k/n;i++){
int x = 0, y = 0;
while(y<n && a[x][y]!=0){
y++;
}
if(y<n){
while(till>0 && y<n && x<n){
a[x][y] = 1;
x++;
y++;
till--;
}
if(till>0){
x = n-1;
y = 0;
while(x>-1 && a[x][y]!=0){
x--;
}
while(till>0 && x<n){
a[x][y]++;
x++;
y++;
till--;
}
}
}else{
x = n-1;
y = 0;
while(x>-1 && a[x][y]!=0){
x--;
}
while(till>0 && x<n){
a[x][y]++;
x++;
y++;
till--;
}
}
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
bw.write(a[i][j] + "");
}
bw.newLine();
}
}
bw.flush();
}
}
| Java | ["4\n2 2\n3 8\n1 0\n4 16"] | 1 second | ["0\n10\n01\n2\n111\n111\n101\n0\n0\n0\n1111\n1111\n1111\n1111"] | NoteIn the first test case, the sum of all elements in the grid is equal to $$$2$$$, so the condition is satisfied. $$$R_1 = 1, R_2 = 1$$$ and $$$C_1 = 1, C_2 = 1$$$. Then, $$$f(A) = (1-1)^2 + (1-1)^2 = 0$$$, which is the minimum possible value of $$$f(A)$$$.In the second test case, the sum of all elements in the grid is equal to $$$8$$$, so the condition is satisfied. $$$R_1 = 3, R_2 = 3, R_3 = 2$$$ and $$$C_1 = 3, C_2 = 2, C_3 = 3$$$. Then, $$$f(A) = (3-2)^2 + (3-2)^2 = 2$$$. It can be proven, that it is the minimum possible value of $$$f(A)$$$. | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"greedy"
] | 0f18382d450be90edf1fd1a3770b232b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Next $$$t$$$ lines contain descriptions of test cases. For each test case the only line contains two integers $$$n$$$, $$$k$$$ $$$(1 \le n \le 300, 0 \le k \le n^2)$$$. It is guaranteed that the sum of $$$n^2$$$ for all test cases does not exceed $$$10^5$$$. | 1,600 | For each test case, firstly print the minimum possible value of $$$f(A)$$$ among all tables, for which the condition is satisfied. After that, print $$$n$$$ lines contain $$$n$$$ characters each. The $$$j$$$-th character in the $$$i$$$-th line should be equal to $$$A_{i,j}$$$. If there are multiple answers you can print any. | standard output | |
PASSED | 54fbacfe1b98d90aef15dc0ffd540ec0 | train_001.jsonl | 1593610500 | A mad scientist Dr.Jubal has made a competitive programming task. Try to solve it!You are given integers $$$n,k$$$. Construct a grid $$$A$$$ with size $$$n \times n$$$ consisting of integers $$$0$$$ and $$$1$$$. The very important condition should be satisfied: the sum of all elements in the grid is exactly $$$k$$$. In other words, the number of $$$1$$$ in the grid is equal to $$$k$$$.Let's define: $$$A_{i,j}$$$ as the integer in the $$$i$$$-th row and the $$$j$$$-th column. $$$R_i = A_{i,1}+A_{i,2}+...+A_{i,n}$$$ (for all $$$1 \le i \le n$$$). $$$C_j = A_{1,j}+A_{2,j}+...+A_{n,j}$$$ (for all $$$1 \le j \le n$$$). In other words, $$$R_i$$$ are row sums and $$$C_j$$$ are column sums of the grid $$$A$$$. For the grid $$$A$$$ let's define the value $$$f(A) = (\max(R)-\min(R))^2 + (\max(C)-\min(C))^2$$$ (here for an integer sequence $$$X$$$ we define $$$\max(X)$$$ as the maximum value in $$$X$$$ and $$$\min(X)$$$ as the minimum value in $$$X$$$). Find any grid $$$A$$$, which satisfies the following condition. Among such grids find any, for which the value $$$f(A)$$$ is the minimum possible. Among such tables, you can find any. | 256 megabytes |
import java.util.*;
import java.io.*;
public class Main {
static List<Integer>[] gp;
static int cnt1=0;
static int cnt2=0;
public static void main(String[] args) {
try{
PrintWriter out = new PrintWriter(System.out);
int t=in.nextInt();
while(t-->0){
int n=in.nextInt();
int k=in.nextInt();
int[][] a=new int[n][n];
int[] row=new int[n];
int[] col=new int[n];
int i=0,j=0;
while(k>0){
a[i][j]=1;
row[i]++;
col[j]++;
i++;
if(i==n){
i=0;
j=(j+1)%n;
}
j=(j+1)%n;
k--;
}
long res=0;
Arrays.sort(row);
Arrays.sort(col);
res=(row[n-1]-row[0])*(row[n-1]-row[0])+(col[n-1]-col[0])*(col[n-1]-col[0]);
out.println(res);
out.flush();
for( i=0;i<n;i++){
for( j=0;j<n;j++){
out.print(a[i][j]);
}
out.println();
out.flush();
}
// System.ot.println();
}
}catch(Exception e){
System.out.println(e);
}
}
static void dfs(int i,int c,HashSet<Integer> hs){
if(c==1){
cnt1++;
}else{
cnt2++;
}
hs.add(i);
for(int j:gp[i]){
if(!hs.contains(j))dfs(j,-c,hs);
}
}
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
static FastReader in = new FastReader();
} | Java | ["4\n2 2\n3 8\n1 0\n4 16"] | 1 second | ["0\n10\n01\n2\n111\n111\n101\n0\n0\n0\n1111\n1111\n1111\n1111"] | NoteIn the first test case, the sum of all elements in the grid is equal to $$$2$$$, so the condition is satisfied. $$$R_1 = 1, R_2 = 1$$$ and $$$C_1 = 1, C_2 = 1$$$. Then, $$$f(A) = (1-1)^2 + (1-1)^2 = 0$$$, which is the minimum possible value of $$$f(A)$$$.In the second test case, the sum of all elements in the grid is equal to $$$8$$$, so the condition is satisfied. $$$R_1 = 3, R_2 = 3, R_3 = 2$$$ and $$$C_1 = 3, C_2 = 2, C_3 = 3$$$. Then, $$$f(A) = (3-2)^2 + (3-2)^2 = 2$$$. It can be proven, that it is the minimum possible value of $$$f(A)$$$. | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"greedy"
] | 0f18382d450be90edf1fd1a3770b232b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Next $$$t$$$ lines contain descriptions of test cases. For each test case the only line contains two integers $$$n$$$, $$$k$$$ $$$(1 \le n \le 300, 0 \le k \le n^2)$$$. It is guaranteed that the sum of $$$n^2$$$ for all test cases does not exceed $$$10^5$$$. | 1,600 | For each test case, firstly print the minimum possible value of $$$f(A)$$$ among all tables, for which the condition is satisfied. After that, print $$$n$$$ lines contain $$$n$$$ characters each. The $$$j$$$-th character in the $$$i$$$-th line should be equal to $$$A_{i,j}$$$. If there are multiple answers you can print any. | standard output | |
PASSED | e61840f9f640289b8062001ff1e444fa | train_001.jsonl | 1593610500 | A mad scientist Dr.Jubal has made a competitive programming task. Try to solve it!You are given integers $$$n,k$$$. Construct a grid $$$A$$$ with size $$$n \times n$$$ consisting of integers $$$0$$$ and $$$1$$$. The very important condition should be satisfied: the sum of all elements in the grid is exactly $$$k$$$. In other words, the number of $$$1$$$ in the grid is equal to $$$k$$$.Let's define: $$$A_{i,j}$$$ as the integer in the $$$i$$$-th row and the $$$j$$$-th column. $$$R_i = A_{i,1}+A_{i,2}+...+A_{i,n}$$$ (for all $$$1 \le i \le n$$$). $$$C_j = A_{1,j}+A_{2,j}+...+A_{n,j}$$$ (for all $$$1 \le j \le n$$$). In other words, $$$R_i$$$ are row sums and $$$C_j$$$ are column sums of the grid $$$A$$$. For the grid $$$A$$$ let's define the value $$$f(A) = (\max(R)-\min(R))^2 + (\max(C)-\min(C))^2$$$ (here for an integer sequence $$$X$$$ we define $$$\max(X)$$$ as the maximum value in $$$X$$$ and $$$\min(X)$$$ as the minimum value in $$$X$$$). Find any grid $$$A$$$, which satisfies the following condition. Among such grids find any, for which the value $$$f(A)$$$ is the minimum possible. Among such tables, you can find any. | 256 megabytes | import java.io.*;
import java.util.*;
import java.lang.*;
public class C{
public static void main(String[] args)throws IOException{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(in.readLine());
while(t-->0){
String[] temp = in.readLine().split(" ");
int n = Integer.parseInt(temp[0]);
int k = Integer.parseInt(temp[1]);
int value = 0;
if(k % n != 0){
value = 2;
}
System.out.println(value);
int[][] matrix = new int[n][n];
int p = 0;
int q = 0;
while(k-- > 0){
matrix[p][q] = 1;
p = (p + 1) % n;
q = (q + 1) % n;
if(p == 0){
q = (q + 1) % n;
}
}
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
System.out.print(matrix[i][j]);
}
System.out.println();
}
}
}
} | Java | ["4\n2 2\n3 8\n1 0\n4 16"] | 1 second | ["0\n10\n01\n2\n111\n111\n101\n0\n0\n0\n1111\n1111\n1111\n1111"] | NoteIn the first test case, the sum of all elements in the grid is equal to $$$2$$$, so the condition is satisfied. $$$R_1 = 1, R_2 = 1$$$ and $$$C_1 = 1, C_2 = 1$$$. Then, $$$f(A) = (1-1)^2 + (1-1)^2 = 0$$$, which is the minimum possible value of $$$f(A)$$$.In the second test case, the sum of all elements in the grid is equal to $$$8$$$, so the condition is satisfied. $$$R_1 = 3, R_2 = 3, R_3 = 2$$$ and $$$C_1 = 3, C_2 = 2, C_3 = 3$$$. Then, $$$f(A) = (3-2)^2 + (3-2)^2 = 2$$$. It can be proven, that it is the minimum possible value of $$$f(A)$$$. | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"greedy"
] | 0f18382d450be90edf1fd1a3770b232b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Next $$$t$$$ lines contain descriptions of test cases. For each test case the only line contains two integers $$$n$$$, $$$k$$$ $$$(1 \le n \le 300, 0 \le k \le n^2)$$$. It is guaranteed that the sum of $$$n^2$$$ for all test cases does not exceed $$$10^5$$$. | 1,600 | For each test case, firstly print the minimum possible value of $$$f(A)$$$ among all tables, for which the condition is satisfied. After that, print $$$n$$$ lines contain $$$n$$$ characters each. The $$$j$$$-th character in the $$$i$$$-th line should be equal to $$$A_{i,j}$$$. If there are multiple answers you can print any. | standard output | |
PASSED | 54270b0a293095d2297dd9fa826f1ab9 | train_001.jsonl | 1593610500 | A mad scientist Dr.Jubal has made a competitive programming task. Try to solve it!You are given integers $$$n,k$$$. Construct a grid $$$A$$$ with size $$$n \times n$$$ consisting of integers $$$0$$$ and $$$1$$$. The very important condition should be satisfied: the sum of all elements in the grid is exactly $$$k$$$. In other words, the number of $$$1$$$ in the grid is equal to $$$k$$$.Let's define: $$$A_{i,j}$$$ as the integer in the $$$i$$$-th row and the $$$j$$$-th column. $$$R_i = A_{i,1}+A_{i,2}+...+A_{i,n}$$$ (for all $$$1 \le i \le n$$$). $$$C_j = A_{1,j}+A_{2,j}+...+A_{n,j}$$$ (for all $$$1 \le j \le n$$$). In other words, $$$R_i$$$ are row sums and $$$C_j$$$ are column sums of the grid $$$A$$$. For the grid $$$A$$$ let's define the value $$$f(A) = (\max(R)-\min(R))^2 + (\max(C)-\min(C))^2$$$ (here for an integer sequence $$$X$$$ we define $$$\max(X)$$$ as the maximum value in $$$X$$$ and $$$\min(X)$$$ as the minimum value in $$$X$$$). Find any grid $$$A$$$, which satisfies the following condition. Among such grids find any, for which the value $$$f(A)$$$ is the minimum possible. Among such tables, you can find any. | 256 megabytes | import java.util.Scanner;
public class GridZeroZeroOneZeroZero {
public static void main(String[] args) {
Scanner read = new Scanner(System.in);
int t = read.nextInt();
while(t-- > 0){
int n = read.nextInt();
int k = read.nextInt();
int[][] a = new int[n][n];
if (k%n==0) System.out.println(0);
else System.out.println(2);
int sum = 0;
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
if (sum < k){
a[j][(i+j)%n] = 1;
sum++;
}
}
}
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++) System.out.print(a[i][j]);
System.out.println();
}
}
}
}
| Java | ["4\n2 2\n3 8\n1 0\n4 16"] | 1 second | ["0\n10\n01\n2\n111\n111\n101\n0\n0\n0\n1111\n1111\n1111\n1111"] | NoteIn the first test case, the sum of all elements in the grid is equal to $$$2$$$, so the condition is satisfied. $$$R_1 = 1, R_2 = 1$$$ and $$$C_1 = 1, C_2 = 1$$$. Then, $$$f(A) = (1-1)^2 + (1-1)^2 = 0$$$, which is the minimum possible value of $$$f(A)$$$.In the second test case, the sum of all elements in the grid is equal to $$$8$$$, so the condition is satisfied. $$$R_1 = 3, R_2 = 3, R_3 = 2$$$ and $$$C_1 = 3, C_2 = 2, C_3 = 3$$$. Then, $$$f(A) = (3-2)^2 + (3-2)^2 = 2$$$. It can be proven, that it is the minimum possible value of $$$f(A)$$$. | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"greedy"
] | 0f18382d450be90edf1fd1a3770b232b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Next $$$t$$$ lines contain descriptions of test cases. For each test case the only line contains two integers $$$n$$$, $$$k$$$ $$$(1 \le n \le 300, 0 \le k \le n^2)$$$. It is guaranteed that the sum of $$$n^2$$$ for all test cases does not exceed $$$10^5$$$. | 1,600 | For each test case, firstly print the minimum possible value of $$$f(A)$$$ among all tables, for which the condition is satisfied. After that, print $$$n$$$ lines contain $$$n$$$ characters each. The $$$j$$$-th character in the $$$i$$$-th line should be equal to $$$A_{i,j}$$$. If there are multiple answers you can print any. | standard output | |
PASSED | 64c63f68a35cd3a7a66efb675ba69602 | train_001.jsonl | 1593610500 | A mad scientist Dr.Jubal has made a competitive programming task. Try to solve it!You are given integers $$$n,k$$$. Construct a grid $$$A$$$ with size $$$n \times n$$$ consisting of integers $$$0$$$ and $$$1$$$. The very important condition should be satisfied: the sum of all elements in the grid is exactly $$$k$$$. In other words, the number of $$$1$$$ in the grid is equal to $$$k$$$.Let's define: $$$A_{i,j}$$$ as the integer in the $$$i$$$-th row and the $$$j$$$-th column. $$$R_i = A_{i,1}+A_{i,2}+...+A_{i,n}$$$ (for all $$$1 \le i \le n$$$). $$$C_j = A_{1,j}+A_{2,j}+...+A_{n,j}$$$ (for all $$$1 \le j \le n$$$). In other words, $$$R_i$$$ are row sums and $$$C_j$$$ are column sums of the grid $$$A$$$. For the grid $$$A$$$ let's define the value $$$f(A) = (\max(R)-\min(R))^2 + (\max(C)-\min(C))^2$$$ (here for an integer sequence $$$X$$$ we define $$$\max(X)$$$ as the maximum value in $$$X$$$ and $$$\min(X)$$$ as the minimum value in $$$X$$$). Find any grid $$$A$$$, which satisfies the following condition. Among such grids find any, for which the value $$$f(A)$$$ is the minimum possible. Among such tables, you can find any. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws FileNotFoundException {
FastReader f = new FastReader();
int t = f.nextInt();
while (t-- > 0) {
int n = f.nextInt();
int k = f.nextInt();
int[][] arr = new int[n][n];
int[] rows = new int[n];
int[] cols = new int[n];
for(int l=0;l<n;l++) {
for(int i=0,j=l;i<n && k > 0;i++,j=(j+1)%n) {
arr[i][j] = 1;
k--;
rows[i]++;
cols[j]++;
}
if(k <= 0) {
break;
}
}
int rowsMin = n, rowsMax = 0;
for(int i : rows) {
rowsMin = Math.min(rowsMin, i);
rowsMax = Math.max(rowsMax, i);
}
int ans = (rowsMax - rowsMin);
ans *= ans;
int colsMin = n, colsMax = 0;
for(int i : cols) {
colsMin = Math.min(colsMin, i);
colsMax = Math.max(colsMax, i);
}
ans += (colsMax - colsMin) * (colsMax - colsMin);
System.out.println(ans);
for(int i=0;i<n;i++) {
for(int j=0;j<n;j++) {
System.out.print(arr[i][j]);
}
System.out.println();
}
}
}
//fast input reader
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
}
| Java | ["4\n2 2\n3 8\n1 0\n4 16"] | 1 second | ["0\n10\n01\n2\n111\n111\n101\n0\n0\n0\n1111\n1111\n1111\n1111"] | NoteIn the first test case, the sum of all elements in the grid is equal to $$$2$$$, so the condition is satisfied. $$$R_1 = 1, R_2 = 1$$$ and $$$C_1 = 1, C_2 = 1$$$. Then, $$$f(A) = (1-1)^2 + (1-1)^2 = 0$$$, which is the minimum possible value of $$$f(A)$$$.In the second test case, the sum of all elements in the grid is equal to $$$8$$$, so the condition is satisfied. $$$R_1 = 3, R_2 = 3, R_3 = 2$$$ and $$$C_1 = 3, C_2 = 2, C_3 = 3$$$. Then, $$$f(A) = (3-2)^2 + (3-2)^2 = 2$$$. It can be proven, that it is the minimum possible value of $$$f(A)$$$. | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"greedy"
] | 0f18382d450be90edf1fd1a3770b232b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Next $$$t$$$ lines contain descriptions of test cases. For each test case the only line contains two integers $$$n$$$, $$$k$$$ $$$(1 \le n \le 300, 0 \le k \le n^2)$$$. It is guaranteed that the sum of $$$n^2$$$ for all test cases does not exceed $$$10^5$$$. | 1,600 | For each test case, firstly print the minimum possible value of $$$f(A)$$$ among all tables, for which the condition is satisfied. After that, print $$$n$$$ lines contain $$$n$$$ characters each. The $$$j$$$-th character in the $$$i$$$-th line should be equal to $$$A_{i,j}$$$. If there are multiple answers you can print any. | standard output | |
PASSED | 4a751f8d1555701c3bbe6dcdb8f8b0f9 | train_001.jsonl | 1593610500 | A mad scientist Dr.Jubal has made a competitive programming task. Try to solve it!You are given integers $$$n,k$$$. Construct a grid $$$A$$$ with size $$$n \times n$$$ consisting of integers $$$0$$$ and $$$1$$$. The very important condition should be satisfied: the sum of all elements in the grid is exactly $$$k$$$. In other words, the number of $$$1$$$ in the grid is equal to $$$k$$$.Let's define: $$$A_{i,j}$$$ as the integer in the $$$i$$$-th row and the $$$j$$$-th column. $$$R_i = A_{i,1}+A_{i,2}+...+A_{i,n}$$$ (for all $$$1 \le i \le n$$$). $$$C_j = A_{1,j}+A_{2,j}+...+A_{n,j}$$$ (for all $$$1 \le j \le n$$$). In other words, $$$R_i$$$ are row sums and $$$C_j$$$ are column sums of the grid $$$A$$$. For the grid $$$A$$$ let's define the value $$$f(A) = (\max(R)-\min(R))^2 + (\max(C)-\min(C))^2$$$ (here for an integer sequence $$$X$$$ we define $$$\max(X)$$$ as the maximum value in $$$X$$$ and $$$\min(X)$$$ as the minimum value in $$$X$$$). Find any grid $$$A$$$, which satisfies the following condition. Among such grids find any, for which the value $$$f(A)$$$ is the minimum possible. Among such tables, you can find any. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
import static java.lang.Math.*;
public class Solution implements Runnable {
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
public int nextInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public double nextDouble() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
if (c == '.') {
c = read();
double m = 1;
while (!isSpaceChar(c)) {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public String readString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next() {
return readString();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
public static void main(String args[]) throws Exception {
new Thread(null, new Solution(), "Main", 1 << 27).start();
}
static class Pair {
int x, y;
Pair(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + x * 7 + (y * 3 + 5 * (y - x));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
Pair other = (Pair) obj;
if (x != other.x && y != other.y) {
return false;
}
return true;
}
}
static void sieveOfEratosthenes(int n) {
//Prints prime nos till n
boolean prime[] = new boolean[n + 1];
for (int i = 0; i <= n; i++)
prime[i] = true;
for (int p = 2; p * p <= n; p++) {
if (prime[p] == true) {
for (int i = p * p; i <= n; i += p)
prime[i] = false;
}
}
for (int i = 2; i <= n; i++) {
if (prime[i] == true)
System.out.print(i + " ");
}
}
public void run() {
InputReader in = new InputReader(System.in);
PrintWriter w = new PrintWriter(System.out);
int t = in.nextInt();
while(t-->0)
{
int num = in.nextInt();
int k = in.nextInt();
int ans[][] = new int[num][num];
int f = k%num==0?0:2;
if(k==0)
{
w.println(0);
for(int i=0;i<num;i++)
{
for(int j=0;j<num;j++)
{
w.print(ans[i][j]);
}
w.println();
}
continue;
}
w.println(f);
for(int i=0;k>0 && i<num;i++)
{
int x = 0;
int y = i;
for(int j=0;k>0 && j<num;j++)
{
ans[x][y] = 1;
k--;
x = (x+1)%num;
y = (y+1)%num;
}
}
for(int i=0;i<num;i++)
{
for(int j=0;j<num;j++)
{
w.print(ans[i][j]);
}
w.println();
}
}
w.flush();
w.close();
}
}
| Java | ["4\n2 2\n3 8\n1 0\n4 16"] | 1 second | ["0\n10\n01\n2\n111\n111\n101\n0\n0\n0\n1111\n1111\n1111\n1111"] | NoteIn the first test case, the sum of all elements in the grid is equal to $$$2$$$, so the condition is satisfied. $$$R_1 = 1, R_2 = 1$$$ and $$$C_1 = 1, C_2 = 1$$$. Then, $$$f(A) = (1-1)^2 + (1-1)^2 = 0$$$, which is the minimum possible value of $$$f(A)$$$.In the second test case, the sum of all elements in the grid is equal to $$$8$$$, so the condition is satisfied. $$$R_1 = 3, R_2 = 3, R_3 = 2$$$ and $$$C_1 = 3, C_2 = 2, C_3 = 3$$$. Then, $$$f(A) = (3-2)^2 + (3-2)^2 = 2$$$. It can be proven, that it is the minimum possible value of $$$f(A)$$$. | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"greedy"
] | 0f18382d450be90edf1fd1a3770b232b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Next $$$t$$$ lines contain descriptions of test cases. For each test case the only line contains two integers $$$n$$$, $$$k$$$ $$$(1 \le n \le 300, 0 \le k \le n^2)$$$. It is guaranteed that the sum of $$$n^2$$$ for all test cases does not exceed $$$10^5$$$. | 1,600 | For each test case, firstly print the minimum possible value of $$$f(A)$$$ among all tables, for which the condition is satisfied. After that, print $$$n$$$ lines contain $$$n$$$ characters each. The $$$j$$$-th character in the $$$i$$$-th line should be equal to $$$A_{i,j}$$$. If there are multiple answers you can print any. | standard output | |
PASSED | 83ea3ce7305ed92181a9bb5bbb64029f | train_001.jsonl | 1593610500 | A mad scientist Dr.Jubal has made a competitive programming task. Try to solve it!You are given integers $$$n,k$$$. Construct a grid $$$A$$$ with size $$$n \times n$$$ consisting of integers $$$0$$$ and $$$1$$$. The very important condition should be satisfied: the sum of all elements in the grid is exactly $$$k$$$. In other words, the number of $$$1$$$ in the grid is equal to $$$k$$$.Let's define: $$$A_{i,j}$$$ as the integer in the $$$i$$$-th row and the $$$j$$$-th column. $$$R_i = A_{i,1}+A_{i,2}+...+A_{i,n}$$$ (for all $$$1 \le i \le n$$$). $$$C_j = A_{1,j}+A_{2,j}+...+A_{n,j}$$$ (for all $$$1 \le j \le n$$$). In other words, $$$R_i$$$ are row sums and $$$C_j$$$ are column sums of the grid $$$A$$$. For the grid $$$A$$$ let's define the value $$$f(A) = (\max(R)-\min(R))^2 + (\max(C)-\min(C))^2$$$ (here for an integer sequence $$$X$$$ we define $$$\max(X)$$$ as the maximum value in $$$X$$$ and $$$\min(X)$$$ as the minimum value in $$$X$$$). Find any grid $$$A$$$, which satisfies the following condition. Among such grids find any, for which the value $$$f(A)$$$ is the minimum possible. Among such tables, you can find any. | 256 megabytes | import java.util.*;import java.io.*;import java.math.*;
public class Grid1010
{
public static void process()throws IOException
{
int n = ni();
int k = ni();
int[][] a = new int[n][n];
if(k % n == 0){
pn(0);
}
else{
pn(2);
}
int p = 0, q = 0;
for(int i = 0; i < k; i++){
a[p][q] = 1;
p++;
q++;
q = q%(n);
if(p == n){
p = 0;
q++;
q = q%(n);
}
}
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++)
p(a[i][j]);
pn("");
}
}
static AnotherReader sc;
static PrintWriter out;
public static void main(String[]args)throws IOException
{
boolean oj = System.getProperty("ONLINE_JUDGE") != null;
if(oj){sc=new AnotherReader();out=new PrintWriter(System.out);}
else{sc=new AnotherReader(100);out=new PrintWriter("output.txt");}
long s = System.currentTimeMillis();
int t=1;
t=ni();
while(t-->0) {process();}
out.flush();
System.err.println(System.currentTimeMillis()-s+"ms");
out.close();
}
static void pn(Object o){out.println(o);}
static void p(Object o){out.print(o);}
static void pni(Object o){out.println(o);out.flush();}
static int ni()throws IOException{return sc.nextInt();}
static long nl()throws IOException{return sc.nextLong();}
static double nd()throws IOException{return sc.nextDouble();}
static String nln()throws IOException{return sc.nextLine();}
static int[] nai(int N)throws IOException{int[]A=new int[N];for(int i=0;i!=N;i++){A[i]=ni();}return A;}
static long[] nal(int N)throws IOException{long[]A=new long[N];for(int i=0;i!=N;i++){A[i]=nl();}return A;}
static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
static long power(long k, long c, long mod){
long y = 1;
while(c > 0){
if(c%2 == 1)
y = y * k % mod;
c = c/2;
k = k * k % mod;
}
return y;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
static class AnotherReader{BufferedReader br; StringTokenizer st;
AnotherReader()throws FileNotFoundException{
br=new BufferedReader(new InputStreamReader(System.in));}
AnotherReader(int a)throws FileNotFoundException{
br = new BufferedReader(new FileReader("input.txt"));}
String next()throws IOException{
while (st == null || !st.hasMoreElements()) {try{
st = new StringTokenizer(br.readLine());}
catch (IOException e){ e.printStackTrace(); }}
return st.nextToken(); } int nextInt() throws IOException{
return Integer.parseInt(next());}
long nextLong() throws IOException
{return Long.parseLong(next());}
double nextDouble()throws IOException { return Double.parseDouble(next()); }
String nextLine() throws IOException{ String str = ""; try{
str = br.readLine();} catch (IOException e){
e.printStackTrace();} return str;}}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
} | Java | ["4\n2 2\n3 8\n1 0\n4 16"] | 1 second | ["0\n10\n01\n2\n111\n111\n101\n0\n0\n0\n1111\n1111\n1111\n1111"] | NoteIn the first test case, the sum of all elements in the grid is equal to $$$2$$$, so the condition is satisfied. $$$R_1 = 1, R_2 = 1$$$ and $$$C_1 = 1, C_2 = 1$$$. Then, $$$f(A) = (1-1)^2 + (1-1)^2 = 0$$$, which is the minimum possible value of $$$f(A)$$$.In the second test case, the sum of all elements in the grid is equal to $$$8$$$, so the condition is satisfied. $$$R_1 = 3, R_2 = 3, R_3 = 2$$$ and $$$C_1 = 3, C_2 = 2, C_3 = 3$$$. Then, $$$f(A) = (3-2)^2 + (3-2)^2 = 2$$$. It can be proven, that it is the minimum possible value of $$$f(A)$$$. | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"greedy"
] | 0f18382d450be90edf1fd1a3770b232b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Next $$$t$$$ lines contain descriptions of test cases. For each test case the only line contains two integers $$$n$$$, $$$k$$$ $$$(1 \le n \le 300, 0 \le k \le n^2)$$$. It is guaranteed that the sum of $$$n^2$$$ for all test cases does not exceed $$$10^5$$$. | 1,600 | For each test case, firstly print the minimum possible value of $$$f(A)$$$ among all tables, for which the condition is satisfied. After that, print $$$n$$$ lines contain $$$n$$$ characters each. The $$$j$$$-th character in the $$$i$$$-th line should be equal to $$$A_{i,j}$$$. If there are multiple answers you can print any. | standard output | |
PASSED | f7c87d841e4d5bf3e8264bfab36adca4 | train_001.jsonl | 1593610500 | A mad scientist Dr.Jubal has made a competitive programming task. Try to solve it!You are given integers $$$n,k$$$. Construct a grid $$$A$$$ with size $$$n \times n$$$ consisting of integers $$$0$$$ and $$$1$$$. The very important condition should be satisfied: the sum of all elements in the grid is exactly $$$k$$$. In other words, the number of $$$1$$$ in the grid is equal to $$$k$$$.Let's define: $$$A_{i,j}$$$ as the integer in the $$$i$$$-th row and the $$$j$$$-th column. $$$R_i = A_{i,1}+A_{i,2}+...+A_{i,n}$$$ (for all $$$1 \le i \le n$$$). $$$C_j = A_{1,j}+A_{2,j}+...+A_{n,j}$$$ (for all $$$1 \le j \le n$$$). In other words, $$$R_i$$$ are row sums and $$$C_j$$$ are column sums of the grid $$$A$$$. For the grid $$$A$$$ let's define the value $$$f(A) = (\max(R)-\min(R))^2 + (\max(C)-\min(C))^2$$$ (here for an integer sequence $$$X$$$ we define $$$\max(X)$$$ as the maximum value in $$$X$$$ and $$$\min(X)$$$ as the minimum value in $$$X$$$). Find any grid $$$A$$$, which satisfies the following condition. Among such grids find any, for which the value $$$f(A)$$$ is the minimum possible. Among such tables, you can find any. | 256 megabytes | import java.io.*;
import java.util.*;
import java.lang.*;
public class Codechef {
PrintWriter out;
StringTokenizer st;
BufferedReader br;
class Pair implements Comparable<Pair>
{
int f;
int s;
Pair(int t, int r) {
f = t;
s = r;
}
public int compareTo(Pair p)
{
if(this.f!=p.f)
return this.f-p.f;
return this.s-p.s;
}
}
// class Sort implements Comparator<String>
// {
// public int compare(String a, String b)
// {
// return (a+b).compareTo(b+a);
// }
// }
String ns() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
String nextLine() throws Exception {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
throw new Exception(e.toString());
}
return str;
}
int nextInt() {
return Integer.parseInt(ns());
}
long nextLong() {
return Long.parseLong(ns());
}
double nextDouble() {
return Double.parseDouble(ns());
}
int upperBound(long a[],long key)
{
int l=0,r=a.length-1;
int i=-1;
while(l<=r)
{
int mid=(l+r)/2;
if(a[mid]<key)
l=mid+1;
else{
i=mid;
r=mid-1;
}
}
return i;
}
int lowerBound(Pair[] a , long key)
{
int l = 0, r = a.length- 1;
int i = -1;
while(l<=r)
{
int mid=(l+r)/2;
if(a[mid].f<key)
{
i=mid;
l=mid+1;
}
else
r=mid-1;
}
return i;
}
long power(long x,long y)
{
long ans=1;
while(y!=0)
{
if(y%2==1) ans=(ans*x)%mod;
x=(x*x)%mod;
y/=2;
}
return ans%mod;
}
int mod= 1000000007;
long gcd(long x ,long y)
{
if(y==0)
return x;
return gcd(y,x%y);
}
// ArrayList a[];
// int vis[],cnt=0;
// void dfs(int ver)
// {
// ArrayList<Integer> l=a[ver];
// if(l.size()==1)
// cnt++;
// for(int v:l)
// {
// if(vis[v]==0){
// vis[v]=vis[ver]+1;
// dfs(v);
// }
// }
// }
int countSetBits(long n)
{
int count = 0;
while (n > 0) {
n &= (n - 1);
count++;
}
return count;
}
void solve() throws IOException{
int t = nextInt();
while(t-- > 0)
{
int n = nextInt();
int k = nextInt();
int r = k % n;
int p = k / n;
int a[][] = new int[n][n];
int ans = 0;
if(r==0)
ans = 0;
else
ans = 2;
for(int i = 0; i < n; i++)
{
if(r-- > 0){
for(int j = 0; j < p + 1; j++)
{
if(j + i < n)
a[i][j + i] = 1;
else
a[i][(j + i) % n] = 1;
}
}
else{
for(int j = 0; j < p; j++)
{
if(j + i < n)
a[i][j + i] = 1;
else
a[i][(j + i) % n] = 1;
}
}
}
out.println(ans);
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
out.print(a[i][j]);
out.println();
}
}
}
void run() throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
long s = System.currentTimeMillis();
solve();
out.flush();
out.close();
}
public static void main(String args[]) throws IOException {
new Codechef().run();
}
} | Java | ["4\n2 2\n3 8\n1 0\n4 16"] | 1 second | ["0\n10\n01\n2\n111\n111\n101\n0\n0\n0\n1111\n1111\n1111\n1111"] | NoteIn the first test case, the sum of all elements in the grid is equal to $$$2$$$, so the condition is satisfied. $$$R_1 = 1, R_2 = 1$$$ and $$$C_1 = 1, C_2 = 1$$$. Then, $$$f(A) = (1-1)^2 + (1-1)^2 = 0$$$, which is the minimum possible value of $$$f(A)$$$.In the second test case, the sum of all elements in the grid is equal to $$$8$$$, so the condition is satisfied. $$$R_1 = 3, R_2 = 3, R_3 = 2$$$ and $$$C_1 = 3, C_2 = 2, C_3 = 3$$$. Then, $$$f(A) = (3-2)^2 + (3-2)^2 = 2$$$. It can be proven, that it is the minimum possible value of $$$f(A)$$$. | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"greedy"
] | 0f18382d450be90edf1fd1a3770b232b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Next $$$t$$$ lines contain descriptions of test cases. For each test case the only line contains two integers $$$n$$$, $$$k$$$ $$$(1 \le n \le 300, 0 \le k \le n^2)$$$. It is guaranteed that the sum of $$$n^2$$$ for all test cases does not exceed $$$10^5$$$. | 1,600 | For each test case, firstly print the minimum possible value of $$$f(A)$$$ among all tables, for which the condition is satisfied. After that, print $$$n$$$ lines contain $$$n$$$ characters each. The $$$j$$$-th character in the $$$i$$$-th line should be equal to $$$A_{i,j}$$$. If there are multiple answers you can print any. | standard output | |
PASSED | c2f7260542b80c31356a78eaa01d7ae0 | train_001.jsonl | 1593610500 | A mad scientist Dr.Jubal has made a competitive programming task. Try to solve it!You are given integers $$$n,k$$$. Construct a grid $$$A$$$ with size $$$n \times n$$$ consisting of integers $$$0$$$ and $$$1$$$. The very important condition should be satisfied: the sum of all elements in the grid is exactly $$$k$$$. In other words, the number of $$$1$$$ in the grid is equal to $$$k$$$.Let's define: $$$A_{i,j}$$$ as the integer in the $$$i$$$-th row and the $$$j$$$-th column. $$$R_i = A_{i,1}+A_{i,2}+...+A_{i,n}$$$ (for all $$$1 \le i \le n$$$). $$$C_j = A_{1,j}+A_{2,j}+...+A_{n,j}$$$ (for all $$$1 \le j \le n$$$). In other words, $$$R_i$$$ are row sums and $$$C_j$$$ are column sums of the grid $$$A$$$. For the grid $$$A$$$ let's define the value $$$f(A) = (\max(R)-\min(R))^2 + (\max(C)-\min(C))^2$$$ (here for an integer sequence $$$X$$$ we define $$$\max(X)$$$ as the maximum value in $$$X$$$ and $$$\min(X)$$$ as the minimum value in $$$X$$$). Find any grid $$$A$$$, which satisfies the following condition. Among such grids find any, for which the value $$$f(A)$$$ is the minimum possible. Among such tables, you can find any. | 256 megabytes | import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
public class Main {
static ArrayList<Integer> adj[];
// static PrintWriter out = new PrintWriter(System.out);
static int[][] notmemo;
static int k;
static int[] a;
static int b[];
static int m;
static class Pair implements Comparable<Pair> {
int c;
int d;
public Pair(int b, int l) {
c = b;
d = l;
}
@Override
public int compareTo(Pair o) {
return o.d-this.d;
}
}
static Pair s1[];
static ArrayList<Pair> adjlist[];
// static char c[];
public static long mod = (long) (1e9 + 7);
static int V;
static long INF = (long) 1E16;
static int n;
static char c[];
static int d[];
static int z;
static Pair p[];
static int R;
static int C;
static int K;
static long grid[][];
static Scanner sc = new Scanner(System.in);
static int x[];
static int y[];
static PrintWriter out = new PrintWriter(System.out);
public static void main(String args[]) throws Exception {
int t=sc.nextInt();
while(t-->0) {
int n=sc.nextInt();
int k=sc.nextInt();
int c[][]=new int[n][n];
int row=0;
int col=0;
int rem=k%n;
int count=k/n;
while(row<n) {
if(count>0) {
c[row][col]=1;
col++;
col%=n;
count--;
}
if(count==0&&rem!=0) {
count=k/n;
c[row][col]=1;
rem--;
row++;
col++;
col%=n;
}
else if(count==0) {
count=k/n;
row++;
}
}
int maxcol=0;
int mincol=n;
int minrow=n;
int maxrow=0;
for (int i = 0; i < c.length; i++) {
int rr=0;
for (int j = 0; j < c.length; j++) {
if(c[i][j]==1)
rr++;
}
maxrow=Math.max(rr,maxrow);
minrow=Math.min(minrow,rr);
int cc=0;
for (int j = 0; j < c.length; j++) {
if(c[j][i]==1)
cc++;
}
maxcol=Math.max(cc,maxcol);
mincol=Math.min(mincol,cc);
}
System.out.println((maxrow-minrow)*(maxrow-minrow)+(maxcol-mincol)*(maxcol-mincol));
for (int i = 0; i < c.length; i++) {
for (int j = 0; j < c.length; j++) {
System.out.print(c[i][j]);
}
System.out.println();
}
}
out.flush();
}
static long dp(int i,int cards) {
if(i==n)
return 0;
if(memo[cards][i]!=-1)
return memo[cards][i];
long ans=dp(i+1,cards);
for(int mask=0;mask<(1<<adjlist[i].size());mask++) {
int total=cards;
long damage=0;
int pp=0;
int maxdamage=0;
for (int j = 0; j <adjlist[i].size(); j++) {
int cc=0;
if((mask&(1<<j))!=0) {
if(adjlist[i].get(j).c==1)
cc=1;
else if(adjlist[i].get(j).c==2)
cc=2;
else
cc=3;
}
pp+=cc;
}
if(pp>3)
continue;
for (int j = 0; j <adjlist[i].size(); j++) {
if((mask&(1<<j))!=0){
total++;
damage+=(adjlist[i].get(j).d*1l);
maxdamage=Math.max(maxdamage,adjlist[i].get(j).d*1);
}
}
if(total>=10) {
damage+=maxdamage;
}
ans=Math.max(ans, 1l*damage+dp(i+1,total%10));
}
return memo[cards][i]=ans;
}
static TreeSet<Integer> ts=new TreeSet();
static HashMap<Integer, Integer> compress(int a[]) {
ts = new TreeSet<>();
HashMap<Integer, Integer> hm = new HashMap<>();
for (int x : a)
ts.add(x);
for (int x : ts) {
hm.put(x, hm.size() + 1);
}
return hm;
}
static class FenwickTree { // one-based DS
int n;
int[] ft;
FenwickTree(int size) { n = size; ft = new int[n+1]; }
int rsq(int b) //O(log n)
{
int sum = 0;
while(b > 0) { sum += ft[b]; b -= b & -b;} //min?
return sum;
}
int rsq(int a, int b) { return rsq(b) - rsq(a-1); }
void point_update(int k, int val) //O(log n), update = increment
{
while(k <= n) { ft[k] += val; k += k & -k; } //min?
}
}
static ArrayList<Integer> euler=new ArrayList<>();
static ArrayList<Integer> arr;
static int[] total;
static TreeMap<Integer,Integer> map1;
static int zz;
//static int dp(int idx,int left,int state) {
//if(idx>=k-((zz-left)*2)||idx+1==n) {
// return 0;
//}
//if(memo[idx][left][state]!=-1) {
// return memo[idx][left][state];
//}
//int ans=a[idx+1]+dp(idx+1,left,0);
//if(left>0&&state==0&&idx>0) {
// ans=Math.max(ans,a[idx-1]+dp(idx-1,left-1,1));
//}
//return memo[idx][left][state]=ans;
//}21
static HashMap<Integer,Integer> map;
static int maxa=0;
static int ff=123123;
static long[][] memo;
static long modmod=998244353;
static int dx[]= {1,-1,0,0};
static int dy[]= {0,0,1,-1};
static class BBOOK implements Comparable<BBOOK>{
int t;
int alice;
int bob;
public BBOOK(int x,int y,int z) {
t=x;
alice=y;
bob=z;
}
@Override
public int compareTo(BBOOK o) {
return this.t-o.t;
}
}
private static long lcm(long a2, long b2) {
return (a2*b2)/gcd(a2,b2);
}
static class Edge implements Comparable<Edge>
{
int node;long cost ; long time;
Edge(int a, long b,long c) { node = a; cost = b; time=c; }
public int compareTo(Edge e){ return Long.compare(time,e.time); }
}
static void sieve(int N) // O(N log log N)
{
isComposite = new int[N+1];
isComposite[0] = isComposite[1] = 1; // 0 indicates a prime number
primes = new ArrayList<Integer>();
for (int i = 2; i <= N; ++i) //can loop till i*i <= N if primes array is not needed O(N log log sqrt(N))
if (isComposite[i] == 0) //can loop in 2 and odd integers for slightly better performance
{
primes.add(i);
if(1l * i * i <= N)
for (int j = i * i; j <= N; j += i) // j = i * 2 will not affect performance too much, may alter in modified sieve
isComposite[j] = 1;
}
}
static TreeSet<Integer> factors;
static ArrayList<Integer> primeFactors(int N) // O(sqrt(N) / ln sqrt(N))
{
ArrayList<Integer> factors = new ArrayList<Integer>(); //take abs(N) in case of -ve integers
int idx = 0, p = primes.get(idx);
while(1l*p * p <= N)
{
while(N % p == 0) { factors.add(p); N /= p; }
p = primes.get(++idx);
}
if(N != 1) // last prime factor may be > sqrt(N)
factors.add(N); // for integers whose largest prime factor has a power of 1
return factors;
}
static class UnionFind {
int[] p, rank, setSize;
int numSets;
int max[];
public UnionFind(int N) {
p = new int[numSets = N];
rank = new int[N];
setSize = new int[N];
for (int i = 0; i < N; i++) {
p[i] = i;
setSize[i] = 1;
}
}
public int findSet(int i) {
return p[i] == i ? i : (p[i] = findSet(p[i]));
}
public boolean isSameSet(int i, int j) {
return findSet(i) == findSet(j);
}
public int chunion(int i,int j, int x2) {
if (isSameSet(i, j))
return 0;
numSets--;
int x = findSet(i), y = findSet(j);
int z=findSet(x2);
p[x]=z;;
p[y]=z;
return x;
}
public void unionSet(int i, int j) {
if (isSameSet(i, j))
return;
numSets--;
int x = findSet(i), y = findSet(j);
if (rank[x] > rank[y]) {
p[y] = x;
setSize[x] += setSize[y];
} else {
p[x] = y;
setSize[y] += setSize[x];
if (rank[x] == rank[y])
rank[y]++;
}
}
public int numDisjointSets() {
return numSets;
}
public int sizeOfSet(int i) {
return setSize[findSet(i)];
}
}
static class Quad implements Comparable<Quad> {
int u;
int v;
char state;
int turns;
public Quad(int i, int j, char c, int k) {
u = i;
v = j;
state = c;
turns = k;
}
public int compareTo(Quad e) {
return (int) (turns - e.turns);
}
}
static long manhatandistance(long x, long x2, long y, long y2) {
return Math.abs(x - x2) + Math.abs(y - y2);
}
static long fib[];
static long fib(int n) {
if (n == 1 || n == 0) {
return 1;
}
if (fib[n] != -1) {
return fib[n];
} else
return fib[n] = ((fib(n - 2) % mod + fib(n - 1) % mod) % mod);
}
static class Point implements Comparable<Point>{
long x, y;
Point(long counth, long counts) {
x = counth;
y = counts;
}
@Override
public int compareTo(Point p )
{
return Long.compare(p.y*1l*x, p.x*1l*y);
}
}
static TreeSet<Long> primeFactors(long N) // O(sqrt(N) / ln sqrt(N))
{
TreeSet<Long> factors = new TreeSet<Long>(); // take abs(N) in case of -ve integers
int idx = 0, p = primes.get(idx);
while (p * p <= N) {
while (N % p == 0) {
factors.add((long) p);
N /= p;
}
if (primes.size() > idx + 1)
p = primes.get(++idx);
else
break;
}
if (N != 1) // last prime factor may be > sqrt(N)
factors.add(N); // for integers whose largest prime factor has a power of 1
return factors;
}
static boolean visited[];
/**
* static int bfs(int s) { Queue<Integer> q = new LinkedList<Integer>();
* q.add(s); int count=0; int maxcost=0; int dist[]=new int[n]; dist[s]=0;
* while(!q.isEmpty()) {
*
* int u = q.remove(); if(dist[u]==k) { break; } for(Pair v: adj[u]) {
* maxcost=Math.max(maxcost, v.cost);
*
*
*
* if(!visited[v.v]) {
*
* visited[v.v]=true; q.add(v.v); dist[v.v]=dist[u]+1; maxcost=Math.max(maxcost,
* v.cost); } }
*
* } return maxcost; }
**/
static boolean[] vis2;
static boolean f2 = false;
static long[][] matMul(long[][] a2, long[][] b, int p, int q, int r) // C(p x r) = A(p x q) x (q x r) -- O(p x q x
// r)
{
long[][] C = new long[p][r];
for (int i = 0; i < p; ++i) {
for (int j = 0; j < r; ++j) {
for (int k = 0; k < q; ++k) {
C[i][j] = (C[i][j] + (a2[i][k] % mod * b[k][j] % mod)) % mod;
C[i][j] %= mod;
}
}
}
return C;
}
public static int[] schuffle(int[] a2) {
for (int i = 0; i < a2.length; i++) {
int x = (int) (Math.random() * a2.length);
int temp = a2[x];
a2[x] = a2[i];
a2[i] = temp;
}
return a2;
}
static boolean vis[];
static HashSet<Integer> set = new HashSet<Integer>();
static long modPow(long ways, long count, long mod) // O(log e)
{
ways %= mod;
long res = 1;
while (count > 0) {
if ((count & 1) == 1)
res = (res * ways) % mod;
ways = (ways * ways) % mod;
count >>= 1;
}
return res % mod;
}
static long gcd(long l, long o) {
if (o == 0) {
return l;
}
return gcd(o, l % o);
}
static int[] isComposite;
static int[] valid;
static ArrayList<Integer> primes;
static ArrayList<Integer> l1;
static TreeSet<Integer> primus = new TreeSet<Integer>();
static void sieveLinear(int N)
{
int[] lp = new int[N + 1]; //lp[i] = least prime divisor of i
for(int i = 2; i <= N; ++i)
{
if(lp[i] == 0)
{
primus.add(i);
lp[i] = i;
}
int curLP = lp[i];
for(int p: primus)
if(p > curLP || p * i > N)
break;
else
lp[p * i] = i;
}
}
public static long[] schuffle(long[] a2) {
for (int i = 0; i < a2.length; i++) {
int x = (int) (Math.random() * a2.length);
long temp = a2[x];
a2[x] = a2[i];
a2[i] = temp;
}
return a2;
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream system) {
br = new BufferedReader(new InputStreamReader(system));
}
public Scanner(String file) throws Exception {
br = new BufferedReader(new FileReader(file));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public String nextLine() throws IOException {
return br.readLine();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public char nextChar() throws IOException {
return next().charAt(0);
}
public Long nextLong() throws IOException {
return Long.parseLong(next());
}
public boolean ready() throws IOException {
return br.ready();
}
public void waitForInput() throws InterruptedException {
Thread.sleep(3000);
}
public int[] nxtArr(int n) throws IOException {
int[] ans = new int[n];
for (int i = 0; i < n; i++)
ans[i] = nextInt();
return ans;
}
}
public static int[] sortarray(int a[]) {
schuffle(a);
Arrays.sort(a);
return a;
}
public static long[] sortarray(long a[]) {
schuffle(a);
Arrays.sort(a);
return a;
}
public static int[] readarray(int n) throws IOException {
int a[]=new int[n];
for (int i = 0; i < a.length; i++) {
a[i]=sc.nextInt();
}
return a;
}
public static long[] readlarray(int n) throws IOException {
long a[]=new long[n];
for (int i = 0; i < a.length; i++) {
a[i]=sc.nextLong();
}
return a;
}
} | Java | ["4\n2 2\n3 8\n1 0\n4 16"] | 1 second | ["0\n10\n01\n2\n111\n111\n101\n0\n0\n0\n1111\n1111\n1111\n1111"] | NoteIn the first test case, the sum of all elements in the grid is equal to $$$2$$$, so the condition is satisfied. $$$R_1 = 1, R_2 = 1$$$ and $$$C_1 = 1, C_2 = 1$$$. Then, $$$f(A) = (1-1)^2 + (1-1)^2 = 0$$$, which is the minimum possible value of $$$f(A)$$$.In the second test case, the sum of all elements in the grid is equal to $$$8$$$, so the condition is satisfied. $$$R_1 = 3, R_2 = 3, R_3 = 2$$$ and $$$C_1 = 3, C_2 = 2, C_3 = 3$$$. Then, $$$f(A) = (3-2)^2 + (3-2)^2 = 2$$$. It can be proven, that it is the minimum possible value of $$$f(A)$$$. | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"greedy"
] | 0f18382d450be90edf1fd1a3770b232b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Next $$$t$$$ lines contain descriptions of test cases. For each test case the only line contains two integers $$$n$$$, $$$k$$$ $$$(1 \le n \le 300, 0 \le k \le n^2)$$$. It is guaranteed that the sum of $$$n^2$$$ for all test cases does not exceed $$$10^5$$$. | 1,600 | For each test case, firstly print the minimum possible value of $$$f(A)$$$ among all tables, for which the condition is satisfied. After that, print $$$n$$$ lines contain $$$n$$$ characters each. The $$$j$$$-th character in the $$$i$$$-th line should be equal to $$$A_{i,j}$$$. If there are multiple answers you can print any. | standard output | |
PASSED | 9fa46dbf8ff0bf08489fea83055d620d | train_001.jsonl | 1593610500 | A mad scientist Dr.Jubal has made a competitive programming task. Try to solve it!You are given integers $$$n,k$$$. Construct a grid $$$A$$$ with size $$$n \times n$$$ consisting of integers $$$0$$$ and $$$1$$$. The very important condition should be satisfied: the sum of all elements in the grid is exactly $$$k$$$. In other words, the number of $$$1$$$ in the grid is equal to $$$k$$$.Let's define: $$$A_{i,j}$$$ as the integer in the $$$i$$$-th row and the $$$j$$$-th column. $$$R_i = A_{i,1}+A_{i,2}+...+A_{i,n}$$$ (for all $$$1 \le i \le n$$$). $$$C_j = A_{1,j}+A_{2,j}+...+A_{n,j}$$$ (for all $$$1 \le j \le n$$$). In other words, $$$R_i$$$ are row sums and $$$C_j$$$ are column sums of the grid $$$A$$$. For the grid $$$A$$$ let's define the value $$$f(A) = (\max(R)-\min(R))^2 + (\max(C)-\min(C))^2$$$ (here for an integer sequence $$$X$$$ we define $$$\max(X)$$$ as the maximum value in $$$X$$$ and $$$\min(X)$$$ as the minimum value in $$$X$$$). Find any grid $$$A$$$, which satisfies the following condition. Among such grids find any, for which the value $$$f(A)$$$ is the minimum possible. Among such tables, you can find any. | 256 megabytes | import java.util.*;
public class D654{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
int x=sc.nextInt();
int[][] ar=new int[n][n];
int z=0,c=0;
if(x%n==0){System.out.println("0");}
else{System.out.println("2");}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
ar[i][j]='0';
}
ar[i][n-1]=0;
}
while(x>0){
x--;
ar[z][c]='1';
z++;c++;c%=n;
if(z==n){
z=0;c++;c%=n;
}
}
for(int j=0;j<n;j++){
for(int i=0;i<n;i++){
if(ar[j][i]%49==0){
System.out.print(ar[j][i]/49+"");
}
else{
System.out.print(ar[j][i]%48+"");
}
}
System.out.println();}
}
}
}
| Java | ["4\n2 2\n3 8\n1 0\n4 16"] | 1 second | ["0\n10\n01\n2\n111\n111\n101\n0\n0\n0\n1111\n1111\n1111\n1111"] | NoteIn the first test case, the sum of all elements in the grid is equal to $$$2$$$, so the condition is satisfied. $$$R_1 = 1, R_2 = 1$$$ and $$$C_1 = 1, C_2 = 1$$$. Then, $$$f(A) = (1-1)^2 + (1-1)^2 = 0$$$, which is the minimum possible value of $$$f(A)$$$.In the second test case, the sum of all elements in the grid is equal to $$$8$$$, so the condition is satisfied. $$$R_1 = 3, R_2 = 3, R_3 = 2$$$ and $$$C_1 = 3, C_2 = 2, C_3 = 3$$$. Then, $$$f(A) = (3-2)^2 + (3-2)^2 = 2$$$. It can be proven, that it is the minimum possible value of $$$f(A)$$$. | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"greedy"
] | 0f18382d450be90edf1fd1a3770b232b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Next $$$t$$$ lines contain descriptions of test cases. For each test case the only line contains two integers $$$n$$$, $$$k$$$ $$$(1 \le n \le 300, 0 \le k \le n^2)$$$. It is guaranteed that the sum of $$$n^2$$$ for all test cases does not exceed $$$10^5$$$. | 1,600 | For each test case, firstly print the minimum possible value of $$$f(A)$$$ among all tables, for which the condition is satisfied. After that, print $$$n$$$ lines contain $$$n$$$ characters each. The $$$j$$$-th character in the $$$i$$$-th line should be equal to $$$A_{i,j}$$$. If there are multiple answers you can print any. | standard output | |
PASSED | 6f8335ad33953ffc33e83825d1a18b38 | train_001.jsonl | 1593610500 | A mad scientist Dr.Jubal has made a competitive programming task. Try to solve it!You are given integers $$$n,k$$$. Construct a grid $$$A$$$ with size $$$n \times n$$$ consisting of integers $$$0$$$ and $$$1$$$. The very important condition should be satisfied: the sum of all elements in the grid is exactly $$$k$$$. In other words, the number of $$$1$$$ in the grid is equal to $$$k$$$.Let's define: $$$A_{i,j}$$$ as the integer in the $$$i$$$-th row and the $$$j$$$-th column. $$$R_i = A_{i,1}+A_{i,2}+...+A_{i,n}$$$ (for all $$$1 \le i \le n$$$). $$$C_j = A_{1,j}+A_{2,j}+...+A_{n,j}$$$ (for all $$$1 \le j \le n$$$). In other words, $$$R_i$$$ are row sums and $$$C_j$$$ are column sums of the grid $$$A$$$. For the grid $$$A$$$ let's define the value $$$f(A) = (\max(R)-\min(R))^2 + (\max(C)-\min(C))^2$$$ (here for an integer sequence $$$X$$$ we define $$$\max(X)$$$ as the maximum value in $$$X$$$ and $$$\min(X)$$$ as the minimum value in $$$X$$$). Find any grid $$$A$$$, which satisfies the following condition. Among such grids find any, for which the value $$$f(A)$$$ is the minimum possible. Among such tables, you can find any. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
public class Task654D {
public static void main(String[] args) {
Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
int t = in.nextInt(); // Scanner has functions to read ints, longs, strings, chars, etc.
int k, n;
for (int i = 1; i <= t; ++i) {
n = in.nextInt();
k = in.nextInt();
int[][] a = new int[n][n];
int count = k / n;
int rem = k % n;
int idx = 0;
int start = 0;
int end = count;
int it;
int minR = count, maxR = count + (rem > 0 ? 1 : 0), minC = n, maxC = 0;
for (int j = 0; j < n; j++) {
for (it = start; it < end; it++) {
a[j][(it + idx) % n] = 1;
}
if (rem > 0) {
a[j][(it + idx ) % n] = 1;
rem--;
}
idx++;
}
for (int j = 0; j < n; j++) {
int s = 0;
for (int q = 0; q < n; q++) {
s += a[q][j];
}
minC = Math.min(minC, s);
maxC = Math.max(maxC, s);
}
System.out.println((maxR - minR) * (maxR - minR) + (maxC - minC) * (maxC - minC));
for (int j = 0; j < n; j++) {
for (int q = 0; q < n; q++)
System.out.print(a[j][q]);
System.out.println();
}
}
}
}
| Java | ["4\n2 2\n3 8\n1 0\n4 16"] | 1 second | ["0\n10\n01\n2\n111\n111\n101\n0\n0\n0\n1111\n1111\n1111\n1111"] | NoteIn the first test case, the sum of all elements in the grid is equal to $$$2$$$, so the condition is satisfied. $$$R_1 = 1, R_2 = 1$$$ and $$$C_1 = 1, C_2 = 1$$$. Then, $$$f(A) = (1-1)^2 + (1-1)^2 = 0$$$, which is the minimum possible value of $$$f(A)$$$.In the second test case, the sum of all elements in the grid is equal to $$$8$$$, so the condition is satisfied. $$$R_1 = 3, R_2 = 3, R_3 = 2$$$ and $$$C_1 = 3, C_2 = 2, C_3 = 3$$$. Then, $$$f(A) = (3-2)^2 + (3-2)^2 = 2$$$. It can be proven, that it is the minimum possible value of $$$f(A)$$$. | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"greedy"
] | 0f18382d450be90edf1fd1a3770b232b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Next $$$t$$$ lines contain descriptions of test cases. For each test case the only line contains two integers $$$n$$$, $$$k$$$ $$$(1 \le n \le 300, 0 \le k \le n^2)$$$. It is guaranteed that the sum of $$$n^2$$$ for all test cases does not exceed $$$10^5$$$. | 1,600 | For each test case, firstly print the minimum possible value of $$$f(A)$$$ among all tables, for which the condition is satisfied. After that, print $$$n$$$ lines contain $$$n$$$ characters each. The $$$j$$$-th character in the $$$i$$$-th line should be equal to $$$A_{i,j}$$$. If there are multiple answers you can print any. | standard output | |
PASSED | 5386e73207ffc958cf09736b33f1c1fe | train_001.jsonl | 1593610500 | A mad scientist Dr.Jubal has made a competitive programming task. Try to solve it!You are given integers $$$n,k$$$. Construct a grid $$$A$$$ with size $$$n \times n$$$ consisting of integers $$$0$$$ and $$$1$$$. The very important condition should be satisfied: the sum of all elements in the grid is exactly $$$k$$$. In other words, the number of $$$1$$$ in the grid is equal to $$$k$$$.Let's define: $$$A_{i,j}$$$ as the integer in the $$$i$$$-th row and the $$$j$$$-th column. $$$R_i = A_{i,1}+A_{i,2}+...+A_{i,n}$$$ (for all $$$1 \le i \le n$$$). $$$C_j = A_{1,j}+A_{2,j}+...+A_{n,j}$$$ (for all $$$1 \le j \le n$$$). In other words, $$$R_i$$$ are row sums and $$$C_j$$$ are column sums of the grid $$$A$$$. For the grid $$$A$$$ let's define the value $$$f(A) = (\max(R)-\min(R))^2 + (\max(C)-\min(C))^2$$$ (here for an integer sequence $$$X$$$ we define $$$\max(X)$$$ as the maximum value in $$$X$$$ and $$$\min(X)$$$ as the minimum value in $$$X$$$). Find any grid $$$A$$$, which satisfies the following condition. Among such grids find any, for which the value $$$f(A)$$$ is the minimum possible. Among such tables, you can find any. | 256 megabytes | import java.io.*;
import java.sql.Array;
import java.util.*;
public class Grid00100 {
public static void main(String[] args) throws Exception {
BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int t = Integer.parseInt(buffer.readLine());
while (t-- > 0) {
String [] inp = buffer.readLine().split(" ");
int n = Integer.parseInt(inp[0]), k = Integer.parseInt(inp[1]);
int cnt1 = k, cnt0 = n*n-k;
int [][] matrix = new int[n][n];
if (k%n==0)
sb.append("0\n");
else
sb.append("2\n");
int rowPos = 0, colPos= 0;
while (k-->0)
{
matrix[rowPos][colPos] = 1;
rowPos++;
colPos++;
colPos%=n;
if (rowPos==n)
{
rowPos = 0;
colPos++;
colPos %= n;
}
}
for (rowPos = 0; rowPos < n; rowPos++) {
for (colPos = 0; colPos < n; colPos++) {
sb.append(matrix[rowPos][colPos]);
}
sb.append("\n");
}
}
System.out.println(sb);
}
}
| Java | ["4\n2 2\n3 8\n1 0\n4 16"] | 1 second | ["0\n10\n01\n2\n111\n111\n101\n0\n0\n0\n1111\n1111\n1111\n1111"] | NoteIn the first test case, the sum of all elements in the grid is equal to $$$2$$$, so the condition is satisfied. $$$R_1 = 1, R_2 = 1$$$ and $$$C_1 = 1, C_2 = 1$$$. Then, $$$f(A) = (1-1)^2 + (1-1)^2 = 0$$$, which is the minimum possible value of $$$f(A)$$$.In the second test case, the sum of all elements in the grid is equal to $$$8$$$, so the condition is satisfied. $$$R_1 = 3, R_2 = 3, R_3 = 2$$$ and $$$C_1 = 3, C_2 = 2, C_3 = 3$$$. Then, $$$f(A) = (3-2)^2 + (3-2)^2 = 2$$$. It can be proven, that it is the minimum possible value of $$$f(A)$$$. | Java 11 | standard input | [
"constructive algorithms",
"implementation",
"greedy"
] | 0f18382d450be90edf1fd1a3770b232b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Next $$$t$$$ lines contain descriptions of test cases. For each test case the only line contains two integers $$$n$$$, $$$k$$$ $$$(1 \le n \le 300, 0 \le k \le n^2)$$$. It is guaranteed that the sum of $$$n^2$$$ for all test cases does not exceed $$$10^5$$$. | 1,600 | For each test case, firstly print the minimum possible value of $$$f(A)$$$ among all tables, for which the condition is satisfied. After that, print $$$n$$$ lines contain $$$n$$$ characters each. The $$$j$$$-th character in the $$$i$$$-th line should be equal to $$$A_{i,j}$$$. If there are multiple answers you can print any. | standard output | |
PASSED | 605731d2f3e73cb727813099adafbf50 | train_001.jsonl | 1509113100 | You are given a matrix of size nβΓβm. Each element of the matrix is either 1 or 0. You have to determine the number of connected components consisting of 1's. Two cells belong to the same component if they have a common border, and both elements in these cells are 1's.Note that the memory limit is unusual! | 16 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
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);
TaskC solver = new TaskC();
solver.Solve(in, out);
out.close();
}
static class TaskC {
static int count = 0;
public class ConnectedComponent {
private ConnectedComponent wasConnectedTo;
public ConnectedComponent GetConnectedComponent() {
if (wasConnectedTo == null) return this;
wasConnectedTo = wasConnectedTo.GetConnectedComponent();
return wasConnectedTo;
}
public void ConnectTo(ConnectedComponent c) {
if (wasConnectedTo == null) {
wasConnectedTo = c;
count--;
} else {
wasConnectedTo.GetConnectedComponent().ConnectTo(c);
}
}
public ConnectedComponent() {
count++;
}
}
public void Solve(InputReader in, PrintWriter out) {
int n = in.NextInt();
int m = in.NextInt();
ConnectedComponent[] currentLine = new ConnectedComponent[m];
for (; n > 0; n--) {
char[] c = in.Next().toCharArray();
for (int i = 0; i < c.length; i++) {
char cc = c[i];
boolean[] a = new boolean[4];
a[3] = (cc == '1' || cc == '3' || cc == '5' || cc == '7' || cc == '9' || cc == 'B' || cc == 'D' || cc == 'F');
a[2] = (cc == '2' || cc == '3' || cc == '6' || cc == '7' || cc == 'A' || cc == 'B' || cc == 'E' || cc == 'F');
a[1] = (cc == '4' || cc == '5' || cc == '6' || cc == '7' || cc == 'C' || cc == 'D' || cc == 'E' || cc == 'F');
a[0] = (cc == '8' || cc == '9' || cc == 'A' || cc == 'B' || cc == 'C' || cc == 'D' || cc == 'E' || cc == 'F');
for (int j = 0; j < 4; j++) {
if (a[j]) {
if (currentLine[i * 4 + j] == null) {
currentLine[i * 4 + j] = new ConnectedComponent();
}
} else {
currentLine[i * 4 + j] = null;
}
}
}
ConnectedComponent last = null;
for (int i = 0; i < m; i++) {
ConnectedComponent current = currentLine[i];
if (current != null) {
current = current.GetConnectedComponent();
if (last != null && last != current) {
current.ConnectTo(last);
current = last;
}
currentLine[i] = current;
}
last = current;
}
}
out.println(count);
}
}
public static int GetMax(int[] ar) {
int max = Integer.MIN_VALUE;
for (int a : ar) {
max = Math.max(max, a);
}
return max;
}
public static int GetMin(int[] ar) {
int min = Integer.MAX_VALUE;
for (int a : ar) {
min = Math.min(min, a);
}
return min;
}
public static int[] GetCount(int[] ar) {
return GetCount(ar, GetMax(ar));
}
public static int[] GetCount(int[] ar, int maxValue) {
int[] dp = new int[maxValue + 1];
for (int a : ar) {
dp[a]++;
}
return dp;
}
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(), " \t\n\r\f,");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int NextInt() {
return Integer.parseInt(Next());
}
public long NextLong() {
return Long.parseLong(Next());
}
public double NextDouble() {
return Double.parseDouble(Next());
}
public int[] NextIntArray(int n) {
return NextIntArray(n, 0);
}
public int[] NextIntArray(int n, int offset) {
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = NextInt() - offset;
}
return a;
}
public int[][] NextIntMatrix(int n, int m) {
return NextIntMatrix(n, m, 0);
}
public int[][] NextIntMatrix(int n, int m, int offset) {
int[][] a = new int[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
a[i][j] = NextInt() - offset;
}
}
return a;
}
}
} | Java | ["3 4\n1\nA\n8", "2 8\n5F\nE3", "1 4\n0"] | 3 seconds | ["3", "2", "0"] | NoteIn the first example the matrix is: 000110101000It is clear that it has three components.The second example: 0101111111100011It is clear that the number of components is 2.There are no 1's in the third example, so the answer is 0. | Java 8 | standard input | [
"dsu"
] | 78b319ee682fa8c4dab53e0fcd018255 | The first line contains two numbers n and m (1ββ€βnββ€β212, 4ββ€βmββ€β214) β the number of rows and columns, respectively. It is guaranteed that m is divisible by 4. Then the representation of matrix follows. Each of n next lines contains one-digit hexadecimal numbers (that is, these numbers can be represented either as digits from 0 to 9 or as uppercase Latin letters from A to F). Binary representation of each of these numbers denotes next 4 elements of the matrix in the corresponding row. For example, if the number B is given, then the corresponding elements are 1011, and if the number is 5, then the corresponding elements are 0101. Elements are not separated by whitespaces. | 2,500 | Print the number of connected components consisting of 1's. | standard output | |
PASSED | c9132dc137ec5d3f962871012c07328f | train_001.jsonl | 1509113100 | You are given a matrix of size nβΓβm. Each element of the matrix is either 1 or 0. You have to determine the number of connected components consisting of 1's. Two cells belong to the same component if they have a common border, and both elements in these cells are 1's.Note that the memory limit is unusual! | 16 megabytes | import java.io.*;
import java.util.*;
public class Program
{
static byte[] buffer = new byte[524288];
static int end = 0;
static int ptr = 0;
static int[] parent;
static int Find(int t)
{
return parent[t] == t ? t : (parent[t] = Find(parent[t]));
}
static boolean Union(int a, int b)
{
if (parent[a] == -1 || parent[b] == -1) return false;
a = Find(a); b = Find(b);
if (a == b) return false;
if (a > b) parent[b] = a;
else parent[a] = b;
return true;
}
static void Slide()
{
for (int i = 0; i < parent.length / 2; i++)
{
parent[i] = parent[parent.length / 2 + i];
if (parent[i] >= parent.length / 2) parent[i] -= parent.length / 2;
}
for (int i = parent.length / 2; i < parent.length; i++)
{
parent[i] = -1;
}
}
static byte GetChar()
{
while (ptr == end)
{
try {
end = System.in.read(buffer);
} catch (Exception e) {
return ' ';
}
ptr = 0;
}
return buffer[ptr++];
}
static int ReadInt()
{
int ret = 0;
byte ch;
while ((ch = GetChar()) < '-')
;
boolean neg = (ch == '-'); if (neg) ch = GetChar();
do ret = ret * 10 + ch - '0'; while ((ch = GetChar()) >= '0');
return neg ? -ret : ret;
}
public static void main(String[] args)
{
int n = ReadInt(), m = ReadInt();
parent = new int[m * 2];
for (int i = 0; i < m * 2; i++) parent[i] = -1;
int ans = 0;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j += 4)
{
byte ch;
do ch = GetChar(); while (ch < '0');
int num = (ch >= 'A') ? ch - 'A' + 10 : ch - '0';
for (int k = 0; k < 4; k++)
{
if ((num & (1 << (3 - k))) == 0) continue;
parent[m + j + k] = m + j + k;
++ans;
if (j + k > 0 && Union(m + j + k, m + j + k - 1)) --ans;
if (Union(m + j + k, j + k)) --ans;
}
}
Slide();
}
System.out.println(ans);
}
} | Java | ["3 4\n1\nA\n8", "2 8\n5F\nE3", "1 4\n0"] | 3 seconds | ["3", "2", "0"] | NoteIn the first example the matrix is: 000110101000It is clear that it has three components.The second example: 0101111111100011It is clear that the number of components is 2.There are no 1's in the third example, so the answer is 0. | Java 8 | standard input | [
"dsu"
] | 78b319ee682fa8c4dab53e0fcd018255 | The first line contains two numbers n and m (1ββ€βnββ€β212, 4ββ€βmββ€β214) β the number of rows and columns, respectively. It is guaranteed that m is divisible by 4. Then the representation of matrix follows. Each of n next lines contains one-digit hexadecimal numbers (that is, these numbers can be represented either as digits from 0 to 9 or as uppercase Latin letters from A to F). Binary representation of each of these numbers denotes next 4 elements of the matrix in the corresponding row. For example, if the number B is given, then the corresponding elements are 1011, and if the number is 5, then the corresponding elements are 0101. Elements are not separated by whitespaces. | 2,500 | Print the number of connected components consisting of 1's. | standard output | |
PASSED | 8a1814011016743b1bfef927677b6b4b | train_001.jsonl | 1509113100 | You are given a matrix of size nβΓβm. Each element of the matrix is either 1 or 0. You have to determine the number of connected components consisting of 1's. Two cells belong to the same component if they have a common border, and both elements in these cells are 1's.Note that the memory limit is unusual! | 16 megabytes | import java.io.*;
import java.util.*;
public class E31 {
static byte[] buffer = new byte[524288];
static int end = 0;
static int ptr = 0;
static int[] parent;
static int FindParent(int v) {
return parent[v] == v ? v : (parent[v] = FindParent(parent[v]));
}
static boolean Union(int a, int b) {
if(parent[a] == -1 || parent[b] == -1) {
return false;
}
a = FindParent(a);
b = FindParent(b);
if(a == b) {
return false;
} else if(a > b) {
parent[b] = a;
} else {
parent[a] = b;
}
return true;
}
static void Slide() {
int m = parent.length / 2;
for(int i = 0; i < m; ++i) {
parent[i] = parent[m + i];
if(parent[i] >= m) {
parent[i] -= m;
}
}
for(int i = m; i < 2 * m; ++i) {
parent[i] = -1;
}
}
static byte getChar() {
while (ptr == end)
{
try {
end = System.in.read(buffer);
} catch (Exception e) {
return ' ';
}
ptr = 0;
}
return buffer[ptr++];
}
public static void main(String[] args) {
InputReader in = new InputReader();
OutputWriter out = new OutputWriter(System.out);
int n = in.nextInt();
int m = in.nextInt();
parent = new int[m * 2];
Arrays.fill(parent, -1);
int ans = 0;
for(int i = 0; i < n; ++i) {
String s = in.next();
for(int j = 0; j < m; j += 4) {
char c = s.charAt(j / 4);
int num = c >= 'A' ? c - 'A' + 10 : c - '0';
for(int k = 0; k < 4; ++k) {
if((num & (1 << (3 - k))) == 0) {
continue;
}
parent[m + j + k] = m + j + k;
ans++;
if(j + k > 0 && Union(m + j + k - 1, m + j + k)) {
ans--;
}
if(Union(j + k, m + j + k)) {
ans--;
}
}
}
Slide();
}
System.out.println(ans);
}
public static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
}
public void println(Object... objects) {
print(objects);
writer.println();
}
public void printf(String format, Object... objects) {
writer.printf(format, objects);
}
public void close() {
writer.close();
}
public void flush() {
writer.flush();
}
}
static class InputReader
{
BufferedReader br;
StringTokenizer st;
public InputReader()
{
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 4\n1\nA\n8", "2 8\n5F\nE3", "1 4\n0"] | 3 seconds | ["3", "2", "0"] | NoteIn the first example the matrix is: 000110101000It is clear that it has three components.The second example: 0101111111100011It is clear that the number of components is 2.There are no 1's in the third example, so the answer is 0. | Java 8 | standard input | [
"dsu"
] | 78b319ee682fa8c4dab53e0fcd018255 | The first line contains two numbers n and m (1ββ€βnββ€β212, 4ββ€βmββ€β214) β the number of rows and columns, respectively. It is guaranteed that m is divisible by 4. Then the representation of matrix follows. Each of n next lines contains one-digit hexadecimal numbers (that is, these numbers can be represented either as digits from 0 to 9 or as uppercase Latin letters from A to F). Binary representation of each of these numbers denotes next 4 elements of the matrix in the corresponding row. For example, if the number B is given, then the corresponding elements are 1011, and if the number is 5, then the corresponding elements are 0101. Elements are not separated by whitespaces. | 2,500 | Print the number of connected components consisting of 1's. | standard output | |
PASSED | a7742adf06be769c0ae006e8f2d57595 | train_001.jsonl | 1509113100 | You are given a matrix of size nβΓβm. Each element of the matrix is either 1 or 0. You have to determine the number of connected components consisting of 1's. Two cells belong to the same component if they have a common border, and both elements in these cells are 1's.Note that the memory limit is unusual! | 16 megabytes | import java.util.*;
import java.io.*;
public class E884 {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
boolean[] prev = new boolean[m];
DisjointSet dsPrev = new DisjointSet(m*2);
int connected = 0;
for (int j = 0; j < n; j++) {
char[] s = br.readLine().toCharArray();
boolean[] cur = new boolean[m];
for (int i = 0; i < m / 4; i++) {
char x = s[i];
int c;
if (x >= 'A')
c = x-'A'+10;
else
c = x-'0';
cur[i*4+0] = (c & 0b1000) != 0;
cur[i*4+1] = (c & 0b0100) != 0;
cur[i*4+2] = (c & 0b0010) != 0;
cur[i*4+3] = (c & 0b0001) != 0;
}
DisjointSet ds = new DisjointSet(m*2);
{
int z = 0;
while (z < m) {
int i = getTrues(cur, z);
if (i == -1) break;
int i2 = getEndTrues(cur, i);
for (; i <= i2; i++) {
if (prev[i])
ds.mergeSets(i,dsPrev.getRepr(i)+m);
if (i+1 <= i2)
ds.mergeSets(i, i+1);
}
z = i2+1;
}
for (int i = 0; i < m; i++)
if (prev[i] && dsPrev.getRepr(i) == i)
if (ds.getSizeOfSet(dsPrev.getRepr(i)+m) == 1)
connected++;
}
prev = cur;
dsPrev = ds;
}
for (int i = 0; i < m; i++)
if (prev[i] && dsPrev.getRepr(i) == i)
connected++;
System.out.println(connected);
}
static int getTrues(boolean[] a, int i) {
while (i < a.length && !a[i])
i++;
if (i == a.length)
return -1;
return i;
}
static int getEndTrues(boolean[] a, int i) {
while (i+1 < a.length && a[i+1])
i++;
return i;
}
}
final class DisjointSet {
/*---- Fields ----*/
// Global properties
private int numSets;
// Per-node properties. This representation is more space-efficient than creating one node object per element.
private int[] parents; // The index of the parent element. An element is a representative iff its parent is itself.
private byte[] ranks; // Always in the range [0, floor(log2(numElems))]. Thus has a maximum value of 30.
int[] sizes; // Positive number if the element is a representative, otherwise zero.
/*---- Constructors ----*/
// Constructs a new set containing the given number of singleton sets.
// For example, new DisjointSet(3) --> {{0}, {1}, {2}}.
public DisjointSet(int numElems) {
if (numElems < 0)
throw new IllegalArgumentException("Number of elements must be non-negative");
parents = new int[numElems];
ranks = new byte[numElems];
sizes = new int[numElems];
for (int i = 0; i < numElems; i++) {
parents[i] = i;
ranks[i] = 0;
sizes[i] = 1;
}
numSets = numElems;
}
/*---- Methods ----*/
// Returns the number of elements among the set of disjoint sets; this was the number passed
// into the constructor and is constant for the lifetime of the object. All the other methods
// require the argument elemIndex to satisfy 0 <= elemIndex < getNumberOfElements().
public int getNumberOfElements() {
return parents.length;
}
// Returns the number of disjoint sets overall. This number decreases monotonically as time progresses;
// each call to mergeSets() either decrements the number by one or leaves it unchanged. 0 <= result <= getNumberOfElements().
public int getNumberOfSets() {
return numSets;
}
// (Private) Returns the representative element for the set containing the given element. This method is also
// known as "find" in the literature. Also performs path compression, which alters the internal state to
// improve the speed of future queries, but has no externally visible effect on the values returned.
int getRepr(int elemIndex) {
if (elemIndex < 0 || elemIndex >= parents.length)
throw new IndexOutOfBoundsException();
// Follow parent pointers until we reach a representative
int parent = parents[elemIndex];
if (parent == elemIndex)
return elemIndex;
while (true) {
int grandparent = parents[parent];
if (grandparent == parent)
return parent;
parents[elemIndex] = grandparent; // Partial path compression
elemIndex = parent;
parent = grandparent;
}
//parents[elemIndex] = getRepr(parents[elemIndex]);
//return parents[elemIndex];
}
// Returns the size of the set that the given element is a member of. 1 <= result <= getNumberOfElements().
public int getSizeOfSet(int elemIndex) {
return sizes[getRepr(elemIndex)];
}
// Tests whether the given two elements are members of the same set. Note that the arguments are orderless.
public boolean areInSameSet(int elemIndex0, int elemIndex1) {
return getRepr(elemIndex0) == getRepr(elemIndex1);
}
// Merges together the sets that the given two elements belong to. This method is also known as "union" in the literature.
// If the two elements belong to different sets, then the two sets are merged and the method returns true.
// Otherwise they belong in the same set, nothing is changed and the method returns false. Note that the arguments are orderless.
public boolean mergeSets(int elemIndex0, int elemIndex1) {
// Get representatives
int repr0 = getRepr(elemIndex0);
int repr1 = getRepr(elemIndex1);
if (repr0 == repr1)
return false;
// Compare ranks
int cmp = ranks[repr0] - ranks[repr1];
if (cmp == 0) // Increment repr0's rank if both nodes have same rank
ranks[repr0]++;
else if (cmp < 0) { // Swap to ensure that repr0's rank >= repr1's rank
int temp = repr0;
repr0 = repr1;
repr1 = temp;
}
// Graft repr1's subtree onto node repr0
parents[repr1] = repr0;
sizes[repr0] += sizes[repr1];
sizes[repr1] = 0;
numSets--;
return true;
}
// For unit tests. This detects many but not all invalid data structures, throwing an AssertionError
// if a structural invariant is known to be violated. This always returns silently on a valid object.
void checkStructure() {
int numRepr = 0;
for (int i = 0; i < parents.length; i++) {
int parent = parents[i];
int rank = ranks[i];
int size = sizes[i];
boolean isRepr = parent == i;
if (isRepr)
numRepr++;
boolean ok = true;
ok &= 0 <= parent && parent < parents.length;
ok &= 0 <= rank && (isRepr || rank < ranks[parent]);
ok &= !isRepr && size == 0 || isRepr && size >= (1 << rank);
if (!ok)
throw new AssertionError();
}
if (!(0 <= numSets && numSets == numRepr && numSets <= parents.length))
throw new AssertionError();
}
}
| Java | ["3 4\n1\nA\n8", "2 8\n5F\nE3", "1 4\n0"] | 3 seconds | ["3", "2", "0"] | NoteIn the first example the matrix is: 000110101000It is clear that it has three components.The second example: 0101111111100011It is clear that the number of components is 2.There are no 1's in the third example, so the answer is 0. | Java 8 | standard input | [
"dsu"
] | 78b319ee682fa8c4dab53e0fcd018255 | The first line contains two numbers n and m (1ββ€βnββ€β212, 4ββ€βmββ€β214) β the number of rows and columns, respectively. It is guaranteed that m is divisible by 4. Then the representation of matrix follows. Each of n next lines contains one-digit hexadecimal numbers (that is, these numbers can be represented either as digits from 0 to 9 or as uppercase Latin letters from A to F). Binary representation of each of these numbers denotes next 4 elements of the matrix in the corresponding row. For example, if the number B is given, then the corresponding elements are 1011, and if the number is 5, then the corresponding elements are 0101. Elements are not separated by whitespaces. | 2,500 | Print the number of connected components consisting of 1's. | standard output | |
PASSED | e1df42989f3948655466294470954819 | train_001.jsonl | 1308236400 | It is nighttime and Joe the Elusive got into the country's main bank's safe. The safe has n cells positioned in a row, each of them contains some amount of diamonds. Let's make the problem more comfortable to work with and mark the cells with positive numbers from 1 to n from the left to the right.Unfortunately, Joe didn't switch the last security system off. On the plus side, he knows the way it works.Every minute the security system calculates the total amount of diamonds for each two adjacent cells (for the cells between whose numbers difference equals 1). As a result of this check we get an nβ-β1 sums. If at least one of the sums differs from the corresponding sum received during the previous check, then the security system is triggered.Joe can move the diamonds from one cell to another between the security system's checks. He manages to move them no more than m times between two checks. One of the three following operations is regarded as moving a diamond: moving a diamond from any cell to any other one, moving a diamond from any cell to Joe's pocket, moving a diamond from Joe's pocket to any cell. Initially Joe's pocket is empty, and it can carry an unlimited amount of diamonds. It is considered that before all Joe's actions the system performs at least one check.In the morning the bank employees will come, which is why Joe has to leave the bank before that moment. Joe has only k minutes left before morning, and on each of these k minutes he can perform no more than m operations. All that remains in Joe's pocket, is considered his loot.Calculate the largest amount of diamonds Joe can carry with him. Don't forget that the security system shouldn't be triggered (even after Joe leaves the bank) and Joe should leave before morning. | 256 megabytes | import java.io.*;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = sc.nextInt();
int m = sc.nextInt();
int k = sc.nextInt();
int[] a = sc.nextIntArray(n);
if (n % 2 == 0) {
System.out.println(0);
return;
}
int min = (int) (1e5 + 10);
for (int i = 0; i < n; i += 2)
min = Math.min(min, a[i]);
int y = n / 2 + 1;
out.println(Math.min(min, 1l * k * (m / y)));
out.flush();
out.close();
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream system) {
br = new BufferedReader(new InputStreamReader(system));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public String nextLine() throws IOException {
return br.readLine();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public char nextChar() throws IOException {
return next().charAt(0);
}
public Long nextLong() throws IOException {
return Long.parseLong(next());
}
public boolean ready() throws IOException {
return br.ready();
}
public int[] nextIntArray(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public long[] nextLongArray(int n) throws IOException {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public Integer[] nextIntegerArray(int n) throws IOException {
Integer[] a = new Integer[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public double[] nextDoubleArray(int n) throws IOException {
double[] ans = new double[n];
for (int i = 0; i < n; i++)
ans[i] = nextDouble();
return ans;
}
public short nextShort() throws IOException {
return Short.parseShort(next());
}
}
} | Java | ["2 3 1\n2 3", "3 2 2\n4 1 3"] | 1 second | ["0", "2"] | NoteIn the second sample Joe can act like this:The diamonds' initial positions are 4 1 3.During the first period of time Joe moves a diamond from the 1-th cell to the 2-th one and a diamond from the 3-th cell to his pocket.By the end of the first period the diamonds' positions are 3 2 2. The check finds no difference and the security system doesn't go off.During the second period Joe moves a diamond from the 3-rd cell to the 2-nd one and puts a diamond from the 1-st cell to his pocket.By the end of the second period the diamonds' positions are 2 3 1. The check finds no difference again and the security system doesn't go off.Now Joe leaves with 2 diamonds in his pocket. | Java 8 | standard input | [
"greedy",
"math"
] | b81e7a786e4083cf7188f718bc045a85 | The first line contains integers n, m and k (1ββ€βnββ€β104, 1ββ€βm,βkββ€β109). The next line contains n numbers. The i-th number is equal to the amount of diamonds in the i-th cell β it is an integer from 0 to 105. | 1,800 | Print a single number β the maximum number of diamonds Joe can steal. | standard output | |
PASSED | dad935bcb6ba7aa5f3aa3a5b0970ee7a | train_001.jsonl | 1308236400 | It is nighttime and Joe the Elusive got into the country's main bank's safe. The safe has n cells positioned in a row, each of them contains some amount of diamonds. Let's make the problem more comfortable to work with and mark the cells with positive numbers from 1 to n from the left to the right.Unfortunately, Joe didn't switch the last security system off. On the plus side, he knows the way it works.Every minute the security system calculates the total amount of diamonds for each two adjacent cells (for the cells between whose numbers difference equals 1). As a result of this check we get an nβ-β1 sums. If at least one of the sums differs from the corresponding sum received during the previous check, then the security system is triggered.Joe can move the diamonds from one cell to another between the security system's checks. He manages to move them no more than m times between two checks. One of the three following operations is regarded as moving a diamond: moving a diamond from any cell to any other one, moving a diamond from any cell to Joe's pocket, moving a diamond from Joe's pocket to any cell. Initially Joe's pocket is empty, and it can carry an unlimited amount of diamonds. It is considered that before all Joe's actions the system performs at least one check.In the morning the bank employees will come, which is why Joe has to leave the bank before that moment. Joe has only k minutes left before morning, and on each of these k minutes he can perform no more than m operations. All that remains in Joe's pocket, is considered his loot.Calculate the largest amount of diamonds Joe can carry with him. Don't forget that the security system shouldn't be triggered (even after Joe leaves the bank) and Joe should leave before morning. | 256 megabytes | // /cf/74/2/practice/ROBBERY
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n_cells = sc.nextInt();
long n_ops = sc.nextLong(), n_mins = sc.nextLong();
long min_diamonds = Long.MAX_VALUE;
for (int i = 1; i <= n_cells; i++) {
long n_diamonds = sc.nextLong();
if (i % 2 == 1)
min_diamonds = Math.min(min_diamonds, n_diamonds);
}
if (n_cells % 2 == 0) {
System.out.println(0);
return;
}
System.out.println(Math.min(min_diamonds, n_ops / ((n_cells + 1) / 2) * n_mins));
}
} | Java | ["2 3 1\n2 3", "3 2 2\n4 1 3"] | 1 second | ["0", "2"] | NoteIn the second sample Joe can act like this:The diamonds' initial positions are 4 1 3.During the first period of time Joe moves a diamond from the 1-th cell to the 2-th one and a diamond from the 3-th cell to his pocket.By the end of the first period the diamonds' positions are 3 2 2. The check finds no difference and the security system doesn't go off.During the second period Joe moves a diamond from the 3-rd cell to the 2-nd one and puts a diamond from the 1-st cell to his pocket.By the end of the second period the diamonds' positions are 2 3 1. The check finds no difference again and the security system doesn't go off.Now Joe leaves with 2 diamonds in his pocket. | Java 8 | standard input | [
"greedy",
"math"
] | b81e7a786e4083cf7188f718bc045a85 | The first line contains integers n, m and k (1ββ€βnββ€β104, 1ββ€βm,βkββ€β109). The next line contains n numbers. The i-th number is equal to the amount of diamonds in the i-th cell β it is an integer from 0 to 105. | 1,800 | Print a single number β the maximum number of diamonds Joe can steal. | standard output | |
PASSED | 884bb1432d994bf62c11bc17a1c62e7f | train_001.jsonl | 1308236400 | It is nighttime and Joe the Elusive got into the country's main bank's safe. The safe has n cells positioned in a row, each of them contains some amount of diamonds. Let's make the problem more comfortable to work with and mark the cells with positive numbers from 1 to n from the left to the right.Unfortunately, Joe didn't switch the last security system off. On the plus side, he knows the way it works.Every minute the security system calculates the total amount of diamonds for each two adjacent cells (for the cells between whose numbers difference equals 1). As a result of this check we get an nβ-β1 sums. If at least one of the sums differs from the corresponding sum received during the previous check, then the security system is triggered.Joe can move the diamonds from one cell to another between the security system's checks. He manages to move them no more than m times between two checks. One of the three following operations is regarded as moving a diamond: moving a diamond from any cell to any other one, moving a diamond from any cell to Joe's pocket, moving a diamond from Joe's pocket to any cell. Initially Joe's pocket is empty, and it can carry an unlimited amount of diamonds. It is considered that before all Joe's actions the system performs at least one check.In the morning the bank employees will come, which is why Joe has to leave the bank before that moment. Joe has only k minutes left before morning, and on each of these k minutes he can perform no more than m operations. All that remains in Joe's pocket, is considered his loot.Calculate the largest amount of diamonds Joe can carry with him. Don't forget that the security system shouldn't be triggered (even after Joe leaves the bank) and Joe should leave before morning. | 256 megabytes | import java.io.*;
import java.util.*;
public class C {
String line = null;
public void run() throws Exception{
BufferedReader br = null;
File file = new File("input.txt");
if(file.exists()){
br = new BufferedReader(new FileReader("input.txt"));
}
else{
br = new BufferedReader(new InputStreamReader(System.in));
}
String s = br.readLine();
String[] ss = s.split(" ");
long n = Integer.parseInt(ss[0]);
long m = Integer.parseInt(ss[1]);
long k = Integer.parseInt(ss[2]);
if(n % 2 == 0 ){
System.out.println("0");
return;
}
s = br.readLine();
ss = s.split(" ");
int tmp = (int)(n/2 + 1);
long[] d = new long[tmp];
for(int i = 0; i < n; i++){
if(i % 2 == 0){
d[i / 2] = Integer.parseInt(ss[i]);
}
}
Arrays.sort(d);
long c = n / 2 + 1;
if(c > m){
System.out.println("0");
return;
}
long cnt = m / c;
cnt *= k;
long min = d[0];
long ans = Math.min(min, cnt);
System.out.println(ans);
}
/**
* @param args
*/
public static void main(String[] args) throws Exception{
C t = new C();
t.run();
}
}
| Java | ["2 3 1\n2 3", "3 2 2\n4 1 3"] | 1 second | ["0", "2"] | NoteIn the second sample Joe can act like this:The diamonds' initial positions are 4 1 3.During the first period of time Joe moves a diamond from the 1-th cell to the 2-th one and a diamond from the 3-th cell to his pocket.By the end of the first period the diamonds' positions are 3 2 2. The check finds no difference and the security system doesn't go off.During the second period Joe moves a diamond from the 3-rd cell to the 2-nd one and puts a diamond from the 1-st cell to his pocket.By the end of the second period the diamonds' positions are 2 3 1. The check finds no difference again and the security system doesn't go off.Now Joe leaves with 2 diamonds in his pocket. | Java 6 | standard input | [
"greedy",
"math"
] | b81e7a786e4083cf7188f718bc045a85 | The first line contains integers n, m and k (1ββ€βnββ€β104, 1ββ€βm,βkββ€β109). The next line contains n numbers. The i-th number is equal to the amount of diamonds in the i-th cell β it is an integer from 0 to 105. | 1,800 | Print a single number β the maximum number of diamonds Joe can steal. | standard output | |
PASSED | eb0d7796567ff0e4a67bec9cf5148677 | train_001.jsonl | 1308236400 | It is nighttime and Joe the Elusive got into the country's main bank's safe. The safe has n cells positioned in a row, each of them contains some amount of diamonds. Let's make the problem more comfortable to work with and mark the cells with positive numbers from 1 to n from the left to the right.Unfortunately, Joe didn't switch the last security system off. On the plus side, he knows the way it works.Every minute the security system calculates the total amount of diamonds for each two adjacent cells (for the cells between whose numbers difference equals 1). As a result of this check we get an nβ-β1 sums. If at least one of the sums differs from the corresponding sum received during the previous check, then the security system is triggered.Joe can move the diamonds from one cell to another between the security system's checks. He manages to move them no more than m times between two checks. One of the three following operations is regarded as moving a diamond: moving a diamond from any cell to any other one, moving a diamond from any cell to Joe's pocket, moving a diamond from Joe's pocket to any cell. Initially Joe's pocket is empty, and it can carry an unlimited amount of diamonds. It is considered that before all Joe's actions the system performs at least one check.In the morning the bank employees will come, which is why Joe has to leave the bank before that moment. Joe has only k minutes left before morning, and on each of these k minutes he can perform no more than m operations. All that remains in Joe's pocket, is considered his loot.Calculate the largest amount of diamonds Joe can carry with him. Don't forget that the security system shouldn't be triggered (even after Joe leaves the bank) and Joe should leave before morning. | 256 megabytes | import java.io.*;
public class cbr74c {
private StreamTokenizer in;
private PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) throws IOException {
new cbr74c().run();
}
private void run() throws IOException {
in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
long n = nextInt(), m = nextInt(), k = nextInt();
int[] a = new int[(int) n];
int q = Integer.MAX_VALUE;
for (int i = 0; i < n; ++i) {
a[i] = nextInt();
if ((i & 1) == 0)
q = Math.min(q, a[i]);
}
if ((n & 1) == 0)
out.println(0);
else if (m < n / 2 + 1)
out.println(0);
else
out.println(Math.min(m / (n / 2 + 1) * k, q));
out.flush();
}
int nextInt() throws IOException {
in.nextToken();
return (int) in.nval;
}
}
| Java | ["2 3 1\n2 3", "3 2 2\n4 1 3"] | 1 second | ["0", "2"] | NoteIn the second sample Joe can act like this:The diamonds' initial positions are 4 1 3.During the first period of time Joe moves a diamond from the 1-th cell to the 2-th one and a diamond from the 3-th cell to his pocket.By the end of the first period the diamonds' positions are 3 2 2. The check finds no difference and the security system doesn't go off.During the second period Joe moves a diamond from the 3-rd cell to the 2-nd one and puts a diamond from the 1-st cell to his pocket.By the end of the second period the diamonds' positions are 2 3 1. The check finds no difference again and the security system doesn't go off.Now Joe leaves with 2 diamonds in his pocket. | Java 6 | standard input | [
"greedy",
"math"
] | b81e7a786e4083cf7188f718bc045a85 | The first line contains integers n, m and k (1ββ€βnββ€β104, 1ββ€βm,βkββ€β109). The next line contains n numbers. The i-th number is equal to the amount of diamonds in the i-th cell β it is an integer from 0 to 105. | 1,800 | Print a single number β the maximum number of diamonds Joe can steal. | standard output | |
PASSED | 19e725f90bc5df03a6614082201accd1 | train_001.jsonl | 1308236400 | It is nighttime and Joe the Elusive got into the country's main bank's safe. The safe has n cells positioned in a row, each of them contains some amount of diamonds. Let's make the problem more comfortable to work with and mark the cells with positive numbers from 1 to n from the left to the right.Unfortunately, Joe didn't switch the last security system off. On the plus side, he knows the way it works.Every minute the security system calculates the total amount of diamonds for each two adjacent cells (for the cells between whose numbers difference equals 1). As a result of this check we get an nβ-β1 sums. If at least one of the sums differs from the corresponding sum received during the previous check, then the security system is triggered.Joe can move the diamonds from one cell to another between the security system's checks. He manages to move them no more than m times between two checks. One of the three following operations is regarded as moving a diamond: moving a diamond from any cell to any other one, moving a diamond from any cell to Joe's pocket, moving a diamond from Joe's pocket to any cell. Initially Joe's pocket is empty, and it can carry an unlimited amount of diamonds. It is considered that before all Joe's actions the system performs at least one check.In the morning the bank employees will come, which is why Joe has to leave the bank before that moment. Joe has only k minutes left before morning, and on each of these k minutes he can perform no more than m operations. All that remains in Joe's pocket, is considered his loot.Calculate the largest amount of diamonds Joe can carry with him. Don't forget that the security system shouldn't be triggered (even after Joe leaves the bank) and Joe should leave before morning. | 256 megabytes | //package Round_74_div2;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
import static java.lang.Math.*;
public class c implements Runnable {
String input = "";
String output = "";
BufferedReader bf;
FastScanner in;
PrintWriter out;
/*
* 1 2 3 0 5
* 0 3 2 1 4
*/
public void solve() throws Exception {
int n = in.nextInt();
int m = in.nextInt();
long k = in.nextInt();
int a[] = new int[n];
for (int i = 0; i<n; i++)
a[i] = in.nextInt();
if (n % 2 == 0){
out.println(0);
return;
}
int min = Integer.MAX_VALUE;
for (int i = 0; i < n; i+=2)
min = min(min, a[i]);
long ans = min(((long)(2 * m / (n + 1))) * k, min);
out.println(ans);
}
public void run() {
try {
if (input.equals("")) {
bf = new BufferedReader(new InputStreamReader(System.in));
} else {
bf = new BufferedReader(new FileReader(input));
}
in = new FastScanner(bf);
if (output.equals("")) {
out = new PrintWriter(System.out);
} else {
out = new PrintWriter(new File(output));
}
solve();
out.flush();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
out.close();
}
}
public static void main(String[] args) {
new Thread(null, new c(), "", 1 << 23).start();
}
class FastScanner {
BufferedReader bf;
StringTokenizer st;
public FastScanner(BufferedReader bf) {
this.bf = bf;
}
public String next() throws Exception {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(bf.readLine());
}
return st.nextToken();
}
public int nextInt() throws Exception {
return Integer.parseInt(next());
}
public long nextLong() throws Exception {
return Long.parseLong(next());
}
public double nextDouble() throws Exception {
return Double.parseDouble(next());
}
}
}
| Java | ["2 3 1\n2 3", "3 2 2\n4 1 3"] | 1 second | ["0", "2"] | NoteIn the second sample Joe can act like this:The diamonds' initial positions are 4 1 3.During the first period of time Joe moves a diamond from the 1-th cell to the 2-th one and a diamond from the 3-th cell to his pocket.By the end of the first period the diamonds' positions are 3 2 2. The check finds no difference and the security system doesn't go off.During the second period Joe moves a diamond from the 3-rd cell to the 2-nd one and puts a diamond from the 1-st cell to his pocket.By the end of the second period the diamonds' positions are 2 3 1. The check finds no difference again and the security system doesn't go off.Now Joe leaves with 2 diamonds in his pocket. | Java 6 | standard input | [
"greedy",
"math"
] | b81e7a786e4083cf7188f718bc045a85 | The first line contains integers n, m and k (1ββ€βnββ€β104, 1ββ€βm,βkββ€β109). The next line contains n numbers. The i-th number is equal to the amount of diamonds in the i-th cell β it is an integer from 0 to 105. | 1,800 | Print a single number β the maximum number of diamonds Joe can steal. | standard output | |
PASSED | 77f26e5421940d20291c3e4cecf2e458 | train_001.jsonl | 1308236400 | It is nighttime and Joe the Elusive got into the country's main bank's safe. The safe has n cells positioned in a row, each of them contains some amount of diamonds. Let's make the problem more comfortable to work with and mark the cells with positive numbers from 1 to n from the left to the right.Unfortunately, Joe didn't switch the last security system off. On the plus side, he knows the way it works.Every minute the security system calculates the total amount of diamonds for each two adjacent cells (for the cells between whose numbers difference equals 1). As a result of this check we get an nβ-β1 sums. If at least one of the sums differs from the corresponding sum received during the previous check, then the security system is triggered.Joe can move the diamonds from one cell to another between the security system's checks. He manages to move them no more than m times between two checks. One of the three following operations is regarded as moving a diamond: moving a diamond from any cell to any other one, moving a diamond from any cell to Joe's pocket, moving a diamond from Joe's pocket to any cell. Initially Joe's pocket is empty, and it can carry an unlimited amount of diamonds. It is considered that before all Joe's actions the system performs at least one check.In the morning the bank employees will come, which is why Joe has to leave the bank before that moment. Joe has only k minutes left before morning, and on each of these k minutes he can perform no more than m operations. All that remains in Joe's pocket, is considered his loot.Calculate the largest amount of diamonds Joe can carry with him. Don't forget that the security system shouldn't be triggered (even after Joe leaves the bank) and Joe should leave before morning. | 256 megabytes | import java.util.*;
public class a {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
long n = in.nextLong();
long m = in.nextLong();
long k = in.nextLong();
long[] v = new long[(int)n];
long min = (long)1e16;
for(int i=0; i<n; i++) {
v[i] = in.nextInt();
if(i%2==0)
min = Math.min(min,v[i]);
}
if(n%2==0)
min = 0;
long steps = m/(n/2+1);
System.out.println(Math.min(steps*k,min));
}
} | Java | ["2 3 1\n2 3", "3 2 2\n4 1 3"] | 1 second | ["0", "2"] | NoteIn the second sample Joe can act like this:The diamonds' initial positions are 4 1 3.During the first period of time Joe moves a diamond from the 1-th cell to the 2-th one and a diamond from the 3-th cell to his pocket.By the end of the first period the diamonds' positions are 3 2 2. The check finds no difference and the security system doesn't go off.During the second period Joe moves a diamond from the 3-rd cell to the 2-nd one and puts a diamond from the 1-st cell to his pocket.By the end of the second period the diamonds' positions are 2 3 1. The check finds no difference again and the security system doesn't go off.Now Joe leaves with 2 diamonds in his pocket. | Java 6 | standard input | [
"greedy",
"math"
] | b81e7a786e4083cf7188f718bc045a85 | The first line contains integers n, m and k (1ββ€βnββ€β104, 1ββ€βm,βkββ€β109). The next line contains n numbers. The i-th number is equal to the amount of diamonds in the i-th cell β it is an integer from 0 to 105. | 1,800 | Print a single number β the maximum number of diamonds Joe can steal. | standard output | |
PASSED | f4a6be7d29968e487a83b10aba3b8ac2 | train_001.jsonl | 1308236400 | It is nighttime and Joe the Elusive got into the country's main bank's safe. The safe has n cells positioned in a row, each of them contains some amount of diamonds. Let's make the problem more comfortable to work with and mark the cells with positive numbers from 1 to n from the left to the right.Unfortunately, Joe didn't switch the last security system off. On the plus side, he knows the way it works.Every minute the security system calculates the total amount of diamonds for each two adjacent cells (for the cells between whose numbers difference equals 1). As a result of this check we get an nβ-β1 sums. If at least one of the sums differs from the corresponding sum received during the previous check, then the security system is triggered.Joe can move the diamonds from one cell to another between the security system's checks. He manages to move them no more than m times between two checks. One of the three following operations is regarded as moving a diamond: moving a diamond from any cell to any other one, moving a diamond from any cell to Joe's pocket, moving a diamond from Joe's pocket to any cell. Initially Joe's pocket is empty, and it can carry an unlimited amount of diamonds. It is considered that before all Joe's actions the system performs at least one check.In the morning the bank employees will come, which is why Joe has to leave the bank before that moment. Joe has only k minutes left before morning, and on each of these k minutes he can perform no more than m operations. All that remains in Joe's pocket, is considered his loot.Calculate the largest amount of diamonds Joe can carry with him. Don't forget that the security system shouldn't be triggered (even after Joe leaves the bank) and Joe should leave before morning. | 256 megabytes | import java.beans.beancontext.BeanContext;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int m = scanner.nextInt();
int k = scanner.nextInt();
int a[] = new int[n];
for (int i = 0; i < n; i ++) a[i] = scanner.nextInt();
long ans = 0;
if (n %2 == 1) {
if (n /2 + 1 <= m ) {
ans = a[0];
for (int i = 0; i <n; i += 2) {
ans = Math.min(ans, a[i]);
}
ans = Math.min(((long)k)*((long)(m/(n/2+1))), ans);
}
if (n == 1) ans = Math.min(((long)k) * ((long)m), a[0]);
}
System.out.println(ans);
}
}
| Java | ["2 3 1\n2 3", "3 2 2\n4 1 3"] | 1 second | ["0", "2"] | NoteIn the second sample Joe can act like this:The diamonds' initial positions are 4 1 3.During the first period of time Joe moves a diamond from the 1-th cell to the 2-th one and a diamond from the 3-th cell to his pocket.By the end of the first period the diamonds' positions are 3 2 2. The check finds no difference and the security system doesn't go off.During the second period Joe moves a diamond from the 3-rd cell to the 2-nd one and puts a diamond from the 1-st cell to his pocket.By the end of the second period the diamonds' positions are 2 3 1. The check finds no difference again and the security system doesn't go off.Now Joe leaves with 2 diamonds in his pocket. | Java 6 | standard input | [
"greedy",
"math"
] | b81e7a786e4083cf7188f718bc045a85 | The first line contains integers n, m and k (1ββ€βnββ€β104, 1ββ€βm,βkββ€β109). The next line contains n numbers. The i-th number is equal to the amount of diamonds in the i-th cell β it is an integer from 0 to 105. | 1,800 | Print a single number β the maximum number of diamonds Joe can steal. | standard output | |
PASSED | 50057c8628332f0ae744e6b1d1bd438f | train_001.jsonl | 1308236400 | It is nighttime and Joe the Elusive got into the country's main bank's safe. The safe has n cells positioned in a row, each of them contains some amount of diamonds. Let's make the problem more comfortable to work with and mark the cells with positive numbers from 1 to n from the left to the right.Unfortunately, Joe didn't switch the last security system off. On the plus side, he knows the way it works.Every minute the security system calculates the total amount of diamonds for each two adjacent cells (for the cells between whose numbers difference equals 1). As a result of this check we get an nβ-β1 sums. If at least one of the sums differs from the corresponding sum received during the previous check, then the security system is triggered.Joe can move the diamonds from one cell to another between the security system's checks. He manages to move them no more than m times between two checks. One of the three following operations is regarded as moving a diamond: moving a diamond from any cell to any other one, moving a diamond from any cell to Joe's pocket, moving a diamond from Joe's pocket to any cell. Initially Joe's pocket is empty, and it can carry an unlimited amount of diamonds. It is considered that before all Joe's actions the system performs at least one check.In the morning the bank employees will come, which is why Joe has to leave the bank before that moment. Joe has only k minutes left before morning, and on each of these k minutes he can perform no more than m operations. All that remains in Joe's pocket, is considered his loot.Calculate the largest amount of diamonds Joe can carry with him. Don't forget that the security system shouldn't be triggered (even after Joe leaves the bank) and Joe should leave before morning. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main{
StreamTokenizer in;
private long nextInt() throws Exception{
in.nextToken();
return (long)in.nval;
}
public void run() throws Exception{
in = new StreamTokenizer(System.in);
int n = (int)nextInt();
long m = nextInt();
long k = nextInt();
long a[] = new long[n];
for(int i=0;i<n;i++) a[i] = nextInt();
if (n % 2 == 1){
long min = a[0];
for(int i=0;i<n;i+=2) min = Math.min(min, a[i]);
long l = m/(n/2+1);
if (l <= 0){
System.out.println(0);
}else{
min = Math.min(min, l * k);
System.out.println(min);
}
}else{
System.out.println(0);
}
}
public static void main(String args[]) throws Exception{
new Main().run();
}
}
| Java | ["2 3 1\n2 3", "3 2 2\n4 1 3"] | 1 second | ["0", "2"] | NoteIn the second sample Joe can act like this:The diamonds' initial positions are 4 1 3.During the first period of time Joe moves a diamond from the 1-th cell to the 2-th one and a diamond from the 3-th cell to his pocket.By the end of the first period the diamonds' positions are 3 2 2. The check finds no difference and the security system doesn't go off.During the second period Joe moves a diamond from the 3-rd cell to the 2-nd one and puts a diamond from the 1-st cell to his pocket.By the end of the second period the diamonds' positions are 2 3 1. The check finds no difference again and the security system doesn't go off.Now Joe leaves with 2 diamonds in his pocket. | Java 6 | standard input | [
"greedy",
"math"
] | b81e7a786e4083cf7188f718bc045a85 | The first line contains integers n, m and k (1ββ€βnββ€β104, 1ββ€βm,βkββ€β109). The next line contains n numbers. The i-th number is equal to the amount of diamonds in the i-th cell β it is an integer from 0 to 105. | 1,800 | Print a single number β the maximum number of diamonds Joe can steal. | standard output | |
PASSED | ffbde3f8bddae5adc5b7a52c0d833479 | train_001.jsonl | 1308236400 | It is nighttime and Joe the Elusive got into the country's main bank's safe. The safe has n cells positioned in a row, each of them contains some amount of diamonds. Let's make the problem more comfortable to work with and mark the cells with positive numbers from 1 to n from the left to the right.Unfortunately, Joe didn't switch the last security system off. On the plus side, he knows the way it works.Every minute the security system calculates the total amount of diamonds for each two adjacent cells (for the cells between whose numbers difference equals 1). As a result of this check we get an nβ-β1 sums. If at least one of the sums differs from the corresponding sum received during the previous check, then the security system is triggered.Joe can move the diamonds from one cell to another between the security system's checks. He manages to move them no more than m times between two checks. One of the three following operations is regarded as moving a diamond: moving a diamond from any cell to any other one, moving a diamond from any cell to Joe's pocket, moving a diamond from Joe's pocket to any cell. Initially Joe's pocket is empty, and it can carry an unlimited amount of diamonds. It is considered that before all Joe's actions the system performs at least one check.In the morning the bank employees will come, which is why Joe has to leave the bank before that moment. Joe has only k minutes left before morning, and on each of these k minutes he can perform no more than m operations. All that remains in Joe's pocket, is considered his loot.Calculate the largest amount of diamonds Joe can carry with him. Don't forget that the security system shouldn't be triggered (even after Joe leaves the bank) and Joe should leave before morning. | 256 megabytes | import java.util.Scanner;
public class Robbery {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int k = sc.nextInt();
int[] diamonds = new int[n];
for (int i = 0; i < n; i++) {
diamonds[i] = sc.nextInt();
}
// if n is even the sum of diamonds is always constant, hence
// there is no possibility of theft
if (n % 2 == 0) {
System.out.println(0);
return;
}
// However when n is odd it is possible to take 1 diamond from 0, 2, 4 ...
// cells in each move. Now Joe has k minutes and in each such minute he can
// do m such operations. So the max no. of diamonds he can take is
long maxPossible = k * ((long)m / ( (n + 1) / 2));
// However, it is possible that while taking diamonds from cells 0, 2, 4...
// one of the cells becomes 0. In such a case he would not be able to take any
// more diamond even though he is eligible to by above
int minOfCells = Integer.MAX_VALUE;
for (int i = 0; i < n; i += 2)
minOfCells = Math.min(minOfCells, diamonds[i]);
System.out.println(Math.min(minOfCells, maxPossible));
}
} | Java | ["2 3 1\n2 3", "3 2 2\n4 1 3"] | 1 second | ["0", "2"] | NoteIn the second sample Joe can act like this:The diamonds' initial positions are 4 1 3.During the first period of time Joe moves a diamond from the 1-th cell to the 2-th one and a diamond from the 3-th cell to his pocket.By the end of the first period the diamonds' positions are 3 2 2. The check finds no difference and the security system doesn't go off.During the second period Joe moves a diamond from the 3-rd cell to the 2-nd one and puts a diamond from the 1-st cell to his pocket.By the end of the second period the diamonds' positions are 2 3 1. The check finds no difference again and the security system doesn't go off.Now Joe leaves with 2 diamonds in his pocket. | Java 6 | standard input | [
"greedy",
"math"
] | b81e7a786e4083cf7188f718bc045a85 | The first line contains integers n, m and k (1ββ€βnββ€β104, 1ββ€βm,βkββ€β109). The next line contains n numbers. The i-th number is equal to the amount of diamonds in the i-th cell β it is an integer from 0 to 105. | 1,800 | Print a single number β the maximum number of diamonds Joe can steal. | standard output | |
PASSED | 2c3882884be058ee66af8a20476aae7f | train_001.jsonl | 1308236400 | It is nighttime and Joe the Elusive got into the country's main bank's safe. The safe has n cells positioned in a row, each of them contains some amount of diamonds. Let's make the problem more comfortable to work with and mark the cells with positive numbers from 1 to n from the left to the right.Unfortunately, Joe didn't switch the last security system off. On the plus side, he knows the way it works.Every minute the security system calculates the total amount of diamonds for each two adjacent cells (for the cells between whose numbers difference equals 1). As a result of this check we get an nβ-β1 sums. If at least one of the sums differs from the corresponding sum received during the previous check, then the security system is triggered.Joe can move the diamonds from one cell to another between the security system's checks. He manages to move them no more than m times between two checks. One of the three following operations is regarded as moving a diamond: moving a diamond from any cell to any other one, moving a diamond from any cell to Joe's pocket, moving a diamond from Joe's pocket to any cell. Initially Joe's pocket is empty, and it can carry an unlimited amount of diamonds. It is considered that before all Joe's actions the system performs at least one check.In the morning the bank employees will come, which is why Joe has to leave the bank before that moment. Joe has only k minutes left before morning, and on each of these k minutes he can perform no more than m operations. All that remains in Joe's pocket, is considered his loot.Calculate the largest amount of diamonds Joe can carry with him. Don't forget that the security system shouldn't be triggered (even after Joe leaves the bank) and Joe should leave before morning. | 256 megabytes | import java.io.*;
import java.util.StringTokenizer;
public class Robbery {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(in.readLine());
int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
long k = Long.parseLong(st.nextToken());
int[] diam = new int[n];
st = new StringTokenizer(in.readLine());
for (int i = 0; i<n; i++) {
diam[i] = Integer.parseInt(st.nextToken());
}
long ans;
if (n == 1) {
ans = Math.min(diam[0], (long)k*m);
} else if (n % 2 == 0) {
ans = 0;
} else if (m < n/2 + 1) {
ans = 0;
} else {
int mini = Integer.MAX_VALUE;
for (int i = 0; i < n; i++) {
if (i % 2 == 0) {
mini = Math.min(mini, diam[i]);
}
}
int d = n/2 + 1;
ans = Math.min(mini, (m/d)*k);
}
System.out.println(ans);
}
}
| Java | ["2 3 1\n2 3", "3 2 2\n4 1 3"] | 1 second | ["0", "2"] | NoteIn the second sample Joe can act like this:The diamonds' initial positions are 4 1 3.During the first period of time Joe moves a diamond from the 1-th cell to the 2-th one and a diamond from the 3-th cell to his pocket.By the end of the first period the diamonds' positions are 3 2 2. The check finds no difference and the security system doesn't go off.During the second period Joe moves a diamond from the 3-rd cell to the 2-nd one and puts a diamond from the 1-st cell to his pocket.By the end of the second period the diamonds' positions are 2 3 1. The check finds no difference again and the security system doesn't go off.Now Joe leaves with 2 diamonds in his pocket. | Java 6 | standard input | [
"greedy",
"math"
] | b81e7a786e4083cf7188f718bc045a85 | The first line contains integers n, m and k (1ββ€βnββ€β104, 1ββ€βm,βkββ€β109). The next line contains n numbers. The i-th number is equal to the amount of diamonds in the i-th cell β it is an integer from 0 to 105. | 1,800 | Print a single number β the maximum number of diamonds Joe can steal. | standard output | |
PASSED | 3f40862ec3b553e2e4a9bbea1fe8a407 | train_001.jsonl | 1308236400 | It is nighttime and Joe the Elusive got into the country's main bank's safe. The safe has n cells positioned in a row, each of them contains some amount of diamonds. Let's make the problem more comfortable to work with and mark the cells with positive numbers from 1 to n from the left to the right.Unfortunately, Joe didn't switch the last security system off. On the plus side, he knows the way it works.Every minute the security system calculates the total amount of diamonds for each two adjacent cells (for the cells between whose numbers difference equals 1). As a result of this check we get an nβ-β1 sums. If at least one of the sums differs from the corresponding sum received during the previous check, then the security system is triggered.Joe can move the diamonds from one cell to another between the security system's checks. He manages to move them no more than m times between two checks. One of the three following operations is regarded as moving a diamond: moving a diamond from any cell to any other one, moving a diamond from any cell to Joe's pocket, moving a diamond from Joe's pocket to any cell. Initially Joe's pocket is empty, and it can carry an unlimited amount of diamonds. It is considered that before all Joe's actions the system performs at least one check.In the morning the bank employees will come, which is why Joe has to leave the bank before that moment. Joe has only k minutes left before morning, and on each of these k minutes he can perform no more than m operations. All that remains in Joe's pocket, is considered his loot.Calculate the largest amount of diamonds Joe can carry with him. Don't forget that the security system shouldn't be triggered (even after Joe leaves the bank) and Joe should leave before morning. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner r = new Scanner(System.in);
int n = r.nextInt();
long m = r.nextInt();
long k = r.nextInt();
int[] a = new int[n];
for(int i = 0; i < n; i++)
a[i] = r.nextInt();
if(n == 1){
System.out.println(Math.min(m*k, a[0]));
}else if(n%2 == 1 && m > 1){
m /= ((n/2)+1);
long res = k*m;
for(int i = 0; i < a.length; i += 2)
res = Math.min(res, a[i]);
System.out.println(res);
}else{
System.out.println(0);
}
}
}
| Java | ["2 3 1\n2 3", "3 2 2\n4 1 3"] | 1 second | ["0", "2"] | NoteIn the second sample Joe can act like this:The diamonds' initial positions are 4 1 3.During the first period of time Joe moves a diamond from the 1-th cell to the 2-th one and a diamond from the 3-th cell to his pocket.By the end of the first period the diamonds' positions are 3 2 2. The check finds no difference and the security system doesn't go off.During the second period Joe moves a diamond from the 3-rd cell to the 2-nd one and puts a diamond from the 1-st cell to his pocket.By the end of the second period the diamonds' positions are 2 3 1. The check finds no difference again and the security system doesn't go off.Now Joe leaves with 2 diamonds in his pocket. | Java 6 | standard input | [
"greedy",
"math"
] | b81e7a786e4083cf7188f718bc045a85 | The first line contains integers n, m and k (1ββ€βnββ€β104, 1ββ€βm,βkββ€β109). The next line contains n numbers. The i-th number is equal to the amount of diamonds in the i-th cell β it is an integer from 0 to 105. | 1,800 | Print a single number β the maximum number of diamonds Joe can steal. | standard output | |
PASSED | 61364c4dc1057f5834ae43ac5ae573ea | train_001.jsonl | 1308236400 | It is nighttime and Joe the Elusive got into the country's main bank's safe. The safe has n cells positioned in a row, each of them contains some amount of diamonds. Let's make the problem more comfortable to work with and mark the cells with positive numbers from 1 to n from the left to the right.Unfortunately, Joe didn't switch the last security system off. On the plus side, he knows the way it works.Every minute the security system calculates the total amount of diamonds for each two adjacent cells (for the cells between whose numbers difference equals 1). As a result of this check we get an nβ-β1 sums. If at least one of the sums differs from the corresponding sum received during the previous check, then the security system is triggered.Joe can move the diamonds from one cell to another between the security system's checks. He manages to move them no more than m times between two checks. One of the three following operations is regarded as moving a diamond: moving a diamond from any cell to any other one, moving a diamond from any cell to Joe's pocket, moving a diamond from Joe's pocket to any cell. Initially Joe's pocket is empty, and it can carry an unlimited amount of diamonds. It is considered that before all Joe's actions the system performs at least one check.In the morning the bank employees will come, which is why Joe has to leave the bank before that moment. Joe has only k minutes left before morning, and on each of these k minutes he can perform no more than m operations. All that remains in Joe's pocket, is considered his loot.Calculate the largest amount of diamonds Joe can carry with him. Don't forget that the security system shouldn't be triggered (even after Joe leaves the bank) and Joe should leave before morning. | 256 megabytes | import java.util.Scanner;
public class P3 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
long m = in.nextInt();
long k = in.nextInt();
int[] b = new int[n];
for (int i = 0; i < n; i++) {
b[i] = in.nextInt();
}
int count = (int) Math.ceil(n / 2.);
if (n == 1) {
int res = (int) Math.min(b[0], k * m);
System.out.println(res);
} else if (n % 2 == 0) {
System.out.println(0);
} else if (count > m) {
System.out.println(0);
} else {
int min = b[0];
for (int i = 0; i < n / 2; i++) {
min = Math.min(min, b[2 * (i + 1)]);
}
int res = (int) Math.min(min, k * (m / count));
System.out.println(res);
}
}
}
| Java | ["2 3 1\n2 3", "3 2 2\n4 1 3"] | 1 second | ["0", "2"] | NoteIn the second sample Joe can act like this:The diamonds' initial positions are 4 1 3.During the first period of time Joe moves a diamond from the 1-th cell to the 2-th one and a diamond from the 3-th cell to his pocket.By the end of the first period the diamonds' positions are 3 2 2. The check finds no difference and the security system doesn't go off.During the second period Joe moves a diamond from the 3-rd cell to the 2-nd one and puts a diamond from the 1-st cell to his pocket.By the end of the second period the diamonds' positions are 2 3 1. The check finds no difference again and the security system doesn't go off.Now Joe leaves with 2 diamonds in his pocket. | Java 6 | standard input | [
"greedy",
"math"
] | b81e7a786e4083cf7188f718bc045a85 | The first line contains integers n, m and k (1ββ€βnββ€β104, 1ββ€βm,βkββ€β109). The next line contains n numbers. The i-th number is equal to the amount of diamonds in the i-th cell β it is an integer from 0 to 105. | 1,800 | Print a single number β the maximum number of diamonds Joe can steal. | standard output | |
PASSED | 7450882d4d6d889580c51222394c56e5 | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes | import java.util.Scanner;
public class Letter {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String s = in.nextLine();
String check = in.nextLine();
for(int i=0;i<check.length();i++){
if(check.charAt(i)==' ')
continue;
if((!s.contains(check.charAt(i)+""))|| (count(s,check.charAt(i))<count(check,check.charAt(i)))){
System.out.println("NO");
System.exit(0);
}
}
System.out.println("YES");
}
static int count(String s,char ch){
int c=0;
for(int i=0;i<s.length();i++){
if(s.charAt(i)==ch)
c++;
}
return c;
}
}
| Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | 5279cfbfdf748e9dc5edc8ac703a7226 | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes |
import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
public class A1008 {
public static void main(String [] args) /*throws Exception*/ {
InputStream inputReader = System.in;
OutputStream outputReader = System.out;
InputReader in = new InputReader(inputReader);//new InputReader(new FileInputStream(new File("input.txt")));new InputReader(inputReader);
PrintWriter out = new PrintWriter(outputReader);//new PrintWriter(new FileOutputStream(new File("output.txt")));
Algorithm solver = new Algorithm();
solver.solve(in, out);
out.close();
}
}
class Algorithm {
void solve(InputReader ir, PrintWriter pw) {
String S1 = ir.nextLine(), S2 = ir.nextLine();
char [] arr1 = S1.toCharArray(), arr2 = S2.toCharArray();
for (int i = 0; i < arr2.length; i++) {
if (arr2[i] != ' ') {
for (int j = 0; j < arr1.length; j++) {
if (arr1[j] == arr2[i]) {
arr1[j] = ' ';
arr2[i] = ' ';
break;
}
}
}
}
String line = new String(arr2).trim();
if (line.isEmpty()) pw.print("YES");
else pw.print("NO");
}
private static void mergeSort(int[] array) {
if(array.length == 1)
return;
int[] first = new int[array.length / 2];
int[] second = new int[array.length - first.length];
System.arraycopy(array, 0, first, 0, first.length);
System.arraycopy(array, first.length, second, 0, second.length);
mergeSort(first);
mergeSort(second);
merge(first, second, array);
}
private static void merge(int[] first, int[] second, int[] result) {
int iFirst = 0;
int iSecond = 0;
int j = 0;
while (iFirst < first.length && iSecond < second.length) {
if (first[iFirst] < second[iSecond]) {
result[j] = first[iFirst];
iFirst++;
}
else {
result[j] = second[iSecond];
iSecond++;
}
j++;
}
System.arraycopy(first, iFirst, result, j, first.length - iFirst);
System.arraycopy(second, iSecond, result, j, second.length - iSecond);
}
}
class InputReader {
private BufferedReader reader;
private StringTokenizer tokenizer;
InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
String nextLine(){
String fullLine;
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
fullLine = reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
return fullLine;
}
return null;
}
String [] toArray() {
return nextLine().split(" ");
}
int nextInt() {
return Integer.parseInt(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
long nextLong() {
return Long.parseLong(next());
}
} | Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | fdb20af26e32d6540a7a35ea50cc17f6 | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes |
import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
public class A1008 {
public static void main(String [] args) /*throws Exception*/ {
InputStream inputReader = System.in;
OutputStream outputReader = System.out;
InputReader in = new InputReader(inputReader);//new InputReader(new FileInputStream(new File("input.txt")));new InputReader(inputReader);
PrintWriter out = new PrintWriter(outputReader);//new PrintWriter(new FileOutputStream(new File("output.txt")));
Algorithm solver = new Algorithm();
solver.solve(in, out);
out.close();
}
}
class Algorithm {
void solve(InputReader ir, PrintWriter pw) {
String S1 = ir.nextLine(), S2 = ir.nextLine();
char [] arr1 = S1.toCharArray(), arr2 = S2.toCharArray();
for (int i = 0; i < arr2.length; i++) {
boolean stop = true;
if (arr2[i] != ' ') {
for (int j = 0; j < arr1.length; j++) {
if (arr1[j] == arr2[i]) {
arr1[j] = ' ';
stop = false;
break;
}
}
if (stop) {
pw.print("NO");
return;
}
}
}
pw.print("YES");
}
private static void mergeSort(int[] array) {
if(array.length == 1)
return;
int[] first = new int[array.length / 2];
int[] second = new int[array.length - first.length];
System.arraycopy(array, 0, first, 0, first.length);
System.arraycopy(array, first.length, second, 0, second.length);
mergeSort(first);
mergeSort(second);
merge(first, second, array);
}
private static void merge(int[] first, int[] second, int[] result) {
int iFirst = 0;
int iSecond = 0;
int j = 0;
while (iFirst < first.length && iSecond < second.length) {
if (first[iFirst] < second[iSecond]) {
result[j] = first[iFirst];
iFirst++;
}
else {
result[j] = second[iSecond];
iSecond++;
}
j++;
}
System.arraycopy(first, iFirst, result, j, first.length - iFirst);
System.arraycopy(second, iSecond, result, j, second.length - iSecond);
}
}
class InputReader {
private BufferedReader reader;
private StringTokenizer tokenizer;
InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
String nextLine(){
String fullLine;
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
fullLine = reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
return fullLine;
}
return null;
}
String [] toArray() {
return nextLine().split(" ");
}
int nextInt() {
return Integer.parseInt(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
long nextLong() {
return Long.parseLong(next());
}
} | Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | 8f12584e86cb9af3b4257d8702905d5e | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes | /*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
//package b.letter.cf;
import java.util.HashMap;
import java.util.Scanner;
/**
*
* @author karim
*/
public class BLetterCF {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int[] occurance = new int[722];
String s1 = cin.nextLine();
int len = s1.length();
for(int i = 0;i < len;i++)
occurance[s1.charAt(i)]++;
s1 = cin.nextLine();
len = s1.length();
boolean f = true;
for(int i = 0;i < len;i++){
if(s1.charAt(i) == ' ')
continue;
if(occurance[s1.charAt(i)] == 0) {
f = false;
break;
}
occurance[s1.charAt(i)]--;
}
System.out.println(f?"YES":"NO");
}
}
| Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | f3e4ef800812d4d5c2cfcea50bf13687 | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes | import java.util.*;
public class Solution{
public static void main(String []args){
Scanner sc=new Scanner(System.in);
String head=sc.nextLine();
String text=sc.nextLine();
int i,flag=1;
int count[]=new int[60];
for(i=0;i<head.length();i++){
if(head.charAt(i)==' ')
continue;
count[(int)head.charAt(i)-65]++;
}
for(i=0;i<text.length();i++){
if(text.charAt(i)==' ')
continue;
if(count[(int)text.charAt(i)-65]==0){
flag=0;
break;
}
else{
count[(int)text.charAt(i)-65]--;
}
}
if(flag==1)
System.out.print("YES");
else
System.out.print("NO");
}
} | Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | 8b401c8f3aec0fa32c2d5eae3a01748a | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes | import java.util.Scanner;
public class Letter {
public static void main(String[] args) {
String s1, s2;
Scanner n = new Scanner(System.in);
s1 = n.nextLine();
s2 = n.nextLine();
n.close();
s2 = s2.replaceAll(" ", "");
boolean flag = true;
for (int i = 0; i < s2.length(); i++) {
Character ch = s2.charAt(i);
if (s1.contains(ch.toString())) {
s1 = s1.replaceFirst(ch.toString(), "");
} else {
flag = false;
break;
}
}
if (flag) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}
| Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | d20a7a4c4526a45fd0a22d608e2c23fd | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes |
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
String str, strWithoutSpace,str2,strWithoutSpace2;
Scanner scan = new Scanner(System.in);
str = scan.nextLine();
strWithoutSpace = str.replaceAll(" ", "");
//System.out.println(strWithoutSpace);
str2 = scan.nextLine();
strWithoutSpace2 = str2.replaceAll(" ", "");
String[] out = strWithoutSpace.split("");
String[] out2 = strWithoutSpace2.split("");
int check = 0;
for(int i = 0;i<out2.length;i++){
for(int j = 0;j<out.length;j++){
if(out2[i].equals(out[j])){
out[j] = "1";
break;
}
}
}
for(int i = 0;i<out.length;i++){
if(out[i]=="1")
check++;
}
if(check == out2.length)
System.out.print("YES");
else
System.out.print("NO");
}
} | Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | a338dbf261c56b2a076b6f87f15d4952 | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes | import java.util.Scanner;
import java.util.Set;
public class bufferedTry {
public static void main (String args[]) {
Scanner key = new Scanner (System.in);
String input1 = key.nextLine();
String input2 = key.nextLine();
int checker1=0;
int checker2=0;
boolean check = false;
int checkerInput = 0;
int checkerSecond [] = new int [input2.length()];
int checkerFirst [] = new int [input1.length()];
char FirstChar [] = input1.toCharArray();
char SecondChar [] = input2.toCharArray();
for (int i=0; i<input2.length(); i++){
for (int j=0; j<input1.length(); j++){
if (SecondChar[i]==FirstChar[j]){
checkerSecond[i]++;
FirstChar[j]=' ';
break;
}
}
}
//First Input Checker
for (int i=0; i<input2.length(); i++){
if (checkerSecond[i]==0){
System.out.println("NO");
checkerInput=10;
break;
}
else
check = true;
}
if (check==true&&checkerInput!=10)
System.out.println ("YES");
}
} | Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | 9210386d7bddf421fe3a9f1797ef7325 | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes | import java.util.Scanner;
public class Letter {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s = new Scanner(System.in);
int comp = 0;
int flag = 1;
String let = s.nextLine();
String l = s.nextLine();
int[] small = new int[26];
int[] cap = new int[26];
char[] z = let.toCharArray();
char[] x = l.toCharArray();
for (int i = 0; i < let.length() ; i++) {
if (z[i] >= 97 && z[i] <= 123) {
// small
small[z[i] - 97]++;
} else if (z[i] < 97 && z[i] > 64) {
cap[z[i] - 65]++;
}
}
/* if (comp > 52) {
System.out.println("YES");
} else { */
for (int i = 0; i < l.length(); i++) {
if (x[i] >= 97 && x[i] <= 123) {
// small
if (small[x[i] - 97] == 0) {
flag = 0;
break;
}
small[x[i] - 97]--;
} else if (x[i] < 97 && x[i] > 64) {
if (cap[x[i] - 65] == 0) {
flag = 0;
break;
}
cap[x[i] - 65]--;
}
}
if (flag == 0) {
System.out.println("NO");
} else {
System.out.println("YES");
}
// }
}
}
| Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | a4af611f705cdce1e94c2be7afd96431 | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes | import java.util.Scanner;
public class Letter {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s = new Scanner(System.in);
int comp = 0;
int flag = 1;
String let = s.nextLine();
String l = s.nextLine();
int[] small = new int[26];
int[] cap = new int[26];
char[] z = let.toCharArray();
char[] x = l.toCharArray();
for (int i = 0; i < let.length() ; i++) {
if (z[i] >= 97 && z[i] <= 123) {
// small
small[z[i] - 97]++;
} else if (z[i] < 97 && z[i] > 64) {
cap[z[i] - 65]++;
}
}
for (int i = 0; i < l.length(); i++) {
if (x[i] >= 97 && x[i] <= 123) {
// small
if (small[x[i] - 97] == 0) {
flag = 0;
break;
}
small[x[i] - 97]--;
} else if (x[i] < 97 && x[i] > 64) {
if (cap[x[i] - 65] == 0) {
flag = 0;
break;
}
cap[x[i] - 65]--;
}
}
if (flag == 0) {
System.out.println("NO");
} else {
System.out.println("YES");
}
}
}
| Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | 6bb6cbc1d0abd4b5cc8567bbe853474a | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes | import java.util.Scanner;
//BLetter
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] caps = new int[26];
int[] small = new int[26];
for (char c : sc.nextLine().toCharArray()) {
if (c == ' ')
continue;
if (isCaps(c))
caps[c - 'A']++;
else
small[c - 'a']++;
}
char[] msg = sc.nextLine().toCharArray();
boolean ans = true;
for (int i = 0; i < msg.length; i++) {
if (msg[i] == ' ') continue;
if ((isCaps(msg[i]) && --caps[msg[i] - 'A'] < 0) || (!isCaps(msg[i]) && --small[msg[i] - 'a'] < 0)) {
ans = false;
break;
}
}
System.out.println(ans ? "YES" : "NO");
}
static boolean isCaps(char c) {
return c >= 'A' && c <= 'Z';
}
}
| Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | 935e896cd9752aa25b893512e501a9db | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes | import java.util.ArrayList;
import java.util.Scanner;
public class Letter {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String s1=scan.nextLine();
String s2=scan.nextLine();
s1=s1.replace(" ", "");
s2=s2.replace(" ", "");
ArrayList<Character> a = new ArrayList<Character>();
for(int i=0;i<s1.length();i++)
{
a.add(s1.charAt(i));
}
int cnt=0;
for(int i=0;i<s2.length();i++)
{
if(a.contains(s2.charAt(i)))
{
cnt++;
a.remove(a.indexOf(s2.charAt(i)));
}
else
{
break;
}
}
if(cnt==s2.length()) System.out.println("YES");
else System.out.println("NO");
}
}
| Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | 4b9cdd60745991a43ee76a115ec26fe2 | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes | //package session1;
import java.util.HashMap;
import java.util.Scanner;
public class Letter {
public static void letter(String s1, String s2){
//making a hashmap
HashMap<Character, Integer> hm = new HashMap<Character,Integer>(52);
char c = 'a';
while(true){
hm.put(c, Character.getNumericValue(c)-10);
if(c == 'z')
break;
c++;
}
c = 'A';
while(true){
hm.put(c, Character.getNumericValue(c)-10+26);
if(c == 'Z')
break;
c++;
}
//making an array
int [] a = new int[52]; //by default zeros
for(int i =0; i<s1.length();i++){
if (s1.charAt(i) == ' ')
continue;
a[hm.get(s1.charAt(i))]++;
}
//checking condition
for(int i=0; i<s2.length();i++){
if (s2.charAt(i) == ' ')
continue;
if(a[hm.get(s2.charAt(i))] != 0){
a[hm.get(s2.charAt(i))]--;
}else{
System.out.println("NO");
return;
}
}
System.out.println("YES");
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String s1 = input.nextLine();
String s2 = input.nextLine();
letter(s1,s2);
input.close();
}
}
| Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | 91985d73328272c7eba6107a1572df56 | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes | import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
String s1 = sc.nextLine();
String s2 = sc.nextLine();
int l1 = s1.length();
int l2 = s2.length();
int xs1[] = new int[200];
//int xs2[] = new int[200];
for(int i=0;i<l1;i++){
xs1[(int)s1.charAt(i)]++;
}
// for(int i=0;i<200;i++){
// System.out.print(xs1[i]);
// }
for(int i=0;i<l2;i++){
if(s2.charAt(i) == ' '){
continue;
}
if(xs1[(int)s2.charAt(i)] <= 0){
System.out.println("NO");
System.exit(0);
}
else{
if(xs1[(int)s2.charAt(i)] != 0){
xs1[(int)s2.charAt(i)]--;
}
}
}
System.out.println("YES");
//System.out.println((int)'a');
}
}
| Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | 033c84e39bddf78afc3b45d8207b9c88 | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes | import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
String s1 = sc.nextLine();
String s2 = sc.nextLine();
String [] words = s1.split(" ");
String [] words2 = s2.split(" ");
String str = "";
for(int i=0;i<words.length;i++){
str = str.concat(words[i]);
}
s2 = "";
for(int i=0;i<words2.length;i++){
s2 = s2.concat(words2[i]);
}
StringBuffer sbf = new StringBuffer(str);
for(int i=0;i<s2.length();i++){
char ch = s2.charAt(i);
for(int j=0;j<sbf.length();j++){
if(sbf.charAt(j) == ch){
sbf.deleteCharAt(j);
break;
}
if(j == sbf.length() - 1){
System.out.println("NO");
System.exit(0);
}
}
}
System.out.println("YES");
//System.out.println(str);
}
}
| Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | 7db358320f3d58f62bbe978a47a01690 | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes | import java.util.Scanner;
public class letter {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
boolean found = false;
StringBuilder x = new StringBuilder(scan.nextLine());
StringBuilder y = new StringBuilder(scan.nextLine());
for (int i = 0; i < y.length(); i++) {
for (int j = 0; j < x.length(); j++) {
Character c = y.charAt(i);
if (c == ' ' || c == '\t') {
found = true;
break;
} else if (c == (x.charAt(j))) {
found = true;
x.setCharAt(j, ' ');
break;
}
}
if (found) {
found = false;
} else {
System.out.println("NO");
return;
}
}
System.out.println("YES");
}
}
| Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | 0f1b8a7232e02ea5791e3498925784d0 | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes |
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.util.Scanner;
/**
*
* @author KCc
*/
public class ACM_Letter {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner s = new Scanner(System.in);
StringBuilder first = new StringBuilder(s.nextLine());
StringBuilder second = new StringBuilder(s.nextLine());
int f = 1;
for (int i = 0; i < second.length() ; i++){
for (int j = 0; j < first.length() ; j++){
Character c = second.charAt(i);
if (c == ' '){
f = 0;
break;
} else if (c == first.charAt(j)){
f = 0;
first.setCharAt(j, ' ');
break;
}
}
if (f == 0){
f = 1;
} else if (f == 1){
System.out.println("NO");
return;
}
}
System.out.println("YES");
/*for (int i = 0; i < second.length() ; i++){
Character c = second.charAt(i);
if(Character.isLetter(c)){
if (first.indexOf(second.charAt(i)) < 0){
f = 0;
System.out.println("NO");
break;
}
}
}*/
/* if (f == 1){
System.out.println("YES");
}*/
}
}
| Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | 4a066fcb90fc59a788e0c9c65b77fd66 | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes | /*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.util.Scanner;
/**
*
* @author KCc
*/
public class ACM_Letter {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner s = new Scanner(System.in);
StringBuilder first = new StringBuilder(s.nextLine());
StringBuilder second = new StringBuilder(s.nextLine());
int f = 1;
for (int i = 0; i < second.length() ; i++){
for (int j = 0; j < first.length() ; j++){
Character c = second.charAt(i);
if (c == ' '){
f = 0;
break;
} else if (c == first.charAt(j)){
f = 0;
first.setCharAt(j, ' ');
break;
}
}
if (f == 0){
f = 1;
} else if (f == 1){
System.out.println("NO");
return;
}
}
System.out.println("YES");
/*for (int i = 0; i < second.length() ; i++){
Character c = second.charAt(i);
if(Character.isLetter(c)){
if (first.indexOf(second.charAt(i)) < 0){
f = 0;
System.out.println("NO");
break;
}
}
}*/
/* if (f == 1){
System.out.println("YES");
}*/
}
}
| Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | 8d450f12f777017c5079233266d0fc7c | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes | import java.io.*;
import java.util.*;
public class Letter {
public static void main(String args[]) {
FastReader sc = new FastReader();
PrintWriter out = new PrintWriter(System.out);
int t, n, i, j,flag=0;
String s,s2;
s= sc.nextLine();
s2= sc.nextLine();
int scap[] = new int[26];
int ssma[] = new int[26];
int s2cap[] = new int[26];
int s2sma[] = new int[26];
for (i = 0; i <s.length() ; i++) {
int p=s.charAt(i);
if (p>=65 && p<=90)
scap[p-'A']++;
if (p>=97 && p<=122)
ssma[p-'a']++;
}
for (i = 0; i <s2.length() ; i++) {
int p=s2.charAt(i);
if (p>=65 && p<=90)
s2cap[p-'A']++;
if (p>=97 && p<=122)
s2sma[p-'a']++;
}
for (i = 0; i < 26; i++) {
if ((scap[i]<s2cap[i]) || (ssma[i]<s2sma[i])) {
flag=1;
break;
}
}
if (flag==1)
out.println("NO");
else
out.println("YES");
out.close();
}
/*
FASTREADER
*/
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;
}
/*DEFINED BY ME
*/
int[] readArray(int n) {
int arr[] = new int[n];
for (int i = 0; i < n; i++)
arr[i] = nextInt();
return arr;
}
void sort(int arr[]) {
ArrayList<Integer> l = new ArrayList<>();
for (int i : arr)
l.add(i);
Collections.sort(l);
for (int i = 0; i < arr.length; i++)
arr[i] = l.get(i);
}
}
} | Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | c34d0f594634867b852ca236deb264b9 | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Solve3 {
public static void main(String[] args) throws IOException {
new Solve3().solve();
}
public void solve() throws IOException {
FastReader sc = new FastReader();
//PrintWriter pw = new PrintWriter(System.out);
String s = sc.nextLine(), t = sc.nextLine();
int[] a = new int[26];
int[] b = new int[26];
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == ' ') {
continue;
}
if (Character.isUpperCase(s.charAt(i))) {
b[s.charAt(i) - 65]++;
}
else a[s.charAt(i) - 97]++;
}
for (int i = 0; i < t.length(); i++) {
if (t.charAt(i) == ' ') {
if(i+1==t.length()) System.out.println("YES");
continue;
}
if (Character.isUpperCase(t.charAt(i))) {
if (b[t.charAt(i) - 65] == 0) {
System.out.println("NO");
break;
} else {
b[t.charAt(i) - 65]--;
}
} else {
if (a[t.charAt(i) - 97] == 0) {
System.out.println("NO");
break;
} else {
a[t.charAt(i) - 97]--;
}
}
if(i+1==t.length()) System.out.println("YES");
}
}
static public class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public String next() throws IOException {
if (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public String nextLine() throws IOException {
return br.readLine();
}
}
}
| Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | 147e30ab6788ee5b0767f27274e4aaa9 | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes | import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
ArrayList<Character> source=new ArrayList<Character>();
ArrayList<Character> letter=new ArrayList<Character>();
Scanner scn = new Scanner(System.in);
for(char item:scn.nextLine().toCharArray())
if(item!=' ')
source.add(item);
for(char item:scn.nextLine().toCharArray())
if(item!=' ')
letter.add(item);
scn.close();
int i=0;
for(;i<letter.size(); i++) {
int index=source.indexOf(letter.get(i));
if(index==-1)
break;
else
source.remove(index);
}
System.out.println(i==letter.size()? "YES":"NO");
}
}
| Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | 95cc628531cbce5e0c82fe4d592af2a9 | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scn = new Scanner(System.in);
StringBuilder heading = new StringBuilder();
StringBuilder text = new StringBuilder();
for(char item: scn.nextLine().toCharArray())
if(item!=' ')
heading.append(item);
for(char item: scn.nextLine().toCharArray())
if(item!=' ')
text.append(item);
scn.close();
/*String ans ="";
for (int i = 0; i < text.length(); i++) {
int j;
for (j = 0; j < heading.length(); j++) {
if (text.charAt(i) == ' ')
text.deleteCharAt(i);
if (text.charAt(i) != heading.charAt(j))
ans = "NO";
else {
heading.deleteCharAt(j);
j=-1;
ans="YES";
break;
}
}
if (j == heading.length())
break;
}
System.out.println(ans);*/
int i = 0;
for (; i < text.length(); i++) {
int j;
for (j = 0; j < heading.length(); j++) {
if (text.charAt(i) != heading.charAt(j))
continue;
else {
heading.deleteCharAt(j);
j=-1;
break;
}
}
if(j==heading.length())
break;
}
System.out.println(i==text.length()? "YES":"NO");
}
}
| Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | 8e750f15ab2f9f82e5295ed691683f07 | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes | import java.util.*;
public class Letter {
static Scanner scn = new Scanner(System.in);
public static void main(String[] args) {
helper();
}
public static void helper() {
String s1 = input(1);
String s2 = input(1);
int[] freq_1 = Freq(s1);
int[] freq_2 = Freq(s2);
for (int i = 0; i < 256; i++) {
if (freq_2[i] > freq_1[i]) {
print("NO");
return;
}
}
print("YES");
}
public static int[] Freq(String s) {
int[] freq = new int[256];
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == ' ') continue;
freq[s.charAt(i)]++;
}
return freq;
}
public static long input() {
return scn.nextLong();
}
public static String input(int... var) {
return scn.nextLine();
}
public static void TakeInput(int[] arr) {
for (int i = 0; i < arr.length; i++)
arr[i] = (int)input();
}
public static void TakeInput(long[] arr) {
for (int i = 0; i < arr.length; i++)
arr[i] = input();
}
public static void printArray(int[] arr) {
for (int val : arr)
print(val + " ");
print("\n");
}
public static void printArray(long[] arr) {
for (long val : arr)
print(val + " ");
print("\n");
}
public static <T> void print(T t) {
System.out.print(t);
}
public static void print() {
System.out.println();
}
} | Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | 2478dc1a4ade8f88971cca9860f41a94 | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes |
import java.util.Scanner;
public class Letter {
public static void main(String args[]){
Scanner in = new Scanner(System.in);
String s1 = in.nextLine();
String s2 = in.nextLine();
if(s1.length() > 200 || s2.length() > 200) {
System.out.println(-1);
}else {
int[] charArray = new int[123];
for(int i=0; i<s1.length(); i++) {
charArray[(int) s1.charAt(i)]++;
}
String result = "NO";
for (int j = 0; j < s2.length(); j++) {
if ((int) s2.charAt(j) == 32) {
continue;
} else if (charArray[(int) s2.charAt(j)] >= 1) {
charArray[(int) s2.charAt(j)]--;
if(result.equals("NO")) {
result = "YES";
}
} else {
result = "NO";
break;
}
}
System.out.println(result);
}
}
}
| Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | 2471e357a74806438b36fe2b8d641761 | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes | import java.util.*;
public class Boboniu
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
String s1 = scanner.nextLine();
String s2 = scanner.nextLine();
int[] arr1 = new int[100];
int[] arr2 = new int[100];
for(int i=0;i<s1.length();i++)
{
if(s1.charAt(i)!=' ')
arr1[s1.charAt(i)-65]++;
}
for(int i=0;i<s2.length();i++)
{
if(s2.charAt(i)!=' ')
arr2[s2.charAt(i)-65]++;
}
for(int i=0;i<100;i++)
{
if(arr2[i]!=0 && arr1[i]<arr2[i])
{
System.out.println("NO");
return;
}
}
System.out.println("YES");
}
} | Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | ca0249f6961606d1ecd58fb20e2698f9 | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes | import java.util.Scanner;
import java.io.PrintWriter;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
String str1 = sc.nextLine();
String str2 = sc.nextLine();
int arr[] = new int[200];
for(int i=0;i<str1.length();i++)
{
if(str1.charAt(i)!=' ')
{
arr[str1.charAt(i)]++;
}
}
boolean flag = true;
for(int i=0;i<str2.length();i++)
{
if(str2.charAt(i)!=' ')
{
char a = str2.charAt(i);
if(arr[a]-- > 0 )
continue;
else
{
flag = false;
break;
}
}
}
if(flag)
out.println("YES");
else
out.println("NO");
out.flush();
}
} | Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | 8161512794567a13f724bd06d769d186 | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes | import java.util.*;
public class Letter {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String s1 = in.nextLine();
String s2 = in.nextLine();
int[] freq1 = new int[128];
int[] freq2 = new int[128];
for (int i = 0; i < s1.length(); i++) {
if(s1.charAt(i) != ' '){
freq1[s1.charAt(i)]++;
}
}
for (int i = 0; i < s2.length(); i++) {
if(s2.charAt(i) != ' '){
freq2[s2.charAt(i)]++;
}
}
for (int i = 0; i < 128; i++) {
if(freq1[i] < freq2[i]){
System.out.println("NO");
return;
}
}
System.out.println("YES");
}
}
| Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | 6e5a148d2f3252326ed007b9b519a075 | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes | import java.util.*;
public class Letter2 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String st1 = in.nextLine();
String st2 = in.nextLine();
int[] freq1 = new int[123];
for (int i = 0; i < st1.length(); i++) {
if(st1.charAt(i) == ' '){
continue;
}
int index = st1.charAt(i);
freq1[index]++;
}
int[] freq2 = new int[123];
for (int i = 0; i < st2.length(); i++) {
if(st2.charAt(i) == ' '){
continue;
}
int index = st2.charAt(i);
freq2[index]++;
}
for (int i = 0; i < freq2.length; i++) {
if(freq2[i] > freq1[i]){
System.out.println("NO");
return;
}
}
System.out.println("YES");
}
}
| Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | 3a10e8e84af8b835e67ab2962a4fc6df | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes |
import java.util.*;
public class Letter {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String s1 = in.nextLine();
String s2 = in.nextLine();
boolean done;
for (int i = 0; i < s2.length(); i++) {
if (s2.charAt(i) == ' ') {
continue;
}
done = false;
for (int j = 0; j < s1.length(); j++) {
if (s2.charAt(i) == s1.charAt(j)) {
done = true;
s1 = s1.replaceFirst(s1.charAt(j) + "", " ");
break;
}
}
if (!done) {
System.out.println("NO");
return;
}
}
System.out.println("YES");
}
}
| Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | f8c0bdd74039b94ce3604464a2397700 | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 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 Pollock
*/
public class Letter {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int heading_freq[] = new int[128];
int msg_freq[] = new int[128];
String heading = sc.nextLine();
String msg = sc.nextLine();
int lenH = heading.length();
for (int i = 0; i < lenH; i++) {
char ch = heading.charAt(i);
if (ch != ' ') {
heading_freq[ch]++;
}
}
int lengthMsg = msg.length();
for (int i = 0; i < lengthMsg; i++) {
char ch = msg.charAt(i);
if (ch != ' ') {
msg_freq[ch]++;
}
}
boolean flag = true;
for (char i = 'a'; i <= 'z'; i++) {
if (heading_freq[i] < msg_freq[i]) {
flag = false;
}
}
for (char i = 'A'; i <= 'Z'; i++) {
if (heading_freq[i] < msg_freq[i]) {
flag = false;
}
}
/*if (flag == true) {
System.out.println("YES");
} else {
System.out.println("NO");
}*/
System.out.println(flag ? "YES" : "NO");
}
}
| Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | 600ade51a19b1d7d8440ae520c3b913a | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes | import java.io.*;
import java.util.*;
public class Mohammad {
//---------------------------------------------Main-----------------------------------------------//
public static void Mohammad_AboHasan() throws IOException{
FastReader fr = new FastReader();
String s = fr.nextLine();
String s2 = fr.nextLine().replaceAll(" ", "");
HashMap<Character, Integer> map = new HashMap<>();
for (int i = 0; i < s.length(); i++){
if(map.get(s.charAt(i)) == null)
map.put(s.charAt(i), 0);
else
map.put(s.charAt(i), map.get(s.charAt(i)) + 1);
}
for (int i = 0; i < s2.length(); i++) {
if(map.get(s2.charAt(i)) == null || map.get(s2.charAt(i)) == -1){
System.out.println("NO");
//System.out.println(map.get(s2.charAt(i)) + " " + s2.charAt(i));
return;
}
else
map.put(s2.charAt(i), map.get(s2.charAt(i)) - 1);
}
System.out.println("YES");
}
public static void main(String[] args) throws IOException{
Mohammad_AboHasan();
}
//---------------------------------------------FAST I/O-----------------------------------------------//
static class FastReader{
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() throws IOException{
while (st == null || !st.hasMoreElements()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
int nextInt() throws IOException{
return Integer.parseInt(next());
}
long nextLong() throws IOException{
return Long.parseLong(next());
}
double nextDouble() throws IOException{
return Double.parseDouble(next());
}
String nextLine() throws IOException{
String s = br.readLine();
return s;
}
}
} | Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | fd3683a46b339f2a8eaf43931e984ffc | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String Head = in.readLine();
String Title = in.readLine();
String result = "YES";
int[] h = new int[26];
int[] H = new int[26];
for (int i = 0; i < Head.length(); i++) {
char digit = Head.charAt(i);
if (digit >= 97 && digit <= 122) {
int index = digit - 97;
if (index >= 0 && index < 27) {
h[index]++;
}
}
if (digit >= 65 && digit <= 90) {
int index = digit - 65;
if (index >= 0 && index < 27) {
H[index]++;
}
}
}
for (int j = 0; j < Title.length(); j++) {
char digit = Title.charAt(j);
if (digit >= 97 && digit <= 122) {
int index = digit - 97;
if (index >= 0 && index < 27) {
if (h[index] > 0) {
h[index]--;
} else {
result = "NO";
}
}
}
if (digit >= 65 && digit <= 90) {
int index = digit - 65;
if (index >= 0 && index < 27) {
if (H[index] > 0) {
H[index]--;
} else {
result = "NO";
}
}
}
}
System.out.println(result);
}
}
| Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | a588ff406c3bc7e8e02939b598d7a045 | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes |
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String str = input.nextLine();
String str2 = input.nextLine();
int no = 0;
str = str.replaceAll(" ", "");
str2 = str2.replaceAll(" ", "");
char[] charstr = str.toCharArray();
char[] charstr2 = str2.toCharArray();
ArrayList<Character> list = new ArrayList<>();
ArrayList<Character> list2 = new ArrayList<>();
for (int i = 0; i < charstr.length; i++) {
list.add(charstr[i]);
}
for (int i = 0; i < charstr2.length; i++) {
list2.add(charstr2[i]);
}
int i = 0;
while (i < str2.length()) {
if (list.contains(list2.get(i))) {
list.remove(list2.get(i));
i++;
} else {
no = 1;
break;
}
}
if (no == 0) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}
| Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | 11d9cb49c1de6d0eb3c2ffba759c2174 | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner x=new Scanner(System.in);
String s=x.nextLine();
String y=x.nextLine();
int i;
int b[]=new int[256];
for(i=0;i<y.length();i++)
{
if(y.charAt(i)!=' ')
b[(int)(y.charAt(i))]++;
}
for(i=0;i<s.length();i++)
{
if(s.charAt(i)!=' ')
b[(int)(s.charAt(i))]--;
}
int c=0;
for(i=0;i<b.length;i++)
{
if(b[i]>0)
{
c=1;
System.out.println("NO");
break;
}
}
if(c==0)
{
System.out.println("YES");
}
}
} | Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | 38ba708d0bc72e6338f7c335896032b4 | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes | import java.util.Scanner;
import java.util.Set;
public class bufferedTry {
public static void main (String args[]) {
Scanner key = new Scanner (System.in);
String input1 = key.nextLine();
String input2 = key.nextLine();
int checker1=0;
int checker2=0;
boolean check = false;
int checkerInput = 0;
int checkerSecond [] = new int [input2.length()];
int checkerFirst [] = new int [input1.length()];
char FirstChar [] = input1.toCharArray();
char SecondChar [] = input2.toCharArray();
for (int i=0; i<input2.length(); i++){
for (int j=0; j<input1.length(); j++){
if (SecondChar[i]==FirstChar[j]){
checkerSecond[i]++;
FirstChar[j]=' ';
break;
}
}
}
//First Input Checker
for (int i=0; i<input2.length(); i++){
if (checkerSecond[i]==0){
System.out.println("NO");
checkerInput=10;
break;
}
else
check = true;
}
if (check==true&&checkerInput!=10)
System.out.println ("YES");
}
} | Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | fbc71f290f4760807477cf9ce912c51b | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes | import java.io.*;
import java.util.*;
import java.util.Map.*;
public class j {
public static void main(String args[] ) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = br.readLine();
int[] a = new int[130];
String str1 = br.readLine();
str= str.replaceAll(" ","");
str1 = str1.replaceAll(" ","");
for(int i=0;i<str1.length();i++) {
a[str1.charAt(i)]++;
}
for(int i=0;i<str.length();i++) {
a[str.charAt(i)]--;
}
for(int i=0;i<130;i++) {
if(a[i]>0) {
System.out.println("NO");return ;
}
}
System.out.println("YES");
}
} | Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | b9074ab9c25c3133b31523deaf68c9cd | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes | import java.util.Scanner;
public class Main {
static int[] charCounter(String word) {
int[] alphabet = new int[52];
for (int i = 0; i < word.length(); i++) {
int indx = (int) word.charAt(i);
if (indx > 64 && indx < 91) {
indx = indx - 65;
alphabet[indx]++;
}
else if (indx > 96 && indx < 123) {
indx = indx - 71;
alphabet[indx]++;
}
}
return alphabet;
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String heading = input.nextLine();
String letter = input.nextLine();
// A 65
// a 97
int[] headingAlphabet = new int[52];
int[] letterAlphabet = new int[52];
headingAlphabet = charCounter(heading);
letterAlphabet = charCounter(letter);
String answer = "YES";
for (int i = 0; i < 52; i++) {
if (letterAlphabet[i] > headingAlphabet[i] && letterAlphabet[i] != 0) {
answer = "NO";
break;
}
}
System.out.println(answer);
}
} | Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | e97ed303cd94e3c4aeea33d1db2eb335 | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes | import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
public class Solution {
private static final Scanner input = new Scanner(System.in);
public static void main(String[] args) {
String s1 = input.nextLine();
String s2 = input.nextLine();
s1 = s1.replaceAll(" ","");
s2 = s2.replaceAll(" ", "");
int[] headingCharsCount = new int[58];
for (int i = 0; i < s1.length(); i++)
headingCharsCount[(int) s1.charAt(i) - 65]++;
boolean isEnough = true;
for (int i = 0; i < s2.length(); i++) {
headingCharsCount[(int)s2.charAt(i)-65]--;
if (headingCharsCount[s2.charAt(i)-65]<0) {
isEnough = false;
break;
}
}
if (isEnough) System.out.println("YES");
else System.out.println("NO");
}
}
| Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | eafd589268be045b2897e192e1545522 | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes | import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
public class Solution {
private static final Scanner input = new Scanner(System.in);
public static void main(String[] args) {
String s1 = input.nextLine();
String s2 = input.nextLine();
s1 = s1.replaceAll(" ","");
s2 = s2.replaceAll(" ", "");
int[] headingCharsCount = new int[58];
for (int i = 0; i < s1.length(); i++)
headingCharsCount[(int) s1.charAt(i) - 65]++;
boolean isEnough = true;
for (int i = 0; i < s2.length(); i++) {
headingCharsCount[(int)s2.charAt(i)-65]--;
if (headingCharsCount[s2.charAt(i)-65]<0) {
isEnough = false;
break;
}
}
if (isEnough) System.out.println("YES");
else System.out.println("NO");
}
} | Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | 62b1a540235e50fc6dce50e7358ba639 | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes |
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
public class Solution {
// ----------------------------------------------------------------------------
static class Task {
public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
BufferedReader inn = new BufferedReader(new InputStreamReader(System.in));
char[] s1 = inn.readLine().toCharArray();
char[] s2 = inn.readLine().toCharArray();
Map<Integer, Integer> mp1 = new HashMap<>();
Map<Integer, Integer> mp2 = new HashMap<>();
for (int i = 0; i < 26; ++i) {
mp1.put('a' + i, 0);
mp1.put('A' + i, 0);
mp2.put('a' + i, 0);
mp2.put('A' + i, 0);
}
for (char c : s1) {
if (c != ' ') {
mp1.put(c + 0, mp1.get(c + 0) + 1);
}
}
for (char c : s2) {
if (c != ' ') {
mp2.put(c + 0, mp2.get(c + 0) + 1);
}
}
for (int i = 0; i < 26; ++i) {
if (mp2.get('a' + i) > mp1.get('a' + i) || mp2.get('A' + i) > mp1.get('A' + i)) {
out.println("NO");
return;
}
}
out.println("YES");
}
}
// ----------------------------------------------------------------------------
// IMPORTANT || COMMON METHODS
// PAIR
static class Pair {
int x;
int y;
// Constructor
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
// how to initialize
// Pair level[] = new Pair[n];
// for (int i = 0; i < n; i++) {
// int x = in.nextInt();
// int y = in.nextInt();
//
// level[i] = new Pair(x, y);
//
// }
// How to sort
// PairSort ps = new PairSort();
// ps.sort(level, 1);
}
static class PairSort {
Pair[] sort(Pair arr[], int i) {
// Comparator to sort the pair according to second element
Arrays.sort(arr, new Comparator<Pair>() {
@Override
public int compare(Pair p1, Pair p2) {
// 1 sees the first elements ans sorts them in increasing order
// 2 sees the second elements ans sorts them in increasing order
// 3 sees the first elements ans sorts them in decreasing order
// 4 sees the second elements ans sorts them in decreasing order
switch (i) {
case 2:
return p1.y - p2.y;
case 1:
return p1.x - p2.x;
case 4:
return p2.y - p1.y;
default:
return p2.x - p1.x;
}
}
});
return arr;
}
}
// GCD || HCF
static long GCD(long x, long y) {
return y == 0 ? x : GCD(y, x % y);
}
// LCM
static long LCM(long a, long b) {
return (a * b) / GCD(a, b);
}
// Returns the divisors of a number
static ArrayList Divisors(long n) {
ArrayList<Long> div = new ArrayList<>();
for (long i = 1; i <= Math.sqrt(n); i++) {
if (n % i == 0) {
div.add(i);
if (n / i != i) {
div.add(n / i);
}
}
}
return div;
}
// PERMUTATIONS
static void permute(int[] a, int k) {
if (k == a.length) {
for (int i = 0; i < k; i++) {
System.out.print(a[i] + " ");
}
System.out.println("");
} else {
for (int i = k; i < a.length; i++) {
int temp = a[k];
a[k] = a[i];
a[i] = temp;
permute(a, k + 1);
// swapping a[k] and a[i] .
temp = a[k];
a[k] = a[i];
a[i] = temp;
}
}
// How to run
//int seq[] = {1, 19, 6}; .. let seq be the array of numbers to be permuted
//permute(seq, 0); // call this function .
//0 -> all permutations ( permutation start from 1st number)
//1-> permutations start from 2nd number
//2-> permutation start from 3rd number
// n-1 that array will be returned
}
// ----------------------------------------------------------------------------
// MAIN - INPUT - OUTPUT
public static void main(String[] args) throws IOException {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Task solver = new Task();
solver.solve(1, in, out);
out.close();
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public Double nextDouble() {
return Double.parseDouble(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public int[] nextIntArray(int arraySize) {
int array[] = new int[arraySize];
for (int i = 0; i < arraySize; i++) {
array[i] = nextInt();
}
return array;
}
}
}
| Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | 880d3ded3fa3bdce64ccf1c750d379be | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes |
import java.util.HashMap;
import java.util.Scanner;
public class Letter {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
String s1=scan.nextLine().replace(" ", "");
String s2=scan.nextLine().replace(" ", "");
HashMap<Character,Integer> hm=new HashMap<Character,Integer>();
for(int i=0;i<s1.length();i++) {
if(!hm.containsKey(s1.charAt(i))==true)
hm.put(s1.charAt(i), 1);
else {
Integer f=hm.get(s1.charAt(i));
hm.put(s1.charAt(i), ++f);
}
}
int temp=0;
for(int i=0;i<s2.length();i++) {
if(!hm.containsKey(s2.charAt(i))==true) {
temp=1;
break;
}
else {
Integer f=hm.get(s2.charAt(i));
if(f==0)temp=1;
else hm.put(s2.charAt(i), --f);
}
}
if(temp==1)System.out.println("NO");
else System.out.println("YES");
}
}
| Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | 1555d9b83dd2cda7f71855f8d5dc1343 | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes | import java.io.*;
public class J {
public static void main(String[] args) throws IOException {
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
String firstLine = input.readLine().replace(" ", "");
char secondLine[] = input.readLine().replace(" ", "").toCharArray();
boolean condition = true;
for (int i = 0; i < secondLine.length; i++) {
if (firstLine.contains(secondLine[i] + "")) {
firstLine = firstLine.replaceFirst(secondLine[i] + "", "");
} else {
condition = false;
break;
}
}
out.println(condition ? "YES" : "NO");
out.close();
}
} | Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | 2cfd939d049be757c4ff7ade3fe86c0d | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
public class J {
public static void main(String[] args) throws IOException {
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
String firstLine = input.readLine().replace(" ", "");
char secondLine[] = input.readLine().replace(" ", "").toCharArray();
boolean condition = true;
for (int i = 0; i < secondLine.length; i++) {
if (firstLine.contains(secondLine[i] + "")) {
firstLine = firstLine.replaceFirst(secondLine[i] + "", "");
} else {
condition = false;
break;
}
}
out.println(condition ? "YES" : "NO");
out.close();
}
} | Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | 974575d9bc9d87f70c4143a48f392eee | train_001.jsonl | 1291046400 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading β he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | 256 megabytes | import java.util.Scanner;
public class Letter {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String s1 = scanner.nextLine();
String s2 = scanner.nextLine();
boolean[] visited = new boolean[s1.length()];
boolean pass = true;
for (int i = 0; i < s2.length(); i++) {
if (s2.charAt(i) == ' ') {
continue;
}
boolean p = false;
for (int j = 0; j < s1.length(); j++) {
if (!visited[j] && s1.charAt(j) == s2.charAt(i)) {
p = true;
visited[j] = true;
break;
}
}
if (!p) {
pass = false;
}
}
if (pass) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}
| Java | ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcdefg hijk\nk j i h g f e d c b a"] | 2 seconds | ["NO", "YES", "NO", "YES"] | null | Java 8 | standard input | [
"implementation",
"strings"
] | b1ef19d7027dc82d76859d64a6f43439 | The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 ΠΈ s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | 1,100 | If Vasya can write the given anonymous letter, print YES, otherwise print NO | standard output | |
PASSED | c0de3d9291560651af753ef953931c5f | train_001.jsonl | 1298908800 | In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense structure accommodates exactly n soldiers. Within this task we can assume that the number of soldiers in the defense structure won't either increase or decrease.Every soldier has a rank β some natural number from 1 to k. 1 stands for a private and k stands for a general. The higher the rank of the soldier is, the better he fights. Therefore, the player profits from having the soldiers of the highest possible rank.To increase the ranks of soldiers they need to train. But the soldiers won't train for free, and each training session requires one golden coin. On each training session all the n soldiers are present.At the end of each training session the soldiers' ranks increase as follows. First all the soldiers are divided into groups with the same rank, so that the least possible number of groups is formed. Then, within each of the groups where the soldiers below the rank k are present, exactly one soldier increases his rank by one.You know the ranks of all n soldiers at the moment. Determine the number of golden coins that are needed to increase the ranks of all the soldiers to the rank k. | 256 megabytes | import java.util.*;
public class SettlersTraining {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int k = in.nextInt();
int[] ranks = new int[k];
for (int i = 0; i < n; ++i) {
int rank = in.nextInt() - 1;
++ranks[rank];
}
int coins = 0;
while (ranks[k - 1] < n) {
for (int i = k - 2; i >= 0; --i) {
if (ranks[i] > 0) {
--ranks[i];
++ranks[i + 1];
}
}
++coins;
}
System.out.println(coins);
in.close();
System.exit(0);
}
} | Java | ["4 4\n1 2 2 3", "4 3\n1 1 1 1"] | 2 seconds | ["4", "5"] | NoteIn the first example the ranks will be raised in the following manner:1 2 2 3 βββ 2 2 3 4 βββ 2 3 4 4 βββ 3 4 4 4 βββ 4 4 4 4Thus totals to 4 training sessions that require 4 golden coins. | Java 7 | standard input | [
"implementation"
] | 3d6411d67c85f6293f1999ccff2cd8ba | The first line contains two integers n and k (1ββ€βn,βkββ€β100). They represent the number of soldiers and the number of different ranks correspondingly. The second line contains n numbers in the non-decreasing order. The i-th of them, ai, represents the rank of the i-th soldier in the defense building (1ββ€βiββ€βn, 1ββ€βaiββ€βk). | 1,200 | Print a single integer β the number of golden coins needed to raise all the soldiers to the maximal rank. | standard output | |
PASSED | 3b8fa39f09c378c89dc1798c9d5fcbde | train_001.jsonl | 1298908800 | In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense structure accommodates exactly n soldiers. Within this task we can assume that the number of soldiers in the defense structure won't either increase or decrease.Every soldier has a rank β some natural number from 1 to k. 1 stands for a private and k stands for a general. The higher the rank of the soldier is, the better he fights. Therefore, the player profits from having the soldiers of the highest possible rank.To increase the ranks of soldiers they need to train. But the soldiers won't train for free, and each training session requires one golden coin. On each training session all the n soldiers are present.At the end of each training session the soldiers' ranks increase as follows. First all the soldiers are divided into groups with the same rank, so that the least possible number of groups is formed. Then, within each of the groups where the soldiers below the rank k are present, exactly one soldier increases his rank by one.You know the ranks of all n soldiers at the moment. Determine the number of golden coins that are needed to increase the ranks of all the soldiers to the rank k. | 256 megabytes | import java.util.*;
import java.io.*;
import static java.lang.Math.*;
public class Main {
FastIO in;
PrintWriter out;
// File names!!!
void solve() throws IOException {
int n = in.nextInt(), k = in.nextInt();
int[] a = new int[k];
for (int i = 0; i < n; i++) {
a[in.nextInt() - 1]++;
}
int ans = 0;
while (a[k - 1] < n) {
int min = 1000000;
for (int i = 0; i < k - 1; i++) {
min = min(min, a[i]);
}
if (min == 0) min = 1;
ans += min;
for (int i = k - 2; i >= 0; i--) {
if (a[i] != 0) {
a[i] -= min;
a[i + 1] += min;
}
}
}
out.println(ans);
}
void run() {
try {
in = new FastIO();
solve();
in.close();
} catch (Exception e) {
e.printStackTrace();
System.exit(abs(-1));
}
}
public static void main(String[] args) {
try {
Locale.setDefault(Locale.US);
} catch (Exception ignore) {
}
new Main().run();
}
class FastIO {
private BufferedReader in;
private StringTokenizer stok;
FastIO() {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
}
FastIO(String s) throws FileNotFoundException {
if ("".equals(s)) {
in = new BufferedReader(new FileReader("input.txt"));
out = new PrintWriter("output.txt");
} else {
in = new BufferedReader(new FileReader(s + ".in"));
out = new PrintWriter(s + ".out");
}
}
void close() throws IOException {
in.close();
out.close();
}
String next() {
while (stok == null || !stok.hasMoreTokens()) {
try {
stok = new StringTokenizer(in.readLine());
} catch (Exception e) {
return null;
}
}
return stok.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
}
} | Java | ["4 4\n1 2 2 3", "4 3\n1 1 1 1"] | 2 seconds | ["4", "5"] | NoteIn the first example the ranks will be raised in the following manner:1 2 2 3 βββ 2 2 3 4 βββ 2 3 4 4 βββ 3 4 4 4 βββ 4 4 4 4Thus totals to 4 training sessions that require 4 golden coins. | Java 7 | standard input | [
"implementation"
] | 3d6411d67c85f6293f1999ccff2cd8ba | The first line contains two integers n and k (1ββ€βn,βkββ€β100). They represent the number of soldiers and the number of different ranks correspondingly. The second line contains n numbers in the non-decreasing order. The i-th of them, ai, represents the rank of the i-th soldier in the defense building (1ββ€βiββ€βn, 1ββ€βaiββ€βk). | 1,200 | Print a single integer β the number of golden coins needed to raise all the soldiers to the maximal rank. | standard output | |
PASSED | e1f0bbcf6f8407c964029cffca991096 | train_001.jsonl | 1298908800 | In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense structure accommodates exactly n soldiers. Within this task we can assume that the number of soldiers in the defense structure won't either increase or decrease.Every soldier has a rank β some natural number from 1 to k. 1 stands for a private and k stands for a general. The higher the rank of the soldier is, the better he fights. Therefore, the player profits from having the soldiers of the highest possible rank.To increase the ranks of soldiers they need to train. But the soldiers won't train for free, and each training session requires one golden coin. On each training session all the n soldiers are present.At the end of each training session the soldiers' ranks increase as follows. First all the soldiers are divided into groups with the same rank, so that the least possible number of groups is formed. Then, within each of the groups where the soldiers below the rank k are present, exactly one soldier increases his rank by one.You know the ranks of all n soldiers at the moment. Determine the number of golden coins that are needed to increase the ranks of all the soldiers to the rank k. | 256 megabytes | import java.util.Scanner;
public class B_63_Settlers_Training {
public static void main(String[] argrs) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int k = in.nextInt();
int[] freq = new int[k+1];
for(int i=0; i<n; i++)
freq[in.nextInt()]++;
int cnt = 0;
while(freq[k] != n) {
for(int i=k-1; i>=0; i--)
if(freq[i] > 0) {
freq[i]--;
freq[i+1]++;
}
cnt++;
}
System.out.println(cnt);
}
}
| Java | ["4 4\n1 2 2 3", "4 3\n1 1 1 1"] | 2 seconds | ["4", "5"] | NoteIn the first example the ranks will be raised in the following manner:1 2 2 3 βββ 2 2 3 4 βββ 2 3 4 4 βββ 3 4 4 4 βββ 4 4 4 4Thus totals to 4 training sessions that require 4 golden coins. | Java 7 | standard input | [
"implementation"
] | 3d6411d67c85f6293f1999ccff2cd8ba | The first line contains two integers n and k (1ββ€βn,βkββ€β100). They represent the number of soldiers and the number of different ranks correspondingly. The second line contains n numbers in the non-decreasing order. The i-th of them, ai, represents the rank of the i-th soldier in the defense building (1ββ€βiββ€βn, 1ββ€βaiββ€βk). | 1,200 | Print a single integer β the number of golden coins needed to raise all the soldiers to the maximal rank. | standard output | |
PASSED | 0902282cfb5079f4c11acaf771912560 | train_001.jsonl | 1298908800 | In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense structure accommodates exactly n soldiers. Within this task we can assume that the number of soldiers in the defense structure won't either increase or decrease.Every soldier has a rank β some natural number from 1 to k. 1 stands for a private and k stands for a general. The higher the rank of the soldier is, the better he fights. Therefore, the player profits from having the soldiers of the highest possible rank.To increase the ranks of soldiers they need to train. But the soldiers won't train for free, and each training session requires one golden coin. On each training session all the n soldiers are present.At the end of each training session the soldiers' ranks increase as follows. First all the soldiers are divided into groups with the same rank, so that the least possible number of groups is formed. Then, within each of the groups where the soldiers below the rank k are present, exactly one soldier increases his rank by one.You know the ranks of all n soldiers at the moment. Determine the number of golden coins that are needed to increase the ranks of all the soldiers to the rank k. | 256 megabytes | import java.util.Scanner;
public class B {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
int n=sc.nextInt();
int k=sc.nextInt();
int a[]=new int [n+1];
boolean used[]=new boolean [n+1];
for (int i = 0; i < a.length-1; i++) {
a[i]=sc.nextInt();
if(a[i]==k) used[i]=true;
}
int cnt=0;
a[n]=k;
used[n]=true;
boolean f=false;
while(true){
for (int i = 0; i < a.length-1; i++) {
if(used[i]) {
if(i==0) f=true;
break;
}
if(a[i]!=a[i+1]) a[i]++;
if(a[i]==k) used[i]=true;
}
if(f) break;
cnt++;
}
System.out.println(cnt);
}
}
| Java | ["4 4\n1 2 2 3", "4 3\n1 1 1 1"] | 2 seconds | ["4", "5"] | NoteIn the first example the ranks will be raised in the following manner:1 2 2 3 βββ 2 2 3 4 βββ 2 3 4 4 βββ 3 4 4 4 βββ 4 4 4 4Thus totals to 4 training sessions that require 4 golden coins. | Java 7 | standard input | [
"implementation"
] | 3d6411d67c85f6293f1999ccff2cd8ba | The first line contains two integers n and k (1ββ€βn,βkββ€β100). They represent the number of soldiers and the number of different ranks correspondingly. The second line contains n numbers in the non-decreasing order. The i-th of them, ai, represents the rank of the i-th soldier in the defense building (1ββ€βiββ€βn, 1ββ€βaiββ€βk). | 1,200 | Print a single integer β the number of golden coins needed to raise all the soldiers to the maximal rank. | standard output | |
PASSED | e3192782bc4e4c497a74973ccd8fd79a | train_001.jsonl | 1298908800 | In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense structure accommodates exactly n soldiers. Within this task we can assume that the number of soldiers in the defense structure won't either increase or decrease.Every soldier has a rank β some natural number from 1 to k. 1 stands for a private and k stands for a general. The higher the rank of the soldier is, the better he fights. Therefore, the player profits from having the soldiers of the highest possible rank.To increase the ranks of soldiers they need to train. But the soldiers won't train for free, and each training session requires one golden coin. On each training session all the n soldiers are present.At the end of each training session the soldiers' ranks increase as follows. First all the soldiers are divided into groups with the same rank, so that the least possible number of groups is formed. Then, within each of the groups where the soldiers below the rank k are present, exactly one soldier increases his rank by one.You know the ranks of all n soldiers at the moment. Determine the number of golden coins that are needed to increase the ranks of all the soldiers to the rank k. | 256 megabytes | import java.io.*;
import java.math.*;
import java.util.*;
import java.util.concurrent.*;
public class P63B {
int n, k;
void inc(TreeMap<Integer, Integer> map, int value) {
if (value < k) {
Integer count = map.get(value);
map.put(value, (count == null) ? 1 : count + 1);
}
}
void dec(TreeMap<Integer, Integer> map, int value) {
Integer count = map.get(value);
if (count != null) {
if (count <= 1) {
map.remove(value);
} else {
map.put(value, count - 1);
}
}
}
@SuppressWarnings("unchecked")
public void run() throws Exception {
n = nextInt();
k = nextInt();
TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
while ((n--) > 0) {
inc(map, nextInt());
}
int steps = 0;
while (map.size() > 0) {
TreeMap<Integer, Integer> newMap = new TreeMap<Integer, Integer>(map);
for (Integer value : map.keySet()) {
inc(newMap, value + 1);
dec(newMap, value);
}
steps++;
map = newMap;
}
println(steps);
}
public static void main(String... args) throws Exception {
br = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(new BufferedOutputStream(System.out));
new P63B().run();
br.close();
pw.close();
}
static BufferedReader br;
static PrintWriter pw;
StringTokenizer stok;
String nextToken() throws IOException {
while (stok == null || !stok.hasMoreTokens()) {
String s = br.readLine();
if (s == null) { return null; }
stok = new StringTokenizer(s);
}
return stok.nextToken();
}
void print(byte b) { print("" + b); }
void print(int i) { print("" + i); }
void print(long l) { print("" + l); }
void print(double d) { print("" + d); }
void print(char c) { print("" + c); }
void print(Object o) {
if (o instanceof int[]) { print(Arrays.toString((int [])o));
} else if (o instanceof long[]) { print(Arrays.toString((long [])o));
} else if (o instanceof char[]) { print(Arrays.toString((char [])o));
} else if (o instanceof byte[]) { print(Arrays.toString((byte [])o));
} else if (o instanceof short[]) { print(Arrays.toString((short [])o));
} else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o));
} else if (o instanceof float[]) { print(Arrays.toString((float [])o));
} else if (o instanceof double[]) { print(Arrays.toString((double [])o));
} else if (o instanceof Object[]) { print(Arrays.toString((Object [])o));
} else { println("" + o); }
}
void print(String s) { pw.print(s); }
void println() { println(""); }
void println(byte b) { println("" + b); }
void println(int i) { println("" + i); }
void println(long l) { println("" + l); }
void println(double d) { println("" + d); }
void println(char c) { println("" + c); }
void println(Object o) { print("" + o); }
void println(String s) { pw.println(s); }
int nextInt() throws IOException { return Integer.parseInt(nextToken()); }
long nextLong() throws IOException { return Long.parseLong(nextToken()); }
double nextDouble() throws IOException { return Double.parseDouble(nextToken()); }
char nextChar() throws IOException { return (char) (br.read()); }
String next() throws IOException { return nextToken(); }
String nextLine() throws IOException { return br.readLine(); }
int [] readInt(int size) throws IOException {
int [] array = new int [size];
for (int i = 0; i < size; i++) { array[i] = nextInt(); }
return array;
}
long [] readLong(int size) throws IOException {
long [] array = new long [size];
for (int i = 0; i < size; i++) { array[i] = nextLong(); }
return array;
}
double [] readDouble(int size) throws IOException {
double [] array = new double [size];
for (int i = 0; i < size; i++) { array[i] = nextDouble(); }
return array;
}
String [] readLines(int size) throws IOException {
String [] array = new String [size];
for (int i = 0; i < size; i++) { array[i] = nextLine(); }
return array;
}
} | Java | ["4 4\n1 2 2 3", "4 3\n1 1 1 1"] | 2 seconds | ["4", "5"] | NoteIn the first example the ranks will be raised in the following manner:1 2 2 3 βββ 2 2 3 4 βββ 2 3 4 4 βββ 3 4 4 4 βββ 4 4 4 4Thus totals to 4 training sessions that require 4 golden coins. | Java 7 | standard input | [
"implementation"
] | 3d6411d67c85f6293f1999ccff2cd8ba | The first line contains two integers n and k (1ββ€βn,βkββ€β100). They represent the number of soldiers and the number of different ranks correspondingly. The second line contains n numbers in the non-decreasing order. The i-th of them, ai, represents the rank of the i-th soldier in the defense building (1ββ€βiββ€βn, 1ββ€βaiββ€βk). | 1,200 | Print a single integer β the number of golden coins needed to raise all the soldiers to the maximal rank. | standard output | |
PASSED | 4af225549bec1e1a65767db3706b0349 | train_001.jsonl | 1298908800 | In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense structure accommodates exactly n soldiers. Within this task we can assume that the number of soldiers in the defense structure won't either increase or decrease.Every soldier has a rank β some natural number from 1 to k. 1 stands for a private and k stands for a general. The higher the rank of the soldier is, the better he fights. Therefore, the player profits from having the soldiers of the highest possible rank.To increase the ranks of soldiers they need to train. But the soldiers won't train for free, and each training session requires one golden coin. On each training session all the n soldiers are present.At the end of each training session the soldiers' ranks increase as follows. First all the soldiers are divided into groups with the same rank, so that the least possible number of groups is formed. Then, within each of the groups where the soldiers below the rank k are present, exactly one soldier increases his rank by one.You know the ranks of all n soldiers at the moment. Determine the number of golden coins that are needed to increase the ranks of all the soldiers to the rank k. | 256 megabytes | import java.util.Scanner;
public class B {
static Scanner in = new Scanner(System.in);
public static void main(String[] args) {
int n = in.nextInt(), k = in.nextInt();
int[] v = new int[n+1];
int sum = 0;
for(int i = 0 ; i < n ; i++) {
v[i] = in.nextInt();
sum += v[i];
}
v[n] = k;
int res = 0;
while(sum < k * n) {
for(int i = 0 ; i < n; i++) {
if(v[i] < v[i+1]) {
v[i]++;
sum++;
}
}
res ++;
}
System.out.println(res);
}
} | Java | ["4 4\n1 2 2 3", "4 3\n1 1 1 1"] | 2 seconds | ["4", "5"] | NoteIn the first example the ranks will be raised in the following manner:1 2 2 3 βββ 2 2 3 4 βββ 2 3 4 4 βββ 3 4 4 4 βββ 4 4 4 4Thus totals to 4 training sessions that require 4 golden coins. | Java 7 | standard input | [
"implementation"
] | 3d6411d67c85f6293f1999ccff2cd8ba | The first line contains two integers n and k (1ββ€βn,βkββ€β100). They represent the number of soldiers and the number of different ranks correspondingly. The second line contains n numbers in the non-decreasing order. The i-th of them, ai, represents the rank of the i-th soldier in the defense building (1ββ€βiββ€βn, 1ββ€βaiββ€βk). | 1,200 | Print a single integer β the number of golden coins needed to raise all the soldiers to the maximal rank. | standard output | |
PASSED | 62c001911fe5612c6ffa63aed35a7634 | train_001.jsonl | 1298908800 | In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense structure accommodates exactly n soldiers. Within this task we can assume that the number of soldiers in the defense structure won't either increase or decrease.Every soldier has a rank β some natural number from 1 to k. 1 stands for a private and k stands for a general. The higher the rank of the soldier is, the better he fights. Therefore, the player profits from having the soldiers of the highest possible rank.To increase the ranks of soldiers they need to train. But the soldiers won't train for free, and each training session requires one golden coin. On each training session all the n soldiers are present.At the end of each training session the soldiers' ranks increase as follows. First all the soldiers are divided into groups with the same rank, so that the least possible number of groups is formed. Then, within each of the groups where the soldiers below the rank k are present, exactly one soldier increases his rank by one.You know the ranks of all n soldiers at the moment. Determine the number of golden coins that are needed to increase the ranks of all the soldiers to the rank k. | 256 megabytes | /*
* @author Sane
*/
import java.util.*;
import java.util.Scanner;
import java.io.File;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.FileOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.OutputStreamWriter;
public class TheMain {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt(), k = sc.nextInt(), price = 0;
int[] rank = new int[n+1];
for (int i = 0; i < n; ++i)
rank[i] = sc.nextInt();
rank[n] = k;
while (rank[0] < k) {
int i = 0;
while (i < n) {
int tmp = rank[i];
while (i < n-1 && rank[i+1] == tmp)
++i;
++rank[i];
++i;
}
++price;
}
System.out.printf("%d\n", price);
}
}
| Java | ["4 4\n1 2 2 3", "4 3\n1 1 1 1"] | 2 seconds | ["4", "5"] | NoteIn the first example the ranks will be raised in the following manner:1 2 2 3 βββ 2 2 3 4 βββ 2 3 4 4 βββ 3 4 4 4 βββ 4 4 4 4Thus totals to 4 training sessions that require 4 golden coins. | Java 7 | standard input | [
"implementation"
] | 3d6411d67c85f6293f1999ccff2cd8ba | The first line contains two integers n and k (1ββ€βn,βkββ€β100). They represent the number of soldiers and the number of different ranks correspondingly. The second line contains n numbers in the non-decreasing order. The i-th of them, ai, represents the rank of the i-th soldier in the defense building (1ββ€βiββ€βn, 1ββ€βaiββ€βk). | 1,200 | Print a single integer β the number of golden coins needed to raise all the soldiers to the maximal rank. | standard output | |
PASSED | f3282a9ed389a510a3c908f1756d649e | train_001.jsonl | 1298908800 | In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense structure accommodates exactly n soldiers. Within this task we can assume that the number of soldiers in the defense structure won't either increase or decrease.Every soldier has a rank β some natural number from 1 to k. 1 stands for a private and k stands for a general. The higher the rank of the soldier is, the better he fights. Therefore, the player profits from having the soldiers of the highest possible rank.To increase the ranks of soldiers they need to train. But the soldiers won't train for free, and each training session requires one golden coin. On each training session all the n soldiers are present.At the end of each training session the soldiers' ranks increase as follows. First all the soldiers are divided into groups with the same rank, so that the least possible number of groups is formed. Then, within each of the groups where the soldiers below the rank k are present, exactly one soldier increases his rank by one.You know the ranks of all n soldiers at the moment. Determine the number of golden coins that are needed to increase the ranks of all the soldiers to the rank k. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main{
BufferedReader in;
StringTokenizer str = null;
PrintWriter out;
private String next() throws Exception{
while (str == null || !str.hasMoreElements())
str = new StringTokenizer(in.readLine());
return str.nextToken();
}
private int nextInt() throws Exception{
return Integer.parseInt(next());
}
public void run() throws Exception{
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
int n = nextInt(), k = nextInt();
int []a = new int[n];
for(int i=0;i<n;i++) a[i] = nextInt();
int remain = 0, ret = 0;
for(int i=0;i<n;i++) if (a[i] < k) remain++;
while(remain > 0){
boolean used[] = new boolean[k];
for(int i=0;i<n;i++){
if (a[i] < k && !used[a[i]]){
used[a[i]] = true;
a[i]++;
if (a[i] == k) remain--;
}
}
++ret;
//System.out.println(Arrays.toString(a));
}
out.println(ret);
out.close();
}
public static void main(String args[]) throws Exception{
new Main().run();
}
} | Java | ["4 4\n1 2 2 3", "4 3\n1 1 1 1"] | 2 seconds | ["4", "5"] | NoteIn the first example the ranks will be raised in the following manner:1 2 2 3 βββ 2 2 3 4 βββ 2 3 4 4 βββ 3 4 4 4 βββ 4 4 4 4Thus totals to 4 training sessions that require 4 golden coins. | Java 7 | standard input | [
"implementation"
] | 3d6411d67c85f6293f1999ccff2cd8ba | The first line contains two integers n and k (1ββ€βn,βkββ€β100). They represent the number of soldiers and the number of different ranks correspondingly. The second line contains n numbers in the non-decreasing order. The i-th of them, ai, represents the rank of the i-th soldier in the defense building (1ββ€βiββ€βn, 1ββ€βaiββ€βk). | 1,200 | Print a single integer β the number of golden coins needed to raise all the soldiers to the maximal rank. | standard output | |
PASSED | b50d964895d44cee4ac7cbb084cb4b98 | train_001.jsonl | 1298908800 | In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense structure accommodates exactly n soldiers. Within this task we can assume that the number of soldiers in the defense structure won't either increase or decrease.Every soldier has a rank β some natural number from 1 to k. 1 stands for a private and k stands for a general. The higher the rank of the soldier is, the better he fights. Therefore, the player profits from having the soldiers of the highest possible rank.To increase the ranks of soldiers they need to train. But the soldiers won't train for free, and each training session requires one golden coin. On each training session all the n soldiers are present.At the end of each training session the soldiers' ranks increase as follows. First all the soldiers are divided into groups with the same rank, so that the least possible number of groups is formed. Then, within each of the groups where the soldiers below the rank k are present, exactly one soldier increases his rank by one.You know the ranks of all n soldiers at the moment. Determine the number of golden coins that are needed to increase the ranks of all the soldiers to the rank k. | 256 megabytes | import java.io.*;
import java.util.*;
public class j
{
public static void main(String a[])throws IOException
{
BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
int k=0,m=0,n=0,i=0;
String s;
StringTokenizer c=new StringTokenizer(b.readLine());
n=Integer.parseInt(c.nextToken());
k=Integer.parseInt(c.nextToken());
int d[]=new int[k+1];
d[0]=0;
s=b.readLine();
StringTokenizer q=new StringTokenizer(s);
for(i=0;i<n;i++)
d[Integer.parseInt(q.nextToken())]++;
while(d[k]!=n)
{
for(i=k-1;i>=0;i--)
{
if(d[i]!=0)
{
d[i]--;
d[i+1]++;
}
}
m++;
}
System.out.print(m);
}
} | Java | ["4 4\n1 2 2 3", "4 3\n1 1 1 1"] | 2 seconds | ["4", "5"] | NoteIn the first example the ranks will be raised in the following manner:1 2 2 3 βββ 2 2 3 4 βββ 2 3 4 4 βββ 3 4 4 4 βββ 4 4 4 4Thus totals to 4 training sessions that require 4 golden coins. | Java 7 | standard input | [
"implementation"
] | 3d6411d67c85f6293f1999ccff2cd8ba | The first line contains two integers n and k (1ββ€βn,βkββ€β100). They represent the number of soldiers and the number of different ranks correspondingly. The second line contains n numbers in the non-decreasing order. The i-th of them, ai, represents the rank of the i-th soldier in the defense building (1ββ€βiββ€βn, 1ββ€βaiββ€βk). | 1,200 | Print a single integer β the number of golden coins needed to raise all the soldiers to the maximal rank. | standard output | |
PASSED | 2787a7743e22cfccbd5da369656e2668 | train_001.jsonl | 1298908800 | In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense structure accommodates exactly n soldiers. Within this task we can assume that the number of soldiers in the defense structure won't either increase or decrease.Every soldier has a rank β some natural number from 1 to k. 1 stands for a private and k stands for a general. The higher the rank of the soldier is, the better he fights. Therefore, the player profits from having the soldiers of the highest possible rank.To increase the ranks of soldiers they need to train. But the soldiers won't train for free, and each training session requires one golden coin. On each training session all the n soldiers are present.At the end of each training session the soldiers' ranks increase as follows. First all the soldiers are divided into groups with the same rank, so that the least possible number of groups is formed. Then, within each of the groups where the soldiers below the rank k are present, exactly one soldier increases his rank by one.You know the ranks of all n soldiers at the moment. Determine the number of golden coins that are needed to increase the ranks of all the soldiers to the rank k. | 256 megabytes | import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
public class Solution3 {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int k = scanner.nextInt();
int rank[] = new int[k];
for(int i=0;i<n;i++){
rank[scanner.nextInt()-1]++;
}
int count = 0;
while(rank[k-1]<n){
for(int i=k-2;i>=0;i--){
if(rank[i] > 0){
rank[i]--;
rank[i+1]++;
}
}
count++;
}
System.out.println(count);
}
}
| Java | ["4 4\n1 2 2 3", "4 3\n1 1 1 1"] | 2 seconds | ["4", "5"] | NoteIn the first example the ranks will be raised in the following manner:1 2 2 3 βββ 2 2 3 4 βββ 2 3 4 4 βββ 3 4 4 4 βββ 4 4 4 4Thus totals to 4 training sessions that require 4 golden coins. | Java 7 | standard input | [
"implementation"
] | 3d6411d67c85f6293f1999ccff2cd8ba | The first line contains two integers n and k (1ββ€βn,βkββ€β100). They represent the number of soldiers and the number of different ranks correspondingly. The second line contains n numbers in the non-decreasing order. The i-th of them, ai, represents the rank of the i-th soldier in the defense building (1ββ€βiββ€βn, 1ββ€βaiββ€βk). | 1,200 | Print a single integer β the number of golden coins needed to raise all the soldiers to the maximal rank. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.