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
|
059a4fe6e8a14a8ff2076c6562f570f7
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.Scanner;
public class CodeForces {
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 c=0;
for (int x=0;x<n;x++){
if (c==1){
break;
}
for (int y=0;y<m;y++){
if (x-2<0&&x+2>=n&&y-2<0&&y+2>=m){
System.out.println((x+1)+" "+(y+1));
c++;
break;}
else if (x+1==n&&y+1==m&&c==0){
System.out.println(n+" "+m);}}}}}}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
ff8a7e7014f60f4361bf648d0d4281ee
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.Scanner;
public class ImmobileKnight {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
while(T-->0){
int x = sc.nextInt();
int y = sc.nextInt();
System.out.println((++x/2)+" "+(++y/2));
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
402ec4e0047da570c3173bff9efd5132
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.*;
public class Main {
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();
solve1739(n,m);
}
}
public static void solve1739(int r,int c){
r/=2;
c/=2;
r++;
c++;
System.out.println(r+" "+c);
}
public static void solve1738(){
Scanner sc= new Scanner(System.in);
int t=sc.nextInt();
for(int ii=0;ii<t;ii++) {
int n = sc.nextInt();
int[] skillTypes = new int[n];
int[] damages = new int[n];
ArrayList<Integer> fires = new ArrayList<>();
ArrayList<Integer> frosts = new ArrayList<>();
for (int i = 0; i < n; i++) {
skillTypes[i] = sc.nextInt();
}
for (int i = 0; i < n; i++) {
damages[i] = sc.nextInt();
}
for (int i = 0; i < n; i++) {
if (skillTypes[i] == 0)
fires.add(damages[i]);
else
frosts.add(damages[i]);
}
Collections.sort(fires);
//System.out.println(fires);
Collections.sort(frosts);
//System.out.println(frosts);
int count = Math.min(fires.size(), frosts.size());
long sum=0;
for(int i=0;i<count;i++){
sum+=2*fires.get(fires.size()-1-i);
sum+=2* frosts.get(frosts.size()-1-i);
}
if(fires.size()>frosts.size()){
for(int i=0;i<fires.size()-count;i++)
sum+=fires.get(i);
}
else if(frosts.size()>fires.size()){
for(int i=0;i<frosts.size()-count;i++)
sum+=frosts.get(i);
}
else{
sum-=Math.min(fires.get(0),frosts.get(0) );
}
System.out.println(sum);
continue;
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
4b39137608dac5598ec774b545b28ccd
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.*;
public class Main {
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();
solve1739(n,m);
}
}
public static void solve1739(int r,int c){
int [][]grid=new int[r][c];
int count=0;
for(int i=0;i<r;i++){
for(int j=0;j<c;j++){
int flag=0;
//up-left
try{
if(grid[i-2][j-1]==0){
continue;
}
}catch (Exception e){
flag++;
}
//up-right
try{
if(grid[i-2][j+1]==0){
continue;
}
}catch (Exception e){
flag++;
}
//down-left
try{
if(grid[i+2][j-1]==0){
continue;
}
}catch (Exception e){
flag++;
}
//down-right
try{
if(grid[i+2][j+1]==0){
continue;
}
}catch (Exception e){
flag++;
}
//left-up
try{
if(grid[i-1][j-2]==0){
continue;
}
}catch (Exception e){
flag++;
}
//left-down
try{
if(grid[i+1][j-2]==0){
continue;
}
}catch (Exception e){
flag++;
}
//right up
try{
if(grid[i-1][j+2]==0){
continue;
}
}catch (Exception e){
flag++;
}
//right down
try{
if(grid[i+1][j+2]==0){
continue;
}
}catch (Exception e){
flag++;
}
if(flag==8) {
i++;
j++;
System.out.println(i+" "+j);
return;
}
}
}
if(count==0)
System.out.println(r+" "+c);
}
public static void solve1738(){
Scanner sc= new Scanner(System.in);
int t=sc.nextInt();
for(int ii=0;ii<t;ii++) {
int n = sc.nextInt();
int[] skillTypes = new int[n];
int[] damages = new int[n];
ArrayList<Integer> fires = new ArrayList<>();
ArrayList<Integer> frosts = new ArrayList<>();
for (int i = 0; i < n; i++) {
skillTypes[i] = sc.nextInt();
}
for (int i = 0; i < n; i++) {
damages[i] = sc.nextInt();
}
for (int i = 0; i < n; i++) {
if (skillTypes[i] == 0)
fires.add(damages[i]);
else
frosts.add(damages[i]);
}
Collections.sort(fires);
//System.out.println(fires);
Collections.sort(frosts);
//System.out.println(frosts);
int count = Math.min(fires.size(), frosts.size());
long sum=0;
for(int i=0;i<count;i++){
sum+=2*fires.get(fires.size()-1-i);
sum+=2* frosts.get(frosts.size()-1-i);
}
if(fires.size()>frosts.size()){
for(int i=0;i<fires.size()-count;i++)
sum+=fires.get(i);
}
else if(frosts.size()>fires.size()){
for(int i=0;i<frosts.size()-count;i++)
sum+=frosts.get(i);
}
else{
sum-=Math.min(fires.get(0),frosts.get(0) );
}
System.out.println(sum);
continue;
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
d1bf45c7cbcbc90c2a9613539aa25484
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
//package com.rajat.cp.codeforces.edu136;
import java.util.Scanner;
public class AImmobileKnight {
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();
if( n == m && n == 3) {
System.out.println("2 2");
continue;
}
if((n== 2 && m == 3) || (n == 3 && m == 2)) {
System.out.println("2 2");
continue;
}
System.out.println("1 1");
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
dd5de3002e963fea84ee1de26ee7ad09
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
/*############################################################################################################
########################################## >>>> Diaa12360 <<<< ###############################################
########################################### Just Nothing #################################################
#################################### If You Need it, Fight For IT; #########################################
###############################################.-. 1 5 9 2 .-.################################################
############################################################################################################*/
import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
public class Solution {
public static void main(String[] args) throws Exception {
FastScanner in = new FastScanner();
// PrintWriter out = new PrintWriter(System.out);
int t = in.nextInt();
while (t-- > 0) {
int n = in.nextInt(),m = in.nextInt();
if(n <= 3 && m <= 3)
System.out.print((n/2+1) + " " + (m/2+1));
else
System.out.print(n + " " + m);
System.out.println();
}
// out.flush();
}
static int lcm(int a, int b) {
return a / gcd(a, b) * b;
}
static int gcd(int a, int b) {
if (a == 0) {
return b;
}
return gcd(b % a, a);
}
//all primes
static ArrayList<Integer> primes;
static boolean[] primesB;
//sieve algorithm
static void sieve(int n) {
primes = new ArrayList<>();
primesB = new boolean[n + 1];
for (int i = 2; i <= n; i++) {
primesB[i] = true;
}
for (int i = 2; i * i <= n; i++) {
if (primesB[i]) {
for (int j = i * i; j <= n; j += i) {
primesB[j] = false;
}
}
}
for (int i = 0; i <= n; i++) {
if (primesB[i]) {
primes.add(i);
}
}
}
// Function to find gcd of array of
// numbers
static int findGCD(int[] arr, int n) {
int result = arr[0];
for (int element : arr) {
result = gcd(result, element);
if (result == 1) {
return 1;
}
}
return result;
}
private static class FastScanner {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
private FastScanner() throws IOException {
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
private short nextShort() throws IOException {
short ret = 0;
byte c = read();
while (c <= ' ') c = read();
boolean neg = (c == '-');
if (neg) c = read();
do ret = (short) (ret * 10 + c - '0'); while ((c = read()) >= '0' && c <= '9');
if (neg) return (short) -ret;
return ret;
}
private 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;
}
private char nextChar() throws IOException {
byte c = read();
while (c <= ' ') c = read();
return (char) c;
}
private String nextString() throws IOException {
StringBuilder ret = new StringBuilder();
byte c = read();
while (c <= ' ') c = read();
do {
ret.append((char) c);
} while ((c = read()) > ' ');
return ret.toString();
}
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++];
}
}
private static int anInt(String s) {
return Integer.parseInt(s);
}
private static long ll(String s) {
return Long.parseLong(s);
}
}
class Pair<K, V> implements Comparable<Pair<K, V>> {
K first;
V second;
Pair(K f, V s) {
first = f;
second = s;
}
@Override
public int compareTo(Pair<K, V> o) {
return 0;
}
}
class PairInt implements Comparable<PairInt> {
int first;
int second;
PairInt(int f, int s) {
first = f;
second = s;
}
@Override
public int compareTo(PairInt o) {
if (this.first > o.first) {
return 1;
} else if (this.first < o.first) return -1;
else {
if (this.second < o.second) return 1;
else if (this.second == o.second) return -1;
return 0;
}
}
@Override
public String toString() {
return "<" + first + ", " + second + ">";
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
77f063692e3f63cb4743ef6d1b94751d
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
/*############################################################################################################
########################################## >>>> Diaa12360 <<<< ###############################################
########################################### Just Nothing #################################################
#################################### If You Need it, Fight For IT; #########################################
###############################################.-. 1 5 9 2 .-.################################################
############################################################################################################*/
import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
public class Solution {
public static void main(String[] args) throws Exception {
FastScanner in = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int t = in.nextInt();
while (t-- > 0) {
int n = in.nextInt(),m = in.nextInt();
if(n <= 3 && m <= 3)
out.print((n/2+1) + " " + (m/2+1));
else
out.print(n + " " + m);
out.println();
}
out.flush();
}
static int lcm(int a, int b) {
return a / gcd(a, b) * b;
}
static int gcd(int a, int b) {
if (a == 0) {
return b;
}
return gcd(b % a, a);
}
//all primes
static ArrayList<Integer> primes;
static boolean[] primesB;
//sieve algorithm
static void sieve(int n) {
primes = new ArrayList<>();
primesB = new boolean[n + 1];
for (int i = 2; i <= n; i++) {
primesB[i] = true;
}
for (int i = 2; i * i <= n; i++) {
if (primesB[i]) {
for (int j = i * i; j <= n; j += i) {
primesB[j] = false;
}
}
}
for (int i = 0; i <= n; i++) {
if (primesB[i]) {
primes.add(i);
}
}
}
// Function to find gcd of array of
// numbers
static int findGCD(int[] arr, int n) {
int result = arr[0];
for (int element : arr) {
result = gcd(result, element);
if (result == 1) {
return 1;
}
}
return result;
}
private static class FastScanner {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
private FastScanner() throws IOException {
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
private short nextShort() throws IOException {
short ret = 0;
byte c = read();
while (c <= ' ') c = read();
boolean neg = (c == '-');
if (neg) c = read();
do ret = (short) (ret * 10 + c - '0'); while ((c = read()) >= '0' && c <= '9');
if (neg) return (short) -ret;
return ret;
}
private 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;
}
private char nextChar() throws IOException {
byte c = read();
while (c <= ' ') c = read();
return (char) c;
}
private String nextString() throws IOException {
StringBuilder ret = new StringBuilder();
byte c = read();
while (c <= ' ') c = read();
do {
ret.append((char) c);
} while ((c = read()) > ' ');
return ret.toString();
}
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++];
}
}
private static int anInt(String s) {
return Integer.parseInt(s);
}
private static long ll(String s) {
return Long.parseLong(s);
}
}
class Pair<K, V> implements Comparable<Pair<K, V>> {
K first;
V second;
Pair(K f, V s) {
first = f;
second = s;
}
@Override
public int compareTo(Pair<K, V> o) {
return 0;
}
}
class PairInt implements Comparable<PairInt> {
int first;
int second;
PairInt(int f, int s) {
first = f;
second = s;
}
@Override
public int compareTo(PairInt o) {
if (this.first > o.first) {
return 1;
} else if (this.first < o.first) return -1;
else {
if (this.second < o.second) return 1;
else if (this.second == o.second) return -1;
return 0;
}
}
@Override
public String toString() {
return "<" + first + ", " + second + ">";
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
25c7523b66e8279d7690a61ee73b76b9
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.*;
public class Knight
{
public static void main(String [] args)
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t>0)
{
t--;
int n=sc.nextInt();
int m=sc.nextInt();
if(n==1||m==1)
{
System.out.println(n+" "+m);
}
else if(n==3 || m<=3)
{
System.out.println("2 2");
}
else
System.out.println(n+" "+m);
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
f53a6fb88650a5e2419f3007c9c78bca
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
int X[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int Y[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
while(t-- > 0)
{
int n = sc.nextInt();
int m = sc.nextInt();
int flag = 0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
flag = 0;
for(int d = 0;d<8;d++)
{
int r = i + X[d];
int c = j + Y[d];
if(r > 0 && r <= n && c >0 && c <=m) continue;
else
flag++;
}
if(flag == 8)
{
System.out.println(i + " " + j);
break;
}
}
if(flag == 8) break;
}
if(flag != 8)
System.out.println(n + " " + m);
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
91d439439f68d42f07bc63e465d9fb9b
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.*;
public class prog1 {
static int[] solve(int n,int m)
{
int ans[] = new int[2];
if(n == 1 || m ==1)
{
ans[0] = 1;
ans[1] = m;
return ans;
}
if(n<=3 && m<=3)
{
ans[0] = n-1;
ans[1] = m-1;
return ans;
}
if(n == 3 && m==3)
{
ans[0] = 2;
ans[1] = 2;
}
ans[0] = 1;
ans[1] = m;
return ans;
}
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int i=1;i<=t;i++)
{
int n = sc.nextInt();
int m = sc.nextInt();
int a[] = new int[2];
a = solve(n,m);
System.out.print(a[0]+" "+a[1]+"\n");
}
sc.close();
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
fd296d3a57b0b848a9dae6455cd79808
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class Main {
public static void main(String [] args) {
FastScanner fs=new FastScanner();
PrintWriter out=new PrintWriter(System.out);
StringBuilder sb = new StringBuilder();
int tt = fs.nextInt();
while(tt-- > 0) {
int n = fs.nextInt(), m = fs.nextInt();
int resn = 0, resm = 0;
if(n == 3 && m == 3) {
resn = 2; resm = 2;
}
else if(n == 3 || m == 3) {
if(n == 3) {
if(m > 3) {
resn = 1;
resm = 1;
}
else {
resn =2;
resm = 1;
}
}else {
if(n > 3) {
resn = 1;
resm = 1;
}
else {
resn =1;
resm = 2;
}
}
}
else {
resn = n; resm = m;
}
sb.append(resn + " " + resm).append("\n");
}
out.print(sb);
out.close();
}
static int isPerfectSquare(int x)
{
if (x >= 0) {
int sr = (int)Math.sqrt(x);
if((sr * sr) == x) return sr;
else return 0;
}
return 0;
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
Long [] readArray(int n) {
Long [] a=new Long [n];
for (int i=0; i<n; i++) a[i]=nextLong();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
90c8e2b01c99d557036d1ddae8794624
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class tr0 {
static StringBuilder sb;
static int inf = (int) 1e9;
static int mod = (int) 1e9 + 7;
static int n, m, k;
static TreeSet<Integer>[] ad, mult;
static long[][][][] memo;
static long[] f, val;
static HashMap<Integer, Integer> hm;
static ArrayList<int[]> av;
static TreeMap<int[], Integer> tm;
static boolean[] vis;
static char[][] g;
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
int m = sc.nextInt();
int max = Math.max(n, m);
int min = Math.min(n, m);
if (n == 3 && m == 3)
out.println(2 + " " + 2);
else {
if (min == 2 && max == 3) {
if (n == 2)
out.println(1 + " " + 2);
else
out.println(2 + " " + 1);
} else
out.println(1 + " " + 1);
}
}
out.flush();
}
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 int[] nextArrInt(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public long[] nextArrLong(int n) throws IOException {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public int[] nextArrIntSorted(int n) throws IOException {
int[] a = new int[n];
Integer[] a1 = new Integer[n];
for (int i = 0; i < n; i++)
a1[i] = nextInt();
Arrays.sort(a1);
for (int i = 0; i < n; i++)
a[i] = a1[i].intValue();
return a;
}
public long[] nextArrLongSorted(int n) throws IOException {
long[] a = new long[n];
Long[] a1 = new Long[n];
for (int i = 0; i < n; i++)
a1[i] = nextLong();
Arrays.sort(a1);
for (int i = 0; i < n; i++)
a[i] = a1[i].longValue();
return a;
}
public boolean ready() throws IOException {
return br.ready();
}
public void waitForInput() throws InterruptedException {
Thread.sleep(3000);
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
62a3463e727851d4df6b7d94e84fb152
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class D {
private void solve() {
int t = nextInt();
for (int tt = 0; tt < t; tt++) {
int n = nextInt();
int m = nextInt();
int min = Math.min(n, m);
int max = Math.max(n, m);
if ((min == 2 || min == 3) && max == 3) {
out.println(2 + " " + 2);
} else {
out.println(1 + " " + 1);
}
}
}
private void run() {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
out.close();
}
public static void main(String[] args) {
new D().run();
}
private BufferedReader br;
private StringTokenizer st;
private PrintWriter out;
private String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
return st.nextToken();
}
private Integer nextInt() {
return Integer.parseInt(next());
}
private Long nextLong() {
return Long.parseLong(next());
}
private Double nextDouble() {
return Double.parseDouble(next());
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
89819cf8f23e5c9a308e17fd8ba96dd5
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
long n = in.nextInt();
while (n-- > 0) {
int m = in.nextInt();
int k = in.nextInt();
int[][] temp = new int[][]{{-1,-2},{1,-2},{-2,-1},{-2,1},{2,-1},{2,1},{-1,2},{1,2}};
boolean needContinue = true;
for (int i = 1; i <= m && needContinue; i++) {
for (int j = 1; j <= k; j++) {
boolean flag = false;
for (int[] ints : temp) {
int x = i + ints[0];
int y = j + ints[1];
if (x > 0 && y > 0 && x <= m && y <= k){
flag = true;
}
}
if (!flag){
System.out.println(i + " " + j);
needContinue = false;
break;
}
}
}
if (needContinue){
System.out.println(m + " " + k);
}
}
}
public static int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
2605f2dd179b51c6315886a54c093cc5
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int tc = sc.nextInt();
while (tc-- > 0) {
int n = sc.nextInt();
int m = sc.nextInt();
if (Math.max(n, m) == 3) {
if (Math.min(n, m) == 1) {
System.out.println(1 + " " + 1);
}
else {
System.out.println(2 + " " + 2);
}
}
else {
System.out.println(1 + " " + 1);
}
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
be6d004d502fab66248b03fc7a95761e
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
int t = Integer.parseInt(br.readLine());
for (int i = 0; i < t; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
if(n==1 || m==1) pw.println(1 + " " + 1);
else if(n==3 || m==3) pw.println(2 + " " +2);
else pw.println(1 + " " + 1);
}
pw.close();
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
ec09411004c2eba2e22038fba7c54b71
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.*;
public class Main{
public static void main(String [] args){
Scanner sc = new Scanner(System.in);
int test = sc.nextInt();
for(int t=0;t<test;t++){
int n = sc.nextInt();
int m = sc.nextInt();
if (n == 1 || m == 1) {
System.out.println("1 1");
} else {
System.out.println("2 2");
}
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
b8d6c454aa80812e2dc8afd26887e9d7
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.io.*;
public class Solution {
public static void main(String args[]){
FastScanner sc = new FastScanner();
int t = sc.nextInt();
while(t-- > 0){
int n = sc.nextInt();
int m = sc.nextInt();
if(n >= 2 && m >= 2){
System.out.println("2 2");
}
else{
System.out.println("1 1");
}
}
}
}
class FastScanner
{
//I don't understand how this works lmao
private int BS = 1 << 16;
private char NC = (char) 0;
private byte[] buf = new byte[BS];
private int bId = 0, size = 0;
private char c = NC;
private double cnt = 1;
private BufferedInputStream in;
public FastScanner() {
in = new BufferedInputStream(System.in, BS);
}
public FastScanner(String s) {
try {
in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
} catch (Exception e) {
in = new BufferedInputStream(System.in, BS);
}
}
private char getChar() {
while (bId == size) {
try {
size = in.read(buf);
} catch (Exception e) {
return NC;
}
if (size == -1) return NC;
bId = 0;
}
return (char) buf[bId++];
}
public int nextInt() {
return (int) nextLong();
}
public int[] nextInts(int N) {
int[] res = new int[N];
for (int i = 0; i < N; i++) {
res[i] = (int) nextLong();
}
return res;
}
public long[] nextLongs(int N) {
long[] res = new long[N];
for (int i = 0; i < N; i++) {
res[i] = nextLong();
}
return res;
}
public long nextLong() {
cnt = 1;
boolean neg = false;
if (c == NC) c = getChar();
for (; (c < '0' || c > '9'); c = getChar()) {
if (c == '-') neg = true;
}
long res = 0;
for (; c >= '0' && c <= '9'; c = getChar()) {
res = (res << 3) + (res << 1) + c - '0';
cnt *= 10;
}
return neg ? -res : res;
}
public double nextDouble() {
double cur = nextLong();
return c != '.' ? cur : cur + nextLong() / cnt;
}
public double[] nextDoubles(int N) {
double[] res = new double[N];
for (int i = 0; i < N; i++) {
res[i] = nextDouble();
}
return res;
}
public String next() {
StringBuilder res = new StringBuilder();
while (c <= 32) c = getChar();
while (c > 32) {
res.append(c);
c = getChar();
}
return res.toString();
}
public String nextLine() {
StringBuilder res = new StringBuilder();
while (c <= 32) c = getChar();
while (c != '\n') {
res.append(c);
c = getChar();
}
return res.toString();
}
public boolean hasNext() {
if (c > 32) return true;
while (true) {
c = getChar();
if (c == NC) return false;
else if (c > 32) return true;
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
a89f95d17374ffe181a951280097275d
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class A {
static class Pair
{
int f;int s; //
Pair(){}
Pair(int f,int s){ this.f=f;this.s=s;}
}
static class sortbyfirst implements Comparator<Pair>
{
public int compare(Pair a,Pair b)
{
return a.f-b.f;
}
}
static class Fast {
BufferedReader br;
StringTokenizer st;
public Fast() {
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());
}
int[] readArray(int n) {
int a[] = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
long[] readArray1(int n) {
long a[] = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
String nextLine() {
String str = "";
try {
str = br.readLine().trim();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
/* static long noOfDivisor(long a)
{
long count=0;
long t=a;
for(long i=1;i<=(int)Math.sqrt(a);i++)
{
if(a%i==0)
count+=2;
}
if(a==((long)Math.sqrt(a)*(long)Math.sqrt(a)))
{
count--;
}
return count;
}*/
static boolean isPrime(long a) {
for (long i = 2; i <= (long) Math.sqrt(a); i++) {
if (a % i == 0)
return false;
}
return true;
}
static void primeFact(int n) {
int temp = n;
HashMap<Integer, Integer> h = new HashMap<>();
for (int i = 2; i * i <= n; i++) {
if (temp % i == 0) {
int c = 0;
while (temp % i == 0) {
c++;
temp /= i;
}
h.put(i, c);
}
}
if (temp != 1)
h.put(temp, 1);
}
static void reverseArray(int a[]) {
int n = a.length;
for (int i = 0; i < n / 2; i++) {
a[i] = a[i] ^ a[n - i - 1];
a[n - i - 1] = a[i] ^ a[n - i - 1];
a[i] = a[i] ^ a[n - i - 1];
}
}
static void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static void sort(long [] a) {
ArrayList<Long> l=new ArrayList<>();
for (long i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static int max(int a,int b)
{
return a>b?a:b;
}
static int min(int a,int b)
{
return a<b?a:b;
}
public static void main(String args[]) throws IOException {
Fast sc = new Fast();
PrintWriter out = new PrintWriter(System.out);
int t1 = sc.nextInt();
while (t1-- > 0) {
int n=sc.nextInt();int m=sc.nextInt();
int d1[]={2,-2};int d2[]={1,-1};int ok=1;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
int f1=0;int f2=0;
for(int i1=0;i1<2;i1++)
{
int nx1=i+d1[i1];
int nx2=i+d2[i1];
for(int j1=0;j1<2;j1++)
{
int ny1=j+d2[j1];
int ny2=j+d1[j1];
if((nx1<0||nx1>=n)||(ny1<0||ny1>=m))
f1++;
if((nx2<0||nx2>=n)||(ny2<0||ny2>=m))
f2++;
}
}
// if(i==1&&j==1)
// out.println(f1+" "+f2);
if(f1==4&&f2==4)
{
out.println(i+1+" "+(j+1));
ok=0;
break;
}
}
if(ok==0)
break;
}
if(ok==1)
out.println("1 1 ");
}
out.close();
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
9b82ed4fe07aeee14678f58bf00d0b81
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.io.*;
import java.util.*;
/**
* @author freya
* @date 2022/9/6
**/
public class A{
public static Reader in;
public static PrintWriter out;
public static void main(String[] args) {
out = new PrintWriter(new BufferedOutputStream(System.out));
in = new Reader();
solve();
out.close();
}
static void solve(){
int t = in.nextInt();
while(t-->0){
int n = in.nextInt(), m = in.nextInt();
boolean flag = false;
if(n>m){
int tmp = n; n = m; m = tmp;
flag = true;
}
if(n==1)out.println("1 1");
else if (n==2){
if (!flag)out.println(1 + " " + Math.min(2, m));
else out.println(Math.min(2, m) + " " + 1);
}else if(n==3){
if (!flag)out.println(2 + " " + Math.min(2, m));
else out.println(Math.min(2, m) + " " + 1);
}else out.println("1 1");
}
}
static class Reader {
private BufferedReader br;
private StringTokenizer st;
Reader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
try {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] nextIntArray(int n) {
int[] arr = new int[n];
for (int i = 0; i < n; i++)
arr[i] = nextInt();
return arr;
}
long nextLong() {
return Long.parseLong(next());
}
String nextLine() {
String s = "";
try {
s = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return s;
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
2f6e1ab49242d98d66430c70a7a1c0bf
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.*;
public class c1733 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t,j,i,n,m;
//long a[];
t=sc.nextInt();
for(j=1;j<=t;j++){
n=sc.nextInt();
m=sc.nextInt();
if(n==1||m==1)
System.out.println(1+" "+1);
// if(n==2||m==2)
// System.out.println(2+" "+2);
// else if(n==3||m==3)
// System.out.println(2+" "+2);
else
System.out.println(2+" "+2);
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
69c16d8083ae3ea78eba8a49e9b6352f
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.*;
public class c1733 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t,j,i,n,m;
//long a[];
t=sc.nextInt();
for(j=1;j<=t;j++){
n=sc.nextInt();
m=sc.nextInt();
if(n==1||m==1){
System.out.println(1+" "+1);
continue;
}
if(n==2||m==2)
System.out.println(2+" "+2);
else if(n==3||m==3)
System.out.println(2+" "+2);
else
System.out.println(1+" "+1);
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
441889b09479c9efcf0ba23d1699a2ac
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.Scanner;
public class ImmobileKnight {
public static void main(String[] args) {
Scanner obj = new Scanner(System.in);
int nTest = obj.nextInt();
while (nTest-- > 0) {
int row = obj.nextInt();
int col = obj.nextInt();
Cell ans = getIsolatedKnight(row, col);
System.out.println(ans.row + " " + ans.col);
}
obj.close();
}
private static Cell getIsolatedKnight(int n, int m) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (!canMove(n, m, i, j)) {
// System.out.println("moving :" + i + " " + j);
return new Cell(i, j);
}
}
}
// System.out.println(" no moving :" + n + " " + m);
return new Cell(n, m);
}
private static boolean canMove(int row, int col, int i, int j) {
// down two steps and move right
if (i + 2 <= row && j + 1 <= col) {
return true;
}
// down two steps and left
if (i + 2 <= row && j - 1 >= 1) {
return true;
}
// up two steps and move right
if (i - 2 >= 1 && j + 1 <= col) {
return true;
}
// up two steps and left
if (i - 2 >= 1 && j - 1 >= 1) {
return true;
}
// left two steps and move down
if (j - 2 >= 1 && i + 1 <= row) {
return true;
}
// left two steps and move up
if (j - 2 >= 1 && i - 1 >= 1) {
return true;
}
// right two steps and move down
if (j + 2 <= col && i + 1 <= row) {
return true;
}
// right two steps and move up
if (j + 2 <= col && i - 1 <= 1) {
return true;
}
return false;
}
}
class Cell {
int row;
int col;
Cell(int r, int c) {
row = r;
col = c;
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
3af2030aa18434392705b139cc22fece
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.Scanner;
public class ImmobileKnight {
public static void main(String[] args) {
Scanner obj = new Scanner(System.in);
int nTest = obj.nextInt();
while (nTest-- > 0) {
int row = obj.nextInt();
int col = obj.nextInt();
Cell ans = getIsolatedKnight(row, col);
System.out.println(ans.row + " " + ans.col);
}
obj.close();
}
private static Cell getIsolatedKnight(int n, int m) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (!canMove(n, m, i, j)) {
// System.out.println("moving :" + i + " " + j);
return new Cell(i, j);
}
}
}
// System.out.println(" no moving :" + n + " " + m);
return new Cell(n, m);
}
private static boolean canMove(int row, int col, int i, int j) {
// down two steps and move right
if (i + 2 <= row && j + 1 <= col) {
return true;
}
// down two steps and left
if (i + 2 <= row && j - 1 >= 1) {
return true;
}
// up two steps and move right
if (i - 2 >= 1 && j + 1 <= col) {
return true;
}
// up two steps and left
if (i - 2 >= 1 && j - 1 >= 1) {
return true;
}
// left two steps and move down
if (j - 2 >= 1 && i + 1 <= row) {
return true;
}
// left two steps and move up
if (j - 2 >= 1 && i - 1 >= 1) {
return true;
}
// right two steps and move down
if (j + 2 <= col && i + 1 <= row) {
return true;
}
// right two steps and move up
if (j + 2 <= col && i - 1 <= 1) {
return true;
}
return false;
}
}
class Cell {
int row;
int col;
Cell(int r, int c) {
row = r;
col = c;
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
4bcec1805e6465cc43c04c267fad0b32
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
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 Main
{
public static void main (String[] args) throws java.lang.Exception
{
BufferedReader rd=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(rd.readLine());
while(t-->0)
{
String str[]=rd.readLine().trim().split(" ");
int n=Integer.parseInt(str[0]);
int m=Integer.parseInt(str[1]);
if(n==1||m==1)
{
System.out.println(n+" "+m);
}
else if(n<=3&&n>1&&m<=3&&m>1)
{
System.out.println("2 2");
}
else
{
int a=n-1;
int b=m-1;
System.out.println(a+" "+b);
}
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
2cb768f8505a9e7eb8a9c176146a4983
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.*;
public class Solution{
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();
if(n==1 || m==1){
System.out.print(n+" "+m);
System.out.println();
}
else if(n==2 && m==3){
System.out.print(2+" "+2);
System.out.println();
}
else if(n==3 && m==2){
System.out.print(2+" "+2);
System.out.println();
}
else if(n==3 && m==3){
System.out.print(2+" "+2);
System.out.println();
}
else{
System.out.print(n+" "+m);
System.out.println();
}
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
b0396023b33c33ad995f3fdec255b143
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.*;
import java.util.Map.Entry;
import java.io.*;
import java.lang.*;
public class main1{
FastScanner in;
PrintWriter out;
public static void main(String[] arg) {
new main1().run();
}
//////////////SOLVE QUESTIONS HERE/////////////
public void solve() throws IOException {
int tc=in.nextInt();
while(tc-->0)
{
int x=in.nextInt();
int y=in.nextInt();
int ans1=-1,ans2=-1;
for(int i=1;i<=x;i++)
{
for(int j=1;j<=y;j++)
{
//upar phir do
boolean flag1=(i+2<=x)&&(j+1<=y);
boolean flag2=(i+2<=x)&&(j-1>=1);
boolean flag3=(i-2>=1)&&(j+1<=1);
boolean flag4=(i-2>=1)&&(j-1>=1);
// lel
boolean flag5=(i+1<=x)&&(j+2<=y);
boolean flag6=(i+1<=x)&&(j-2>=1);
boolean flag7=(i-1>=1)&&(j+2<=1);
boolean flag8=(i-1>=1)&&(j-2>=1);
if(flag1 || flag2 ||flag3 ||flag4 ||flag5 ||flag6 ||flag7 ||flag8 )
continue;
else if(ans1==-1 && ans2==-1)
{
ans1=i;
ans2=j;
break;
}
}
}
if(ans1==-1)
{
out.println("1 1");
}
else
{
out.println(ans1+ " "+ ans2);
}
}
}
public void run() {
try {
in = new FastScanner(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(Reader f) {
br = new BufferedReader(f);
}
String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong(){
return Long.parseLong(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
String nextLine(){
String str="";
try {
str=br.readLine().trim();
} catch (Exception e) {
e.printStackTrace();
}
return str;
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
89d6ebd778c184021c250d3c2fbe418f
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class Contest {
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();
if (n > 8 || n < 1 || m > 8 || m < 1)
System.out.println(0);
if (n == 1 || m == 1)
System.out.println(n + " " + m);
else if (n == 2)
System.out.println(1 + " " + 2);
else if (m == 2)
System.out.println(2 + " " + 1);
else if (m == 3 && n == 3)
System.out.println(2 + " " + 2);
else
System.out.println(n + " " + m);
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
980ac4cad00364bd044258b2a2ddbb46
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
// "static void main" must be defined in a public class.
import java.util.*;
import java.io.*;
public class Solution {
public static void main(String[] args) {
FastScanner fs=new FastScanner();
PrintWriter out=new PrintWriter(System.out);
int T = fs.nextInt();
for(int i = 0; i < T; i++) {
int N = fs.nextInt();
int M = fs.nextInt();
int min = Math.min(N, M);
int max = Math.max(N, M);
if(min == 3 && max == 3) {
out.println(2 + " " + 2);
continue;
}
int mid = 0;
int mid1 = 0;
if(N%2 == 0) {
mid = N/2;
}else{
mid = N/2 + 1;
}
if(M%2 == 0) {
mid1 = M/2;
}else{
mid1 = M/2 + 1;
}
out.println(mid + " " + mid1);
}
out.close();
}
static long gcd(long a, long b) {
if(b == 0) {
return a;
}else{
return gcd(b, a%b);
}
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong(){
return Long.parseLong(next());
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
fa9cbf54a404fd1ebd51badc6d07eaaa
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.Scanner;
public class Rough {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
int r = sc.nextInt(), c = sc.nextInt();
int min = Math.min(r, c), max = Math.max(r, c);
if (min == 1) {
System.out.printf("%d %d\n", r, c);
} else if (min == 2) {
if (max == 3) {
System.out.printf("%d %d\n", 2, 2);
} else {
System.out.printf("%d %d\n", r, c);
}
} else if (min == 3) {
System.out.printf("%d %d\n", 2, 2);
} else {
System.out.printf("%d %d\n", r, c);
}
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
7520b0cd666801edafc7c2960bc94550
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;
public class Main {
public static void main(String[] args) {
FastScanner s = new FastScanner();
int o = s.nextInt();
while(o-->0){
int n = s.nextInt();
int m = s.nextInt();
if(n==1 || m==1){
System.out.println(1 + " " + 1);
}else if(n>=4 && n>=4){
System.out.println(1+" " + 1);
}else if(n==2 && m==2){
System.out.println(1+" " +1);
}else if (n==2 && m==3){
System.out.println(1 + " " + 2);
}else if (n==3 && m==2){
System.out.println(2 + " " + 1);
}else if(n==3 && m==3){
System.out.println(2+" "+2);
}else{
System.out.println(1+" " + 1);
}
}}
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens()) try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
c0961016b855cf117170d33b8a608368
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.*;
import java.lang.*;
import java.io.*;
public class main
//class contest
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0) {
int n = sc.nextInt();
int m = sc.nextInt();
if(n==1 || m==1)
System.out.println(n + " " + m);
else
if(n<=3 && m<=3){
if(n<=m)
System.out.println(2 + " " + 2);
else if(n>m)
System.out.println(2+" "+1);
}
else
System.out.println(1 + " " + 1);
}
}
/* ################################functions##################################################### */
//power of ten
public static boolean isPowerOfTen(long input) {
if (input % 10 != 0 || input == 0) {
return false;
}
if (input == 10) {
return true;
}
return isPowerOfTen(input/10);
}
//method to check prime
static boolean isPrime(long n)
{
// Corner cases
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;
}
// method to return gcd of two numbers
static long gcd(long a, long b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
// method to return LCM of two numbers
static long lcm(long a, long b)
{
return (a / gcd(a, b)) * b;
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
fab7f11b3d677340cb49e267b6007325
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;
import static java.lang.Math.*;
public class Solution {
static MyScanner str = new MyScanner();
// static Scanner str = new Scanner(System.in);
public static void main(String[] args) throws IOException {
int T = i();
while (T-- > 0) {
solve();
}
}
static void solve() throws IOException {
int n = i(), m = i();
if (n >= 2 && m >= 2) System.out.println("2 2");
else System.out.println(n + " " + m);
}
public static void out_arr(int[] a) {
StringBuffer sf = new StringBuffer();
for (int i = 0; i < a.length; i++) {
sf.append(a[i] + " ");
}
System.out.println(sf);
}
public static int i() throws IOException {
return str.nextInt();
}
public static long l() throws IOException {
return str.nextLong();
}
public static double d() throws IOException {
return str.nextDouble();
}
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public 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;
}
}
private static class ArraysInt {
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);
}
}
private static class ArraysLong {
static void merge(long arr[], int l, int m, int r) {
int n1 = m - l + 1;
int n2 = r - m;
long L[] = new long[n1];
long R[] = new long[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(long 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(long[] arr) {
sort(arr, 0, arr.length - 1);
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
9ea8706a07d6e77ada839e36d9358382
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.io.*;
import java.util.*;
import static java.lang.Math.*;
public class Main {
public static void main(String[] args) throws IOException{
FastScanner fs=new FastScanner();
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
int t = fs.nextInt();
for (int i = 0; i < t; i++) {
int n = fs.nextInt();
int m = fs.nextInt();
out.println(((n+1)/2 + " " + (m+1)/2));
}
out.close();
//
//5 7 15 7 5
//5 8 9 5
}
public static boolean isPalindrome(String s){
int lo = 0, hi = s.length()-1;
while(lo < hi){
if(s.charAt(lo) != s.charAt(hi)) return false;
lo++;
hi--;
}
return true;
}
public static int lcd(int a,int b){
return a*b/gcd(a,b);
}
public static int gcd(int a, int b){
if(b == 0){
return a;
}
return gcd(b,a % b);
}
public static boolean isPerfectSquare(int n){
int sqr = (int)sqrt(n);
return sqr * sqr == n;
}
public static boolean isPrime(int x){
int a = (int)sqrt(x);
for(int i = 2; i<=a ; i++){
if(x % i == 0) return false;
}
return true;
}
static void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
static class Pair implements Comparable
{
int a,b;
public String toString() {
return a+" " + b;
}
public Pair(int x , int y) {
a=x;b=y;
}
@Override
public int compareTo(Object o) {
Pair p = (Pair)o;
if(p.a < a)
return 1;
else if(p.a==a)
if(p.b<b)
return 1;
else if(p.b==b)
return 0;
return -1;
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
dd63e4d2ac418cfbdc5fa31d04f16475
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.Scanner;
public class Test12 {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
int k;
for (k = 0; k < t; k++) {
int n = sc.nextInt();
int m = sc.nextInt();
int flag = 0;
for(int i=1; i<=n; i++) {
if(flag == 1)
break;
for(int j=1; j<=m; j++) {
if(!(((i-2) > 0 && ((j+1) <= m || (j-1) >= 1)) || ((i+2) <=n && ((j+1) <= m || (j-1) >= 1)) ||
((j+2) <= m && ((i-1) >= 1 || (i+1) <= n)) || ((j-2) > 0 && ((i+1) <= n || (i-1) >= 1)))) {
System.out.println(i + " " + j);
flag = 1;
break;
}
}
}
if(flag == 0) {
System.out.println(n + " " + m);
}
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
4fad17c96d2fdf3331ab51524b0273b2
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException, InterruptedException {
Scanner sc = new Scanner(new BufferedInputStream(System.in));
PrintWriter pw = new PrintWriter(System.out);
int t = sc.nextInt();
while (t-->0) {
int n = sc.nextInt();
int m = sc.nextInt();
if(n<=3 || m<=3 ) pw.println((int)Math.ceil(n/2.0) +" " + (int)Math.ceil(m/2.0));
else pw.println(1 +" " + 1);
}
pw.flush();
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public int[] nextIntArray(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
return a;
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public String nextLine() throws IOException {
return br.readLine();
}
public double nextDouble() throws IOException {
String x = next();
StringBuilder sb = new StringBuilder("0");
double res = 0, f = 1;
boolean dec = false, neg = false;
int start = 0;
if (x.charAt(0) == '-') {
neg = true;
start++;
}
for (int i = start; i < x.length(); i++)
if (x.charAt(i) == '.') {
res = Long.parseLong(sb.toString());
sb = new StringBuilder("0");
dec = true;
} else {
sb.append(x.charAt(i));
if (dec)
f *= 10;
}
res += Long.parseLong(sb.toString()) / f;
return res * (neg ? -1 : 1);
}
public boolean ready() throws IOException {
return br.ready();
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
6d18999aa02e3ef6ac3d84127a7f9765
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.Scanner;
public class CF {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
short n = in.nextShort();
for (n=n; n > 0; n--) {
short x, y;
x = in.nextShort();
y = in.nextShort();
// if x >= 2 and y >= 3 there is a solution
// if x >= 3 and y >= 3 (not including 3, 3) every cell is a solution
if (x == 3 && y == 3)
System.out.println("2 2"); // only invalid
// all but 3, 3
else if (x >= 3 && y >= 3)
System.out.println("1 1"); // all valid
// rectangles with atleast one dimension < 3
else if (x == 1 || y == 1)
System.out.println("1 1"); // all invalid
// rectangles with atleast one dimension = 2
else if (x == 2 && y == 2)
System.out.println("1 1"); // all invalid
// rectangles with only one dimension = 2
else if (x > 3 || y > 3)
System.out.println("1 1"); // all valid
else if (x == 3)
System.out.println("2 1");
else if (y == 3)
System.out.println("1 2");
else
System.out.println("UNATTENDED: " + x + " " + y);
}
in.close();
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
449e58b62c1476ef8193aa5cf94f3276
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.Scanner;
/**
* @author 温志森
* @version 1.0
*/
public class Immobile_Knight {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int time=scanner.nextInt();
int n, m;
for (int i = 0; i < time; i++) {
n=scanner.nextInt();
m=scanner.nextInt();
System.out.println(Math.min(2,n)+" "+Math.min(2,m));
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
00d6164bcf6ac72f463512607ed7e09d
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int t=sc.nextInt();
while(t-- > 0){
int r=sc.nextInt();
int c=sc.nextInt();
System.out.println((r / 2 + 1) + " " + (c / 2 + 1));
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
c94df3937ab38b29bbfc84fef8e9689f
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.io.InputStreamReader;
import java.util.*;
public class Main {
static Scanner cin = new Scanner(new InputStreamReader(System.in));
public static void main(String[] args) {
int t = cin.nextInt();
for (int i=1;i<=t;i++) {
solve();
}
}
private static void solve() {
int m = cin.nextInt();
int n = cin.nextInt();
int x =1,y=1;
if(m<5) {
x = (m+1)/2;
}
if(n<5) {
y = (n+1)/2;
}
System.out.println(x +" "+y);
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
022509b6a75ca9297a8d54fe799cef8e
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.Scanner;
public class ImmobileKnight {
public static void main(String args[]) throws Exception {
Scanner s = new Scanner(System.in);
int testcases = Integer.parseInt(s.nextLine());
while (testcases > 0) {
int row = s.nextInt();
int col = s.nextInt();
int i, j;
if(testcases != 1) s.nextLine();
boolean isIsolated = true;
for (i = 1; i <= row; i++) {
for (j = 1; j <= col; j++) {
if (j + 2 <= col || j - 2 >= 1) {
if (i + 1 <= col || i - 1 >= 1) {
isIsolated = false;
}
} else if (i + 2 <= row || i - 2 >= 1) {
if (j + 1 <= row || j - 1 <= 1) {
isIsolated = false;
}
} else {
isIsolated = true;
System.out.println(i + " " + j);
break;
}
}
if (isIsolated) {
break;
}
}
if (isIsolated == false) {
System.out.println("1 1");
}
testcases--;
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
532d2722ab9f2b50f9686a860806377d
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Random;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.Map.Entry;
import java.util.concurrent.PriorityBlockingQueue;
public class Main {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
static long gcd(long no, long sum) {
if (sum == 0)
return no;
return gcd(sum, no % sum);
}
static long lcm(long a , long b){
return (a / gcd(a , b))*b;
}
static void countSort(int[] arr)
{
int max = Arrays.stream(arr).max().getAsInt();
int min = Arrays.stream(arr).min().getAsInt();
int range = max - min + 1;
int count[] = new int[range];
int output[] = new int[arr.length];
for (int i = 0; i < arr.length; i++) {
count[arr[i] - min]++;
}
for (int i = 1; i < count.length; i++) {
count[i] += count[i - 1];
}
for (int i = arr.length - 1; i >= 0; i--) {
output[count[arr[i] - min] - 1] = arr[i];
count[arr[i] - min]--;
}
for (int i = 0; i < arr.length; i++) {
arr[i] = output[i];
}
}
static void RandomShuffleSort(int [] a , int start , int end){
Random random = new Random();
for(int i = start; i<end; i++){
int j = random.nextInt(end);
int temp = a[j];
a[j] = a[i];
a[i] = temp;
}
Arrays.sort(a , start , end);
}
public static void main(String[] args) throws IOException , ParseException{
BufferedWriter out = new BufferedWriter(
new OutputStreamWriter(System.out));
FastReader sc = new FastReader();
int t = sc.nextInt();
while(t-->0){
int n = sc.nextInt();
int m = sc.nextInt();
boolean ans = false;
for(int i = 0; i<n; i++){
boolean check = true;
for(int j = 0; j<m; j++){
if((i-1) > -1){
// System.out.println("i-1 > -1" + " " + i + " "+ j);
if((j-2) > -1) check = false;
else if((j+2) < m) check = false;
}
if((i+1) < n){
// System.out.println("i+1 < n" + " " + i + " "+ j);
if((j-2) > -1) check = false;
else if((j+2) < m) check = false;
}
if((i-2) > -1) {
// System.out.println("i-2 > -1" + " " + i + " "+ j);
if((j-1) > -1) check = false;
else if((j+1) < m) check = false;
}
if((i+2) < n){
// System.out.println("i+2 < n" + " " + i + " "+ j);
if((j-1) > -1) check = false;
else if((j+1) < m) check = false;
}
if(check) {
System.out.println((i+1) + " " + (j+1));
ans = true;
break;
}
check = true;
}
if(ans) break;
}
if(!ans) {
System.out.println(1 + " " + 1);
// System.out.println("HERE");
}
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
80dbbecf725748194daf8dcc9eaea7e8
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class Main {
private static final int[] dx = {};
private static final int[] dy = {};
private static void solve(int n, int m){
int min = Math.min(n, m);
int max = Math.max(n, m);
if(min <= 1){
out.println("1 1");
}
else if(min <= 3 && max <= 3){
out.println("2 2");
}
else {
out.println("1 1");
}
}
public static void main(String[] args){
MyScanner scanner = new MyScanner();
int testCount = scanner.nextInt();
for(int testIdx = 1; testIdx <= testCount; testIdx++){
int n = scanner.nextInt();
int m = scanner.nextInt();
solve(n, m);
}
out.close();
}
static void print1DArray(int[] arr){
for(int i = 0; i < arr.length; i++){
out.print(arr[i]);
if(i < arr.length - 1){
out.print(' ');
}
}
out.print('\n');
}
static void print1DArrayList(List<Integer> arrayList){
for(int i = 0; i < arrayList.size(); i++){
out.print(arrayList.get(i));
if(i < arrayList.size() - 1){
out.print(' ');
}
}
out.print('\n');
}
public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public 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;
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
f93616d68e700cf9cb8e24e383c391aa
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.Scanner;
public class ImmobileKnights {
public static void immobileKnights(int n , int m){
if (n==1 || m == 1){
System.out.println(n + " " + m);
return;
}
if (n<=3 && m<=3){
System.out.println("2 2");
return;
}
else
System.out.println(n + " " + m);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
for (int i = 0 ; i < num ; i++){
int n = sc.nextInt();
int m = sc.nextInt();
immobileKnights(n,m);
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
746a962fd6f2d943e5e064e65958866f
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.*;
public class tasks {
public static void main(String... args){
Scanner in=new Scanner(System.in);
int t=in.nextInt();
int n=0,m=0;
for(int i=0;i<t;i++){
n=in.nextInt();
m=in.nextInt();
if(n==1||m==1){
System.out.println(n+" "+m);
}
else if(m*n==6||(n==3&&m==3)){
System.out.println(2+" "+2);
}
else{
System.out.println(n+" "+m);
}
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
68c5a365c8a8f69d0fa197e07f54d6a2
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
// Java program to find length of the longest valid
// substring
import java.util.*;
public class A1739
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int tt=0;tt<t;tt++)
{
int n = sc.nextInt();
int m = sc.nextInt();
int min = Math.min(n,m);
int max = Math.max(n,m);
if(max == 3&&min == 3)
{
System.out.println("2 2");
}
else if(max>=4)
{
System.out.println("1 1");
}
else if(min==1)
{
System.out.println("1 1");
}
else if(max==3)
{
System.out.println("2 2");
}
else
{
System.out.println("1 1");
}
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
7b42e8a2f3428e54d155bcf22cf4e0dc
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
public class Main {
public static void main(String[] args) throws Exception {
Sol obj=new Sol();
obj.runner();
}
}
class Sol{
FastScanner fs=new FastScanner();
Scanner sc=new Scanner(System.in);
PrintWriter out=new PrintWriter(System.out);
void runner() throws Exception{
int T=1;
//T=sc.nextInt();
//preCompute();
T=fs.nextInt();
while(T-->0) {
solve(T);
}
out.close();
System.gc();
}
private void solve(int T) throws Exception {
int n=fs.nextInt();
int m=fs.nextInt();
if( n>m ) {
int temp=n;
n=m;
m=temp;
}
if( n>2 && m>3 ) {
System.out.println(1+" "+1);
}else if( n>=2 && m==3 ) {
System.out.println(2+" "+2);
}else {
System.out.println(1+" "+1);
}
}
private void preCompute() {
}
static class FastScanner {
BufferedReader br;
StringTokenizer st ;
FastScanner(){
br = new BufferedReader(new InputStreamReader(System.in));
st = new StringTokenizer("");
}
FastScanner(String file) {
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
st = new StringTokenizer("");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
System.out.println("file not found");
e.printStackTrace();
}
}
String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
String readLine() throws IOException{
return br.readLine();
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
de7674ae224e17253143bda5f285c94d
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.io.*;
import java.util.*;
@SuppressWarnings("unused")
public class A_Immobile_Knight {
public static void main(String[] args) {
MyScanner sc = new MyScanner();
out = new PrintWriter(new BufferedOutputStream(System.out));
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt(), m = sc.nextInt();
out.println((n+1)/2+" "+(m+1)/2);
}
out.close();
}
public static PrintWriter out;
public static long mod = (long) 1e9 + 7;
public static int[] parent = new int[101];
public static int[] rank = new int[101];
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public 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());
}
int[] readArray(int n) {
int a[] = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
long[] readLongArray(int n) {
long a[] = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
int[][] readArrayMatrix(int N, int M, int Index) {
if (Index == 0) {
int[][] res = new int[N][M];
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++)
res[i][j] = (int) nextLong();
}
return res;
}
int[][] res = new int[N][M];
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= M; j++)
res[i][j] = (int) nextLong();
}
return res;
}
long[][] readArrayMatrixLong(int N, int M, int Index) {
if (Index == 0) {
long[][] res = new long[N][M];
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++)
res[i][j] = nextLong();
}
return res;
}
long[][] res = new long[N][M];
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= M; j++)
res[i][j] = nextLong();
}
return res;
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
private static boolean nextPerm(int[] 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;
}
private static void google(int tt) {
out.print("Case #" + (tt) + ": ");
}
public static int lower_bound(int[] arr, int x) {
int low = 0, high = arr.length - 1, mid = -1;
int ans = -1;
while (low <= high) {
mid = (low + high) / 2;
if (arr[mid] > x) {
high = mid - 1;
} else {
ans = mid;
low = mid + 1;
}
}
return ans;
}
public static int upper_bound(int[] arr, int x) {
int low = 0, high = arr.length - 1, mid = -1;
int ans = arr.length;
while (low < high) {
mid = (low + high) / 2;
if (arr[mid] >= x) {
ans = mid;
high = mid - 1;
} else {
low = mid + 1;
}
}
return ans;
}
static void reverseArray(int[] a) {
int n = a.length;
int arr[] = new int[n];
for (int i = 0; i < n; i++)
arr[i] = a[n - i - 1];
for (int i = 0; i < n; i++)
a[i] = arr[i];
}
static void reverseArray(long[] a) {
int n = a.length;
long arr[] = new long[n];
for (int i = 0; i < n; i++)
arr[i] = a[n - i - 1];
for (int i = 0; i < n; i++)
a[i] = arr[i];
}
public static void push(TreeMap<Integer, Integer> map, int k, int v) {
if (!map.containsKey(k))
map.put(k, v);
else
map.put(k, map.get(k) + v);
}
public static void pull(TreeMap<Integer, Integer> map, int k, int v) {
int lol = map.get(k);
if (lol == v)
map.remove(k);
else
map.put(k, lol - v);
}
static int[][] matrixMul(int[][] a, int[][] m) {
if (a[0].length == m.length) {
int[][] b = new int[a.length][m.length];
for (int i = 0; i < m.length; i++) {
for (int j = 0; j < m.length; j++) {
int sum = 0;
for (int k = 0; k < m.length; k++) {
sum += m[i][k] * m[k][j];
}
b[i][j] = sum;
}
}
return b;
}
return null;
}
static void swap(int[] a, int l, int r) {
int temp = a[l];
a[l] = a[r];
a[r] = temp;
}
static void SieveOfEratosthenes(int n, boolean prime[]) {
prime[0] = false;
prime[1] = false;
for (int p = 2; p * p <= n; p++) {
if (prime[p] == true)
for (int i = p * p; i <= n; i += p)
prime[i] = false;
}
}
static void dfs(int root, boolean[] vis, int[] value, ArrayList[] gr, int prev) {
vis[root] = true;
value[root] = 3 - prev;
prev = 3 - prev;
for (int i = 0; i < gr[root].size(); i++) {
int next = (int) gr[root].get(i);
if (!vis[next])
dfs(next, vis, value, gr, prev);
}
}
static boolean isPrime(int n) {
for (int i = 2; i <= Math.sqrt(n); i++)
if (n % i == 0)
return false;
return true;
}
static boolean isPrime(long n) {
for (long i = 2; i <= Math.sqrt(n); i++)
if (n % i == 0)
return false;
return true;
}
static int abs(int a) {
return a > 0 ? a : -a;
}
static int max(int a, int b) {
return a > b ? a : b;
}
static int min(int a, int b) {
return a < b ? a : b;
}
static int ceil(int x, int y) {
return (x % y == 0 ? x / y : (x / y + 1));
}
static long ceil(long x, long y) {
return (x % y == 0 ? x / y : (x / y + 1));
}
static boolean isSquare(double a) {
boolean isSq = false;
double b = Math.sqrt(a);
double c = Math.sqrt(a) - Math.floor(b);
if (c == 0)
isSq = true;
return isSq;
}
static long sqrt(long z) {
long sqz = (long) Math.sqrt(z);
while (sqz * 1L * sqz < z) {
sqz++;
}
while (sqz * 1L * sqz > z) {
sqz--;
}
return sqz;
}
static int log2(int N) {
int result = (int) (Math.log(N) / Math.log(2));
return result;
}
static long pow(long n, long m) {
if (m == 0)
return 1;
long temp = pow(n, m / 2);
long res = ((temp * temp) % mod);
if (m % 2 == 0)
return res;
return (res * n) % mod;
}
static long modular_add(long a, long b) {
return ((a % mod) + (b % mod)) % mod;
}
static long modular_sub(long a, long b) {
return ((a % mod) - (b % mod) + mod) % mod;
}
static long modular_mult(long a, long b) {
return ((a % mod) * (b % mod)) % mod;
}
public static long gcd(long a, long b) {
if (a > b)
a = (a + b) - (b = a);
if (a == 0L)
return b;
return gcd(b % a, a);
}
public static long lcm(long a, long b) {
return (a * b) / gcd(a, b);
}
static int gcd(int n1, int n2) {
if (n2 != 0)
return gcd(n2, n1 % n2);
else
return n1;
}
static int find(int u) {
if (u == parent[u])
return u;
return parent[u] = find(parent[u]);
}
static void union(int u, int v) {
int a = find(u), b = find(v);
if (a == b)
return;
if (rank[a] > rank[b]) {
parent[b] = a;
rank[a] += rank[b];
} else {
parent[a] = b;
rank[b] += rank[a];
}
}
static void dsu() {
for (int i = 0; i < 101; i++) {
parent[i] = i;
rank[i] = 1;
}
}
static class Pair {
int x, y;
Pair(int x, int y) {
this.x = x;
this.y = y;
}
static void sortbyx(Pair[] coll) {
List<Pair> al = new ArrayList<>(Arrays.asList(coll));
Collections.sort(al, new Comparator<Pair>() {
public int compare(Pair p1, Pair p2) {
return p1.x - p2.x;
}
});
for (int i = 0; i < al.size(); i++) {
coll[i] = al.get(i);
}
}
static void sortbyy(Pair[] coll) {
List<Pair> al = new ArrayList<>(Arrays.asList(coll));
Collections.sort(al, new Comparator<Pair>() {
public int compare(Pair p1, Pair p2) {
return p1.y - p2.y;
}
});
for (int i = 0; i < al.size(); i++) {
coll[i] = al.get(i);
}
}
static void sortbyx(ArrayList<Pair> al) {
Collections.sort(al, new Comparator<Pair>() {
public int compare(Pair p1, Pair p2) {
return Integer.compare(p1.x, p2.x);
}
});
}
static void sortbyy(ArrayList<Pair> al) {
Collections.sort(al, new Comparator<Pair>() {
public int compare(Pair p1, Pair p2) {
return Integer.compare(p1.y, p2.y);
}
});
}
public String toString() {
return String.format("(%s, %s)", String.valueOf(x), String.valueOf(y));
}
}
static void sort(int[] a) {
ArrayList<Integer> list = new ArrayList<>();
for (int i : a)
list.add(i);
Collections.sort(list);
for (int i = 0; i < a.length; i++)
a[i] = list.get(i);
}
static void sort(long a[]) {
ArrayList<Long> list = new ArrayList<>();
for (long i : a)
list.add(i);
Collections.sort(list);
for (int i = 0; i < a.length; i++)
a[i] = list.get(i);
}
static int[] array(int n, int value) {
int a[] = new int[n];
for (int i = 0; i < n; i++)
a[i] = value;
return a;
}
static long sum(long a[]) {
long sum = 0;
for (long i : a)
sum += i;
return (sum);
}
static long count(long a[], long x) {
long c = 0;
for (long i : a)
if (i == x)
c++;
return (c);
}
static int sum(int a[]) {
int sum = 0;
for (int i : a)
sum += i;
return (sum);
}
static int count(int a[], int x) {
int c = 0;
for (int i : a)
if (i == x)
c++;
return (c);
}
static int count(String s, char ch) {
int c = 0;
char x[] = s.toCharArray();
for (char i : x)
if (ch == i)
c++;
return (c);
}
static int[] freq(int a[], int n) {
int f[] = new int[n + 1];
for (int i : a)
f[i]++;
return f;
}
static int[] pos(int a[], int n) {
int f[] = new int[n + 1];
for (int i = 0; i < n; i++)
f[a[i]] = i;
return f;
}
static boolean isPalindrome(String s) {
StringBuilder sb = new StringBuilder();
sb.append(s);
String str = String.valueOf(sb.reverse());
if (s.equals(str))
return true;
else
return false;
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
c4b992aac15e037d207bfd9245d2b524
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.io.*;
import java.util.*;
@SuppressWarnings("unused")
public class A_Immobile_Knight {
public static void main(String[] args) {
MyScanner sc = new MyScanner();
out = new PrintWriter(new BufferedOutputStream(System.out));
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt(), m = sc.nextInt();
ArrayList<Pair> set = new ArrayList<>();
ArrayList<Pair> temp = new ArrayList<>();
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
boolean b = false;
if ((i + 2) < n && (i + 2) >= 0 && (j + 1) < m && (j + 1) >= 0) {
set.add(new Pair(i, j));
b = true;
}
if ((i + 1) < n && (i + 1) >= 0 && (j + 2) < m && (j + 2) >= 0) {
set.add(new Pair(i, j));
b = true;
}
if ((i - 2) < n && (i - 2) >= 0 && (j - 1) < m && (j - 1) >= 0) {
set.add(new Pair(i, j));
b = true;
}
if ((i - 1) < n && (i - 1) >= 0 && (j - 2) < m && (j - 2) >= 0) {
set.add(new Pair(i, j));
b = true;
}
if ((i - 2) < n && (i - 2) >= 0 && (j + 1) < m && (j + 1) >= 0) {
set.add(new Pair(i, j));
b = true;
}
if ((i + 2) < n && (i + 2) >= 0 && (j - 1) < m && (j - 1) >= 0) {
set.add(new Pair(i, j));
b = true;
}
if (!b)
temp.add(new Pair(i, j));
}
}
Pair.sortbyx(set);
Pair.sortbyx(temp);
if (temp.size() > 0)
out.println((temp.get(0).x + 1) + " " + (temp.get(0).y + 1));
else
out.println((set.get(0).x + 1) + " " + (set.get(0).y + 1));
}
out.close();
}
public static PrintWriter out;
public static long mod = (long) 1e9 + 7;
public static int[] parent = new int[101];
public static int[] rank = new int[101];
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public 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());
}
int[] readArray(int n) {
int a[] = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
long[] readLongArray(int n) {
long a[] = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
int[][] readArrayMatrix(int N, int M, int Index) {
if (Index == 0) {
int[][] res = new int[N][M];
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++)
res[i][j] = (int) nextLong();
}
return res;
}
int[][] res = new int[N][M];
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= M; j++)
res[i][j] = (int) nextLong();
}
return res;
}
long[][] readArrayMatrixLong(int N, int M, int Index) {
if (Index == 0) {
long[][] res = new long[N][M];
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++)
res[i][j] = nextLong();
}
return res;
}
long[][] res = new long[N][M];
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= M; j++)
res[i][j] = nextLong();
}
return res;
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
private static boolean nextPerm(int[] 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;
}
private static void google(int tt) {
out.print("Case #" + (tt) + ": ");
}
public static int lower_bound(int[] arr, int x) {
int low = 0, high = arr.length - 1, mid = -1;
int ans = -1;
while (low <= high) {
mid = (low + high) / 2;
if (arr[mid] > x) {
high = mid - 1;
} else {
ans = mid;
low = mid + 1;
}
}
return ans;
}
public static int upper_bound(int[] arr, int x) {
int low = 0, high = arr.length - 1, mid = -1;
int ans = arr.length;
while (low < high) {
mid = (low + high) / 2;
if (arr[mid] >= x) {
ans = mid;
high = mid - 1;
} else {
low = mid + 1;
}
}
return ans;
}
static void reverseArray(int[] a) {
int n = a.length;
int arr[] = new int[n];
for (int i = 0; i < n; i++)
arr[i] = a[n - i - 1];
for (int i = 0; i < n; i++)
a[i] = arr[i];
}
static void reverseArray(long[] a) {
int n = a.length;
long arr[] = new long[n];
for (int i = 0; i < n; i++)
arr[i] = a[n - i - 1];
for (int i = 0; i < n; i++)
a[i] = arr[i];
}
public static void push(TreeMap<Integer, Integer> map, int k, int v) {
if (!map.containsKey(k))
map.put(k, v);
else
map.put(k, map.get(k) + v);
}
public static void pull(TreeMap<Integer, Integer> map, int k, int v) {
int lol = map.get(k);
if (lol == v)
map.remove(k);
else
map.put(k, lol - v);
}
static int[][] matrixMul(int[][] a, int[][] m) {
if (a[0].length == m.length) {
int[][] b = new int[a.length][m.length];
for (int i = 0; i < m.length; i++) {
for (int j = 0; j < m.length; j++) {
int sum = 0;
for (int k = 0; k < m.length; k++) {
sum += m[i][k] * m[k][j];
}
b[i][j] = sum;
}
}
return b;
}
return null;
}
static void swap(int[] a, int l, int r) {
int temp = a[l];
a[l] = a[r];
a[r] = temp;
}
static void SieveOfEratosthenes(int n, boolean prime[]) {
prime[0] = false;
prime[1] = false;
for (int p = 2; p * p <= n; p++) {
if (prime[p] == true)
for (int i = p * p; i <= n; i += p)
prime[i] = false;
}
}
static void dfs(int root, boolean[] vis, int[] value, ArrayList[] gr, int prev) {
vis[root] = true;
value[root] = 3 - prev;
prev = 3 - prev;
for (int i = 0; i < gr[root].size(); i++) {
int next = (int) gr[root].get(i);
if (!vis[next])
dfs(next, vis, value, gr, prev);
}
}
static boolean isPrime(int n) {
for (int i = 2; i <= Math.sqrt(n); i++)
if (n % i == 0)
return false;
return true;
}
static boolean isPrime(long n) {
for (long i = 2; i <= Math.sqrt(n); i++)
if (n % i == 0)
return false;
return true;
}
static int abs(int a) {
return a > 0 ? a : -a;
}
static int max(int a, int b) {
return a > b ? a : b;
}
static int min(int a, int b) {
return a < b ? a : b;
}
static int ceil(int x, int y) {
return (x % y == 0 ? x / y : (x / y + 1));
}
static long ceil(long x, long y) {
return (x % y == 0 ? x / y : (x / y + 1));
}
static boolean isSquare(double a) {
boolean isSq = false;
double b = Math.sqrt(a);
double c = Math.sqrt(a) - Math.floor(b);
if (c == 0)
isSq = true;
return isSq;
}
static long sqrt(long z) {
long sqz = (long) Math.sqrt(z);
while (sqz * 1L * sqz < z) {
sqz++;
}
while (sqz * 1L * sqz > z) {
sqz--;
}
return sqz;
}
static int log2(int N) {
int result = (int) (Math.log(N) / Math.log(2));
return result;
}
static long pow(long n, long m) {
if (m == 0)
return 1;
long temp = pow(n, m / 2);
long res = ((temp * temp) % mod);
if (m % 2 == 0)
return res;
return (res * n) % mod;
}
static long modular_add(long a, long b) {
return ((a % mod) + (b % mod)) % mod;
}
static long modular_sub(long a, long b) {
return ((a % mod) - (b % mod) + mod) % mod;
}
static long modular_mult(long a, long b) {
return ((a % mod) * (b % mod)) % mod;
}
public static long gcd(long a, long b) {
if (a > b)
a = (a + b) - (b = a);
if (a == 0L)
return b;
return gcd(b % a, a);
}
public static long lcm(long a, long b) {
return (a * b) / gcd(a, b);
}
static int gcd(int n1, int n2) {
if (n2 != 0)
return gcd(n2, n1 % n2);
else
return n1;
}
static int find(int u) {
if (u == parent[u])
return u;
return parent[u] = find(parent[u]);
}
static void union(int u, int v) {
int a = find(u), b = find(v);
if (a == b)
return;
if (rank[a] > rank[b]) {
parent[b] = a;
rank[a] += rank[b];
} else {
parent[a] = b;
rank[b] += rank[a];
}
}
static void dsu() {
for (int i = 0; i < 101; i++) {
parent[i] = i;
rank[i] = 1;
}
}
static class Pair {
int x, y;
Pair(int x, int y) {
this.x = x;
this.y = y;
}
static void sortbyx(Pair[] coll) {
List<Pair> al = new ArrayList<>(Arrays.asList(coll));
Collections.sort(al, new Comparator<Pair>() {
public int compare(Pair p1, Pair p2) {
return p1.x - p2.x;
}
});
for (int i = 0; i < al.size(); i++) {
coll[i] = al.get(i);
}
}
static void sortbyy(Pair[] coll) {
List<Pair> al = new ArrayList<>(Arrays.asList(coll));
Collections.sort(al, new Comparator<Pair>() {
public int compare(Pair p1, Pair p2) {
return p1.y - p2.y;
}
});
for (int i = 0; i < al.size(); i++) {
coll[i] = al.get(i);
}
}
static void sortbyx(ArrayList<Pair> al) {
Collections.sort(al, new Comparator<Pair>() {
public int compare(Pair p1, Pair p2) {
return Integer.compare(p1.x, p2.x);
}
});
}
static void sortbyy(ArrayList<Pair> al) {
Collections.sort(al, new Comparator<Pair>() {
public int compare(Pair p1, Pair p2) {
return Integer.compare(p1.y, p2.y);
}
});
}
public String toString() {
return String.format("(%s, %s)", String.valueOf(x), String.valueOf(y));
}
}
static void sort(int[] a) {
ArrayList<Integer> list = new ArrayList<>();
for (int i : a)
list.add(i);
Collections.sort(list);
for (int i = 0; i < a.length; i++)
a[i] = list.get(i);
}
static void sort(long a[]) {
ArrayList<Long> list = new ArrayList<>();
for (long i : a)
list.add(i);
Collections.sort(list);
for (int i = 0; i < a.length; i++)
a[i] = list.get(i);
}
static int[] array(int n, int value) {
int a[] = new int[n];
for (int i = 0; i < n; i++)
a[i] = value;
return a;
}
static long sum(long a[]) {
long sum = 0;
for (long i : a)
sum += i;
return (sum);
}
static long count(long a[], long x) {
long c = 0;
for (long i : a)
if (i == x)
c++;
return (c);
}
static int sum(int a[]) {
int sum = 0;
for (int i : a)
sum += i;
return (sum);
}
static int count(int a[], int x) {
int c = 0;
for (int i : a)
if (i == x)
c++;
return (c);
}
static int count(String s, char ch) {
int c = 0;
char x[] = s.toCharArray();
for (char i : x)
if (ch == i)
c++;
return (c);
}
static int[] freq(int a[], int n) {
int f[] = new int[n + 1];
for (int i : a)
f[i]++;
return f;
}
static int[] pos(int a[], int n) {
int f[] = new int[n + 1];
for (int i = 0; i < n; i++)
f[a[i]] = i;
return f;
}
static boolean isPalindrome(String s) {
StringBuilder sb = new StringBuilder();
sb.append(s);
String str = String.valueOf(sb.reverse());
if (s.equals(str))
return true;
else
return false;
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
fee110536651f3d61e95842d6830bf05
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.*;
public class Test{
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();
if(n >=4 && m>=4) {System.out.println(n+" "+m);}
else if((n == 3 || n== 2) && (m == 3 || m == 2)) {System.out.println(2+" "+2);}
else {System.out.println(n+" "+m);}
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
2f0ec24ed91c9d88435c21e440c02b72
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class ImmobileKnight {
private static final int START_TEST_CASE = 1;
public static void solveCase(FastIO io, int testCase) {
final int N = io.nextInt();
final int M = io.nextInt();
if (N >= 4 || M >= 4) {
io.println(1, 1);
} else {
io.println(Math.min(N, 2), Math.min(M, 2));
}
}
public static void solve(FastIO io) {
final int T = io.nextInt();
for (int t = 0; t < T; ++t) {
solveCase(io, START_TEST_CASE + t);
}
}
public static class FastIO {
private InputStream reader;
private PrintWriter writer;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public FastIO(InputStream r, OutputStream w) {
reader = r;
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(w)));
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = reader.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;
}
// TODO: read this byte-by-byte like the other read functions.
public double nextDouble() {
return Double.parseDouble(nextString());
}
public int[] nextIntArray(int n) {
return nextIntArray(n, 0);
}
public int[] nextIntArray(int n, int off) {
int[] arr = new int[n + off];
for (int i = 0; i < n; i++) {
arr[i + off] = nextInt();
}
return arr;
}
public long[] nextLongArray(int n) {
return nextLongArray(n, 0);
}
public long[] nextLongArray(int n, int off) {
long[] arr = new long[n + off];
for (int i = 0; i < n; i++) {
arr[i + off] = nextLong();
}
return arr;
}
private boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
}
public void println(Object... objects) {
print(objects);
writer.println();
}
public void printArray(int[] arr) {
for (int i = 0; i < arr.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(arr[i]);
}
}
public void printArray(long[] arr) {
for (int i = 0; i < arr.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(arr[i]);
}
}
public void printlnArray(int[] arr) {
printArray(arr);
writer.println();
}
public void printlnArray(long[] arr) {
printArray(arr);
writer.println();
}
public void printf(String format, Object... args) {
print(String.format(format, args));
}
public void flush() {
writer.flush();
}
}
public static void main(String[] args) {
FastIO io = new FastIO(System.in, System.out);
solve(io);
io.flush();
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
cf5d29999a24e4cd8d17818c336d3228
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class ImmobileKnight {
private static final int START_TEST_CASE = 1;
private static final int[] DR = {-2, -1, 1, 2, 2, 1, -1, -2};
private static final int[] DC = {1, 2, 2, 1, -1, -2, -2, -1};
public static void solveCase(FastIO io, int testCase) {
final int N = io.nextInt();
final int M = io.nextInt();
for (int r = 1; r <= N; ++r) {
for (int c = 1; c <= M; ++c) {
boolean stuck = true;
for (int d = 0; d < DR.length; ++d) {
int nr = r + DR[d];
int nc = c + DC[d];
if (nr >= 1 && nr <= N && nc >= 1 && nc <= M) {
stuck = false;
break;
}
}
if (stuck) {
io.println(r, c);
return;
}
}
}
io.println(1, 1);
}
public static void solve(FastIO io) {
final int T = io.nextInt();
for (int t = 0; t < T; ++t) {
solveCase(io, START_TEST_CASE + t);
}
}
public static class FastIO {
private InputStream reader;
private PrintWriter writer;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public FastIO(InputStream r, OutputStream w) {
reader = r;
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(w)));
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = reader.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;
}
// TODO: read this byte-by-byte like the other read functions.
public double nextDouble() {
return Double.parseDouble(nextString());
}
public int[] nextIntArray(int n) {
return nextIntArray(n, 0);
}
public int[] nextIntArray(int n, int off) {
int[] arr = new int[n + off];
for (int i = 0; i < n; i++) {
arr[i + off] = nextInt();
}
return arr;
}
public long[] nextLongArray(int n) {
return nextLongArray(n, 0);
}
public long[] nextLongArray(int n, int off) {
long[] arr = new long[n + off];
for (int i = 0; i < n; i++) {
arr[i + off] = nextLong();
}
return arr;
}
private boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
}
public void println(Object... objects) {
print(objects);
writer.println();
}
public void printArray(int[] arr) {
for (int i = 0; i < arr.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(arr[i]);
}
}
public void printArray(long[] arr) {
for (int i = 0; i < arr.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(arr[i]);
}
}
public void printlnArray(int[] arr) {
printArray(arr);
writer.println();
}
public void printlnArray(long[] arr) {
printArray(arr);
writer.println();
}
public void printf(String format, Object... args) {
print(String.format(format, args));
}
public void flush() {
writer.flush();
}
}
public static void main(String[] args) {
FastIO io = new FastIO(System.in, System.out);
solve(io);
io.flush();
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
0d19b6561b2bbf5f077d2fa4e585823d
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.io.*;
import java.util.HashSet;
import java.util.LinkedList;
public class Main {
static InputReader in;
static OutputWriter out;
public static void main(String[] args) throws Exception {
in=new InputReader(System.in);
out=new OutputWriter(System.out);
int T=in.nextInt();
while(T-->0) {
int n=in.nextInt();
int m=in.nextInt();
int ans1=1,ans2=1;
for(int i=1;i<=n;i++) {
for(int j=1;j<=m;j++) {
if(i-1>0 && j-2>0)
continue;
if(i-1>0 && j+2<=m)
continue;
if(i+1<=n && j-2>0)
continue;
if(i+1<=n && j+2<=m)
continue;
if(i-2>0 && j-1>0)
continue;
if(i-2>0 && j+1<=m)
continue;
if(i+2<=n && j-1>0)
continue;
if(i+2<=n && j+1<=m)
continue;
ans1=i;
ans2=j;
}
}
out.println(ans1+" "+ans2);
}
out.flush();
}
static class InputReader {
private final BufferedReader br;
public InputReader(InputStream stream) {
br = new BufferedReader(new InputStreamReader(stream));
}
public int nextInt() throws IOException {
int c = br.read();
while (c <= 32) {
c = br.read();
}
boolean negative = false;
if (c == '-') {
negative = true;
c = br.read();
}
int x = 0;
while (c > 32) {
x = x * 10 + c - '0';
c = br.read();
}
return negative ? -x : x;
}
public long nextLong() throws IOException {
int c = br.read();
while (c <= 32) {
c = br.read();
}
boolean negative = false;
if (c == '-') {
negative = true;
c = br.read();
}
long x = 0;
while (c > 32) {
x = x * 10 + c - '0';
c = br.read();
}
return negative ? -x : x;
}
public String next() throws IOException {
int c = br.read();
while (c <= 32) {
c = br.read();
}
StringBuilder sb = new StringBuilder();
while (c > 32) {
sb.append((char) c);
c = br.read();
}
return sb.toString();
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
}
static class OutputWriter {
private final BufferedWriter writer;
public OutputWriter(OutputStream out) {
writer=new BufferedWriter(new OutputStreamWriter(out));
}
public void print(String str) {
try {
writer.write(str);
}
catch (IOException e) {
e.printStackTrace();
}
}
public void print(Object obj) {
print(String.valueOf(obj));
}
public void println(String str) {
print(str+"\n");
}
public void println() {
print('\n');
}
public void println(Object obj) {
println(String.valueOf(obj));
}
public void flush() {
try {
writer.flush();
}
catch (IOException e) {
e.printStackTrace();
}
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
0003fa5b14444e9aee7a5f1d72dd6631
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.*;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
@SuppressWarnings("unchecked")
public class CodeForces{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int t = input.nextInt();
while(t-- > 0){
int n = input.nextInt();
int m = input.nextInt();
if(n < 4 && m < 4){
System.out.println((n / 2 + 1) + " " + (m / 2 + 1));
}
else{
System.out.println(n + " " + m);
}
}
}
public static void ReverseInteger(int number){
int reverse = 0;
while(number != 0)
{
int remainder = number % 10;
reverse = reverse * 10 + remainder;
number = number/10;
}
System.out.println("The reverse of the given number is: " + reverse);
}
public static void ShiftToRight(int a[],int n){
int temp = a[n];
for (int i = n; i > 0; i--) {
a[i] = a[i-1];
}
a[0] = temp;
System.out.println("Array after shifting to right by one : "+Arrays.toString(a));
}
public static int binarysearch(int low, int high, int target, int[] nums){
if(low <= high){
int mid = (low + high) / 2;
if(nums[mid] == target){
return mid;
}
else if(nums[mid] < target){
return binarysearch(mid + 1, high, target, nums);
}
else if(nums[mid] > target){
return binarysearch(low, mid - 1, target,nums);
}
}
return -1;
}
public static void reverse(int[] arr){
// Length of the array
int n = arr.length;
// Swaping the first half elements with last half
// elements
for (int i = 0; i < n / 2; i++) {
// Storing the first half elements temporarily
int temp = arr[i];
// Assigning the first half to the last half
arr[i] = arr[n - i - 1];
// Assigning the last half to the first half
arr[n - i - 1] = temp;
}
}
static int recursive_lower_bound(int low, int high, int target, int[] arr){
// Base Case
if (low > high) {
return low;
}
// Find the middle index
int mid = low + (high - low) / 2;
// If key is lesser than or equal to
// array[mid] , then search
// in left subarray
if (target <= arr[mid]){
return recursive_lower_bound(low, mid - 1, target, arr);
}
// If key is greater than array[mid],
// then find in right subarray
return recursive_lower_bound(mid + 1, high,
target, arr);
}
public static void printInteger(List<Integer> list){
for(int i = 0;i < list.size();i++){
System.out.print(list.get(i) + " ");
}
}
public static void printString(List<String> list){
for(int i = 0;i < list.size();i++){
System.out.print(list.get(i));
}
}
public static void printArray(int[] arr){
for(int i = 0;i < arr.length;i++){
System.out.print(arr[i] + " ");
}
}
public static void sortArray(int[] arr){
Arrays.sort(arr);
}
public static void ShiftedToNPositions(int[] nums,int k){
for(int i = 0; i < k; i++){
int j, last;
//Stores the last element of array
last = nums[nums.length-1];
for(j = nums.length-1; j > 0; j--){
//Shift element of array by one
nums[j] = nums[j-1];
}
//Last element of array will be added to the start of array.
nums[0] = last;
}
for(int i = 0;i < nums.length;i++){
System.out.print(nums[i] + " ");
}
}
}
class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
c4ae5246fcb60aaa2b3cb6aad74745b0
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.Scanner;
public class ImmobileKnight {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-->0) {
int n = sc.nextInt(), m = sc.nextInt();
if(n==1 || m==1) System.out.println(n+" "+m);
else if(n==2 && m==2) System.out.println(n+" "+m);
else if((n==3 && m==2)||(n==2&&m==3)||(n==3&&m==3)) System.out.println(2+" "+2);
else System.out.println(2+" "+2);
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
ebcd0afe9a3543a598ae3394b0bbcc20
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int t = input.nextInt();
input.nextLine();
for(int i = 1; i <= t; i++){
String s = input.nextLine();
String[] row = s.split(" ");
// System.out.println(Arrays.toString(row));
isolated(Integer.parseInt(row[0]),Integer.parseInt(row[1]));
}
}
public static void isolated(int n , int m){
int[][] next = {{-2,1}, {-1,2},{1, 2},{2,1},{2,-1},{1,-2},{-1,-2},{-2,-1}};
for(int i = 0; i < n; i ++){
for (int j = 0; j < m; j++){
boolean is = true;
for (int[] dire : next){
if (i + dire[0] >= 0 && i + dire[0] <n && j + dire[1] >=0 && j + dire[1] <m){
is = false;
break;
}
}
if (is){
i++;
j ++;
System.out.println(i +" " +j);
return;
}
}
}
System.out.println(n+" "+m);
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
2396ff995e849bf7a4db4cc4330244a3
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.Scanner;
public class _136A {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for(int i = 0; i < t; ++i){
int n = in.nextInt();
int m = in.nextInt();
if (n <= 3 && m <= 3){
if (n < 2 || m < 2) System.out.println(n + " " + m);
else if (n == 3 && m == 3) System.out.println(n - 1 + " " + (m - 1));
else System.out.println(Math.max(n, m) - 1 + " " + Math.min(n, m));
}
else System.out.println(n + " " + m);
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
d08dab52d924d2936772b8fb3291c7a0
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
// Author MAVERICK
// https://codeforces.com/contest/1348/submission/119576836
//com.package.Maverick.java;
import java.util.*;
import java.io.*;
import java.lang.*;
// codechef no public declaration
public class Maverick{
// constants
static int counter = 0;
static boolean flag = false;
static final int MOD = 1000000007;
static final int MAX = 100001;
//static final boolean[] prime = new boolean[MAX];
static final ArrayList <Integer> primesFound = new ArrayList <Integer> ();
static final ArrayList <Integer> storeInt = new ArrayList <Integer> ();
static final ArrayList <Long> storeLong = new ArrayList <Long> ();
static final ArrayList <Double> storeDoub = new ArrayList <Double> ();
static final ArrayList <String> storeStr = new ArrayList <String> ();
static FastScanner in = new FastScanner(); // inherited from SecondThread
static Scanner scan = new Scanner(System.in);
// Custom input output start
static int ii(){ return in.nextInt();} // Integer
static long loi() {return in.nextLong();} // Long
static double di(){ return in.nextDouble();} // float
static String si(){ return in.nextLine();} // String
static int[] li(int x) {return in.readArray(x);} // array
// End of Custom I/O
// >>>>>>>>>>>>>>>>>>>>>>>>>>> MAIN CODE GOES HERE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
static void solve(){
// main codes goes here >>>
//int[] t = li(j-1);
int a,b;
a = ii();
b = ii();
if(a<=1 || b<=1) System.out.println(a+" "+b);
else if(a<=2 && b<=2) System.out.println("2 2");
else if(a<=3 && b<=3) System.out.println("2 2");
else{
int c,d;
//Random random = new Random();
c = a;
d = b;
System.out.println(c+" "+d);
}
}
public static void main(String args[]) throws IOException { // in short PSVM
int x = in.nextInt(); while(x-- > 0) solve();
//solve();
}
}
// >>>>>>>>>>>>>>>>>>>>>>>>>>> MAIN CODE ENDS HERE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
//class by SecondThread for fast I/O
class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {st=new StringTokenizer(br.readLine());}
catch (IOException e) {e.printStackTrace();}
return st.nextToken();
}
String nextLine() {
String str = "";
try {str = br.readLine();}
catch (IOException e) {e.printStackTrace();}
return str;}
double nextDouble() {return Double.parseDouble(next());}
int nextInt() {return Integer.parseInt(next());}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i] = nextInt();
return a;
}
long nextLong() {return Long.parseLong(next());}} // End of FastScanner
// if something is lost , then here is the solution
/*
Conversion ->
Integer.parseInt()
Double.parseDouble()
Long.parseDouble()
int x = (int) 3.33;
Math Functions ->
Math.abs(a)
Math.max(a,b)
Math.min(a,b)
Math.pow(a,b)
Math.round(a)
Math.sqrt(a)
Random random = new Random();
String operations ->
String x = String.valueOf(a);
a.length()
a.charAt(i)
a.substring(b,c)
a.contains(substring)
a.startsWith(b)
a.endsWith(b)
a.indexOf(b)
a.indexOf(c,b)
a.concat()
compareTo()
toLowerCase()
toUpperCase()
a.replace()
a.trim()
a.matches()
a.split()
a.equals()
Scanner x = new Scanner(System.in);
Array ->
ArrayList <String> str = new ArrayList<>(); str.add("Miraj");
for (String s : str) System.out.println(s);
cars.get(0);
cars.set(0, "Opel");
cars.remove(0);
cars.clear();
cars.size();
Iterator<Integer> it = numbers.iterator();
while(it.hasNext()) {
Integer i = it.next();
if(i < 10) {
it.remove();
}
}
Arrays.sort(a, Collections.reverseOrder());
Array.push -> ArrayList.add(Object o); // Append the list
Array.pop -> ArrayList.remove(int index); // Remove list[index]
Array.shift -> ArrayList.remove(0); // Remove first element
Array.unshift -> ArrayList.add(int index, Object o); // Prepend the list
*/
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
522cfb16ed774f97da74d2f02d631ef2
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.*;
public class contest {
public static void main(String args[]){
Scanner sc =new Scanner(System.in);
int n=sc.nextInt();
for(int i=0;i<n;i++){
int r=sc.nextInt();
int c=sc.nextInt();
if(r==3&&c==3){
System.out.println(2+" "+2);
}
else if(r==3&&c==2){
System.out.println(2+" "+1);
}
else if(r==2&&c==3){
System.out.println(1+" "+2);
}
else{
System.out.println(1+" "+1);
}
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
3d3f6591d81a210d78e5f19ae4122b80
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.Scanner;
public class A{
public static int xdir[]=new int[]{-2,-1,1,2,2,1,-1,-2};
public static int ydir[]=new int[]{1,2,2,1,-1,-2,-2,-1};
public static boolean isPossible(int i,int j,int n,int m){
boolean flag=false;
for(int k=0;k<8;k++){
if(i+xdir[k]>=0&&i+xdir[k]<n&&j+ydir[k]>=0&&j+ydir[k]<m){
flag=true;
}
}
return flag;
}
public static void main(String[] args) {
try {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
int m=sc.nextInt();
int resi=1;
int resj=1;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(!isPossible(i,j,n,m)){
resi=i+1;
resj=j+1;
}
}
}
System.out.println(resi+" "+resj);
}
} catch (Exception e) {
//TODO: handle exception
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
ae4f891788437240419223a093b7f3de
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class Codechef{
public static void main(String args[]) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int tc = Integer.parseInt(br.readLine());
while(tc-->0){
String s[] = br.readLine().trim().split(" ");
int m = Integer.parseInt(s[0]);
int n = Integer.parseInt(s[1]);
int min = Math.min(m, n);
int max = Math.max(m, n);
if(min > 3) {
System.out.println(m+" "+n);
}
else if(min == 3){
if(max==3) System.out.println("2 2");
else System.out.println("1 1");
}
else if(min == 2){
if(max==2 || max==3) System.out.println("2 2");
else System.out.println("1 1");
}
else{
System.out.println("1 1");
}
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
0769186a45d3e2c4ec58e743feb1f622
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner in=new Scanner (System.in);
int t=in.nextInt();
while(t>0)
{
int a=in.nextInt(),b=in.nextInt();
if(a<=3||b<=3)
System.out.println(((a/2)+1)+" "+((b/2)+1));
else
System.out.println(1+" "+1);
t--;
}
// System.out.println("Hello World");
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
05fc5d611ba402b26081e717d0a11ea0
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.*;
public class CD {
int [] arrr;
public static void main(String[] args) {
Scanner st = new Scanner(System.in);
int t = st.nextInt();
while (t-- > 0){
int n = st.nextInt();int m = st.nextInt();
if (n < 4 && m < 4){
System.out.println((n / 2 + 1) + " " + (m / 2 + 1));
}
else {
System.out.println(n + " " + m);
}
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
fd5dc48d3e3228dd8215b2f737b18a1f
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
/* package codechef; // 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 Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- > 0){
int row = sc.nextInt();
int col = sc.nextInt();
boolean board[][] = new boolean [row][col];
int dirs[][] = {{1,2},{1,-2},{-1,2},{-1,-2},{2,1},{2,-1},{-2,1},{-2,-1}};
for(int i=0;i<row;i++){
for(int j=0;j<col;j++){
for(int dir[] : dirs){
int newI = i + dir[0];
int newJ = j + dir[1];
if(newI>=0 && newI<row && newJ>=0 && newJ<col){
board[newI][newJ] = true;
}
}
}
}
boolean found = false;
for(int i=0;i<row;i++){
for(int j=0;j<col;j++){
if(!board[i][j]){
found = true;
System.out.println((i+1)+" "+(j+1));
break;
}
}
if(found)break;
}
if(!found){
System.out.println(row+" "+col);
}
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
a504c60b11a61094028f4feb3795bf85
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.*;
import java.lang.*;
import java.io.*;
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();
System.out.println(n/2+1+" "+ (m/2+1));
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
129926c0a2854359b241e33ef9e0663d
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.*;
public class cf {
public static void main(String[] args) {
Scanner css = new Scanner(System.in);
int t = css.nextInt();
for (int i = 0; i < t; i++) {
int n = css.nextInt(), m = css.nextInt();
if((n == 1 && m >= 1) || (m == 1 && n >= 1)){
System.out.println(n + " " + m);
}else if(n == 2 && m == 2){
System.out.println(n + " " + m);
}else if((n == 2 && m == 3) || (n == 3 && m == 2)){
System.out.println(2 + " " + 2);
}else if(n == 3 && m == 3){
System.out.println(2 + " " + 2);
}else{
System.out.println(n + " " + m);
}
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
70c39906d17a3bac27f9ebf97995f23f
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
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.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;
public class A {
static final int mod = (int) 1e9 + 7;
static final long modL = (long) 1e9 + 7;
private static void solve(int t) {
int n = fs.nextInt();
int m = fs.nextInt();
if(n ==1 || m==1){
out.println(1+" "+1);
return;
}
out.println(2+" "+2);
return;
}
private static int[] sortByCollections(int[] arr) {
ArrayList<Integer> ls = new ArrayList<>(arr.length);
for (int i = 0; i < arr.length; i++) {
ls.add(arr[i]);
}
Collections.sort(ls);
for (int i = 0; i < arr.length; i++) {
arr[i] = ls.get(i);
}
return arr;
}
public static void main(String[] args) {
fs = new FastScanner();
out = new PrintWriter(System.out);
long s = System.currentTimeMillis();
int t = fs.nextInt();
for (int i = 1; i <= t; i++) solve(t);
out.close();
// System.err.println( System.currentTimeMillis() - s + "ms" );
}
static boolean DEBUG = true;
static PrintWriter out;
static FastScanner fs;
static void trace(Object... o) {
if (!DEBUG) return;
System.err.println(Arrays.deepToString(o));
}
static void pl(Object o) {
out.println(o);
}
static void p(Object o) {
out.print(o);
}
static long gcd(long a, long b) {
return (b == 0) ? a : gcd(b, a % b);
}
static int gcd(int a, int b) {
return (b == 0) ? a : gcd(b, a % b);
}
static void sieveOfEratosthenes(int n, int factors[]) {
factors[1] = 1;
for (int p = 2; p * p <= n; p++) {
if (factors[p] == 0) {
factors[p] = p;
for (int i = p * p; i <= n; i += p)
factors[i] = p;
}
}
}
static long mul(long a, long b) {
return a * b % mod;
}
static long fact(int x) {
long ans = 1;
for (int i = 2; i <= x; i++) ans = mul(ans, i);
return ans;
}
static long fastPow(long base, long exp) {
if (exp == 0) return 1;
long half = fastPow(base, exp / 2);
if (exp % 2 == 0) return mul(half, half);
return mul(half, mul(half, base));
}
static long modInv(long x) {
return fastPow(x, mod - 2);
}
static long nCk(int n, int k) {
return mul(fact(n), mul(modInv(fact(k)), modInv(fact(n - k))));
}
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
public String next() {
while (!st.hasMoreElements())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
static class _Scanner {
InputStream is;
_Scanner(InputStream is) {
this.is = is;
}
byte[] bb = new byte[1 << 15];
int k, l;
byte getc() throws IOException {
if (k >= l) {
k = 0;
l = is.read(bb);
if (l < 0) return -1;
}
return bb[k++];
}
byte skip() throws IOException {
byte b;
while ((b = getc()) <= 32)
;
return b;
}
int nextInt() throws IOException {
int n = 0;
for (byte b = skip(); b > 32; b = getc())
n = n * 10 + b - '0';
return n;
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
1131b785ae98bc11897694e845afec2b
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.*;
public class A{
public static void main(String args[]){
Scanner Sc=new Scanner(System.in);
int t=Sc.nextInt();
while(t-->0)
{
int n=Sc.nextInt();
int m=Sc.nextInt();
if(n==1|| m==1)
{
System.out.println("1 1");
}
else if(n==2 && m==3)
{
System.out.println("2 2");
}
else if(n==3 && m==2)
{
System.out.println("2 1");
}
else if(n==3 && m==3){
System.out.println("2 2");
}
else {
System.out.println("1 1");
}
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
b69e6e35d58a359f7f5429e69629e73a
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Round22 { // -----------------------------------stuff-----------------------------------------------------
public static void main(String[] args) throws IOException {
Scanner scanner=new Scanner(System.in);
int t=scanner.nextInt();
while(t-->0){
int rows=scanner.nextInt();
int col=scanner.nextInt();
boolean flag=false;
for (int i = 1; i <=rows &&!flag; i++) {
for(int j=1;j<=col&&!flag;j++){
if (!check(i,j,rows,col)){
flag=true;
System.out.println(i+" "+j);
break;
}
}
}
if (!flag)
System.out.println("1 1");
}
}
public static boolean check(int i,int j,int rows,int col){
int i1=i+2;
int j1=j+1;
if (i1<=rows&&j1<=col)
return true;
i1=i+2;
j1=j-1;
if (i1<=rows&&j1>0)
return true;
i1=i-2;
j1=j-1;
if (i1>0&&j1>0)
return true;
j1=j+1;
if (i1>0&&j1<=col)
return true;
j1=j+2;
i1=i+1;
if (i1<=rows&&j1<=col)
return true;
i1=i-1;
if (i1>0&&j1<=col)
return true;
j1=j-2;
i1=i+1;
if (j1>0&&i1<=rows)
return true;
i1=i-1;
if (j1>0&&i1>0)
return true;
return false;
}
public static void print(int[][] all) {
for (int[] i : all)
System.out.println(Arrays.toString(i));
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public Scanner(FileReader r) {
br = new BufferedReader(r);
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public String nextLine() throws IOException {
return br.readLine();
}
public double nextDouble() throws IOException {
String x = next();
StringBuilder sb = new StringBuilder("0");
double res = 0, f = 1;
boolean dec = false, neg = false;
int start = 0;
if (x.charAt(0) == '-') {
neg = true;
start++;
}
for (int i = start; i < x.length(); i++)
if (x.charAt(i) == '.') {
res = Long.parseLong(sb.toString());
sb = new StringBuilder("0");
dec = true;
} else {
sb.append(x.charAt(i));
if (dec)
f *= 10;
}
res += Long.parseLong(sb.toString()) / f;
return res * (neg ? -1 : 1);
}
public long[] nextlongArray(int n) throws IOException {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public long[] nextLongArray(int n) throws IOException {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public int[] nextIntArray(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public Integer[] nextIntegerArray(int n) throws IOException {
Integer[] a = new Integer[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public boolean ready() throws IOException {
return br.ready();
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
da6e0948252ff952d3a9628d991142f0
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.io.*;
import java.util.*;
import java.util.StringTokenizer;
public class mm
{
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') {
if (cnt != 0) {
break;
}
else {
continue;
}
}
buf[cnt++] = (byte)c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ') {
c = read();
}
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0,
BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
public static PrintWriter out;
public static void main (String[] args) throws java.lang.Exception
{
out = new PrintWriter(System.out);
try
{
//Scanner obj = new Scanner (System.in);
Reader obj = new Reader ();
int t = obj.nextInt();
while (t > 0)
{
t--;
int n = obj.nextInt();
int m = obj.nextInt();
//String str = obj.next();
if (n == 1 || m == 1)
{
out.println (n + " " + m);
}
else if (n == 2 && m <= 3)
{
out.println ("2 2");
}
else if (m == 2 && n <= 3)
{
out.println ("2 2");
}
else if (n == 3 && m == 3)
{
out.println ("2 2");
}
else
{
out.println ("1 1");
}
}
}catch(Exception e){
return;
}
out.flush();
out.close();
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
49f78ae25ab5a8cda07c7ca6304fc525
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.lang.*;
import java.io.*;
import java.util.*;
public class Codeforces {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter writer = new PrintWriter(System.out);
int T = Integer.parseInt(br.readLine());
while(T-- > 0) {
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
if(n == 2 && m == 3) writer.println("1 2");
else if(n == 3 && m == 2) writer.println("2 1");
else if(m == 3 && n == 3) writer.println("2 2");
else writer.println("1 1");
}
writer.close();
br.close();
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
2552054e64a9f365ad0eb8285552bd65
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.io.*;
import java.util.StringTokenizer;
public class A {
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args) throws IOException {
FastReader fs = new FastReader();
BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out));
int t = fs.nextInt();
while (t > 0) {
int n = fs.nextInt();
int m = fs.nextInt();
boolean isolated = false;
int x = 1;
int y = 1;
for (int i = 0; i < n && !isolated; i++) {
for (int j = 0; j < m && !isolated; j++) {
isolated = true;
if (i - 2 >= 0 && j + 1 < m) {
isolated = false;
}
if (i - 2 >= 0 && j - 1 >= 0) {
isolated = false;
}
if (i - 1 >= 0 && j + 2 < m) {
isolated = false;
}
if (i - 1 >= 0 && j - 2 >= 0) {
isolated = false;
}
if (i + 2 < n && j + 1 < m) {
isolated = false;
}
if (i + 2 < n && j - 1 >= 0) {
isolated = false;
}
if (i + 1 < n && j + 2 < m) {
isolated = false;
}
if (i + 1 < n && j - 2 >= 0) {
isolated = false;
}
if (isolated) {
x = i + 1;
y = j + 1;
}
}
}
output.write(x + " " + y);
output.newLine();
t--;
}
output.flush();
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
d44a29c897feab41239064bea398fff2
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.*;
public class MyClass {
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();
System.out.println((N / 2 + 1) + " " + (M / 2 + 1));
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
fd48ec71aadacf30ba1403a16959afac
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
new Thread(null, () -> new Main().run(), "1", 1 << 23).start();
}
private void run() {
FastReader scan = new FastReader();
PrintWriter out = new PrintWriter(System.out);
Solution solve = new Solution();
int t = scan.nextInt();
// int t = 1;
for (int qq = 0; qq < t; qq++) {
solve.solve(scan, out);
out.println();
}
out.close();
}
}
class Solution {
/*
* think and coding
*/
static long MOD = (long) (1e9);
double EPS = 0.000_0001;
public void solve(FastReader scan, PrintWriter out) {
int[][] arr = new int[20][20];
int n = scan.nextInt(), m = scan.nextInt();
for (int i = 2; i < n + 2; i++) {
for (int j = 2; j < m + 2; j++) {
arr[i][j] = 1;
}
}
for (int i = 2; i <= n + 2; i++) {
for (int j = 2; j <= m + 2; j++) {
int sum = arr[i - 2][j - 1] + arr[i - 1][j - 2] + arr[i - 1][j + 2] + arr[i - 2][j + 1];
sum += arr[i + 1][j - 2] + arr[i + 2][j - 1] + arr[i + 2][j + 1] + arr[i + 1][j + 2];
if (sum == 0) {
out.print((i - 1) + " " + (j - 1));
return;
}
}
}
out.print(n + " " + m);
}
int lower(int val, Pair[] arr) {
int l = -1, r = arr.length;
while (r - l > 1) {
int mid = (r + l) / 2;
if (arr[mid].a < val) {
l = mid;
} else r = mid;
}
return r;
}
static class Pair implements Comparable<Pair> {
int a, b;
public Pair(int a, int b) {
this.a = a;
this.b = b;
}
public Pair(Pair p) {
this.a = p.a;
this.b = p.b;
}
@Override
public int compareTo(Pair p) {
return Integer.compare(a, p.a);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Pair pair = (Pair) o;
return a == pair.a && b == pair.b;
}
@Override
public int hashCode() {
return Objects.hash(a, b);
}
@Override
public String toString() {
return "Pair{" + "a=" + a + ", b=" + b + '}';
}
}
}
class FastReader {
private final BufferedReader br;
private StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public FastReader(String s) throws FileNotFoundException {
br = new BufferedReader(new FileReader(new File(s)));
}
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;
}
int[] initInt(int n) {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = nextInt();
}
return arr;
}
long[] initLong(int n) {
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = nextLong();
}
return arr;
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
5395bc0485bf991e51161ffd382b92b1
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int t;
t = cin.nextInt();
while (t-- > 0) {
int n = cin.nextInt(), m = cin.nextInt();
int ans1 = 2, ans2 = 2;
if(ans1>n)ans1=n;
if(ans2>m)ans2=m;
System.out.println(ans1 + " " + ans2);
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
9068e5077288b4c1526754689a7f1287
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class Main {
static PrintWriter pw;
public static void main(String[] args) throws IOException, InterruptedException {
Scanner sc = new Scanner(System.in);
pw = new PrintWriter(System.out);
int t =sc.nextInt();
while(t-->0) {
int r =sc.nextInt();
int c =sc.nextInt();
pw.println((int)Math.ceil(r/2.0) +" "+(int)Math.ceil(c/2.0));
}
pw.close();
}
public static int log2(Long N) // log base 2
{
int result = (int) (Math.log(N) / Math.log(2));
return result;
}
public static int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
public static int lcm(int a, int b) {
return a * b / gcd(a, b);
}
public static long fac(long i) {
long res = 1;
while (i > 0) {
res = res * i--;
}
return res;
}
public static long combination(long x, long y) {
return 1l * (fac(x) / (fac(x - y) * fac(y)));
}
public static long permutation(long x, long y) {
return combination(x, y) * fac(y);
}
static class Pair implements Comparable<Pair> {
int x;
int y;
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
public String toString() {
return x + " " + y;
}
public int compareTo(Pair p) {
if (this.x == p.x)
return this.y - p.y;
return this.x - p.x;
}
}
static class SegmentTree {
char[] array;
int[] sTree;
int N;
public SegmentTree(char[] in) {
array = in;
N = in.length - 1;
sTree = new int[2 * N];
build(1, 1, N);
}
public void build(int node, int l, int r) { // o(n)
if (l == r) {
sTree[node] = 1 << array[l] - 'a';
} else {
int mid = l + r >> 1;
int leftChild = node << 1;
int rightChild = (node << 1) + 1;
build(leftChild, l, mid);
build(rightChild, mid + 1, r);
sTree[node] = sTree[leftChild] | sTree[rightChild];
}
}
public int query(int i, int j) {
return query(1, 1, N, i, j);
}
public int query(int node, int l, int r, int i, int j) { // [i,j] range I query on
if (l > j || r < i) // no intersection
return 0;
if (l >= i && r <= j) // kolo gwa el range
return sTree[node];
// else (some intersection)
int mid = l + r >> 1;
int leftChild = node << 1;
int rightChild = (node << 1) + 1;
int left = query(leftChild, l, mid, i, j);
int right = query(rightChild, mid + 1, r, i, j);
return left | right;
}
public void updatePoint(int index, char val) {
int node = index + N - 1;
array[index] = val;
sTree[node] = 1 << val - 'a'; // updating the point
while (node > 1) {
node >>= 1; // dividing by 2 to get the parent then update it
int leftChild = node << 1;
int rightChild = (node << 1) + 1;
sTree[node] = sTree[leftChild] | sTree[rightChild];
}
}
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public Scanner(FileReader r) {
br = new BufferedReader(r);
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public String nextLine() throws IOException {
return br.readLine();
}
public double nextDouble() throws IOException {
String x = next();
StringBuilder sb = new StringBuilder("0");
double res = 0, f = 1;
boolean dec = false, neg = false;
int start = 0;
if (x.charAt(0) == '-') {
neg = true;
start++;
}
for (int i = start; i < x.length(); i++)
if (x.charAt(i) == '.') {
res = Long.parseLong(sb.toString());
sb = new StringBuilder("0");
dec = true;
} else {
sb.append(x.charAt(i));
if (dec)
f *= 10;
}
res += Long.parseLong(sb.toString()) / f;
return res * (neg ? -1 : 1);
}
public int[] nextIntArray(int n) throws IOException {
int[] array = new int[n];
for (int i = 0; i < n; i++) {
array[i] = nextInt();
}
return array;
}
public Integer[] nextIntegerArray(int n) throws IOException {
Integer[] array = new Integer[n];
for (int i = 0; i < n; i++) {
array[i] = nextInt();
}
return array;
}
public long[] nextlongArray(int n) throws IOException {
long[] array = new long[n];
for (int i = 0; i < n; i++) {
array[i] = nextLong();
}
return array;
}
public Long[] nextLongArray(int n) throws IOException {
Long[] array = new Long[n];
for (int i = 0; i < n; i++) {
array[i] = nextLong();
}
return array;
}
public char[] nextCharArray(int n) throws IOException {
char[] array = new char[n];
String string = next();
for (int i = 0; i < n; i++) {
array[i] = string.charAt(i);
}
return array;
}
public boolean ready() throws IOException {
return br.ready();
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
db744dcef243b4b50884ede33b3107cd
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.lang.*;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.security.spec.RSAOtherPrimeInfo;
import java.util.*;
public class First {
static int k;
static int c = 0;
static long mod = (long)(1e9+7);
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
static void sort(long[] arr) {
ArrayList<Long> a = new ArrayList<>();
for (long i : arr) {
a.add(i);
}
Collections.sort(a);
for (int i = 0; i < a.size(); i++) {
arr[i] = a.get(i);
}
}
static long highestPowerof2(long x) {
x |= x >> 1;
x |= x >> 2;
x |= x >> 4;
x |= x >> 8;
x |= x >> 16;
return x ^ (x >> 1);
}
public static long fact(long number) {
if (number == 0 || number == 1) {
return 1;
} else {
return number * fact(number - 1);
}
}
public static ArrayList<Long> primeFactors(long n) {
ArrayList<Long> arr = new ArrayList<>();
long count = 0;
while (n % 2 == 0) {
arr.add(2l);
n /= 2;
}
for (long i = 3; i <= Math.sqrt(n); i += 2) {
while (n % i == 0) {
arr.add(i);
n /= i;
}
}
if (n > 2)
arr.add(n);
return arr;
}
static public long[] prime(long number) {
long n = number;
long count = 0;
long even = 0;
for (long i = 2; i <= n / i; i++) {
while (n % i == 0) {
if (i % 2 == 1) {
count++;
} else {
even++;
}
n /= i;
}
}
if (n > 1) {
if (n % 2 == 1) {
count++;
} else {
even++;
}
}
return new long[]{even, count};
}
static void swap(int[] arr, int i, int j) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
static int search(ArrayList<Integer> arr, int tar) {
int low = 0, hi = arr.size() - 1;
int ans = -1;
while (low <= hi) {
int mid = (low + hi) / 2;
if (arr.get(mid) > tar) {
ans = arr.get(mid);
hi = mid - 1;
} else {
low = mid + 1;
}
}
return ans;
}
static long gcd(long a, long b) {
// if b=0, a is the GCD
if (b == 0)
return a;
else
return gcd(b, a % b);
}
static long power(long x, long y, long p) {
long res = 1;
x = x % p;
if (x == 0)
return 0;
while (y > 0) {
if ((y & 1) != 0)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
static long get(long x, long[] a, long[]b){
long ans = Long.MIN_VALUE;
for(int i = 0; i < a.length; i++){
ans = Math.max(ans,b[i] + Math.abs(a[i]-x));
}
return ans;
}
public static void main(String[] args) throws Exception {
FastReader sc = new FastReader();
int t = sc.nextInt();
while(t-- > 0){
int r = sc.nextInt();
int c = sc.nextInt();
if(r == 1 || c == 1){
System.out.println("1 1");
}else if(r <= 3 || c <= 3){
System.out.println("2 2");
}else{
System.out.println("1 1");
}
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
233ddf8857daaf93a435a328419e52e5
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class ImmobileKnight {
public static void main(String[] args) throws IOException {
FastScanner in = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int t = in.nextInt();
for (int i = 1; i <= t; i++) {
int n = in.nextInt();
int m = in.nextInt();
if ((n == 1) || (m == 1)) {
out.println(n + " " + m);
}
else if ((n == 2) || (m == 2)) {
if (n == 2) {
if (m == 2) {
out.println(n + " " + m);
}
else if (m >= 3) {
out.println(1 + " " + 2);
}
}
else if (m == 2) {
if (n == 2) {
out.println(n + " " + m);
}
else if (n >= 3) {
out.println(2 + " " + 1);
}
}
}
else if ((n == 3) && (m == 3)) {
out.println(2 + " " + 2);
}
else {
out.println(n + " " + m);
}
}
out.close();
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
// noop
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
dd267469613e3e5d4a5a14e69dea45a6
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.*;
import java.io.*;
import java.math.*;
import java.text.*;
public class Main{
public static void main(String args[]) throws IOException{
Read sc=new Read();
int n=sc.nextInt();
for(int i=0;i<n;i++){
int a=sc.nextInt();
int b=sc.nextInt();
sc.println((1+a)/2+" "+((1+b)/2));
}
//sc.print(0);
sc.bw.flush();
sc.bw.close();
}
}
//记住看数字范围,需要开long吗,需要用BigInteger吗,需要手动处理字符串吗,复杂度数量级控制在1e7或者以下了吗
//开数组的数据范围最高不能超过1e7,数据范围再大就要用哈希表离散化了
//基本数据类型不能自定义sort排序,二维数组就可以了,顺序排序的时候是小减大,注意返回值应该是int
class Read{
BufferedReader bf;
StringTokenizer st;
BufferedWriter bw;
public Read(){
bf=new BufferedReader(new InputStreamReader(System.in));
st=new StringTokenizer("");
bw=new BufferedWriter(new OutputStreamWriter(System.out));
}
public String nextLine() throws IOException{
return bf.readLine();
}
public String next() throws IOException{
while(!st.hasMoreTokens()){
st=new StringTokenizer(bf.readLine());
}
return st.nextToken();
}
public char nextChar() throws IOException{
//确定下一个token只有一个字符的时候再用
return next().charAt(0);
}
public int nextInt() throws IOException{
return Integer.parseInt(next());
}
public long nextLong() throws IOException{
return Long.parseLong(next());
}
public double nextDouble() throws IOException{
return Double.parseDouble(next());
}
public float nextFloat() throws IOException{
return Float.parseFloat(next());
}
public byte nextByte() throws IOException{
return Byte.parseByte(next());
}
public short nextShort() throws IOException{
return Short.parseShort(next());
}
public BigInteger nextBigInteger() throws IOException{
return new BigInteger(next());
}
public void println(int a) throws IOException{
bw.write(String.valueOf(a));
bw.newLine();
return;
}
public void print(int a) throws IOException{
bw.write(String.valueOf(a));
return;
}
public void println(String a) throws IOException{
bw.write(a);
bw.newLine();
return;
}
public void print(String a) throws IOException{
bw.write(a);
return;
}
public void println(long a) throws IOException{
bw.write(String.valueOf(a));
bw.newLine();
return;
}
public void print(long a) throws IOException{
bw.write(String.valueOf(a));
return;
}
public void println(double a) throws IOException{
bw.write(String.valueOf(a));
bw.newLine();
return;
}
public void print(double a) throws IOException{
bw.write(String.valueOf(a));
return;
}
public void print(BigInteger a) throws IOException{
bw.write(a.toString());
return;
}
public void print(char a) throws IOException{
bw.write(String.valueOf(a));
return;
}
public void println(char a) throws IOException{
bw.write(String.valueOf(a));
bw.newLine();
return;
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
0c8d11a529a9fa2b17a724a5fa773615
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.io.*;
import java.util.*;
import java.math.*;
import java.time.*;
import static java.time.temporal.ChronoUnit.MINUTES;
import javafx.util.Pair;
public class Program {
public static void print(Object str) {
System.out.print(str);
}
public static void println(Object str) {
System.out.println(str);
}
public static void printArr(int[] arr) {
StringBuilder sb = new StringBuilder("");
for(int i=0;i<arr.length;i++) {
sb.append(arr[i]+" ");
}
System.out.println(sb.toString());
}
public static void printArr2(int[][] arr) {
int n = arr.length;
int m = arr[0].length;
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 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) {
try {
System.setIn(new FileInputStream("input.txt"));
System.setOut(new PrintStream(new FileOutputStream("output.txt")));
} catch (Exception e) {
System.err.println("Error");
}
// code
FastReader sc = new FastReader();
int t = sc.nextInt();
// int t = 1;
for(int tt=0; tt<t; tt++) {
int n = sc.nextInt();
int m = sc.nextInt();
// int[] arr = new int[n];
// for(int i=0;i<n;i++) {
// arr[i] = sc.nextInt();
// }
Object result = find(n, m);
println(result);
}
return;
}
public static Object find(int n, int m) {
return (n+1)/2+ " "+(m+1)/2;
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
0b47cf8894030f20e7553e6e6536029d
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main
{
public static void main(String[] args)
{
FastScanner input = new FastScanner();
int tc = input.nextInt();
work:
while (tc-- > 0) {
int n = input.nextInt();
int m = input.nextInt();
if(n==3&&m==3)
{
System.out.println("2 2");
}
else if(n==3&&m==2)
{
System.out.println("2 1");
}
else if(n==2&&m==3)
{
System.out.println("2 2");
}
else
System.out.println("1 1");
}
}
static class FastScanner
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next()
{
while (!st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine() throws IOException
{
return br.readLine();
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
e8a72ee0f8f6ae9f1335f43d3017a309
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class Main
{
public static void main(String args[]) throws IOException
{
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();
if(n==1||m==1)
System.out.println("1 1");
else if(n*m<=6)
System.out.println("2 2");
else if(n==3&&n==3)
System.out.println("2 2");
else
System.out.println("1 1");
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
c9d1ad2f3a68a09c6fe78d0b8b3a0d97
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class C {
public static void main(String[] args) {
FastScanner sc = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int t = sc.nextInt();
for (int oo = 0; oo < t; oo++) {
int n = sc.nextInt();
int m = sc.nextInt();
if (n == 3 && m == 3){
out.println("2 2");
continue;
}
if (n == 3 && m < 3){
out.println("2 1");
continue;
}
if (n < 3 && m ==3){
out.println("1 2");
continue;
}
out.println("1 1");
}
out.close();
}
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens()) try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
Integer[] readArray(int n) {
Integer[] a = new Integer[n];
for (int i = 0; i < n; i++) a[i] = nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
3d75903b0b5d7e6ecb498060675b2d12
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class cp {
static PrintWriter w = new PrintWriter(System.out);
static FastScanner s = new FastScanner();
static int mod = 1000000007;
static class Edge {
int src;
int wt;
int nbr;
Edge(int src, int nbr, int et) {
this.src = src;
this.wt = et;
this.nbr = nbr;
}
}
class EdgeComparator implements Comparator<Edge> {
@Override
//return samllest elemnt on polling
public int compare(Edge s1, Edge s2) {
if (s1.wt < s2.wt) {
return -1;
} else if (s1.wt > s2.wt) {
return 1;
}
return 0;
}
}
static long gcd(long a, long b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
static void prime_till_n(boolean[] prime) {
// Create a boolean array
// "prime[0..n]" and
// initialize all entries
// it as true. A value in
// prime[i] will finally be
// false if i is Not a
// prime, else true.
for (int p = 2; p * p < prime.length; p++) {
// If prime[p] is not changed, then it is a
// prime
if (prime[p] == true) {
// Update all multiples of p
for (int i = p * p; i < prime.length; i += p) {
prime[i] = false;
}
}
}
// int l = 1;
// for (int i = 2; i <= n; i++) {
// if (prime[i]) {
// w.print(i+",");
// arr[i] = l;
// l++;
// }
// }
//Time complexit Nlog(log(N))
}
static int noofdivisors(int n) {
//it counts no of divisors of every number upto number n
int arr[] = new int[n + 1];
for (int i = 1; i <= (n); i++) {
for (int j = i; j <= (n); j = j + i) {
arr[j]++;
}
}
return arr[0];
}
static char[] reverse(char arr[]) {
char[] b = new char[arr.length];
int j = arr.length;
for (int i = 0; i < arr.length; i++) {
b[j - 1] = arr[i];
j = j - 1;
}
return b;
}
static long factorial(int n) {
if (n == 0) {
return 1;
}
long su = 1;
for (int i = 1; i <= n; i++) {
su *= (long) i;
}
return su;
}
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
public String next() {
while (!st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
long[] readArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++) {
a[i] = nextLong();
}
return a;
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
}
static class Vertex {
int x;
int y;
int wt;
public Vertex(int x, int y) {
this.x = x;
this.y = y;
}
public Vertex(int x, int y, int wt) {
this.x = x;
this.y = y;
this.wt = wt;
}
}
public static long power(long x, int n) {
if (n == 0) {
return 1l;
}
long pow = power(x, n / 2) % mod;
if ((n & 1) == 1) // if `y` is odd
{
return ((((x % mod) * (pow % mod)) % mod) * (pow % mod)) % mod;
}
// otherwise, `y` is even
return ((pow % mod) * (pow % mod)) % mod;
}
public static void main(String[] args) {
{
int t = s.nextInt();
// int t = 1;
while (t-- > 0) {
solve();
}
w.close();
}
}
public static void solve() {
int n = s.nextInt();int m = s.nextInt();
int arr[] = new int[n];
Map<Integer, Integer> mp = new HashMap<>();
TreeSet<Integer> set = new TreeSet<>();
// String str=s.next();
for (int i = 0; i < n; i++) {
// arr[i] = s.nextInt();
}
if(n<3 && m<3)
w.println("1 1");
else
w.println((n+1)/2+" "+((m+1)/2));
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
a58b64faba0b3c6824e6304af4c4e5e0
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class Main {
static BufferedReader bf;
static PrintWriter out;
static Scanner sc;
static StringTokenizer st;
static long mod = (long)(1e9+7);
static long mod2 = 998244353;
static long fact[];
static long inverse[];
public static void main (String[] args)throws IOException {
bf = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
sc = new Scanner(System.in);
// fact = new long[2001];
// inverse = new long[2001];
// fact[0] = 1;
// inverse[0] = 1;
// for(int i = 1;i<fact.length;i++){
// fact[i] = (fact[i-1] * i)%mod;
// inverse[i] = binaryExpo(fact[i], mod-2);
// }
int t = nextInt();
while(t-->0){
solve();
}
out.flush();
}
public static void solve()throws IOException{
int n = nextInt();
int m = nextInt();
if(n == 3 && m == 3){
out.println(2 + " " + 2);
}
else if(n >= 3 && m >= 3){
out.println(1 + " " + 1);
}
else{
if(n == 1 || m == 1){
out.println(1 + " " + 1);
}
else if(n == 2 && m == 3){
out.println(1 + " " + 2);
}
else if(n == 3 && m == 2){
out.println(2 + " " + 1);
}
else {
out.println(1 + " " + 1);
}
}
}
public static int compare(String a , String b){
if(a.compareTo(b) < 0)return -1;
if(a.compareTo(b) > 0)return 1;
return 0;
}
public static void req(long l,long r){
out.println("? " + l + " " + r);
out.flush();
}
public static long sum(int node ,int left,int right,int tleft,int tright,long[]tree){
if(left >= tleft && right <= tright)return tree[node];
if(right < tleft || left > tright)return 0;
int mid = (left + right )/2;
return sum(node * 2, left,mid,tleft,tright,tree) + sum(node * 2 + 1 ,mid + 1, right,tleft,tright,tree);
}
public static void req(int l,int r){
out.println("? " + l + " " + r);
out.flush();
}
public static int[] bringSame(int u,int v ,int parent[][],int[]depth){
if(depth[u] < depth[v]){
int temp = u;
u = v;
v = temp;
}
int k = depth[u] - depth[v];
for(int i = 0;i<=18;i++){
if((k & (1<<i)) != 0){
u = parent[u][i];
}
}
return new int[]{u,v};
}
public static void findDepth(List<List<Integer>>list,int cur,int parent,int[]depth,int[][]p){
List<Integer>temp = list.get(cur);
p[cur][0] = parent;
for(int i = 0;i<temp.size();i++){
int next = temp.get(i);
if(next != parent){
depth[next] = depth[cur]+1;
findDepth(list,next,cur,depth,p);
}
}
}
public static int lca(int u, int v,int[][]parent){
if(u == v)return u;
for(int i = 18;i>=0;i--){
if(parent[u][i] != parent[v][i]){
u = parent[u][i];
v = parent[v][i];
}
}
return parent[u][0];
}
public static void plus(int node,int low,int high,int tlow,int thigh,int[]tree){
if(low >= tlow && high <= thigh){
tree[node]++;
return;
}
if(high < tlow || low > thigh)return;
int mid = (low + high)/2;
plus(node*2,low,mid,tlow,thigh,tree);
plus(node*2 + 1 , mid + 1, high,tlow, thigh,tree);
}
public static boolean allEqual(int[]arr,int x){
for(int i = 0;i<arr.length;i++){
if(arr[i] != x)return false;
}
return true;
}
public static long helper(StringBuilder sb){
return Long.parseLong(sb.toString());
}
public static int min(int node,int low,int high,int tlow,int thigh,int[][]tree){
if(low >= tlow&& high <= thigh)return tree[node][0];
if(high < tlow || low > thigh)return Integer.MAX_VALUE;
int mid = (low + high)/2;
// println(low+" "+high+" "+tlow+" "+thigh);
return Math.min(min(node*2,low,mid,tlow,thigh,tree) ,min(node*2+1,mid+1,high,tlow,thigh,tree));
}
public static int max(int node,int low,int high,int tlow,int thigh,int[][]tree){
if(low >= tlow && high <= thigh)return tree[node][1];
if(high < tlow || low > thigh)return Integer.MIN_VALUE;
int mid = (low + high)/2;
return Math.max(max(node*2,low,mid,tlow,thigh,tree) ,max(node*2+1,mid+1,high,tlow,thigh,tree));
}
public static long[] help(List<List<Integer>>list,int[][]range,int cur){
List<Integer>temp = list.get(cur);
if(temp.size() == 0)return new long[]{range[cur][1],1};
long sum = 0;
long count = 0;
for(int i = 0;i<temp.size();i++){
long []arr = help(list,range,temp.get(i));
sum += arr[0];
count += arr[1];
}
if(sum < range[cur][0]){
count++;
sum = range[cur][1];
}
return new long[]{sum,count};
}
public static long findSum(int node,int low, int high,int tlow,int thigh,long[]tree,long mod){
if(low >= tlow && high <= thigh)return tree[node]%mod;
if(low > thigh || high < tlow)return 0;
int mid = (low + high)/2;
return((findSum(node*2,low,mid,tlow,thigh,tree,mod) % mod) + (findSum(node*2+1,mid+1,high,tlow,thigh,tree,mod)))%mod;
}
public static boolean allzero(long[]arr){
for(int i =0 ;i<arr.length;i++){
if(arr[i]!=0)return false;
}
return true;
}
public static long count(long[][]dp,int i,int[]arr,int drank,long sum){
if(i == arr.length)return 0;
if(dp[i][drank]!=-1 && arr[i]+sum >=0)return dp[i][drank];
if(sum + arr[i] >= 0){
long count1 = 1 + count(dp,i+1,arr,drank+1,sum+arr[i]);
long count2 = count(dp,i+1,arr,drank,sum);
return dp[i][drank] = Math.max(count1,count2);
}
return dp[i][drank] = count(dp,i+1,arr,drank,sum);
}
public static void help(int[]arr,char[]signs,int l,int r){
if( l < r){
int mid = (l+r)/2;
help(arr,signs,l,mid);
help(arr,signs,mid+1,r);
merge(arr,signs,l,mid,r);
}
}
public static void merge(int[]arr,char[]signs,int l,int mid,int r){
int n1 = mid - l + 1;
int n2 = r - mid;
int[]a = new int[n1];
int []b = new int[n2];
char[]asigns = new char[n1];
char[]bsigns = new char[n2];
for(int i = 0;i<n1;i++){
a[i] = arr[i+l];
asigns[i] = signs[i+l];
}
for(int i = 0;i<n2;i++){
b[i] = arr[i+mid+1];
bsigns[i] = signs[i+mid+1];
}
int i = 0;
int j = 0;
int k = l;
boolean opp = false;
while(i<n1 && j<n2){
if(a[i] <= b[j]){
arr[k] = a[i];
if(opp){
if(asigns[i] == 'R'){
signs[k] = 'L';
}
else{
signs[k] = 'R';
}
}
else{
signs[k] = asigns[i];
}
i++;
k++;
}
else{
arr[k] = b[j];
int times = n1 - i;
if(times%2 == 1){
if(bsigns[j] == 'R'){
signs[k] = 'L';
}
else{
signs[k] = 'R';
}
}
else{
signs[k] = bsigns[j];
}
j++;
opp = !opp;
k++;
}
}
while(i<n1){
arr[k] = a[i];
if(opp){
if(asigns[i] == 'R'){
signs[k] = 'L';
}
else{
signs[k] = 'R';
}
}
else{
signs[k] = asigns[i];
}
i++;
k++;
}
while(j<n2){
arr[k] = b[j];
signs[k] = bsigns[j];
j++;
k++;
}
}
public static long nck(int n,int k){
return ((fact[n] * (inverse[n-k])%mod) * inverse[k])%mod;
}
public static long binaryExpo(long base,long expo){
if(expo == 0)return 1;
long val;
if(expo%2 == 1){
val = (binaryExpo(base, expo/2));
val = (val * val)%mod;
val = (val * base)%mod;
}
else{
val = binaryExpo(base, expo/2);
val = (val*val)%mod;
}
return (val%mod);
}
public static boolean isSorted(int[]arr){
for(int i =1;i<arr.length;i++){
if(arr[i] < arr[i-1]){
return false;
}
}
return true;
}
//function to find the topological sort of the a DAG
public static boolean hasCycle(int[]indegree,List<List<Integer>>list,int n,List<Integer>topo){
Queue<Integer>q = new LinkedList<>();
for(int i =1;i<indegree.length;i++){
if(indegree[i] == 0){
q.add(i);
topo.add(i);
}
}
while(!q.isEmpty()){
int cur = q.poll();
List<Integer>l = list.get(cur);
for(int i = 0;i<l.size();i++){
indegree[l.get(i)]--;
if(indegree[l.get(i)] == 0){
q.add(l.get(i));
topo.add(l.get(i));
}
}
}
if(topo.size() == n)return false;
return true;
}
// function to find the parent of any given node with path compression in DSU
public static int find(int val,int[]parent){
if(val == parent[val])return val;
return parent[val] = find(parent[val],parent);
}
// function to connect two components
public static void union(int[]rank,int[]parent,int u,int v){
int a = find(u,parent);
int b= find(v,parent);
if(a == b)return;
if(rank[a] == rank[b]){
parent[b] = a;
rank[a]++;
}
else{
if(rank[a] > rank[b]){
parent[b] = a;
}
else{
parent[a] = b;
}
}
}
//
public static int findN(int n){
int num = 1;
while(num < n){
num *=2;
}
return num;
}
// code for input
public static void print(String s ){
System.out.print(s);
}
public static void print(int num ){
System.out.print(num);
}
public static void print(long num ){
System.out.print(num);
}
public static void println(String s){
System.out.println(s);
}
public static void println(int num){
System.out.println(num);
}
public static void println(long num){
System.out.println(num);
}
public static void println(){
System.out.println();
}
public static int Int(String s){
return Integer.parseInt(s);
}
public static long Long(String s){
return Long.parseLong(s);
}
public static String[] nextStringArray()throws IOException{
return bf.readLine().split(" ");
}
public static String nextString()throws IOException{
return bf.readLine();
}
public static long[] nextLongArray(int n)throws IOException{
String[]str = bf.readLine().split(" ");
long[]arr = new long[n];
for(int i =0;i<n;i++){
arr[i] = Long.parseLong(str[i]);
}
return arr;
}
public static int[][] newIntMatrix(int r,int c)throws IOException{
int[][]arr = new int[r][c];
for(int i =0;i<r;i++){
String[]str = bf.readLine().split(" ");
for(int j =0;j<c;j++){
arr[i][j] = Integer.parseInt(str[j]);
}
}
return arr;
}
public static long[][] newLongMatrix(int r,int c)throws IOException{
long[][]arr = new long[r][c];
for(int i =0;i<r;i++){
String[]str = bf.readLine().split(" ");
for(int j =0;j<c;j++){
arr[i][j] = Long.parseLong(str[j]);
}
}
return arr;
}
static class pair{
int one;
int two;
pair(int one,int two){
this.one = one ;
this.two =two;
}
}
public static long gcd(long a,long b){
if(b == 0)return a;
return gcd(b,a%b);
}
public static long lcm(long a,long b){
return (a*b)/(gcd(a,b));
}
public static boolean isPalindrome(String s){
int i = 0;
int j = s.length()-1;
while(i<=j){
if(s.charAt(i) != s.charAt(j)){
return false;
}
i++;
j--;
}
return true;
}
// these functions are to calculate the number of smaller elements after self
public static void sort(int[]arr,int l,int r){
if(l < r){
int mid = (l+r)/2;
sort(arr,l,mid);
sort(arr,mid+1,r);
smallerNumberAfterSelf(arr, l, mid, r);
}
}
public static void smallerNumberAfterSelf(int[]arr,int l,int mid,int r){
int n1 = mid - l +1;
int n2 = r - mid;
int []a = new int[n1];
int[]b = new int[n2];
for(int i = 0;i<n1;i++){
a[i] = arr[l+i];
}
for(int i =0;i<n2;i++){
b[i] = arr[mid+i+1];
}
int i = 0;
int j =0;
int k = l;
while(i<n1 && j < n2){
if(a[i] < b[j]){
arr[k++] = a[i++];
}
else{
arr[k++] = b[j++];
}
}
while(i<n1){
arr[k++] = a[i++];
}
while(j<n2){
arr[k++] = b[j++];
}
}
public static String next(){
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(bf.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
static int nextInt() {
return Integer.parseInt(next());
}
static long nextLong() {
return Long.parseLong(next());
}
static double nextDouble() {
return Double.parseDouble(next());
}
static String nextLine(){
String str = "";
try {
str = bf.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
// use some math tricks it might help
// sometimes just try to think in straightforward plan in A and B problems don't always complecate the questions with thinking too much differently
// always use long number to do 10^9+7 modulo
// if a problem is related to binary string it could also be related to parenthesis
// *****try to use binary search(it is a very beautiful thing it can work in some of the very unexpected problems ) in the question it might work******
// try sorting
// try to think in opposite direction of question it might work in your way
// if a problem is related to maths try to relate some of the continuous subarray with variables like - > a+b+c+d or a,b,c,d in general
// if the question is to much related to left and/or right side of any element in an array then try monotonic stack it could work.
// in range query sums try to do binary search it could work
// analyse the time complexity of program thoroughly
// anylyse the test cases properly
// if we divide any number by 2 till it gets 1 then there will be (number - 1) operation required
// try to do the opposite operation of what is given in the problem
//think about the base cases properly
//If a question is related to numbers try prime factorisation or something related to number theory
// keep in mind unique strings
//you can calculate the number of inversion in O(n log n)
// in a matrix you could sometimes think about row and cols indenpendentaly.
// Try to think in more constructive(means a way to look through various cases of a problem) way.
// observe the problem carefully the answer could be hidden in the given test cases itself. (A, B , C);
// when we have equations like (a+b = N) and we have to find the max of (a*b) then the values near to the N/2 must be chosen as (a and b);
// give emphasis to the number of occurences of elements it might help.
// if a number is even then we can find the pair for each and every number in that range whose bitwise AND is zero.
// if a you find a problem related to the graph make a graph
// There is atleast one prime number between the interval [n , 3n/2];
// If a problem is related to maths then try to form an mathematical equation.
// you can create any sum between (n * (n + 1)/2) with first n natural numbers.
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
32079050c0751e5636f144ee01575679
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class Solution {
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 {
if(st.hasMoreTokens()){
str = st.nextToken("\n");
}
else{
str = br.readLine();
}
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}}
public static void main(String[] args) throws IOException{
// try {
// System.setIn(new FileInputStream("input.txt"));
// System.setOut(new PrintStream(new FileOutputStream("output.txt")));
// } catch (Exception e) {
// System.err.println("Error");
// }
FastReader in = new FastReader();
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out, "UTF-8")));
int t = in.nextInt();
while(t-- > 0) {
int r = in.nextInt();
int c = in.nextInt();
// int[] arr = new int[n];
// for(int i = 0; i < n; i++) {
// arr[i] = in.nextInt();
// }
int[] ans= solve(r, c);
System.out.println(ans[0] + " " + ans[1]);
}
}
static int[][] DIRS = new int[][] {{2, 1}, {1, 2}, {-1, 2}, {-2, 1}, {-2, -1}, {-1, -2}, {1, -2}, {2, -1}};
static int[] solve(int m, int n) {
for(int i = 0; i < m; i++) {
for(int j = 0; j < n; j++) {
int cnt = 0;
for(int[] d : DIRS) {
int r = i + d[0];
int c = j + d[1];
if(r < 0 || c < 0 || r >= m || c >= n) cnt++;
}
if(cnt == 8) return new int[] {i+1, j+1};
}
}
return new int[] {1, 1};
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
387048ac2114ed37ac7ef4a85ffe93af
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class Main {
static Scanner sc;
static PrintWriter pw;
public static void main(String[] args) throws Exception {
pw = new PrintWriter(System.out);
sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt(), m = sc.nextInt();
if (n == 1 || m == 1) {
pw.println(1 + " " + 1);
} else if (n <= 3 || m <= 3) {
pw.println(2 + " " + 2);
} else
pw.println(1 + " " + 1);
}
pw.flush();
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public Scanner(FileReader r) {
br = new BufferedReader(r);
}
public String readAllLines(BufferedReader reader) throws IOException {
StringBuilder content = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
content.append(line);
content.append(System.lineSeparator());
}
return content.toString();
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public String nextLine() throws IOException {
return br.readLine();
}
public double nextDouble() throws IOException {
String x = next();
StringBuilder sb = new StringBuilder("0");
double res = 0, f = 1;
boolean dec = false, neg = false;
int start = 0;
if (x.charAt(0) == '-') {
neg = true;
start++;
}
for (int i = start; i < x.length(); i++)
if (x.charAt(i) == '.') {
res = Long.parseLong(sb.toString());
sb = new StringBuilder("0");
dec = true;
} else {
sb.append(x.charAt(i));
if (dec)
f *= 10;
}
res += Long.parseLong(sb.toString()) / f;
return res * (neg ? -1 : 1);
}
public long[] nextlongArray(int n) throws IOException {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public Long[] nextLongArray(int n) throws IOException {
Long[] a = new Long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public int[] nextIntArray(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public Integer[] nextIntegerArray(int n) throws IOException {
Integer[] a = new Integer[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public boolean ready() throws IOException {
return br.ready();
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
ee034352d5d9db2b3a18f61f9da58381
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class Main {
public static void main(String args[]) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
int t = Integer.parseInt(in.readLine());
while (t-- > 0) {
StringTokenizer st1 = new StringTokenizer(in.readLine());
// StringTokenizer st2 = new StringTokenizer(in.readLine());
int n = Integer.parseInt(st1.nextToken());
int m = Integer.parseInt(st1.nextToken());
// int[] a = new int[n];
// for (int i = 0; i < n; i++) {
// a[i] = Integer.parseInt(st2.nextToken());
// }
// if (n > m) {
// int temp = n;
// n = m;
// m = temp;
// }
if (n == 1 || m == 1)
out.println("1 1");
else
out.println("2 2");
}
in.close();
out.close();
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
e8bb15634a47996ec362f5bf20a77be7
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.time.Clock;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Random;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.function.Supplier;
public class Solution {
private void solve() throws IOException {
int n = nextInt();
int m = nextInt();
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
boolean c = false;
for (int x = -2; x <= 2 && !c; x++) {
for (int y = -2; y <= 2 && !c; y++) {
if (Math.abs(x) + Math.abs(y) == 3) {
int ii = i + x;
int jj = j + y;
if (ii >= 0 && jj >= 0 && ii < n && jj < m) {
c = true;
}
}
}
}
if (!c) {
println(i + 1, j + 1);
return;
}
}
}
println(1, 1);
}
private static final boolean runNTestsInProd = true;
private static final boolean printCaseNumber = false;
private static final boolean assertInProd = false;
private static final boolean logToFile = false;
private static final boolean readFromConsoleInDebug = false;
private static final boolean writeToConsoleInDebug = true;
private static final boolean testTimer = false;
private static Boolean isDebug = null;
private BufferedReader in;
private StringTokenizer line;
private PrintWriter out;
public static void main(String[] args) throws Exception {
isDebug = Arrays.asList(args).contains("DEBUG_MODE");
if (isDebug) {
log = logToFile ? new PrintWriter("logs/j_solution_" + System.currentTimeMillis() + ".log") : new PrintWriter(System.out);
clock = Clock.systemDefaultZone();
}
new Solution().run();
}
private void run() throws Exception {
in = new BufferedReader(new InputStreamReader(!isDebug || readFromConsoleInDebug ? System.in : new FileInputStream("input.txt")));
out = !isDebug || writeToConsoleInDebug ? new PrintWriter(System.out) : new PrintWriter("output.txt");
try (Timer totalTimer = new Timer("total")) {
int t = runNTestsInProd || isDebug ? nextInt() : 1;
for (int i = 0; i < t; i++) {
if (printCaseNumber) {
out.print("Case #" + (i + 1) + ": ");
}
if (testTimer) {
try (Timer testTimer = new Timer("test #" + (i + 1))) {
solve();
}
} else {
solve();
}
if (isDebug) {
out.flush();
}
}
}
in.close();
out.flush();
out.close();
}
private void println(Object... objects) {
boolean isFirst = true;
for (Object o : objects) {
if (!isFirst) {
out.print(" ");
} else {
isFirst = false;
}
out.print(o.toString());
}
out.println();
}
private int[] nextIntArray(int n) throws IOException {
return nextIntArray(n, 0);
}
private int[] nextIntArray(int n, int delta) throws IOException {
int[] res = new int[n];
for (int i = 0; i < n; i++) {
res[i] = nextInt() + delta;
}
return res;
}
private long[] nextLongArray(int n) throws IOException {
long[] res = new long[n];
for (int i = 0; i < n; i++) {
res[i] = nextLong();
}
return res;
}
private int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
private long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
private double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
private char[] nextTokenChars() throws IOException {
return nextToken().toCharArray();
}
private String nextToken() throws IOException {
while (line == null || !line.hasMoreTokens()) {
line = new StringTokenizer(in.readLine());
}
return line.nextToken();
}
private static void assertPredicate(boolean p) {
if ((isDebug || assertInProd) && !p) {
throw new RuntimeException();
}
}
private static void assertPredicate(boolean p, String message) {
if ((isDebug || assertInProd) && !p) {
throw new RuntimeException(message);
}
}
private static <T> void assertNotEqual(T unexpected, T actual) {
if ((isDebug || assertInProd) && Objects.equals(actual, unexpected)) {
throw new RuntimeException("assertNotEqual: " + unexpected + " == " + actual);
}
}
private static <T> void assertEqual(T expected, T actual) {
if ((isDebug || assertInProd) && !Objects.equals(actual, expected)) {
throw new RuntimeException("assertEqual: " + expected + " != " + actual);
}
}
private static PrintWriter log = null;
private static Clock clock = null;
private static void log(Object... objects) {
log(true, objects);
}
private static void logNoDelimiter(Object... objects) {
log(false, objects);
}
private static void log(boolean printDelimiter, Object[] objects) {
if (isDebug) {
StringBuilder sb = new StringBuilder();
sb.append(LocalDateTime.now(clock)).append(" - ");
boolean isFirst = true;
for (Object o : objects) {
if (!isFirst && printDelimiter) {
sb.append(" ");
} else {
isFirst = false;
}
sb.append(o.toString());
}
log.println(sb);
log.flush();
}
}
private static class Timer implements Closeable {
private final String label;
private final long startTime = isDebug ? System.nanoTime() : 0;
public Timer(String label) {
this.label = label;
}
@Override
public void close() throws IOException {
if (isDebug) {
long executionTime = System.nanoTime() - startTime;
String fraction = Long.toString(executionTime / 1000 % 1_000_000);
logNoDelimiter("Timer[", label, "]: ", executionTime / 1_000_000_000, '.', "00000".substring(0, 6 - fraction.length()), fraction, 's');
}
}
}
private static <T> T timer(String label, Supplier<T> f) throws Exception {
if (isDebug) {
try (Timer timer = new Timer(label)) {
return f.get();
}
} else {
return f.get();
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
93b0fe08c79f9c27b6af0e59483b934e
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.*;
public class Solution
{
static Scanner sc=new Scanner(System.in);
public static void main (String[] args) throws java.lang.Exception
{
int t;
t = sc.nextInt();
while(t-- != 0){
int n,m;
n = sc.nextInt();
m = sc.nextInt();
System.out.println((n/2+1) + " " + (m/2+1));
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
19fc51f57183d7b07f88b15bad00dfda
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int x=0;x<t;x++){
int r=sc.nextInt();int c=sc.nextInt();
if(r==1 || c==1)
System.out.println(1+" "+1);
else if((r<3 && c>3) || (c<3 && r>3) || (r>3 && c>3))
System.out.println(1+" "+1);
else{
System.out.println((int)(Math.ceil(r/2.0f))+" "+(int)(Math.ceil(c/2.0f)));
}
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
ce6a2d3ec182c968837470993d9f3e1e
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.*;
import java.lang.*;
public class codeforces
{
public static void main(String[] args)
{
Scanner ob=new Scanner(System.in);
int t=ob.nextInt();
for(int z=0;z<t;z++)
{
int a=ob.nextInt();
int b=ob.nextInt();
if(a==1 || b==1)
System.out.println("1 1");
else if(a<4 && b<4)
{
System.out.println((a-1)+" "+(b-1));
}
else
{
System.out.println("1 1");
}
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
670fae7af41007843c92dbfad2ee3964
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class A {
public static void main(String[] args) throws IOException {
FastReader in = new FastReader(System.in);
PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
int t = in.nextInt();
for (int tt = 0; tt < t; tt++) {
int n = in.nextInt();
int m = in.nextInt();
if (n == 1 || m == 1) pw.println("1 1");
else pw.println("2 2");
}
pw.close();
}
public static void Sort(int[] a) {
ArrayList<Integer> lst = new ArrayList<>();
for (int i : a) lst.add(i);
Collections.sort(lst);
for (int i = 0; i < lst.size(); i++) a[i] = lst.get(i);
}
static void debug(Object... obj) {
System.err.println(Arrays.deepToString(obj));
}
static class FastReader {
InputStream is;
private byte[] inbuf = new byte[1024];
private int lenbuf = 0, ptrbuf = 0;
public FastReader(InputStream is) {
this.is = is;
}
public 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++];
}
public boolean isSpaceChar(int c) {
return !(c >= 33 && c <= 126);
}
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
public int skip() {
int b;
while ((b = readByte()) != -1 && isSpaceChar(b)) ;
return b;
}
public String next() {
int b = skip();
StringBuilder sb = new StringBuilder();
while (!(isSpaceChar(b))) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public String nextLine() {
int c = skip();
StringBuilder sb = new StringBuilder();
while (!isEndOfLine(c)) {
sb.appendCodePoint(c);
c = readByte();
}
return sb.toString();
}
public int nextInt() {
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 << 3) + (num << 1) + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
public long nextLong() {
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 << 3) + (num << 1) + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
public double nextDouble() {
return Double.parseDouble(next());
}
public char[] next(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);
}
public char readChar() {
return (char) skip();
}
public long[] readArrayL(int n) {
long[] arr = new long[n];
for (int i = 0; i < n; i++) arr[i] = nextLong();
return arr;
}
public int[] readArray(int n) {
int[] arr = new int[n];
for (int i = 0; i < n; i++) arr[i] = nextInt();
return arr;
}
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
7ad0b84de56593e46cb1ac2305b001d1
|
train_109.jsonl
|
1664462100
|
There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction: Find any isolated cell on the board. If there are no such cells, print any cell on the board.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class Main{
static int T,N,M;
static int[] dx={-1,-2,-2,-1,1,2,2,1};
static int[] dy={-2,-1,1,2,2,1,-1,-2};
public static void main(String[] args) throws Exception{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
T=Integer.parseInt(br.readLine());
int res=0;
while(T-->0){
String[] in=br.readLine().split(" ");
N=Integer.parseInt(in[0]);
M=Integer.parseInt(in[1]);
boolean flag=false;
for(int i=1;i<=N;i++){
for(int j=1;j<=M;j++){
if(valid(i,j)){
System.out.println(i+" "+j);
flag=true;
break;
}
}
if(flag){
break;
}
}
if(!flag){
System.out.println(N+" "+M);
}
}
}
public static boolean valid(int x,int y){
for(int i=0;i<dx.length;i++){
int nx=dx[i]+x;
int ny=dy[i]+y;
if(nx<=0||nx>N||ny<=0||ny>M){
continue;
}
return false;
}
return true;
}
}
|
Java
|
["3\n\n1 7\n\n8 8\n\n3 3"]
|
2 seconds
|
["1 7\n7 2\n2 2"]
|
NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.
|
Java 8
|
standard input
|
[
"implementation"
] |
e6753e3f71ff13cebc1aaf04d3d2106b
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.
| 800
|
For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.
|
standard output
| |
PASSED
|
279ea7796b12ef78c80181bf3bf95a03
|
train_109.jsonl
|
1664462100
|
You are given a rooted tree, consisting of $$$n$$$ vertices. The vertices are numbered from $$$1$$$ to $$$n$$$, the root is the vertex $$$1$$$.You can perform the following operation at most $$$k$$$ times: choose an edge $$$(v, u)$$$ of the tree such that $$$v$$$ is a parent of $$$u$$$; remove the edge $$$(v, u)$$$; add an edge $$$(1, u)$$$ (i. e. make $$$u$$$ with its subtree a child of the root). The height of a tree is the maximum depth of its vertices, and the depth of a vertex is the number of edges on the path from the root to it. For example, the depth of vertex $$$1$$$ is $$$0$$$, since it's the root, and the depth of all its children is $$$1$$$.What's the smallest height of the tree that can be achieved?
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class Main {
static Scanner sc;
static PrintWriter pw;
static int depth[][], par[];
static boolean[] vis;
static void dfs(int u) {
vis[u] = true;
if (u == 0)
return;
if (vis[par[u]]) {
depth[u][0] = 1 + depth[par[u]][0];
depth[u][1] = u;
return;
}
dfs(par[u]);
depth[u][0] = 1 + depth[par[u]][0];
depth[u][1] = u;
}
public static void main(String[] args) throws Exception {
pw = new PrintWriter(System.out);
sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt(), k = sc.nextInt();
par = new int[n + 1];
depth = new int[n + 1][2];
vis = new boolean[n + 1];
for (int i = 2; i <= n; i++)
par[i] = sc.nextInt();
for (int i = n; i >= 0; i--) {
if (!vis[i])
dfs(i);
}
Arrays.sort(depth, (a, b) -> a[0] - b[0]);
int l = 1, r = n - 1;
while (l <= r) {
int mid = l + r >> 1;
boolean[] vis = new boolean[n + 1];
int[] cnt = new int[n + 1];
for (int i = n; i > 1; i--) {
if (!vis[depth[i][1]]) {
int c = 0, j = depth[i][1];
while (j != 0 && c < mid) {
if (vis[j])
break;
vis[j] = true;
c++;
j = par[j];
}
if (c == mid && j != 1 && j != 0)
cnt[i]++;
}
cnt[par[i]] += cnt[i];
}
// System.out.println(Arrays.toString(cnt) + " " + mid);
if (cnt[1] <= k) {
r = mid - 1;
} else {
l = mid + 1;
}
}
pw.println(l);
}
pw.flush();
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public Scanner(FileReader r) {
br = new BufferedReader(r);
}
public String readAllLines(BufferedReader reader) throws IOException {
StringBuilder content = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
content.append(line);
content.append(System.lineSeparator());
}
return content.toString();
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public String nextLine() throws IOException {
return br.readLine();
}
public double nextDouble() throws IOException {
String x = next();
StringBuilder sb = new StringBuilder("0");
double res = 0, f = 1;
boolean dec = false, neg = false;
int start = 0;
if (x.charAt(0) == '-') {
neg = true;
start++;
}
for (int i = start; i < x.length(); i++)
if (x.charAt(i) == '.') {
res = Long.parseLong(sb.toString());
sb = new StringBuilder("0");
dec = true;
} else {
sb.append(x.charAt(i));
if (dec)
f *= 10;
}
res += Long.parseLong(sb.toString()) / f;
return res * (neg ? -1 : 1);
}
public long[] nextlongArray(int n) throws IOException {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public Long[] nextLongArray(int n) throws IOException {
Long[] a = new Long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public int[] nextIntArray(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public Integer[] nextIntegerArray(int n) throws IOException {
Integer[] a = new Integer[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public boolean ready() throws IOException {
return br.ready();
}
}
}
|
Java
|
["5\n\n5 1\n\n1 1 2 2\n\n5 2\n\n1 1 2 2\n\n6 0\n\n1 2 3 4 5\n\n6 1\n\n1 2 3 4 5\n\n4 3\n\n1 1 1"]
|
4 seconds
|
["2\n1\n5\n3\n1"]
| null |
Java 8
|
standard input
|
[
"binary search",
"data structures",
"dfs and similar",
"graphs",
"greedy",
"trees"
] |
f260d0885319a146904b43f89e253f0c
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of testcases. The first line of each testcase contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 2 \cdot 10^5$$$; $$$0 \le k \le n - 1$$$) — the number of vertices in the tree and the maximum number of operations you can perform. The second line contains $$$n-1$$$ integers $$$p_2, p_3, \dots, p_n$$$ ($$$1 \le p_i < i$$$) — the parent of the $$$i$$$-th vertex. Vertex $$$1$$$ is the root. The sum of $$$n$$$ over all testcases doesn't exceed $$$2 \cdot 10^5$$$.
| 1,900
|
For each testcase, print a single integer — the smallest height of the tree that can achieved by performing at most $$$k$$$ operations.
|
standard output
| |
PASSED
|
4043dcc8f52fcc15a8eddb0099dfb60e
|
train_109.jsonl
|
1664462100
|
You are given a rooted tree, consisting of $$$n$$$ vertices. The vertices are numbered from $$$1$$$ to $$$n$$$, the root is the vertex $$$1$$$.You can perform the following operation at most $$$k$$$ times: choose an edge $$$(v, u)$$$ of the tree such that $$$v$$$ is a parent of $$$u$$$; remove the edge $$$(v, u)$$$; add an edge $$$(1, u)$$$ (i. e. make $$$u$$$ with its subtree a child of the root). The height of a tree is the maximum depth of its vertices, and the depth of a vertex is the number of edges on the path from the root to it. For example, the depth of vertex $$$1$$$ is $$$0$$$, since it's the root, and the depth of all its children is $$$1$$$.What's the smallest height of the tree that can be achieved?
|
256 megabytes
|
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.function.Function;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author tauros
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
RealFastReader in = new RealFastReader(inputStream);
FastWriter out = new FastWriter(outputStream);
CF1739D solver = new CF1739D();
solver.solve(1, in, out);
out.close();
}
static class CF1739D {
public void solve(int testNumber, RealFastReader in, FastWriter out) {
int cases = in.ni();
while (cases-- > 0) {
int n = in.ni(), k = in.ni();
Graph graph = new GraphArr(n + 1, n);
for (int i = 2; i <= n; i++) {
int parent = in.ni();
graph.addEdge(parent, i);
}
int ans = Common.findFirst(n - 2, x -> {
int height = x + 1;
int[] cnt = new int[]{ 0 };
dfs(1, 0, graph, cnt, height);
return cnt[0] <= k;
}) + 1;
out.println(ans);
}
out.flush();
}
private int dfs(int u, int fa, Graph graph, int[] cnt, int maxHeight) {
int height = 0;
for (int e = graph.firstEdge(u); e != 0; e = graph.nextEdge(e)) {
int v = graph.getEdge(e).to;
int chdHeight = dfs(v, u, graph, cnt, maxHeight);
height = Math.max(height, chdHeight + 1);
}
if (u != 1 && fa != 1 && height >= maxHeight - 1) {
cnt[0]++;
return -1;
}
return height;
}
}
static interface Graph {
int firstEdge(int u);
Edge getEdge(int id);
int nextEdge(int id);
default int addEdge(int from, int to) {
return addEdge(from, to, 0, 0);
}
int addEdge(int from, int to, int vol, int cost);
}
static final class Common {
public static int findFirst(int n, Function<Integer, Boolean> judge) {
int l = 0, r = n;
while (l < r) {
int mid = l + ((r - l) >> 1);
Boolean result = judge.apply(mid);
if (result != null && result) {
r = mid;
} else {
l = mid + 1;
}
}
return l;
}
}
static class RealFastReader {
InputStream is;
private byte[] inbuf = new byte[8192];
public int lenbuf = 0;
public int ptrbuf = 0;
public RealFastReader(final InputStream is) {
this.is = is;
}
public 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++];
}
public int ni() {
int 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();
}
}
}
static class Edge {
public int from;
public int to;
public int next;
public int vol;
public int cost;
}
static class FastWriter {
private final PrintWriter writer;
public FastWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream), 8192));
}
public FastWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void println(int x) {
writer.println(x);
}
public void flush() {
writer.flush();
}
public void close() {
writer.flush();
try {
writer.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
static class GraphArr implements Graph {
private final int MAXN;
private int[] heads;
private Edge[] edges;
private int cnt;
public GraphArr(final int MAXN) {
this(MAXN, 2 * MAXN);
}
public GraphArr(final int MAXN, final int MAXE) {
this.MAXN = MAXN;
this.cnt = 1;
this.heads = new int[this.MAXN];
this.edges = new Edge[MAXE + 2];
}
public int firstEdge(final int u) {
return heads[u];
}
public Edge getEdge(final int id) {
return edges[id];
}
public int nextEdge(final int id) {
return edges[id].next;
}
public int addEdge(final int from, final int to, final int vol, final int cost) {
Edge edge = new Edge();
edge.from = from;
edge.to = to;
edge.vol = vol;
edge.cost = cost;
edge.next = heads[from];
edges[++cnt] = edge;
heads[from] = cnt;
return cnt;
}
}
}
|
Java
|
["5\n\n5 1\n\n1 1 2 2\n\n5 2\n\n1 1 2 2\n\n6 0\n\n1 2 3 4 5\n\n6 1\n\n1 2 3 4 5\n\n4 3\n\n1 1 1"]
|
4 seconds
|
["2\n1\n5\n3\n1"]
| null |
Java 8
|
standard input
|
[
"binary search",
"data structures",
"dfs and similar",
"graphs",
"greedy",
"trees"
] |
f260d0885319a146904b43f89e253f0c
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of testcases. The first line of each testcase contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 2 \cdot 10^5$$$; $$$0 \le k \le n - 1$$$) — the number of vertices in the tree and the maximum number of operations you can perform. The second line contains $$$n-1$$$ integers $$$p_2, p_3, \dots, p_n$$$ ($$$1 \le p_i < i$$$) — the parent of the $$$i$$$-th vertex. Vertex $$$1$$$ is the root. The sum of $$$n$$$ over all testcases doesn't exceed $$$2 \cdot 10^5$$$.
| 1,900
|
For each testcase, print a single integer — the smallest height of the tree that can achieved by performing at most $$$k$$$ operations.
|
standard output
| |
PASSED
|
e2175a7e41e9b43e9f81153040214b01
|
train_109.jsonl
|
1664462100
|
You are given a rooted tree, consisting of $$$n$$$ vertices. The vertices are numbered from $$$1$$$ to $$$n$$$, the root is the vertex $$$1$$$.You can perform the following operation at most $$$k$$$ times: choose an edge $$$(v, u)$$$ of the tree such that $$$v$$$ is a parent of $$$u$$$; remove the edge $$$(v, u)$$$; add an edge $$$(1, u)$$$ (i. e. make $$$u$$$ with its subtree a child of the root). The height of a tree is the maximum depth of its vertices, and the depth of a vertex is the number of edges on the path from the root to it. For example, the depth of vertex $$$1$$$ is $$$0$$$, since it's the root, and the depth of all its children is $$$1$$$.What's the smallest height of the tree that can be achieved?
|
256 megabytes
|
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.function.Function;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author tauros
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
RealFastReader in = new RealFastReader(inputStream);
FastWriter out = new FastWriter(outputStream);
CF1739D solver = new CF1739D();
solver.solve(1, in, out);
out.close();
}
static class CF1739D {
public void solve(int testNumber, RealFastReader in, FastWriter out) {
int cases = in.ni();
for (int number = 1; number <= cases; number++) {
int n = in.ni(), k = in.ni();
Graph graph = new GraphArr(n + 1, n);
for (int i = 2; i <= n; i++) {
int parent = in.ni();
graph.addEdge(parent, i);
}
int ans = Common.findFirst(n - 2, x -> {
int height = x + 1;
int[] cnt = new int[]{ 0 };
dfs(1, 0, graph, cnt, height);
return cnt[0] <= k;
}) + 1;
out.println(ans);
}
out.flush();
}
private int dfs(int u, int fa, Graph graph, int[] cnt, int maxHeight) {
int height = 0;
for (int e = graph.firstEdge(u); e != 0; e = graph.nextEdge(e)) {
int v = graph.getEdge(e).to;
int chdHeight = dfs(v, u, graph, cnt, maxHeight);
height = Math.max(height, chdHeight + 1);
}
if (u != 1 && fa != 1 && height >= maxHeight - 1) {
cnt[0]++;
return -1;
}
return height;
}
}
static interface Graph {
int firstEdge(int u);
Edge getEdge(int id);
int nextEdge(int id);
default int addEdge(int from, int to) {
return addEdge(from, to, 0, 0);
}
int addEdge(int from, int to, int vol, int cost);
}
static final class Common {
public static int findFirst(int n, Function<Integer, Boolean> judge) {
int l = 0, r = n;
while (l < r) {
int mid = l + ((r - l) >> 1);
Boolean result = judge.apply(mid);
if (result != null && result) {
r = mid;
} else {
l = mid + 1;
}
}
return l;
}
}
static class RealFastReader {
InputStream is;
private byte[] inbuf = new byte[8192];
public int lenbuf = 0;
public int ptrbuf = 0;
public RealFastReader(final InputStream is) {
this.is = is;
}
public 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++];
}
public int ni() {
int 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();
}
}
}
static class Edge {
public int from;
public int to;
public int next;
public int vol;
public int cost;
}
static class FastWriter {
private final PrintWriter writer;
public FastWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream), 8192));
}
public FastWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void println(int x) {
writer.println(x);
}
public void flush() {
writer.flush();
}
public void close() {
writer.flush();
try {
writer.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
static class GraphArr implements Graph {
private final int MAXN;
private int[] heads;
private Edge[] edges;
private int cnt;
public GraphArr(final int MAXN) {
this(MAXN, 2 * MAXN);
}
public GraphArr(final int MAXN, final int MAXE) {
this.MAXN = MAXN;
this.cnt = 1;
this.heads = new int[this.MAXN];
this.edges = new Edge[MAXE + 2];
}
public int firstEdge(final int u) {
return heads[u];
}
public Edge getEdge(final int id) {
return edges[id];
}
public int nextEdge(final int id) {
return edges[id].next;
}
public int addEdge(final int from, final int to, final int vol, final int cost) {
Edge edge = new Edge();
edge.from = from;
edge.to = to;
edge.vol = vol;
edge.cost = cost;
edge.next = heads[from];
edges[++cnt] = edge;
heads[from] = cnt;
return cnt;
}
}
}
|
Java
|
["5\n\n5 1\n\n1 1 2 2\n\n5 2\n\n1 1 2 2\n\n6 0\n\n1 2 3 4 5\n\n6 1\n\n1 2 3 4 5\n\n4 3\n\n1 1 1"]
|
4 seconds
|
["2\n1\n5\n3\n1"]
| null |
Java 8
|
standard input
|
[
"binary search",
"data structures",
"dfs and similar",
"graphs",
"greedy",
"trees"
] |
f260d0885319a146904b43f89e253f0c
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of testcases. The first line of each testcase contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 2 \cdot 10^5$$$; $$$0 \le k \le n - 1$$$) — the number of vertices in the tree and the maximum number of operations you can perform. The second line contains $$$n-1$$$ integers $$$p_2, p_3, \dots, p_n$$$ ($$$1 \le p_i < i$$$) — the parent of the $$$i$$$-th vertex. Vertex $$$1$$$ is the root. The sum of $$$n$$$ over all testcases doesn't exceed $$$2 \cdot 10^5$$$.
| 1,900
|
For each testcase, print a single integer — the smallest height of the tree that can achieved by performing at most $$$k$$$ operations.
|
standard output
| |
PASSED
|
431f55284d8dc55c91c4817b6310800a
|
train_109.jsonl
|
1664462100
|
You are given a rooted tree, consisting of $$$n$$$ vertices. The vertices are numbered from $$$1$$$ to $$$n$$$, the root is the vertex $$$1$$$.You can perform the following operation at most $$$k$$$ times: choose an edge $$$(v, u)$$$ of the tree such that $$$v$$$ is a parent of $$$u$$$; remove the edge $$$(v, u)$$$; add an edge $$$(1, u)$$$ (i. e. make $$$u$$$ with its subtree a child of the root). The height of a tree is the maximum depth of its vertices, and the depth of a vertex is the number of edges on the path from the root to it. For example, the depth of vertex $$$1$$$ is $$$0$$$, since it's the root, and the depth of all its children is $$$1$$$.What's the smallest height of the tree that can be achieved?
|
256 megabytes
|
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.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 tauros
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
RealFastReader in = new RealFastReader(inputStream);
FastWriter out = new FastWriter(outputStream);
CF1739D solver = new CF1739D();
solver.solve(1, in, out);
out.close();
}
static class CF1739D {
private int cnt = 0;
public void solve(int testNumber, RealFastReader in, FastWriter out) {
int cases = in.ni();
for (int number = 1; number <= cases; number++) {
int n = in.ni(), k = in.ni();
Graph graph = new GraphArr(n + 1, n);
for (int i = 2; i <= n; i++) {
int parent = in.ni();
graph.addEdge(parent, i);
}
int l = 1, r = n - 1;
while (l < r) {
int mid = l + r >> 1;
this.cnt = 0;
dfs(1, 0, graph, mid);
if (cnt <= k) {
r = mid;
} else {
l = mid + 1;
}
}
out.println(l);
}
out.flush();
}
private int dfs(int u, int fa, Graph graph, int maxHeight) {
int height = 0;
for (int e = graph.firstEdge(u); e != 0; e = graph.nextEdge(e)) {
int v = graph.getEdge(e).to;
int chdHeight = dfs(v, u, graph, maxHeight);
height = Math.max(height, chdHeight + 1);
}
if (u != 1 && fa != 1 && height >= maxHeight - 1) {
cnt++;
return -1;
}
return height;
}
}
static class RealFastReader {
InputStream is;
private byte[] inbuf = new byte[8192];
public int lenbuf = 0;
public int ptrbuf = 0;
public RealFastReader(final InputStream is) {
this.is = is;
}
public 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++];
}
public int ni() {
int 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();
}
}
}
static interface Graph {
int firstEdge(int u);
Edge getEdge(int id);
int nextEdge(int id);
default int addEdge(int from, int to) {
return addEdge(from, to, 0, 0);
}
int addEdge(int from, int to, int vol, int cost);
}
static class GraphArr implements Graph {
private final int MAXN;
private int[] heads;
private Edge[] edges;
private int cnt;
public GraphArr(final int MAXN) {
this(MAXN, 2 * MAXN);
}
public GraphArr(final int MAXN, final int MAXE) {
this.MAXN = MAXN;
this.cnt = 1;
this.heads = new int[this.MAXN];
this.edges = new Edge[MAXE + 2];
}
public int firstEdge(final int u) {
return heads[u];
}
public Edge getEdge(final int id) {
return edges[id];
}
public int nextEdge(final int id) {
return edges[id].next;
}
public int addEdge(final int from, final int to, final int vol, final int cost) {
Edge edge = new Edge();
edge.from = from;
edge.to = to;
edge.vol = vol;
edge.cost = cost;
edge.next = heads[from];
edges[++cnt] = edge;
heads[from] = cnt;
return cnt;
}
}
static class Edge {
public int from;
public int to;
public int next;
public int vol;
public int cost;
}
static class FastWriter {
private final PrintWriter writer;
public FastWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream), 8192));
}
public FastWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void println(int x) {
writer.println(x);
}
public void flush() {
writer.flush();
}
public void close() {
writer.flush();
try {
writer.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
|
Java
|
["5\n\n5 1\n\n1 1 2 2\n\n5 2\n\n1 1 2 2\n\n6 0\n\n1 2 3 4 5\n\n6 1\n\n1 2 3 4 5\n\n4 3\n\n1 1 1"]
|
4 seconds
|
["2\n1\n5\n3\n1"]
| null |
Java 8
|
standard input
|
[
"binary search",
"data structures",
"dfs and similar",
"graphs",
"greedy",
"trees"
] |
f260d0885319a146904b43f89e253f0c
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of testcases. The first line of each testcase contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 2 \cdot 10^5$$$; $$$0 \le k \le n - 1$$$) — the number of vertices in the tree and the maximum number of operations you can perform. The second line contains $$$n-1$$$ integers $$$p_2, p_3, \dots, p_n$$$ ($$$1 \le p_i < i$$$) — the parent of the $$$i$$$-th vertex. Vertex $$$1$$$ is the root. The sum of $$$n$$$ over all testcases doesn't exceed $$$2 \cdot 10^5$$$.
| 1,900
|
For each testcase, print a single integer — the smallest height of the tree that can achieved by performing at most $$$k$$$ operations.
|
standard output
| |
PASSED
|
73d4a363dd39e45bc76b1d220e65d03c
|
train_109.jsonl
|
1664462100
|
You are given a rooted tree, consisting of $$$n$$$ vertices. The vertices are numbered from $$$1$$$ to $$$n$$$, the root is the vertex $$$1$$$.You can perform the following operation at most $$$k$$$ times: choose an edge $$$(v, u)$$$ of the tree such that $$$v$$$ is a parent of $$$u$$$; remove the edge $$$(v, u)$$$; add an edge $$$(1, u)$$$ (i. e. make $$$u$$$ with its subtree a child of the root). The height of a tree is the maximum depth of its vertices, and the depth of a vertex is the number of edges on the path from the root to it. For example, the depth of vertex $$$1$$$ is $$$0$$$, since it's the root, and the depth of all its children is $$$1$$$.What's the smallest height of the tree that can be achieved?
|
256 megabytes
|
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.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 tauros
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
RealFastReader in = new RealFastReader(inputStream);
FastWriter out = new FastWriter(outputStream);
CF1739D solver = new CF1739D();
solver.solve(1, in, out);
out.close();
}
static class CF1739D {
public void solve(int testNumber, RealFastReader in, FastWriter out) {
int cases = in.ni();
for (int number = 1; number <= cases; number++) {
int n = in.ni(), k = in.ni();
Graph graph = new GraphArr(n + 1, n);
for (int i = 2; i <= n; i++) {
int parent = in.ni();
graph.addEdge(parent, i);
}
int l = 1, r = n - 1;
while (l < r) {
int[] cnt = new int[]{ 0 };
int mid = l + r >> 1;
dfs(1, 0, graph, cnt, mid);
if (cnt[0] <= k) {
r = mid;
} else {
l = mid + 1;
}
}
out.println(l);
}
out.flush();
}
private int dfs(int u, int fa, Graph graph, int[] cnt, int maxHeight) {
int height = 0;
for (int e = graph.firstEdge(u); e != 0; e = graph.nextEdge(e)) {
int v = graph.getEdge(e).to;
int chdHeight = dfs(v, u, graph, cnt, maxHeight);
height = Math.max(height, chdHeight + 1);
}
if (u != 1 && fa != 1 && height >= maxHeight - 1) {
cnt[0]++;
return -1;
}
return height;
}
}
static class RealFastReader {
InputStream is;
private byte[] inbuf = new byte[8192];
public int lenbuf = 0;
public int ptrbuf = 0;
public RealFastReader(final InputStream is) {
this.is = is;
}
public 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++];
}
public int ni() {
int 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();
}
}
}
static interface Graph {
int firstEdge(int u);
Edge getEdge(int id);
int nextEdge(int id);
default int addEdge(int from, int to) {
return addEdge(from, to, 0, 0);
}
int addEdge(int from, int to, int vol, int cost);
}
static class GraphArr implements Graph {
private final int MAXN;
private int[] heads;
private Edge[] edges;
private int cnt;
public GraphArr(final int MAXN) {
this(MAXN, 2 * MAXN);
}
public GraphArr(final int MAXN, final int MAXE) {
this.MAXN = MAXN;
this.cnt = 1;
this.heads = new int[this.MAXN];
this.edges = new Edge[MAXE + 2];
}
public int firstEdge(final int u) {
return heads[u];
}
public Edge getEdge(final int id) {
return edges[id];
}
public int nextEdge(final int id) {
return edges[id].next;
}
public int addEdge(final int from, final int to, final int vol, final int cost) {
Edge edge = new Edge();
edge.from = from;
edge.to = to;
edge.vol = vol;
edge.cost = cost;
edge.next = heads[from];
edges[++cnt] = edge;
heads[from] = cnt;
return cnt;
}
}
static class Edge {
public int from;
public int to;
public int next;
public int vol;
public int cost;
}
static class FastWriter {
private final PrintWriter writer;
public FastWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream), 8192));
}
public FastWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void println(int x) {
writer.println(x);
}
public void flush() {
writer.flush();
}
public void close() {
writer.flush();
try {
writer.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
|
Java
|
["5\n\n5 1\n\n1 1 2 2\n\n5 2\n\n1 1 2 2\n\n6 0\n\n1 2 3 4 5\n\n6 1\n\n1 2 3 4 5\n\n4 3\n\n1 1 1"]
|
4 seconds
|
["2\n1\n5\n3\n1"]
| null |
Java 8
|
standard input
|
[
"binary search",
"data structures",
"dfs and similar",
"graphs",
"greedy",
"trees"
] |
f260d0885319a146904b43f89e253f0c
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of testcases. The first line of each testcase contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 2 \cdot 10^5$$$; $$$0 \le k \le n - 1$$$) — the number of vertices in the tree and the maximum number of operations you can perform. The second line contains $$$n-1$$$ integers $$$p_2, p_3, \dots, p_n$$$ ($$$1 \le p_i < i$$$) — the parent of the $$$i$$$-th vertex. Vertex $$$1$$$ is the root. The sum of $$$n$$$ over all testcases doesn't exceed $$$2 \cdot 10^5$$$.
| 1,900
|
For each testcase, print a single integer — the smallest height of the tree that can achieved by performing at most $$$k$$$ operations.
|
standard output
| |
PASSED
|
6ef40112dd1bbd6ee05057fd7928386e
|
train_109.jsonl
|
1664462100
|
You are given a rooted tree, consisting of $$$n$$$ vertices. The vertices are numbered from $$$1$$$ to $$$n$$$, the root is the vertex $$$1$$$.You can perform the following operation at most $$$k$$$ times: choose an edge $$$(v, u)$$$ of the tree such that $$$v$$$ is a parent of $$$u$$$; remove the edge $$$(v, u)$$$; add an edge $$$(1, u)$$$ (i. e. make $$$u$$$ with its subtree a child of the root). The height of a tree is the maximum depth of its vertices, and the depth of a vertex is the number of edges on the path from the root to it. For example, the depth of vertex $$$1$$$ is $$$0$$$, since it's the root, and the depth of all its children is $$$1$$$.What's the smallest height of the tree that can be achieved?
|
256 megabytes
|
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.function.Function;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author tauros
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
RealFastReader in = new RealFastReader(inputStream);
FastWriter out = new FastWriter(outputStream);
CF1739D solver = new CF1739D();
solver.solve(1, in, out);
out.close();
}
static class CF1739D {
public void solve(int testNumber, RealFastReader in, FastWriter out) {
int cases = in.ni();
for (int number = 1; number <= cases; number++) {
int n = in.ni(), k = in.ni();
Graph graph = new GraphArr(n + 1, n);
for (int i = 2; i <= n; i++) {
int parent = in.ni();
graph.addEdge(parent, i);
}
int ans = Common.findFirst(n - 2, x -> {
int height = x + 1;
int[] cnt = new int[]{ 0 };
dfs(1, 0, graph, cnt, height);
return cnt[0] <= k;
}) + 1;
out.println(ans);
}
out.flush();
}
private int dfs(int u, int fa, Graph graph, int[] cnt, int maxHeight) {
int height = 0;
for (int e = graph.firstEdge(u); e != 0; e = graph.nextEdge(e)) {
int v = graph.getEdge(e).to;
int chdHeight = dfs(v, u, graph, cnt, maxHeight);
height = Math.max(height, chdHeight + 1);
}
if (u != 1 && fa != 1 && height >= maxHeight - 1) {
cnt[0]++;
return -1;
}
return height;
}
}
static class RealFastReader {
InputStream is;
private byte[] inbuf = new byte[8192];
public int lenbuf = 0;
public int ptrbuf = 0;
public RealFastReader(final InputStream is) {
this.is = is;
}
public 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++];
}
public int ni() {
int 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();
}
}
}
static interface Graph {
int firstEdge(int u);
Edge getEdge(int id);
int nextEdge(int id);
default int addEdge(int from, int to) {
return addEdge(from, to, 0, 0);
}
int addEdge(int from, int to, int vol, int cost);
}
static class GraphArr implements Graph {
private final int MAXN;
private int[] heads;
private Edge[] edges;
private int cnt;
public GraphArr(final int MAXN) {
this(MAXN, 2 * MAXN);
}
public GraphArr(final int MAXN, final int MAXE) {
this.MAXN = MAXN;
this.cnt = 1;
this.heads = new int[this.MAXN];
this.edges = new Edge[MAXE + 2];
}
public int firstEdge(final int u) {
return heads[u];
}
public Edge getEdge(final int id) {
return edges[id];
}
public int nextEdge(final int id) {
return edges[id].next;
}
public int addEdge(final int from, final int to, final int vol, final int cost) {
Edge edge = new Edge();
edge.from = from;
edge.to = to;
edge.vol = vol;
edge.cost = cost;
edge.next = heads[from];
edges[++cnt] = edge;
heads[from] = cnt;
return cnt;
}
}
static class Edge {
public int from;
public int to;
public int next;
public int vol;
public int cost;
}
static final class Common {
public static int findFirst(int n, Function<Integer, Boolean> judge) {
int l = 0, r = n;
while (l < r) {
int mid = l + ((r - l) >> 1);
Boolean result = judge.apply(mid);
if (result != null && result) {
r = mid;
} else {
l = mid + 1;
}
}
return l;
}
}
static class FastWriter {
private final PrintWriter writer;
public FastWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream), 8192));
}
public FastWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void println(int x) {
writer.println(x);
}
public void flush() {
writer.flush();
}
public void close() {
writer.flush();
try {
writer.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
|
Java
|
["5\n\n5 1\n\n1 1 2 2\n\n5 2\n\n1 1 2 2\n\n6 0\n\n1 2 3 4 5\n\n6 1\n\n1 2 3 4 5\n\n4 3\n\n1 1 1"]
|
4 seconds
|
["2\n1\n5\n3\n1"]
| null |
Java 8
|
standard input
|
[
"binary search",
"data structures",
"dfs and similar",
"graphs",
"greedy",
"trees"
] |
f260d0885319a146904b43f89e253f0c
|
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of testcases. The first line of each testcase contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 2 \cdot 10^5$$$; $$$0 \le k \le n - 1$$$) — the number of vertices in the tree and the maximum number of operations you can perform. The second line contains $$$n-1$$$ integers $$$p_2, p_3, \dots, p_n$$$ ($$$1 \le p_i < i$$$) — the parent of the $$$i$$$-th vertex. Vertex $$$1$$$ is the root. The sum of $$$n$$$ over all testcases doesn't exceed $$$2 \cdot 10^5$$$.
| 1,900
|
For each testcase, print a single integer — the smallest height of the tree that can achieved by performing at most $$$k$$$ operations.
|
standard output
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.