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 | f93abf8a10f8865a6ae4d3d131bed433 | train_003.jsonl | 1593873900 | You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k > 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge. | 256 megabytes | import java.lang.*;
import java.util.*;
import java.io.*;
public class Grid{
boolean checkInc(int[][]gArr,int r, int c){
boolean retV = false;
if(gArr[r][c]==0){
gArr[r][c]++;
retV = true;
}
return retV;
}
int[][]updateGrid(int n, int m, int[][]gArr){
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(gArr[i][j]>0){
boolean cv = checkNBors(n,m,gArr,i,j);
if(!cv){
return new int[0][0];
}
}
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(gArr[i][j]>0){
int nInc = getNumInc(n,m,gArr,i,j);
gArr[i][j] -= nInc;
}
}
}
return gArr;
}
int getNumInc(int n, int m, int[][]gArr,int r, int c){
int val = gArr[r][c];
if((r>0)&&(gArr[r-1][c]>0)){
val--;
}
if((r<(n-1))&&(gArr[r+1][c]>0)){
val--;
}
if((c>0)&&(gArr[r][c-1]>0)){
val--;
}
if((c<(m-1))&&(gArr[r][c+1]>0)){
val--;
}
return val;
}
boolean checkNBors(int n, int m, int[][]gArr,int r, int c){
int el = getNumInc(n,m,gArr,r,c);
boolean retV = true;
if(el>4){
retV = false;
}else if(el<0){
gArr[r][c] -= el;
el = 0;
}else{
if(r<(n-1)){
if(el>0){
if(checkInc(gArr,r+1,c))
el--;
}
}
if(c<(m-1)){
if(el>0){
if(checkInc(gArr,r,c+1))
el--;
}
}
if(c>0){
if(el>0){
if(checkInc(gArr,r,c-1)){
el--;
}
}
}
if(r>0){
if(el>0){
if(checkInc(gArr,r-1,c))
el--;
}
}
if(el>0){
retV = false;
}
}
return retV;
}
static Integer[]strToIntArr(String s){
// s = s.substring(1,s.length()-1);
// String[] sArr = s.split(",");
String[] sArr = s.split(" ");
int len = sArr.length;
Integer[] retArr = new Integer[len];
for(int i=0;i<len;i++){
retArr[i] = Integer.parseInt(sArr[i]);
}
return retArr;
}
public static void main(String[]args)throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
Grid g = new Grid();
String tLn = br.readLine();
int t = Integer.parseInt(tLn);
for(int i=0;i<t;i++){
String nmLn = br.readLine();
Integer[]nmArr = strToIntArr(nmLn);
int n = nmArr[0];
int m = nmArr[1];
int[][]gArr = new int[n][m];
for(int j=0;j<n;j++){
String gLn = br.readLine();
Integer[]rowArr = strToIntArr(gLn);
for(int k=0;k<m;k++){
gArr[j][k] = rowArr[k];
}
}
int[][]newG = g.updateGrid(n,m,gArr);
String outStr = "YES";
if(newG.length==0){
outStr = "NO";
}
bw.write(outStr);
bw.newLine();
bw.flush();
if(newG.length>0){
for(int j=0;j<n;j++){
for(int k=0;k<m;k++){
String elStr = Integer.toString(newG[j][k]);
bw.write(elStr);
if(k<(m-1)){
bw.write(" ");
}
}
bw.newLine();
bw.flush();
}
}
}
}
}
| Java | ["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"] | 1 second | ["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"] | NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 8afcdfaabba66fb9cefc5b6ceabac0d0 | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$) Β β the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$) Β β the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$. | 1,200 | If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them. | standard output | |
PASSED | 5d019fb0bfd170e89db6919d399ef073 | train_003.jsonl | 1593873900 | You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k > 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge. | 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 mystr[]=br.readLine().split(" ");
int n=Integer.parseInt(mystr[0]);
int m=Integer.parseInt(mystr[1]);
int a[][]=new int[n][m];
for(int i=0;i<n;i++)
{
String str[]=br.readLine().split(" ");
for(int j=0;j<m;j++)
a[i][j]=Integer.parseInt(str[j]);
}
boolean flag=true;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(i!=0&&i!=n-1&&j!=0&&j!=m-1)
{
if(a[i][j]>4)
flag=false;
a[i][j]=4;
}
else if((i==0&&j==0)||(i==n-1&&j==0)||(i==0&&j==m-1)||(i==n-1&&j==m-1))
{
if(a[i][j]>2)
flag=false;
a[i][j]=2;
}
else
{
if(a[i][j]>3)
flag=false;
a[i][j]=3;
}
}
}
if(flag)
{
bw.write("YES\n");
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
bw.write(a[i][j]+" ");
bw.newLine();
}
}
else
bw.write("NO\n");
}
bw.close();
}
} | Java | ["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"] | 1 second | ["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"] | NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 8afcdfaabba66fb9cefc5b6ceabac0d0 | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$) Β β the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$) Β β the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$. | 1,200 | If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them. | standard output | |
PASSED | bb32a2f12e651facfa77f9607ae871e4 | train_003.jsonl | 1593873900 | You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k > 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge. | 256 megabytes | import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
public class Main {
InputStream is;
PrintWriter out;
String INPUT = "";
void solve() {
for(int T = ni(); T > 0; T--) {
int n = ni(), m = ni();
int[][] a = new int[n][];
for(int i = 0; i < n; i++) a[i] = na(m);
int[][] ideal = new int[n][m];
boolean ans = true;
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
if(i-1 >= 0) ideal[i][j]++;
if(j-1 >= 0) ideal[i][j]++;
if(i+1 < n) ideal[i][j]++;
if(j+1 < m) ideal[i][j]++;
ans &= ideal[i][j] >= a[i][j];
}
}
if(ans) {
out.println("YES");
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
out.print(ideal[i][j]+" ");
}
}
out.println();
}
else {
out.println("NO");
}
}
}
void run() throws Exception {
is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
out = new PrintWriter(System.out);
long s = System.currentTimeMillis();
solve();
out.flush();
if (!INPUT.isEmpty())
tr(System.currentTimeMillis() - s + "ms");
}
public static void main(String[] args) throws Exception {
new Main().run();
}
private byte[] inbuf = new byte[1024];
public int lenbuf = 0, ptrbuf = 0;
private int readByte() {
if (lenbuf == -1)
throw new InputMismatchException();
if (ptrbuf >= lenbuf) {
ptrbuf = 0;
try {
lenbuf = is.read(inbuf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0)
return -1;
}
return inbuf[ptrbuf++];
}
private boolean isSpaceChar(int c) {
return !(c >= 33 && c <= 126);
}
private int skip() {
int b;
while ((b = readByte()) != -1 && isSpaceChar(b))
;
return b;
}
private double nd() {
return Double.parseDouble(ns());
}
private char nc() {
return (char) skip();
}
private String ns() {
int b = skip();
StringBuilder sb = new StringBuilder();
while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private String nsl() {
int b = skip();
StringBuilder sb = new StringBuilder();
while (!(isSpaceChar(b) && b != ' ')) { // when nextLine, (isSpaceChar(b) && b != ' ')
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private char[] ns(int n) {
char[] buf = new char[n];
int b = skip(), p = 0;
while (p < n && !(isSpaceChar(b))) {
buf[p++] = (char) b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
private char[][] nm(int n, int m) {
char[][] map = new char[n][];
for (int i = 0; i < n; i++)
map[i] = ns(m);
return map;
}
private int[] na(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = ni();
return a;
}
private int ni() {
int num = 0, b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
private long nl() {
long num = 0;
int b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
private static void tr(Object... o) {
System.out.println(Arrays.deepToString(o));
}
} | Java | ["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"] | 1 second | ["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"] | NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 8afcdfaabba66fb9cefc5b6ceabac0d0 | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$) Β β the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$) Β β the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$. | 1,200 | If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them. | standard output | |
PASSED | 08f84e2a00acd41a4b6a6a3fb4f49e44 | train_003.jsonl | 1593873900 | You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k > 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge. | 256 megabytes |
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
public class BB {
public static void main(String[] args) {
try {
FastReader fr = new FastReader(System.in);
int t = fr.nextInt();
while (t > 0) {
t--;
int n, m;
n = fr.nextInt();
m = fr.nextInt();
List<List<Integer>> matrix = new ArrayList<>();
for (int i = 0; i < n; i++) {
List<Integer> row = new ArrayList<>();
for (int j = 0; j < m; j++) {
row.add(fr.nextInt());
}
matrix.add(row);
}
boolean ans = true;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
List<Integer> row = matrix.get(i);
for (int j = 0; j < m; j++) {
Integer curr = row.get(j);
if(curr <= 4) {
int no = getNo(curr, i, j, matrix, n, m);
if (no < curr) {
ans = false;
break;
} else {
sb.append(no + " ");
row.set(j, no);
}
} else {
ans = false;
break;
}
}
sb.append("\n");
if (!ans) break;
}
if (ans) {
System.out.println("YES");
System.out.print(sb);
} else System.out.println("NO");
}
} catch (Exception e) {
}
}
private static int getNo(Integer curr, int i, int j, List<List<Integer>> matrix, int n, int m) {
int total = 0;
if(j>0) total++;
if(j<m-1) total++;
if(i>0) total++;
if(i<n-1) total++;
return total;
}
static class FastReader {
byte[] buf = new byte[2048];
int index, total;
InputStream in;
FastReader(InputStream is) {
in = is;
}
int scan() throws IOException {
if (index >= total) {
index = 0;
total = in.read(buf);
if (total <= 0) {
return -1;
}
}
return buf[index++];
}
String next() throws IOException {
int c;
for (c = scan(); c <= 32; c = scan()) ;
StringBuilder sb = new StringBuilder();
for (; c > 32; c = scan()) {
sb.append((char) c);
}
return sb.toString();
}
int nextInt() throws IOException {
int c, val = 0;
for (c = scan(); c <= 32; c = scan()) ;
boolean neg = c == '-';
if (c == '-' || c == '+') {
c = scan();
}
for (; c >= '0' && c <= '9'; c = scan()) {
val = (val << 3) + (val << 1) + (c & 15);
}
return neg ? -val : val;
}
long nextLong() throws IOException {
int c;
long val = 0;
for (c = scan(); c <= 32; c = scan()) ;
boolean neg = c == '-';
if (c == '-' || c == '+') {
c = scan();
}
for (; c >= '0' && c <= '9'; c = scan()) {
val = (val << 3) + (val << 1) + (c & 15);
}
return neg ? -val : val;
}
}
}
| Java | ["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"] | 1 second | ["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"] | NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 8afcdfaabba66fb9cefc5b6ceabac0d0 | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$) Β β the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$) Β β the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$. | 1,200 | If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them. | standard output | |
PASSED | 18f2fd343d00a4c17ffe831d10f3c74a | train_003.jsonl | 1593873900 | You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k > 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge. | 256 megabytes |
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class BB {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t > 0) {
t--;
int n,m;
n = sc.nextInt();
m = sc.nextInt();
List<List<Integer>> matrix = new ArrayList<>();
for(int i = 0;i<n;i++) {
List<Integer> row = new ArrayList<>();
for(int j = 0;j<m;j++) {
row.add(sc.nextInt());
}
matrix.add(row);
}
boolean ans = true;
for(int i = 0;i<n;i++) {
List<Integer> row = matrix.get(i);
for(int j = 0;j<m; j++) {
Integer curr = row.get(j);
int no = getNo(curr,i,j,matrix,n,m);
if(no<curr){
ans = false;
break;
} else {
row.set(j,no);
}
}
if(!ans) break;
}
if(ans) {
System.out.println("YES");
for(int i = 0;i<n;i++) {
List<Integer> row = matrix.get(i);
for(int j = 0;j<m; j++) {
System.out.print(row.get(j) + " ");
}
System.out.print("\n");
}
} else System.out.println("NO");
}
}
private static int getNo(Integer curr, int i, int j, List<List<Integer>> matrix, int n, int m) {
int total = 0;
if(j>0) total++;
if(j<m-1) total++;
if(i>0) total++;
if(i<n-1) total++;
return total;
}
}
| Java | ["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"] | 1 second | ["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"] | NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 8afcdfaabba66fb9cefc5b6ceabac0d0 | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$) Β β the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$) Β β the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$. | 1,200 | If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them. | standard output | |
PASSED | 82df136866246bae8734bcdc1d3b31c4 | train_003.jsonl | 1593873900 | You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k > 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge. | 256 megabytes | import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class BB {
public static void main(String[] args) {
try {
FastReader fr = new FastReader(System.in);
int t = fr.nextInt();
while (t > 0) {
t--;
int n, m;
n = fr.nextInt();
m = fr.nextInt();
List<List<Integer>> matrix = new ArrayList<>();
boolean ans = true;
for (int i = 0; i < n; i++) {
List<Integer> row = new ArrayList<>();
for (int j = 0; j < m; j++) {
int curr = fr.nextInt();
int no = getNo(i, j, n, m);
if (no < curr) {
ans = false;
row.add(curr);
} else {
row.add(no);
}
}
matrix.add(row);
}
if (ans) {
System.out.println("YES");
for (int i = 0; i < n; i++) {
List<Integer> row = matrix.get(i);
for (int j = 0; j < m; j++) {
System.out.print(row.get(j) + " ");
}
System.out.print("\n");
}
} else System.out.println("NO");
}
} catch (Exception e) {
}
}
private static int getNo(int i, int j, int n, int m) {
int total = 0;
if(j>0) total++;
if(j<m-1) total++;
if(i>0) total++;
if(i<n-1) total++;
return total;
}
static class FastReader {
byte[] buf = new byte[2048];
int index, total;
InputStream in;
FastReader(InputStream is) {
in = is;
}
int scan() throws IOException {
if (index >= total) {
index = 0;
total = in.read(buf);
if (total <= 0) {
return -1;
}
}
return buf[index++];
}
String next() throws IOException {
int c;
for (c = scan(); c <= 32; c = scan()) ;
StringBuilder sb = new StringBuilder();
for (; c > 32; c = scan()) {
sb.append((char) c);
}
return sb.toString();
}
int nextInt() throws IOException {
int c, val = 0;
for (c = scan(); c <= 32; c = scan()) ;
boolean neg = c == '-';
if (c == '-' || c == '+') {
c = scan();
}
for (; c >= '0' && c <= '9'; c = scan()) {
val = (val << 3) + (val << 1) + (c & 15);
}
return neg ? -val : val;
}
long nextLong() throws IOException {
int c;
long val = 0;
for (c = scan(); c <= 32; c = scan()) ;
boolean neg = c == '-';
if (c == '-' || c == '+') {
c = scan();
}
for (; c >= '0' && c <= '9'; c = scan()) {
val = (val << 3) + (val << 1) + (c & 15);
}
return neg ? -val : val;
}
}
}
| Java | ["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"] | 1 second | ["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"] | NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 8afcdfaabba66fb9cefc5b6ceabac0d0 | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$) Β β the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$) Β β the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$. | 1,200 | If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them. | standard output | |
PASSED | 4ff2dbfb4da6c55586ce0158c07dab23 | train_003.jsonl | 1593873900 | You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k > 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge. | 256 megabytes |
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class BB {
public static void main(String[] args) {
try {
FastReader fr = new FastReader(System.in);
int t = fr.nextInt();
while (t > 0) {
t--;
int n, m;
n = fr.nextInt();
m = fr.nextInt();
List<List<Integer>> matrix = new ArrayList<>();
StringBuilder sb = new StringBuilder();
boolean ans = true;
for (int i = 0; i < n; i++) {
List<Integer> row = new ArrayList<>();
for (int j = 0; j < m; j++) {
int curr = fr.nextInt();
int no = getNo(i, j, n, m);
if (no < curr) {
ans = false;
row.add(curr);
} else {
row.add(no);
sb.append(no + " ");
}
}
sb.append("\n");
matrix.add(row);
}
if (ans) {
System.out.println("YES");
System.out.println(sb);
} else System.out.println("NO");
}
} catch (Exception e) {
}
}
private static int getNo(int i, int j, int n, int m) {
int total = 0;
if(j>0) total++;
if(j<m-1) total++;
if(i>0) total++;
if(i<n-1) total++;
return total;
}
static class FastReader {
byte[] buf = new byte[2048];
int index, total;
InputStream in;
FastReader(InputStream is) {
in = is;
}
int scan() throws IOException {
if (index >= total) {
index = 0;
total = in.read(buf);
if (total <= 0) {
return -1;
}
}
return buf[index++];
}
String next() throws IOException {
int c;
for (c = scan(); c <= 32; c = scan()) ;
StringBuilder sb = new StringBuilder();
for (; c > 32; c = scan()) {
sb.append((char) c);
}
return sb.toString();
}
int nextInt() throws IOException {
int c, val = 0;
for (c = scan(); c <= 32; c = scan()) ;
boolean neg = c == '-';
if (c == '-' || c == '+') {
c = scan();
}
for (; c >= '0' && c <= '9'; c = scan()) {
val = (val << 3) + (val << 1) + (c & 15);
}
return neg ? -val : val;
}
long nextLong() throws IOException {
int c;
long val = 0;
for (c = scan(); c <= 32; c = scan()) ;
boolean neg = c == '-';
if (c == '-' || c == '+') {
c = scan();
}
for (; c >= '0' && c <= '9'; c = scan()) {
val = (val << 3) + (val << 1) + (c & 15);
}
return neg ? -val : val;
}
}
} | Java | ["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"] | 1 second | ["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"] | NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 8afcdfaabba66fb9cefc5b6ceabac0d0 | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$) Β β the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$) Β β the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$. | 1,200 | If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them. | standard output | |
PASSED | d4448b426a2828b604209224679f764e | train_003.jsonl | 1593873900 | You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k > 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge. | 256 megabytes |
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class BB {
public static void main(String[] args) {
try {
FastReader fr = new FastReader(System.in);
int t = fr.nextInt();
while (t > 0) {
t--;
int n, m;
n = fr.nextInt();
m = fr.nextInt();
List<List<Integer>> matrix = new ArrayList<>();
boolean ans = true;
for (int i = 0; i < n; i++) {
List<Integer> row = new ArrayList<>();
for (int j = 0; j < m; j++) {
int curr = fr.nextInt();
int no = getNo(i, j, n, m);
if (no < curr) {
ans = false;
row.add(curr);
} else {
row.add(no);
}
}
matrix.add(row);
}
if (ans) {
System.out.println("YES");
for (int i = 0; i < n; i++) {
List<Integer> row = matrix.get(i);
for (int j = 0; j < m; j++) {
System.out.print(row.get(j) + " ");
}
System.out.print("\n");
}
} else System.out.println("NO");
}
} catch (Exception e) {
}
}
private static int getNo(int i, int j, int n, int m) {
int total = 0;
if(j>0) total++;
if(j<m-1) total++;
if(i>0) total++;
if(i<n-1) total++;
return total;
}
static class FastReader {
byte[] buf = new byte[2048];
int index, total;
InputStream in;
FastReader(InputStream is) {
in = is;
}
int scan() throws IOException {
if (index >= total) {
index = 0;
total = in.read(buf);
if (total <= 0) {
return -1;
}
}
return buf[index++];
}
String next() throws IOException {
int c;
for (c = scan(); c <= 32; c = scan()) ;
StringBuilder sb = new StringBuilder();
for (; c > 32; c = scan()) {
sb.append((char) c);
}
return sb.toString();
}
int nextInt() throws IOException {
int c, val = 0;
for (c = scan(); c <= 32; c = scan()) ;
boolean neg = c == '-';
if (c == '-' || c == '+') {
c = scan();
}
for (; c >= '0' && c <= '9'; c = scan()) {
val = (val << 3) + (val << 1) + (c & 15);
}
return neg ? -val : val;
}
long nextLong() throws IOException {
int c;
long val = 0;
for (c = scan(); c <= 32; c = scan()) ;
boolean neg = c == '-';
if (c == '-' || c == '+') {
c = scan();
}
for (; c >= '0' && c <= '9'; c = scan()) {
val = (val << 3) + (val << 1) + (c & 15);
}
return neg ? -val : val;
}
}
}
| Java | ["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"] | 1 second | ["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"] | NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 8afcdfaabba66fb9cefc5b6ceabac0d0 | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$) Β β the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$) Β β the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$. | 1,200 | If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them. | standard output | |
PASSED | ba0b49ca3d43fabaa7c6fe71d8029f60 | train_003.jsonl | 1593873900 | You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k > 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge. | 256 megabytes |
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class BB {
public static void main(String[] args) {
try {
FastReader fr = new FastReader(System.in);
int t = fr.nextInt();
while (t > 0) {
t--;
int n, m;
n = fr.nextInt();
m = fr.nextInt();
List<List<Integer>> matrix = new ArrayList<>();
for (int i = 0; i < n; i++) {
List<Integer> row = new ArrayList<>();
for (int j = 0; j < m; j++) {
row.add(fr.nextInt());
}
matrix.add(row);
}
boolean ans = true;
for (int i = 0; i < n; i++) {
List<Integer> row = matrix.get(i);
for (int j = 0; j < m; j++) {
Integer curr = row.get(j);
int no = getNo(curr, i, j, matrix, n, m);
if (no < curr) {
ans = false;
break;
} else {
row.set(j, no);
}
}
if (!ans) break;
}
if (ans) {
System.out.println("YES");
for (int i = 0; i < n; i++) {
List<Integer> row = matrix.get(i);
for (int j = 0; j < m; j++) {
System.out.print(row.get(j) + " ");
}
System.out.print("\n");
}
} else System.out.println("NO");
}
} catch (Exception e) {
}
}
private static int getNo(Integer curr, int i, int j, List<List<Integer>> matrix, int n, int m) {
int total = 0;
if(j>0) total++;
if(j<m-1) total++;
if(i>0) total++;
if(i<n-1) total++;
return total;
}
static class FastReader {
byte[] buf = new byte[2048];
int index, total;
InputStream in;
FastReader(InputStream is) {
in = is;
}
int scan() throws IOException {
if (index >= total) {
index = 0;
total = in.read(buf);
if (total <= 0) {
return -1;
}
}
return buf[index++];
}
String next() throws IOException {
int c;
for (c = scan(); c <= 32; c = scan()) ;
StringBuilder sb = new StringBuilder();
for (; c > 32; c = scan()) {
sb.append((char) c);
}
return sb.toString();
}
int nextInt() throws IOException {
int c, val = 0;
for (c = scan(); c <= 32; c = scan()) ;
boolean neg = c == '-';
if (c == '-' || c == '+') {
c = scan();
}
for (; c >= '0' && c <= '9'; c = scan()) {
val = (val << 3) + (val << 1) + (c & 15);
}
return neg ? -val : val;
}
long nextLong() throws IOException {
int c;
long val = 0;
for (c = scan(); c <= 32; c = scan()) ;
boolean neg = c == '-';
if (c == '-' || c == '+') {
c = scan();
}
for (; c >= '0' && c <= '9'; c = scan()) {
val = (val << 3) + (val << 1) + (c & 15);
}
return neg ? -val : val;
}
}
}
| Java | ["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"] | 1 second | ["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"] | NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 8afcdfaabba66fb9cefc5b6ceabac0d0 | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$) Β β the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$) Β β the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$. | 1,200 | If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them. | standard output | |
PASSED | da4a6bd2d99563d46a186db162f00a97 | train_003.jsonl | 1593873900 | You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k > 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge. | 256 megabytes |
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
public class BB {
public static void main(String[] args) {
try {
FastReader fr = new FastReader(System.in);
int t = fr.nextInt();
while (t > 0) {
t--;
int n, m;
n = fr.nextInt();
m = fr.nextInt();
List<List<Integer>> matrix = new ArrayList<>();
for (int i = 0; i < n; i++) {
List<Integer> row = new ArrayList<>();
for (int j = 0; j < m; j++) {
row.add(fr.nextInt());
}
matrix.add(row);
}
boolean ans = true;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
List<Integer> row = matrix.get(i);
for (int j = 0; j < m; j++) {
Integer curr = row.get(j);
int no = getNo(curr, i, j, matrix, n, m);
if (no < curr) {
ans = false;
break;
} else {
sb.append(no + " ");
row.set(j, no);
}
}
sb.append("\n");
if (!ans) break;
}
if (ans) {
System.out.println("YES");
System.out.print(sb);
} else System.out.println("NO");
}
} catch (Exception e) {
}
}
private static int getNo(Integer curr, int i, int j, List<List<Integer>> matrix, int n, int m) {
int total = 0;
if(j>0) total++;
if(j<m-1) total++;
if(i>0) total++;
if(i<n-1) total++;
return total;
}
static class FastReader {
byte[] buf = new byte[2048];
int index, total;
InputStream in;
FastReader(InputStream is) {
in = is;
}
int scan() throws IOException {
if (index >= total) {
index = 0;
total = in.read(buf);
if (total <= 0) {
return -1;
}
}
return buf[index++];
}
String next() throws IOException {
int c;
for (c = scan(); c <= 32; c = scan()) ;
StringBuilder sb = new StringBuilder();
for (; c > 32; c = scan()) {
sb.append((char) c);
}
return sb.toString();
}
int nextInt() throws IOException {
int c, val = 0;
for (c = scan(); c <= 32; c = scan()) ;
boolean neg = c == '-';
if (c == '-' || c == '+') {
c = scan();
}
for (; c >= '0' && c <= '9'; c = scan()) {
val = (val << 3) + (val << 1) + (c & 15);
}
return neg ? -val : val;
}
long nextLong() throws IOException {
int c;
long val = 0;
for (c = scan(); c <= 32; c = scan()) ;
boolean neg = c == '-';
if (c == '-' || c == '+') {
c = scan();
}
for (; c >= '0' && c <= '9'; c = scan()) {
val = (val << 3) + (val << 1) + (c & 15);
}
return neg ? -val : val;
}
}
} | Java | ["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"] | 1 second | ["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"] | NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 8afcdfaabba66fb9cefc5b6ceabac0d0 | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$) Β β the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$) Β β the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$. | 1,200 | If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them. | standard output | |
PASSED | e168891707098cd371bc370710f13680 | train_003.jsonl | 1593873900 | You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k > 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge. | 256 megabytes |
import java.util.*;
import java.io.*;
public class NeighborGrid {
// https://codeforces.com/contest/1375/problem/B
public static void main(String[] args) throws IOException, FileNotFoundException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
//BufferedReader in = new BufferedReader(new FileReader("NeighborGrid"));
int t = Integer.parseInt(in.readLine());
while (t --> 0) {
StringTokenizer st = new StringTokenizer(in.readLine());
int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
int[][] origarr =new int[n][m];
for (int i=0; i<n; i++) {
//origarr[i] = in.readLine().toCharArray();
st = new StringTokenizer(in.readLine());
for (int j=0; j<m; j++) {
origarr[i][j] = Integer.parseInt(st.nextToken());
}
}
int[][] arr = new int[n][m];
// arr[0][0] = 2;
// arr[n-1][0] = 2;
// arr[0][m-1] = 2;
// arr[n-1][m-1] = 2;
boolean works=true;
outer: for (int i=0; i<n; i++) {
for (int j=0; j<m; j++) {
int c = 4;
if (i-1 <0 ) c--;
if (j -1 <0) c--;
if (i+1 >= n) c--;
if (j + 1 >= m) c--;
// arr[i][j] = (char) ('0' + c);
// if (arr[i][j] - '0' < origarr[i][j] - '0') {
// works = false;
// break outer;
// }
arr[i][j] = c;
if (arr[i][j] < origarr[i][j]) {
works = false;
break outer;
}
}
}
if (works) {
System.out.println("YES");
for (int i=0; i<n; i++) {
for (int j=0; j<m; j++) {
System.out.print(arr[i][j] + " ");
}
System.out.println();
}
}
else {
System.out.println("NO");
}
}
}
}
| Java | ["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"] | 1 second | ["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"] | NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 8afcdfaabba66fb9cefc5b6ceabac0d0 | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$) Β β the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$) Β β the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$. | 1,200 | If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them. | standard output | |
PASSED | 1d89825f4d393b12558c5e11cad9b025 | train_003.jsonl | 1593873900 | You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k > 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge. | 256 megabytes | import java.util.*;
public class Main {
public static int helper(int r, int c,int n, int m) {
if(r==0 && c==0)
return 2;
if(r==0 && c==m-1)
return 2;
if(r==n-1 && c==0)
return 2;
if(r==n-1 && c==m-1)
return 2;
if(r==0 || r==n-1 || c==0 || c==m-1)
return 3;
else
return 4;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
int arr[][]=new int[300][300];
while(t-->0) {
int n=sc.nextInt();
int m=sc.nextInt();
for(int i=0;i<n;i++) {
for(int j=0;j<m;j++) {
arr[i][j]=sc.nextInt();
}
}
int flag=0;
int a[][]=new int[n][m];
for(int i=0;i<n;i++) {
for(int j=0;j<m;j++) {
a[i][j]=helper(i,j,n,m);
if(arr[i][j]>a[i][j]) {
flag=1;
break;
}
}
if(flag==1)
break;
}
if(flag==1) {
System.out.println("NO");
continue;
}
else {
System.out.println("YES");
for(int i=0;i<n;i++) {
for(int j=0;j<m;j++) {
System.out.print(a[i][j]+" ");
}
System.out.println();
}
}
}
}
}
| Java | ["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"] | 1 second | ["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"] | NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 8afcdfaabba66fb9cefc5b6ceabac0d0 | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$) Β β the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$) Β β the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$. | 1,200 | If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them. | standard output | |
PASSED | 53c7863681cc8405ccd84dc7107bb672 | train_003.jsonl | 1593873900 | You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k > 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge. | 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 m = in.nextInt();
int n = in.nextInt();
int arr[][] = new int[m][n];
for(int i = 0;i<m;i++) {
for(int j = 0;j<n;j++) {
arr[i][j] = in.nextInt();
}
}
boolean b = true;
for(int i= 0;i<m;i++) {
for(int j = 0;j<n;j++) {
if(i==0&&j==0||i==0&&j==n-1||i==m-1&&j==0||i==m-1&&j==n-1) {
if(arr[i][j]>2) {
b = false;
break;
}
arr[i][j] = 2;
}
else if(i==0||j==0||i==m-1||j==n-1) {
if(arr[i][j]>3) {
b = false;
break;
}
arr[i][j] = 3;
}
else {
if(arr[i][j]>4) {
b = false;
break;
}
arr[i][j] = 4;
}
}
if(!b) {
break;
}
}
if(!b) {
str.append("NO\n");
}else {
str.append("YES\n");
for(int i = 0;i<m;i++) {
for(int j = 0;j<n;j++) {
str.append(arr[i][j] + " ");
}
str.append("\n");
}
}
}
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 | ["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"] | 1 second | ["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"] | NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 8afcdfaabba66fb9cefc5b6ceabac0d0 | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$) Β β the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$) Β β the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$. | 1,200 | If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them. | standard output | |
PASSED | c2fb9c29034495a3e70238f7219388a3 | train_003.jsonl | 1593873900 | You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k > 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
// File file = new File("input.txt");
// Scanner in = new Scanner(file);
// PrintWriter out = new PrintWriter(new FileWriter("output.txt"));
public static void main(String[] args) {
// Scanner in = new Scanner(System.in);
FastReader in = new FastReader();
int t = in.nextInt();
while(t-- > 0) {
int n = in.nextInt(), m = in.nextInt();
int[][] a = new int[n][m];
for(int i = 0; i<n; i++)
for(int j = 0; j<m; j++)
a[i][j] = in.nextInt();
boolean ans = true;
for(int i = 0; i<n; i++) {
for(int j = 0; j<m; j++) {
int total = 0;
if(i-1>=0) total++;
if(j-1>=0) total++;
if(i+1<n) total++;
if(j+1<m) total++;
if(a[i][j]>total) {
System.out.println("NO");
ans = false;
break;
}else {
a[i][j] = total;
}
}
if(!ans) break;
}
if(ans) {
System.out.println("YES");
for(int i = 0; i<n; i++) {
for(int j = 0; j<m; j++) {
System.out.print(a[i][j]+" ");
}
System.out.println();
}
}
}
}
private static int gcd(int a, int b) {
if(b==0) return a;
return gcd(b, a%b);
}
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 | ["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"] | 1 second | ["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"] | NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 8afcdfaabba66fb9cefc5b6ceabac0d0 | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$) Β β the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$) Β β the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$. | 1,200 | If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them. | standard output | |
PASSED | bf28c6b3e9dd0fcb776a2588b0bc62d8 | train_003.jsonl | 1593873900 | You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k > 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge. | 256 megabytes | import java.util.*;
import java.io.*;
public class B {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0) {
int n = sc.nextInt();
int m = sc.nextInt();
int[][] a = new int[n][m];
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
a[i][j] = sc.nextInt();
}
}
boolean good = true;
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
int numneighbors = 0;
if(i != 0) {
numneighbors++; //left side
}
if(i != n - 1) {
numneighbors++; //right side
}
if(j != 0) {
numneighbors++; //top side
}
if(j != m - 1) {
numneighbors++; //botside
}
if(a[i][j] > numneighbors) {
good = false;
}
a[i][j] = numneighbors;
}
}
if(good) {
System.out.println("YES");
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
System.out.print(a[i][j] + " ");
}
System.out.println();
}
} else {
System.out.println("NO");
}
}
}
}
| Java | ["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"] | 1 second | ["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"] | NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 8afcdfaabba66fb9cefc5b6ceabac0d0 | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$) Β β the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$) Β β the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$. | 1,200 | If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them. | standard output | |
PASSED | 427394830b5f38588a8403e58d8fd127 | train_003.jsonl | 1593873900 | You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k > 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge. | 256 megabytes | import java.util.*;
public class bgr9{
public static void main(String args[]){
Scanner s = new Scanner(System.in);
int t = s.nextInt();
while(t-->0){
int n = s.nextInt();
int m = s.nextInt();
int arr[][] = new int[n][m];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
arr[i][j] = s.nextInt();
}
}
if(!chk(arr)){
System.out.println("NO");
}else{
System.out.println("YES");
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(i==0||j==0||i==n-1||j==m-1){
if(i==0&&j==0||i==0&&j==m-1||i==n-1&&j==0||i==n-1&&j==m-1){
arr[i][j] = 2;
}else
arr[i][j] = 3;
}else{
arr[i][j] = 4;
}
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
System.out.print(arr[i][j]+" ");
}
System.out.println();
}
}
}
}
public static boolean chk(int arr[][]){
for(int i=0;i<arr.length;i++){
for(int j=0;j<arr[0].length;j++){
if(!safe(arr,i,j)){
return false;
}
}
}
return true;
}
public static boolean safe(int arr[][], int x, int y){
int num = arr[x][y];
int mx[] = {1,0,-1,0};
int my[] = {0,-1,0,1};
int count = 0;
for(int i=0;i<4;i++){
int fi = mx[i]+x;
int fj = my[i]+y;
if(fi>=0&&fj>=0&&fi<arr.length&&fj<arr[0].length){
count++;
}
}
if(count<num){
return false;
}else{
return true;
}
}
} | Java | ["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"] | 1 second | ["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"] | NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 8afcdfaabba66fb9cefc5b6ceabac0d0 | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$) Β β the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$) Β β the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$. | 1,200 | If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them. | standard output | |
PASSED | 835652b7a0908650ee13583a4e6594a7 | train_003.jsonl | 1593873900 | You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k > 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
Problem problem = new Problem();
problem.solve();
}
}
class Problem {
private final Parser parser = new Parser();
void solve() {
int t = parser.parseInt();
for (int i = 0; i < t; i++) {
solve(i);
}
}
void solve(int testCase) {
int n = parser.parseInt();
int m = parser.parseInt();
int[][] arr = new int[n][m];
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
arr[i][j] = parser.parseInt();
}
}
StringBuilder sb = new StringBuilder();
sb.append("YES\n");
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
int cnt = 0;
if(i - 1 >= 0) {
cnt += 1;
}
if(i + 1 < n) {
cnt += 1;
}
if(j - 1 >= 0) {
cnt += 1;
}
if(j + 1 < m) {
cnt += 1;
}
if(arr[i][j] > cnt) {
System.out.println("NO");
return;
}
sb.append(cnt);
sb.append(" ");
}
sb.append("\n");
}
System.out.print(sb.toString());
}
}
class Parser {
private final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
private final Iterator<String> stringIterator = br.lines().iterator();
private final Deque<String> inputs = new ArrayDeque<>();
void fill() {
if (inputs.isEmpty()) {
if (!stringIterator.hasNext()) throw new NoSuchElementException();
inputs.addAll(Arrays.asList(stringIterator.next().split(" ")));
}
}
Integer parseInt() {
fill();
if (!inputs.isEmpty()) {
return Integer.parseInt(inputs.pollFirst());
}
throw new NoSuchElementException();
}
Long parseLong() {
fill();
if (!inputs.isEmpty()) {
return Long.parseLong(inputs.pollFirst());
}
throw new NoSuchElementException();
}
Double parseDouble() {
fill();
if (!inputs.isEmpty()) {
return Double.parseDouble(inputs.pollFirst());
}
throw new NoSuchElementException();
}
String parseString() {
fill();
return inputs.removeFirst();
}
} | Java | ["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"] | 1 second | ["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"] | NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 8afcdfaabba66fb9cefc5b6ceabac0d0 | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$) Β β the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$) Β β the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$. | 1,200 | If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them. | standard output | |
PASSED | e504ba3657fc6a4555a7a4c79e42ca91 | train_003.jsonl | 1593873900 | You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k > 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge. | 256 megabytes | import java.util.*;
public class Problem1375b {
static int n,m;
static int[][] a;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
n = sc.nextInt();
m = sc.nextInt();
a = new int[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
a[i][j] = sc.nextInt();
}
}
mine();
}
}
public static void mine() {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
int c = 0;
if (i > 0) c++;
if (j > 0) c++;
if (i < n - 1) c++;
if (j < m - 1) c++;
if (a[i][j] > c) {
System.out.println("NO");
return;
}
else {
a[i][j] = c;
}
}
}
System.out.println("YES");
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++)
System.out.print(a[i][j] + " ");
System.out.println();
}
}
} | Java | ["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"] | 1 second | ["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"] | NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 8afcdfaabba66fb9cefc5b6ceabac0d0 | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$) Β β the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$) Β β the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$. | 1,200 | If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them. | standard output | |
PASSED | 07ed1883d4839ce39f84e7273f26e4bc | train_003.jsonl | 1593873900 | You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k > 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge. | 256 megabytes | //package test;
import java.io.*;
import java.util.*;
public class Grid {
static class FastReader
{
BufferedReader br;
public FastReader()
{
br = new BufferedReader(new InputStreamReader(System.in));
}
int nextInt() throws IOException
{
return Integer.parseInt(br.readLine());
}
int[] getArray(int n) throws IOException
{
int a[] = new int[n];
String line = br.readLine(); // to read multiple integers line
String[] strs = line.trim().split(" ");
for (int i = 0; i < n; i++) {
a[i] = Integer.parseInt(strs[i]);
}
return a;
}
}
public static void main(String[] args) throws IOException
{
FastReader sc=new FastReader();
int t=sc.nextInt();
for(int k=0;k<t;k++)
{
int[] arr=sc.getArray(2);
int row=arr[0];
int col=arr[1];
int x[][]=new int[row][col];
for(int i=0;i<row;i++)
{
int[] temp=sc.getArray(col);
for(int j=0;j<col;j++)
{
x[i][j]=temp[j];
}
}
int flag=0;
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
if((i==0&&j==0)||(i==0&&j==col-1)||(i==row-1&&j==0)||(i==row-1&&j==col-1))
{
if(x[i][j]>2)
{
flag=-1;
break;
}
else
x[i][j]=2;
}
else if(i==0||j==0||i==row-1||j==col-1)
{
if(x[i][j]>3)
{
flag=-1;
break;
}
else
x[i][j]=3;
}
else
{
if(x[i][j]>4)
{
flag=-1;
break;
}
else
x[i][j]=4;
}
}
}
if(flag==0)
{
System.out.println("YES");
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
System.out.print(x[i][j]+" ");
}
System.out.println();
}
}
else
System.out.println("NO");
}
}
}
| Java | ["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"] | 1 second | ["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"] | NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 8afcdfaabba66fb9cefc5b6ceabac0d0 | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$) Β β the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$) Β β the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$. | 1,200 | If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them. | standard output | |
PASSED | 22cf8840613eb3831efc8b4378ad09fb | train_003.jsonl | 1593873900 | You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k > 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge. | 256 megabytes | import java.util.*;
public class Main {
private static boolean go(int n, int m, int[][] p) {
if (p[0][0] > 2) return false;
if (p[n-1][0] > 2) return false;
if (p[0][m-1] > 2) return false;
if (p[n-1][m-1] > 2) return false;
for (int i = 0; i < n; ++i) {
if (p[i][0] > 3) return false;
if (p[i][m-1] > 3) return false;
}
for (int i = 0; i < m; ++i) {
if (p[0][i] > 3) return false;
if (p[n-1][i] > 3) return false;
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (p[i][j] > 4) return false;
}
}
return true;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for (int i = 0; i < T; ++i) {
int n = sc.nextInt();
int m = sc.nextInt();
int[][] p = new int[n][m];
for (int j = 0; j < n; ++j) {
for (int k = 0; k < m; ++k) {
p[j][k] = sc.nextInt();
}
}
if (go(n, m, p)) {
System.out.println("YES");
for (int j = 0; j < n; ++j) {
for (int k = 0; k < m; ++k) {
int v = 0;
if (j == 0 && k == 0) v = 2;
else if (j == 0 && k == m-1) v = 2;
else if (j == n-1 && k == 0) v = 2;
else if (j == n-1 && k == m-1) v = 2;
else if (j == 0) v = 3;
else if (j == n-1) v = 3;
else if (k == 0) v = 3;
else if (k == m-1) v = 3;
else v = 4;
System.out.print(v + " ");
}
System.out.println();
}
} else {
System.out.println("NO");
}
}
}
} | Java | ["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"] | 1 second | ["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"] | NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 8afcdfaabba66fb9cefc5b6ceabac0d0 | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$) Β β the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$) Β β the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$. | 1,200 | If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them. | standard output | |
PASSED | 408140d88dcb560d4df8532c0059ff8d | train_003.jsonl | 1593873900 | You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k > 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class code {
public static void main(String[] args)throws IOException {
FastReader sc = new FastReader();
PrintWriter pw = new PrintWriter(System.out);
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
int m = sc.nextInt();
long arr[][] = new long[n][m];
boolean flag = true;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
arr[i][j] = sc.nextLong();
if ((i == 0 && j == 0) || (i == 0 && j == m - 1) || (i == n - 1 && j == 0) || (i == n - 1 && j == m - 1)) {
if (arr[i][j] > 2)
flag = false;
} else if (i == 0 || j == 0 || i == n - 1 || j == m - 1) {
if (arr[i][j] > 3)
flag = false;
} else {
if (arr[i][j] > 4)
flag = false;
}
}
}
if (!flag) {
System.out.println("NO");
continue;
}
System.out.println("YES");
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if ((i == 0 && j == 0) || (i == 0 && j == m - 1) || (i == n - 1 && j == 0) || (i == n - 1 && j == m - 1)) {
System.out.print(2 + " ");
} else if (i == 0 || j == 0 || i == n - 1 || j == m - 1) {
System.out.print(3 + " ");
} else
System.out.print(4 + " ");
}
System.out.println();
}
}
}
}
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 | ["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"] | 1 second | ["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"] | NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 8afcdfaabba66fb9cefc5b6ceabac0d0 | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$) Β β the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$) Β β the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$. | 1,200 | If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them. | standard output | |
PASSED | cc1c9b88915249daada5e605b1db077e | train_003.jsonl | 1593873900 | You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k > 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge. | 256 megabytes |
import java.util.*;
public class neighbor_grid {
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t>0){
t-=1;
int n=sc.nextInt(); int m=sc.nextInt();
int checker=0; int arr[][]=new int[n][m];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
arr[i][j]=sc.nextInt();
if(i==0 || i==n-1){
if(j==0 || j==m-1){
if(arr[i][j]>2) checker=1;
else arr[i][j]=2;
}
else{
if(arr[i][j]>3) checker=1;
else arr[i][j]=3;
}
}
else{
if(j==0 || j==m-1){
if(arr[i][j]>3) checker=1;
else arr[i][j]=3;
}
else{
if(arr[i][j]>4) checker=1;
else arr[i][j]=4;
}
}
}
}
if(checker==1) System.out.println("NO");
else{
System.out.println("YES");
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
System.out.print(arr[i][j]+" ");
}
System.out.println();
}
}
}
}
} | Java | ["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"] | 1 second | ["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"] | NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 8afcdfaabba66fb9cefc5b6ceabac0d0 | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$) Β β the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$) Β β the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$. | 1,200 | If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them. | standard output | |
PASSED | a92c3e4aaa920e9df7497f9eb31a5968 | train_003.jsonl | 1593873900 | You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k > 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge. | 256 megabytes |
//package cf;
import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
public class gcd {
static int p=1000000007;
public static void main(String[] args) throws Exception{
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out), "ASCII"), 512);
FastReader sc=new FastReader();
long t= sc.nextLong();
StringBuilder sb=new StringBuilder();
while(t-->0)
{
int n=sc.nextInt();
int m=sc.nextInt();
int ar[][]=new int[n][m];
boolean f=true;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
int x=4;
int te=sc.nextInt();
if(i==0||i==n-1)
x--;
if(j==0||j==m-1)
x--;
if(te>x)
{
f=false;
}
ar[i][j]=x;
}
}
if(f) {
sb.append("YES\n");
for (int i = 0; i < n && f; i++) {
for (int j = 0; j < m && f; j++) {
sb.append(ar[i][j]+" ");
}
sb.append("\n");
}
}
else
{
sb.append("NO\n");
}
//System.out.println(t+" "+e);
//System.out.println(t+" "+o);
}
out.write(sb.toString());
out.flush();
}
///////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
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 | ["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"] | 1 second | ["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"] | NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 8afcdfaabba66fb9cefc5b6ceabac0d0 | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$) Β β the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$) Β β the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$. | 1,200 | If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them. | standard output | |
PASSED | f97ac66dada371b79f030bc2ac6147ac | train_003.jsonl | 1593873900 | You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k > 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
FastReader f = new FastReader();
int t = f.nextInt();
while(t-- > 0) {
int n = f.nextInt();
int m = f.nextInt();
int[][] arr = new int[n][m];
for(int i=0;i<n;i++) {
for(int j=0;j<m;j++) {
arr[i][j] = f.nextInt();
}
}
if(arr[0][0] > 2 || arr[n-1][m-1] > 2 || arr[n-1][0] > 2 || arr[0][m-1] > 2) {
System.out.println("NO");
continue;
}
arr[0][0] = 2;
arr[n-1][m-1] = 2;
arr[n-1][0] = 2;
arr[0][m-1] = 2;
boolean end = false;
for(int i=1;i<n-1;i++) {
if(arr[i][0] > 3 || arr[i][m-1] > 3) {
end = true;
break;
}
arr[i][0] = 3;
arr[i][m-1] = 3;
}
if(end) {
System.out.println("NO");
continue;
}
for(int i=1;i<m-1;i++) {
if(arr[0][i] > 3 || arr[n-1][i] > 3) {
end = true;
break;
}
arr[0][i] = 3;
arr[n-1][i] = 3;
}
if(end) {
System.out.println("NO");
continue;
}
for(int i=1;i<n-1;i++) {
for(int j=1;j<m-1;j++) {
if(arr[i][j] > 4) {
end = true;
break;
}
arr[i][j] = 4;
}
if(end) {
break;
}
}
if(end) {
System.out.println("NO");
continue;
}
System.out.println("YES");
StringBuilder sb = new StringBuilder();
for(int i=0;i<n;i++) {
for(int j=0;j<m;j++) {
sb.append(arr[i][j]);
sb.append(' ');
}
System.out.println(sb.toString());
sb = new StringBuilder();
}
}
}
//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 | ["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"] | 1 second | ["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"] | NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 8afcdfaabba66fb9cefc5b6ceabac0d0 | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$) Β β the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$) Β β the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$. | 1,200 | If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them. | standard output | |
PASSED | 62fe9433e347adb414b123dcc2067604 | train_003.jsonl | 1593873900 | You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k > 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int test=0;test<t;test++)
{
int a=sc.nextInt();
int b=sc.nextInt();
int sol[][]=new int[a][b];
boolean flag=false;
for(int i=0;i<a;i++){
for(int j=0;j<b;j++){
sol[i][j]=sc.nextInt();
if(sol[i][j]>4)
{
flag=true;
}
if(i==0||j==0||i==a-1||j==b-1)
{
if(sol[i][j]>3)
flag=true;
}
if((i==0&&j==0)||(i==0&&j==b-1)||(i==a-1&&j==0)||(i==a-1&&j==b-1))
{
if(sol[i][j]>2)
flag=true;
}
}}
if(flag==true)
{
System.out.println("NO");
continue;
}
for(int i=0;i<a;i++){
for(int j=0;j<b;j++){
sol[i][j]=4;
if(i==0||j==0||i==a-1||j==b-1)
{
sol[i][j]=3;
}
if((i==0&&j==0)||(i==0&&j==b-1)||(i==a-1&&j==0)||(i==a-1&&j==b-1))
{
sol[i][j]=2;
}
}}
System.out.println("YES");
for(int i=0;i<a;i++){
for(int j=0;j<b;j++){
System.out.print(sol[i][j]+" ");
}
System.out.println();
}
}
}
}
| Java | ["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"] | 1 second | ["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"] | NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 8afcdfaabba66fb9cefc5b6ceabac0d0 | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$) Β β the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$) Β β the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$. | 1,200 | If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them. | standard output | |
PASSED | 2ebcd6689af4b275c3f0546437302437 | train_003.jsonl | 1593873900 | You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k > 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge. | 256 megabytes | /* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(input.readLine());
for(int i=0;i<t;i++) {
String[] rc = input.readLine().split(" ");
int r = Integer.parseInt(rc[0]);
int c = Integer.parseInt(rc[1]);
ArrayList<String[]> grid = new ArrayList<String[]>();
for(int j=0;j<r;j++) {
String[] row = input.readLine().split(" ");
grid.add(row);
}
int[][] x = new int[r][c];
x[0][0] = x[0][c-1]=x[r-1][0] = x[r-1][c-1] = 2;
for(int j=1;j<r-1;j++) {
x[j][0] = 3;
x[j][c-1] = 3;
}
for(int j=1;j<c-1;j++) {
x[0][j] = x[r-1][j] = 3;
}
for(int j=1;j<r-1;j++) {
for(int k=1;k<c-1;k++) {
x[j][k] = 4;
}
}
boolean res = true;
for(int j=0;j<r;j++) {
for(int k=0;k<c;k++) {
if(Integer.parseInt(grid.get(j)[k])>x[j][k]) {
res = false;
}
}
}
if(res==false) {
System.out.println("NO");
}else {
System.out.println("YES");
for(int j=0;j<r;j++) {
for(int k=0;k<c;k++) {
System.out.print(x[j][k]+" ");
}
System.out.println();
}
}
}
}
} | Java | ["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"] | 1 second | ["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"] | NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 8afcdfaabba66fb9cefc5b6ceabac0d0 | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$) Β β the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$) Β β the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$. | 1,200 | If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them. | standard output | |
PASSED | bfafa871d2a817c2b8c4b74468291bda | train_003.jsonl | 1593873900 | You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k > 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge. | 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.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
import javax.sound.sampled.ReverbType;
import java.util.*;
import java.io.*;
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 d;
int s;
public Pair(int b, int l) {
d = b;
s = l;
}
@Override
public int compareTo(Pair o) {
if (o.d - o.s > this.d - this.s) {
return 1;
} else if (o.d - o.s < this.d - this.s) {
return -1;
} else
return 0;
}
}
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 int c;
static int d[];
static int z;
static Pair p[];
static int R;
static int C;
static int K;
static long grid[][];
public static void main(String args[]) throws Exception {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int t=sc.nextInt();
label:while(t-->0) {
int n=sc.nextInt();
int m=sc.nextInt();
int grid[][]=new int[n][m];
for (int i = 0; i < grid.length; i++) {
for (int j = 0; j < m; j++) {
grid[i][j]=sc.nextInt();
}
}
for (int i = 0; i < grid.length; i++) {
for (int j = 0; j < m; j++) {
if(grid[i][j]>4) {
System.out.println("NO");
continue label;
}
if((i==0||i==n-1)&&(j==0||j==m-1)) {
if(grid[i][j]>2) {
System.out.println("NO");
continue label;
}
grid[i][j]=2;
}
else if(i==0||i==n-1||j==0||j==m-1) {
if(grid[i][j]>3) {
System.out.println("NO");
continue label;
}
grid[i][j]=3;
}
else {
grid[i][j]=4;
}
}
}
System.out.println("YES");
for (int i = 0; i < grid.length; i++) {
for (int j = 0; j <m; j++) {
System.out.print(grid[i][j]+" ");
}
System.out.println();
}
}
}
static ArrayList<Integer> euler=new ArrayList<>();
static long dp(int i,int j,int count) {
if(i==R-1&&j==C-1) {
if(count<3) {
return grid[i][j];
}
else
return 0;
}
else if(i>=R||j>=C) {
return -INF;
}
if(memo[i][j][count]!=-1) {
return memo[i][j][count];
}
long ans=0;
ans=Math.max(ans,dp(i+1,j,0));
ans=Math.max(ans,dp(i,j+1,count));
if(count<3) {
ans=Math.max(ans,dp(i+1,j,0)+grid[i][j]);
ans=Math.max(ans,dp(i,j+1,count+1)+grid[i][j]);
}
return memo[i][j][count]=ans;
}
static ArrayList<Integer> arr;
static long total[];
static TreeMap<Integer,Integer> map1;
static int zz;
//static int dp(int idx,int left,int state) {
//if(idx>=k-((zz-left)*2)||idx+1==n) {
// return 0;
//}
//if(memo[idx][left][state]!=-1) {
// return memo[idx][left][state];
//}
//int ans=a[idx+1]+dp(idx+1,left,0);
//if(left>0&&state==0&&idx>0) {
// ans=Math.max(ans,a[idx-1]+dp(idx-1,left-1,1));
//}
//return memo[idx][left][state]=ans;
//}21
static HashMap<Integer,Integer> map;
static int maxa=0;
static int ff=123123;
static long dist[][];
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;
}
} | Java | ["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"] | 1 second | ["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"] | NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 8afcdfaabba66fb9cefc5b6ceabac0d0 | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$) Β β the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$) Β β the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$. | 1,200 | If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them. | standard output | |
PASSED | c394ce4231466bde6fa624969c0639b4 | train_003.jsonl | 1593873900 | You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k > 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge. | 256 megabytes | import java.util.Scanner;
public class Main7 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while (t-->0)
{
int rows=sc.nextInt();
int col=sc.nextInt();
int arr[][]=new int[rows][col];
for(int i=0;i<rows;i++)
for(int j=0;j<col;j++)
arr[i][j]=sc.nextInt();
boolean con=false;
if(arr[0][0]>2 || arr[rows-1][0]>2)con=true;
else if(arr[0][col-1]>2 || arr[rows-1][col-1]>2) con=true;
for(int i=1;i<rows-1;i++) {if(arr[i][0]>3 || arr[i][col-1]>3){con=true; break;}}
if(con!=true)
for(int j=1;j<col;j++) {if(arr[0][j]>3 || arr[rows-1][j]>3) {con=true; break;}}
if(con==true) System.out.println("NO");
else
{
arr[0][0]=2;
arr[rows-1][0]=2;
arr[0][col-1]=2;
arr[rows-1][col-1]=2;
for(int i=1;i<rows-1;i++)
{
arr[i][0]=3;
arr[i][col-1]=3;
}
for(int j=1;j<col-1;j++)
{
arr[0][j]=3;
arr[rows-1][j]=3;
}
for(int i=1;i<rows-1;i++)
{
for(int j=1;j<col-1;j++)
{
if(arr[i][j]>4)
{
con=true;
break;
}
else arr[i][j]=4;
}
if(con==true)break;
}
if(con==true) System.out.println("NO");
}
if(con==false)
{
System.out.println("YES");
for(int i=0;i<rows;i++)
{
for(int j=0;j<col;j++)
{
System.out.print(arr[i][j]+" ");
}
System.out.println();
}
}
}
}
}
| Java | ["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"] | 1 second | ["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"] | NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 8afcdfaabba66fb9cefc5b6ceabac0d0 | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$) Β β the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$) Β β the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$. | 1,200 | If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them. | standard output | |
PASSED | 1e4f56245f6958d5e53ad8aa0f1bcab7 | train_003.jsonl | 1593873900 | You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k > 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge. | 256 megabytes |
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
public final class B {
public static void main(String[] args) {
final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
final int t = Integer.parseInt(in.nextLine());
for (int x = 0; x < t; x++) {
final String[] str = in.nextLine().split(" ");
final int n = Integer.parseInt(str[0]);
final int m = Integer.parseInt(str[1]);
boolean canDo = true;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
final int curr = in.nextInt();
final int resCell = getResCell(n, m, i, j);
if (curr > resCell) {
canDo = false;
}
}
in.nextLine();
}
if (canDo) {
System.out.println("YES");
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
System.out.print(getResCell(n, m, i, j) + " ");
}
System.out.println();
}
} else {
System.out.println("NO");
}
}
}
private static int getResCell(int n, int m, int i, int j) {
int resCell = 2;
if (i > 0 && i < n - 1) {
resCell++;
}
if (j > 0 && j < m - 1) {
resCell++;
}
return resCell;
}
}
| Java | ["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"] | 1 second | ["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"] | NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 8afcdfaabba66fb9cefc5b6ceabac0d0 | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$) Β β the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$) Β β the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$. | 1,200 | If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them. | standard output | |
PASSED | dd37d4267624a4d0ee94fa5665a4e3cf | train_003.jsonl | 1593873900 | You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k > 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
static Scanner sc = new Scanner(System.in);
static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) throws Exception {
int t = sc.nextInt();
while(t-- > 0) {
int n = sc.nextInt(), m = sc.nextInt();
int arr[][] = new int[n][m];
boolean flag = true;
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
arr[i][j] = sc.nextInt();
int cnt = i == 0 || i == n - 1 ? 1 : 0;
cnt += j == 0 || j == m - 1 ? 1 : 0;
if(cnt == 2) {
arr[i][j] = Math.max(arr[i][j],2);
if(arr[i][j] > 2) flag = false;
}else if(cnt == 0){
arr[i][j] = Math.max(arr[i][j], 4);
if(arr[i][j] > 4) flag = false;
}else {
arr[i][j] = Math.max(arr[i][j],3);
if(arr[i][j] > 3) flag = false;
}
}
}
if(flag) {
out.println("YES");
for(int i = 0; i < n; i++) {
for(int x : arr[i]) {
out.print(x + " ");
}
out.println();
}
}else {
out.println("NO");
}
}
out.close();
}
}
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 Long nextLong() throws IOException {
return Long.parseLong(next());
}
} | Java | ["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"] | 1 second | ["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"] | NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 8afcdfaabba66fb9cefc5b6ceabac0d0 | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$) Β β the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$) Β β the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$. | 1,200 | If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them. | standard output | |
PASSED | c9ae58f4d07696c38897d34cb011053c | train_003.jsonl | 1593873900 | You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k > 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge. | 256 megabytes | import java.util.*;
public class solution
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
int m=sc.nextInt();
int[][] a=new int[n][m];
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
a[i][j]=sc.nextInt();
}
}
solve(a,n,m);
}
}
static void solve(int[][] a,int n,int m)
{
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
int total=0;
if(i-1>=0)
{
total++;
}
if(i+1<n)
{
total++;
}
if(j-1>=0)
{
total++;
}
if(j+1<m)
{
total++;
}
if(a[i][j]>total)
{
System.out.println("NO");
return;
}
a[i][j]=total;
}
}
System.out.println("YES");
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
System.out.print(a[i][j]+" ");
}
System.out.println();
}
}
} | Java | ["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"] | 1 second | ["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"] | NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 8afcdfaabba66fb9cefc5b6ceabac0d0 | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$) Β β the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$) Β β the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$. | 1,200 | If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them. | standard output | |
PASSED | 931d3092b0428d37a85917127228b372 | train_003.jsonl | 1593873900 | You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k > 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
/* Name of the class has to be "Main" only if the class is public.
By : SSD
*/
public class NeibhourGrid {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args) throws Exception {
FastReader sc = new FastReader();
StringBuilder res = new StringBuilder();
int t = sc.nextInt();
while (t-- > 0) {
boolean possible=true;
int n=sc.nextInt();
int m=sc.nextInt();
int a[][]=new int [n][m];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++)
{
int count=0;
a[i][j]=sc.nextInt();
if(i-1>=0)
count++;
if(i+1<n)
count++;
if(j-1>=0)
count++;
if(j+1<m)
count++;
if(possible&&a[i][j]<=count)
a[i][j]=count;
else
possible=false;
}
}
if (!possible)
res.append("No\n");
else
{
res.append("Yes\n");
for (int i = 0; i <n ; i++) {
for (int j = 0; j <m ; j++) {
res.append(a[i][j]+" ");
}
res.append("\n");
}
}
}
System.out.println(res);
}
}
| Java | ["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"] | 1 second | ["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"] | NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 8afcdfaabba66fb9cefc5b6ceabac0d0 | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$) Β β the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$) Β β the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$. | 1,200 | If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them. | standard output | |
PASSED | 8406c6f933db89131e90ee6543cd92aa | train_003.jsonl | 1593873900 | You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k > 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge. | 256 megabytes | import java.util.*;
import java.io.*;
public class Template {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
int test = sc.nextInt();
while(test-->0) {
int m = sc.nextInt();
int n = sc.nextInt();
int[][] a = new int[m][n];
for(int i=0 ; i<m ; i++) {
for(int j=0 ; j<n ; j++) {
a[i][j] = sc.nextInt();
}
}
boolean impossible = false;
for(int i=0 ; i<m ; i++) {
for(int j=0 ; j<n ; j++) {
int max = 4;
if(j+1==n || j==0) {
if(i+1==m || i==0) max--;
max--;
}else if(i+1==m || i==0) max--;
if(a[i][j]>max) {
impossible = true;
break;
}
a[i][j] = max;
}if(impossible) break;
}
if(impossible) System.out.println("NO");
else {
System.out.println("YES");
for(int i=0 ; i<m ; i++) {
for(int j=0 ; j<n ; j++) {
System.out.print(a[i][j] + " ");
}System.out.println();
}
}
}
}
} | Java | ["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"] | 1 second | ["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"] | NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 8afcdfaabba66fb9cefc5b6ceabac0d0 | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$) Β β the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$) Β β the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$. | 1,200 | If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them. | standard output | |
PASSED | 6618e946be0cc30ba49b3e9715515bde | train_003.jsonl | 1593873900 | You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k > 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge. | 256 megabytes | import java.io.*;
import java.util.*;
public class Question2 {
static Reader sc = new Reader();
public static void main(String[] args) throws IOException{
int t = sc.nextInt();
while(t-->0) {
solve();
}
}
public static void solve() throws IOException{
int n = sc.nextInt();
int m = sc.nextInt();
int[][] arr = new int[n][m];
for(int i = 0;i < n;i++)Arrays.fill(arr[i], 4);
for(int i = 0;i < n;i++) {
arr[i][0] = 3;
arr[i][m-1] = 3;
}
for(int j = 0;j < m;j++) {
arr[0][j] = 3;
arr[n-1][j] = 3;
}
arr[0][0] = 2;
arr[0][m-1] = 2;
arr[n-1][0] = 2;
arr[n-1][m-1] = 2;
boolean flag = false;
for(int i = 0;i < n;i++) {
for(int j = 0;j < m;j++) {
if(arr[i][j] < sc.nextInt()) {
flag = true;
}
}
}
if(flag) {
System.out.println("NO");
return;
}
System.out.println("YES");
for(int i = 0;i < n;i++) {
for(int j = 0;j< m;j++) {
System.out.print(arr[i][j] + " ");
}System.out.println();
}
}
static class Reader
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1)
{
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.')
{
while ((c = read()) >= '0' && c <= '9')
{
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
}
| Java | ["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"] | 1 second | ["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"] | NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 8afcdfaabba66fb9cefc5b6ceabac0d0 | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$) Β β the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$) Β β the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$. | 1,200 | If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them. | standard output | |
PASSED | 5cf474b66f9b85ee438cd7b7ec86a60d | train_003.jsonl | 1593873900 | You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k > 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge. | 256 megabytes | import java.io.*;
import java.util.*;
public class Question2 {
static Reader sc = new Reader();
public static void main(String[] args) throws IOException{
int t = sc.nextInt();
while(t-->0) {
solve();
}
}
public static void solve() throws IOException{
int n = sc.nextInt();
int m = sc.nextInt();
int[][] arr = new int[n][m];
for(int i = 0;i < n;i++){
for(int j = 0;j < m;j++)
arr[i][j] = 4;
}
for(int i = 0;i < n;i++) {
arr[i][0] = 3;
arr[i][m-1] = 3;
}
for(int i = 0;i < m;i++) {
arr[0][i] = 3;
arr[n-1][i] = 3;
}
arr[0][0] = 2;
arr[0][m-1] = 2;
arr[n-1][0] = 2;
arr[n-1][m-1] = 2;
boolean flag = false;
for(int i = 0;i < n;i++) {
for(int j = 0;j < m;j++) {
int temp = sc.nextInt();
if(temp > arr[i][j])flag = true;
}
}
if(flag) {
System.out.println("NO");
return;
}
System.out.println("YES");
for(int i = 0;i < n;i++) {
for(int j = 0;j < m;j++) {
System.out.print(arr[i][j] + " ");
}System.out.println();
}
}
static class Reader
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1)
{
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.')
{
while ((c = read()) >= '0' && c <= '9')
{
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
}
| Java | ["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"] | 1 second | ["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"] | NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 8afcdfaabba66fb9cefc5b6ceabac0d0 | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$) Β β the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$) Β β the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$. | 1,200 | If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them. | standard output | |
PASSED | 27d8da8a4914a0d7594b87447e9f50a1 | train_003.jsonl | 1593873900 | You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k > 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge. | 256 megabytes | import java.io.*;
import java.util.*;
public class Question2 {
static Reader sc = new Reader();
public static void main(String[] args) throws IOException{
int t = sc.nextInt();
while(t-->0) {
solve();
}
}
public static void solve() throws IOException{
int n = sc.nextInt();
int m = sc.nextInt();
int[][] arr = new int[n][m];
boolean flag = false;
for(int i = 0;i < n;i++) {
for(int j = 0;j < m;j++) {
int temp = sc.nextInt();
arr[i][j] = 4;
if(temp > 4)flag = true;
if((i == 0 || i == n-1)) {
if(temp > 3)flag = true;
if(j == 0 || j == m-1) {
if(temp > 2)flag = true;
}
}
if(j == 0 || j == m - 1) {
if(temp > 3)flag = true;
}
}
}
if(flag) {
System.out.println("NO");
return;
}
for(int i = 0;i < n;i++) {
arr[i][0] = 3;
arr[i][m-1] = 3;
}
for(int i = 0;i < m;i++) {
arr[0][i] = 3;
arr[n-1][i] = 3;
}
arr[0][0] = 2;
arr[0][m-1] = 2;
arr[n-1][0] = 2;
arr[n-1][m-1] = 2;
System.out.println("YES");
for(int i = 0;i < n;i++) {
for(int j = 0;j < m;j++) {
System.out.print(arr[i][j] + " ");
}System.out.println();
}
}
static class Reader
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1)
{
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.')
{
while ((c = read()) >= '0' && c <= '9')
{
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
}
| Java | ["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"] | 1 second | ["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"] | NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 8afcdfaabba66fb9cefc5b6ceabac0d0 | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$) Β β the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$) Β β the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$. | 1,200 | If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them. | standard output | |
PASSED | 3814b87a9ef32928e42e33248f637205 | train_003.jsonl | 1593873900 | You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k > 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
static Scanner sc = new Scanner(System.in);
static PrintWriter out = new PrintWriter(System.out);
/*
public static void main(String[] args) throws Exception {
int t = 1;
t = sc.nextInt();
while (t-- > 0) {
out.println(" ");
}
*/
public static void main(String[] args) throws Exception {
int t = 1;
t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt(), m = sc.nextInt();
int[][] a = new int[n][m];
int[][] b = new int[n][m];
boolean F = true;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
a[i][j] = sc.nextInt();
int around = 4;
if (i == 0) around--;
if (i == n - 1) around--;
if (j == 0) around--;
if (j == m - 1) around--;
if (a[i][j] > around) {
F = false;
}
b[i][j] = around;
}
if (F==false)
{
out.println("NO");
}
else
{
out.println("YES");
for (int i = 0; i < n; i++) {
for (int x : b[i]) {
out.print(x + " ");
}
out.println("");
}
}
}
out.close();
}
}
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 Long nextLong() throws IOException {
return Long.parseLong(next());
}
} | Java | ["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 0\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0"] | 1 second | ["YES\n0 0 0 0\n0 1 1 0\n0 0 0 0\nNO\nYES\n0 0\n0 0\nNO\nYES\n0 1 0 0\n1 4 2 1\n0 2 0 0\n1 3 1 0"] | NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good. | Java 11 | standard input | [
"constructive algorithms",
"greedy"
] | 8afcdfaabba66fb9cefc5b6ceabac0d0 | The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$) Β β the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$) Β β the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$. | 1,200 | If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them. | standard output | |
PASSED | 4b3a7fc5e8af69421f07fea03d0d8c6d | train_003.jsonl | 1349623800 | A piece of paper contains an array of n integers a1,βa2,β...,βan. Your task is to find a number that occurs the maximum number of times in this array.However, before looking for such number, you are allowed to perform not more than k following operations β choose an arbitrary element from the array and add 1 to it. In other words, you are allowed to increase some array element by 1 no more than k times (you are allowed to increase the same element of the array multiple times).Your task is to find the maximum number of occurrences of some number in the array after performing no more than k allowed operations. If there are several such numbers, your task is to find the minimum one. | 256 megabytes | // Main Code at the Bottom
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.BigInteger;
public class Main {
//Fast IO class
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
boolean env=System.getProperty("ONLINE_JUDGE") != null;
if(!env) {
try {
br=new BufferedReader(new FileReader("src\\input.txt"));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
else br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
static long MOD=1000000000+7;
//debug
static void debug(Object... o) {
System.out.println(Arrays.deepToString(o));
}
// Pair
static class pair{
long x,y;
pair(long a,long b){
this.x=a;
this.y=b;
}
public boolean equals(Object obj) {
if(obj == null || obj.getClass()!= this.getClass()) return false;
pair p = (pair) obj;
return (this.x==p.x && this.y==p.y);
}
public int hashCode() {
return Objects.hash(x,y);
}
}
static FastReader sc=new FastReader();
static PrintWriter out=new PrintWriter(System.out);
//Main function(The main code starts from here)
static int n,k;
static long val=0;
static long a[];
static boolean check(int x) {
long sum=0;
val=a[x-1];
for(int i=0;i<x;i++) sum+=a[i];
if(val*x-sum<=k) return true;
for(int i=x;i<n;i++) {
sum=sum+a[i]-a[i-x];
val=a[i];
if(val*x-sum<=k) return true;
}
return false;
}
public static void main (String[] args) throws java.lang.Exception {
int test=1;
//test=sc.nextInt();
while(test-->0){
n=sc.nextInt();k=sc.nextInt();a=new long[n];
for(int i=0;i<n;i++) a[i]=sc.nextLong();
Arrays.parallelSort(a);
int l=1,r=n,ans=1;
while(l<=r) {
int mid=l+(r-l)/2;
if(check(mid)) {
ans=mid;
l=mid+1;
}
else r=mid-1;
}
check(ans);
out.println(ans+" "+val);
}
out.flush();
out.close();
}
} | Java | ["5 3\n6 3 4 0 2", "3 4\n5 5 5", "5 3\n3 1 2 2 1"] | 2 seconds | ["3 4", "3 5", "4 2"] | NoteIn the first sample your task is to increase the second element of the array once and increase the fifth element of the array twice. Thus, we get sequence 6,β4,β4,β0,β4, where number 4 occurs 3 times.In the second sample you don't need to perform a single operation or increase each element by one. If we do nothing, we get array 5,β5,β5, if we increase each by one, we get 6,β6,β6. In both cases the maximum number of occurrences equals 3. So we should do nothing, as number 5 is less than number 6.In the third sample we should increase the second array element once and the fifth element once. Thus, we get sequence 3,β2,β2,β2,β2, where number 2 occurs 4 times. | Java 11 | standard input | [
"two pointers",
"binary search",
"sortings"
] | 3791d1a504b39eb2e72472bcfd9a7e22 | The first line contains two integers n and k (1ββ€βnββ€β105; 0ββ€βkββ€β109) β the number of elements in the array and the number of operations you are allowed to perform, correspondingly. The third line contains a sequence of n integers a1,βa2,β...,βan (|ai|ββ€β109) β the initial array. The numbers in the lines are separated by single spaces. | 1,600 | In a single line print two numbers β the maximum number of occurrences of some number in the array after at most k allowed operations are performed, and the minimum number that reaches the given maximum. Separate the printed numbers by whitespaces. | standard output | |
PASSED | 363c7f08735e0e3b91a7e42d7ab5ddff | train_003.jsonl | 1349623800 | A piece of paper contains an array of n integers a1,βa2,β...,βan. Your task is to find a number that occurs the maximum number of times in this array.However, before looking for such number, you are allowed to perform not more than k following operations β choose an arbitrary element from the array and add 1 to it. In other words, you are allowed to increase some array element by 1 no more than k times (you are allowed to increase the same element of the array multiple times).Your task is to find the maximum number of occurrences of some number in the array after performing no more than k allowed operations. If there are several such numbers, your task is to find the minimum one. | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.*;
public class Main
{
static int increment_to(long x, int idx, long k, long pref[]){
int l = 1, r = idx, res = 0, mid, cnt = 0;
long sum = 0l;
while(l <= r){
mid = l + (r - l)/2;
sum = pref[idx] - pref[mid - 1];
cnt = idx - mid + 1;
if((cnt * 1l) * x - sum <= k){
res = cnt;
r = mid - 1;
}
else
l = mid + 1;
}
return res;
}
public static void process(int test_number)throws IOException
{
int n = ni(), res = 0;
long k = nl(), pref[] = new long[n + 1], arr[] = new long[n + 1], take = 0l;
for(int i = 1; i <= n; i++)
arr[i] = ni();
Arrays.sort(arr, 1, n + 1);
for(int i = 1; i <= n; i++){
pref[i] = pref[i - 1] + arr[i];
}
for(int i = 1; i <= n; i++){
int x = increment_to(arr[i], i, k, pref);
if(x > res){
res = x;
take = arr[i];
}
}
pn(res + " " + take);
}
static final long mod = (long)1e9+7l;
static FastReader sc;
static PrintWriter out;
public static void main(String[]args)throws IOException
{
out = new PrintWriter(System.out);
sc = new FastReader();
long s = System.currentTimeMillis();
int t = 1;
//t = ni();
for(int i = 1; i <= t; i++)
process(i);
out.flush();
System.err.println(System.currentTimeMillis()-s+"ms");
}
static void trace(Object... o){ System.err.println(Arrays.deepToString(o)); };
static void pn(Object o){ out.println(o); }
static void p(Object o){ out.print(o); }
static int ni()throws IOException{ return Integer.parseInt(sc.next()); }
static long nl()throws IOException{ return Long.parseLong(sc.next()); }
static double nd()throws IOException{ return Double.parseDouble(sc.next()); }
static String nln()throws IOException{ return sc.nextLine(); }
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 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();
}
String nextLine(){
String str = "";
try{ str = br.readLine(); } catch (IOException e) { e.printStackTrace(); }
return str;
}
}
}
| Java | ["5 3\n6 3 4 0 2", "3 4\n5 5 5", "5 3\n3 1 2 2 1"] | 2 seconds | ["3 4", "3 5", "4 2"] | NoteIn the first sample your task is to increase the second element of the array once and increase the fifth element of the array twice. Thus, we get sequence 6,β4,β4,β0,β4, where number 4 occurs 3 times.In the second sample you don't need to perform a single operation or increase each element by one. If we do nothing, we get array 5,β5,β5, if we increase each by one, we get 6,β6,β6. In both cases the maximum number of occurrences equals 3. So we should do nothing, as number 5 is less than number 6.In the third sample we should increase the second array element once and the fifth element once. Thus, we get sequence 3,β2,β2,β2,β2, where number 2 occurs 4 times. | Java 11 | standard input | [
"two pointers",
"binary search",
"sortings"
] | 3791d1a504b39eb2e72472bcfd9a7e22 | The first line contains two integers n and k (1ββ€βnββ€β105; 0ββ€βkββ€β109) β the number of elements in the array and the number of operations you are allowed to perform, correspondingly. The third line contains a sequence of n integers a1,βa2,β...,βan (|ai|ββ€β109) β the initial array. The numbers in the lines are separated by single spaces. | 1,600 | In a single line print two numbers β the maximum number of occurrences of some number in the array after at most k allowed operations are performed, and the minimum number that reaches the given maximum. Separate the printed numbers by whitespaces. | standard output | |
PASSED | 32c0f92f7d775d6abf56c2b36c69031e | train_003.jsonl | 1349623800 | A piece of paper contains an array of n integers a1,βa2,β...,βan. Your task is to find a number that occurs the maximum number of times in this array.However, before looking for such number, you are allowed to perform not more than k following operations β choose an arbitrary element from the array and add 1 to it. In other words, you are allowed to increase some array element by 1 no more than k times (you are allowed to increase the same element of the array multiple times).Your task is to find the maximum number of occurrences of some number in the array after performing no more than k allowed operations. If there are several such numbers, your task is to find the minimum one. | 256 megabytes | import java.util.*;
import java.io.*;
public class AddOrNot{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = sc.nextInt();
int k = sc.nextInt();
int[] array = new int[n];
for(int i =0;i<n;i++){
array[i] =sc.nextInt();
}
Arrays.sort(array);
int l=0;
long s =0;
long ans = 1;
long best = array[0];
for(int r = 1;r<n;r++){
s += (long)(r-l)*(array[r]-array[r-1]);
while(s>k){
s -= (long)array[r]-array[l];
l++;
}
if((r-l+1)>ans){
ans = (long)r-l+1;
best = (long)array[r];
}
}
out.println(ans+" "+best);
out.close();
sc.close();
}
} | Java | ["5 3\n6 3 4 0 2", "3 4\n5 5 5", "5 3\n3 1 2 2 1"] | 2 seconds | ["3 4", "3 5", "4 2"] | NoteIn the first sample your task is to increase the second element of the array once and increase the fifth element of the array twice. Thus, we get sequence 6,β4,β4,β0,β4, where number 4 occurs 3 times.In the second sample you don't need to perform a single operation or increase each element by one. If we do nothing, we get array 5,β5,β5, if we increase each by one, we get 6,β6,β6. In both cases the maximum number of occurrences equals 3. So we should do nothing, as number 5 is less than number 6.In the third sample we should increase the second array element once and the fifth element once. Thus, we get sequence 3,β2,β2,β2,β2, where number 2 occurs 4 times. | Java 11 | standard input | [
"two pointers",
"binary search",
"sortings"
] | 3791d1a504b39eb2e72472bcfd9a7e22 | The first line contains two integers n and k (1ββ€βnββ€β105; 0ββ€βkββ€β109) β the number of elements in the array and the number of operations you are allowed to perform, correspondingly. The third line contains a sequence of n integers a1,βa2,β...,βan (|ai|ββ€β109) β the initial array. The numbers in the lines are separated by single spaces. | 1,600 | In a single line print two numbers β the maximum number of occurrences of some number in the array after at most k allowed operations are performed, and the minimum number that reaches the given maximum. Separate the printed numbers by whitespaces. | standard output | |
PASSED | f308a5e87f78f18bed60c5f7b73c26ec | train_003.jsonl | 1349623800 | A piece of paper contains an array of n integers a1,βa2,β...,βan. Your task is to find a number that occurs the maximum number of times in this array.However, before looking for such number, you are allowed to perform not more than k following operations β choose an arbitrary element from the array and add 1 to it. In other words, you are allowed to increase some array element by 1 no more than k times (you are allowed to increase the same element of the array multiple times).Your task is to find the maximum number of occurrences of some number in the array after performing no more than k allowed operations. If there are several such numbers, your task is to find the minimum one. | 256 megabytes |
import java.util.*;
import java.io.*;
public class ToAddorNottoAdd {
// https://codeforces.com/contest/231/problem/C
public static void main(String[] args) throws IOException, FileNotFoundException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
//BufferedReader in = new BufferedReader(new FileReader("ToAddorNottoAdd"));
StringTokenizer st = new StringTokenizer(in.readLine());
int n = Integer.parseInt(st.nextToken());
long k = Integer.parseInt(st.nextToken());
long[] arr = new long[n];
st = new StringTokenizer(in.readLine());
for (int i=0; i<n; i++) arr[i] = Long.parseLong(st.nextToken());
if (n == 1) {
System.out.println(1 + " " + arr[0]);
return;
}
Arrays.sort(arr);
// 2 pointers
int maxnum = 1;
long number=arr[0];
int firstpointer=0;
for (int secondpointer=1; secondpointer<n; secondpointer++) {
k -= (secondpointer-firstpointer)*(arr[secondpointer]-arr[secondpointer-1]);
while (k < 0) {
k += (arr[secondpointer] - arr[firstpointer]);
firstpointer++;
}
if (secondpointer-firstpointer+1 > maxnum) {
number = arr[secondpointer];
maxnum = secondpointer-firstpointer+1;
}
}
System.out.println(maxnum + " " + number);
}
}
/*
long min = arr[0];
long max = arr[arr.length-1];
long curmax=0;
long maxnum=0;
// first find max amount of times it could work
HashMap<Long, Long> map =new HashMap<>();
while (min < max) {
long middle = (min+max)/2;
map.put(middle, works(middle, arr, k));
if (map.get(middle) > curmax) {
curmax = map.get(middle);
maxnum = middle;
min = middle;
}
else max = middle-1;
}
// now that have curmax
for (long i=maxnum; i>=arr[0]; i--) {
if (works(i, arr, k) == curmax) {
maxnum = i;
}
else break;
}
System.out.println(curmax + " " + maxnum );
}
public static long works(long middle, long[] arr, long k) {
ArrayList<Long> a = new ArrayList<>();
for (int i=0; i<arr.length; i++) {
if (arr[i] <= middle) a.add(arr[i]);
else break;
}
long count=0;
int pointer=a.size()-1;
while (k>0 && pointer>=0) {
if (middle - a.get(pointer) <= k) {
k -= (middle - a.get(pointer));
count++;
}
pointer--;
}
return count;
}
*/ | Java | ["5 3\n6 3 4 0 2", "3 4\n5 5 5", "5 3\n3 1 2 2 1"] | 2 seconds | ["3 4", "3 5", "4 2"] | NoteIn the first sample your task is to increase the second element of the array once and increase the fifth element of the array twice. Thus, we get sequence 6,β4,β4,β0,β4, where number 4 occurs 3 times.In the second sample you don't need to perform a single operation or increase each element by one. If we do nothing, we get array 5,β5,β5, if we increase each by one, we get 6,β6,β6. In both cases the maximum number of occurrences equals 3. So we should do nothing, as number 5 is less than number 6.In the third sample we should increase the second array element once and the fifth element once. Thus, we get sequence 3,β2,β2,β2,β2, where number 2 occurs 4 times. | Java 11 | standard input | [
"two pointers",
"binary search",
"sortings"
] | 3791d1a504b39eb2e72472bcfd9a7e22 | The first line contains two integers n and k (1ββ€βnββ€β105; 0ββ€βkββ€β109) β the number of elements in the array and the number of operations you are allowed to perform, correspondingly. The third line contains a sequence of n integers a1,βa2,β...,βan (|ai|ββ€β109) β the initial array. The numbers in the lines are separated by single spaces. | 1,600 | In a single line print two numbers β the maximum number of occurrences of some number in the array after at most k allowed operations are performed, and the minimum number that reaches the given maximum. Separate the printed numbers by whitespaces. | standard output | |
PASSED | bcd60904dab59ae026a931720d9ff6a1 | train_003.jsonl | 1349623800 | A piece of paper contains an array of n integers a1,βa2,β...,βan. Your task is to find a number that occurs the maximum number of times in this array.However, before looking for such number, you are allowed to perform not more than k following operations β choose an arbitrary element from the array and add 1 to it. In other words, you are allowed to increase some array element by 1 no more than k times (you are allowed to increase the same element of the array multiple times).Your task is to find the maximum number of occurrences of some number in the array after performing no more than k allowed operations. If there are several such numbers, your task is to find the minimum one. | 256 megabytes |
import java.util.Arrays;
import java.util.Scanner;
public class Main {
static int arr[], dp[][], N, K, p;
static long pre[];
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
K = input.nextInt();
arr = new int[n];
pre = new long[n];
for(int i=0 ; i<n ; i++)
arr[i] = input.nextInt();
Arrays.sort(arr);
pre[0] = arr[0];
for(int i=1 ; i<n ; i++)
pre[i] = pre[i-1] + arr[i];
int maxsize = -1;
int maxval = -1;
for(int i=0 ; i<n ; i++){
int mid = bs(0,i,arr[i],i);
if(i-mid+1 > maxsize){
maxsize = i-mid+1;
maxval = arr[i];
}
}
System.out.println(maxsize + " " + maxval);
}
static int bs(int start, int end,long x,int index){
while (start < end){
int mid = start + (end - start)/2;
if((index - mid + 1)*x - (pre[index] - ((mid != 0 ) ? pre[mid-1] : 0)) <= K)
end = mid;
else
start = mid+1;
}
return start;
}
}
| Java | ["5 3\n6 3 4 0 2", "3 4\n5 5 5", "5 3\n3 1 2 2 1"] | 2 seconds | ["3 4", "3 5", "4 2"] | NoteIn the first sample your task is to increase the second element of the array once and increase the fifth element of the array twice. Thus, we get sequence 6,β4,β4,β0,β4, where number 4 occurs 3 times.In the second sample you don't need to perform a single operation or increase each element by one. If we do nothing, we get array 5,β5,β5, if we increase each by one, we get 6,β6,β6. In both cases the maximum number of occurrences equals 3. So we should do nothing, as number 5 is less than number 6.In the third sample we should increase the second array element once and the fifth element once. Thus, we get sequence 3,β2,β2,β2,β2, where number 2 occurs 4 times. | Java 11 | standard input | [
"two pointers",
"binary search",
"sortings"
] | 3791d1a504b39eb2e72472bcfd9a7e22 | The first line contains two integers n and k (1ββ€βnββ€β105; 0ββ€βkββ€β109) β the number of elements in the array and the number of operations you are allowed to perform, correspondingly. The third line contains a sequence of n integers a1,βa2,β...,βan (|ai|ββ€β109) β the initial array. The numbers in the lines are separated by single spaces. | 1,600 | In a single line print two numbers β the maximum number of occurrences of some number in the array after at most k allowed operations are performed, and the minimum number that reaches the given maximum. Separate the printed numbers by whitespaces. | standard output | |
PASSED | 3c57c7d27139231e4b77399fe3bfc480 | train_003.jsonl | 1349623800 | A piece of paper contains an array of n integers a1,βa2,β...,βan. Your task is to find a number that occurs the maximum number of times in this array.However, before looking for such number, you are allowed to perform not more than k following operations β choose an arbitrary element from the array and add 1 to it. In other words, you are allowed to increase some array element by 1 no more than k times (you are allowed to increase the same element of the array multiple times).Your task is to find the maximum number of occurrences of some number in the array after performing no more than k allowed operations. If there are several such numbers, your task is to find the minimum one. | 256 megabytes | import java.util.*;
import java.io.*;
public class Forces{
public static PrintWriter cout;
public static void main(String ...arg)
{
//Read cin = new Read();
InputReader cin = new InputReader(System.in);
cout = new PrintWriter(new BufferedOutputStream(System.out));
int n = cin.nextInt();
long k = cin.nextInt();
Long[] a = new Long[n];
for(int i=0;i<n;i++)
a[i] = (long)cin.nextInt();
Arrays.sort(a);
int i=0,j=0;
long ans = -1,ansF = 0;
long runsum = 0;
for(j=0;j<n;j++)
{
runsum += a[j];
if( (j-i+1)*a[j] - runsum <= k && j-i+1 > ansF)
{
ans = a[j];
ansF = j-i+1;
}
else
{
runsum -= a[i];
i++;
}
}
cout.print(ansF + " " + ans);
cout.close();
}
static class InputReader {
final InputStream is;
final byte[] buf = new byte[1024];
int pos;
int size;
public InputReader(InputStream is) {
this.is = is;
}
public int nextInt() {
int c = read();
while (isWhitespace(c))
c = read();
int sign = 1;
if (c == '-') {
sign = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res = res * 10 + c - '0';
c = read();
} while (!isWhitespace(c));
return res * sign;
}
int read() {
if (size == -1)
throw new InputMismatchException();
if (pos >= size) {
pos = 0;
try {
size = is.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (size <= 0)
return -1;
}
return buf[pos++] & 255;
}
static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
}
}
class Read
{
private BufferedReader br;
private StringTokenizer st;
public Read()
{ 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 | ["5 3\n6 3 4 0 2", "3 4\n5 5 5", "5 3\n3 1 2 2 1"] | 2 seconds | ["3 4", "3 5", "4 2"] | NoteIn the first sample your task is to increase the second element of the array once and increase the fifth element of the array twice. Thus, we get sequence 6,β4,β4,β0,β4, where number 4 occurs 3 times.In the second sample you don't need to perform a single operation or increase each element by one. If we do nothing, we get array 5,β5,β5, if we increase each by one, we get 6,β6,β6. In both cases the maximum number of occurrences equals 3. So we should do nothing, as number 5 is less than number 6.In the third sample we should increase the second array element once and the fifth element once. Thus, we get sequence 3,β2,β2,β2,β2, where number 2 occurs 4 times. | Java 11 | standard input | [
"two pointers",
"binary search",
"sortings"
] | 3791d1a504b39eb2e72472bcfd9a7e22 | The first line contains two integers n and k (1ββ€βnββ€β105; 0ββ€βkββ€β109) β the number of elements in the array and the number of operations you are allowed to perform, correspondingly. The third line contains a sequence of n integers a1,βa2,β...,βan (|ai|ββ€β109) β the initial array. The numbers in the lines are separated by single spaces. | 1,600 | In a single line print two numbers β the maximum number of occurrences of some number in the array after at most k allowed operations are performed, and the minimum number that reaches the given maximum. Separate the printed numbers by whitespaces. | standard output | |
PASSED | 643cc4f76b4a5202ed6b8e4aba011d9e | train_003.jsonl | 1349623800 | A piece of paper contains an array of n integers a1,βa2,β...,βan. Your task is to find a number that occurs the maximum number of times in this array.However, before looking for such number, you are allowed to perform not more than k following operations β choose an arbitrary element from the array and add 1 to it. In other words, you are allowed to increase some array element by 1 no more than k times (you are allowed to increase the same element of the array multiple times).Your task is to find the maximum number of occurrences of some number in the array after performing no more than k allowed operations. If there are several such numbers, your task is to find the minimum one. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.Arrays;
public class Contest {
static PrintWriter out = new PrintWriter(System.out);
static final Random random = new Random();
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
long k = sc.nextInt();
long[] a = new long[n];
for(int i = 0;i < n;i++)
a[i] = sc.nextInt();
Arrays.sort(a);
long maxOcc = a[0], countOcc = 1;
int l = 0, r = 1, prevCost = 0;
while(r < n) {
while(r < n && prevCost+Math.abs(a[r]-a[r-1])*(r-l) <= k) {
prevCost = (int) (prevCost + Math.abs(a[r]-a[r-1])*(r-l));
r++;
}
long sz = r - l;
long num = a[r - 1];
if(sz > countOcc) {
countOcc = sz;
maxOcc = num;
}
prevCost -= (a[(int)r-1] - a[l]);
l++;
}
System.out.println(countOcc + " " + maxOcc);
out.flush();
}
static void ruffleSort(int[] a) {
int n = a.length;// shuffle, then sort
for (int i = 0; i < n; i++) {
int oi = random.nextInt(n), temp = a[oi];
a[oi] = a[i];
a[i] = temp;
}
java.util.Arrays.sort(a);
}
private static class Scanner {
public BufferedReader reader;
public StringTokenizer st;
public Scanner(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
st = null;
}
public String next() {
while (st == null || !st.hasMoreTokens()) {
try {
String line = reader.readLine();
if (line == null)
return null;
st = new StringTokenizer(line);
} catch (Exception e) {
throw (new RuntimeException());
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String nextLine() throws IOException {
return reader.readLine();
}
}
} | Java | ["5 3\n6 3 4 0 2", "3 4\n5 5 5", "5 3\n3 1 2 2 1"] | 2 seconds | ["3 4", "3 5", "4 2"] | NoteIn the first sample your task is to increase the second element of the array once and increase the fifth element of the array twice. Thus, we get sequence 6,β4,β4,β0,β4, where number 4 occurs 3 times.In the second sample you don't need to perform a single operation or increase each element by one. If we do nothing, we get array 5,β5,β5, if we increase each by one, we get 6,β6,β6. In both cases the maximum number of occurrences equals 3. So we should do nothing, as number 5 is less than number 6.In the third sample we should increase the second array element once and the fifth element once. Thus, we get sequence 3,β2,β2,β2,β2, where number 2 occurs 4 times. | Java 11 | standard input | [
"two pointers",
"binary search",
"sortings"
] | 3791d1a504b39eb2e72472bcfd9a7e22 | The first line contains two integers n and k (1ββ€βnββ€β105; 0ββ€βkββ€β109) β the number of elements in the array and the number of operations you are allowed to perform, correspondingly. The third line contains a sequence of n integers a1,βa2,β...,βan (|ai|ββ€β109) β the initial array. The numbers in the lines are separated by single spaces. | 1,600 | In a single line print two numbers β the maximum number of occurrences of some number in the array after at most k allowed operations are performed, and the minimum number that reaches the given maximum. Separate the printed numbers by whitespaces. | standard output | |
PASSED | 0b5378d0e41737339afdd82b8c9e3a1f | train_003.jsonl | 1349623800 | A piece of paper contains an array of n integers a1,βa2,β...,βan. Your task is to find a number that occurs the maximum number of times in this array.However, before looking for such number, you are allowed to perform not more than k following operations β choose an arbitrary element from the array and add 1 to it. In other words, you are allowed to increase some array element by 1 no more than k times (you are allowed to increase the same element of the array multiple times).Your task is to find the maximum number of occurrences of some number in the array after performing no more than k allowed operations. If there are several such numbers, your task is to find the minimum one. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
FastReader in = new FastReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
CToAddOrNotToAdd solver = new CToAddOrNotToAdd();
solver.solve(1, in, out);
out.close();
}
static class CToAddOrNotToAdd {
public void solve(int testNumber, FastReader s, PrintWriter out) {
int n = s.nextInt();
int k = s.nextInt();
int[] arr = s.nextIntArray(n);
CToAddOrNotToAdd.arrays.sort(arr);
long lo = 0, hi = n, ans = 0, el = -1;
while (lo <= hi) {
long s1 = 0, mid = lo + hi >> 1;
for (int i = 0; i < n; ++i) {
s1 += arr[i];
if (i < mid - 1) continue;
if (i >= mid) s1 -= arr[(int) (i - mid)];
long cost = Math.abs(arr[i] * mid - s1);
if (cost <= k) {
ans = mid;
el = arr[i];
break;
}
}
if (ans == mid) lo = mid + 1;
else hi = mid - 1;
}
out.println(ans + " " + el);
}
private static class arrays {
static void merge(int arr[], int l, int m, int r) {
int n1 = m - l + 1;
int n2 = r - m;
int L[] = new int[n1];
int R[] = new int[n2];
for (int i = 0; i < n1; ++i)
L[i] = arr[l + i];
for (int j = 0; j < n2; ++j)
R[j] = arr[m + 1 + j];
int i = 0, j = 0;
int k = l;
while (i < n1 && j < n2) {
if (L[i] <= R[j]) {
arr[k] = L[i];
i++;
} else {
arr[k] = R[j];
j++;
}
k++;
}
while (i < n1) {
arr[k] = L[i];
i++;
k++;
}
while (j < n2) {
arr[k] = R[j];
j++;
k++;
}
}
static void sort(int arr[], int l, int r) {
if (l < r) {
int m = (l + r) / 2;
sort(arr, l, m);
sort(arr, m + 1, r);
merge(arr, l, m, r);
}
}
static void sort(int[] arr) {
sort(arr, 0, arr.length - 1);
}
}
}
static class FastReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private FastReader.SpaceCharFilter filter;
public FastReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public int nextInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c) {
if (filter != null) {
return filter.isSpaceChar(c);
}
return isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public int[] nextIntArray(int n) {
int[] array = new int[n];
for (int i = 0; i < n; ++i) array[i] = nextInt();
return array;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
}
| Java | ["5 3\n6 3 4 0 2", "3 4\n5 5 5", "5 3\n3 1 2 2 1"] | 2 seconds | ["3 4", "3 5", "4 2"] | NoteIn the first sample your task is to increase the second element of the array once and increase the fifth element of the array twice. Thus, we get sequence 6,β4,β4,β0,β4, where number 4 occurs 3 times.In the second sample you don't need to perform a single operation or increase each element by one. If we do nothing, we get array 5,β5,β5, if we increase each by one, we get 6,β6,β6. In both cases the maximum number of occurrences equals 3. So we should do nothing, as number 5 is less than number 6.In the third sample we should increase the second array element once and the fifth element once. Thus, we get sequence 3,β2,β2,β2,β2, where number 2 occurs 4 times. | Java 11 | standard input | [
"two pointers",
"binary search",
"sortings"
] | 3791d1a504b39eb2e72472bcfd9a7e22 | The first line contains two integers n and k (1ββ€βnββ€β105; 0ββ€βkββ€β109) β the number of elements in the array and the number of operations you are allowed to perform, correspondingly. The third line contains a sequence of n integers a1,βa2,β...,βan (|ai|ββ€β109) β the initial array. The numbers in the lines are separated by single spaces. | 1,600 | In a single line print two numbers β the maximum number of occurrences of some number in the array after at most k allowed operations are performed, and the minimum number that reaches the given maximum. Separate the printed numbers by whitespaces. | standard output | |
PASSED | 7760821ba24e583b41b55f92b4cc238f | train_003.jsonl | 1567587900 | Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has $$$n$$$ rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar is $$$d$$$ rubles, and one euro costs $$$e$$$ rubles.Recall that there exist the following dollar bills: $$$1$$$, $$$2$$$, $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, and the following euro billsΒ β $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, $$$200$$$ (note that, in this problem we do not consider the $$$500$$$ euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.Help himΒ β write a program that given integers $$$n$$$, $$$e$$$ and $$$d$$$, finds the minimum number of rubles Andrew can get after buying dollar and euro bills. | 512 megabytes | import java.util.Scanner;
public class CodeForces{
public static void main(String[] args){
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int d=s.nextInt();
int e=5*s.nextInt();
int i=0,min=n;
while(n>=i*e) {
int rem=n-i*e;
rem-=(rem/d)*d;
min=Math.min(rem, min);
i++;
if(min==0){
break;
}
}
System.out.println(min);
}
} | Java | ["100\n60\n70", "410\n55\n70", "600\n60\n70"] | 1.5 seconds | ["40", "5", "0"] | NoteIn the first example, we can buy just $$$1$$$ dollar because there is no $$$1$$$ euro bill.In the second example, optimal exchange is to buy $$$5$$$ euro and $$$1$$$ dollar.In the third example, optimal exchange is to buy $$$10$$$ dollars in one bill. | Java 8 | standard input | [
"brute force",
"math"
] | 8c5d9b4fd297706fac3be83fc85028a0 | The first line of the input contains one integer $$$n$$$ ($$$1 \leq n \leq 10^8$$$)Β β the initial sum in rubles Andrew has. The second line of the input contains one integer $$$d$$$ ($$$30 \leq d \leq 100$$$)Β β the price of one dollar in rubles. The third line of the input contains integer $$$e$$$ ($$$30 \leq e \leq 100$$$)Β β the price of one euro in rubles. | 1,400 | Output one integerΒ β the minimum number of rubles Andrew can have after buying dollar and euro bills optimally. | standard output | |
PASSED | 66f1fd221661d490a7bcbc87f0a08eba | train_003.jsonl | 1567587900 | Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has $$$n$$$ rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar is $$$d$$$ rubles, and one euro costs $$$e$$$ rubles.Recall that there exist the following dollar bills: $$$1$$$, $$$2$$$, $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, and the following euro billsΒ β $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, $$$200$$$ (note that, in this problem we do not consider the $$$500$$$ euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.Help himΒ β write a program that given integers $$$n$$$, $$$e$$$ and $$$d$$$, finds the minimum number of rubles Andrew can get after buying dollar and euro bills. | 512 megabytes | import java.util.*;
import java.lang.*;
import java.math.*;
import java.awt.image.ConvolveOp;
import java.io.*;
import java.text.DecimalFormat;
import java.lang.reflect.Array;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.util.*;
public class Codeforces{
public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
static long MOD = (long)(1e9+7);
static FastReader sc = new FastReader();
static int pInf = Integer.MAX_VALUE;
static int nInf = Integer.MIN_VALUE;
public static void main(String[] args){
int test = 1;
//test = sc.nextInt();
while(test-->0){
int n = sc.nextInt();
int d = sc.nextInt();
int e = sc.nextInt();
int ce = (int)Math.ceil((n+0.0)/e);
int ans = pInf;
for(int i = 0; i <= ce; i+=5) {
int temp = n-(i*e);
if(temp<0) {
break;
}
int cost = temp-(temp/d)*d;
ans = Math.min(ans, cost);
}
out.print(ans);
}
out.close();
}
public static long mul(long a, long b){
return ((a%MOD)*(b%MOD))%MOD;
}
public static long add(long a, long b){
return ((a%MOD)+(b%MOD))%MOD;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Integer.lowestOneBit(i) Equals k where k is the position of the first one in the binary
//Integer.highestOneBit(i) Equals k where k is the position of the last one in the binary
//Integer.bitCount(i) returns the number of one-bits
//Collections.sort(A,(p1,p2)->(int)(p2.x-p1.x)) To sort ArrayList in descending order wrt values of x.
// Arrays.parallelSort(a,new Comparator<TPair>() {
// public int compare(TPair a,TPair b) {
// if(a.y==b.y) return a.x-b.x;
// return b.y-a.y;
// }
// });
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//PrimeFactors
public static ArrayList<Long> primeFactors(long n) {
ArrayList<Long> arr = new ArrayList<>();
if (n % 2 == 0)
arr.add((long) 2);
while (n % 2 == 0)
n /= 2;
for (long i = 3; i <= Math.sqrt(n); i += 2) {
int flag = 0;
while (n % i == 0) {
n /= i;
flag = 1;
}
if (flag == 1)
arr.add(i);
}
if (n > 2)
arr.add(n);
return arr;
}
//Pair Class
static class Pair implements Comparable<Pair>{
int x;
int y;
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public int compareTo(Pair o) {
if(this.x==o.x){
return (this.y-o.y);
}
return (this.x-o.x);
}
}
static class TPair{
long x;
int y;
public TPair(long x, int y) {
this.x = x;
this.y = y;
}
}
//Merge Sort
static void merge(long arr[], int l, int m, int r)
{
// Find sizes of two subarrays to be merged
int n1 = m - l + 1;
int n2 = r - m;
/* Create temp arrays */
long L[] = new long [n1];
long R[] = new long [n2];
/*Copy data to temp arrays*/
for (int i=0; i<n1; ++i)
L[i] = arr[l + i];
for (int j=0; j<n2; ++j)
R[j] = arr[m + 1+ j];
/* Merge the temp arrays */
// Initial indexes of first and second subarrays
int i = 0, j = 0;
// Initial index of merged subarry array
int k = l;
while (i < n1 && j < n2)
{
if (L[i] <= R[j])
{
arr[k] = L[i];
i++;
}
else
{
arr[k] = R[j];
j++;
}
k++;
}
/* Copy remaining elements of L[] if any */
while (i < n1)
{
arr[k] = L[i];
i++;
k++;
}
/* Copy remaining elements of R[] if any */
while (j < n2)
{
arr[k] = R[j];
j++;
k++;
}
}
// Main function that sorts arr[l..r] using
// merge()
static void sort(long arr[], int l, int r)
{
if (l < r)
{
// Find the middle point
int m = (l+r)/2;
// Sort first and second halves
sort(arr, l, m);
sort(arr , m+1, r);
// Merge the sorted halves
merge(arr, l, m, r);
}
}
//Brian Kernighanβs Algorithm
static long countSetBits(long n){
if(n==0) return 0;
return 1+countSetBits(n&(n-1));
}
//Factorial
static long factorial(long n){
if(n==1) return 1;
if(n==2) return 2;
if(n==3) return 6;
return n*factorial(n-1);
}
//Euclidean Algorithm
static long gcd(long A,long B){
if(B==0) return A;
return gcd(B,A%B);
}
//Modular Exponentiation
static long fastExpo(long x,long n){
if(n==0) return 1;
if((n&1)==0) return fastExpo((x*x)%MOD,n/2)%MOD;
return ((x%MOD)*fastExpo((x*x)%MOD,(n-1)/2))%MOD;
}
//AKS Algorithm
static boolean isPrime(long n){
if(n<=1) return false;
if(n<=3) return true;
if(n%2==0 || n%3==0) return false;
for(int i=5;i<=Math.sqrt(n);i+=6)
if(n%i==0 || n%(i+2)==0) return false;
return true;
}
//Reverse an array
static <T> void reverse(T arr[],int l,int r){
Collections.reverse(Arrays.asList(arr).subList(l, r));
}
//Sieve of eratosthenes
static int[] findPrimes(int n){
boolean isPrime[]=new boolean[n+1];
ArrayList<Integer> a=new ArrayList<>();
int result[];
Arrays.fill(isPrime,true);
isPrime[0]=false;
isPrime[1]=false;
for(int i=2;i*i<=n;++i){
if(isPrime[i]==true){
for(int j=i*i;j<=n;j+=i) isPrime[j]=false;
}
}
for(int i=0;i<=n;i++) if(isPrime[i]==true) a.add(i);
result=new int[a.size()];
for(int i=0;i<a.size();i++) result[i]=a.get(i);
return result;
}
//Segmented Sieve
static boolean[] segmentedSieve(long l, long r){
boolean[] segSieve = new boolean[(int)(r-l+1)];
Arrays.fill(segSieve, true);
int[] prePrimes = findPrimes((int)Math.sqrt(r));
for(int p:prePrimes) {
long low = (l/p)*p;
if(low < l) {
low += p;
}
if(low == p) {
low += p;
}
for(long j = low; j<= r; j += p) {
segSieve[(int) (j-l)] = false;
}
}
if(l==1) {
segSieve[0] = false;
}
return segSieve;
}
//Euler Totent function
static long countCoprimes(long n){
ArrayList<Long> prime_factors=new ArrayList<>();
long x=n,flag=0;
while(x%2==0){
if(flag==0) prime_factors.add(2L);
flag=1;
x/=2;
}
for(long i=3;i*i<=x;i+=2){
flag=0;
while(x%i==0){
if(flag==0) prime_factors.add(i);
flag=1;
x/=i;
}
}
if(x>2) prime_factors.add(x);
double ans=(double)n;
for(Long p:prime_factors){
ans*=(1.0-(Double)1.0/p);
}
return (long)ans;
}
static long modulo = (long)1e9+7;
public static long modinv(long x){
return modpow(x, modulo-2);
}
public static long modpow(long a, long b){
if(b==0){
return 1;
}
long x = modpow(a, b/2);
x = (x*x)%modulo;
if(b%2==1){
return (x*a)%modulo;
}
return x;
}
public static class FastReader {
BufferedReader br;
StringTokenizer st;
//it reads the data about the specified point and divide the data about it ,it is quite fast
//than using direct
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception r) {
r.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());//converts string to integer
}
double nextDouble() {
return Double.parseDouble(next());
}
long nextLong() {
return Long.parseLong(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (Exception r) {
r.printStackTrace();
}
return str;
}
}
} | Java | ["100\n60\n70", "410\n55\n70", "600\n60\n70"] | 1.5 seconds | ["40", "5", "0"] | NoteIn the first example, we can buy just $$$1$$$ dollar because there is no $$$1$$$ euro bill.In the second example, optimal exchange is to buy $$$5$$$ euro and $$$1$$$ dollar.In the third example, optimal exchange is to buy $$$10$$$ dollars in one bill. | Java 8 | standard input | [
"brute force",
"math"
] | 8c5d9b4fd297706fac3be83fc85028a0 | The first line of the input contains one integer $$$n$$$ ($$$1 \leq n \leq 10^8$$$)Β β the initial sum in rubles Andrew has. The second line of the input contains one integer $$$d$$$ ($$$30 \leq d \leq 100$$$)Β β the price of one dollar in rubles. The third line of the input contains integer $$$e$$$ ($$$30 \leq e \leq 100$$$)Β β the price of one euro in rubles. | 1,400 | Output one integerΒ β the minimum number of rubles Andrew can have after buying dollar and euro bills optimally. | standard output | |
PASSED | 63898fac7fcfbef5f64ede5da2f58b2e | train_003.jsonl | 1567587900 | Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has $$$n$$$ rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar is $$$d$$$ rubles, and one euro costs $$$e$$$ rubles.Recall that there exist the following dollar bills: $$$1$$$, $$$2$$$, $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, and the following euro billsΒ β $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, $$$200$$$ (note that, in this problem we do not consider the $$$500$$$ euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.Help himΒ β write a program that given integers $$$n$$$, $$$e$$$ and $$$d$$$, finds the minimum number of rubles Andrew can get after buying dollar and euro bills. | 512 megabytes | import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.stream.IntStream;
public class Main {
public static void main(String args[]) {
InputReader in = new InputReader(System.in);
PrintWriter out = new PrintWriter(System.out);
IntStream.range(0, 1).forEach(tc -> {
new Solver(tc, in, out).solve();
out.flush();
});
out.close();
}
}
class InputReader {
BufferedReader reader;
StringTokenizer tokenizer;
InputReader(InputStream in) {
reader = new BufferedReader(new InputStreamReader(in));
}
String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
int nextInt() {
return Integer.valueOf(next());
}
double nextDouble() {
return Double.valueOf(next());
}
String nextLine() {
try {
return reader.readLine();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
class Solver {
private InputReader in;
private PrintWriter out;
private Integer tc;
Solver(Integer tc, InputReader in, PrintWriter out) {
this.in = in;
this.out = out;
this.tc = tc;
}
void solve() {
Integer n = in.nextInt();
Integer e = in.nextInt();
Integer b = in.nextInt();
IntStream.rangeClosed(0, n / b / 5).map(i -> (n - b * 5 * i) % e).min().ifPresent(out::println);
}
}
| Java | ["100\n60\n70", "410\n55\n70", "600\n60\n70"] | 1.5 seconds | ["40", "5", "0"] | NoteIn the first example, we can buy just $$$1$$$ dollar because there is no $$$1$$$ euro bill.In the second example, optimal exchange is to buy $$$5$$$ euro and $$$1$$$ dollar.In the third example, optimal exchange is to buy $$$10$$$ dollars in one bill. | Java 8 | standard input | [
"brute force",
"math"
] | 8c5d9b4fd297706fac3be83fc85028a0 | The first line of the input contains one integer $$$n$$$ ($$$1 \leq n \leq 10^8$$$)Β β the initial sum in rubles Andrew has. The second line of the input contains one integer $$$d$$$ ($$$30 \leq d \leq 100$$$)Β β the price of one dollar in rubles. The third line of the input contains integer $$$e$$$ ($$$30 \leq e \leq 100$$$)Β β the price of one euro in rubles. | 1,400 | Output one integerΒ β the minimum number of rubles Andrew can have after buying dollar and euro bills optimally. | standard output | |
PASSED | 5a61c56b928df96644c191dffe4fde6f | train_003.jsonl | 1567587900 | Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has $$$n$$$ rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar is $$$d$$$ rubles, and one euro costs $$$e$$$ rubles.Recall that there exist the following dollar bills: $$$1$$$, $$$2$$$, $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, and the following euro billsΒ β $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, $$$200$$$ (note that, in this problem we do not consider the $$$500$$$ euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.Help himΒ β write a program that given integers $$$n$$$, $$$e$$$ and $$$d$$$, finds the minimum number of rubles Andrew can get after buying dollar and euro bills. | 512 megabytes | import java.io.IOException;
import java.util.*;
public class contest {
public static void main(String []arg) throws IOException {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();int d=sc.nextInt();int e=sc.nextInt();int min=Integer.MAX_VALUE;
e=5*e;
for(int div=0;div*d<=n;div++) {
int divE=(n-div*d)/e;
min=Math.min(min,n-div*d-divE*e);
}
System.out.println(min);
}
}
| Java | ["100\n60\n70", "410\n55\n70", "600\n60\n70"] | 1.5 seconds | ["40", "5", "0"] | NoteIn the first example, we can buy just $$$1$$$ dollar because there is no $$$1$$$ euro bill.In the second example, optimal exchange is to buy $$$5$$$ euro and $$$1$$$ dollar.In the third example, optimal exchange is to buy $$$10$$$ dollars in one bill. | Java 8 | standard input | [
"brute force",
"math"
] | 8c5d9b4fd297706fac3be83fc85028a0 | The first line of the input contains one integer $$$n$$$ ($$$1 \leq n \leq 10^8$$$)Β β the initial sum in rubles Andrew has. The second line of the input contains one integer $$$d$$$ ($$$30 \leq d \leq 100$$$)Β β the price of one dollar in rubles. The third line of the input contains integer $$$e$$$ ($$$30 \leq e \leq 100$$$)Β β the price of one euro in rubles. | 1,400 | Output one integerΒ β the minimum number of rubles Andrew can have after buying dollar and euro bills optimally. | standard output | |
PASSED | 02bc911182d07e1501f24c1a07baebf2 | train_003.jsonl | 1567587900 | Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has $$$n$$$ rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar is $$$d$$$ rubles, and one euro costs $$$e$$$ rubles.Recall that there exist the following dollar bills: $$$1$$$, $$$2$$$, $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, and the following euro billsΒ β $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, $$$200$$$ (note that, in this problem we do not consider the $$$500$$$ euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.Help himΒ β write a program that given integers $$$n$$$, $$$e$$$ and $$$d$$$, finds the minimum number of rubles Andrew can get after buying dollar and euro bills. | 512 megabytes | import java.io.IOException;
import java.util.*;
public class contest {
public static void main(String []arg) throws IOException {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();int d=sc.nextInt();int e=sc.nextInt();int min=Integer.MAX_VALUE;
for (int j = 0; j <= n / d; j++) {
int s = n - j*d;//remain after exchanging dollars
int p = s/(5*e);//number of exchanging euro
int mm = s - p*5*e;//the remaining after exchanging euro
min = Math.min(mm, min);
}
System.out.println(min);
}}
| Java | ["100\n60\n70", "410\n55\n70", "600\n60\n70"] | 1.5 seconds | ["40", "5", "0"] | NoteIn the first example, we can buy just $$$1$$$ dollar because there is no $$$1$$$ euro bill.In the second example, optimal exchange is to buy $$$5$$$ euro and $$$1$$$ dollar.In the third example, optimal exchange is to buy $$$10$$$ dollars in one bill. | Java 8 | standard input | [
"brute force",
"math"
] | 8c5d9b4fd297706fac3be83fc85028a0 | The first line of the input contains one integer $$$n$$$ ($$$1 \leq n \leq 10^8$$$)Β β the initial sum in rubles Andrew has. The second line of the input contains one integer $$$d$$$ ($$$30 \leq d \leq 100$$$)Β β the price of one dollar in rubles. The third line of the input contains integer $$$e$$$ ($$$30 \leq e \leq 100$$$)Β β the price of one euro in rubles. | 1,400 | Output one integerΒ β the minimum number of rubles Andrew can have after buying dollar and euro bills optimally. | standard output | |
PASSED | 67454091c4dd9d84ea708338f6f219fb | train_003.jsonl | 1567587900 | Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has $$$n$$$ rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar is $$$d$$$ rubles, and one euro costs $$$e$$$ rubles.Recall that there exist the following dollar bills: $$$1$$$, $$$2$$$, $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, and the following euro billsΒ β $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, $$$200$$$ (note that, in this problem we do not consider the $$$500$$$ euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.Help himΒ β write a program that given integers $$$n$$$, $$$e$$$ and $$$d$$$, finds the minimum number of rubles Andrew can get after buying dollar and euro bills. | 512 megabytes | import java.io.*;
import java.util.*;
public class Main {
private static int[][] st;
private static int [] logs;
public static void main(String[] args) throws IOException {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
InputReader.OutputWriter out = new InputReader.OutputWriter(outputStream);
Scanner scanner = new Scanner(System.in);
int n = in.nextInt();
int a = in.nextInt();
int b = in.nextInt();
int ans = n;
for (int i = 0; i * 5 * b <= n; ++i) {
ans = Math.min(ans, (n - i * 5 * b) % a);
}
out.println(ans);
out.flush();
}
private static void shuffle(int [] a) {
for (int i = 0; i < a.length; i++) {
int index = (int)(Math.random()*(i+1));
int temp = a[i];
a[i] = a[index];
a[index] = temp;
}
}
private static boolean isPrime(int n) {
if(n < 2) return false;
for (int i = 2; i*i <=n; i++) {
if(n%i==0) return false;
}
return true;
}
public void fillSt(int []a,int n) {
logs = new int[n+1];
logs[1] = 0;
for (int i = 2; i <=n; i++) {
logs[i] = logs[i/2] + 1;
}
st = new int[30][n];
for (int i = 0; i <= logs[n]; i++) {
int curLen = 1 << i;
for (int j = 0; j+curLen <=n; j++) {
if(curLen == 1) {
st[i][j] = a[j];
}
else {
st[i][j] = Math.max(st[i-1][j],st[i-1][j+(curLen/2)]);
}
}
}
}
static int getMin(int l, int r) {
int p = logs[r-l+1];
int pLen = 1<<p;
return Math.max(st[p][l],st[p][r-pLen+1]);
}
static int numberOfSubsequences(String a, String b) {
int [] dp = new int[b.length()+1];
dp[0] = 1;
for (int i = 0; i < a.length(); i++) {
for (int j = b.length() - 1; j >=0;j--) {
if(a.charAt(i) == b.charAt(j)) {
dp[j+1]+=dp[j];
}
}
}
return dp[dp.length - 1];
}
private static int binPow(int a, int b) {
if(b == 0) return 1;
if(b%2!=0) {
return a*binPow(a,b-1);
}
int res = binPow(a,b/2);
return res*res;
}
}
class Point {
private int x;
private int y;
public int getX() {
return x;
}
public int getY() {
return y;
}
public Point(int x,int y) {
this.x = x;
this.y = y;
}
public long dest() {
return this.getX()*this.getX() + this.getY()*this.getY();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Point point = (Point) o;
return x == point.x &&
y == point.y;
}
@Override
public int hashCode() {
return Objects.hash(x, y);
}
}
class InputReader extends BufferedReader {
StringTokenizer tokenizer;
public InputReader(InputStream inputStream) {
super(new InputStreamReader(inputStream), 32768);
}
public InputReader(String filename) {
super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)));
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(readLine());
} catch (IOException e) {
throw new RuntimeException();
}
}
return tokenizer.nextToken();
}
public Integer nextInt(){
return Integer.valueOf(next());
}
public Long nextLong() {
return Long.valueOf(next());
}
public Double nextDouble() {
return Double.valueOf(next());
}
static class OutputWriter extends PrintWriter {
public OutputWriter(OutputStream outputStream) {
super(outputStream);
}
public OutputWriter(Writer writer) {
super(writer);
}
public OutputWriter(String filename) throws FileNotFoundException {
super(filename);
}
public void close() {
super.close();
}
}
} | Java | ["100\n60\n70", "410\n55\n70", "600\n60\n70"] | 1.5 seconds | ["40", "5", "0"] | NoteIn the first example, we can buy just $$$1$$$ dollar because there is no $$$1$$$ euro bill.In the second example, optimal exchange is to buy $$$5$$$ euro and $$$1$$$ dollar.In the third example, optimal exchange is to buy $$$10$$$ dollars in one bill. | Java 8 | standard input | [
"brute force",
"math"
] | 8c5d9b4fd297706fac3be83fc85028a0 | The first line of the input contains one integer $$$n$$$ ($$$1 \leq n \leq 10^8$$$)Β β the initial sum in rubles Andrew has. The second line of the input contains one integer $$$d$$$ ($$$30 \leq d \leq 100$$$)Β β the price of one dollar in rubles. The third line of the input contains integer $$$e$$$ ($$$30 \leq e \leq 100$$$)Β β the price of one euro in rubles. | 1,400 | Output one integerΒ β the minimum number of rubles Andrew can have after buying dollar and euro bills optimally. | standard output | |
PASSED | dc2f71b8e6a6233174232b8ee2729390 | train_003.jsonl | 1567587900 | Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has $$$n$$$ rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar is $$$d$$$ rubles, and one euro costs $$$e$$$ rubles.Recall that there exist the following dollar bills: $$$1$$$, $$$2$$$, $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, and the following euro billsΒ β $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, $$$200$$$ (note that, in this problem we do not consider the $$$500$$$ euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.Help himΒ β write a program that given integers $$$n$$$, $$$e$$$ and $$$d$$$, finds the minimum number of rubles Andrew can get after buying dollar and euro bills. | 512 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int a,b,c,n,i,k,d,e,min;
a=s.nextInt();
b=s.nextInt();
c=s.nextInt();
c=5*c;
min=a;
for (d=0;d<=a;d+=b){
e=a-d;
e=e%c;
min=Math.min(min,e);
}
System.out.print(min);
}
}
| Java | ["100\n60\n70", "410\n55\n70", "600\n60\n70"] | 1.5 seconds | ["40", "5", "0"] | NoteIn the first example, we can buy just $$$1$$$ dollar because there is no $$$1$$$ euro bill.In the second example, optimal exchange is to buy $$$5$$$ euro and $$$1$$$ dollar.In the third example, optimal exchange is to buy $$$10$$$ dollars in one bill. | Java 8 | standard input | [
"brute force",
"math"
] | 8c5d9b4fd297706fac3be83fc85028a0 | The first line of the input contains one integer $$$n$$$ ($$$1 \leq n \leq 10^8$$$)Β β the initial sum in rubles Andrew has. The second line of the input contains one integer $$$d$$$ ($$$30 \leq d \leq 100$$$)Β β the price of one dollar in rubles. The third line of the input contains integer $$$e$$$ ($$$30 \leq e \leq 100$$$)Β β the price of one euro in rubles. | 1,400 | Output one integerΒ β the minimum number of rubles Andrew can have after buying dollar and euro bills optimally. | standard output | |
PASSED | 261830a51fc14372be8ec4505d70a2cb | train_003.jsonl | 1567587900 | Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has $$$n$$$ rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar is $$$d$$$ rubles, and one euro costs $$$e$$$ rubles.Recall that there exist the following dollar bills: $$$1$$$, $$$2$$$, $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, and the following euro billsΒ β $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, $$$200$$$ (note that, in this problem we do not consider the $$$500$$$ euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.Help himΒ β write a program that given integers $$$n$$$, $$$e$$$ and $$$d$$$, finds the minimum number of rubles Andrew can get after buying dollar and euro bills. | 512 megabytes | import java.util.Scanner;
public class doors {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int d = s.nextInt();
int e = s.nextInt();
e*=5;
int ans = n;
for(int i = 0; i*d<=n; i++) {
ans = Math.min(ans, (n-i*d)%e);
}
System.out.println(ans);
}
}
| Java | ["100\n60\n70", "410\n55\n70", "600\n60\n70"] | 1.5 seconds | ["40", "5", "0"] | NoteIn the first example, we can buy just $$$1$$$ dollar because there is no $$$1$$$ euro bill.In the second example, optimal exchange is to buy $$$5$$$ euro and $$$1$$$ dollar.In the third example, optimal exchange is to buy $$$10$$$ dollars in one bill. | Java 8 | standard input | [
"brute force",
"math"
] | 8c5d9b4fd297706fac3be83fc85028a0 | The first line of the input contains one integer $$$n$$$ ($$$1 \leq n \leq 10^8$$$)Β β the initial sum in rubles Andrew has. The second line of the input contains one integer $$$d$$$ ($$$30 \leq d \leq 100$$$)Β β the price of one dollar in rubles. The third line of the input contains integer $$$e$$$ ($$$30 \leq e \leq 100$$$)Β β the price of one euro in rubles. | 1,400 | Output one integerΒ β the minimum number of rubles Andrew can have after buying dollar and euro bills optimally. | standard output | |
PASSED | ffb42f96becddd201a34708d34f308a7 | train_003.jsonl | 1567587900 | Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has $$$n$$$ rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar is $$$d$$$ rubles, and one euro costs $$$e$$$ rubles.Recall that there exist the following dollar bills: $$$1$$$, $$$2$$$, $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, and the following euro billsΒ β $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, $$$200$$$ (note that, in this problem we do not consider the $$$500$$$ euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.Help himΒ β write a program that given integers $$$n$$$, $$$e$$$ and $$$d$$$, finds the minimum number of rubles Andrew can get after buying dollar and euro bills. | 512 megabytes | import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
public class cf1214a {
static int[] weights;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// BufferedReader bu = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
int rubles = sc.nextInt();
int dollarcost = sc.nextInt();
int eurocost = sc.nextInt()*5;
int best = rubles;
for (int i = 0; i <= rubles; i++) {
if (dollarcost*i > rubles) {
break;
}
int rem = rubles-i*dollarcost;
int e = rem/eurocost;
int left = rem-e*eurocost;
best = Math.min(left, best);
}
System.out.println(best);
}
}
/*
100000000
30
45
*/ | Java | ["100\n60\n70", "410\n55\n70", "600\n60\n70"] | 1.5 seconds | ["40", "5", "0"] | NoteIn the first example, we can buy just $$$1$$$ dollar because there is no $$$1$$$ euro bill.In the second example, optimal exchange is to buy $$$5$$$ euro and $$$1$$$ dollar.In the third example, optimal exchange is to buy $$$10$$$ dollars in one bill. | Java 8 | standard input | [
"brute force",
"math"
] | 8c5d9b4fd297706fac3be83fc85028a0 | The first line of the input contains one integer $$$n$$$ ($$$1 \leq n \leq 10^8$$$)Β β the initial sum in rubles Andrew has. The second line of the input contains one integer $$$d$$$ ($$$30 \leq d \leq 100$$$)Β β the price of one dollar in rubles. The third line of the input contains integer $$$e$$$ ($$$30 \leq e \leq 100$$$)Β β the price of one euro in rubles. | 1,400 | Output one integerΒ β the minimum number of rubles Andrew can have after buying dollar and euro bills optimally. | standard output | |
PASSED | 959b56a59a5d3b6ab160682f22cdc631 | train_003.jsonl | 1567587900 | Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has $$$n$$$ rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar is $$$d$$$ rubles, and one euro costs $$$e$$$ rubles.Recall that there exist the following dollar bills: $$$1$$$, $$$2$$$, $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, and the following euro billsΒ β $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, $$$200$$$ (note that, in this problem we do not consider the $$$500$$$ euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.Help himΒ β write a program that given integers $$$n$$$, $$$e$$$ and $$$d$$$, finds the minimum number of rubles Andrew can get after buying dollar and euro bills. | 512 megabytes | import java.io.*;
import java.util.*;
import static java.lang.Math.*;
public class Main {
void problem() {
int n = in.nextInt();
int d = in.nextInt();
int e = in.nextInt() * 5;
int ans = n;
for (int i = 0; i <= n; i += e) {
ans = min(ans, (n - i) % d);
}
out.println(ans);
}
void run() {
in = new FastScanner();
out = new PrintWriter(System.out);
problem();
out.close();
}
class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
// public FastScanner(String s) {
// try {
// br = new BufferedReader(new FileReader(s));
// } catch (FileNotFoundException e) {
// e.printStackTrace();
// }
// }
public String nextToken() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(nextToken());
}
public long nextLong() {
return Long.parseLong(nextToken());
}
public double nextDouble() {
return Double.parseDouble(nextToken());
}
}
public static void main(String[] args) {
new Main().run();
}
FastScanner in;
PrintWriter out;
} | Java | ["100\n60\n70", "410\n55\n70", "600\n60\n70"] | 1.5 seconds | ["40", "5", "0"] | NoteIn the first example, we can buy just $$$1$$$ dollar because there is no $$$1$$$ euro bill.In the second example, optimal exchange is to buy $$$5$$$ euro and $$$1$$$ dollar.In the third example, optimal exchange is to buy $$$10$$$ dollars in one bill. | Java 8 | standard input | [
"brute force",
"math"
] | 8c5d9b4fd297706fac3be83fc85028a0 | The first line of the input contains one integer $$$n$$$ ($$$1 \leq n \leq 10^8$$$)Β β the initial sum in rubles Andrew has. The second line of the input contains one integer $$$d$$$ ($$$30 \leq d \leq 100$$$)Β β the price of one dollar in rubles. The third line of the input contains integer $$$e$$$ ($$$30 \leq e \leq 100$$$)Β β the price of one euro in rubles. | 1,400 | Output one integerΒ β the minimum number of rubles Andrew can have after buying dollar and euro bills optimally. | standard output | |
PASSED | ab493bec7a0b8eff8485d1dd5bca9620 | train_003.jsonl | 1567587900 | Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has $$$n$$$ rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar is $$$d$$$ rubles, and one euro costs $$$e$$$ rubles.Recall that there exist the following dollar bills: $$$1$$$, $$$2$$$, $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, and the following euro billsΒ β $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, $$$200$$$ (note that, in this problem we do not consider the $$$500$$$ euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.Help himΒ β write a program that given integers $$$n$$$, $$$e$$$ and $$$d$$$, finds the minimum number of rubles Andrew can get after buying dollar and euro bills. | 512 megabytes | import java.util.Scanner;
public class Solution {
public static void main(String args[]) {
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int d=s.nextInt();
int e=s.nextInt();
System.out.println(remainingRubles(n,d,e));
}
public static int remainingRubles(int n,int d,int e)
{
int minRemaining=n;
int rubles=n;
while(rubles>=0)
{
if(rubles%(5*e)<minRemaining)
{
minRemaining=rubles%(5*e);
}
rubles-=d;
}
rubles=n;
while(rubles>=0)
{
if(rubles%d<minRemaining)
{
minRemaining=rubles%(d);
}
rubles-=(5*e);
}
return minRemaining;
}
} | Java | ["100\n60\n70", "410\n55\n70", "600\n60\n70"] | 1.5 seconds | ["40", "5", "0"] | NoteIn the first example, we can buy just $$$1$$$ dollar because there is no $$$1$$$ euro bill.In the second example, optimal exchange is to buy $$$5$$$ euro and $$$1$$$ dollar.In the third example, optimal exchange is to buy $$$10$$$ dollars in one bill. | Java 8 | standard input | [
"brute force",
"math"
] | 8c5d9b4fd297706fac3be83fc85028a0 | The first line of the input contains one integer $$$n$$$ ($$$1 \leq n \leq 10^8$$$)Β β the initial sum in rubles Andrew has. The second line of the input contains one integer $$$d$$$ ($$$30 \leq d \leq 100$$$)Β β the price of one dollar in rubles. The third line of the input contains integer $$$e$$$ ($$$30 \leq e \leq 100$$$)Β β the price of one euro in rubles. | 1,400 | Output one integerΒ β the minimum number of rubles Andrew can have after buying dollar and euro bills optimally. | standard output | |
PASSED | e52a6a8a3652d4d64f946b3953d732ad | train_003.jsonl | 1567587900 | Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has $$$n$$$ rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar is $$$d$$$ rubles, and one euro costs $$$e$$$ rubles.Recall that there exist the following dollar bills: $$$1$$$, $$$2$$$, $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, and the following euro billsΒ β $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, $$$200$$$ (note that, in this problem we do not consider the $$$500$$$ euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.Help himΒ β write a program that given integers $$$n$$$, $$$e$$$ and $$$d$$$, finds the minimum number of rubles Andrew can get after buying dollar and euro bills. | 512 megabytes | //package main;
import java.io.*;
import java.util.*;
public final class Main {
Scanner sc;
public static void main(String[] args) throws Exception {
new Thread(null, new Main()::run, "main", 1 << 28).start();
}
{
sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
}
void run() {
long n = sc.nextLong();
long d = sc.nextLong();
long e = sc.nextLong();
long ans = n;
for(long i=0; i * e * 5L <= n; i++) {
ans = Math.min(ans, (n - (i * e * 5L)) % d);
}
System.out.println(ans);
}
} | Java | ["100\n60\n70", "410\n55\n70", "600\n60\n70"] | 1.5 seconds | ["40", "5", "0"] | NoteIn the first example, we can buy just $$$1$$$ dollar because there is no $$$1$$$ euro bill.In the second example, optimal exchange is to buy $$$5$$$ euro and $$$1$$$ dollar.In the third example, optimal exchange is to buy $$$10$$$ dollars in one bill. | Java 8 | standard input | [
"brute force",
"math"
] | 8c5d9b4fd297706fac3be83fc85028a0 | The first line of the input contains one integer $$$n$$$ ($$$1 \leq n \leq 10^8$$$)Β β the initial sum in rubles Andrew has. The second line of the input contains one integer $$$d$$$ ($$$30 \leq d \leq 100$$$)Β β the price of one dollar in rubles. The third line of the input contains integer $$$e$$$ ($$$30 \leq e \leq 100$$$)Β β the price of one euro in rubles. | 1,400 | Output one integerΒ β the minimum number of rubles Andrew can have after buying dollar and euro bills optimally. | standard output | |
PASSED | a878927c51472805c991231afc24a518 | train_003.jsonl | 1567587900 | Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has $$$n$$$ rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar is $$$d$$$ rubles, and one euro costs $$$e$$$ rubles.Recall that there exist the following dollar bills: $$$1$$$, $$$2$$$, $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, and the following euro billsΒ β $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, $$$200$$$ (note that, in this problem we do not consider the $$$500$$$ euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.Help himΒ β write a program that given integers $$$n$$$, $$$e$$$ and $$$d$$$, finds the minimum number of rubles Andrew can get after buying dollar and euro bills. | 512 megabytes | import java.util.*;
import java.lang.*;
import java.math.*;
public class tc_5_1 {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int n=scn.nextInt();
int d=scn.nextInt();
int e=scn.nextInt();
int dn=0;
int de=0;
int ans=Integer.MAX_VALUE;
while((e*de)<=n) {
ans=Math.min(ans,(n-de*e)-((n-(de*e))/d)*d);
de+=5;
}
System.out.println(ans);
}
} | Java | ["100\n60\n70", "410\n55\n70", "600\n60\n70"] | 1.5 seconds | ["40", "5", "0"] | NoteIn the first example, we can buy just $$$1$$$ dollar because there is no $$$1$$$ euro bill.In the second example, optimal exchange is to buy $$$5$$$ euro and $$$1$$$ dollar.In the third example, optimal exchange is to buy $$$10$$$ dollars in one bill. | Java 8 | standard input | [
"brute force",
"math"
] | 8c5d9b4fd297706fac3be83fc85028a0 | The first line of the input contains one integer $$$n$$$ ($$$1 \leq n \leq 10^8$$$)Β β the initial sum in rubles Andrew has. The second line of the input contains one integer $$$d$$$ ($$$30 \leq d \leq 100$$$)Β β the price of one dollar in rubles. The third line of the input contains integer $$$e$$$ ($$$30 \leq e \leq 100$$$)Β β the price of one euro in rubles. | 1,400 | Output one integerΒ β the minimum number of rubles Andrew can have after buying dollar and euro bills optimally. | standard output | |
PASSED | a7ec3575b943be28866630730b8fd8be | train_003.jsonl | 1567587900 | Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has $$$n$$$ rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar is $$$d$$$ rubles, and one euro costs $$$e$$$ rubles.Recall that there exist the following dollar bills: $$$1$$$, $$$2$$$, $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, and the following euro billsΒ β $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, $$$200$$$ (note that, in this problem we do not consider the $$$500$$$ euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.Help himΒ β write a program that given integers $$$n$$$, $$$e$$$ and $$$d$$$, finds the minimum number of rubles Andrew can get after buying dollar and euro bills. | 512 megabytes | import java.util.Scanner;
public class Codeforces {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int dollar=s.nextInt();
int euro=5*s.nextInt();
int i=0;
int ans=Integer.MAX_VALUE;
while (i*dollar<=n){
ans=Math.min(ans,(n-(i*dollar))%euro);
i++;
}
System.out.println(ans);
}
}
| Java | ["100\n60\n70", "410\n55\n70", "600\n60\n70"] | 1.5 seconds | ["40", "5", "0"] | NoteIn the first example, we can buy just $$$1$$$ dollar because there is no $$$1$$$ euro bill.In the second example, optimal exchange is to buy $$$5$$$ euro and $$$1$$$ dollar.In the third example, optimal exchange is to buy $$$10$$$ dollars in one bill. | Java 8 | standard input | [
"brute force",
"math"
] | 8c5d9b4fd297706fac3be83fc85028a0 | The first line of the input contains one integer $$$n$$$ ($$$1 \leq n \leq 10^8$$$)Β β the initial sum in rubles Andrew has. The second line of the input contains one integer $$$d$$$ ($$$30 \leq d \leq 100$$$)Β β the price of one dollar in rubles. The third line of the input contains integer $$$e$$$ ($$$30 \leq e \leq 100$$$)Β β the price of one euro in rubles. | 1,400 | Output one integerΒ β the minimum number of rubles Andrew can have after buying dollar and euro bills optimally. | standard output | |
PASSED | 850f941797ab802e329dc2576e9b1ddb | train_003.jsonl | 1567587900 | Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has $$$n$$$ rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar is $$$d$$$ rubles, and one euro costs $$$e$$$ rubles.Recall that there exist the following dollar bills: $$$1$$$, $$$2$$$, $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, and the following euro billsΒ β $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, $$$200$$$ (note that, in this problem we do not consider the $$$500$$$ euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.Help himΒ β write a program that given integers $$$n$$$, $$$e$$$ and $$$d$$$, finds the minimum number of rubles Andrew can get after buying dollar and euro bills. | 512 megabytes | import java.io.*;
import java.util.*;
public class ProblemA {
BufferedReader in;
PrintWriter out;
StringTokenizer ss;
String _token() throws IOException {
while (!ss.hasMoreTokens())
ss = new StringTokenizer(in.readLine());
return ss.nextToken();
}
int _int() throws IOException {
return Integer.parseInt(_token());
}
void RUN() throws IOException {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
ss = new StringTokenizer(" ");
int n = _int();
int d= _int();
int e= _int()*5;
int ans=n;
for(int i=0;i*e<=n;i++) {
ans=Math.min(ans,(n-i*e)%d);
}
out.println(ans);
out.close();
}
public static void main(String[] args) throws Exception {
try {
new ProblemA().RUN();
} catch (Exception e) {
System.out.println("RE");
}
}
}
| Java | ["100\n60\n70", "410\n55\n70", "600\n60\n70"] | 1.5 seconds | ["40", "5", "0"] | NoteIn the first example, we can buy just $$$1$$$ dollar because there is no $$$1$$$ euro bill.In the second example, optimal exchange is to buy $$$5$$$ euro and $$$1$$$ dollar.In the third example, optimal exchange is to buy $$$10$$$ dollars in one bill. | Java 8 | standard input | [
"brute force",
"math"
] | 8c5d9b4fd297706fac3be83fc85028a0 | The first line of the input contains one integer $$$n$$$ ($$$1 \leq n \leq 10^8$$$)Β β the initial sum in rubles Andrew has. The second line of the input contains one integer $$$d$$$ ($$$30 \leq d \leq 100$$$)Β β the price of one dollar in rubles. The third line of the input contains integer $$$e$$$ ($$$30 \leq e \leq 100$$$)Β β the price of one euro in rubles. | 1,400 | Output one integerΒ β the minimum number of rubles Andrew can have after buying dollar and euro bills optimally. | standard output | |
PASSED | f2ae2d8144e5f58e934f95a19f8c2183 | train_003.jsonl | 1567587900 | Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has $$$n$$$ rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar is $$$d$$$ rubles, and one euro costs $$$e$$$ rubles.Recall that there exist the following dollar bills: $$$1$$$, $$$2$$$, $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, and the following euro billsΒ β $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, $$$200$$$ (note that, in this problem we do not consider the $$$500$$$ euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.Help himΒ β write a program that given integers $$$n$$$, $$$e$$$ and $$$d$$$, finds the minimum number of rubles Andrew can get after buying dollar and euro bills. | 512 megabytes | import java.io.*;
import java.util.*;
public class Laba {
FScanner fs;
PrintWriter pw;
int n, m;
boolean[] used;
int[][] dst;
long[] t;
HashMap<String, HashMap<String, Integer>> g;
HashSet<Character> goods = new HashSet<>();
public static void main(String[] args) throws IOException {
new Laba().start();
}
public void start() throws IOException {
fs = new FScanner(new InputStreamReader(System.in));
// reader = new FScanner(new FileReader("input"));
//pw = new PrintWriter("input.txt");
pw = new PrintWriter(System.out);
int n = fs.nextInt(), d = fs.nextInt(), e = fs.nextInt() * 5;
if (n < d)
pw.println(n);
else {
int ans = n % d;
while (n >= e) {
n -= e;
ans = Math.min(ans, n % d);
}
pw.println(ans);
}
pw.close();
}
void build(long a[], int v, int tl, int tr) {
if (tl == tr)
t[v] = a[tl];
else {
int tm = (tl + tr) / 2;
build(a, v * 2, tl, tm);
build(a, v * 2 + 1, tm + 1, tr);
t[v] = t[v * 2] + t[v * 2 + 1];
}
}
void update(int v, int tl, int tr, int pos, long new_val) {
if (tl == tr)
t[v] = new_val;
else {
int tm = (tl + tr) / 2;
if (pos <= tm)
update(v * 2, tl, tm, pos, new_val);
else
update(v * 2 + 1, tm + 1, tr, pos, new_val);
t[v] = t[v * 2] + t[v * 2 + 1];
}
}
long sum(int v, int tl, int tr, int l, int r) {
if (l > r)
return 0;
if (l == tl && r == tr)
return t[v];
int tm = (tl + tr) / 2;
return sum(v * 2, tl, tm, l, Math.min(r, tm))
+ sum(v * 2 + 1, tm + 1, tr, Math.max(l, tm + 1), r);
}
int findss(int v, int tl, int tr, long sum) {
if (sum > t[v])
return -1;
if (tl == tr)
return tl;
int tm = (tl + tr) / 2;
if (t[v * 2] > sum) {
return findss(v * 2, tl, tm, sum);
} else {
return findss(v * 2 + 1, tm + 1, tr, sum - t[v * 2]);
}
}
}
class Pair {
int x, y;
Pair(int x1, int y1) {
x = x1;
y = y1;
}
}
class FScanner {
StringTokenizer st;
BufferedReader reader;
FScanner(InputStreamReader isr) throws IOException {
reader = new BufferedReader(isr);
}
String nextLine() throws IOException {
return reader.readLine();
}
String nextToken() throws IOException {
while (st == null || !st.hasMoreTokens()) {
String s = reader.readLine();
if (s == null)
return null;
st = new StringTokenizer(s);
}
return st.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
char nextChar() throws IOException {
return (char) reader.read();
}
long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
int[] iarr(int n) throws IOException {
int[] mas = new int[n];
for (int i = 0; i < n; i++)
mas[i] = nextInt();
return mas;
}
double[] darr(int n) throws IOException {
double[] mas = new double[n];
for (int i = 0; i < n; i++)
mas[i] = nextDouble();
return mas;
}
char[][] cmas2(int n, int m) throws IOException {
char[][] mas = new char[n][m];
for (int i = 0; i < n; i++)
mas[i] = nextLine().toCharArray();
return mas;
}
long[] larr(int n) throws IOException {
long[] mas = new long[n];
for (int i = 0; i < n; i++)
mas[i] = nextLong();
return mas;
}
} | Java | ["100\n60\n70", "410\n55\n70", "600\n60\n70"] | 1.5 seconds | ["40", "5", "0"] | NoteIn the first example, we can buy just $$$1$$$ dollar because there is no $$$1$$$ euro bill.In the second example, optimal exchange is to buy $$$5$$$ euro and $$$1$$$ dollar.In the third example, optimal exchange is to buy $$$10$$$ dollars in one bill. | Java 8 | standard input | [
"brute force",
"math"
] | 8c5d9b4fd297706fac3be83fc85028a0 | The first line of the input contains one integer $$$n$$$ ($$$1 \leq n \leq 10^8$$$)Β β the initial sum in rubles Andrew has. The second line of the input contains one integer $$$d$$$ ($$$30 \leq d \leq 100$$$)Β β the price of one dollar in rubles. The third line of the input contains integer $$$e$$$ ($$$30 \leq e \leq 100$$$)Β β the price of one euro in rubles. | 1,400 | Output one integerΒ β the minimum number of rubles Andrew can have after buying dollar and euro bills optimally. | standard output | |
PASSED | b7eafe620116acc7b3c82d8ac125f4f7 | train_003.jsonl | 1567587900 | Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has $$$n$$$ rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar is $$$d$$$ rubles, and one euro costs $$$e$$$ rubles.Recall that there exist the following dollar bills: $$$1$$$, $$$2$$$, $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, and the following euro billsΒ β $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, $$$200$$$ (note that, in this problem we do not consider the $$$500$$$ euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.Help himΒ β write a program that given integers $$$n$$$, $$$e$$$ and $$$d$$$, finds the minimum number of rubles Andrew can get after buying dollar and euro bills. | 512 megabytes | import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner S=new Scanner(System.in);
int n=S.nextInt();
int d=S.nextInt();
int e=S.nextInt();
int ans=0x3f3f3f3f;
e*=5;
for(int i=0;i*d<=n;i++){
ans=Math.min(ans,n-i*d-(n-i*d)/e*e);
}
System.out.println(ans);
}} | Java | ["100\n60\n70", "410\n55\n70", "600\n60\n70"] | 1.5 seconds | ["40", "5", "0"] | NoteIn the first example, we can buy just $$$1$$$ dollar because there is no $$$1$$$ euro bill.In the second example, optimal exchange is to buy $$$5$$$ euro and $$$1$$$ dollar.In the third example, optimal exchange is to buy $$$10$$$ dollars in one bill. | Java 8 | standard input | [
"brute force",
"math"
] | 8c5d9b4fd297706fac3be83fc85028a0 | The first line of the input contains one integer $$$n$$$ ($$$1 \leq n \leq 10^8$$$)Β β the initial sum in rubles Andrew has. The second line of the input contains one integer $$$d$$$ ($$$30 \leq d \leq 100$$$)Β β the price of one dollar in rubles. The third line of the input contains integer $$$e$$$ ($$$30 \leq e \leq 100$$$)Β β the price of one euro in rubles. | 1,400 | Output one integerΒ β the minimum number of rubles Andrew can have after buying dollar and euro bills optimally. | standard output | |
PASSED | 5c90621d2dbf12312f47c26a3b57af88 | train_003.jsonl | 1567587900 | Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has $$$n$$$ rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar is $$$d$$$ rubles, and one euro costs $$$e$$$ rubles.Recall that there exist the following dollar bills: $$$1$$$, $$$2$$$, $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, and the following euro billsΒ β $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, $$$200$$$ (note that, in this problem we do not consider the $$$500$$$ euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.Help himΒ β write a program that given integers $$$n$$$, $$$e$$$ and $$$d$$$, finds the minimum number of rubles Andrew can get after buying dollar and euro bills. | 512 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class OptimalCurrencyExchange {
static class MyScanner {
private BufferedReader br;
private StringTokenizer st;
MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args) {
MyScanner sc = new MyScanner();
int rubles = sc.nextInt();
int dolarPrice = sc.nextInt(); //dollar bills: 1, 2, 5, 10, 20, 50, 100
int euroPrice = sc.nextInt() * 5; //euro bills β 5, 10, 20, 50, 100, 200
int ans = rubles;
for (int e=0; e * euroPrice <= rubles; ++e) {
int restRublesNoEuro = rubles - e * euroPrice;
int restRublesNoEuroNoDolar = restRublesNoEuro % dolarPrice;
ans = Math.min(ans, restRublesNoEuroNoDolar);
}
System.out.println(ans);
}
}
| Java | ["100\n60\n70", "410\n55\n70", "600\n60\n70"] | 1.5 seconds | ["40", "5", "0"] | NoteIn the first example, we can buy just $$$1$$$ dollar because there is no $$$1$$$ euro bill.In the second example, optimal exchange is to buy $$$5$$$ euro and $$$1$$$ dollar.In the third example, optimal exchange is to buy $$$10$$$ dollars in one bill. | Java 8 | standard input | [
"brute force",
"math"
] | 8c5d9b4fd297706fac3be83fc85028a0 | The first line of the input contains one integer $$$n$$$ ($$$1 \leq n \leq 10^8$$$)Β β the initial sum in rubles Andrew has. The second line of the input contains one integer $$$d$$$ ($$$30 \leq d \leq 100$$$)Β β the price of one dollar in rubles. The third line of the input contains integer $$$e$$$ ($$$30 \leq e \leq 100$$$)Β β the price of one euro in rubles. | 1,400 | Output one integerΒ β the minimum number of rubles Andrew can have after buying dollar and euro bills optimally. | standard output | |
PASSED | 4271e936fef3d508cd4a1040f26c3e43 | train_003.jsonl | 1567587900 | Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has $$$n$$$ rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar is $$$d$$$ rubles, and one euro costs $$$e$$$ rubles.Recall that there exist the following dollar bills: $$$1$$$, $$$2$$$, $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, and the following euro billsΒ β $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, $$$200$$$ (note that, in this problem we do not consider the $$$500$$$ euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.Help himΒ β write a program that given integers $$$n$$$, $$$e$$$ and $$$d$$$, finds the minimum number of rubles Andrew can get after buying dollar and euro bills. | 512 megabytes | import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
int n=sc.nextInt();
int d=sc.nextInt();
int e=sc.nextInt();
int r1,r2=n;
for(int i=0;i*5*e<=n;i++){
r1=(n-i*5*e)%(d);
if(r1<r2){
r2=r1;
}
}
System.out.println(r2);
}
} | Java | ["100\n60\n70", "410\n55\n70", "600\n60\n70"] | 1.5 seconds | ["40", "5", "0"] | NoteIn the first example, we can buy just $$$1$$$ dollar because there is no $$$1$$$ euro bill.In the second example, optimal exchange is to buy $$$5$$$ euro and $$$1$$$ dollar.In the third example, optimal exchange is to buy $$$10$$$ dollars in one bill. | Java 8 | standard input | [
"brute force",
"math"
] | 8c5d9b4fd297706fac3be83fc85028a0 | The first line of the input contains one integer $$$n$$$ ($$$1 \leq n \leq 10^8$$$)Β β the initial sum in rubles Andrew has. The second line of the input contains one integer $$$d$$$ ($$$30 \leq d \leq 100$$$)Β β the price of one dollar in rubles. The third line of the input contains integer $$$e$$$ ($$$30 \leq e \leq 100$$$)Β β the price of one euro in rubles. | 1,400 | Output one integerΒ β the minimum number of rubles Andrew can have after buying dollar and euro bills optimally. | standard output | |
PASSED | 63df97f78b07474ce5a584c90025fd37 | train_003.jsonl | 1567587900 | Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has $$$n$$$ rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar is $$$d$$$ rubles, and one euro costs $$$e$$$ rubles.Recall that there exist the following dollar bills: $$$1$$$, $$$2$$$, $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, and the following euro billsΒ β $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, $$$200$$$ (note that, in this problem we do not consider the $$$500$$$ euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.Help himΒ β write a program that given integers $$$n$$$, $$$e$$$ and $$$d$$$, finds the minimum number of rubles Andrew can get after buying dollar and euro bills. | 512 megabytes | import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
int n=sc.nextInt();
int d=sc.nextInt();
int e=sc.nextInt();
int r1,r2=n;
for(int i=0;i*d<=n;i++){
r1=(n-i*d)%(5*e);
if(r1<r2){
r2=r1;
}
}
System.out.println(r2);
}
}
| Java | ["100\n60\n70", "410\n55\n70", "600\n60\n70"] | 1.5 seconds | ["40", "5", "0"] | NoteIn the first example, we can buy just $$$1$$$ dollar because there is no $$$1$$$ euro bill.In the second example, optimal exchange is to buy $$$5$$$ euro and $$$1$$$ dollar.In the third example, optimal exchange is to buy $$$10$$$ dollars in one bill. | Java 8 | standard input | [
"brute force",
"math"
] | 8c5d9b4fd297706fac3be83fc85028a0 | The first line of the input contains one integer $$$n$$$ ($$$1 \leq n \leq 10^8$$$)Β β the initial sum in rubles Andrew has. The second line of the input contains one integer $$$d$$$ ($$$30 \leq d \leq 100$$$)Β β the price of one dollar in rubles. The third line of the input contains integer $$$e$$$ ($$$30 \leq e \leq 100$$$)Β β the price of one euro in rubles. | 1,400 | Output one integerΒ β the minimum number of rubles Andrew can have after buying dollar and euro bills optimally. | standard output | |
PASSED | bd20aed8e8f1079ea4211f87d54d8b38 | train_003.jsonl | 1567587900 | Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has $$$n$$$ rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar is $$$d$$$ rubles, and one euro costs $$$e$$$ rubles.Recall that there exist the following dollar bills: $$$1$$$, $$$2$$$, $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, and the following euro billsΒ β $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, $$$200$$$ (note that, in this problem we do not consider the $$$500$$$ euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.Help himΒ β write a program that given integers $$$n$$$, $$$e$$$ and $$$d$$$, finds the minimum number of rubles Andrew can get after buying dollar and euro bills. | 512 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// write your code here
Scanner sc = new Scanner(System.in);
long n = sc.nextInt();
long d = sc.nextInt();
long e = sc.nextInt();
long nAns = n;
for (int i = 0; i < 10000000; i++) {
long buy = e * 5 * i;
long money = n;
if (n >= buy) {
money -= buy;
}
if (money >= d) {
money -= d * (money / d);
}
if (money < nAns){
nAns = Math.min(nAns, money);
}
}
System.out.println(nAns);
}
}
| Java | ["100\n60\n70", "410\n55\n70", "600\n60\n70"] | 1.5 seconds | ["40", "5", "0"] | NoteIn the first example, we can buy just $$$1$$$ dollar because there is no $$$1$$$ euro bill.In the second example, optimal exchange is to buy $$$5$$$ euro and $$$1$$$ dollar.In the third example, optimal exchange is to buy $$$10$$$ dollars in one bill. | Java 8 | standard input | [
"brute force",
"math"
] | 8c5d9b4fd297706fac3be83fc85028a0 | The first line of the input contains one integer $$$n$$$ ($$$1 \leq n \leq 10^8$$$)Β β the initial sum in rubles Andrew has. The second line of the input contains one integer $$$d$$$ ($$$30 \leq d \leq 100$$$)Β β the price of one dollar in rubles. The third line of the input contains integer $$$e$$$ ($$$30 \leq e \leq 100$$$)Β β the price of one euro in rubles. | 1,400 | Output one integerΒ β the minimum number of rubles Andrew can have after buying dollar and euro bills optimally. | standard output | |
PASSED | 456c4a878e1cb3e6b4fc9e45d67b1778 | train_003.jsonl | 1567587900 | Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has $$$n$$$ rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar is $$$d$$$ rubles, and one euro costs $$$e$$$ rubles.Recall that there exist the following dollar bills: $$$1$$$, $$$2$$$, $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, and the following euro billsΒ β $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, $$$200$$$ (note that, in this problem we do not consider the $$$500$$$ euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.Help himΒ β write a program that given integers $$$n$$$, $$$e$$$ and $$$d$$$, finds the minimum number of rubles Andrew can get after buying dollar and euro bills. | 512 megabytes | import java.io.*;
import java.util.*;
public class Program {
public static void main(String[] argv) throws IOException {
In cin = new In(new BufferedReader(new InputStreamReader(System.in)));
PrintWriter cout = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
int n = cin.nextInt(), d = cin.nextInt(), e = cin.nextInt(); e *= 5;
int sol = n % d;
while (n >= 0) {
sol = Math.min(sol, n % d);
n -= e;
}
cout.println(sol);
cout.close();
}
static String swapString(String str, int i, int j) {
StringBuilder sb = new StringBuilder(str);
sb.setCharAt(i, str.charAt(j));
sb.setCharAt(j, str.charAt(i));
return sb.toString();
}
static boolean diffNums(int n) {
int count = 0;
String number = Integer.toString(n);
for (int i = 0; i < number.length() - 1; i++) {
for (int j = i + 1; j < number.length(); j++) {
if (number.charAt(i) == number.charAt(j)) {
return false;
}
}
}
return true;
}
protected static class In {
private BufferedReader reader;
private StringTokenizer tokenizer = new StringTokenizer("");
public In(BufferedReader reader) {
this.reader = reader;
}
public String next() throws IOException {
while (!tokenizer.hasMoreTokens())
tokenizer = new StringTokenizer(reader.readLine());
return tokenizer.nextToken();
}
public String nextLine() throws IOException {
return reader.readLine();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
}
} | Java | ["100\n60\n70", "410\n55\n70", "600\n60\n70"] | 1.5 seconds | ["40", "5", "0"] | NoteIn the first example, we can buy just $$$1$$$ dollar because there is no $$$1$$$ euro bill.In the second example, optimal exchange is to buy $$$5$$$ euro and $$$1$$$ dollar.In the third example, optimal exchange is to buy $$$10$$$ dollars in one bill. | Java 8 | standard input | [
"brute force",
"math"
] | 8c5d9b4fd297706fac3be83fc85028a0 | The first line of the input contains one integer $$$n$$$ ($$$1 \leq n \leq 10^8$$$)Β β the initial sum in rubles Andrew has. The second line of the input contains one integer $$$d$$$ ($$$30 \leq d \leq 100$$$)Β β the price of one dollar in rubles. The third line of the input contains integer $$$e$$$ ($$$30 \leq e \leq 100$$$)Β β the price of one euro in rubles. | 1,400 | Output one integerΒ β the minimum number of rubles Andrew can have after buying dollar and euro bills optimally. | standard output | |
PASSED | 1a571a4197a1d088ccf815894d3e1809 | train_003.jsonl | 1567587900 | Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has $$$n$$$ rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar is $$$d$$$ rubles, and one euro costs $$$e$$$ rubles.Recall that there exist the following dollar bills: $$$1$$$, $$$2$$$, $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, and the following euro billsΒ β $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, $$$200$$$ (note that, in this problem we do not consider the $$$500$$$ euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.Help himΒ β write a program that given integers $$$n$$$, $$$e$$$ and $$$d$$$, finds the minimum number of rubles Andrew can get after buying dollar and euro bills. | 512 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author Jenish
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
ScanReader in = new ScanReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
AOptimalCurrencyExchange solver = new AOptimalCurrencyExchange();
solver.solve(1, in, out);
out.close();
}
static class AOptimalCurrencyExchange {
public void solve(int testNumber, ScanReader in, PrintWriter out) {
long n = in.scanLong();
long d = in.scanLong();
long e = in.scanLong();
long a = d;
long b = 5 * e;
long ans = Long.MAX_VALUE;
for (long y = 0; y * b <= n; y++) {
long temp = n - y * b;
ans = Math.min(ans, temp % d);
}
out.println(ans);
}
}
static class ScanReader {
private byte[] buf = new byte[4 * 1024];
private int INDEX;
private BufferedInputStream in;
private int TOTAL;
public ScanReader(InputStream inputStream) {
in = new BufferedInputStream(inputStream);
}
private int scan() {
if (INDEX >= TOTAL) {
INDEX = 0;
try {
TOTAL = in.read(buf);
} catch (Exception e) {
e.printStackTrace();
}
if (TOTAL <= 0) return -1;
}
return buf[INDEX++];
}
private boolean isWhiteSpace(int n) {
if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
else return false;
}
public long scanLong() {
long I = 0;
int n = scan();
while (isWhiteSpace(n)) n = scan();
int neg = 1;
if (n == '-') {
neg = -1;
n = scan();
}
while (!isWhiteSpace(n)) {
if (n >= '0' && n <= '9') {
I *= 10;
I += n - '0';
n = scan();
}
}
return neg * I;
}
}
}
| Java | ["100\n60\n70", "410\n55\n70", "600\n60\n70"] | 1.5 seconds | ["40", "5", "0"] | NoteIn the first example, we can buy just $$$1$$$ dollar because there is no $$$1$$$ euro bill.In the second example, optimal exchange is to buy $$$5$$$ euro and $$$1$$$ dollar.In the third example, optimal exchange is to buy $$$10$$$ dollars in one bill. | Java 8 | standard input | [
"brute force",
"math"
] | 8c5d9b4fd297706fac3be83fc85028a0 | The first line of the input contains one integer $$$n$$$ ($$$1 \leq n \leq 10^8$$$)Β β the initial sum in rubles Andrew has. The second line of the input contains one integer $$$d$$$ ($$$30 \leq d \leq 100$$$)Β β the price of one dollar in rubles. The third line of the input contains integer $$$e$$$ ($$$30 \leq e \leq 100$$$)Β β the price of one euro in rubles. | 1,400 | Output one integerΒ β the minimum number of rubles Andrew can have after buying dollar and euro bills optimally. | standard output | |
PASSED | a1110cf79e57ea90ed8ad27900510bb8 | train_003.jsonl | 1567587900 | Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has $$$n$$$ rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar is $$$d$$$ rubles, and one euro costs $$$e$$$ rubles.Recall that there exist the following dollar bills: $$$1$$$, $$$2$$$, $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, and the following euro billsΒ β $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, $$$200$$$ (note that, in this problem we do not consider the $$$500$$$ euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.Help himΒ β write a program that given integers $$$n$$$, $$$e$$$ and $$$d$$$, finds the minimum number of rubles Andrew can get after buying dollar and euro bills. | 512 megabytes | import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.Random;
import java.io.PrintWriter;
/*
Solution Created: 16:44:52 11/09/2019
Custom Competitive programming helper.
*/
public class Main {
public static void solve(Reader in, Writer out) {
int n = in.nextInt();
int d = in.nextInt();
int e = in.nextInt()*5;
int ans = n;
for(int i = 0; i*d<=n; i++) ans = Math.min(ans, (n-i*d)%e);
out.println(ans);
}
public static void main(String[] args) {
Reader in = new Reader();
Writer out = new Writer();
solve(in, out);
out.exit();
}
static class Graph {
private ArrayList<Integer> con[];
private boolean[] visited;
public Graph(int n) {
con = new ArrayList[n];
for (int i = 0; i < n; ++i)
con[i] = new ArrayList();
visited = new boolean[n];
}
public void reset() {
Arrays.fill(visited, false);
}
public void addEdge(int v, int w) {
con[v].add(w);
}
public void dfs(int cur) {
visited[cur] = true;
for (Integer v : con[cur]) {
if (!visited[v]) {
dfs(v);
}
}
}
public void bfs(int cur) {
Queue<Integer> q = new LinkedList<>();
q.add(cur);
visited[cur] = true;
while (!q.isEmpty()) {
cur = q.poll();
for (Integer v : con[cur]) {
if (!visited[v]) {
visited[v] = true;
q.add(v);
}
}
}
}
}
static class Reader {
static BufferedReader br;
static StringTokenizer st;
private int charIdx = 0;
private String s;
public Reader() {
this.br = new BufferedReader(new InputStreamReader(System.in));
}
public int[] na(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public double[] nd(int n) {
double[] a = new double[n];
for (int i = 0; i < n; i++)
a[i] = nextDouble();
return a;
}
public char nextChar() {
if (s == null || charIdx >= s.length()) {
if (st == null || !st.hasMoreTokens())
try {
readLine();
} catch (Exception e) {
}
s = st.nextToken();
charIdx = 0;
}
return s.charAt(charIdx++);
}
public long[] nl(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public char[] nca() {
return next().toCharArray();
}
public String[] nS(int n) {
String[] a = new String[n];
for (int i = 0; i < n; i++)
a[i] = next();
return a;
}
public int nextInt() {
if (st == null || !st.hasMoreTokens())
try {
readLine();
} catch (Exception e) {
}
return Integer.parseInt(st.nextToken());
}
public double nextDouble() {
if (st == null || !st.hasMoreTokens())
try {
readLine();
} catch (Exception e) {
}
return Double.parseDouble(st.nextToken());
}
public Long nextLong() {
if (st == null || !st.hasMoreTokens())
try {
readLine();
} catch (Exception e) {
}
return Long.parseLong(st.nextToken());
}
public String next() {
if (st == null || !st.hasMoreTokens())
try {
readLine();
} catch (Exception e) {
}
return st.nextToken();
}
public static void readLine() {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
}
}
}
static class Sort {
static Random random = new Random();
public static void sortArray(int[] s) {
shuffle(s);
Arrays.sort(s);
}
public static void sortArray(long[] s) {
shuffle(s);
Arrays.sort(s);
}
public static void sortArray(String[] s) {
shuffle(s);
Arrays.sort(s);
}
public static void sortArray(char[] s) {
shuffle(s);
Arrays.sort(s);
}
private static void shuffle(int[] s) {
for (int i = 0; i < s.length; ++i) {
int j = random.nextInt(i + 1);
int t = s[i];
s[i] = s[j];
s[j] = t;
}
}
private static void shuffle(long[] s) {
for (int i = 0; i < s.length; ++i) {
int j = random.nextInt(i + 1);
long t = s[i];
s[i] = s[j];
s[j] = t;
}
}
private static void shuffle(String[] s) {
for (int i = 0; i < s.length; ++i) {
int j = random.nextInt(i + 1);
String t = s[i];
s[i] = s[j];
s[j] = t;
}
}
private static void shuffle(char[] s) {
for (int i = 0; i < s.length; ++i) {
int j = random.nextInt(i + 1);
char t = s[i];
s[i] = s[j];
s[j] = t;
}
}
}
static class Util{
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;
}
public static int upperBound(long[] a, long v) {
int l=0, h=a.length-1, ans = -1;
while(l<h) {
int mid = (l+h)/2;
if(a[mid]<=v) {
ans = mid;
l = mid+1;
}else h = mid-1;
}
return ans;
}
public static int lowerBound(long[] a, long v) {
int l=0, h=a.length-1, ans = -1;
while(l<h) {
int mid = (l+h)/2;
if(v<=a[mid]) {
ans = mid;
h = mid-1;
}else l = mid-1;
}
return ans;
}
public static boolean[] getSieve(int n) {
boolean[] isPrime = new boolean[n+1];
for (int i = 2; i <= n; i++) isPrime[i] = true;
for (int i = 2; i*i <= n; i++) if (isPrime[i])
for (int j = i; i*j <= n; j++) isPrime[i*j] = false;
return isPrime;
}
public static int gcd(int a, int b) {
if (a == 0)
return b;
return gcd(b%a, a);
}
public static long modAdd(long a, long b, long mod) {
return (a%mod+b%mod)%mod;
}
public static long modMul(long a, long b, long mod) {
return ((a%mod)*(b%mod))%mod;
}
public static void dbg(Object... o) {
System.out.println(Arrays.deepToString(o));
}
}
static class Writer {
private PrintWriter pw;
public Writer(){
pw = new PrintWriter(System.out);
}
public void printArray(int[] a) {
for(int i = 0; i<a.length; i++) print(a[i]+" ");
}
public void printlnArray(int[] a) {
for(int i = 0; i<a.length; i++) print(a[i]+" ");
pw.println();
}
public void printArray(long[] a) {
for(int i = 0; i<a.length; i++) print(a[i]+" ");
}
public void printlnArray(long[] a) {
for(int i = 0; i<a.length; i++) print(a[i]+" ");
pw.println();
}
public void print(Object o) {
pw.print(o.toString());
}
public void println(Object o) {
pw.println(o.toString());
}
public void println() {
pw.println();
}
public void flush() {
pw.flush();
}
public void exit() {
pw.close();
}
}
}
| Java | ["100\n60\n70", "410\n55\n70", "600\n60\n70"] | 1.5 seconds | ["40", "5", "0"] | NoteIn the first example, we can buy just $$$1$$$ dollar because there is no $$$1$$$ euro bill.In the second example, optimal exchange is to buy $$$5$$$ euro and $$$1$$$ dollar.In the third example, optimal exchange is to buy $$$10$$$ dollars in one bill. | Java 8 | standard input | [
"brute force",
"math"
] | 8c5d9b4fd297706fac3be83fc85028a0 | The first line of the input contains one integer $$$n$$$ ($$$1 \leq n \leq 10^8$$$)Β β the initial sum in rubles Andrew has. The second line of the input contains one integer $$$d$$$ ($$$30 \leq d \leq 100$$$)Β β the price of one dollar in rubles. The third line of the input contains integer $$$e$$$ ($$$30 \leq e \leq 100$$$)Β β the price of one euro in rubles. | 1,400 | Output one integerΒ β the minimum number of rubles Andrew can have after buying dollar and euro bills optimally. | standard output | |
PASSED | b4a8266028b383aa48f2f31f34c7151b | train_003.jsonl | 1567587900 | Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has $$$n$$$ rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar is $$$d$$$ rubles, and one euro costs $$$e$$$ rubles.Recall that there exist the following dollar bills: $$$1$$$, $$$2$$$, $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, and the following euro billsΒ β $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, $$$200$$$ (note that, in this problem we do not consider the $$$500$$$ euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.Help himΒ β write a program that given integers $$$n$$$, $$$e$$$ and $$$d$$$, finds the minimum number of rubles Andrew can get after buying dollar and euro bills. | 512 megabytes | import java.io.*;
import java.util.*;
import java.lang.*;
import static java.lang.Math.*;
public class TaskC implements Runnable {
InputReader c;
PrintWriter w;
/*Global Variables*/
public void run() {
c = new InputReader(System.in);
w = new PrintWriter(System.out);
int n = c.nextInt(), d = c.nextInt(), e = c.nextInt()*5;
int ans=n;
for(int i=0;i*e<=n;i++)
{
ans = min(ans,(n-i*e)%d);
}
w.println(ans);
w.close();
}
public static class DJSet {
public int[] upper;
public DJSet(int n) {
upper = new int[n];
Arrays.fill(upper, -1);
}
public int root(int x) {
return upper[x] < 0 ? x : (upper[x] = root(upper[x]));
}
public boolean equiv(int x, int y) {
return root(x) == root(y);
}
public boolean union(int x, int y) {
x = root(x);
y = root(y);
if (x != y) {
if (upper[y] < upper[x]) {
int d = x;
x = y;
y = d;
}
upper[x] += upper[y];
upper[y] = x;
}
return x == y;
}
}
/*Template Stuff*/
ArrayList<Long> getDiv(long num){
long square_root = (long) sqrt(num) + 1;
ArrayList<Long> l = new ArrayList<>();
for (long i = 1; i < square_root; i++) {
if (num % i == 0&&i*i!=num) {
l.add(i);
l.add(num / i);
}
if (num % i == 0&&i*i==num)
l.add(i);
}
return l;
}
class pair implements Comparable<pair>{
int x,y;
@Override
public String toString() {
return "pair{" +
"x=" + x +
", y=" + y +
'}';
}
pair(int x, int y){
this.x = x;
this.y = y;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
pair pair = (pair) o;
return (x == pair.x && y == pair.y) || (x==pair.y && y==pair.x);
}
@Override
public int hashCode() {
return Objects.hash(x+ y);
}
@Override
public int compareTo(pair o) {
return this.x - o.x;
}
}
public static void sortbyColumn(int arr[][], int col){
Arrays.sort(arr, new Comparator<int[]>()
{
public int compare(int[] o1, int[] o2){
return(Integer.valueOf(o1[col]).compareTo(o2[col]));
}
});
}
static long gcd(long a, long b){
if (b == 0)
return a;
return gcd(b, a % b);
}
public void printArray(int[] a){
for(int i=0;i<a.length;i++)
w.print(a[i]+" ");
w.println();
}
public int[] scanArrayI(int n){
int a[] = new int[n];
for(int i=0;i<n;i++)
a[i] = c.nextInt();
return a;
}
public long[] scanArrayL(int n){
long a[] = new long[n];
for(int i=0;i<n;i++)
a[i] = c.nextLong();
return a;
}
public void printArray(long[] a){
for(int i=0;i<a.length;i++)
w.print(a[i]+" ");
w.println();
}
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 TaskC(),"TaskC",1<<26).start();
}
} | Java | ["100\n60\n70", "410\n55\n70", "600\n60\n70"] | 1.5 seconds | ["40", "5", "0"] | NoteIn the first example, we can buy just $$$1$$$ dollar because there is no $$$1$$$ euro bill.In the second example, optimal exchange is to buy $$$5$$$ euro and $$$1$$$ dollar.In the third example, optimal exchange is to buy $$$10$$$ dollars in one bill. | Java 8 | standard input | [
"brute force",
"math"
] | 8c5d9b4fd297706fac3be83fc85028a0 | The first line of the input contains one integer $$$n$$$ ($$$1 \leq n \leq 10^8$$$)Β β the initial sum in rubles Andrew has. The second line of the input contains one integer $$$d$$$ ($$$30 \leq d \leq 100$$$)Β β the price of one dollar in rubles. The third line of the input contains integer $$$e$$$ ($$$30 \leq e \leq 100$$$)Β β the price of one euro in rubles. | 1,400 | Output one integerΒ β the minimum number of rubles Andrew can have after buying dollar and euro bills optimally. | standard output | |
PASSED | b031a857fdfb962d6949c6e4cb3b083c | train_003.jsonl | 1567587900 | Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has $$$n$$$ rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar is $$$d$$$ rubles, and one euro costs $$$e$$$ rubles.Recall that there exist the following dollar bills: $$$1$$$, $$$2$$$, $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, and the following euro billsΒ β $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, $$$200$$$ (note that, in this problem we do not consider the $$$500$$$ euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.Help himΒ β write a program that given integers $$$n$$$, $$$e$$$ and $$$d$$$, finds the minimum number of rubles Andrew can get after buying dollar and euro bills. | 512 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author Mufaddal Naya
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
AOptimalCurrencyExchange solver = new AOptimalCurrencyExchange();
solver.solve(1, in, out);
out.close();
}
static class AOptimalCurrencyExchange {
public void solve(int testNumber, InputReader c, OutputWriter w) {
int n = c.readInt(), d = c.readInt(), e = c.readInt() * 5;
int ans = n;
for (int i = 0; i * e <= n; i++) {
ans = Math.min(ans, (n - i * e) % d);
}
w.printLine(ans);
}
}
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 close() {
writer.close();
}
public void printLine(int i) {
writer.println(i);
}
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private InputReader.SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public int readInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c) {
if (filter != null) {
return filter.isSpaceChar(c);
}
return isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
}
| Java | ["100\n60\n70", "410\n55\n70", "600\n60\n70"] | 1.5 seconds | ["40", "5", "0"] | NoteIn the first example, we can buy just $$$1$$$ dollar because there is no $$$1$$$ euro bill.In the second example, optimal exchange is to buy $$$5$$$ euro and $$$1$$$ dollar.In the third example, optimal exchange is to buy $$$10$$$ dollars in one bill. | Java 8 | standard input | [
"brute force",
"math"
] | 8c5d9b4fd297706fac3be83fc85028a0 | The first line of the input contains one integer $$$n$$$ ($$$1 \leq n \leq 10^8$$$)Β β the initial sum in rubles Andrew has. The second line of the input contains one integer $$$d$$$ ($$$30 \leq d \leq 100$$$)Β β the price of one dollar in rubles. The third line of the input contains integer $$$e$$$ ($$$30 \leq e \leq 100$$$)Β β the price of one euro in rubles. | 1,400 | Output one integerΒ β the minimum number of rubles Andrew can have after buying dollar and euro bills optimally. | standard output | |
PASSED | 8cbcbbc0da25a2182b02149a69246041 | train_003.jsonl | 1567587900 | Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has $$$n$$$ rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar is $$$d$$$ rubles, and one euro costs $$$e$$$ rubles.Recall that there exist the following dollar bills: $$$1$$$, $$$2$$$, $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, and the following euro billsΒ β $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, $$$200$$$ (note that, in this problem we do not consider the $$$500$$$ euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.Help himΒ β write a program that given integers $$$n$$$, $$$e$$$ and $$$d$$$, finds the minimum number of rubles Andrew can get after buying dollar and euro bills. | 512 megabytes | import java.util.*;
import java.io.*;
import java.math.*;
public class Es1
{
static IO io = new IO();
public static void main(String[] args)
{
int R = io.getInt();
int d = io.getInt();
int e = io.getInt();
int D = d;
int E = 5*e;
int mcm = (D*E);
int res = 1000000000;
int resto = R%mcm;
if(resto + mcm < R)
resto += mcm;
for(int i=0; i<= 1001; i++){
for(int j=0; j<=1001; j++){
int tmp = resto - i*D - j*E;
if(tmp >= 0)
res = Math.min(res, tmp);
}
}
io.println(res);
io.close();
}
static int Euclide(int a, int b) // prototipo della funzione Euclide //
{
int r;
r = a % b; // operazione modulo //
while(r != 0) // ciclo di iterazione //
{
a = b;
b = r;
r = a % b;
}
return b;
}
}
class IO extends PrintWriter {
public IO() {
super(new BufferedOutputStream(System.out));
r = new BufferedReader(new InputStreamReader(System.in));
}
public IO(String fileName) {
super(new BufferedOutputStream(System.out));
try{
r = new BufferedReader(new FileReader(fileName));
} catch (FileNotFoundException e) {
this.println("File Not Found");
}
}
public boolean hasMoreTokens() {
return peekToken() != null;
}
public int getInt() {
return Integer.parseInt(nextToken());
}
public double getDouble() {
return Double.parseDouble(nextToken());
}
public long getLong() {
return Long.parseLong(nextToken());
}
public String getWord() {
return nextToken();
}
public String getLine(){
try{
st = null;
return r.readLine();
}
catch(IOException ex){}
return null;
}
private BufferedReader r;
private String line;
private StringTokenizer st;
private String token;
private String peekToken() {
if (token == null)
try {
while (st == null || !st.hasMoreTokens()) {
line = r.readLine();
if (line == null) return null;
st = new StringTokenizer(line);
}
token = st.nextToken();
} catch (IOException e) { }
return token;
}
private String nextToken() {
String ans = peekToken();
token = null;
return ans;
}
}
| Java | ["100\n60\n70", "410\n55\n70", "600\n60\n70"] | 1.5 seconds | ["40", "5", "0"] | NoteIn the first example, we can buy just $$$1$$$ dollar because there is no $$$1$$$ euro bill.In the second example, optimal exchange is to buy $$$5$$$ euro and $$$1$$$ dollar.In the third example, optimal exchange is to buy $$$10$$$ dollars in one bill. | Java 8 | standard input | [
"brute force",
"math"
] | 8c5d9b4fd297706fac3be83fc85028a0 | The first line of the input contains one integer $$$n$$$ ($$$1 \leq n \leq 10^8$$$)Β β the initial sum in rubles Andrew has. The second line of the input contains one integer $$$d$$$ ($$$30 \leq d \leq 100$$$)Β β the price of one dollar in rubles. The third line of the input contains integer $$$e$$$ ($$$30 \leq e \leq 100$$$)Β β the price of one euro in rubles. | 1,400 | Output one integerΒ β the minimum number of rubles Andrew can have after buying dollar and euro bills optimally. | standard output | |
PASSED | eae1a9b18fd82c24ed1a51e0f33904c1 | train_003.jsonl | 1567587900 | Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has $$$n$$$ rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar is $$$d$$$ rubles, and one euro costs $$$e$$$ rubles.Recall that there exist the following dollar bills: $$$1$$$, $$$2$$$, $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, and the following euro billsΒ β $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, $$$200$$$ (note that, in this problem we do not consider the $$$500$$$ euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.Help himΒ β write a program that given integers $$$n$$$, $$$e$$$ and $$$d$$$, finds the minimum number of rubles Andrew can get after buying dollar and euro bills. | 512 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class Try
{
PrintWriter out;
Reader s;
private class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader() {
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException {
byte[] buf = new byte[200001];
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException {
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException {
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException {
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException {
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException {
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
}
public static class Pair<T1,T2>{
public T1 first;
public T2 second;
private Pair(T1 first, T2 second){
this.first = first;
this.second = second;
}
}
public static void main(String args[]) throws IOException{
new Try().run();
}
void run() throws IOException{
out = new PrintWriter(System.out);
s=new Reader();
solve();
out.flush();
out.close();
}
int max(int a,int b)
{
return a>b?a:b;
}
void solve() throws IOException{
int n= s.nextInt();
int d= s.nextInt();
int e= s.nextInt();
int min=Integer.MAX_VALUE;
for(int i=0;i*e*5<=n;i++)
{
int t=n;
t-=i*e*5;
if(min>t%d)
min=t%d;
}
out.println(min);
}
}
| Java | ["100\n60\n70", "410\n55\n70", "600\n60\n70"] | 1.5 seconds | ["40", "5", "0"] | NoteIn the first example, we can buy just $$$1$$$ dollar because there is no $$$1$$$ euro bill.In the second example, optimal exchange is to buy $$$5$$$ euro and $$$1$$$ dollar.In the third example, optimal exchange is to buy $$$10$$$ dollars in one bill. | Java 8 | standard input | [
"brute force",
"math"
] | 8c5d9b4fd297706fac3be83fc85028a0 | The first line of the input contains one integer $$$n$$$ ($$$1 \leq n \leq 10^8$$$)Β β the initial sum in rubles Andrew has. The second line of the input contains one integer $$$d$$$ ($$$30 \leq d \leq 100$$$)Β β the price of one dollar in rubles. The third line of the input contains integer $$$e$$$ ($$$30 \leq e \leq 100$$$)Β β the price of one euro in rubles. | 1,400 | Output one integerΒ β the minimum number of rubles Andrew can have after buying dollar and euro bills optimally. | standard output | |
PASSED | 7a3f61f4ae58b1dbfced7000c542827c | train_003.jsonl | 1567587900 | Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has $$$n$$$ rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar is $$$d$$$ rubles, and one euro costs $$$e$$$ rubles.Recall that there exist the following dollar bills: $$$1$$$, $$$2$$$, $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, and the following euro billsΒ β $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, $$$200$$$ (note that, in this problem we do not consider the $$$500$$$ euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.Help himΒ β write a program that given integers $$$n$$$, $$$e$$$ and $$$d$$$, finds the minimum number of rubles Andrew can get after buying dollar and euro bills. | 512 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int d = Integer.parseInt(br.readLine());
int e = Integer.parseInt(br.readLine());
int cnt = n;
for (int i = 0; i * e * 5 <= n; i++){
cnt = Math.min(cnt, (n - i * e * 5) % d);
}
System.out.println(cnt);
}
} | Java | ["100\n60\n70", "410\n55\n70", "600\n60\n70"] | 1.5 seconds | ["40", "5", "0"] | NoteIn the first example, we can buy just $$$1$$$ dollar because there is no $$$1$$$ euro bill.In the second example, optimal exchange is to buy $$$5$$$ euro and $$$1$$$ dollar.In the third example, optimal exchange is to buy $$$10$$$ dollars in one bill. | Java 8 | standard input | [
"brute force",
"math"
] | 8c5d9b4fd297706fac3be83fc85028a0 | The first line of the input contains one integer $$$n$$$ ($$$1 \leq n \leq 10^8$$$)Β β the initial sum in rubles Andrew has. The second line of the input contains one integer $$$d$$$ ($$$30 \leq d \leq 100$$$)Β β the price of one dollar in rubles. The third line of the input contains integer $$$e$$$ ($$$30 \leq e \leq 100$$$)Β β the price of one euro in rubles. | 1,400 | Output one integerΒ β the minimum number of rubles Andrew can have after buying dollar and euro bills optimally. | standard output | |
PASSED | 4bbf7ed9f46dfd7025931645019034c9 | train_003.jsonl | 1567587900 | Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has $$$n$$$ rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar is $$$d$$$ rubles, and one euro costs $$$e$$$ rubles.Recall that there exist the following dollar bills: $$$1$$$, $$$2$$$, $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, and the following euro billsΒ β $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, $$$200$$$ (note that, in this problem we do not consider the $$$500$$$ euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.Help himΒ β write a program that given integers $$$n$$$, $$$e$$$ and $$$d$$$, finds the minimum number of rubles Andrew can get after buying dollar and euro bills. | 512 megabytes | /******************************************************************************
Online Java Compiler.
Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.
*******************************************************************************/
import java.lang.Math;
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
int n, d, e;
String s;
Scanner scan = new Scanner (System.in);
n = scan.nextInt ();
d = scan.nextInt ();
e = scan.nextInt ();
e *= 5;
int minV = Math.min (e, d);
int maxV = Math.max (e, d);
// System.out.println (Integer.toString (minV));
// System.out.println (Integer.toString (maxV));
//System.out.println ("minV " + minV + " maxV " + maxV);
int ans = -1;
for (int i = 0; i <= (n/minV); i++) {
int pa = n - i*minV;
pa -= maxV*(pa/maxV);
if (ans == -1 || pa < ans)
ans = pa;
}
for (int i = 0; i <= (n/maxV); i++) {
int pa = n - i*maxV;
pa -= minV*(pa/minV);
// System.out.println ("pa " + pa);
if (ans == -1 || pa < ans)
ans = pa;
}
System.out.println (ans);
}
}
| Java | ["100\n60\n70", "410\n55\n70", "600\n60\n70"] | 1.5 seconds | ["40", "5", "0"] | NoteIn the first example, we can buy just $$$1$$$ dollar because there is no $$$1$$$ euro bill.In the second example, optimal exchange is to buy $$$5$$$ euro and $$$1$$$ dollar.In the third example, optimal exchange is to buy $$$10$$$ dollars in one bill. | Java 8 | standard input | [
"brute force",
"math"
] | 8c5d9b4fd297706fac3be83fc85028a0 | The first line of the input contains one integer $$$n$$$ ($$$1 \leq n \leq 10^8$$$)Β β the initial sum in rubles Andrew has. The second line of the input contains one integer $$$d$$$ ($$$30 \leq d \leq 100$$$)Β β the price of one dollar in rubles. The third line of the input contains integer $$$e$$$ ($$$30 \leq e \leq 100$$$)Β β the price of one euro in rubles. | 1,400 | Output one integerΒ β the minimum number of rubles Andrew can have after buying dollar and euro bills optimally. | standard output | |
PASSED | fc70aec8b5aeecc04847b562fb218656 | train_003.jsonl | 1567587900 | Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has $$$n$$$ rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar is $$$d$$$ rubles, and one euro costs $$$e$$$ rubles.Recall that there exist the following dollar bills: $$$1$$$, $$$2$$$, $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, and the following euro billsΒ β $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, $$$200$$$ (note that, in this problem we do not consider the $$$500$$$ euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.Help himΒ β write a program that given integers $$$n$$$, $$$e$$$ and $$$d$$$, finds the minimum number of rubles Andrew can get after buying dollar and euro bills. | 512 megabytes | import java.util.*;
public class Test{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int d=sc.nextInt();
int e=sc.nextInt();
int ans=n;
for (int i = 0; i * 5 * e <= n; ++i) {
ans = Math.min(ans, (n - i * 5 * e) % d);
}
System.out.println(ans);
}
} | Java | ["100\n60\n70", "410\n55\n70", "600\n60\n70"] | 1.5 seconds | ["40", "5", "0"] | NoteIn the first example, we can buy just $$$1$$$ dollar because there is no $$$1$$$ euro bill.In the second example, optimal exchange is to buy $$$5$$$ euro and $$$1$$$ dollar.In the third example, optimal exchange is to buy $$$10$$$ dollars in one bill. | Java 8 | standard input | [
"brute force",
"math"
] | 8c5d9b4fd297706fac3be83fc85028a0 | The first line of the input contains one integer $$$n$$$ ($$$1 \leq n \leq 10^8$$$)Β β the initial sum in rubles Andrew has. The second line of the input contains one integer $$$d$$$ ($$$30 \leq d \leq 100$$$)Β β the price of one dollar in rubles. The third line of the input contains integer $$$e$$$ ($$$30 \leq e \leq 100$$$)Β β the price of one euro in rubles. | 1,400 | Output one integerΒ β the minimum number of rubles Andrew can have after buying dollar and euro bills optimally. | standard output | |
PASSED | 8d1590c6fd29c5951c30565070641d29 | train_003.jsonl | 1383379200 | A permutation p is an ordered group of numbers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,βββp2,βββ...,βββpn.Simon has a positive integer n and a non-negative integer k, such that 2kββ€βn. Help him find permutation a of length 2n, such that it meets this equation: . | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class CodeForce209B {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer tokenixer = new StringTokenizer(in.readLine());
int n = Integer.parseInt(tokenixer.nextToken());
int k = Integer.parseInt(tokenixer.nextToken());
StringBuilder str = new StringBuilder();
for(int i=1;i<=k;i++) {
str.append(2*i+" "+(2*i-1)+" ");
}
// if(k!=0) {
// str.append(" ");
// }
for(int i=k+1;i<=n;i++) {
str.append((2*i-1)+" "+(2*i)+" ");
}
System.out.println(str.toString());
}
}
| Java | ["1 0", "2 1", "4 0"] | 1 second | ["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"] | NoteRecord |x| represents the absolute value of number x. In the first sample |1β-β2|β-β|1β-β2|β=β0.In the second sample |3β-β2|β+β|1β-β4|β-β|3β-β2β+β1β-β4|β=β1β+β3β-β2β=β2.In the third sample |2β-β7|β+β|4β-β6|β+β|1β-β3|β+β|5β-β8|β-β|2β-β7β+β4β-β6β+β1β-β3β+β5β-β8|β=β12β-β12β=β0. | Java 7 | standard input | [
"dp",
"constructive algorithms",
"math"
] | 82de6d4c892f4140e72606386ec2ef59 | The first line contains two integers n and k (1ββ€βnββ€β50000, 0ββ€β2kββ€βn). | 1,400 | Print 2n integers a1,βa2,β...,βa2n β the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them. | standard output | |
PASSED | cafd258981c659cfabc60f59c80af869 | train_003.jsonl | 1383379200 | A permutation p is an ordered group of numbers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,βββp2,βββ...,βββpn.Simon has a positive integer n and a non-negative integer k, such that 2kββ€βn. Help him find permutation a of length 2n, such that it meets this equation: . | 256 megabytes |
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Scanner;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author mark
*/
public class Permutation {
private static int ii;
public static void main(String[] args) throws FileNotFoundException {
//FileInputStream file = new FileInputStream(new File("/home/mark/tmp/input.txt"));
//Scanner scan = new Scanner(file);
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int k = scan.nextInt();
int ans[] = new int[2*n];
for(int i=0;i<=((2*n)-(2*k))-1;i++){
ans[i]=i+1;
}
int rem = ((2*n)-(2*k))%2;
for(int i=((2*n)-(2*k));i<2*n;i++){
if ((i)%2==rem){
ans[i]=i+2;
}else{
ans[i]=i;
}
}
System.out.println(Arrays.toString(ans).replace("[","").replace("]","").replace(",",""));
}
}
| Java | ["1 0", "2 1", "4 0"] | 1 second | ["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"] | NoteRecord |x| represents the absolute value of number x. In the first sample |1β-β2|β-β|1β-β2|β=β0.In the second sample |3β-β2|β+β|1β-β4|β-β|3β-β2β+β1β-β4|β=β1β+β3β-β2β=β2.In the third sample |2β-β7|β+β|4β-β6|β+β|1β-β3|β+β|5β-β8|β-β|2β-β7β+β4β-β6β+β1β-β3β+β5β-β8|β=β12β-β12β=β0. | Java 7 | standard input | [
"dp",
"constructive algorithms",
"math"
] | 82de6d4c892f4140e72606386ec2ef59 | The first line contains two integers n and k (1ββ€βnββ€β50000, 0ββ€β2kββ€βn). | 1,400 | Print 2n integers a1,βa2,β...,βa2n β the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them. | standard output | |
PASSED | 42d71095004ded14c962ce9226c05f19 | train_003.jsonl | 1383379200 | A permutation p is an ordered group of numbers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,βββp2,βββ...,βββpn.Simon has a positive integer n and a non-negative integer k, such that 2kββ€βn. Help him find permutation a of length 2n, such that it meets this equation: . | 256 megabytes | import java.io.*;
import java.util.*;
import static java.lang.Math.*;
public class Solution {
private IO io;
private int ioMode = -1;
private String problemName = "";
private final String mjArgument = "master_j";
public static void main(String programArguments[]) throws IOException{
if(programArguments != null && programArguments.length > 0)
new Solution().run(programArguments[0]);
else
new Solution().run(null);
}
private void run(String programArgument) throws IOException {
// _______________________________________________ _________
// | Input Mode | Output Mode | mode | comment |
// |------------------|---------------------|----- |---------|
// | input.txt | System.out | 0 | mj |
// | System.in | System.out | 1 | T / CF |
// |<problemName>.in | <problemName>.out | 2 | |
// | input.txt | output.txt | 3 | C |
// |__________________|_____________________|______|_________|
long nanoTime = 0;
if(programArgument != null && programArgument.equals(mjArgument)) // mj
ioMode = 0;
else if(System.getProperty("ONLINE_JUDGE") != null) // T / CF
ioMode = 1;
else
ioMode = 2;
switch(ioMode){
case -1:
try{
throw new Exception("<ioMode> init failure") ;
}catch (Exception e){
e.printStackTrace();
}
return;
case 0:
break;
case 1:
break;
case 2:
if(problemName.length() == 0){
try{
throw new Exception("<problemName> init failure");
}catch (Exception e){
e.printStackTrace();
}
return;
}
case 3:
break;
}
io = new IO(ioMode, problemName);
if(ioMode == 0){
System.out.println("File output : \n<start>");
System.out.flush();
nanoTime = System.nanoTime();
}
solve();
io.flush();
if(ioMode == 0){
System.out.println("</start>");
long t = System.nanoTime() - nanoTime;
int d3 = 1000000000, d2 = 1000000, d1 = 1000;
if(t>=d3)
System.out.println(t/d3 + "." + t%d3 + " seconds");
else if(t>=d2)
System.out.println(t/d2 + "." + t%d2 + " millis");
else if(t>=d1)
System.out.println(t/d1 + "." + t%d1 + " micros");
else
System.out.println(t + " nanos");
System.out.flush();
}
}
private void solve() throws IOException {
int n = io.nI(), k = io.nI();
if(k == 0){
for(int i = 2*n; i>=1; i--){
io.w(i);
io.w(' ');
}
return;
}
io.w(2*n-k); io.w(' ');
io.w(2*n); io.w(' ');
for(int i = 2*n-1; i>0; i--)
if(i != 2*n-k){
io.w(i); io.w(' ');
}
}//2.2250738585072012e-308
/**
* Input-output class
* @author master_j
* @version 0.2.5
*/
@SuppressWarnings("unused")
private class IO{
private boolean alwaysFlush;
StreamTokenizer in; PrintWriter out; BufferedReader br; Reader reader; Writer writer;
public IO(int ioMode, String problemName) throws IOException{
Locale.setDefault(Locale.US);
// _______________________________________________ _________
// | Input Mode | Output Mode | mode | comment |
// |------------------|---------------------|----- |---------|
// | input.txt | System.out | 0 | mj |
// | System.in | System.out | 1 | T / CF |
// |<problemName>.in | <problemName>.out | 2 | |
// | input.txt | output.txt | 3 | C |
// |__________________|_____________________|______|_________|
switch(ioMode){
case 0:
reader = new FileReader("input.txt");
writer = new OutputStreamWriter(System.out);
break;
case 1:
reader = new InputStreamReader(System.in);
writer = new OutputStreamWriter(System.out);
break;
case 2:
reader = new FileReader(problemName + ".in");
writer = new FileWriter(problemName + ".out");
break;
case 3:
reader = new FileReader("input.txt");
writer = new FileWriter("output.txt");
break;
}
br = new BufferedReader(reader);
in = new StreamTokenizer(br);
out = new PrintWriter(writer);
alwaysFlush = false;
}
public void setAlwaysFlush(boolean arg){alwaysFlush = arg;}
public void wln(){out.println(); if(alwaysFlush)flush();}
public void wln(int arg){out.println(arg); if(alwaysFlush)flush();}
public void wln(long arg){out.println(arg); if(alwaysFlush)flush();}
public void wln(double arg){out.println(arg); if(alwaysFlush)flush();}
public void wln(String arg){out.println(arg); if(alwaysFlush)flush();}
public void wln(boolean arg){out.println(arg); if(alwaysFlush)flush();}
public void wln(char arg){out.println(arg); if(alwaysFlush)flush();}
public void wln(float arg){out.println(arg); if(alwaysFlush)flush();}
public void wln(Object arg){out.println(arg); if(alwaysFlush)flush();}
public void w(int arg){out.print(arg); if(alwaysFlush)flush();}
public void w(long arg){out.print(arg); if(alwaysFlush)flush();}
public void w(double arg){out.print(arg); if(alwaysFlush)flush();}
public void w(String arg){out.print(arg); if(alwaysFlush)flush();}
public void w(boolean arg){out.print(arg); if(alwaysFlush)flush();}
public void w(char arg){out.print(arg); if(alwaysFlush)flush();}
public void w(float arg){out.print(arg); if(alwaysFlush)flush();}
public void w(Object arg){out.print(arg); if(alwaysFlush)flush();}
public void wf(String format, Object...args){out.printf(format, args); if(alwaysFlush)flush();}
public void flush(){out.flush();}
public int nI() throws IOException {in.nextToken(); return(int)in.nval;}
public long nL() throws IOException {in.nextToken(); return(long)in.nval;}
public String nS() throws IOException {in.nextToken(); return in.sval;}
public double nD() throws IOException {in.nextToken(); return in.nval;}
public float nF() throws IOException {in.nextToken(); return (float)in.nval;}
public char nC() throws IOException {return (char)br.read();}
public void wc(char...arg){for(char c : arg){in.ordinaryChar(c);in.wordChars(c, c);}}
public void wc(String arg){wc(arg.toCharArray());}
public void wc(char arg0, char arg1){in.ordinaryChars(arg0, arg1); in.wordChars(arg0, arg1);}
public boolean eof(){return in.ttype == StreamTokenizer.TT_EOF;}
public boolean eol(){return in.ttype == StreamTokenizer.TT_EOL;}
}
} | Java | ["1 0", "2 1", "4 0"] | 1 second | ["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"] | NoteRecord |x| represents the absolute value of number x. In the first sample |1β-β2|β-β|1β-β2|β=β0.In the second sample |3β-β2|β+β|1β-β4|β-β|3β-β2β+β1β-β4|β=β1β+β3β-β2β=β2.In the third sample |2β-β7|β+β|4β-β6|β+β|1β-β3|β+β|5β-β8|β-β|2β-β7β+β4β-β6β+β1β-β3β+β5β-β8|β=β12β-β12β=β0. | Java 7 | standard input | [
"dp",
"constructive algorithms",
"math"
] | 82de6d4c892f4140e72606386ec2ef59 | The first line contains two integers n and k (1ββ€βnββ€β50000, 0ββ€β2kββ€βn). | 1,400 | Print 2n integers a1,βa2,β...,βa2n β the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them. | standard output | |
PASSED | c6461e57655abb5d7e89a03f54a08eb7 | train_003.jsonl | 1383379200 | A permutation p is an ordered group of numbers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,βββp2,βββ...,βββpn.Simon has a positive integer n and a non-negative integer k, such that 2kββ€βn. Help him find permutation a of length 2n, such that it meets this equation: . | 256 megabytes | import java.util.*;
public class Permutation {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int k = in.nextInt();
// start with sequence 1, 2, ..., 2*n, and invert first k pairs to obtain 2*k diff
StringBuilder sb = new StringBuilder();
for (int i = 1; i <= 2 * k; i += 2) {
if (i > 1) sb.append(" ");
sb.append(i + 1);
sb.append(" ");
sb.append(i);
}
for (int i = 2 * k + 1; i <= 2 * n; ++i) {
if (i > 1) sb.append(" ");
sb.append(i);
}
System.out.println(sb);
in.close();
System.exit(0);
}
}
| Java | ["1 0", "2 1", "4 0"] | 1 second | ["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"] | NoteRecord |x| represents the absolute value of number x. In the first sample |1β-β2|β-β|1β-β2|β=β0.In the second sample |3β-β2|β+β|1β-β4|β-β|3β-β2β+β1β-β4|β=β1β+β3β-β2β=β2.In the third sample |2β-β7|β+β|4β-β6|β+β|1β-β3|β+β|5β-β8|β-β|2β-β7β+β4β-β6β+β1β-β3β+β5β-β8|β=β12β-β12β=β0. | Java 7 | standard input | [
"dp",
"constructive algorithms",
"math"
] | 82de6d4c892f4140e72606386ec2ef59 | The first line contains two integers n and k (1ββ€βnββ€β50000, 0ββ€β2kββ€βn). | 1,400 | Print 2n integers a1,βa2,β...,βa2n β the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them. | standard output | |
PASSED | 32ac6e4ad22ac90c43c1d446e0ceb242 | train_003.jsonl | 1383379200 | A permutation p is an ordered group of numbers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,βββp2,βββ...,βββpn.Simon has a positive integer n and a non-negative integer k, such that 2kββ€βn. Help him find permutation a of length 2n, such that it meets this equation: . | 256 megabytes | import java.util.*;
import java.io.*;
import static java.lang.Math.*;
public class TaskB {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n=in.nextInt();
int k=in.nextInt();
int[] a=new int[2*n];
if (k==0){
for (int i=1;i<=2*n;i++){
out.print(i+" ");
}
}else {
for (int i=0;i<2*n;i++){
if (i%2==0) a[i]=i+2;
else a[i]=i;
}
int j=0;
for (int i=0;i<k;i++){
int temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
j+=2;
}
for (int i=0;i<2*n;i++){
out.print(a[i]+" ");
}
}
out.close();
}
} | Java | ["1 0", "2 1", "4 0"] | 1 second | ["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"] | NoteRecord |x| represents the absolute value of number x. In the first sample |1β-β2|β-β|1β-β2|β=β0.In the second sample |3β-β2|β+β|1β-β4|β-β|3β-β2β+β1β-β4|β=β1β+β3β-β2β=β2.In the third sample |2β-β7|β+β|4β-β6|β+β|1β-β3|β+β|5β-β8|β-β|2β-β7β+β4β-β6β+β1β-β3β+β5β-β8|β=β12β-β12β=β0. | Java 7 | standard input | [
"dp",
"constructive algorithms",
"math"
] | 82de6d4c892f4140e72606386ec2ef59 | The first line contains two integers n and k (1ββ€βnββ€β50000, 0ββ€β2kββ€βn). | 1,400 | Print 2n integers a1,βa2,β...,βa2n β the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them. | standard output | |
PASSED | 8d492932a0fd896d35fa98504afffc33 | train_003.jsonl | 1383379200 | A permutation p is an ordered group of numbers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,βββp2,βββ...,βββpn.Simon has a positive integer n and a non-negative integer k, such that 2kββ€βn. Help him find permutation a of length 2n, such that it meets this equation: . | 256 megabytes | import java.util.*;
public class Main {
private static final long MOD = 1000000007;
public static void main(String[] args) throws Exception {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int k = scan.nextInt();
int[] arr = new int[2 * n];
for (int i = 0; i < arr.length; i++) {
arr[i] = i + 1;
}
if (k > 0) {
if (k % 2 == 0) {
swap(arr, 0, 1);
k--;
}
swap(arr, 0, k + 1);
}
print(arr);
scan.close();
}
private static void swap(int[] arr, int i, int j) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
private static void print(int[] arr) {
System.out.print(arr[0]);
for (int i = 1; i < arr.length; i++) {
System.out.print(" ");
System.out.print(arr[i]);
}
System.out.println();
}
private static void print(long[] arr) {
System.out.print(arr[0]);
for (int i = 1; i < arr.length; i++) {
System.out.print(" ");
System.out.print(arr[i]);
}
System.out.println();
}
private static void read(Scanner scan, int[]... arrs) {
int len = arrs[0].length;
for (int i = 0; i < len; i++) {
for (int[] arr : arrs) {
arr[i] = scan.nextInt();
}
}
}
private static void decreaseByOne(int[]... arrs) {
for (int[] arr : arrs) {
for (int i = 0; i < arr.length; i++) {
arr[i] --;
}
}
}
}
| Java | ["1 0", "2 1", "4 0"] | 1 second | ["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"] | NoteRecord |x| represents the absolute value of number x. In the first sample |1β-β2|β-β|1β-β2|β=β0.In the second sample |3β-β2|β+β|1β-β4|β-β|3β-β2β+β1β-β4|β=β1β+β3β-β2β=β2.In the third sample |2β-β7|β+β|4β-β6|β+β|1β-β3|β+β|5β-β8|β-β|2β-β7β+β4β-β6β+β1β-β3β+β5β-β8|β=β12β-β12β=β0. | Java 7 | standard input | [
"dp",
"constructive algorithms",
"math"
] | 82de6d4c892f4140e72606386ec2ef59 | The first line contains two integers n and k (1ββ€βnββ€β50000, 0ββ€β2kββ€βn). | 1,400 | Print 2n integers a1,βa2,β...,βa2n β the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them. | standard output | |
PASSED | dac7ccafb09e88a0a8098bdc177aedea | train_003.jsonl | 1383379200 | A permutation p is an ordered group of numbers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,βββp2,βββ...,βββpn.Simon has a positive integer n and a non-negative integer k, such that 2kββ€βn. Help him find permutation a of length 2n, such that it meets this equation: . | 256 megabytes | /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.text.*;
public class cf359b {
static BufferedReader br;
static Scanner sc;
static PrintWriter out;
public static void initA() {
try {
br = new BufferedReader(new InputStreamReader(System.in));
sc = new Scanner(System.in);
out = new PrintWriter(System.out);
} catch (Exception e) {
}
}
static boolean next_permutation(Integer[] p) {
for (int a = p.length - 2; a >= 0; --a) {
if (p[a] < p[a + 1]) {
for (int b = p.length - 1;; --b) {
if (p[b] > p[a]) {
int t = p[a];
p[a] = p[b];
p[b] = t;
for (++a, b = p.length - 1; a < b; ++a, --b) {
t = p[a];
p[a] = p[b];
p[b] = t;
}
return true;
}
}
}
}
return false;
}
public static String getString() {
try {
return br.readLine();
} catch (Exception e) {
}
return "";
}
public static Integer getInt() {
try {
return Integer.parseInt(br.readLine());
} catch (Exception e) {
}
return 0;
}
public static Integer[] getIntArr() {
try {
StringTokenizer temp = new StringTokenizer(br.readLine());
int n = temp.countTokens();
Integer temp2[] = new Integer[n];
for (int i = 0; i < n; i++) {
temp2[i] = Integer.parseInt(temp.nextToken());
}
return temp2;
} catch (Exception e) {
}
return null;
}
public static Long[] getLongArr() {
try {
StringTokenizer temp = new StringTokenizer(br.readLine());
int n = temp.countTokens();
Long temp2[] = new Long[n];
for (int i = 0; i < n; i++) {
temp2[i] = Long.parseLong(temp.nextToken());
}
return temp2;
} catch (Exception e) {
}
return null;
}
public static String[] getStringArr() {
try {
StringTokenizer temp = new StringTokenizer(br.readLine());
int n = temp.countTokens();
String temp2[] = new String[n];
for (int i = 0; i < n; i++) {
temp2[i] = (temp.nextToken());
}
return temp2;
} catch (Exception e) {
}
return null;
}
public static void print(Object a) {
out.println(a);
}
public static void print(String s, Object... a) {
out.printf(s, a);
}
public static int nextInt() {
return sc.nextInt();
}
public static double nextDouble() {
return sc.nextDouble();
}
public static void main(String[] ar) {
initA();
solve();
out.flush();
}
public static void solve() {
Integer xx[] = getIntArr();
int n = xx[0], k = xx[1];
Integer data[] = new Integer[2*n];
for(int i =0 ;i<data.length;i++){
data[i] = i+1;
}
int pos = 0;
while(k>0){
int temp = data[pos];
data[pos] = data[pos+1];
data[pos+1] = temp;
pos+=2;
k--;
}
for(int i =0 ;i<data.length-1;i++){
print("%d ",data[i]);
}
print(data[data.length-1]);
}
}
| Java | ["1 0", "2 1", "4 0"] | 1 second | ["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"] | NoteRecord |x| represents the absolute value of number x. In the first sample |1β-β2|β-β|1β-β2|β=β0.In the second sample |3β-β2|β+β|1β-β4|β-β|3β-β2β+β1β-β4|β=β1β+β3β-β2β=β2.In the third sample |2β-β7|β+β|4β-β6|β+β|1β-β3|β+β|5β-β8|β-β|2β-β7β+β4β-β6β+β1β-β3β+β5β-β8|β=β12β-β12β=β0. | Java 7 | standard input | [
"dp",
"constructive algorithms",
"math"
] | 82de6d4c892f4140e72606386ec2ef59 | The first line contains two integers n and k (1ββ€βnββ€β50000, 0ββ€β2kββ€βn). | 1,400 | Print 2n integers a1,βa2,β...,βa2n β the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them. | standard output | |
PASSED | 366558e8420ff0b279f4f5b2450a6a11 | train_003.jsonl | 1383379200 | A permutation p is an ordered group of numbers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,βββp2,βββ...,βββpn.Simon has a positive integer n and a non-negative integer k, such that 2kββ€βn. Help him find permutation a of length 2n, such that it meets this equation: . | 256 megabytes | import java.util.Scanner;
public class Test {
public static void main(String[] args) {
permutation();
}
public static void permutation() {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
sc.close();
System.out.print((k + 1));
if(k!=0)
{
System.out.print(" "+1);
}
for (int i = 1; i <= 2*n; i++) {
if (i != 1 && i != (k + 1)) {
System.out.print(" " + i);
}
}
}
} | Java | ["1 0", "2 1", "4 0"] | 1 second | ["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"] | NoteRecord |x| represents the absolute value of number x. In the first sample |1β-β2|β-β|1β-β2|β=β0.In the second sample |3β-β2|β+β|1β-β4|β-β|3β-β2β+β1β-β4|β=β1β+β3β-β2β=β2.In the third sample |2β-β7|β+β|4β-β6|β+β|1β-β3|β+β|5β-β8|β-β|2β-β7β+β4β-β6β+β1β-β3β+β5β-β8|β=β12β-β12β=β0. | Java 7 | standard input | [
"dp",
"constructive algorithms",
"math"
] | 82de6d4c892f4140e72606386ec2ef59 | The first line contains two integers n and k (1ββ€βnββ€β50000, 0ββ€β2kββ€βn). | 1,400 | Print 2n integers a1,βa2,β...,βa2n β the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them. | standard output | |
PASSED | 5d6465c6fd599d10719e8554976f2ddd | train_003.jsonl | 1383379200 | A permutation p is an ordered group of numbers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,βββp2,βββ...,βββpn.Simon has a positive integer n and a non-negative integer k, such that 2kββ€βn. Help him find permutation a of length 2n, such that it meets this equation: . | 256 megabytes | import java.util.Scanner;
public class CodeForce {
public static void main(String[] args) {
try (Scanner sc = new Scanner(System.in)) {
int n=sc.nextInt();
int k=sc.nextInt();
if(k==0){
for(int i=1;i<=(2*n);i++){
if(i==(2*n)){
System.out.print(i);
}else{
System.out.print(i+" ");
}
}
}else{
int regular=(n-k);
int reverse=k;
int count=1;
for(int i=0;i<regular;i++){
if(i>0){ System.out.print(" ");}
System.out.print(count+" "+(count+1));
count+=2;
}
for(int i=0;i<reverse;i++){
if(count>1){System.out.print(" ");}
System.out.print((count+1)+" "+count);
count+=2;
}
}
sc.close();
}
}
}
| Java | ["1 0", "2 1", "4 0"] | 1 second | ["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"] | NoteRecord |x| represents the absolute value of number x. In the first sample |1β-β2|β-β|1β-β2|β=β0.In the second sample |3β-β2|β+β|1β-β4|β-β|3β-β2β+β1β-β4|β=β1β+β3β-β2β=β2.In the third sample |2β-β7|β+β|4β-β6|β+β|1β-β3|β+β|5β-β8|β-β|2β-β7β+β4β-β6β+β1β-β3β+β5β-β8|β=β12β-β12β=β0. | Java 7 | standard input | [
"dp",
"constructive algorithms",
"math"
] | 82de6d4c892f4140e72606386ec2ef59 | The first line contains two integers n and k (1ββ€βnββ€β50000, 0ββ€β2kββ€βn). | 1,400 | Print 2n integers a1,βa2,β...,βa2n β the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them. | standard output | |
PASSED | 5db3cd2b29e429e56be42343f888d743 | train_003.jsonl | 1383379200 | A permutation p is an ordered group of numbers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,βββp2,βββ...,βββpn.Simon has a positive integer n and a non-negative integer k, such that 2kββ€βn. Help him find permutation a of length 2n, such that it meets this equation: . | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main (String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int k = in.nextInt();
for (int i = 0; i < k; i++) {
System.out.print((2 * i + 2) + " " + (2 * i + 1) + " ");
}
for (int i = k; i < n; i++) {
System.out.print((2 * i + 1) + " " + (2 * i + 2) + ((i +1 ==n) ? "\n" : " "));
}
in.close();
}
}
| Java | ["1 0", "2 1", "4 0"] | 1 second | ["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"] | NoteRecord |x| represents the absolute value of number x. In the first sample |1β-β2|β-β|1β-β2|β=β0.In the second sample |3β-β2|β+β|1β-β4|β-β|3β-β2β+β1β-β4|β=β1β+β3β-β2β=β2.In the third sample |2β-β7|β+β|4β-β6|β+β|1β-β3|β+β|5β-β8|β-β|2β-β7β+β4β-β6β+β1β-β3β+β5β-β8|β=β12β-β12β=β0. | Java 7 | standard input | [
"dp",
"constructive algorithms",
"math"
] | 82de6d4c892f4140e72606386ec2ef59 | The first line contains two integers n and k (1ββ€βnββ€β50000, 0ββ€β2kββ€βn). | 1,400 | Print 2n integers a1,βa2,β...,βa2n β the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them. | standard output | |
PASSED | b5d04d4df8a019586de5fc182d5259ab | train_003.jsonl | 1383379200 | A permutation p is an ordered group of numbers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,βββp2,βββ...,βββpn.Simon has a positive integer n and a non-negative integer k, such that 2kββ€βn. Help him find permutation a of length 2n, such that it meets this equation: . | 256 megabytes | import static java.util.Arrays.deepToString;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.StringTokenizer;
public class Main {
static void solve() throws IOException {
int n = nextInt();
int k = nextInt();
for (int i = 1; i <= n; i++) {
if (k > 0) {
writer.print(2 * i + " " + (2 * i - 1) + " ");
k--;
} else {
writer.print((2 * i - 1) + " " + 2 * i + " ");
}
}
writer.println();
}
public static void main(String[] args) throws Exception {
reader = new BufferedReader(new InputStreamReader(System.in));
writer = new PrintWriter(System.out);
// reader = new BufferedReader(new FileReader("input.txt"));
// writer = new PrintWriter("output.txt");
setTime();
solve();
printTime();
printMemory();
writer.close();
}
static BufferedReader reader;
static PrintWriter writer;
static StringTokenizer tok = new StringTokenizer("");
static long systemTime;
static void debug(Object... o) {
System.err.println(deepToString(o));
}
static void setTime() {
systemTime = System.currentTimeMillis();
}
static void printTime() {
System.err.println("Time consumed: "
+ (System.currentTimeMillis() - systemTime));
}
static void printMemory() {
System.err.println("Memory consumed: "
+ (Runtime.getRuntime().totalMemory() - Runtime.getRuntime()
.freeMemory()) / 1000 + "kb");
}
static String next() {
while (!tok.hasMoreTokens()) {
String w = null;
try {
w = reader.readLine();
} catch (Exception e) {
e.printStackTrace();
}
if (w == null)
return null;
tok = new StringTokenizer(w);
}
return tok.nextToken();
}
static int nextInt() {
return Integer.parseInt(next());
}
static long nextLong() {
return Long.parseLong(next());
}
static double nextDouble() {
return Double.parseDouble(next());
}
static BigInteger nextBigInteger() {
return new BigInteger(next());
}
} | Java | ["1 0", "2 1", "4 0"] | 1 second | ["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"] | NoteRecord |x| represents the absolute value of number x. In the first sample |1β-β2|β-β|1β-β2|β=β0.In the second sample |3β-β2|β+β|1β-β4|β-β|3β-β2β+β1β-β4|β=β1β+β3β-β2β=β2.In the third sample |2β-β7|β+β|4β-β6|β+β|1β-β3|β+β|5β-β8|β-β|2β-β7β+β4β-β6β+β1β-β3β+β5β-β8|β=β12β-β12β=β0. | Java 7 | standard input | [
"dp",
"constructive algorithms",
"math"
] | 82de6d4c892f4140e72606386ec2ef59 | The first line contains two integers n and k (1ββ€βnββ€β50000, 0ββ€β2kββ€βn). | 1,400 | Print 2n integers a1,βa2,β...,βa2n β the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them. | standard output | |
PASSED | dcfa493075df8f3e45f810e4b7102969 | train_003.jsonl | 1383379200 | A permutation p is an ordered group of numbers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,βββp2,βββ...,βββpn.Simon has a positive integer n and a non-negative integer k, such that 2kββ€βn. Help him find permutation a of length 2n, such that it meets this equation: . | 256 megabytes | /*
Date :
Problem Name :
Location :
Algorithm :
Status :
Coding :
Thinking :
Time spent :
Note :
*/
import java.util.*;
import java.io.*;
public class Main {
static BufferedReader reader
= new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args){
int[] inp = getIntArray();
int n = inp[0];
int k = inp[1];
int[] ary = new int[2*n + 2];
for (int i = 1; i <= n; i++){
if (k > 0){
ary[2*i-1] = 2*i;
ary[2*i] = 2*i - 1;
k--;
} else {
ary[2*i-1] = 2*i - 1;
ary[2*i] = 2*i;
}
}
for (int i = 1; i <= 2*n; i++){
System.out.print(ary[i]);
if (i + 1 <= 2*n){
System.out.print(' ');
}
}
System.out.print('\n');
}
static int[] getIntArray(){
String[] inp = getLine().split("\\s+");
int[] ret = new int[inp.length];
for (int i = 0; i < inp.length; i++) ret[i] = Integer.parseInt(inp[i]);
return ret;
}
static String getLine(){
try {
return reader.readLine().trim();
} catch (Exception e){
}
return null;
}
}
| Java | ["1 0", "2 1", "4 0"] | 1 second | ["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"] | NoteRecord |x| represents the absolute value of number x. In the first sample |1β-β2|β-β|1β-β2|β=β0.In the second sample |3β-β2|β+β|1β-β4|β-β|3β-β2β+β1β-β4|β=β1β+β3β-β2β=β2.In the third sample |2β-β7|β+β|4β-β6|β+β|1β-β3|β+β|5β-β8|β-β|2β-β7β+β4β-β6β+β1β-β3β+β5β-β8|β=β12β-β12β=β0. | Java 7 | standard input | [
"dp",
"constructive algorithms",
"math"
] | 82de6d4c892f4140e72606386ec2ef59 | The first line contains two integers n and k (1ββ€βnββ€β50000, 0ββ€β2kββ€βn). | 1,400 | Print 2n integers a1,βa2,β...,βa2n β the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them. | standard output | |
PASSED | 0d8aa97c3d3d274538b2531a8d5ed508 | train_003.jsonl | 1383379200 | A permutation p is an ordered group of numbers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,βββp2,βββ...,βββpn.Simon has a positive integer n and a non-negative integer k, such that 2kββ€βn. Help him find permutation a of length 2n, such that it meets this equation: . | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
static BufferedReader reader
= new BufferedReader(new InputStreamReader(System.in));
static StringBuilder out = new StringBuilder();
public static void main(String[] args){
int n, k;
int[] inp = nextIntArray();
n = inp[0]; k = inp[1];
int[] a = new int[2 * n];
for (int i = 0; i < 2*n; i++) a[i] = i + 1;
for (int i = 0; i < k; i++){
int tmp = a[2*i];
a[2*i] = a[2*i + 1];
a[2*i + 1] = tmp;
}
for (int i = 0; i < 2*n; i++){
out.append(a[i]);
if (i + 1 < 2*n)
out.append(" ");
}
System.out.println(out);
}
// the followings are methods to take care of inputs.
static int nextInt(){
return Integer.parseInt(nextLine());
}
static long nextLong(){
return Long.parseLong(nextLine());
}
static int[] nextIntArray(){
String[] inp = nextLine().split("\\s+");
int[] ary = new int[inp.length]; for (int i = 0; i < ary.length; i++){
ary[i] = Integer.parseInt(inp[i]);
}
return ary;
}
static int[] nextIntArrayFrom1(){
String[] inp = nextLine().split("\\s+");
int[] ary = new int[inp.length + 1];
for (int i = 0; i < inp.length; i++){
ary[i+1] = Integer.parseInt(inp[i]);
}
return ary;
}
static long[] nextLongArray(){
String[] inp = nextLine().split("\\s+");
long[] ary = new long[inp.length];
for (int i = 0; i < inp.length; i++){
ary[i] = Long.parseLong(inp[i]);
}
return ary;
}
static long[] nextLongArrayFrom1(){
String[] inp = nextLine().split("\\s+");
long[] ary = new long[inp.length + 1];
for (int i = 0; i < inp.length; i++){
ary[i+1] = Long.parseLong(inp[i]);
}
return ary;
}
static String nextLine(){
try {
return reader.readLine().trim();
} catch (Exception e){}
return null;
}
}
| Java | ["1 0", "2 1", "4 0"] | 1 second | ["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"] | NoteRecord |x| represents the absolute value of number x. In the first sample |1β-β2|β-β|1β-β2|β=β0.In the second sample |3β-β2|β+β|1β-β4|β-β|3β-β2β+β1β-β4|β=β1β+β3β-β2β=β2.In the third sample |2β-β7|β+β|4β-β6|β+β|1β-β3|β+β|5β-β8|β-β|2β-β7β+β4β-β6β+β1β-β3β+β5β-β8|β=β12β-β12β=β0. | Java 7 | standard input | [
"dp",
"constructive algorithms",
"math"
] | 82de6d4c892f4140e72606386ec2ef59 | The first line contains two integers n and k (1ββ€βnββ€β50000, 0ββ€β2kββ€βn). | 1,400 | Print 2n integers a1,βa2,β...,βa2n β the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them. | standard output | |
PASSED | 4404461cc7440e345ae75e06ad5fca9a | train_003.jsonl | 1383379200 | A permutation p is an ordered group of numbers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,βββp2,βββ...,βββpn.Simon has a positive integer n and a non-negative integer k, such that 2kββ€βn. Help him find permutation a of length 2n, such that it meets this equation: . | 256 megabytes | import java.io.InputStreamReader;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.StringTokenizer;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author Lokesh Khandelwal
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
TaskB solver = new TaskB();
solver.solve(1, in, out);
out.close();
}
}
class TaskB {
public void solve(int testNumber, InputReader in, OutputWriter out) {
int n = in.nextInt(), k = in.nextInt();
int a[] = new int[2*n], i;
for(i=0;i<2*n;i++)
a[i] = i + 1;
int j=0;
for(i=0;i<k;i++) {
int temp = a[j];
a[j] = a[j+1];
a[j+1]=temp;
j+=2;
}
for(i=0;i<2*n;i++)
out.print(a[i]+ " ");
}
}
class InputReader
{
BufferedReader in;
StringTokenizer tokenizer=null;
public InputReader(InputStream inputStream)
{
in=new BufferedReader(new InputStreamReader(inputStream));
}
public String next()
{
try{
while (tokenizer==null||!tokenizer.hasMoreTokens())
{
tokenizer=new StringTokenizer(in.readLine());
}
return tokenizer.nextToken();
}
catch (IOException e)
{
return null;
}
}
public int nextInt()
{
return Integer.parseInt(next());
}
}
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 close() {
writer.close();
}
}
| Java | ["1 0", "2 1", "4 0"] | 1 second | ["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"] | NoteRecord |x| represents the absolute value of number x. In the first sample |1β-β2|β-β|1β-β2|β=β0.In the second sample |3β-β2|β+β|1β-β4|β-β|3β-β2β+β1β-β4|β=β1β+β3β-β2β=β2.In the third sample |2β-β7|β+β|4β-β6|β+β|1β-β3|β+β|5β-β8|β-β|2β-β7β+β4β-β6β+β1β-β3β+β5β-β8|β=β12β-β12β=β0. | Java 7 | standard input | [
"dp",
"constructive algorithms",
"math"
] | 82de6d4c892f4140e72606386ec2ef59 | The first line contains two integers n and k (1ββ€βnββ€β50000, 0ββ€β2kββ€βn). | 1,400 | Print 2n integers a1,βa2,β...,βa2n β the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them. | standard output | |
PASSED | 34be582e7c1d3e4e2423682697f278eb | train_003.jsonl | 1383379200 | A permutation p is an ordered group of numbers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,βββp2,βββ...,βββpn.Simon has a positive integer n and a non-negative integer k, such that 2kββ€βn. Help him find permutation a of length 2n, such that it meets this equation: . | 256 megabytes | import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.HashSet;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeSet;
public class Solution{
///////////////////////////////////////////////////////////////////////////
static class FastScanner{
BufferedReader s;
StringTokenizer st;
public FastScanner(){
st = new StringTokenizer("");
s = new BufferedReader(new InputStreamReader(System.in));
}
public FastScanner(File f) throws FileNotFoundException{
st = new StringTokenizer("");
s = new BufferedReader (new FileReader(f));
}
public int nextInt() throws IOException{
if(st.hasMoreTokens())
return Integer.parseInt(st.nextToken());
else{
st = new StringTokenizer(s.readLine());
return nextInt();
}
}
/* public double nextDouble() throws IOException{
if(st.hasMoreTokens())
return Double.parseDouble(st.nextToken());
else{
st = new StringTokenizer(s.readLine());
return nextDouble();
}
}
*/
public long nextLong() throws IOException{
if(st.hasMoreTokens())
return Long.parseLong(st.nextToken());
else{
st = new StringTokenizer(s.readLine());
return nextLong();
}
}
public String nextString() throws IOException{
if(st.hasMoreTokens())
return st.nextToken();
else{
st = new StringTokenizer(s.readLine());
return nextString();
}
}
public String readLine() throws IOException{
return s.readLine();
}
public void close() throws IOException{
s.close();
}
}
////////////////////////////////////////////////////////////////////
// Number Theory
long pow(long a,long b,long mod){
long x = 1; long y = a;
while(b > 0){
if(b % 2 == 1){
x = (x*y);
x %= mod;
}
y = (y*y);
y %= mod;
b /= 2;
}
return x;
}
int divisor(long x,long[] a){
long limit = x;
int numberOfDivisors = 0;
for (int i=1; i < limit; ++i) {
if (x % i == 0) {
limit = x / i;
if (limit != i) {
numberOfDivisors++;
}
numberOfDivisors++;
}
}
return numberOfDivisors;
}
void findSubsets(int array[]){
long numOfSubsets = 1 << array.length;
for(int i = 0; i < numOfSubsets; i++){
int pos = array.length - 1;
int bitmask = i;
while(bitmask > 0){
if((bitmask & 1) == 1)
ww.print(array[pos]+" ");
bitmask >>= 1;
pos--;
}
ww.println();
}
}
public static int gcd(int a, int b){
return b == 0 ? a : gcd(b,a%b);
}
public static int lcm(int a,int b, int c){
return lcm(lcm(a,b),c);
}
public static int lcm(int a, int b){
return a*b/gcd(a,b);
}
////////////////////////////////////////////////////////////////////
// private static FastScanner s = new FastScanner(new File("input.txt"));
// private static PrintWriter ww = new PrintWriter(new FileWriter("output.txt"));
private static FastScanner s = new FastScanner();
private static PrintWriter ww = new PrintWriter(new OutputStreamWriter(System.out));
// private static Scanner s = new Scanner(System.in);
@SuppressWarnings("unused")
private static int[][] states = { {-1,0} , {1,0} , {0,-1} , {0,1} };
////////////////////////////////////////////////////////////////////
public static void main(String[] args) throws IOException{
new Solution().solve();
}
////////////////////////////////////////////////////////////////////
void solve() throws IOException{
int n = s.nextInt();
int k = s.nextInt();
for(int i=0;i<n;i++){
if(i != 0) ww.print(" ");
if(k > 0) ww.print((2*i+2)+" "+(2*i+1));
else ww.print((2*i+1)+" "+(2*i+2));
k--;
}
s.close();
ww.close();
}
} | Java | ["1 0", "2 1", "4 0"] | 1 second | ["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"] | NoteRecord |x| represents the absolute value of number x. In the first sample |1β-β2|β-β|1β-β2|β=β0.In the second sample |3β-β2|β+β|1β-β4|β-β|3β-β2β+β1β-β4|β=β1β+β3β-β2β=β2.In the third sample |2β-β7|β+β|4β-β6|β+β|1β-β3|β+β|5β-β8|β-β|2β-β7β+β4β-β6β+β1β-β3β+β5β-β8|β=β12β-β12β=β0. | Java 7 | standard input | [
"dp",
"constructive algorithms",
"math"
] | 82de6d4c892f4140e72606386ec2ef59 | The first line contains two integers n and k (1ββ€βnββ€β50000, 0ββ€β2kββ€βn). | 1,400 | Print 2n integers a1,βa2,β...,βa2n β the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them. | standard output | |
PASSED | 2feca5e3e13f0775142401daecc768eb | train_003.jsonl | 1383379200 | A permutation p is an ordered group of numbers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,βββp2,βββ...,βββpn.Simon has a positive integer n and a non-negative integer k, such that 2kββ€βn. Help him find permutation a of length 2n, such that it meets this equation: . | 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();
for(int i = 1; i <= n; i++){
if(k > 0){
System.out.print(2*i + " " + (2*i-1));
k--;
}
else{
System.out.print((2*i-1) + " " + 2*i);
}
if(i != n){
System.out.print(" ");
}
}
}
} | Java | ["1 0", "2 1", "4 0"] | 1 second | ["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"] | NoteRecord |x| represents the absolute value of number x. In the first sample |1β-β2|β-β|1β-β2|β=β0.In the second sample |3β-β2|β+β|1β-β4|β-β|3β-β2β+β1β-β4|β=β1β+β3β-β2β=β2.In the third sample |2β-β7|β+β|4β-β6|β+β|1β-β3|β+β|5β-β8|β-β|2β-β7β+β4β-β6β+β1β-β3β+β5β-β8|β=β12β-β12β=β0. | Java 7 | standard input | [
"dp",
"constructive algorithms",
"math"
] | 82de6d4c892f4140e72606386ec2ef59 | The first line contains two integers n and k (1ββ€βnββ€β50000, 0ββ€β2kββ€βn). | 1,400 | Print 2n integers a1,βa2,β...,βa2n β the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them. | standard output | |
PASSED | 2a4d523a1762ebecfbdc440d4edda7db | train_003.jsonl | 1383379200 | A permutation p is an ordered group of numbers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,βββp2,βββ...,βββpn.Simon has a positive integer n and a non-negative integer k, such that 2kββ€βn. Help him find permutation a of length 2n, such that it meets this equation: . | 256 megabytes | import java.io.PrintStream;
import java.util.*;
public class Problem209B {
public static void main(String[] args) throws Exception {
new Problem209B().solve(new Scanner(System.in), System.out);
}
public void solve(Scanner in, PrintStream out) throws Exception{
int n = in.nextInt();
int k = in.nextInt();
if (k == 0) {
out.print(1);
for (int i = 2; i <= 2*n; i++) {
out.print(" " + i);
}
out.println();
return;
}
for (int i = 1; i <= k; i++) {
out.print((i * 2 + 1) + " " + (i * 2) + " ");
}
for (int i = k + 1; i < n; i++) {
out.print((i * 2) + " " + (i * 2 + 1) + " ");
}
if (4 - k == 2*n) {
out.println((n * 2) + " " + 1);
} else {
out.println(1 + " " + (n * 2));
}
}
} | Java | ["1 0", "2 1", "4 0"] | 1 second | ["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"] | NoteRecord |x| represents the absolute value of number x. In the first sample |1β-β2|β-β|1β-β2|β=β0.In the second sample |3β-β2|β+β|1β-β4|β-β|3β-β2β+β1β-β4|β=β1β+β3β-β2β=β2.In the third sample |2β-β7|β+β|4β-β6|β+β|1β-β3|β+β|5β-β8|β-β|2β-β7β+β4β-β6β+β1β-β3β+β5β-β8|β=β12β-β12β=β0. | Java 7 | standard input | [
"dp",
"constructive algorithms",
"math"
] | 82de6d4c892f4140e72606386ec2ef59 | The first line contains two integers n and k (1ββ€βnββ€β50000, 0ββ€β2kββ€βn). | 1,400 | Print 2n integers a1,βa2,β...,βa2n β the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them. | standard output | |
PASSED | f0a41784cb1f7a3ee5d74c8768f17043 | train_003.jsonl | 1383379200 | A permutation p is an ordered group of numbers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,βββp2,βββ...,βββpn.Simon has a positive integer n and a non-negative integer k, such that 2kββ€βn. Help him find permutation a of length 2n, such that it meets this equation: . | 256 megabytes | import java.util.Scanner;
public class Permutation {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
int n_swaps = n - k;
int swapped = 0;
for (int i = 1; i <= n; i++) {
if (swapped < n_swaps) {
System.out.print(2 * i + " ");
System.out.print(2 * i - 1 + " ");
swapped++;
} else {
System.out.print(2 * i - 1 + " ");
System.out.print(2 * i + " ");
}
}
}
}
| Java | ["1 0", "2 1", "4 0"] | 1 second | ["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"] | NoteRecord |x| represents the absolute value of number x. In the first sample |1β-β2|β-β|1β-β2|β=β0.In the second sample |3β-β2|β+β|1β-β4|β-β|3β-β2β+β1β-β4|β=β1β+β3β-β2β=β2.In the third sample |2β-β7|β+β|4β-β6|β+β|1β-β3|β+β|5β-β8|β-β|2β-β7β+β4β-β6β+β1β-β3β+β5β-β8|β=β12β-β12β=β0. | Java 7 | standard input | [
"dp",
"constructive algorithms",
"math"
] | 82de6d4c892f4140e72606386ec2ef59 | The first line contains two integers n and k (1ββ€βnββ€β50000, 0ββ€β2kββ€βn). | 1,400 | Print 2n integers a1,βa2,β...,βa2n β the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them. | standard output | |
PASSED | 723af62ef49f24f749861999d6967233 | train_003.jsonl | 1383379200 | A permutation p is an ordered group of numbers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,βββp2,βββ...,βββpn.Simon has a positive integer n and a non-negative integer k, such that 2kββ€βn. Help him find permutation a of length 2n, such that it meets this equation: . | 256 megabytes |
import java.math.BigInteger;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;
import java.lang.Thread;
import java.lang.reflect.Array;
import java.util.Vector;
import java.math.*;
import javax.sound.sampled.Line;
public class Main {
public static void main(String[] args){
Scanner scanner=new Scanner(System.in);
int n=scanner.nextInt(),k=scanner.nextInt();
for (int i=0;i<n;i++){
int d;
if (i>=k) d=1;else d=0;
System.out.print(2*i+1+d);
System.out.print(' ');
System.out.print(2*i+2-d);
System.out.print(' ');
}
}
}
| Java | ["1 0", "2 1", "4 0"] | 1 second | ["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"] | NoteRecord |x| represents the absolute value of number x. In the first sample |1β-β2|β-β|1β-β2|β=β0.In the second sample |3β-β2|β+β|1β-β4|β-β|3β-β2β+β1β-β4|β=β1β+β3β-β2β=β2.In the third sample |2β-β7|β+β|4β-β6|β+β|1β-β3|β+β|5β-β8|β-β|2β-β7β+β4β-β6β+β1β-β3β+β5β-β8|β=β12β-β12β=β0. | Java 7 | standard input | [
"dp",
"constructive algorithms",
"math"
] | 82de6d4c892f4140e72606386ec2ef59 | The first line contains two integers n and k (1ββ€βnββ€β50000, 0ββ€β2kββ€βn). | 1,400 | Print 2n integers a1,βa2,β...,βa2n β the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them. | standard output | |
PASSED | 0733c49e311b85dc9673ec561030cc9b | train_003.jsonl | 1383379200 | A permutation p is an ordered group of numbers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,βββp2,βββ...,βββpn.Simon has a positive integer n and a non-negative integer k, such that 2kββ€βn. Help him find permutation a of length 2n, such that it meets this equation: . | 256 megabytes |
import java.util.Arrays;
import java.util.Scanner;
public class A {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int k = s.nextInt() * 2;
int[] arr = new int[n * 2];
for (int i = 0; i < n * 2; i++)
arr[i] = i + 1;
int count = k / 2;
for (int i = 0; i < arr.length - 1; i += 2) {
if (count == 0)
break;
int tmp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = tmp;
count--;
}
for (int i = 0; i < arr.length; i++)
System.out.print(arr[i] + " ");
System.out.println();
}
}
| Java | ["1 0", "2 1", "4 0"] | 1 second | ["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"] | NoteRecord |x| represents the absolute value of number x. In the first sample |1β-β2|β-β|1β-β2|β=β0.In the second sample |3β-β2|β+β|1β-β4|β-β|3β-β2β+β1β-β4|β=β1β+β3β-β2β=β2.In the third sample |2β-β7|β+β|4β-β6|β+β|1β-β3|β+β|5β-β8|β-β|2β-β7β+β4β-β6β+β1β-β3β+β5β-β8|β=β12β-β12β=β0. | Java 7 | standard input | [
"dp",
"constructive algorithms",
"math"
] | 82de6d4c892f4140e72606386ec2ef59 | The first line contains two integers n and k (1ββ€βnββ€β50000, 0ββ€β2kββ€βn). | 1,400 | Print 2n integers a1,βa2,β...,βa2n β the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them. | standard output | |
PASSED | 2057fae00fc6ad394fefe2d39c2e85e5 | train_003.jsonl | 1383379200 | A permutation p is an ordered group of numbers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,βββp2,βββ...,βββpn.Simon has a positive integer n and a non-negative integer k, such that 2kββ€βn. Help him find permutation a of length 2n, such that it meets this equation: . | 256 megabytes | import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Stack;
public class Q1 {
public static void main(String[] args) {
FasterScanner s= new FasterScanner();
PrintWriter out=new PrintWriter(System.out);
int n=s.nextInt();
int k=s.nextInt();
int i=0;
for(i=0;i<k;i++)
{
out.print(2*i+2);
out.print(' ');
out.print(2*i+1);
out.print(' ');
}
for(;i<n;i++)
{
out.print(2*i+1);
out.print(' ');
out.print(2*i+2);
out.print(' ');
}
out.close();
}
static class FasterScanner {
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = System.in.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public String nextLine() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c));
return res.toString();
}
public String nextString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public long nextLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public int nextInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public int[] nextIntArray(int n) {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = nextInt();
}
return arr;
}
public long[] nextLongArray(int n) {
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = nextLong();
}
return arr;
}
private boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
}
} | Java | ["1 0", "2 1", "4 0"] | 1 second | ["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"] | NoteRecord |x| represents the absolute value of number x. In the first sample |1β-β2|β-β|1β-β2|β=β0.In the second sample |3β-β2|β+β|1β-β4|β-β|3β-β2β+β1β-β4|β=β1β+β3β-β2β=β2.In the third sample |2β-β7|β+β|4β-β6|β+β|1β-β3|β+β|5β-β8|β-β|2β-β7β+β4β-β6β+β1β-β3β+β5β-β8|β=β12β-β12β=β0. | Java 7 | standard input | [
"dp",
"constructive algorithms",
"math"
] | 82de6d4c892f4140e72606386ec2ef59 | The first line contains two integers n and k (1ββ€βnββ€β50000, 0ββ€β2kββ€βn). | 1,400 | Print 2n integers a1,βa2,β...,βa2n β the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them. | standard output | |
PASSED | 18fdae8d5a23bcae568a21f4da634e17 | train_003.jsonl | 1383379200 | A permutation p is an ordered group of numbers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,βββp2,βββ...,βββpn.Simon has a positive integer n and a non-negative integer k, such that 2kββ€βn. Help him find permutation a of length 2n, such that it meets this equation: . | 256 megabytes | import java.util.Scanner;
public class Problem_B_359 {
/**
* @param args
*/
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int[] a=new int[100001];
int n,m,i,j,l,k,w;
n=in.nextInt();
k=in.nextInt();
for(i=1;i<=2*n;i++){
a[i]=i;
if(i%2==0 && i/2<=k){
w=a[i];
a[i]=a[i-1];
a[i-1]=w;
}
}
for(i=1;i<=2*n;i++){
System.out.print(a[i]+" ");
}
}
}
| Java | ["1 0", "2 1", "4 0"] | 1 second | ["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"] | NoteRecord |x| represents the absolute value of number x. In the first sample |1β-β2|β-β|1β-β2|β=β0.In the second sample |3β-β2|β+β|1β-β4|β-β|3β-β2β+β1β-β4|β=β1β+β3β-β2β=β2.In the third sample |2β-β7|β+β|4β-β6|β+β|1β-β3|β+β|5β-β8|β-β|2β-β7β+β4β-β6β+β1β-β3β+β5β-β8|β=β12β-β12β=β0. | Java 7 | standard input | [
"dp",
"constructive algorithms",
"math"
] | 82de6d4c892f4140e72606386ec2ef59 | The first line contains two integers n and k (1ββ€βnββ€β50000, 0ββ€β2kββ€βn). | 1,400 | Print 2n integers a1,βa2,β...,βa2n β the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them. | standard output | |
PASSED | 7a202c09cbbf8971e4baaea964a185bc | train_003.jsonl | 1383379200 | A permutation p is an ordered group of numbers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,βββp2,βββ...,βββpn.Simon has a positive integer n and a non-negative integer k, such that 2kββ€βn. Help him find permutation a of length 2n, such that it meets this equation: . | 256 megabytes | import java.io.*;
import java.util.*;
public class cf359b {
static FastIO in = new FastIO(), out = in;
public static void main(String[] args) {
int n = in.nextInt(), k = in.nextInt();
int[] v = new int[2*n];
for(int i=0; i<2*n; i++)
v[i] = i+1;
for(int i=0; i<2*k; i+=2) {
int tmp = v[i];
v[i] = v[i+1];
v[i+1] = tmp;
}
for(int x : v) out.print(x+" ");
out.println();
out.close();
}
static class FastIO extends PrintWriter {
BufferedReader br;
StringTokenizer st;
public FastIO() {
this(System.in, System.out);
}
public FastIO(InputStream in, OutputStream out) {
super(new BufferedWriter(new OutputStreamWriter(out)));
br = new BufferedReader(new InputStreamReader(in));
scanLine();
}
public void scanLine() {
try {
st = new StringTokenizer(br.readLine().trim());
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
}
public int numTokens() {
if (!st.hasMoreTokens()) {
scanLine();
return numTokens();
}
return st.countTokens();
}
public String next() {
if (!st.hasMoreTokens()) {
scanLine();
return next();
}
return st.nextToken();
}
public double nextDouble() {
return Double.parseDouble(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
| Java | ["1 0", "2 1", "4 0"] | 1 second | ["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"] | NoteRecord |x| represents the absolute value of number x. In the first sample |1β-β2|β-β|1β-β2|β=β0.In the second sample |3β-β2|β+β|1β-β4|β-β|3β-β2β+β1β-β4|β=β1β+β3β-β2β=β2.In the third sample |2β-β7|β+β|4β-β6|β+β|1β-β3|β+β|5β-β8|β-β|2β-β7β+β4β-β6β+β1β-β3β+β5β-β8|β=β12β-β12β=β0. | Java 7 | standard input | [
"dp",
"constructive algorithms",
"math"
] | 82de6d4c892f4140e72606386ec2ef59 | The first line contains two integers n and k (1ββ€βnββ€β50000, 0ββ€β2kββ€βn). | 1,400 | Print 2n integers a1,βa2,β...,βa2n β the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them. | standard output | |
PASSED | 8ceb7decae023a399c7b5b0f5587e238 | train_003.jsonl | 1383379200 | A permutation p is an ordered group of numbers p1,βββp2,βββ...,βββpn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,βββp2,βββ...,βββpn.Simon has a positive integer n and a non-negative integer k, such that 2kββ€βn. Help him find permutation a of length 2n, such that it meets this equation: . | 256 megabytes | import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.io.Writer;
import java.math.BigInteger;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author Roman Dzhadan
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
TaskB solver = new TaskB();
solver.solve(1, in, out);
out.close();
}
}
class TaskB {
int n;
int k;
int[]numbers;
public void solve(int testNumber, InputReader in, OutputWriter out) {
n = in.readInt();
k = in.readInt();
numbers = new int[(int)(2 * n)];
for (int i = 0; i < 2 * n; i++) {
numbers[i] = i + 1;
}
int result = check();
if (result == 2 * k) {
out.printLine(numbers);
}
else {
if (result != 2 * k) {
result = Math.abs(result - 2 * k);
for (int i = 0; i < result; i++) {
numbers[i] = result - i;
}
for (int i = result; i < 2 * n; i++) {
numbers[i] = i + 1;
}
// int tmp = numbers[(int)result];
// numbers[(int)result] = numbers[(int)(n - result)];
// numbers[(int)(n - result)] = tmp;
}
if (check() == 2 * k)
out.printLine(numbers);
}
}
public int check() {
int first = 0;
int second = 0;
for (int i = 0; i < n; i++) {
first += Math.abs(numbers[2 * i] - numbers[2 * i + 1]);
second += numbers[2 * i] - numbers[2 * i + 1];
}
second = Math.abs(second);
return first - second;
}
}
class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int readInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
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(int[] array) {
for (int i = 0; i < array.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(array[i]);
}
}
public void printLine(int[] array) {
print(array);
writer.println();
}
public void close() {
writer.close();
}
}
| Java | ["1 0", "2 1", "4 0"] | 1 second | ["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"] | NoteRecord |x| represents the absolute value of number x. In the first sample |1β-β2|β-β|1β-β2|β=β0.In the second sample |3β-β2|β+β|1β-β4|β-β|3β-β2β+β1β-β4|β=β1β+β3β-β2β=β2.In the third sample |2β-β7|β+β|4β-β6|β+β|1β-β3|β+β|5β-β8|β-β|2β-β7β+β4β-β6β+β1β-β3β+β5β-β8|β=β12β-β12β=β0. | Java 7 | standard input | [
"dp",
"constructive algorithms",
"math"
] | 82de6d4c892f4140e72606386ec2ef59 | The first line contains two integers n and k (1ββ€βnββ€β50000, 0ββ€β2kββ€βn). | 1,400 | Print 2n integers a1,βa2,β...,βa2n β the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.