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 | a7f6c72965333010a9b182de348c12a9 | train_003.jsonl | 1499791500 | Polycarp has a checkered sheet of paper of size nβΓβm. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length. | 256 megabytes | import java.util.*;
import java.awt.*;
public class p828B {
public static void main(String args[]){
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int m = in.nextInt();
char[][] arr = new char[n][m];
int totalB = 0;
int minX = 101;
int maxX = -1;
int minY = 101;
int maxY = -1;
for(int y = 0; y < n; y++){
String s = in.next();
for(int x = 0; x < m; x++){
char letter = s.charAt(x);
arr[y][x] = letter;
if(letter=='B'){
totalB++;
if(y>maxX){
maxX = y;
}
if(y<minX){
minX = y;
}
if(x>maxY){
maxY = x;
}
if(x<minY){
minY = x;
}
}
}
}
/*
ArrayList<Point> X = new ArrayList<>();
for(int x = 0; x < n; x++){
for(int y = 0; y < m; y++){
if(arr[x][y] == 'B'){
Point point = new Point(x, y);
X.add(point);
System.out.println(point);
}
}
}
ArrayList<Point> Y = new ArrayList<>();
for(int y = 0; y < m; y++){
for(int x = 0; x < n; x++){
if(arr[x][y]=='B'){
Point point = new Point(x, y);
Y.add(point);
System.out.println(point);
}
}
}
*/
if(totalB==0){
System.out.println(1);
System.exit(0);
}
/*
int topY = Y.get(0).y;
int bottomY = Y.get(Y.size()-1).y;
int topX = X.get(0).x;
int bottomX = Y.get(X.size()-1).x;
int yLength = bottomY-topY +1;
int xLength = bottomX-topX +1;
*/
int xLength = maxX-minX+1;
int yLength = maxY-minY+1;
int longest = 0;
if(yLength>xLength){
longest = yLength;
} else {
longest = xLength;
}
if(longest>n||longest>m){
System.out.println(-1);
System.exit(0);
}
System.out.println(longest*longest-totalB);
}
}
| Java | ["5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW", "1 2\nBB", "3 3\nWWW\nWWW\nWWW"] | 1 second | ["5", "-1", "1"] | NoteIn the first example it is needed to paint 5 cells β (2,β2), (2,β3), (3,β2), (3,β3) and (4,β2). Then there will be a square with side equal to three, and the upper left corner in (2,β2).In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.In the third example all cells are colored white, so it's sufficient to color any cell black. | Java 8 | standard input | [
"implementation"
] | cd6bc23ea61c43b38c537f9e04ad11a6 | The first line contains two integers n and m (1ββ€βn,βmββ€β100) β the sizes of the sheet. The next n lines contain m letters 'B' or 'W' each β the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white. | 1,300 | Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1. | standard output | |
PASSED | 221b2aee8229a3c4f569f6893fdd289e | train_003.jsonl | 1499791500 | Polycarp has a checkered sheet of paper of size nβΓβm. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskB solver = new TaskB();
solver.solve(1, in, out);
out.close();
}
static class TaskB {
public void solve(int testNumber, Scanner in, PrintWriter out) {
int n = in.nextInt();
int m = in.nextInt();
int tot = n * m;
boolean[][] arr = new boolean[n][m];
int tr = -1, br = -1, lc = -1, rc = -1;
for (int i = -0; i < n; i++) {
String s = in.next();
for (int j = 0; j < m; j++) {
if (s.charAt(j) == 'W') {
arr[i][j] = false;
} else {
arr[i][j] = true;
if (tr == -1) {
tr = i;
}
if (lc == -1) {
lc = j;
}
if (j < lc) {
lc = j;
}
br = i;
if (rc == -1) {
rc = j;
}
if (j > rc) {
rc = j;
}
}
}
}
//out.println(tr+" "+br+" "+lc+" "+rc);
int rs = br - tr + 1;
int cs = rc - lc + 1;
if (tr == -1) {
out.println("1");
return;
}
int diff = rs - cs;
if (diff > 0) {
if (lc >= diff) {
lc = lc - diff;
} else {
if ((m - 1 - rc) >= (diff - lc)) {
rc = rc + diff - lc;
lc = 0;
} else {
out.println("-1");
return;
}
}
} else {
if (diff < 0) {
diff = Math.abs(diff);
if (tr >= diff) {
tr = tr - diff;
} else {
if ((n - 1 - br) >= (diff - tr)) {
br = br + diff - tr;
tr = 0;
} else {
out.println("-1");
return;
}
}
}
}
//out.println(tr+" "+br+" "+lc+" "+rc);
int ans = 0;
for (int i = tr; i <= br; i++) {
for (int j = lc; j <= rc; j++) {
if (arr[i][j] == false) {
ans++;
}
}
}
out.println(ans);
}
}
}
| Java | ["5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW", "1 2\nBB", "3 3\nWWW\nWWW\nWWW"] | 1 second | ["5", "-1", "1"] | NoteIn the first example it is needed to paint 5 cells β (2,β2), (2,β3), (3,β2), (3,β3) and (4,β2). Then there will be a square with side equal to three, and the upper left corner in (2,β2).In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.In the third example all cells are colored white, so it's sufficient to color any cell black. | Java 8 | standard input | [
"implementation"
] | cd6bc23ea61c43b38c537f9e04ad11a6 | The first line contains two integers n and m (1ββ€βn,βmββ€β100) β the sizes of the sheet. The next n lines contain m letters 'B' or 'W' each β the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white. | 1,300 | Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1. | standard output | |
PASSED | 7c3e775b4a494e826986e877282cebac | train_003.jsonl | 1499791500 | Polycarp has a checkered sheet of paper of size nβΓβm. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String args[]){
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int m = input.nextInt();
char[][] map = new char[n][m];
for(int i=0; i<n; i++){
map[i] = input.next().toCharArray();
}
blackSq(map);
input.close();
}
public static int countBs(char[][] map, int top, int bottom, int left, int right){
int cnt = 0;
for(int i=top; i<=bottom; i++){
for(int j=left; j<=right; j++){
if(map[i][j] == 'B'){
cnt++;
}
}
}
return cnt;
}
public static void blackSq(char[][] map){
int mostLeft = Integer.MAX_VALUE;
int mostRight = - 1;
int mostTop = Integer.MAX_VALUE;
int mostBottom = -1;
for(int i=0; i<map.length; i++){
for(int j=0; j<map[i].length; j++){
if(map[i][j] == 'B'){
mostLeft = Math.min(mostLeft, j);
mostRight = Math.max(mostRight, j);
mostTop = Math.min(mostTop, i);
mostBottom = Math.max(mostBottom, i);
}
}
}
if(mostLeft == Integer.MAX_VALUE && mostRight == -1 && mostTop == Integer.MAX_VALUE && mostBottom == -1){
System.out.println(1);
} else {
int n = map.length;
int m = map[0].length;
int minSqSize = Math.max(mostBottom - mostTop, mostRight - mostLeft) + 1;
int totalBs = countBs(map, 0, n-1, 0, m-1);
if(n - mostTop >= minSqSize && m - mostLeft >= minSqSize){
if(totalBs == countBs(map, mostTop, mostTop + minSqSize - 1, mostLeft, mostLeft + minSqSize - 1)){
System.out.println(minSqSize*minSqSize - totalBs);
return;
}
}
if (n - mostTop >= minSqSize && mostRight + 1 >= minSqSize){
if(totalBs == countBs(map, mostTop, mostTop + minSqSize - 1, mostRight - minSqSize + 1, mostRight)){
System.out.println(minSqSize*minSqSize - totalBs);
return;
}
}
if (mostBottom + 1 >= minSqSize && m - mostLeft >= minSqSize){
if(totalBs == countBs(map, mostBottom - minSqSize + 1, mostBottom, mostLeft, mostLeft + minSqSize - 1)){
System.out.println(minSqSize*minSqSize - totalBs);
return;
}
}
if (mostBottom + 1 >= minSqSize && mostRight + 1 >= minSqSize){
if(totalBs == countBs(map, mostBottom - minSqSize + 1, mostBottom, mostRight - minSqSize + 1, mostRight)){
System.out.println(minSqSize*minSqSize - totalBs);
return;
}
}
if(Math.min(m, n) >= minSqSize){
System.out.println(minSqSize*minSqSize - totalBs);
return;
}
System.out.println(-1);
}
}
}
| Java | ["5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW", "1 2\nBB", "3 3\nWWW\nWWW\nWWW"] | 1 second | ["5", "-1", "1"] | NoteIn the first example it is needed to paint 5 cells β (2,β2), (2,β3), (3,β2), (3,β3) and (4,β2). Then there will be a square with side equal to three, and the upper left corner in (2,β2).In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.In the third example all cells are colored white, so it's sufficient to color any cell black. | Java 8 | standard input | [
"implementation"
] | cd6bc23ea61c43b38c537f9e04ad11a6 | The first line contains two integers n and m (1ββ€βn,βmββ€β100) β the sizes of the sheet. The next n lines contain m letters 'B' or 'W' each β the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white. | 1,300 | Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1. | standard output | |
PASSED | 578b0673b8d787388891ef29f4cea260 | train_003.jsonl | 1499791500 | Polycarp has a checkered sheet of paper of size nβΓβm. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
FastScanner sc = new FastScanner();
PrintWriter pw = new PrintWriter(System.out);
while (sc.hasNext()) {
int n=sc.nextInt();
int m=sc.nextInt();
int[][]maze=new int[n][m];
int up=9999;
int down=-1;
int left=9999;
int right=-1;
int count=0;
for(int i=0;i<n;i++){
String s=sc.next();
for(int j=0;j<m;j++){
if(s.charAt(j)=='W')
maze[i][j]=0;
else{
maze[i][j]=1;
count++;
if(i<up)up=i;
if(i>down)down=i;
if(j<left)left=j;
if(j>right)right=j;
}
}
}
if(count==0)pw.println(1);
else if(count==1){
pw.println(0);
}else{
int len1=(right-left+1);
int len2=(down-up+1);
int len=Math.max(len1, len2);
if(n>=len&&m>=len){
pw.println(len*len-count);
}else{
pw.println(-1);
}
}
pw.flush();
}
}
}
class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner() {
try {
br = new BufferedReader(new InputStreamReader(System.in));
st = new StringTokenizer("");
} catch (Exception e) {
e.printStackTrace();
}
}
public boolean hasNext() {
while (!st.hasMoreTokens()) {
String line = nextLine();
if (line == null) {
return false;
}
st = new StringTokenizer(line);
}
return true;
}
public String next() {
while(!st.hasMoreTokens()){
st=new StringTokenizer(nextLine());
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String nextLine() {
String line = "";
try {
line = br.readLine();
} catch (Exception e) {
e.printStackTrace();
}
return line;
}
} | Java | ["5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW", "1 2\nBB", "3 3\nWWW\nWWW\nWWW"] | 1 second | ["5", "-1", "1"] | NoteIn the first example it is needed to paint 5 cells β (2,β2), (2,β3), (3,β2), (3,β3) and (4,β2). Then there will be a square with side equal to three, and the upper left corner in (2,β2).In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.In the third example all cells are colored white, so it's sufficient to color any cell black. | Java 8 | standard input | [
"implementation"
] | cd6bc23ea61c43b38c537f9e04ad11a6 | The first line contains two integers n and m (1ββ€βn,βmββ€β100) β the sizes of the sheet. The next n lines contain m letters 'B' or 'W' each β the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white. | 1,300 | Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1. | standard output | |
PASSED | 3185ced382dbf0f05caa8f3110446be2 | train_003.jsonl | 1499791500 | Polycarp has a checkered sheet of paper of size nβΓβm. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length. | 256 megabytes | import java.io.*;
import java.util.*;
public class CF828B
{
public static void main(String[] args)throws IOException
{
BufferedReader bs=new BufferedReader(new InputStreamReader(System.in));
String[] t1=bs.readLine().split(" ");
int n=Integer.parseInt(t1[0]);
int m=Integer.parseInt(t1[1]);
char[][] bo=new char[n][m];
for(int i=0;i<n;i++)
{
String t2=bs.readLine();
bo[i]=t2.toCharArray();
}
int wc=0;
int bc=0;
for(int j=0;j<n;j++)
{
for(int k=0;k<m;k++)
{
if(bo[j][k]=='W')
{
wc++;
}
else if(bo[j][k]=='B')
{
bc++;
}
}
}
if(bc==0)
{
System.out.println(1);
}
else if(wc==0&&n==m)
{
System.out.println(0);
}
else if(wc==0&&n!=m)
{
System.out.println(-1);
}
else
{
int bt=-1;
int bb=-1;
int bl=-1;
int br=-1;
for(int j=0;j<n;j++)
{
for(int k=0;k<m;k++)
{
if(bo[j][k]=='B')
{
bb=j;
break;
}
}
}
for(int j=n-1;j>=0;j--)
{
for(int k=m-1;k>=0;k--)
{
if(bo[j][k]=='B')
{
bt=j;
break;
}
}
}
for(int j=0;j<m;j++)
{
for(int k=0;k<n;k++)
{
if(bo[k][j]=='B')
{
br=j;
break;
}
}
}
for(int j=m-1;j>=0;j--)
{
for(int k=n-1;k>=0;k--)
{
if(bo[k][j]=='B')
{
bl=j;
break;
}
}
}
int lh=br-bl+1;
int lv=bb-bt+1;
if(lh==lv)
{
System.out.println(Math.abs((lh*lh)-bc));
}
else if(lh>lv)
{
if(n<lh)
{
System.out.println(-1);
}
else if(n>=lh)
{
System.out.println(Math.abs((lh*lh)-bc));
}
}
else if(lv>lh)
{
if(m<lv)
{
System.out.println(-1);
}
else if(m>=lv)
{
System.out.println(Math.abs((lv*lv)-bc));
}
}
}
}
} | Java | ["5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW", "1 2\nBB", "3 3\nWWW\nWWW\nWWW"] | 1 second | ["5", "-1", "1"] | NoteIn the first example it is needed to paint 5 cells β (2,β2), (2,β3), (3,β2), (3,β3) and (4,β2). Then there will be a square with side equal to three, and the upper left corner in (2,β2).In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.In the third example all cells are colored white, so it's sufficient to color any cell black. | Java 8 | standard input | [
"implementation"
] | cd6bc23ea61c43b38c537f9e04ad11a6 | The first line contains two integers n and m (1ββ€βn,βmββ€β100) β the sizes of the sheet. The next n lines contain m letters 'B' or 'W' each β the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white. | 1,300 | Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1. | standard output | |
PASSED | 07a1bd32f2444ffdf74f688eec6d62ff | train_003.jsonl | 1499791500 | Polycarp has a checkered sheet of paper of size nβΓβm. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length. | 256 megabytes |
/**
* @author: Mehul Raheja
*/
import java.util.*;
import java.io.*;
import static java.lang.Math.*;
public class B{
/*
Runtime = O()
*/
static int N, M, K;
static String s;
static StringTokenizer st;
static int[] d;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
int[][] c = new int[N][M];
int mX = 101;
int MX = -1;
int mY = 101;
int MY = -1;
for (int i = 0; i < N; i++) {
s =br.readLine();
for (int j = 0; j < M; j++) {
c[i][j] = (s.charAt(j) == 'B')?1:0;
if(s.charAt(j) == 'B'){
mX = min(mX,i);
MX = max(MX,i);
mY = min(mY,j);
MY = max(MY,j);
}
}
}
int dist = max(MX-mX+1,MY-mY+1);
if(dist > min(N,M)){
System.out.println(-1);
System.exit(0);
}
if(mX == 101){
System.out.println(1);
System.exit(0);
}
int w = 0;
for (int i = max(0,MX - dist + 1); i <= mX; i++) {
for (int j = max(0,MY-dist + 1); j <= mY; j++) {
int tw = 0;
if(i + dist <= c.length && j + dist <= c[0].length){
for (int k = i; k < i + dist; k++) {
for (int l =j ; l < j + dist; l++) {
tw += c[k][l]^1;
}
}
}
w = max(tw,w);
}
}
System.out.println(w);
}
}
| Java | ["5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW", "1 2\nBB", "3 3\nWWW\nWWW\nWWW"] | 1 second | ["5", "-1", "1"] | NoteIn the first example it is needed to paint 5 cells β (2,β2), (2,β3), (3,β2), (3,β3) and (4,β2). Then there will be a square with side equal to three, and the upper left corner in (2,β2).In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.In the third example all cells are colored white, so it's sufficient to color any cell black. | Java 8 | standard input | [
"implementation"
] | cd6bc23ea61c43b38c537f9e04ad11a6 | The first line contains two integers n and m (1ββ€βn,βmββ€β100) β the sizes of the sheet. The next n lines contain m letters 'B' or 'W' each β the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white. | 1,300 | Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1. | standard output | |
PASSED | 963a7c8718abe32b5f3a3b7e35880f02 | train_003.jsonl | 1499791500 | Polycarp has a checkered sheet of paper of size nβΓβm. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length. | 256 megabytes | import java.util.Scanner;
public class BlackSquare2 {
public static void main(String[] args) {
Scanner draw = new Scanner(System.in);
int n = draw.nextInt();
int m = draw.nextInt();
String str[] = new String[n];
for (int i = 0; i < n; i++)
str
[i] = draw.next();
int m1 = 200 , m2 = -1 ;
int m3 = 200 , m4 = -1 ;
int count = 0 ;
for (int i = 0; i < n; i++){
for (int j = 0 ; j < m ; j++)
if (str[i].charAt(j) == 'B'){
if (i + 1 < m1) m1 = i + 1;
if (m2 < i + 1) m2 = i + 1;
if (j + 1 < m3) m3 = j + 1;
if (m4 < j + 1) m4 = j + 1;
} else {
count++;
}
}
if(count == n*m){
System.out.println(1);
} else if (count == 0){
if (n == m)
System.out.println(0);
else
System.out.println(-1);
} else {
int ans1 = m2 - m1 + 1;
int ans2 = m4 - m3 + 1;
if (ans1 > ans2){
int answer = 0;
if (m >= ans1){
for (int i = m1-1 ; i < m2 ; i++)
for (int j = m3-1; j < m4 ; j++)
if (str[i].charAt(j) == 'W')
answer++;
answer += ((ans1 - ans2)*ans1);
System.out.println(answer);
} else {
System.out.println(-1);
}
} else if (ans1 == ans2){
int answer = 0;
for (int i = m1 - 1 ; i < m2; i++)
for (int j = m3 - 1; j < m4; j++)
if (str[i].charAt(j) == 'W')
answer++;
System.out.println(answer);
} else {
if (n >= ans2){
int answer = 0;
for (int i = m1 - 1; i < m2 ; i++)
for (int j = m3-1; j < m4 ; j++)
if (str[i].charAt(j) == 'W')
answer++;
answer += ((ans2 - ans1) * ans2);
System.out.println(answer);
} else {
System.out.println(-1);
}
}
}
}
} //end of BlackSquare2 class | Java | ["5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW", "1 2\nBB", "3 3\nWWW\nWWW\nWWW"] | 1 second | ["5", "-1", "1"] | NoteIn the first example it is needed to paint 5 cells β (2,β2), (2,β3), (3,β2), (3,β3) and (4,β2). Then there will be a square with side equal to three, and the upper left corner in (2,β2).In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.In the third example all cells are colored white, so it's sufficient to color any cell black. | Java 8 | standard input | [
"implementation"
] | cd6bc23ea61c43b38c537f9e04ad11a6 | The first line contains two integers n and m (1ββ€βn,βmββ€β100) β the sizes of the sheet. The next n lines contain m letters 'B' or 'W' each β the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white. | 1,300 | Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1. | standard output | |
PASSED | 1989a6a0e1832b2d4c0a96fb6704922f | train_003.jsonl | 1499791500 | Polycarp has a checkered sheet of paper of size nβΓβm. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length. | 256 megabytes | import java.io.*;
import java.util.*;
public class BlackSquare {
static int check(String[][] s, int width, int length) {
int area = width*length;
int size = Math.min(length, width);
int left = Integer.MAX_VALUE;
int right = 0;
int up = Integer.MAX_VALUE;
int down = 0;
int blackcount = 0;
for (int i = 0; i < width; i++) {
for (int j = 0; j < length; j++) {
if (s[i][j].equals("B")) {
blackcount++;
if (i < left) {
left = i;
}
if (i > right) {
right = i;
}
if (j < up) {
up = j;
}
if (j > down) {
down = j;
}
}
}
} //end of for loop
int max = Math.max(down - up + 1, right - left + 1);
if (max > size) {
return -1;
}
if (blackcount == 0) {
return 1;
}
return max*max - blackcount;
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int width = scan.nextInt();
int length = scan.nextInt();
scan.nextLine();
String[][] s = new String[width][length];
for (int i = 0; i < width; i++) {
String[] str = scan.nextLine().split("");
for (int j = 0; j < length; j++) {
s[i][j] = str[j];
}
}
System.out.println(check(s, width, length));
}
} //end of BlackSquare class | Java | ["5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW", "1 2\nBB", "3 3\nWWW\nWWW\nWWW"] | 1 second | ["5", "-1", "1"] | NoteIn the first example it is needed to paint 5 cells β (2,β2), (2,β3), (3,β2), (3,β3) and (4,β2). Then there will be a square with side equal to three, and the upper left corner in (2,β2).In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.In the third example all cells are colored white, so it's sufficient to color any cell black. | Java 8 | standard input | [
"implementation"
] | cd6bc23ea61c43b38c537f9e04ad11a6 | The first line contains two integers n and m (1ββ€βn,βmββ€β100) β the sizes of the sheet. The next n lines contain m letters 'B' or 'W' each β the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white. | 1,300 | Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1. | standard output | |
PASSED | 0300023d5dd9c98d641239d1df3ba99e | train_003.jsonl | 1499791500 | Polycarp has a checkered sheet of paper of size nβΓβm. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Ex828 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String firstLine = br.readLine();
String[] splitedFirstLine = firstLine.split(" ");
int n = Integer.parseInt(splitedFirstLine[0]);
int m = Integer.parseInt(splitedFirstLine[1]);
String[] paper = new String[n];
for (int i = 0; i < n; i++) {
paper[i] = br.readLine();
}
System.out.println(minToSquare(n, m, paper));
}
static int minToSquare(int v, int h, String[] paper) {
int minX = h;
int maxX = 0;
int minY = v;
int maxY = 0;
int countB = 0;
for (int n = 0; n < v; n++) {
for (int m = 0; m < h; m++) {
if (paper[n].charAt(m) == 'B') {
countB++;
maxY = Math.max(n, maxY);
maxX = Math.max(m, maxX);
minY = Math.min(n, minY);
minX = Math.min(m, minX);
}
}
}
if (countB == 0) return 1;
int vSize = maxY - minY + 1;
int hSize = maxX - minX + 1;
if (vSize == hSize) {
return vSize * hSize - countB;
} else if (vSize > hSize) {
if (vSize <= h) {
return vSize * vSize - countB;
} else {
return -1;
}
} else {
if (hSize <= v) {
return hSize * hSize - countB;
} else {
return -1;
}
}
}
}
| Java | ["5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW", "1 2\nBB", "3 3\nWWW\nWWW\nWWW"] | 1 second | ["5", "-1", "1"] | NoteIn the first example it is needed to paint 5 cells β (2,β2), (2,β3), (3,β2), (3,β3) and (4,β2). Then there will be a square with side equal to three, and the upper left corner in (2,β2).In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.In the third example all cells are colored white, so it's sufficient to color any cell black. | Java 8 | standard input | [
"implementation"
] | cd6bc23ea61c43b38c537f9e04ad11a6 | The first line contains two integers n and m (1ββ€βn,βmββ€β100) β the sizes of the sheet. The next n lines contain m letters 'B' or 'W' each β the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white. | 1,300 | Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1. | standard output | |
PASSED | 66c476af772d95bbd6a3f0382238cab1 | train_003.jsonl | 1499791500 | Polycarp has a checkered sheet of paper of size nβΓβm. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] firstLineA = br.readLine().trim().split(" ");
int n = Integer.parseInt(firstLineA[0]);
int m = Integer.parseInt(firstLineA[1]);
char[][] matrix = new char[n][m];
for(int i=0; i<n; i++) {
String line = br.readLine().trim();
for(int j=0; j<m; j++) {
matrix[i][j] = line.charAt(j);
}
}
int minX = n-1;
int maxX = 0;
int minY = m-1;
int maxY = 0;
boolean found = false;
for(int i=0; i<n; i++) {
for (int j=0; j<m; j++) {
if(matrix[i][j] == 'B') {
if(minX > i)
minX = i;
if(minY > j)
minY = j;
if(maxX < i)
maxX = i;
if(maxY < j)
maxY = j;
found = true;
}
}
}
if(!found)
System.out.println(1);
else {
int maxLength = Math.max((maxX-minX+1), (maxY-minY+1));
if(maxLength > n || maxLength > m) {
System.out.println(-1);
}
else {
if(maxLength > (maxX-minX+1)) {
int reqDiff = maxLength - (maxX-minX+1);
if(minX != 0) {
if(minX < reqDiff) {
reqDiff -= minX;
minX = 0;
}
else {
minX -= reqDiff;
reqDiff = 0;
}
}
if(reqDiff > 0)
maxX += reqDiff;
}
else {
int reqDiff = maxLength - (maxY-minY+1);
if(minY != 0) {
if(minY < reqDiff) {
reqDiff -= minY;
minY = 0;
}
else {
minY -= reqDiff;
reqDiff = 0;
}
}
if(reqDiff > 0)
maxY += reqDiff;
}
int count = 0;
for(int i=minX; i<=maxX; i++) {
for(int j=minY; j<=maxY; j++) {
if(matrix[i][j] == 'W')
count++;
}
}
System.out.println(count);
}
}
}
}
| Java | ["5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW", "1 2\nBB", "3 3\nWWW\nWWW\nWWW"] | 1 second | ["5", "-1", "1"] | NoteIn the first example it is needed to paint 5 cells β (2,β2), (2,β3), (3,β2), (3,β3) and (4,β2). Then there will be a square with side equal to three, and the upper left corner in (2,β2).In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.In the third example all cells are colored white, so it's sufficient to color any cell black. | Java 8 | standard input | [
"implementation"
] | cd6bc23ea61c43b38c537f9e04ad11a6 | The first line contains two integers n and m (1ββ€βn,βmββ€β100) β the sizes of the sheet. The next n lines contain m letters 'B' or 'W' each β the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white. | 1,300 | Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1. | standard output | |
PASSED | d1d60cf71b10eed67ec6d963eb8cc992 | train_003.jsonl | 1394465400 | Sereja is a coder and he likes to take part in Codesorfes rounds. However, Uzhland doesn't have good internet connection, so Sereja sometimes skips rounds.Codesorfes has rounds of two types: Div1 (for advanced coders) and Div2 (for beginner coders). Two rounds, Div1 and Div2, can go simultaneously, (Div1 round cannot be held without Div2) in all other cases the rounds don't overlap in time. Each round has a unique identifier β a positive integer. The rounds are sequentially (without gaps) numbered with identifiers by the starting time of the round. The identifiers of rounds that are run simultaneously are different by one, also the identifier of the Div1 round is always greater.Sereja is a beginner coder, so he can take part only in rounds of Div2 type. At the moment he is taking part in a Div2 round, its identifier equals to x. Sereja remembers very well that he has taken part in exactly k rounds before this round. Also, he remembers all identifiers of the rounds he has taken part in and all identifiers of the rounds that went simultaneously with them. Sereja doesn't remember anything about the rounds he missed.Sereja is wondering: what minimum and what maximum number of Div2 rounds could he have missed? Help him find these two numbers. | 256 megabytes | //package codeforces;
import java.io.PrintWriter;
import java.util.Scanner;
public class SerejaandContests {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int x = in.nextInt();
int k = in.nextInt();
boolean[] id = new boolean[x];
for (int i = 0; i < k; i++) {
int rtype = in.nextInt();
id[in.nextInt()] = true;
if (rtype == 1) {
id[in.nextInt()] = true;
}
}
int min = 0, max = 0;
for (int i = 1; i < x; i++)
if (!id[i]) {
min++;
if (i < x-1 && (!id[i+1])) {
max += 2;
i++;
}
else {
max++;
}
//System.out.println(i + " " + min + " " + max);
}
out.println(min + " " + max);
out.flush();
}
}
| Java | ["3 2\n2 1\n2 2", "9 3\n1 2 3\n2 8\n1 4 5", "10 0"] | 1 second | ["0 0", "2 3", "5 9"] | NoteIn the second sample we have unused identifiers of rounds 1, 6, 7. The minimum number of rounds Sereja could have missed equals to 2. In this case, the round with the identifier 1 will be a usual Div2 round and the round with identifier 6 will be synchronous with the Div1 round. The maximum number of rounds equals 3. In this case all unused identifiers belong to usual Div2 rounds. | Java 7 | standard input | [
"implementation",
"greedy",
"math"
] | fb77c9339250f206e7188b951902a221 | The first line contains two integers: x (1ββ€βxββ€β4000) β the round Sereja is taking part in today, and k (0ββ€βkβ<β4000) β the number of rounds he took part in. Next k lines contain the descriptions of the rounds that Sereja took part in before. If Sereja took part in one of two simultaneous rounds, the corresponding line looks like: "1 num2 num1" (where num2 is the identifier of this Div2 round, num1 is the identifier of the Div1 round). It is guaranteed that num1β-βnum2β=β1. If Sereja took part in a usual Div2 round, then the corresponding line looks like: "2 num" (where num is the identifier of this Div2 round). It is guaranteed that the identifiers of all given rounds are less than x. | 1,200 | Print in a single line two integers β the minimum and the maximum number of rounds that Sereja could have missed. | standard output | |
PASSED | 7242721a9802b83fdc7770cd2f64dacb | train_003.jsonl | 1394465400 | Sereja is a coder and he likes to take part in Codesorfes rounds. However, Uzhland doesn't have good internet connection, so Sereja sometimes skips rounds.Codesorfes has rounds of two types: Div1 (for advanced coders) and Div2 (for beginner coders). Two rounds, Div1 and Div2, can go simultaneously, (Div1 round cannot be held without Div2) in all other cases the rounds don't overlap in time. Each round has a unique identifier β a positive integer. The rounds are sequentially (without gaps) numbered with identifiers by the starting time of the round. The identifiers of rounds that are run simultaneously are different by one, also the identifier of the Div1 round is always greater.Sereja is a beginner coder, so he can take part only in rounds of Div2 type. At the moment he is taking part in a Div2 round, its identifier equals to x. Sereja remembers very well that he has taken part in exactly k rounds before this round. Also, he remembers all identifiers of the rounds he has taken part in and all identifiers of the rounds that went simultaneously with them. Sereja doesn't remember anything about the rounds he missed.Sereja is wondering: what minimum and what maximum number of Div2 rounds could he have missed? Help him find these two numbers. | 256 megabytes | import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int n,k;
n=in.nextInt(); k=in.nextInt();
int[] finished=new int[n];
int type;
int min=0,max=0;
finished[0]=1;
for(int i=0;i<k;i++){
type=in.nextInt();
if(type==1){
finished[in.nextInt()]=1;
finished[in.nextInt()]=1;
}else finished[in.nextInt()]=1;
}
for(int i=0;i<n;i++){
if(finished[i]==0){
//System.out.println(i);
max++;min++;
if(i<n-1&&finished[i+1]==0){
i++;
max++;
}
}
}
System.out.println(min+" "+max);
}
} | Java | ["3 2\n2 1\n2 2", "9 3\n1 2 3\n2 8\n1 4 5", "10 0"] | 1 second | ["0 0", "2 3", "5 9"] | NoteIn the second sample we have unused identifiers of rounds 1, 6, 7. The minimum number of rounds Sereja could have missed equals to 2. In this case, the round with the identifier 1 will be a usual Div2 round and the round with identifier 6 will be synchronous with the Div1 round. The maximum number of rounds equals 3. In this case all unused identifiers belong to usual Div2 rounds. | Java 7 | standard input | [
"implementation",
"greedy",
"math"
] | fb77c9339250f206e7188b951902a221 | The first line contains two integers: x (1ββ€βxββ€β4000) β the round Sereja is taking part in today, and k (0ββ€βkβ<β4000) β the number of rounds he took part in. Next k lines contain the descriptions of the rounds that Sereja took part in before. If Sereja took part in one of two simultaneous rounds, the corresponding line looks like: "1 num2 num1" (where num2 is the identifier of this Div2 round, num1 is the identifier of the Div1 round). It is guaranteed that num1β-βnum2β=β1. If Sereja took part in a usual Div2 round, then the corresponding line looks like: "2 num" (where num is the identifier of this Div2 round). It is guaranteed that the identifiers of all given rounds are less than x. | 1,200 | Print in a single line two integers β the minimum and the maximum number of rounds that Sereja could have missed. | standard output | |
PASSED | 5af344e4b3b8dd3cdf28acbb45c2dc44 | train_003.jsonl | 1394465400 | Sereja is a coder and he likes to take part in Codesorfes rounds. However, Uzhland doesn't have good internet connection, so Sereja sometimes skips rounds.Codesorfes has rounds of two types: Div1 (for advanced coders) and Div2 (for beginner coders). Two rounds, Div1 and Div2, can go simultaneously, (Div1 round cannot be held without Div2) in all other cases the rounds don't overlap in time. Each round has a unique identifier β a positive integer. The rounds are sequentially (without gaps) numbered with identifiers by the starting time of the round. The identifiers of rounds that are run simultaneously are different by one, also the identifier of the Div1 round is always greater.Sereja is a beginner coder, so he can take part only in rounds of Div2 type. At the moment he is taking part in a Div2 round, its identifier equals to x. Sereja remembers very well that he has taken part in exactly k rounds before this round. Also, he remembers all identifiers of the rounds he has taken part in and all identifiers of the rounds that went simultaneously with them. Sereja doesn't remember anything about the rounds he missed.Sereja is wondering: what minimum and what maximum number of Div2 rounds could he have missed? Help him find these two numbers. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class A {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int c = sc.nextInt();
int k = sc.nextInt();
boolean[] a = new boolean[c];
for (int i = 0; i < k; i++) {
int a1 = sc.nextInt();
int b1 = sc.nextInt();
if (a1 == 1) {
int c1 = sc.nextInt();
a[b1] = a[c1] = true;
} else {
a[b1] = true;
}
}
int ans1 = 0, ans2 = 0;
for (int i = 1; i < a.length; i++) {
if (i + 1 < a.length && !a[i] && !a[i + 1]) {
ans1++;
i++;
continue;
}
if (!a[i])
ans1++;
}
for (int i = 1; i < a.length; i++) {
if (!a[i]) {
ans2++;
}
}
System.out.println(ans1 + " " + ans2);
}
}
| Java | ["3 2\n2 1\n2 2", "9 3\n1 2 3\n2 8\n1 4 5", "10 0"] | 1 second | ["0 0", "2 3", "5 9"] | NoteIn the second sample we have unused identifiers of rounds 1, 6, 7. The minimum number of rounds Sereja could have missed equals to 2. In this case, the round with the identifier 1 will be a usual Div2 round and the round with identifier 6 will be synchronous with the Div1 round. The maximum number of rounds equals 3. In this case all unused identifiers belong to usual Div2 rounds. | Java 7 | standard input | [
"implementation",
"greedy",
"math"
] | fb77c9339250f206e7188b951902a221 | The first line contains two integers: x (1ββ€βxββ€β4000) β the round Sereja is taking part in today, and k (0ββ€βkβ<β4000) β the number of rounds he took part in. Next k lines contain the descriptions of the rounds that Sereja took part in before. If Sereja took part in one of two simultaneous rounds, the corresponding line looks like: "1 num2 num1" (where num2 is the identifier of this Div2 round, num1 is the identifier of the Div1 round). It is guaranteed that num1β-βnum2β=β1. If Sereja took part in a usual Div2 round, then the corresponding line looks like: "2 num" (where num is the identifier of this Div2 round). It is guaranteed that the identifiers of all given rounds are less than x. | 1,200 | Print in a single line two integers β the minimum and the maximum number of rounds that Sereja could have missed. | standard output | |
PASSED | fe2eeea7795fbe4b0801212bf52e0364 | train_003.jsonl | 1394465400 | Sereja is a coder and he likes to take part in Codesorfes rounds. However, Uzhland doesn't have good internet connection, so Sereja sometimes skips rounds.Codesorfes has rounds of two types: Div1 (for advanced coders) and Div2 (for beginner coders). Two rounds, Div1 and Div2, can go simultaneously, (Div1 round cannot be held without Div2) in all other cases the rounds don't overlap in time. Each round has a unique identifier β a positive integer. The rounds are sequentially (without gaps) numbered with identifiers by the starting time of the round. The identifiers of rounds that are run simultaneously are different by one, also the identifier of the Div1 round is always greater.Sereja is a beginner coder, so he can take part only in rounds of Div2 type. At the moment he is taking part in a Div2 round, its identifier equals to x. Sereja remembers very well that he has taken part in exactly k rounds before this round. Also, he remembers all identifiers of the rounds he has taken part in and all identifiers of the rounds that went simultaneously with them. Sereja doesn't remember anything about the rounds he missed.Sereja is wondering: what minimum and what maximum number of Div2 rounds could he have missed? Help him find these two numbers. | 256 megabytes | import java.lang.*;
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
new Task().solve(scanner, out);
out.close();
scanner.close();
}
}
class Task {
public void solve(Scanner in, PrintWriter out) {
int x = in.nextInt();
int k = in.nextInt();
boolean[] rounds = new boolean[x];
for (int i = 0; i < k; i++) {
int type = in.nextInt();
if (2 == type) {
rounds[in.nextInt()] = true;
} else
{
rounds[in.nextInt()] = true;
rounds[in.nextInt()] = true;
}
}
int min = 0;
int max = 0;
int gap = 0;
for (int i=1; i < x; i++) {
if (rounds[i]) {
max += gap;
min += (gap / 2) + (0 < gap % 2 ? 1 : 0);
gap = 0;
} else {
gap++;
}
}
max += gap;
min += (gap / 2) + (0 < gap % 2 ? 1 : 0);
out.print(min);
out.print(" ");
out.print(max);
}
}
| Java | ["3 2\n2 1\n2 2", "9 3\n1 2 3\n2 8\n1 4 5", "10 0"] | 1 second | ["0 0", "2 3", "5 9"] | NoteIn the second sample we have unused identifiers of rounds 1, 6, 7. The minimum number of rounds Sereja could have missed equals to 2. In this case, the round with the identifier 1 will be a usual Div2 round and the round with identifier 6 will be synchronous with the Div1 round. The maximum number of rounds equals 3. In this case all unused identifiers belong to usual Div2 rounds. | Java 7 | standard input | [
"implementation",
"greedy",
"math"
] | fb77c9339250f206e7188b951902a221 | The first line contains two integers: x (1ββ€βxββ€β4000) β the round Sereja is taking part in today, and k (0ββ€βkβ<β4000) β the number of rounds he took part in. Next k lines contain the descriptions of the rounds that Sereja took part in before. If Sereja took part in one of two simultaneous rounds, the corresponding line looks like: "1 num2 num1" (where num2 is the identifier of this Div2 round, num1 is the identifier of the Div1 round). It is guaranteed that num1β-βnum2β=β1. If Sereja took part in a usual Div2 round, then the corresponding line looks like: "2 num" (where num is the identifier of this Div2 round). It is guaranteed that the identifiers of all given rounds are less than x. | 1,200 | Print in a single line two integers β the minimum and the maximum number of rounds that Sereja could have missed. | standard output | |
PASSED | 4fc5e4b1189c79b567ca3dbd31ca5254 | train_003.jsonl | 1394465400 | Sereja is a coder and he likes to take part in Codesorfes rounds. However, Uzhland doesn't have good internet connection, so Sereja sometimes skips rounds.Codesorfes has rounds of two types: Div1 (for advanced coders) and Div2 (for beginner coders). Two rounds, Div1 and Div2, can go simultaneously, (Div1 round cannot be held without Div2) in all other cases the rounds don't overlap in time. Each round has a unique identifier β a positive integer. The rounds are sequentially (without gaps) numbered with identifiers by the starting time of the round. The identifiers of rounds that are run simultaneously are different by one, also the identifier of the Div1 round is always greater.Sereja is a beginner coder, so he can take part only in rounds of Div2 type. At the moment he is taking part in a Div2 round, its identifier equals to x. Sereja remembers very well that he has taken part in exactly k rounds before this round. Also, he remembers all identifiers of the rounds he has taken part in and all identifiers of the rounds that went simultaneously with them. Sereja doesn't remember anything about the rounds he missed.Sereja is wondering: what minimum and what maximum number of Div2 rounds could he have missed? Help him find these two numbers. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader s = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
int x=s.nextInt(),k=s.nextInt();
int sum=0;
int n=x;
boolean arr[] = new boolean[n];
arr[n-1]=true;
while (k-- >0)
{
int val=s.nextInt();
if (val ==1)
{
int div2=s.nextInt();
int div1= s.nextInt();
arr[div2-1]=true;
arr[div1-1]=true;
} else {
int div2=s.nextInt();
arr[div2-1]=true;
}
}
int min = 0;
int max = 0;
int ans=0;
int an=0;
for (int i=0;i<x;i++)
{
if (!arr[i] )
{
if (i+1 < x && !arr[i+1])
{
arr[i] = true;
arr[i + 1] = true;
min++;
max+=2;
i++;
}
else {
arr[i] = true;
max++;
min++;
}
}}
out.print(min+" "+max);
out.flush();
out.close();
}
}
class InputReader{
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream){
reader= new BufferedReader(new InputStreamReader (stream), 32768);
tokenizer=null;
}
public String next(){
while(tokenizer==null || !tokenizer.hasMoreTokens()){
try{
tokenizer=new StringTokenizer(reader.readLine());
} catch (IOException e){
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt(){
return Integer.parseInt(next());
}
}
| Java | ["3 2\n2 1\n2 2", "9 3\n1 2 3\n2 8\n1 4 5", "10 0"] | 1 second | ["0 0", "2 3", "5 9"] | NoteIn the second sample we have unused identifiers of rounds 1, 6, 7. The minimum number of rounds Sereja could have missed equals to 2. In this case, the round with the identifier 1 will be a usual Div2 round and the round with identifier 6 will be synchronous with the Div1 round. The maximum number of rounds equals 3. In this case all unused identifiers belong to usual Div2 rounds. | Java 7 | standard input | [
"implementation",
"greedy",
"math"
] | fb77c9339250f206e7188b951902a221 | The first line contains two integers: x (1ββ€βxββ€β4000) β the round Sereja is taking part in today, and k (0ββ€βkβ<β4000) β the number of rounds he took part in. Next k lines contain the descriptions of the rounds that Sereja took part in before. If Sereja took part in one of two simultaneous rounds, the corresponding line looks like: "1 num2 num1" (where num2 is the identifier of this Div2 round, num1 is the identifier of the Div1 round). It is guaranteed that num1β-βnum2β=β1. If Sereja took part in a usual Div2 round, then the corresponding line looks like: "2 num" (where num is the identifier of this Div2 round). It is guaranteed that the identifiers of all given rounds are less than x. | 1,200 | Print in a single line two integers β the minimum and the maximum number of rounds that Sereja could have missed. | standard output | |
PASSED | 1c8ac4ecac365245f9eb5e3dcd865248 | train_003.jsonl | 1394465400 | Sereja is a coder and he likes to take part in Codesorfes rounds. However, Uzhland doesn't have good internet connection, so Sereja sometimes skips rounds.Codesorfes has rounds of two types: Div1 (for advanced coders) and Div2 (for beginner coders). Two rounds, Div1 and Div2, can go simultaneously, (Div1 round cannot be held without Div2) in all other cases the rounds don't overlap in time. Each round has a unique identifier β a positive integer. The rounds are sequentially (without gaps) numbered with identifiers by the starting time of the round. The identifiers of rounds that are run simultaneously are different by one, also the identifier of the Div1 round is always greater.Sereja is a beginner coder, so he can take part only in rounds of Div2 type. At the moment he is taking part in a Div2 round, its identifier equals to x. Sereja remembers very well that he has taken part in exactly k rounds before this round. Also, he remembers all identifiers of the rounds he has taken part in and all identifiers of the rounds that went simultaneously with them. Sereja doesn't remember anything about the rounds he missed.Sereja is wondering: what minimum and what maximum number of Div2 rounds could he have missed? Help him find these two numbers. | 256 megabytes | import java.io.*;
import java.util.*;
public class p401b
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println();
int x = sc.nextInt();
int k = sc.nextInt();
int t=0,div1=0,div2=0,max=0,min=0;
boolean[] check = new boolean[x];
for(int i=0;i<k;i++)
{
t = sc.nextInt();
div2 = sc.nextInt();
if (t==1)
{
div1 = sc.nextInt();
check[div1] = true;
}
check[div2] = true;
}
for (int i=1;i<check.length;i++) if (!check[i]) max++;
for (int i=1;i<check.length;i++)
{
if (!check[i])
{
if(i+1<x && !check[i + 1])
{
min++;
i++;
}
else min++;
}
}
System.out.println(min+" "+max);
}
} | Java | ["3 2\n2 1\n2 2", "9 3\n1 2 3\n2 8\n1 4 5", "10 0"] | 1 second | ["0 0", "2 3", "5 9"] | NoteIn the second sample we have unused identifiers of rounds 1, 6, 7. The minimum number of rounds Sereja could have missed equals to 2. In this case, the round with the identifier 1 will be a usual Div2 round and the round with identifier 6 will be synchronous with the Div1 round. The maximum number of rounds equals 3. In this case all unused identifiers belong to usual Div2 rounds. | Java 7 | standard input | [
"implementation",
"greedy",
"math"
] | fb77c9339250f206e7188b951902a221 | The first line contains two integers: x (1ββ€βxββ€β4000) β the round Sereja is taking part in today, and k (0ββ€βkβ<β4000) β the number of rounds he took part in. Next k lines contain the descriptions of the rounds that Sereja took part in before. If Sereja took part in one of two simultaneous rounds, the corresponding line looks like: "1 num2 num1" (where num2 is the identifier of this Div2 round, num1 is the identifier of the Div1 round). It is guaranteed that num1β-βnum2β=β1. If Sereja took part in a usual Div2 round, then the corresponding line looks like: "2 num" (where num is the identifier of this Div2 round). It is guaranteed that the identifiers of all given rounds are less than x. | 1,200 | Print in a single line two integers β the minimum and the maximum number of rounds that Sereja could have missed. | standard output | |
PASSED | df4aed6cb60afa5d2037c13d397d854a | train_003.jsonl | 1394465400 | Sereja is a coder and he likes to take part in Codesorfes rounds. However, Uzhland doesn't have good internet connection, so Sereja sometimes skips rounds.Codesorfes has rounds of two types: Div1 (for advanced coders) and Div2 (for beginner coders). Two rounds, Div1 and Div2, can go simultaneously, (Div1 round cannot be held without Div2) in all other cases the rounds don't overlap in time. Each round has a unique identifier β a positive integer. The rounds are sequentially (without gaps) numbered with identifiers by the starting time of the round. The identifiers of rounds that are run simultaneously are different by one, also the identifier of the Div1 round is always greater.Sereja is a beginner coder, so he can take part only in rounds of Div2 type. At the moment he is taking part in a Div2 round, its identifier equals to x. Sereja remembers very well that he has taken part in exactly k rounds before this round. Also, he remembers all identifiers of the rounds he has taken part in and all identifiers of the rounds that went simultaneously with them. Sereja doesn't remember anything about the rounds he missed.Sereja is wondering: what minimum and what maximum number of Div2 rounds could he have missed? Help him find these two numbers. | 256 megabytes | /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.text.*;
public class cf401b {
static BufferedReader br;
static Scanner sc;
static PrintWriter out;
public static void initA() {
try {
br = new BufferedReader(new InputStreamReader(System.in));
sc = new Scanner(System.in);
out = new PrintWriter(System.out);
} catch (Exception e) {
}
}
static boolean next_permutation(Integer[] p) {
for (int a = p.length - 2; a >= 0; --a) {
if (p[a] < p[a + 1]) {
for (int b = p.length - 1;; --b) {
if (p[b] > p[a]) {
int t = p[a];
p[a] = p[b];
p[b] = t;
for (++a, b = p.length - 1; a < b; ++a, --b) {
t = p[a];
p[a] = p[b];
p[b] = t;
}
return true;
}
}
}
}
return false;
}
public static String getString() {
try {
return br.readLine();
} catch (Exception e) {
}
return "";
}
public static Integer getInt() {
try {
return Integer.parseInt(br.readLine());
} catch (Exception e) {
}
return 0;
}
public static Integer[] getIntArr() {
try {
StringTokenizer temp = new StringTokenizer(br.readLine());
int n = temp.countTokens();
Integer temp2[] = new Integer[n];
for (int i = 0; i < n; i++) {
temp2[i] = Integer.parseInt(temp.nextToken());
}
return temp2;
} catch (Exception e) {
}
return null;
}
public static Long[] getLongArr() {
try {
StringTokenizer temp = new StringTokenizer(br.readLine());
int n = temp.countTokens();
Long temp2[] = new Long[n];
for (int i = 0; i < n; i++) {
temp2[i] = Long.parseLong(temp.nextToken());
}
return temp2;
} catch (Exception e) {
}
return null;
}
public static String[] getStringArr() {
try {
StringTokenizer temp = new StringTokenizer(br.readLine());
int n = temp.countTokens();
String temp2[] = new String[n];
for (int i = 0; i < n; i++) {
temp2[i] = (temp.nextToken());
}
return temp2;
} catch (Exception e) {
}
return null;
}
public static void print(Object a) {
out.println(a);
}
public static void print(String s, Object... a) {
out.printf(s, a);
}
public static int nextInt() {
return sc.nextInt();
}
public static double nextDouble() {
return sc.nextDouble();
}
public static void main(String[] ar) {
initA();
cf401b c = new cf401b();
c.solve();
out.flush();
}
void solve() {
Integer xx[] = getIntArr();
int cur = xx[0]-1, ik = xx[1];
LinkedHashSet<Integer> al =new LinkedHashSet<Integer>();
for(int i =1;i<=cur;i++){
al.add(i);
}
for(int i =0 ;i<ik;i++){
xx = getIntArr();
if(xx[0]==1){
al.remove(xx[1]);
al.remove(xx[2]);
cur-=2;
} else{
al.remove(xx[1]);
cur--;
}
}
int min = 0;
Integer[] p = new Integer[al.size()];
al.toArray(p);
int i = 0;
for( ;i<p.length-1;){
if(p[i+1] - p[i]==1){
min++;
i+=2;
} else {
min++;
i++;
}
}
if(i<p.length){
min++;
}
//print(al);
print(min+" "+cur);
}
}
| Java | ["3 2\n2 1\n2 2", "9 3\n1 2 3\n2 8\n1 4 5", "10 0"] | 1 second | ["0 0", "2 3", "5 9"] | NoteIn the second sample we have unused identifiers of rounds 1, 6, 7. The minimum number of rounds Sereja could have missed equals to 2. In this case, the round with the identifier 1 will be a usual Div2 round and the round with identifier 6 will be synchronous with the Div1 round. The maximum number of rounds equals 3. In this case all unused identifiers belong to usual Div2 rounds. | Java 7 | standard input | [
"implementation",
"greedy",
"math"
] | fb77c9339250f206e7188b951902a221 | The first line contains two integers: x (1ββ€βxββ€β4000) β the round Sereja is taking part in today, and k (0ββ€βkβ<β4000) β the number of rounds he took part in. Next k lines contain the descriptions of the rounds that Sereja took part in before. If Sereja took part in one of two simultaneous rounds, the corresponding line looks like: "1 num2 num1" (where num2 is the identifier of this Div2 round, num1 is the identifier of the Div1 round). It is guaranteed that num1β-βnum2β=β1. If Sereja took part in a usual Div2 round, then the corresponding line looks like: "2 num" (where num is the identifier of this Div2 round). It is guaranteed that the identifiers of all given rounds are less than x. | 1,200 | Print in a single line two integers β the minimum and the maximum number of rounds that Sereja could have missed. | standard output | |
PASSED | af2c3c8f8007e64005d6dd2cc3283896 | train_003.jsonl | 1394465400 | Sereja is a coder and he likes to take part in Codesorfes rounds. However, Uzhland doesn't have good internet connection, so Sereja sometimes skips rounds.Codesorfes has rounds of two types: Div1 (for advanced coders) and Div2 (for beginner coders). Two rounds, Div1 and Div2, can go simultaneously, (Div1 round cannot be held without Div2) in all other cases the rounds don't overlap in time. Each round has a unique identifier β a positive integer. The rounds are sequentially (without gaps) numbered with identifiers by the starting time of the round. The identifiers of rounds that are run simultaneously are different by one, also the identifier of the Div1 round is always greater.Sereja is a beginner coder, so he can take part only in rounds of Div2 type. At the moment he is taking part in a Div2 round, its identifier equals to x. Sereja remembers very well that he has taken part in exactly k rounds before this round. Also, he remembers all identifiers of the rounds he has taken part in and all identifiers of the rounds that went simultaneously with them. Sereja doesn't remember anything about the rounds he missed.Sereja is wondering: what minimum and what maximum number of Div2 rounds could he have missed? Help him find these two numbers. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
public class B {
static int x,k;
static int[] c,d1,d2;
static int min(int i) {
return (i>>1)+(i&1);
}
static String solve() {
if(k==0) {
int min=((x-1)>>1)+((x-1)&1), max=x-1;
return min+" "+max;
}
Integer[] i2j=new Integer[k];
for (int i=0; i<k; i++) {
i2j[i]=i;
}
Arrays.sort(i2j, new Comparator<Integer>() {
public int compare(Integer o1, Integer o2) {
return d2[o1]-d2[o2];
}});
int min=min(d2[i2j[0]]-1), max=d2[i2j[0]]-1;
for (int i=1; i<k; i++) {
int d=d2[i2j[i]]-d1[i2j[i-1]]-1;
min+=min(d);
max+=d;
}
int d=x-d1[i2j[k-1]]-1;
min+=min(d);
max+=d;
return min+" "+max;
}
static void run_stream(InputStream ins) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String[] xk=br.readLine().split(" ");
x=Integer.parseInt(xk[0]);
k=Integer.parseInt(xk[1]);
c=new int[k]; d1=new int[k]; d2=new int[k];
for (int i=0; i<k; i++) {
String[] cd2d1=br.readLine().split(" ");
c[i]=Integer.parseInt(cd2d1[0]);
d2[i]=Integer.parseInt(cd2d1[1]);
if(c[i]==1) {
d1[i]=Integer.parseInt(cd2d1[2]);
} else {
d1[i]=d2[i];
}
}
System.out.println(solve());
}
public static void main(String[] args) throws IOException {
run_stream(System.in);
}
}
| Java | ["3 2\n2 1\n2 2", "9 3\n1 2 3\n2 8\n1 4 5", "10 0"] | 1 second | ["0 0", "2 3", "5 9"] | NoteIn the second sample we have unused identifiers of rounds 1, 6, 7. The minimum number of rounds Sereja could have missed equals to 2. In this case, the round with the identifier 1 will be a usual Div2 round and the round with identifier 6 will be synchronous with the Div1 round. The maximum number of rounds equals 3. In this case all unused identifiers belong to usual Div2 rounds. | Java 7 | standard input | [
"implementation",
"greedy",
"math"
] | fb77c9339250f206e7188b951902a221 | The first line contains two integers: x (1ββ€βxββ€β4000) β the round Sereja is taking part in today, and k (0ββ€βkβ<β4000) β the number of rounds he took part in. Next k lines contain the descriptions of the rounds that Sereja took part in before. If Sereja took part in one of two simultaneous rounds, the corresponding line looks like: "1 num2 num1" (where num2 is the identifier of this Div2 round, num1 is the identifier of the Div1 round). It is guaranteed that num1β-βnum2β=β1. If Sereja took part in a usual Div2 round, then the corresponding line looks like: "2 num" (where num is the identifier of this Div2 round). It is guaranteed that the identifiers of all given rounds are less than x. | 1,200 | Print in a single line two integers β the minimum and the maximum number of rounds that Sereja could have missed. | standard output | |
PASSED | bdb7b608fb75f838f5a8bd7835715ad9 | train_003.jsonl | 1394465400 | Sereja is a coder and he likes to take part in Codesorfes rounds. However, Uzhland doesn't have good internet connection, so Sereja sometimes skips rounds.Codesorfes has rounds of two types: Div1 (for advanced coders) and Div2 (for beginner coders). Two rounds, Div1 and Div2, can go simultaneously, (Div1 round cannot be held without Div2) in all other cases the rounds don't overlap in time. Each round has a unique identifier β a positive integer. The rounds are sequentially (without gaps) numbered with identifiers by the starting time of the round. The identifiers of rounds that are run simultaneously are different by one, also the identifier of the Div1 round is always greater.Sereja is a beginner coder, so he can take part only in rounds of Div2 type. At the moment he is taking part in a Div2 round, its identifier equals to x. Sereja remembers very well that he has taken part in exactly k rounds before this round. Also, he remembers all identifiers of the rounds he has taken part in and all identifiers of the rounds that went simultaneously with them. Sereja doesn't remember anything about the rounds he missed.Sereja is wondering: what minimum and what maximum number of Div2 rounds could he have missed? Help him find these two numbers. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
public class SerajaAndContests {
public static class Pair implements Comparable<Pair>{
public int first,second=0;
Pair(int first,int second){
this.first=first;
this.second=second;
}
@Override
public int compareTo(Pair e) {
if(first>e.first){
return 1;
}
return -1;
}
};
public static void main(String[] args) throws IOException {
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String s="";
while((s=in.readLine())!=null){
String a[]=s.split(" ");
int x=Integer.parseInt(a[0]);
int k=Integer.parseInt(a[1]);
if(k==0){
double min=x/2;
if(min!=(int)min){
min++;
}
out.println((int)min+" "+(x-1));
}else{
Pair num[]=new Pair[k];
for (int i = 0; i < k; i++) {
a=in.readLine().split(" ");
if(Integer.parseInt(a[0])==2){
num[i]=new Pair(Integer.parseInt(a[1]),0);
}else{
num[i]=new Pair(Integer.parseInt(a[1]),Integer.parseInt(a[2]));
}
}
Arrays.sort(num);
int sum[]=new int[k+5];
int p=1;
sum[0]=num[0].first-1;
int max=sum[0];
double min=0;
min+=(double)sum[0]/2.0;
if(min!=(int)min){
min=(int)min+1;
}
for (int i = 1; i < k; i++) {
if(num[i-1].second!=0){
sum[p]=num[i].first-num[i-1].second-1;
max+=sum[p];
min+=(double)sum[p]/2.0;
if(min!=(int)min){
min=(int)min+1;
}
p++;
}else{
sum[p]=num[i].first-num[i-1].first-1;
max+=sum[p];
min+=(double)sum[p]/2.0;
if(min!=(int)min){
min=(int)min+1;
}
p++;
}
}
if(num[k-1].second!=0){
sum[p]=x-num[k-1].second-1;
max+=sum[p];
min+=(double)sum[p]/2.0;
if(min!=(int)min){
min=(int)min+1;
}
}else{
sum[p]=x-num[k-1].first-1;
max+=sum[p];
min+=(double)sum[p]/2.0;
if(min!=(int)min){
min=(int)min+1;
}
}
out.println((int)min+" "+max);
}
}
out.close();
}
}
| Java | ["3 2\n2 1\n2 2", "9 3\n1 2 3\n2 8\n1 4 5", "10 0"] | 1 second | ["0 0", "2 3", "5 9"] | NoteIn the second sample we have unused identifiers of rounds 1, 6, 7. The minimum number of rounds Sereja could have missed equals to 2. In this case, the round with the identifier 1 will be a usual Div2 round and the round with identifier 6 will be synchronous with the Div1 round. The maximum number of rounds equals 3. In this case all unused identifiers belong to usual Div2 rounds. | Java 7 | standard input | [
"implementation",
"greedy",
"math"
] | fb77c9339250f206e7188b951902a221 | The first line contains two integers: x (1ββ€βxββ€β4000) β the round Sereja is taking part in today, and k (0ββ€βkβ<β4000) β the number of rounds he took part in. Next k lines contain the descriptions of the rounds that Sereja took part in before. If Sereja took part in one of two simultaneous rounds, the corresponding line looks like: "1 num2 num1" (where num2 is the identifier of this Div2 round, num1 is the identifier of the Div1 round). It is guaranteed that num1β-βnum2β=β1. If Sereja took part in a usual Div2 round, then the corresponding line looks like: "2 num" (where num is the identifier of this Div2 round). It is guaranteed that the identifiers of all given rounds are less than x. | 1,200 | Print in a single line two integers β the minimum and the maximum number of rounds that Sereja could have missed. | standard output | |
PASSED | 9eabb81899396ca441f2b37bea14ca54 | train_003.jsonl | 1394465400 | Sereja is a coder and he likes to take part in Codesorfes rounds. However, Uzhland doesn't have good internet connection, so Sereja sometimes skips rounds.Codesorfes has rounds of two types: Div1 (for advanced coders) and Div2 (for beginner coders). Two rounds, Div1 and Div2, can go simultaneously, (Div1 round cannot be held without Div2) in all other cases the rounds don't overlap in time. Each round has a unique identifier β a positive integer. The rounds are sequentially (without gaps) numbered with identifiers by the starting time of the round. The identifiers of rounds that are run simultaneously are different by one, also the identifier of the Div1 round is always greater.Sereja is a beginner coder, so he can take part only in rounds of Div2 type. At the moment he is taking part in a Div2 round, its identifier equals to x. Sereja remembers very well that he has taken part in exactly k rounds before this round. Also, he remembers all identifiers of the rounds he has taken part in and all identifiers of the rounds that went simultaneously with them. Sereja doesn't remember anything about the rounds he missed.Sereja is wondering: what minimum and what maximum number of Div2 rounds could he have missed? Help him find these two numbers. | 256 megabytes | import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Main {
PrintWriter out;
BufferedReader input;
Main() {
try {
input = new BufferedReader(new FileReader("input.txt"));
out = new PrintWriter(new FileWriter("output.txt"), true);
solver();
} catch (Exception ex) {
ex.printStackTrace();
input = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out, true);
solver();
} finally {
out.close();
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
StringTokenizer st = new StringTokenizer("");
private String nextToken() {
while (!st.hasMoreElements()) {
try {
st = new StringTokenizer(input.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
private int nextInt() {
return Integer.parseInt(nextToken());
}
private long nextLong() {
return Long.parseLong(nextToken());
}
public void solver() {
int x = nextInt();
int k = nextInt();
boolean[] arr = new boolean[x];
for (int i = 0; i < k; i++) {
int choose = nextInt();
if (choose == 1) {
arr[nextInt()] = true;
arr[nextInt()] = true;
} else
arr[nextInt()] = true;
}
int max = 0;
int min = 0;
for (int i = 1, pr = 0; i < x; i++) {
if (!arr[i]) {
if (pr != 0 && i - pr == 1) {
} else {
min++;
pr = i;
}
max++;
}
}
System.out.println(min + " " + max);
}
public static void main(String[] args) {
new Main();
}
}
| Java | ["3 2\n2 1\n2 2", "9 3\n1 2 3\n2 8\n1 4 5", "10 0"] | 1 second | ["0 0", "2 3", "5 9"] | NoteIn the second sample we have unused identifiers of rounds 1, 6, 7. The minimum number of rounds Sereja could have missed equals to 2. In this case, the round with the identifier 1 will be a usual Div2 round and the round with identifier 6 will be synchronous with the Div1 round. The maximum number of rounds equals 3. In this case all unused identifiers belong to usual Div2 rounds. | Java 7 | standard input | [
"implementation",
"greedy",
"math"
] | fb77c9339250f206e7188b951902a221 | The first line contains two integers: x (1ββ€βxββ€β4000) β the round Sereja is taking part in today, and k (0ββ€βkβ<β4000) β the number of rounds he took part in. Next k lines contain the descriptions of the rounds that Sereja took part in before. If Sereja took part in one of two simultaneous rounds, the corresponding line looks like: "1 num2 num1" (where num2 is the identifier of this Div2 round, num1 is the identifier of the Div1 round). It is guaranteed that num1β-βnum2β=β1. If Sereja took part in a usual Div2 round, then the corresponding line looks like: "2 num" (where num is the identifier of this Div2 round). It is guaranteed that the identifiers of all given rounds are less than x. | 1,200 | Print in a single line two integers β the minimum and the maximum number of rounds that Sereja could have missed. | standard output | |
PASSED | 81aebea74a75b067cb1a0a33970683fd | train_003.jsonl | 1394465400 | Sereja is a coder and he likes to take part in Codesorfes rounds. However, Uzhland doesn't have good internet connection, so Sereja sometimes skips rounds.Codesorfes has rounds of two types: Div1 (for advanced coders) and Div2 (for beginner coders). Two rounds, Div1 and Div2, can go simultaneously, (Div1 round cannot be held without Div2) in all other cases the rounds don't overlap in time. Each round has a unique identifier β a positive integer. The rounds are sequentially (without gaps) numbered with identifiers by the starting time of the round. The identifiers of rounds that are run simultaneously are different by one, also the identifier of the Div1 round is always greater.Sereja is a beginner coder, so he can take part only in rounds of Div2 type. At the moment he is taking part in a Div2 round, its identifier equals to x. Sereja remembers very well that he has taken part in exactly k rounds before this round. Also, he remembers all identifiers of the rounds he has taken part in and all identifiers of the rounds that went simultaneously with them. Sereja doesn't remember anything about the rounds he missed.Sereja is wondering: what minimum and what maximum number of Div2 rounds could he have missed? Help him find these two numbers. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Main {
public static void main(String args[]) throws NumberFormatException,IOException {
Stdin in = new Stdin();
PrintWriter out = new PrintWriter(System.out);
int x=in.readInt();
int k=in.readInt();
boolean[]taking=new boolean[x];
int min = 0,max=0;
int type,num1,num2;
for(int i=0;i<k;i++){
type=in.readInt();
if(type==2){
num2=in.readInt();
taking[num2]=true;
}else{
num1=in.readInt();
num2=in.readInt();
taking[num1]=true;
taking[num2]=true;
}
}
int count=0;
for(int i=1;i<taking.length;i++){
if(!taking[i]){
count++;
max++;
}else{
if(count>0){
min+=count/2+count%2;
}
count=0;
}
}
if(count>0)
min+=count/2+count%2;
out.println(min+" "+max);
out.flush();
}
private static class Stdin {
InputStreamReader read;
BufferedReader br;
StringTokenizer st = new StringTokenizer("");
private Stdin() {
read = new InputStreamReader(System.in);
br = new BufferedReader(read);
}
private String readNext() throws IOException {
while (!st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
private int readInt() throws IOException, NumberFormatException {
return Integer.parseInt(readNext());
}
private long readLong() throws IOException, NumberFormatException {
return Long.parseLong(readNext());
}
}
}
| Java | ["3 2\n2 1\n2 2", "9 3\n1 2 3\n2 8\n1 4 5", "10 0"] | 1 second | ["0 0", "2 3", "5 9"] | NoteIn the second sample we have unused identifiers of rounds 1, 6, 7. The minimum number of rounds Sereja could have missed equals to 2. In this case, the round with the identifier 1 will be a usual Div2 round and the round with identifier 6 will be synchronous with the Div1 round. The maximum number of rounds equals 3. In this case all unused identifiers belong to usual Div2 rounds. | Java 7 | standard input | [
"implementation",
"greedy",
"math"
] | fb77c9339250f206e7188b951902a221 | The first line contains two integers: x (1ββ€βxββ€β4000) β the round Sereja is taking part in today, and k (0ββ€βkβ<β4000) β the number of rounds he took part in. Next k lines contain the descriptions of the rounds that Sereja took part in before. If Sereja took part in one of two simultaneous rounds, the corresponding line looks like: "1 num2 num1" (where num2 is the identifier of this Div2 round, num1 is the identifier of the Div1 round). It is guaranteed that num1β-βnum2β=β1. If Sereja took part in a usual Div2 round, then the corresponding line looks like: "2 num" (where num is the identifier of this Div2 round). It is guaranteed that the identifiers of all given rounds are less than x. | 1,200 | Print in a single line two integers β the minimum and the maximum number of rounds that Sereja could have missed. | standard output | |
PASSED | f9f42b8267168ccef2dc75fe4e2cc83e | train_003.jsonl | 1415718000 | Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0,β1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: where is equal to 1 if some aiβ=β1, otherwise it is equal to 0.Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1ββ€βiββ€βm) and column j (1ββ€βjββ€βn) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula:.(Bij is OR of all elements in row i and column j of matrix A)Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. | 256 megabytes | import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int m = scanner.nextInt() , n = scanner.nextInt();
Boolean isThereOne = false;
int[][] A = new int[n][m];
int[][] B = new int[n][m];
Boolean hasOne = false;
for (int i = 0; i < m; i++){
for (int j = 0; j < n; j++){
B[j][i] = scanner.nextInt();
if(B[j][i] == 1)
isThereOne = true;
}
}
Boolean flag = false;
for (int i = 0; i < m; i++){
if(flag)
break;
for (int j = 0; j < n; j++){
hasOne = false;
if(B[j][i] == 1) {
for ( int k = 0; k < m; k++){
if(B[j][k] == 0){
for( int P = 0; P < n; P++ ){
if( B[P][i] == 0 ){
hasOne = true;
}
}
}
}
if(hasOne)
{
System.out.println("NO");
flag = true;
break;
}
}
else{
for ( int k = 0; k < m; k++){
A[j][k] = -1;
}
for( int k = 0; k < n; k++ ){
A[k][i] = -1;
}
}
}
}
Boolean flag2 = false;
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if(A[j][i] != -1){
flag2 = true;
break;
}
}
if( flag2 )
break;
}
if(isThereOne && !flag2 && !(hasOne)){
System.out.println("NO");
flag = true;
}
if(!flag){
System.out.println("YES");
for (int i = 0; i < m; i++){
for (int j = 0; j < n; j++){
if( A[j][i] == -1)
System.out.print(0);
else
System.out.print(1);
System.out.print(" ");
}
System.out.println();
}
}
}
}
| Java | ["2 2\n1 0\n0 0", "2 3\n1 1 1\n1 1 1", "2 3\n0 1 0\n1 1 1"] | 1 second | ["NO", "YES\n1 1 1\n1 1 1", "YES\n0 0 0\n0 1 0"] | null | Java 11 | standard input | [
"implementation",
"hashing",
"greedy"
] | bacd613dc8a91cee8bef87b787e878ca | The first line contains two integer m and n (1ββ€βm,βnββ€β100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). | 1,300 | In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. | standard output | |
PASSED | 401ee594ae9a211a93f9da321db0b7fa | train_003.jsonl | 1415718000 | Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0,β1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: where is equal to 1 if some aiβ=β1, otherwise it is equal to 0.Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1ββ€βiββ€βm) and column j (1ββ€βjββ€βn) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula:.(Bij is OR of all elements in row i and column j of matrix A)Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. | 256 megabytes | import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.TreeSet;
import java.util.Scanner;
import java.util.Set;
import java.util.Vector;
import static java.util.Collections.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
public class cf {
private static final int MOD = (int) (1e9 + 7), MOD_FFT = 998244353;
private static final Reader r = new Reader();
private static final PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
private static final boolean thread = false;
static final boolean HAS_TEST_CASES = false;
static final int SCAN_LINE_LENGTH = 1000002;
static int n, a[], e[][];
private static Vector<Integer> adj[], v = new Vector<>();
static void solve() throws Exception {
int n = ni(), m = ni();
e = new int[n][m];
for (int i = 0; i < e.length; i++) {
e[i] = na(m);
}
int ans[][] = new int[n][m];
for (int i = 0; i < ans.length; i++) {
fill(ans[i], 1);
}
for (int i = 0; i < ans.length; i++) {
for (int j = 0; j < ans[i].length; j++) {
if (e[i][j] == 0) {
for (int k = 0; k < n; k++) {
ans[k][j] = 0;
}
for (int k = 0; k < m; k++) {
ans[i][k] = 0;
}
}
}
}
for (int i = 0; i < ans.length; i++) {
for (int j = 0; j < ans[i].length; j++) {
if (e[i][j] == 1) {
boolean find = false;
for (int k = 0; k < n; k++) {
if (ans[k][j] == 1)
find = true;
}
for (int k = 0; k < m; k++) {
if (ans[i][k] == 1)
find = true;
}
if (!find) {
pn("NO");
return;
}
}
}
}
pn("YES");
for (int i = 0; i < ans.length; i++) {
for (int j = 0; j < ans[i].length; j++) {
p(ans[i][j] + " ");
}
pn();
}
}
public static void main(final String[] args) throws Exception {
if (!thread) {
final int testcases = HAS_TEST_CASES ? ni() : 1;
for (int i = 1; i <= testcases; i++) {
// out.print("Case #" + (i + 1) + ": ");
try {
solve();
} catch (final Exception e) {
// pni("idk Exception");
// e.printStackTrace(System.err);
// System.exit(0);
throw e;
}
}
out.flush();
}
r.close();
out.close();
}
private static void swap(final int i, final int j) {
final int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
private static boolean isMulOverflow(final long A, final long B) {
if (A == 0 || B == 0)
return false;
final long result = A * B;
if (A == result / B)
return true;
return false;
}
private static int gcd(final int a, final int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
private static class Pair<T, E> implements Comparable<Pair<T, E>> {
T fir;
E snd;
Pair() {
}
Pair(final T x, final E y) {
this.fir = x;
this.snd = y;
}
@Override
@SuppressWarnings("unchecked")
public int compareTo(final Pair<T, E> o) {
final int c = ((Comparable<T>) fir).compareTo(o.fir);
return c != 0 ? c : ((Comparable<E>) snd).compareTo(o.snd);
}
}
private static class pi implements Comparable<pi> {
int fir, snd;
pi() {
}
pi(final int a, final int b) {
fir = a;
snd = b;
}
public int compareTo(final pi o) {
return fir == o.fir ? snd - o.snd : fir - o.fir;
}
}
private static <T> void checkV(final Vector<T> adj[], final int i) {
adj[i] = adj[i] == null ? new Vector<>() : adj[i];
}
private static int[] na(final int n) throws Exception {
final int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = ni();
}
return a;
}
private static int[] na1(final int n) throws Exception {
final int[] a = new int[n + 1];
for (int i = 1; i < a.length; i++) {
a[i] = ni();
}
return a;
}
private static String n() throws IOException {
return r.readToken();
}
private static String nln() throws IOException {
return r.readLine();
}
private static int ni() throws IOException {
return r.nextInt();
}
private static long nl() throws IOException {
return r.nextLong();
}
private static double nd() throws IOException {
return r.nextDouble();
}
private static void p(final Object o) {
out.print(o);
}
private static void pn(final Object o) {
out.println(o);
}
private static void pn() {
out.println("");
}
private static void pni(final Object o) {
out.println(o);
out.flush();
}
private static class Reader {
private final int BUFFER_SIZE = 1 << 17;
private final DataInputStream din;
private final byte[] buffer;
private int bufferPointer, bytesRead;
// private StringTokenizer st;
public Reader() {
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(final String file_name) throws IOException {
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
final byte[] buf = new byte[SCAN_LINE_LENGTH];
public String readLine() throws IOException {
int cnt = 0;
int c;
o: while ((c = read()) != -1) {
if (c == '\n')
if (cnt == 0)
continue o;
else
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public String readToken() throws IOException {
int cnt = 0;
int c;
o: while ((c = read()) != -1) {
if (!(c >= 33 && c <= 126))
if (cnt == 0)
continue o;
else
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException {
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
final 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();
final 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();
final 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();
}
}
static {
if (thread)
new Thread(null, new Runnable() {
@Override
public void run() {
try {
final int testcases = HAS_TEST_CASES ? ni() : 1;
for (int i = 1; i <= testcases; i++) {
// out.print("Case #" + (i + 1) + ": ");
try {
solve();
} catch (final ArrayIndexOutOfBoundsException e) {
e.printStackTrace(System.err);
System.exit(-1);
} catch (final Exception e) {
pni("idk Exception in solve");
e.printStackTrace(System.err);
System.exit(-1);
}
}
out.flush();
} catch (final Throwable t) {
t.printStackTrace(System.err);
System.exit(-1);
}
}
}, "rec", (1L << 28)).start();
}
@SuppressWarnings({ "unchecked" })
private static <T> T deepCopy(final T old) {
try {
return (T) deepCopyObject(old);
} catch (final IOException | ClassNotFoundException e) {
e.printStackTrace(System.err);
System.exit(-1);
}
return null;
}
private static Object deepCopyObject(final Object oldObj) throws IOException, ClassNotFoundException {
ObjectOutputStream oos = null;
ObjectInputStream ois = null;
try {
final ByteArrayOutputStream bos = new ByteArrayOutputStream(); // A
oos = new ObjectOutputStream(bos); // B
// serialize and pass the object
oos.writeObject(oldObj); // C
oos.flush(); // D
final ByteArrayInputStream bin = new ByteArrayInputStream(bos.toByteArray()); // E
ois = new ObjectInputStream(bin); // F
// return the new object
return ois.readObject(); // G
} catch (final ClassNotFoundException e) {
pni("Exception in ObjectCloner = " + e);
throw (e);
} finally {
oos.close();
ois.close();
}
}
} | Java | ["2 2\n1 0\n0 0", "2 3\n1 1 1\n1 1 1", "2 3\n0 1 0\n1 1 1"] | 1 second | ["NO", "YES\n1 1 1\n1 1 1", "YES\n0 0 0\n0 1 0"] | null | Java 11 | standard input | [
"implementation",
"hashing",
"greedy"
] | bacd613dc8a91cee8bef87b787e878ca | The first line contains two integer m and n (1ββ€βm,βnββ€β100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). | 1,300 | In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. | standard output | |
PASSED | 8a39fb3f098599924bb8b857bccad66f | train_003.jsonl | 1415718000 | Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0,β1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: where is equal to 1 if some aiβ=β1, otherwise it is equal to 0.Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1ββ€βiββ€βm) and column j (1ββ€βjββ€βn) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula:.(Bij is OR of all elements in row i and column j of matrix A)Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. | 256 megabytes | import java.util.*;
import java.lang.*;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m =sc.nextInt();
int a[][] = new int[n][m];
boolean b[][] = new boolean[n][m];
HashMap<Integer,Integer> h = new HashMap<>();
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
a[i][j] = sc.nextInt();
if(a[i][j]==0){
for(int k=0;k<n;k++) b[k][j] = true;
for(int k=0;k<m;k++) b[i][k] = true;
}
if(a[i][j]==1) h.put(i,j);
}
}
if(a[0][0]==1) h.put(0,0);
int allnotHappy=0;
for(HashMap.Entry<Integer,Integer> set: h.entrySet()){
int i = set.getKey();
int j = set.getValue();
int happy = 0;
for(int k=0;k<m;k++){
if(b[i][k]==false){
happy++;
break;
}
}
int hp1 = 0;
for(int k=0;k<n;k++){
if(b[k][j]==false){
hp1++;
break;
}
}
if(happy==0&&hp1==0){
allnotHappy++;
System.out.println("NO");
break;
}
}
if(allnotHappy==0){
System.out.println("YES");
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(b[i][j]==false) System.out.print(1+" ");
else System.out.print(0+" ");
}
System.out.println();
}
}
}
} | Java | ["2 2\n1 0\n0 0", "2 3\n1 1 1\n1 1 1", "2 3\n0 1 0\n1 1 1"] | 1 second | ["NO", "YES\n1 1 1\n1 1 1", "YES\n0 0 0\n0 1 0"] | null | Java 11 | standard input | [
"implementation",
"hashing",
"greedy"
] | bacd613dc8a91cee8bef87b787e878ca | The first line contains two integer m and n (1ββ€βm,βnββ€β100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). | 1,300 | In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. | standard output | |
PASSED | 484e6271a0d23e4be2e87a2d8fc53dbf | train_003.jsonl | 1415718000 | Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0,β1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: where is equal to 1 if some aiβ=β1, otherwise it is equal to 0.Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1ββ€βiββ€βm) and column j (1ββ€βjββ€βn) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula:.(Bij is OR of all elements in row i and column j of matrix A)Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. | 256 megabytes | import java.io.*;
import java.math.*;
import java.util.*;
public class B_orInMatrix {
public static void main(String[] args) throws IOException {
FastScanner sc = new FastScanner(System.in);
PrintWriter pw = new PrintWriter(System.out);
int m = sc.nextInt();
int n = sc.nextInt();
int[][] arr = new int[m][n];
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[0].length; j++) {
arr[i][j] = sc.nextInt();
}
}
int[][] oldArr = new int[m][n];
for (int i = 0; i < oldArr.length; i++ ) {
for (int j = 0; j < oldArr[0].length; j++) {
oldArr[i][j] = 1;
}
}
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[0].length; j++) {
if (arr[i][j] == 0) {
for (int k = 0; k < arr[0].length; k++) {
oldArr[i][k] = 0;
}
for (int k = 0; k < arr.length; k++) {
oldArr[k][j] = 0;
}
}
}
}
int[][] copy = new int[m][n];
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[0].length; j++) {
if (oldArr[i][j] == 1) {
for (int k = 0; k < arr[0].length; k++) {
copy[i][k] = 1;
}
for (int k = 0; k < arr.length; k++) {
copy[k][j] = 1;
}
}
}
}
boolean same = true;
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[0].length; j++) {
if (arr[i][j] != copy[i][j]) {
same = false;
}
}
}
if (!same) {
pw.println("NO");
}
else {
pw.println("YES");
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[0].length; j++) {
pw.print(oldArr[i][j] + " ");
}
pw.println();
}
}
pw.close();
}
static class FastScanner {
private boolean finished = false;
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public FastScanner(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public int peek() {
if (numChars == -1) {
return -1;
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
return -1;
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar];
}
public int nextInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public String nextString() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
if (Character.isValidCodePoint(c)) {
res.appendCodePoint(c);
}
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null) {
return filter.isSpaceChar(c);
}
return isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private String readLine0() {
StringBuilder buf = new StringBuilder();
int c = read();
while (c != '\n' && c != -1) {
if (c != '\r') {
buf.appendCodePoint(c);
}
c = read();
}
return buf.toString();
}
public String readLine() {
String s = readLine0();
while (s.trim().length() == 0) {
s = readLine0();
}
return s;
}
public String readLine(boolean ignoreEmptyLines) {
if (ignoreEmptyLines) {
return readLine();
} else {
return readLine0();
}
}
public BigInteger readBigInteger() {
try {
return new BigInteger(nextString());
} catch (NumberFormatException e) {
throw new InputMismatchException();
}
}
public char nextCharacter() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
return (char) c;
}
public double nextDouble() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E') {
return res * Math.pow(10, nextInt());
}
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
}
if (c == '.') {
c = read();
double m = 1;
while (!isSpaceChar(c)) {
if (c == 'e' || c == 'E') {
return res * Math.pow(10, nextInt());
}
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public boolean isExhausted() {
int value;
while (isSpaceChar(value = peek()) && value != -1) {
read();
}
return value == -1;
}
public String next() {
return nextString();
}
public SpaceCharFilter getFilter() {
return filter;
}
public void setFilter(SpaceCharFilter filter) {
this.filter = filter;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
public int[] nextIntArray(int n){
int[] array=new int[n];
for(int i=0;i<n;++i)array[i]=nextInt();
return array;
}
public int[] nextSortedIntArray(int n){
int array[]=nextIntArray(n);
PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
for(int i = 0; i < n; i++){
pq.add(array[i]);
}
int[] out = new int[n];
for(int i = 0; i < n; i++){
out[i] = pq.poll();
}
return out;
}
public int[] nextSumIntArray(int n){
int[] array=new int[n];
array[0]=nextInt();
for(int i=1;i<n;++i)array[i]=array[i-1]+nextInt();
return array;
}
public ArrayList<Integer>[] nextGraph(int n, int m){
ArrayList<Integer>[] adj = new ArrayList[n];
for(int i = 0; i < n; i++){
adj[i] = new ArrayList<Integer>();
}
for(int i = 0; i < m; i++){
int u = nextInt(); int v = nextInt();
u--; v--;
adj[u].add(v); adj[v].add(u);
}
return adj;
}
public ArrayList<Integer>[] nextTree(int n){
return nextGraph(n, n-1);
}
public long[] nextLongArray(int n){
long[] array=new long[n];
for(int i=0;i<n;++i)array[i]=nextLong();
return array;
}
public long[] nextSumLongArray(int n){
long[] array=new long[n];
array[0]=nextInt();
for(int i=1;i<n;++i)array[i]=array[i-1]+nextInt();
return array;
}
public long[] nextSortedLongArray(int n){
long array[]=nextLongArray(n);
Arrays.sort(array);
return array;
}
}
static void shuffle(int[] a) {
Random get = new Random();
for (int i = 0; i < a.length; i++) {
int r = get.nextInt(a.length);
int temp = a[i];
a[i] = a[r];
a[r] = temp;
}
}
static void shuffle(long[] a) {
Random get = new Random();
for (int i = 0; i < a.length; i++) {
int r = get.nextInt(a.length);
long temp = a[i];
a[i] = a[r];
a[r] = temp;
}
}
} | Java | ["2 2\n1 0\n0 0", "2 3\n1 1 1\n1 1 1", "2 3\n0 1 0\n1 1 1"] | 1 second | ["NO", "YES\n1 1 1\n1 1 1", "YES\n0 0 0\n0 1 0"] | null | Java 11 | standard input | [
"implementation",
"hashing",
"greedy"
] | bacd613dc8a91cee8bef87b787e878ca | The first line contains two integer m and n (1ββ€βm,βnββ€β100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). | 1,300 | In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. | standard output | |
PASSED | f38f325049cc0c099bf6ce30646c89fd | train_003.jsonl | 1415718000 | Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0,β1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: where is equal to 1 if some aiβ=β1, otherwise it is equal to 0.Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1ββ€βiββ€βm) and column j (1ββ€βjββ€βn) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula:.(Bij is OR of all elements in row i and column j of matrix A)Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. | 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
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();int m=sc.nextInt();
int b[][]=new int[n][m];
boolean row[]=new boolean[n];
boolean col[]=new boolean[m];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
b[i][j]=sc.nextInt();
if(b[i][j]==0){row[i]=true;col[j]=true;}
}
}
//System.out.println(row[5]+" "+col[5]);
boolean k=false;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(b[i][j]==1){if(row[i]&&col[j]) {k=true;break;}}
}
}
int c1=0,c2=0;
for(int i=0;i<n;i++){if(!row[i])c1++;}
for(int i=0;i<m;i++){if(!col[i])c2++;}
if((c1!=0&&c2==0)||(c2!=0&&c1==0)){k=true;}
// System.out.println(k);
if(k) {System.out.println("NO");}
else{
System.out.println("YES");
for(int i=0;i<n;i++){
if(row[i])
for(int j=0;j<m;j++){b[i][j]=0;}
}
for(int j=0;j<m;j++){
if(col[j])
for(int i=0;i<n;i++){b[i][j]=0;}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
System.out.print(b[i][j]+" ");
}
System.out.println();
}
}
}
}
| Java | ["2 2\n1 0\n0 0", "2 3\n1 1 1\n1 1 1", "2 3\n0 1 0\n1 1 1"] | 1 second | ["NO", "YES\n1 1 1\n1 1 1", "YES\n0 0 0\n0 1 0"] | null | Java 11 | standard input | [
"implementation",
"hashing",
"greedy"
] | bacd613dc8a91cee8bef87b787e878ca | The first line contains two integer m and n (1ββ€βm,βnββ€β100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). | 1,300 | In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. | standard output | |
PASSED | 415c9774cddddb7e6f2c5ae63941582c | train_003.jsonl | 1415718000 | Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0,β1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: where is equal to 1 if some aiβ=β1, otherwise it is equal to 0.Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1ββ€βiββ€βm) and column j (1ββ€βjββ€βn) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula:.(Bij is OR of all elements in row i and column j of matrix A)Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. | 256 megabytes | import java.util.*;
public class MyClass {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n= sc.nextInt();
int m= sc.nextInt();
int a[][] = new int [n][m];
int b[][] = new int [n][m];
int i,j,ones=0;
int f=0;
for(i=0;i<n;i++){
for(j=0;j<m;j++)
a[i][j]=sc.nextInt();
}
for(i=0;i<n;i++){
for(j=0;j<m;j++){
if(a[i][j]==1){
++ones;
if(check(a,i,j,n,m,b)==2){
f = 2;
break;
}
}
}
}
if(f!=2||ones==0){
System.out.println("YES");
for(i=0;i<n;i++){
for(j=0;j<m;j++){
System.out.print(b[i][j]+" ");
}
System.out.println();
}
}
else{
System.out.println("NO");
}
}
static int check(int a[][], int i,int j, int n ,int m, int b[][]){
int one=0,zero=0;
//left
for(int k =j-1;k>=0;k--){
if(a[i][k]==0){
a[i][j]=-1;
++zero;
break;
}
if(a[i][k]==1){
++one;
}
}
//right
for(int k =j+1;k<m;k++){
if(a[i][k]==0){
a[i][j]=-1;
++zero;
break;
}
if(a[i][k]==1){
++one;
}
}
;
//top
for(int k =i-1;k>=0;k--){
if(a[k][j]==0){
a[i][j]=-1;
++zero;
break;
}
if(a[k][j]==1){
++one;
break;
}
}
//bottom
for(int k =i+1;k<n;k++){
if(a[k][j]==0){
a[i][j]=-1;
++zero;
break;
}
if(a[k][j]==1){
++one;
}
}
if(one==0&&zero!=0)
return 2;
else if(one!=0&&zero!=0)
return 1;
else{
b[i][j]=1;
return 0;
}
}
} | Java | ["2 2\n1 0\n0 0", "2 3\n1 1 1\n1 1 1", "2 3\n0 1 0\n1 1 1"] | 1 second | ["NO", "YES\n1 1 1\n1 1 1", "YES\n0 0 0\n0 1 0"] | null | Java 11 | standard input | [
"implementation",
"hashing",
"greedy"
] | bacd613dc8a91cee8bef87b787e878ca | The first line contains two integer m and n (1ββ€βm,βnββ€β100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). | 1,300 | In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. | standard output | |
PASSED | 3a3df9d13bf2ada665eda4b8e435aedb | train_003.jsonl | 1415718000 | Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0,β1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: where is equal to 1 if some aiβ=β1, otherwise it is equal to 0.Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1ββ€βiββ€βm) and column j (1ββ€βjββ€βn) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula:.(Bij is OR of all elements in row i and column j of matrix A)Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. | 256 megabytes |
import java.util.*;
import java.io.*;
public class OR_In_Matrix {
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) {
// TODO Auto-generated method stub
FastReader t = new FastReader();
PrintWriter o = new PrintWriter(System.out);
int m = t.nextInt();
int n = t.nextInt();
int[][] a = new int[m][n];
int[][] b = new int[m][n];
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j) {
a[i][j] = t.nextInt();
b[i][j] = 1;
}
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (a[i][j] == 0) {
for (int k = 0; k < n; k++) {
b[i][k] = 0;
}
for (int k = 0; k < m; k++) {
b[k][j] = 0;
}
}
}
}
boolean res = true;
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (a[i][j] == 1) {
res = false;
for (int k = 0; k < n; k++) {
if (b[i][k] == 1) {
res = true;
}
}
for (int k = 0; k < m; k++) {
if (b[k][j] == 1) {
res = true;
}
}
}
if (!res) {
break;
}
}
if (!res)
break;
}
if (res) {
o.println("YES");
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
o.print(b[i][j] + " ");
}
o.println();
}
} else
o.println("NO");
o.flush();
o.close();
}
}
| Java | ["2 2\n1 0\n0 0", "2 3\n1 1 1\n1 1 1", "2 3\n0 1 0\n1 1 1"] | 1 second | ["NO", "YES\n1 1 1\n1 1 1", "YES\n0 0 0\n0 1 0"] | null | Java 11 | standard input | [
"implementation",
"hashing",
"greedy"
] | bacd613dc8a91cee8bef87b787e878ca | The first line contains two integer m and n (1ββ€βm,βnββ€β100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). | 1,300 | In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. | standard output | |
PASSED | 9d91692d4fbe4fb00c0031ba33b6860d | train_003.jsonl | 1415718000 | Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0,β1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: where is equal to 1 if some aiβ=β1, otherwise it is equal to 0.Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1ββ€βiββ€βm) and column j (1ββ€βjββ€βn) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula:.(Bij is OR of all elements in row i and column j of matrix A)Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. | 256 megabytes | import java.io.*;
import java.util.*;
public class OR_Mtx
{
public static void main(String[] args)throws IOException
{
BufferedReader ob=new BufferedReader(new InputStreamReader(System.in));
String s[]=ob.readLine().split(" ");
int n=Integer.parseInt(s[0]);
int m=Integer.parseInt(s[1]);
int b[][]=new int[n][m];
int a[][]=new int[n][m];
for(int i=0;i<n;i++)
{
String str[]=ob.readLine().split(" ");
for(int j=0;j<m;j++)
{
b[i][j]=Integer.parseInt(str[j]);
a[i][j]=1;
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(b[i][j]==0)
{
change(a,i,j,n,m);
}
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(b[i][j]==1)
{
boolean x=check(a,i,j,n,m);
if(!x)
{
System.out.println("NO");
return;
}
}
}
}
System.out.println("YES");
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
System.out.print(a[i][j]+" ");
}
System.out.println();
}
}
public static void change(int a[][],int i,int j,int n,int m)
{
for(int k=0;k<m;k++)
{
a[i][k]=0;
}
for(int k=0;k<n;k++)
{
a[k][j]=0;
}
}
public static boolean check(int a[][],int i,int j,int n,int m)
{
for(int k=0;k<m;k++)
{
if(a[i][k]==1)
return true;
}
for(int k=0;k<n;k++)
{
if(a[k][j]==1)
return true;
}
return false;
}
} | Java | ["2 2\n1 0\n0 0", "2 3\n1 1 1\n1 1 1", "2 3\n0 1 0\n1 1 1"] | 1 second | ["NO", "YES\n1 1 1\n1 1 1", "YES\n0 0 0\n0 1 0"] | null | Java 11 | standard input | [
"implementation",
"hashing",
"greedy"
] | bacd613dc8a91cee8bef87b787e878ca | The first line contains two integer m and n (1ββ€βm,βnββ€β100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). | 1,300 | In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. | standard output | |
PASSED | ad40cf383c308bd9ab973c12f28c74c6 | train_003.jsonl | 1415718000 | Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0,β1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: where is equal to 1 if some aiβ=β1, otherwise it is equal to 0.Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1ββ€βiββ€βm) and column j (1ββ€βjββ€βn) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula:.(Bij is OR of all elements in row i and column j of matrix A)Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
public class zizo {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int m = sc.nextInt(), n = sc.nextInt();
int[][] mat = new int[m][n], ans = new int[m][n];
boolean[][] safe = new boolean[m][n];
for(int i = 0; i < m; i++)
for(int j = 0; j < n; j++)
mat[i][j] = sc.nextInt();
for(int i = 0; i < m; i++) {
for(int j = 0; j < n; j++) {
if(mat[i][j] == 0) {
safe[i][j] = true;
continue;
}
safe[i][j] = safe[i][j] ? true : check(i, j, mat);
if(check(i, j, mat)) {
makeSafe(i, j, safe);
ans[i][j] = 1;
}
}
}
boolean mistake = true;
for(int i = 0; i < m; i++)
for(int j = 0; j < n; j++)
mistake&=safe[i][j];
if(!mistake)
out.println("NO");
else {
out.println("YES");
for(int i = 0; i < m; i++) {
for(int j = 0; j < n; j++)
out.print(ans[i][j] + (j == n - 1 ? "" : " "));
out.println();
}
}
out.flush();
out.close();
}
public static boolean check(int r, int c, int[][] mat) {
for (int i = 0; i < mat[0].length; i++)
if (mat[r][i] == 0)
return false;
for (int i = 0; i < mat.length; i++)
if (mat[i][c] == 0)
return false;
return true;
}
public static void makeSafe(int r, int c, boolean[][] safe) {
for (int i = 0; i < safe[0].length; i++)
safe[r][i] = true;
for (int i = 0; i < safe.length; i++)
safe[i][c] = true;
}
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 long nextLong() throws IOException {
return Long.parseLong(next());
}
public String nextLine() throws IOException {
return br.readLine();
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public boolean ready() throws IOException {
return br.ready();
}
}
} | Java | ["2 2\n1 0\n0 0", "2 3\n1 1 1\n1 1 1", "2 3\n0 1 0\n1 1 1"] | 1 second | ["NO", "YES\n1 1 1\n1 1 1", "YES\n0 0 0\n0 1 0"] | null | Java 11 | standard input | [
"implementation",
"hashing",
"greedy"
] | bacd613dc8a91cee8bef87b787e878ca | The first line contains two integer m and n (1ββ€βm,βnββ€β100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). | 1,300 | In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. | standard output | |
PASSED | 8e74d75c13c6110dda941462528275bd | train_003.jsonl | 1415718000 | Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0,β1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: where is equal to 1 if some aiβ=β1, otherwise it is equal to 0.Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1ββ€βiββ€βm) and column j (1ββ€βjββ€βn) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula:.(Bij is OR of all elements in row i and column j of matrix A)Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. | 256 megabytes |
/**
* @author egaeus
* @mail sebegaeusprogram@gmail.com
* @veredict Not sended
* @url <https://codeforces.com/problemset/problem/486/B>
* @category biginteger
* @date 6/06/2020
**/
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import static java.lang.Integer.*;
import static java.lang.Math.*;
public class CF486B {
public static void main(String args[]) throws Throwable {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
for (String ln; (ln = in.readLine()) != null && !ln.equals(""); ) {
StringTokenizer st = new StringTokenizer(ln);
int N = parseInt(st.nextToken()), M = parseInt(st.nextToken());
int[] rows = new int[N];
int[] cols = new int[M];
int[][] mat = new int[N][M];
for (int i = 0; i < N; i++) {
st = new StringTokenizer(in.readLine());
for (int j = 0; j < M; j++) {
int v = parseInt(st.nextToken());
rows[i] += v;
cols[j] += v;
mat[i][j] = v;
}
}
int[][] solution = new int[N][M];
boolean[] row = new boolean[N];
boolean[] col = new boolean[M];
for (int i = 0; i < N; i++)
for (int j = 0; j < M; j++) {
if (rows[i] == M && cols[j] == N) {
solution[i][j] = 1;
row[i] = true;
col[j] = true;
}
}
boolean ws = true;
for (int i = 0; i < N; i++)
for (int j = 0; j < M; j++) {
if (mat[i][j] == 1 && !row[i] && !col[j])
ws = false;
if (mat[i][j] == 0 && (row[i] || col[j]))
ws = false;
}
if (ws) {
System.out.println("YES");
for (int[] a : solution)
System.out.println(IntStream.of(a).mapToObj(c -> c + "").collect(Collectors.joining(" ")));
} else System.out.println("NO");
}
}
}
| Java | ["2 2\n1 0\n0 0", "2 3\n1 1 1\n1 1 1", "2 3\n0 1 0\n1 1 1"] | 1 second | ["NO", "YES\n1 1 1\n1 1 1", "YES\n0 0 0\n0 1 0"] | null | Java 11 | standard input | [
"implementation",
"hashing",
"greedy"
] | bacd613dc8a91cee8bef87b787e878ca | The first line contains two integer m and n (1ββ€βm,βnββ€β100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). | 1,300 | In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. | standard output | |
PASSED | c0413772edf1b9ee3c477b8f15a745a3 | train_003.jsonl | 1415718000 | Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0,β1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: where is equal to 1 if some aiβ=β1, otherwise it is equal to 0.Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1ββ€βiββ€βm) and column j (1ββ€βjββ€βn) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula:.(Bij is OR of all elements in row i and column j of matrix A)Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. | 256 megabytes |
import java.util.*;
public class contest1 {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int m = s.nextInt();
int n = s.nextInt();
int arr[][] = new int[m+1][n+1];
int arr1[][] = new int[m+1][n+1];
for(int i=1; i<m+1;i++) {
for(int j=1; j<n+1;j++) {
arr[i][j] = s.nextInt();
arr1[i][j] = 1;
}
}
int r = 0;
int c = 0;
int ci = 0;
int ri = 0;
String ans = "YES";
for(int i=1; i<m+1;i++) {
for(int j=1; j<n+1;j++) {
if(arr[i][j] == 0) {
ci = j;
for(int k=1;k<m+1;k++) {
arr1[k][ci] = 0;
}
}else {
continue;
}
}
}
for(int i=1; i<n+1;i++) {
for(int j=1; j<m+1;j++) {
if(arr[j][i] == 0) {
ri = j;
for(int k=1;k<n+1;k++) {
arr1[ri][k] = 0;
}
}
}
}
for(int i=1;i<m+1;i++) {
for(int j=1; j<n+1;j++) {
if(arr[i][j] == 1) {
int a = 0;
for(int k=1;k<m+1;k++) {
a+=arr1[k][j];
}
for(int k=1;k<n+1;k++) {
a+=arr1[i][k];
}
if(a==0) {
ans = "NO";
}
}
}
}
System.out.println(ans);
if(ans.equals("YES")) {
for(int i=1; i<m+1;i++) {
for(int j=1; j<n+1;j++) {
System.out.print(arr1[i][j] + " ");
}
System.out.println();
}
}
}
} | Java | ["2 2\n1 0\n0 0", "2 3\n1 1 1\n1 1 1", "2 3\n0 1 0\n1 1 1"] | 1 second | ["NO", "YES\n1 1 1\n1 1 1", "YES\n0 0 0\n0 1 0"] | null | Java 11 | standard input | [
"implementation",
"hashing",
"greedy"
] | bacd613dc8a91cee8bef87b787e878ca | The first line contains two integer m and n (1ββ€βm,βnββ€β100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). | 1,300 | In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. | standard output | |
PASSED | 82b7d42ddca9ed2211decb372a816642 | train_003.jsonl | 1415718000 | Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0,β1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: where is equal to 1 if some aiβ=β1, otherwise it is equal to 0.Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1ββ€βiββ€βm) and column j (1ββ€βjββ€βn) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula:.(Bij is OR of all elements in row i and column j of matrix A)Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. | 256 megabytes | import java.io.*;
import java.util.*;
public class B {
public static void main(String[] args) {
FastScanner sc = new FastScanner();
int n = sc.nextInt();
int m = sc.nextInt();
int[][] arr = new int[n][m];
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
arr[i][j] = sc.nextInt();
}
}
int[][] ans = new int[n][m];
for(int e[] : ans) {
Arrays.fill(e, 1);
}
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
if(arr[i][j] == 0) {
makeZero(ans,i,j);
}
}
}
boolean ok = false;
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
if(arr[i][j] == 1) {
if(!valid(ans,i,j)) {
System.out.println("NO");
ok = true;
break;
}
}
}
if(ok) {
break;
}
}
if(!ok) {
System.out.println("YES");
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
System.out.print(ans[i][j] + " ");
}
System.out.println();
}
}
}
private static boolean valid(int[][] ans, int i, int j) {
if(ans[i][j] == 1) {
return true;
}
for(int x = 0; x < ans[0].length; x++) {
if(ans[i][x] == 1) {
return true;
}
}
for(int x = 0; x < ans.length; x++) {
if(ans[x][j] == 1) {
return true;
}
}
return false;
}
private static void makeZero(int[][] ans, int i, int j) {
ans[i][j] = 0;
for(int x = 0; x < ans[0].length; x++) {
ans[i][x] = 0;
}
for(int x = 0; x < ans.length; x++) {
ans[x][j] = 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());
}
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 int gcd(int a, int b) {
return a%b == 0 ? b : gcd(b,a%b);
}
static boolean[] sieve(int n) {
boolean isPrime[] = new boolean[n+1];
for(int i = 2; i <= n; i++) {
if(isPrime[i]) continue;
for(int j = 2*i; j <= n; j+=i) {
isPrime[j] = true;
}
}
return isPrime;
}
} | Java | ["2 2\n1 0\n0 0", "2 3\n1 1 1\n1 1 1", "2 3\n0 1 0\n1 1 1"] | 1 second | ["NO", "YES\n1 1 1\n1 1 1", "YES\n0 0 0\n0 1 0"] | null | Java 11 | standard input | [
"implementation",
"hashing",
"greedy"
] | bacd613dc8a91cee8bef87b787e878ca | The first line contains two integer m and n (1ββ€βm,βnββ€β100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). | 1,300 | In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. | standard output | |
PASSED | 5a1723bb71e6a54eafecddaa54c0dba0 | train_003.jsonl | 1415718000 | Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0,β1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: where is equal to 1 if some aiβ=β1, otherwise it is equal to 0.Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1ββ€βiββ€βm) and column j (1ββ€βjββ€βn) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula:.(Bij is OR of all elements in row i and column j of matrix A)Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. | 256 megabytes | import java.util.*;
public class hero{
public static void main(String[] args) {
Scanner no=new Scanner(System.in);
boolean t=true;
boolean w=false;
int m=no.nextInt();
int n=no.nextInt();
int u=0;
int arr[][]=new int[m][n];
int arr1[][]=new int[m][n];
//int arr2[][]=new int[m][n];
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
arr1[i][j]=1;
}
}
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
arr[i][j]=no.nextInt();
if(arr[i][j]==0){
Arrays.fill(arr1[i],0);
for(int k=0;k<m;k++){
arr1[k][j]=0;
}
}
else{
w=true;
}
}
}
int o=0;
outer:for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
if(arr[i][j]==1){
for(int k=0;k<n;k++){
/*if(arr[i][k]!=1){
t=false;
System.out.println("NO");
break outer;
}*/
o=o+arr1[i][k];
}
for(int k=0;k<m;k++){
/*if(arr[k][j]!=1){
t=false;
System.out.println("NO");
break outer;
}*/
o=o+arr1[k][j];
}
if(o==0){
t=false;
}
o=0;
}
}
}
//System.out.println(t);
if(t){
System.out.println("YES");
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
System.out.print(arr1[i][j]+" ");
}
System.out.println();
}
}
else{
System.out.println("NO");
}
}} | Java | ["2 2\n1 0\n0 0", "2 3\n1 1 1\n1 1 1", "2 3\n0 1 0\n1 1 1"] | 1 second | ["NO", "YES\n1 1 1\n1 1 1", "YES\n0 0 0\n0 1 0"] | null | Java 11 | standard input | [
"implementation",
"hashing",
"greedy"
] | bacd613dc8a91cee8bef87b787e878ca | The first line contains two integer m and n (1ββ€βm,βnββ€β100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). | 1,300 | In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. | standard output | |
PASSED | 5fee314d99b023565ed5ef7b3ecebaec | train_003.jsonl | 1415718000 | Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0,β1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: where is equal to 1 if some aiβ=β1, otherwise it is equal to 0.Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1ββ€βiββ€βm) and column j (1ββ€βjββ€βn) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula:.(Bij is OR of all elements in row i and column j of matrix A)Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. | 256 megabytes | import java.io.*;
import java.util.*;
public class OR_Mtx
{
public static void main(String[] args)throws IOException
{
BufferedReader ob=new BufferedReader(new InputStreamReader(System.in));
String s[]=ob.readLine().split(" ");
int n=Integer.parseInt(s[0]);
int m=Integer.parseInt(s[1]);
int b[][]=new int[n][m];
int a[][]=new int[n][m];
for(int i=0;i<n;i++)
{
String str[]=ob.readLine().split(" ");
for(int j=0;j<m;j++)
{
b[i][j]=Integer.parseInt(str[j]);
a[i][j]=1;
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(b[i][j]==0)
{
change(a,i,j,n,m);
}
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(b[i][j]==1)
{
boolean x=check(a,i,j,n,m);
if(!x)
{
System.out.println("NO");
return;
}
}
}
}
System.out.println("YES");
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
System.out.print(a[i][j]+" ");
}
System.out.println();
}
}
public static void change(int a[][],int i,int j,int n,int m)
{
for(int k=0;k<m;k++)
{
a[i][k]=0;
}
for(int k=0;k<n;k++)
{
a[k][j]=0;
}
}
public static boolean check(int a[][],int i,int j,int n,int m)
{
for(int k=0;k<m;k++)
{
if(a[i][k]==1)
return true;
}
for(int k=0;k<n;k++)
{
if(a[k][j]==1)
return true;
}
return false;
}
} | Java | ["2 2\n1 0\n0 0", "2 3\n1 1 1\n1 1 1", "2 3\n0 1 0\n1 1 1"] | 1 second | ["NO", "YES\n1 1 1\n1 1 1", "YES\n0 0 0\n0 1 0"] | null | Java 11 | standard input | [
"implementation",
"hashing",
"greedy"
] | bacd613dc8a91cee8bef87b787e878ca | The first line contains two integer m and n (1ββ€βm,βnββ€β100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). | 1,300 | In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. | standard output | |
PASSED | 3dd8e9396cd6784b73fe95fcbff57f6c | train_003.jsonl | 1415718000 | Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0,β1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: where is equal to 1 if some aiβ=β1, otherwise it is equal to 0.Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1ββ€βiββ€βm) and column j (1ββ€βjββ€βn) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula:.(Bij is OR of all elements in row i and column j of matrix A)Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. | 256 megabytes | import java.util.*;
import java.math.*;
import java.io.*;
public class A{
final int N = 10000;
static int cnt[]=new int[27];
static int n;
static String multiply(String num1, String num2)
{
int len1 = num1.length();
int len2 = num2.length();
if (len1 == 0 || len2 == 0)
return "0";
// will keep the result number in vector
// in reverse order
int result[] = new int[len1 + len2];
// Below two indexes are used to
// find positions in result.
int i_n1 = 0;
int i_n2 = 0;
// Go from right to left in num1
for (int i = len1 - 1; i >= 0; i--)
{
int carry = 0;
int n1 = num1.charAt(i) - '0';
// To shift position to left after every
// multipliccharAtion of a digit in num2
i_n2 = 0;
// Go from right to left in num2
for (int j = len2 - 1; j >= 0; j--)
{
// Take current digit of second number
int n2 = num2.charAt(j) - '0';
// Multiply with current digit of first number
// and add result to previously stored result
// charAt current position.
int sum = n1 * n2 + result[i_n1 + i_n2] + carry;
// Carry for next itercharAtion
carry = sum / 10;
// Store result
result[i_n1 + i_n2] = sum % 10;
i_n2++;
}
// store carry in next cell
if (carry > 0)
result[i_n1 + i_n2] += carry;
// To shift position to left after every
// multipliccharAtion of a digit in num1.
i_n1++;
}
// ignore '0's from the right
int i = result.length - 1;
while (i >= 0 && result[i] == 0)
i--;
// If all were '0's - means either both
// or one of num1 or num2 were '0'
if (i == -1)
return "0";
// genercharAte the result String
String s = "";
while (i >= 0)
s += (result[i--]);
return s;
}
public static void main(String[] args) throws IOException
{
InputReader scan=new InputReader(System.in);
PrintWriter out=new PrintWriter(System.out);
int n=scan.nextInt();
int m=scan.nextInt();
int [][]matrix=new int [n][m];
int [][]helper=new int [n][m];
int [][]helper2=new int [n][m];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
helper[i][j]=1;
helper2[i][j]=0;
} }
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
int a=scan.nextInt();
matrix[i][j]=a;
if(a==0){
for(int l=0;l<n;l++){
// out.println(l+" "+j);
helper[l][j]=0;
}
for(int k=0;k<m;k++){
// out.println(i+" "+k);
helper[i][k]=0;
}
}
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(helper[i][j]==1){
for(int l=0;l<n;l++){
// out.println(l+" "+j);
helper2[l][j]=1;
}
for(int k=0;k<m;k++){
// out.println(i+" "+k);
helper2[i][k]=1;
}
}
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(helper2[i][j]!=matrix[i][j]){
out.println("NO");
out.close();
return;
}
}}
out.println("YES");
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
out.print(helper[i][j]+" ");
}
out.println();
}
out.close();
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public Double nextDouble() {
return Double.parseDouble(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public int[] nextIntArray(int arraySize) {
int array[] = new int[arraySize];
for (int i = 0; i < arraySize; i++) {
array[i] = nextInt();
}
return array;
}
}
static class pair{
int i;
int j;
pair(int i,int j){
this.i=i;
this.j=j;
}
}
}
| Java | ["2 2\n1 0\n0 0", "2 3\n1 1 1\n1 1 1", "2 3\n0 1 0\n1 1 1"] | 1 second | ["NO", "YES\n1 1 1\n1 1 1", "YES\n0 0 0\n0 1 0"] | null | Java 11 | standard input | [
"implementation",
"hashing",
"greedy"
] | bacd613dc8a91cee8bef87b787e878ca | The first line contains two integer m and n (1ββ€βm,βnββ€β100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). | 1,300 | In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. | standard output | |
PASSED | 16d527914123509f8dfa9aec2418a6e5 | train_003.jsonl | 1415718000 | Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0,β1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: where is equal to 1 if some aiβ=β1, otherwise it is equal to 0.Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1ββ€βiββ€βm) and column j (1ββ€βjββ€βn) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula:.(Bij is OR of all elements in row i and column j of matrix A)Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. | 256 megabytes | import java.io.*;
import java.lang.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
Scanner s = new Scanner(System.in);
int m=s.nextInt();
int n=s.nextInt();
int[][] arr = new int[m][n];
int[][] prr = new int[m][n];
for(int i=0;i<m;i++) {
for (int j = 0; j < n; j++) {
arr[i][j] = s.nextInt();
prr[i][j] = arr[i][j];
}
}
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
if(prr[i][j]==0){
for(int k=0;k<m;k++){
if(prr[k][j]!=0){
prr[k][j]=-1;
}
}
for(int k=0;k<n;k++){
if(prr[i][k]!=0){
prr[i][k]=-1;
}
}
}
}
}
boolean yes=true;
l: for(int i=0;i<m;i++){
m: for(int j=0;j<n;j++){
if(arr[i][j]==1){
for(int k=0;k<m;k++){
// if(k==i)
// continue;
if(prr[k][j]==1){
continue m;
}
}
for(int k=0;k<n;k++){
// if(k==j)
// continue;
if(prr[i][k]==1)
continue m;
}
// System.out.println(i+" "+j);
yes=false;
break l;
}
}
}
// for(int i=0;i<m;i++){
// for(int j=0;j<n;j++){
// System.out.print(prr[i][j]+" ");
// }
// System.out.println();
// }
if(!yes)
System.out.println("NO");
else{
System.out.println("YES");
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
if(prr[i][j]==-1)
System.out.print("0 ");
else
System.out.print(prr[i][j]+" ");
}
System.out.println();
}
}
}
}
| Java | ["2 2\n1 0\n0 0", "2 3\n1 1 1\n1 1 1", "2 3\n0 1 0\n1 1 1"] | 1 second | ["NO", "YES\n1 1 1\n1 1 1", "YES\n0 0 0\n0 1 0"] | null | Java 11 | standard input | [
"implementation",
"hashing",
"greedy"
] | bacd613dc8a91cee8bef87b787e878ca | The first line contains two integer m and n (1ββ€βm,βnββ€β100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). | 1,300 | In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. | standard output | |
PASSED | 713c8e44188b9700599db26cc19bffa0 | train_003.jsonl | 1415718000 | Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0,β1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: where is equal to 1 if some aiβ=β1, otherwise it is equal to 0.Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1ββ€βiββ€βm) and column j (1ββ€βjββ€βn) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula:.(Bij is OR of all elements in row i and column j of matrix A)Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;
public class sa {
public static void helper(int [][]arr,int n,int m,int c1,int[][]ans){
if(n==1 && m==1) {
System.out.println("YES");
System.out.println(arr[0][0]);
return;
}
if(c1==n*m) {
System.out.println("YES");
for(int i=0;i<n;i++) {
for(int j=0;j<m;j++) {
System.out.print(1+" ");
}
System.out.println();
}
return;
}
if(c1==0) {
System.out.println("YES");
for(int i=0;i<n;i++) {
for(int j=0;j<m;j++) {
System.out.print(0+" ");
}
System.out.println();
}
return;
}
HashSet<Integer> rows=new HashSet<>();
HashSet<Integer> columns=new HashSet<>();
for(int i=0;i<n;i++) {
for(int j=0;j<m;j++) {
if(arr[i][j]==0) {
rows.add(i);
columns.add(j);
}
}
}
HashSet<Integer> rows2=new HashSet<>();
HashSet<Integer> columns2=new HashSet<>();
for(int i=0;i<n;i++) {
for(int j=0;j<m;j++) {
if(rows.contains(i) || columns.contains(j)) {
ans[i][j]=0;
}
else {
ans[i][j]=1;
rows2.add(i);
columns2.add(j);
}
}
}
for(int i=0;i<n;i++) {
for(int j=0;j<m;j++) {
if(arr[i][j]==1) {
if(rows2.contains(i) || columns2.contains(j))
continue;
else {
System.out.println("NO");
return;
}
}
}
}
System.out.println("YES");
for(int i=0;i<n;i++) {
for(int j=0;j<m;j++)
System.out.print(ans[i][j]+" ");
System.out.println();
}
}
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
Reader.init(System.in);
int n=Reader.nextInt();
int m=Reader.nextInt();
int arr[][]=new int[n][m];
int ans[][]=new int[n][m];
int c1=0;
for(int i=0;i<n;i++) {
for(int j=0;j<m;j++) {
arr[i][j]=Reader.nextInt();
if(arr[i][j]==1)
c1++;
}
}
helper(arr,n,m,c1,ans);
}
}
class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(
new InputStreamReader(input) );
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while ( !tokenizer.hasMoreTokens() ) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(
reader.readLine() );
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt(next());
}
static double nextDouble() throws IOException {
return Double.parseDouble(next());
}
}
| Java | ["2 2\n1 0\n0 0", "2 3\n1 1 1\n1 1 1", "2 3\n0 1 0\n1 1 1"] | 1 second | ["NO", "YES\n1 1 1\n1 1 1", "YES\n0 0 0\n0 1 0"] | null | Java 11 | standard input | [
"implementation",
"hashing",
"greedy"
] | bacd613dc8a91cee8bef87b787e878ca | The first line contains two integer m and n (1ββ€βm,βnββ€β100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). | 1,300 | In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. | standard output | |
PASSED | ef3725f3362bfe4cc0e6fc8497383661 | train_003.jsonl | 1415718000 | Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0,β1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: where is equal to 1 if some aiβ=β1, otherwise it is equal to 0.Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1ββ€βiββ€βm) and column j (1ββ€βjββ€βn) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula:.(Bij is OR of all elements in row i and column j of matrix A)Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. | 256 megabytes | import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public final class ORInMatrix {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int m=sc.nextInt();
int b[][]=new int[n][m];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
b[i][j]=sc.nextInt();
}
}
boolean ok=true;
int a[][]=new int[n][m];
for(int arr[]:a)
Arrays.fill(arr,-1);
ArrayList<Integer> row=new ArrayList<>();
ArrayList<Integer> col=new ArrayList<>();
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(b[i][j]==0){
fillA(a,n,m,i,j);
}else{
BoolPair p= helper(b,n,m,i,j);
if(!p.ok1 && !p.ok2){
ok=false;
break;
}else{
row.add(i);
col.add(j);
}
}
}
}
if(ok){
for(int i=0;i<row.size();i++){
int ii=row.get(i);
int jj=col.get(i);
if(!helper2(a,n,m,ii,jj)){
ok=false;
break;
}
}
}
if(ok){
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(a[i][j]==-1){
a[i][j]=1;
}
}
}
}
if(ok){
System.out.println("YES");
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
System.out.print(a[i][j]+" ");
}
System.out.println();
}
}else{
System.out.println("NO");
}
}
private static boolean helper2(int[][] a, int n, int m, int i, int j) {
int top=i,bottom=i+1;
while (top>=0 || bottom<n){
if(top>=0 && a[top][j]==-1) return true;
if(bottom<n && a[bottom][j]==-1) return true;
top--;
bottom++;
}
int left=j,right=j+1;
while (left>=0 || right<m){
if(left>=0 && a[i][left]==-1) return true;
if(right<m && a[i][right]==-1) return true;
left--;
right++;
}
return false;
}
private static BoolPair helper(int[][] a, int n, int m, int i, int j) {
boolean ok1=false,ok2=false;
int top=i,bottom=i+1;
int cnt=0;
while (top>=0 || bottom<n){
if(top>=0 && a[top][j]==1) cnt++;
if(bottom<n && a[bottom][j]==1) cnt++;
top--;
bottom++;
}
if(cnt==n)
ok1=true;
cnt=0;
int left=j,right=j+1;
while (left>=0 || right<m){
if(left>=0 && a[i][left]==1) cnt++;
if(right<m && a[i][right]==1) cnt++;
left--;
right++;
}
if(cnt==m)
ok2=true;
return new BoolPair(ok1,ok2);
}
private static void fillA(int[][] a, int n, int m, int i, int j) {
int top=i,bottom=i;
while (top>=0 || bottom<n){
if(top>=0)
a[top][j]=0;
if(bottom<n)
a[bottom][j]=0;
top--;
bottom++;
}
int left=j,right=j;
while (left>=0 || right<m){
if(left>=0)
a[i][left]=0;
if(right<m)
a[i][right]=0;
left--;
right++;
}
}
}
class BoolPair{
boolean ok1,ok2;
public BoolPair(boolean ok1,boolean ok2){
this.ok1=ok1;
this.ok2=ok2;
}
}
| Java | ["2 2\n1 0\n0 0", "2 3\n1 1 1\n1 1 1", "2 3\n0 1 0\n1 1 1"] | 1 second | ["NO", "YES\n1 1 1\n1 1 1", "YES\n0 0 0\n0 1 0"] | null | Java 11 | standard input | [
"implementation",
"hashing",
"greedy"
] | bacd613dc8a91cee8bef87b787e878ca | The first line contains two integer m and n (1ββ€βm,βnββ€β100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). | 1,300 | In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. | standard output | |
PASSED | d24e88ac1f6541cd80c9d9f2da5ccadc | train_003.jsonl | 1415718000 | Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0,β1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: where is equal to 1 if some aiβ=β1, otherwise it is equal to 0.Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1ββ€βiββ€βm) and column j (1ββ€βjββ€βn) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula:.(Bij is OR of all elements in row i and column j of matrix A)Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. | 256 megabytes | import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int a[] = new int[2];
List<Integer> row = new ArrayList<>();
List<Integer> col = new ArrayList<>();
int d[][] = new int[n][m];
for(int i=0;i<n;i++)
{
int c=0;
for(int j=0;j<m;j++)
{
d[i][j] = sc.nextInt();
a[d[i][j]]++;
if(d[i][j] == 1) c++;
if(c==m) row.add(i);
}
}
for(int i=0;i<m;i++)
{
int c1=0;
for(int j=0;j<n;j++)
{
if(d[j][i] == 1) c1++;
if(c1==n) col.add(i);
}
}
if((a[1] != ((n*col.size()) + (m*row.size()) - row.size()*col.size()) || col.size()==0 || row.size()==0) && (a[1]!=0)) System.out.println("NO");
else
{
System.out.println("YES");
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(row.contains(i) && col.contains(j)) System.out.print("1 ");
else System.out.print("0 ");
}
System.out.println();
}
}
}
}
| Java | ["2 2\n1 0\n0 0", "2 3\n1 1 1\n1 1 1", "2 3\n0 1 0\n1 1 1"] | 1 second | ["NO", "YES\n1 1 1\n1 1 1", "YES\n0 0 0\n0 1 0"] | null | Java 11 | standard input | [
"implementation",
"hashing",
"greedy"
] | bacd613dc8a91cee8bef87b787e878ca | The first line contains two integer m and n (1ββ€βm,βnββ€β100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). | 1,300 | In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. | standard output | |
PASSED | cc23441cadc6a8e2b25ed43d830f8602 | train_003.jsonl | 1415718000 | Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0,β1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: where is equal to 1 if some aiβ=β1, otherwise it is equal to 0.Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1ββ€βiββ€βm) and column j (1ββ€βjββ€βn) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula:.(Bij is OR of all elements in row i and column j of matrix A)Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int m,n;
m = scanner.nextInt();
n = scanner.nextInt();
int[][] b = new int[m][n];
int[][] a = new int[m][n];
for (int i=0;i<m;i++) {
for (int j=0;j<n;j++) {
b[i][j] = scanner.nextInt();
a[i][j] = 1;
}
}
for (int i=0;i<m;i++) {
for (int j=0;j<n;j++) {
if (b[i][j] == 0) {
for (int k=0;k<n;k++)
a[i][k] = 0;
for (int t=0;t<m;t++)
a[t][j] = 0;
}
}
}
if (canAProduceB(a,b,m,n)) {
System.out.println("YES");
for (int i=0;i<m;i++) {
for (int j=0;j<n;j++) {
System.out.print(a[i][j] + " ");
}
System.out.println();
}
}
else
System.out.println("NO");
}
public static boolean canAProduceB(int[][] a,int[][] b,int m,int n) {
int[][] c = new int[m][n];
for (int i=0;i<m;i++) {
for (int j=0;j<n;j++) {
for (int k=0;k<n;k++)
c[i][j] = c[i][j] | a[i][k];
for (int t=0;t<m;t++)
c[i][j] = c[i][j] | a[t][j];
}
}
for (int i=0;i<m;i++) {
for (int j=0;j<n;j++) {
if (c[i][j] != b[i][j])
return false;
}
}
return true;
}
}
| Java | ["2 2\n1 0\n0 0", "2 3\n1 1 1\n1 1 1", "2 3\n0 1 0\n1 1 1"] | 1 second | ["NO", "YES\n1 1 1\n1 1 1", "YES\n0 0 0\n0 1 0"] | null | Java 11 | standard input | [
"implementation",
"hashing",
"greedy"
] | bacd613dc8a91cee8bef87b787e878ca | The first line contains two integer m and n (1ββ€βm,βnββ€β100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). | 1,300 | In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. | standard output | |
PASSED | a6e469f0f1970e012590320b877af422 | train_003.jsonl | 1415718000 | Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0,β1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: where is equal to 1 if some aiβ=β1, otherwise it is equal to 0.Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1ββ€βiββ€βm) and column j (1ββ€βjββ€βn) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula:.(Bij is OR of all elements in row i and column j of matrix A)Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. | 256 megabytes |
import java.io.*;
import java.util.*;
import java.math.*;
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 int n, m;
static int[][] arr, original;
static boolean hasOne = false, noOne = true;
public static void main(String args[]) throws Exception {
FastReader cin = new FastReader();
n = cin.nextInt();
m = cin.nextInt();
arr = new int[n][m];
original = new int[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
arr[i][j] = cin.nextInt();
if (arr[i][j] == 1) {
noOne = false;
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (arr[i][j] == 1) {
if (!checkRow(i, j) && !checkCol(i, j)) {
System.out.println("NO");
return;
} else {
if (checkRow(i, j) && checkCol(i, j)) {
original[i][j] = 1;
hasOne = true;
}
}
}
}
}
if (!hasOne && !noOne) {
System.out.println("NO");
return;
}
System.out.println("YES");
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
System.out.print(original[i][j] + " ");
}
System.out.println();
}
}
public static boolean checkRow(int row, int col) {
for (int i = 0; i < n; i++) {
if (arr[i][col] != 1) {
return false;
}
}
return true;
}
public static boolean checkCol(int row, int col) {
for (int i = 0; i < m; i++) {
if (arr[row][i] != 1) {
return false;
}
}
return true;
}
} | Java | ["2 2\n1 0\n0 0", "2 3\n1 1 1\n1 1 1", "2 3\n0 1 0\n1 1 1"] | 1 second | ["NO", "YES\n1 1 1\n1 1 1", "YES\n0 0 0\n0 1 0"] | null | Java 11 | standard input | [
"implementation",
"hashing",
"greedy"
] | bacd613dc8a91cee8bef87b787e878ca | The first line contains two integer m and n (1ββ€βm,βnββ€β100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). | 1,300 | In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. | standard output | |
PASSED | b98be57da9a500ba498c3be60d09b363 | train_003.jsonl | 1415718000 | Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0,β1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: where is equal to 1 if some aiβ=β1, otherwise it is equal to 0.Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1ββ€βiββ€βm) and column j (1ββ€βjββ€βn) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula:.(Bij is OR of all elements in row i and column j of matrix A)Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. | 256 megabytes | import java.util.*;import java.io.*;import java.math.*;
public class ORinMatrix
{
public static void process()throws IOException
{
int m = ni(), n = ni();
int[][] b = new int[m][n];
for(int i = 0; i < m; i++){
b[i] = nai(n);
}
int f = 0;
int[][] c = new int[m][n];
int[][] a = new int[m][n];
for(int i = 0; i < m; i++)
Arrays.fill(a[i],1);
for(int i = 0; i < m; i++){
for(int j = 0; j < n; j++){
if(b[i][j] == 0){
Arrays.fill(a[i], 0);
for(int k = 0; k < m; k++){
a[k][j] = 0;
}
//break;
}
}
}
for(int i = 0; i < m; i++){
for(int j = 0; j < n; j++){
for(int k = 0; k < m; k++){
if(a[k][j] == 1){
c[i][j] = 1;
break;
}
}
for(int k = 0; k < n; k++){
if(a[i][k] == 1){
c[i][j] = 1;
break;
}
}
}
}
for(int i = 0; i < m; i++){
for(int j = 0; j < n; j++){
if(c[i][j] != b[i][j]){
pn("NO");
return;
}
}
}
pn("YES");
for(int i = 0; i < m; i++){
for(int j = 0; j < n; j++)
p(a[i][j] + " ");
pn("");
}
}
static AnotherReader sc;
static PrintWriter out;
public static void main(String[]args)throws IOException
{
boolean oj = System.getProperty("ONLINE_JUDGE") != null;
if(oj){sc=new AnotherReader();out=new PrintWriter(System.out);}
else{sc=new AnotherReader(100);out=new PrintWriter("output.txt");}
long s = System.currentTimeMillis();
int t=1;
//t=ni();
while(t-->0) {process();}
out.flush();
System.err.println(System.currentTimeMillis()-s+"ms");
out.close();
}
static void pn(Object o){out.println(o);}
static void p(Object o){out.print(o);}
static void pni(Object o){out.println(o);out.flush();}
static int ni()throws IOException{return sc.nextInt();}
static long nl()throws IOException{return sc.nextLong();}
static double nd()throws IOException{return sc.nextDouble();}
static String nln()throws IOException{return sc.nextLine();}
static int[] nai(int N)throws IOException{int[]A=new int[N];for(int i=0;i!=N;i++){A[i]=ni();}return A;}
static long[] nal(int N)throws IOException{long[]A=new long[N];for(int i=0;i!=N;i++){A[i]=nl();}return A;}
static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
static class AnotherReader{BufferedReader br; StringTokenizer st;
AnotherReader()throws FileNotFoundException{
br=new BufferedReader(new InputStreamReader(System.in));}
AnotherReader(int a)throws FileNotFoundException{
br = new BufferedReader(new FileReader("input.txt"));}
String next()throws IOException{
while (st == null || !st.hasMoreElements()) {try{
st = new StringTokenizer(br.readLine());}
catch (IOException e){ e.printStackTrace(); }}
return st.nextToken(); } int nextInt() throws IOException{
return Integer.parseInt(next());}
long nextLong() throws IOException
{return Long.parseLong(next());}
double nextDouble()throws IOException { return Double.parseDouble(next()); }
String nextLine() throws IOException{ String str = ""; try{
str = br.readLine();} catch (IOException e){
e.printStackTrace();} return str;}}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
} | Java | ["2 2\n1 0\n0 0", "2 3\n1 1 1\n1 1 1", "2 3\n0 1 0\n1 1 1"] | 1 second | ["NO", "YES\n1 1 1\n1 1 1", "YES\n0 0 0\n0 1 0"] | null | Java 11 | standard input | [
"implementation",
"hashing",
"greedy"
] | bacd613dc8a91cee8bef87b787e878ca | The first line contains two integer m and n (1ββ€βm,βnββ€β100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). | 1,300 | In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. | standard output | |
PASSED | 9511c540ce43ec6f4f7be9aee4d1ea5b | train_003.jsonl | 1415718000 | Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0,β1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: where is equal to 1 if some aiβ=β1, otherwise it is equal to 0.Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1ββ€βiββ€βm) and column j (1ββ€βjββ€βn) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula:.(Bij is OR of all elements in row i and column j of matrix A)Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. | 256 megabytes | import java.util.*;
public class helloWorld
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int m = in.nextInt();
int[][] A = new int[n][m];
int[][] B = new int[n][m];
String ans = "YES";
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++) {
B[i][j] = in.nextInt();
A[i][j] = 1;
}
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
if(B[i][j] == 0) {
for(int k = 0; k < n; k++)
A[k][j] = 0;
for(int k = 0; k < m; k++)
A[i][k] = 0;
}
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
if(B[i][j] == 1) {
int a = 0;
for(int k = 0; k < n; k++)
a += A[k][j];
for(int k = 0; k < m; k++)
a += A[i][k];
if(a == 0)
ans = "NO";
}
System.out.println(ans);
if(ans.equals("YES"))
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++)
System.out.printf(A[i][j] + " ");
System.out.println();
}
in.close();
}
}
| Java | ["2 2\n1 0\n0 0", "2 3\n1 1 1\n1 1 1", "2 3\n0 1 0\n1 1 1"] | 1 second | ["NO", "YES\n1 1 1\n1 1 1", "YES\n0 0 0\n0 1 0"] | null | Java 11 | standard input | [
"implementation",
"hashing",
"greedy"
] | bacd613dc8a91cee8bef87b787e878ca | The first line contains two integer m and n (1ββ€βm,βnββ€β100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). | 1,300 | In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. | standard output | |
PASSED | f153f0712e423a33246fa75e2269a0d8 | train_003.jsonl | 1415718000 | Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0,β1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: where is equal to 1 if some aiβ=β1, otherwise it is equal to 0.Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1ββ€βiββ€βm) and column j (1ββ€βjββ€βn) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula:.(Bij is OR of all elements in row i and column j of matrix A)Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. | 256 megabytes | // Author : AMIT KUMAR BARMAN (gearman_0712)
import java.io.*;
import java.util.*;
public class Ormatrix{
static final long modp =1000000007;
static long x_ec=1,y_ec=0,d_ec =1;
static long maxi=0;
static boolean v1 =false ,v2 = false;
static InputReader in = new InputReader(System.in);
static OutputStream outputStream = System.out;
static OutputWriter out = new OutputWriter(outputStream);
public static void main (String args[]) throws IOException {
int n= in.readInt();
int m= in.readInt();
int output[][] = new int[n][m];
int input[][] = new int[n][m];
for( int i=0;i<n;i++)
Arrays.fill(output[i],1);
for(int i=0;i<n;i++)
{ for(int j=0;j<m;j++)
{
input[i][j] = in.readInt();
if( input[i][j]==0)
{for( int k=0;k<m;k++)
output[i][k]=0;
for( int k=0;k<n;k++)
output[k][j]=0;
}
}
}
int flag=0,flag2=0;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
{ if( input[i][j]==1 )
{ flag=0;
for( int k=0;k<m;k++)
if(output[i][k]==1)
{flag=1;
}
for( int k=0;k<n;k++)
if(output[k][j]==1)
{flag=1;
}
if(flag==0)
flag2=1;
}
}
if(flag2==1)
out.print("NO");
else
{ out.println("YES");
for(int i=0;i<n;i++)
{for( int j=0;j<m;j++)
out.print(output[i][j]+" ");
out.println("");}
}
out.close();
}
/*
static Node lca(Node root,int x,int y)
{if(root==null)
return null;
if(root.value>x &&root.value>y )
return lca(root.left, x, y);
if(root.value<x &&root.value<y )
return lca(root.right, x, y);
return root;
}
static Node common(Node root,int x,int y)
{ if(root==null)
return null;
Node temp=null;
if(root.value ==x)
{ v1= true;
temp =new Node(x);
}
else if(root.value ==y)
{ v2= true;
temp =new Node(y);
}
Node lef =common(root.left, x, y);
Node rig =common(root.right, x, y);
if(temp!=null)
return temp;
if(lef ==null)
return rig;
if(rig==null)
return lef;
return root;
}
// static class Node {
// int value;
// Node left;
// Node right;
// Node(int value){
// this.value =value;
// right =null;
// left =null;
// }
// }
static Node insert(Node root,int v)
{ if(root==null)
return new Node(v);
if( v<=root.value)
root.left =insert(root.left, v);
else
root.right =insert(root.right,v);
return root;
}
static int minvalue(Node root)
{
while(root.left!=null)
root =root.left;
return root.value;
}
static Node delete(Node root ,int val)
{ if(root ==null)
return root;
if(val<root.value)
root.left=delete(root.left, val);
else if(val>root.value)
root.right =delete(root.right,val);
else {
if(root.left==null)
return root.right;
else if(root.right==null)
return root.left;
root.value= minvalue(root.right);
root.right =delete(root.right, root.value);
}
return root;
}
*/
/*
static void inorder(Node root,OutputWriter out)
{ if(root!=null)
{inorder(root.left ,out);
out.print(root.value+" ");
inorder(root.right, out);
}
}
static void preorder(Node root ,OutputWriter out)
{ if(root!=null)
{ out.println(root.value+" ");
preorder(root.left, out);
preorder(root.right,out);
}
}
static void postorder(Node root,OutputWriter out)
{ if(root!=null)
{ postorder(root.left, out);
postorder(root.right ,out);
out.print(root.value+" ");
}
}
*/
// Input: Indices Range [0..size]
// Invariant: A[l] <= key and A[r] > key
static long modExponential(long x,long n)
{long result =1l;
while(n>0l)
{ if(n%2==1)
result =(x*result)%modp;
x= (x*x)%modp;
n=n/2;
}
return result;
}
/*
static int GetRightPosition(int A[], int l, int r, int key)
{
int m;
while( r - l > 1 )
{
m = l + (r - l)/2;
if( A[m] <= key )
l = m;
else
r = m;
}
return l;
}
// Input: Indices Range -1 to size-1
// Invariant: A[r] >= key and A[l] > key
static int GetLeftPosition(int A[], int l, int r, int key)
{
int m;
while( r - l > 1 )
{
m = l + (r - l)/2;
if( A[m] >= key )
r = m;
else
l = m;
}
return r;
}
*/
public static long gcd(long a,long b)
{
if(b==0)
return a;
else
return gcd(b,a%b);
}
public static int gcd(int a,int b)
{
if(b==0)
return a;
else
return gcd(b,a%b);
}
public static int abs(int a,int b)
{
return (int)Math.abs(a-b);
}
public static long abs(long a,long b)
{
return (long)Math.abs(a-b);
}
public static int max(int a,int b)
{
if(a>b)
return a;
else
return b;
}
public static int min(int a,int b)
{
if(a>b)
return b;
else
return a;
}
public static long max(long a,long b)
{
if(a>b)
return a;
else
return b;
}
public static long min(long a,long b)
{
if(a>b)
return b;
else
return a;
}
/*
void countsort(int arr[],int n,int place)
{
int i,freq[range]={0}; //range for integers is 10 as digits range from 0-9
int output[n];
for(i=0;i<n;i++)
freq[(arr[i]/place)%range]++;
for(i=1;i<range;i++)
freq[i]+=freq[i-1];
for(i=n-1;i>=0;i--)
{
output[freq[(arr[i]/place)%range]-1]=arr[i];
freq[(arr[i]/place)%range]--;
}
for(i=0;i<n;i++)
arr[i]=output[i];
}
void radixsort(ll arr[],int n,int maxx) //maxx is the maximum element in the array
{
int mul=1;
while(maxx)
{
countsort(arr,n,mul);
mul*=10;
maxx/=10;
}
}*/
/* BufferedReader bf =new BufferedReader (new InputStreamReader(System.in));
int t= Integer.parseInt(bf.readLine());
StringBuffer gh =new StringBuffer("");
StringTokenizer tk=new StringTokenizer(bf.readLine());
long a= Long.parseLong(tk.nextToken());
*/
static class Pair implements Comparable<Pair>
{
int a,b;
Pair (int a,int b)
{
this.a=a;
this.b=b;
}
public int compareTo(Pair o) {
if(this.a!=o.a)
return -Integer.compare(this.a,o.a);
else
return Integer.compare(this.b, o.b);
//return 0;
}
public boolean equals(Object o) {
if (o instanceof Pair) {
Pair p = (Pair)o;
return p.a == a && p.b == b;
}
return false;
}
public int hashCode(Object o) {
Pair p = (Pair)o;
return p.a* 31 +p.b;
}
}
static class Pair1 implements Comparable<Pair1>
{
char a;
int b;
Pair1 (char a,int b)
{
this.a=a;
this.b=b;
}
public int compareTo(Pair1 o) {
if(this.a!=o.a)
return Integer.compare(this.a,o.a);
else
return Integer.compare(this.b, o.b);
//return 0;
}
public boolean equals(Object o) {
if (o instanceof Pair1) {
Pair1 p = (Pair1)o;
return p.a == a && p.b == b;
}
return false;
}
public int hashCode(Object o) {
Pair1 p = (Pair1)o;
return (int)p.a* 31 +(int)p.b;
}
}
/*
//public void solve(int testNumber, InputReader in, OutputWriter out)
// in case u want to print And take input inside and static method
static void extendedEuclid( long A, long B) {
if(B==0)
{d_ec=A;
x_ec =1;
y_ec=0;
}
else{
extendedEuclid(B, A%B);
long temp =x_ec;
x_ec = y_ec;
y_ec =temp -(A/B)*y_ec;
}
}
static long modInverse( long A, long M) //A and M are coprime i.e. Ax+My=1. In the extended Euclidean algorithm, x is the modular multiplicative inverse of A under modulo M.
{
extendedEuclid(A,M);
return (x_ec%M+M)%M; //x may be negative
}
static boolean checkprime(int N) {
int count = 0;
for( int i = 1;i * i <=N;++i ) {
if( N % i == 0) {
if( i * i == N )
count++;
else // i < sqrt(N) and (N / i) > sqrt(N)
count += 2;
}
}
if(count == 2)
return true;
else
return false;
}
static void factorize (long a,HashMap<Long,Long> map)
{
long i=2;
for( i=2;i*i<=a;i++)
{
if(a%i==0){
long f=0;
while((a>0)&&(a%i==0))
{
a= a/i;
f++;
}
map.put(i, f);
}
}
if(a>1l)
map.put(a, 1l);
}*/
/*static class DSU
{
int parent[];
int rank[];
int state[];
DSU(int n)
{parent=new int[n];
rank=new int[n];
state=new int[n+1];
}
void makeset(int n)
{
for(int i=0;i<n;i++)
{
parent[i]=i;
rank[i]=1;
state[i]=0;// for jamboard question
}
}
void decP(int x)// for jamboard question
{
if(state[x]>0)
state[x]--;
}
void incP(int x)// for jamboard question
{
state[x]++;
}
boolean getP(int x)// for jamboard question
{
return (state[x]!=0);
}
int find(int x)
{
if(x==parent[x])
return x;
parent[x]=find(parent[x]);
return parent[x];
}
void union(int x,int y)
{
int xRoot=find(x);
int yRoot=find(y);
if(xRoot==yRoot)
return;
if(rank[xRoot]>rank[yRoot])
{
parent[yRoot]=xRoot;
state[xRoot]+=state[yRoot];// for jamboard question
}
else if(rank[xRoot]<rank[yRoot])
{
parent[xRoot]=yRoot;
state[yRoot]+=state[xRoot];// for jamboard question
}
else
{
parent[xRoot]=yRoot;
rank[yRoot]++;
state[yRoot]+=state[xRoot];// for jamboard question
}
}
}
*/
}/*
class DSU
{
int parent[];
int rank[];
int diff[];
DSU(int sd){
parent=new int[sd];
rank=new int[sd];
diff=new int[sd];
}
void makeset(int n)
{
for(int i=0;i<n;i++)
{
parent[i]=i;
rank[i]=1;
diff[i]=0;
}
}
int find (int x) {
if (x == parent [x]) return x;
int t = parent [x];
parent [x] = find (parent [x]);
diff [x] ^= diff [t];
return parent [x];
}
boolean union(int x,int y,int w)
{
int xRoot=find(x);
int yRoot=find(y);
if(xRoot==yRoot)
{ if(w != (diff[x]^diff[y]))
return false;
}
else if(rank[xRoot]>rank[yRoot])
{
parent[yRoot]=xRoot;
diff[yRoot]= diff[x]^diff[y]^w;
}
else if(rank[xRoot]<rank[yRoot])
{
parent[xRoot]=yRoot;
diff[xRoot]= diff[x]^diff[y]^w;
}
else
{
parent[xRoot]=yRoot;
rank[yRoot]++;
diff[xRoot]= diff[x]^diff[y]^w;
}
return true;
}
}*/
class Gnode{
int value;
List<Gnode> neighbours;
Gnode(int x)
{value=x;
neighbours =new ArrayList<>();
}
}
class Node{
int value;
Node left;
Node right;
Node(int qw){
this.value = qw;
this.left = null;
this.right = null;
}
}
class SegTree{
long[] seg;
int[] map;
long[] arr;
SegTree(int n,long[] a){
seg=new long[4*n];
arr=a;
map=new int[n+1];
}
void build(int low,int high, int pos) {
if(low==high) {
map[low]=pos;
seg[pos]=arr[low];
}
else {
int middle=(low+high)/2;
build(low,middle,2*pos+1);
build(middle+1,high,2*pos+2);
seg[pos]=Math.max(seg[2*pos+1], seg[2*pos+2]);
}
}
void update(int low,int high, int pos,int elpos, long value) {
if(low==high) {
seg[pos]=value;
}
else {
int middle=(low+high)/2;
if(elpos<=middle) {
update(low,middle,2*pos+1,elpos,value);
}
else update(middle+1,high,2*pos+2,elpos,value);
seg[pos]=Math.max(seg[2*pos+1], seg[2*pos+2]);
}
}
}
class MinHeap {
int size;
int maxsize;
int heap[];
MinHeap(int maxsize,int size) //size = capacity
{this.size=size;
this.maxsize= maxsize;
heap = new int[maxsize];
}
boolean isEmpty()
{return size==0;
}
int peek()
{if(isEmpty())
return -99999;
return heap[0];
}
int remove()
{if(isEmpty())
return -99999;
int minItem = heap[1];
heap[1]= heap[size];
size --;
heapifyDown(1);
return minItem;
}
void print()
{
System.out.println(Arrays.toString(heap));
}
boolean add( int item)
{ if(size>= maxsize)
return false;
heap[size+1]= item;
size++;
heapifyUp(size);
return true;
}
void heapifyDown( int i)
{ int left = 2*i;
int right = 2*i +1;
int smallest =i;
if(left<= size && heap[left]<heap[smallest])
smallest =left;
if(right<= size && heap[right]<heap[smallest])
smallest =right;
if(smallest!=i)
{ int temp =heap[i];
heap[i]= heap[smallest];
heap[smallest]=temp;
heapifyDown(smallest);
}
}
void heapifyUp( int i)
{
int parent = i/2;
if( parent>0 && heap[parent]>heap[i])
{ int temp =heap[parent];
heap[parent]= heap[i];
heap[i]=temp;
heapifyUp(parent);
}
}}
class MaxHeap {
int size;
int maxsize;
int heap[];
MaxHeap(int maxsize,int size) //size = capacity
{this.size=size;
this.maxsize= maxsize;
heap = new int[maxsize];
}
void buildHeap(int arr[])
{size = arr.length+1;
for(int i=0;i<arr.length;i++)
heap[i+1]= arr[i];
for( int i=size/2;i>=1;i--)
{heapifyDown(i);
}
}
boolean isEmpty()
{return size==0;
}
int peek()
{if(isEmpty())
return -99999;
return heap[0];
}
int remove()
{if(isEmpty())
return -99999;
int minItem = heap[1];
heap[1]= heap[size];
size --;
heapifyDown(1);
return minItem;
}
void print()
{
System.out.println(Arrays.toString(heap));
}
boolean add( int item)
{ if(size>= maxsize)
return false;
heap[size+1]= item;
size++;
heapifyUp(size);
return true;
}
void heapifyDown( int i)
{ int left = 2*i;
int right = 2*i +1;
int largest =i;
if(left<= size && heap[left]>heap[largest])
largest =left;
if(right<= size && heap[right]>heap[largest])
largest =right;
if(largest!=i)
{ int temp =heap[i];
heap[i]= heap[largest];
heap[largest]=temp;
heapifyDown(largest);
}
}
void heapifyUp( int i)
{
int parent = i/2;
if( parent>0 && heap[parent]<heap[i])
{ int temp =heap[parent];
heap[parent]= heap[i];
heap[i]=temp;
heapifyUp(parent);
}
}
}
class InputReader
{
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream)
{
this.stream = stream;
}
public int read()
{
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars)
{
curChar = 0;
try
{
numChars = stream.read(buf);
} catch (IOException e)
{
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int readInt ()
{
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
int res = 0;
do
{
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public String readString ()
{
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do
{
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public String readLine() {
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 double readDouble() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E')
return res * Math.pow(10, readInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
if (c == '.') {
c = read();
double m = 1;
while (!isSpaceChar(c)) {
if (c == 'e' || c == 'E')
return res * Math.pow(10, readInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public long readLong() {
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 boolean isSpaceChar(int c)
{
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next()
{
return readString();
}
public interface SpaceCharFilter
{
public boolean isSpaceChar(int ch);
}
public boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
}
class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
}
public void println(Object... objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
} | Java | ["2 2\n1 0\n0 0", "2 3\n1 1 1\n1 1 1", "2 3\n0 1 0\n1 1 1"] | 1 second | ["NO", "YES\n1 1 1\n1 1 1", "YES\n0 0 0\n0 1 0"] | null | Java 11 | standard input | [
"implementation",
"hashing",
"greedy"
] | bacd613dc8a91cee8bef87b787e878ca | The first line contains two integer m and n (1ββ€βm,βnββ€β100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). | 1,300 | In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. | standard output | |
PASSED | d4564061b6a50a82e4759efe1f838b04 | train_003.jsonl | 1415718000 | Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0,β1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: where is equal to 1 if some aiβ=β1, otherwise it is equal to 0.Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1ββ€βiββ€βm) and column j (1ββ€βjββ€βn) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula:.(Bij is OR of all elements in row i and column j of matrix A)Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. | 256 megabytes | import java.io.*;
import java.math.*;
import java.util.*;
public class B {
static MyScanner in = new MyScanner();
static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer st;
static long H,W;
static BitSet bs;
static long mod = 1000000007;
// All possible moves of a knight
static int X[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
static int Y[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
static int [] dr = {-1,0,0,1};
static int [] dc = {0,1,-1,0};
public static void main(String args[]) throws IOException {
/**
1.What is the unknown:
2.What are the data: an array of tlen ght the value is 10^9
3.What is the condition:
4. understand the problem:
5. What are the cases edges in the problem:
6.What what max:
7. Are you using a data stcuture. And which one:
8.Is there reursion what is the base case. For example COINS:
*/
int n = in.nextInt();
int m= in.nextInt();
boolean work = true;
int [][] B = new int[n][m];
int[][]b = new int [n][m];
int [][] A = new int[n][m];
for(int i=0;i<n;i++){
Arrays.fill(A[i], 1);
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
int k = in.nextInt();
b[i][j] = k;
if(k==0){
//go sideway
for(int p=0;p<m;p++){
A[i][p] = 0;
}
for(int p=0;p<n;p++){
A[p][j] = 0;
}
}
}
}
//create the B matrix
for(int i=0;i<n;i++)
for(int j=0;j<m;j++){
if(A[i][j] ==1){
//go sideway
for(int p=0;p<m;p++){
B[i][p] = 1;
}
for(int p=0;p<n;p++){
B[p][j] = 1;
}
}
}
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
if(b[i][j]!=B[i][j])
work = false;
if(work){
out.println("YES");
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
out.print(A[i][j]+" ");
}
out.print("\n");
}
}else{
out.print("NO");
}
out.flush();
}
public static boolean subseqeunce(String s, String t){
for(int i=0,j=0;i<s.length();i++){
if(j<t.length()&&s.charAt(i)==t.charAt(j)){
j++;
}
if(j==t.length()) return true;
}
return false;
}
private static int lowrBound(int[] a, int lo, int hi, int element) {
while(lo<hi){
int mid = lo+(hi-lo)/2;
if(element>a[mid]){
lo = mid+1;
}else{
hi = mid;
}
}
if(lo<a.length&&a[lo]==element){
return lo+1;
}
return lo;
}
static long lcm(int a, int b) {
return (a*b)/gcd(a, b);
}
static boolean isVowel(char c) {
if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'||c=='y'){
return true;
}
return false ;
}
static class IP implements Comparable<IP>{
public int first,second;
IP(int first, int second){
this.first = first;
this.second = second;
}
public int compareTo(IP ip){
if(first==ip.first)
return second-ip.second;
return first-ip.first;
}
@Override
public String toString() {
return first+" "+second;
}
}
static long gcd(long a, long b){
return b!=0?gcd(b, a%b):a;
}
static boolean isEven(long a) {
return (a&1)==0;
}
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 | ["2 2\n1 0\n0 0", "2 3\n1 1 1\n1 1 1", "2 3\n0 1 0\n1 1 1"] | 1 second | ["NO", "YES\n1 1 1\n1 1 1", "YES\n0 0 0\n0 1 0"] | null | Java 11 | standard input | [
"implementation",
"hashing",
"greedy"
] | bacd613dc8a91cee8bef87b787e878ca | The first line contains two integer m and n (1ββ€βm,βnββ€β100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). | 1,300 | In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. | standard output | |
PASSED | faa3c132d852efab164112bbaec31db1 | train_003.jsonl | 1415718000 | Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0,β1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: where is equal to 1 if some aiβ=β1, otherwise it is equal to 0.Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1ββ€βiββ€βm) and column j (1ββ€βjββ€βn) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula:.(Bij is OR of all elements in row i and column j of matrix A)Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. | 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 Ideone
{
public static void assign(int i,int j,int a[][],int n,int m){
for(int ii=0;ii<n;ii++){
a[ii][j]=-1;
}
for(int ii=0;ii<m;ii++){
a[i][ii]=-1;
}
return;
}
public static boolean allr(int i,int j,int b[][],int n,int m){
// boolean flag=true;
for(int ii=0;ii<n;ii++){
if(b[ii][j]!=1){
return false;
}
}
return true;
}
public static boolean allc(int i,int j,int b[][],int n,int m){
// boolean flag=true;
for(int ii=0;ii<m;ii++){
if(b[i][ii]!=1){
return false;
}
}
return true;
}
public static boolean all(int i,int j,int b[][],int n,int m){
boolean flag1=true;
boolean flag2=true;
for(int ii=0;ii<n;ii++){
if(b[ii][j]!=1){
flag2=false;
break;
}
}
for(int ii=0;ii<m;ii++){
if(b[i][ii]!=1){
flag1=false;
break;
}
}
if(flag1==true ||flag2==true)
return true;
else
return false;
}
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner in=new Scanner(System.in);
int n=in.nextInt();
int m=in.nextInt();
int a[][]=new int[n][m];
int b[][]=new int[n][m];
boolean zero=true;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
b[i][j]=in.nextInt();
if(b[i][j]==1){
zero=false;
}
}
}
if(zero==true){
System.out.println("YES");
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
System.out.print(b[i][j]+" ");
}
System.out.println();
}
}
else{
boolean ans=false;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(b[i][j]==1){
if(all(i,j,b,n,m)){
}
else{
ans=true;
break;
}
}
}
if(ans==true){
break;
}
}
if(ans){
System.out.println("NO");
}
else{
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(b[i][j]==0){
assign(i,j,a,n,m);
}
}
}
boolean flag=false;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(a[i][j]==0){
flag=true;
a[i][j]=1;
}
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(a[i][j]==-1){
a[i][j]=0;
}
}
}
if(flag==true){
System.out.println("YES");
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
System.out.print(a[i][j]+" ");
}
System.out.println();
}
}
else{
System.out.println("NO");
}
}
}
}
} | Java | ["2 2\n1 0\n0 0", "2 3\n1 1 1\n1 1 1", "2 3\n0 1 0\n1 1 1"] | 1 second | ["NO", "YES\n1 1 1\n1 1 1", "YES\n0 0 0\n0 1 0"] | null | Java 11 | standard input | [
"implementation",
"hashing",
"greedy"
] | bacd613dc8a91cee8bef87b787e878ca | The first line contains two integer m and n (1ββ€βm,βnββ€β100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). | 1,300 | In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. | standard output | |
PASSED | fd20622602a939d57c6765bc424bcca0 | train_003.jsonl | 1415718000 | Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0,β1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: where is equal to 1 if some aiβ=β1, otherwise it is equal to 0.Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1ββ€βiββ€βm) and column j (1ββ€βjββ€βn) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula:.(Bij is OR of all elements in row i and column j of matrix A)Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large. | 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 Ideone
{
public static int checkc(int i,int j,int n,int m,int a[][]){
int ans=0;
for(int jj=0;jj<m;jj++){
ans=ans | a[i][jj];
}
for(int jj=0;jj<n;jj++){
ans= ans| a[jj][j];
}
return ans;
}
public static void checkr(int i,int j,int n,int m,int a[][]){
for(int jj=0;jj<m;jj++){
a[i][jj]=0;
}
for(int jj=0;jj<n;jj++){
a[jj][j]=0;
}
return;
}
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner in=new Scanner(System.in);
int n=in.nextInt();
int m=in.nextInt();
int b[][]=new int[n][m];
int a[][]=new int[n][m];
int c[][]=new int[n][m];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
b[i][j]=in.nextInt();
a[i][j]=-1;
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(b[i][j]==0){
checkr(i,j,n,m,a);
}
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(a[i][j]==-1){
a[i][j]=1;
}
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
c[i][j]=checkc(i,j,n,m,a);
}
}
boolean flag=true;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(b[i][j]!=c[i][j]){
flag=false;
break;
}
}
}
if(flag){
System.out.println("YES");
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
System.out.print(a[i][j]+" ");
}
System.out.println();
}
}
else{
System.out.println("NO");
}
}
} | Java | ["2 2\n1 0\n0 0", "2 3\n1 1 1\n1 1 1", "2 3\n0 1 0\n1 1 1"] | 1 second | ["NO", "YES\n1 1 1\n1 1 1", "YES\n0 0 0\n0 1 0"] | null | Java 11 | standard input | [
"implementation",
"hashing",
"greedy"
] | bacd613dc8a91cee8bef87b787e878ca | The first line contains two integer m and n (1ββ€βm,βnββ€β100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1). | 1,300 | In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one. | standard output | |
PASSED | 6cf17080a2004bf92d250245de405974 | train_003.jsonl | 1520696100 | There is a number x initially written on a blackboard. You repeat the following action a fixed amount of times: take the number x currently written on a blackboard and erase it select an integer uniformly at random from the range [0,βx] inclusive, and write it on the blackboard Determine the distribution of final number given the distribution of initial number and the number of steps. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Deque;
import java.util.function.Supplier;
import java.io.OutputStreamWriter;
import java.math.BigInteger;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Collection;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.function.Consumer;
import java.io.Closeable;
import java.io.Writer;
import java.util.ArrayDeque;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) throws Exception {
Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 29);
thread.start();
thread.join();
}
static class TaskAdapter implements Runnable {
@Override
public void run() {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
FastInput in = new FastInput(inputStream);
FastOutput out = new FastOutput(outputStream);
EPerpetualSubtraction solver = new EPerpetualSubtraction();
solver.solve(1, in, out);
out.close();
}
}
static class EPerpetualSubtraction {
int mod = 998244353;
Modular modular = new Modular(mod);
Power pow = new Power(modular);
Debug debug = new Debug(true);
NumberTheoryTransform ntt = new NumberTheoryTransform(mod);
public void solve(int testNumber, FastInput in, FastOutput out) {
int n = in.readInt();
long m = in.readLong();
int[] p = new int[n + 1];
in.populate(p);
Factorial factorial = new Factorial(n + 1, mod);
int[] p0 = p;
int[] p1 = new int[n + 1];
int[] p2 = new int[n + 1];
int[] p3 = new int[n + 1];
{
IntegerArrayList a = Polynomials.listBuffer.alloc();
IntegerArrayList b = Polynomials.listBuffer.alloc();
IntegerArrayList c = Polynomials.listBuffer.alloc();
a.expandWith(0, n + 1);
b.expandWith(0, n + 1);
for (int i = 0; i <= n; i++) {
a.set(i, (int) ((long) factorial.fact(i) * p0[i] % mod));
b.set(i, factorial.invFact(i));
}
ntt.deltaNTT(a, b, c);
c.expandWith(0, n + 1);
for (int i = 0; i <= n; i++) {
p1[i] = (int) ((long) c.get(i) * factorial.invFact(i) % mod);
}
Polynomials.listBuffer.release(a);
Polynomials.listBuffer.release(b);
Polynomials.listBuffer.release(c);
}
for (int i = 0; i <= n; i++) {
p2[i] = (int) ((long) pow.inversePower(i + 1, m) * p1[i] % mod);
}
{
IntegerArrayList a = Polynomials.listBuffer.alloc();
IntegerArrayList b = Polynomials.listBuffer.alloc();
IntegerArrayList c = Polynomials.listBuffer.alloc();
a.expandWith(0, n + 1);
b.expandWith(0, n + 1);
for (int i = 0; i <= n; i++) {
a.set(i, (int) ((long) factorial.fact(i) * p2[i] % mod));
b.set(i, DigitUtils.mod((i % 2 == 0 ? 1 : -1) * factorial.invFact(i), mod));
}
ntt.deltaNTT(a, b, c);
c.expandWith(0, n + 1);
for (int i = 0; i <= n; i++) {
p3[i] = (int) ((long) c.get(i) * factorial.invFact(i) % mod);
}
Polynomials.listBuffer.release(a);
Polynomials.listBuffer.release(b);
Polynomials.listBuffer.release(c);
}
for (int i = 0; i <= n; i++) {
out.println(p3[i]);
}
debug.debug("p0", p0);
debug.debug("p1", p1);
debug.debug("p2", p2);
debug.debug("p3", p3);
}
}
static class Factorial {
int[] fact;
int[] inv;
int mod;
public Factorial(int[] fact, int[] inv, int mod) {
this.mod = mod;
this.fact = fact;
this.inv = inv;
fact[0] = inv[0] = 1;
int n = Math.min(fact.length, mod);
for (int i = 1; i < n; i++) {
fact[i] = i;
fact[i] = (int) ((long) fact[i] * fact[i - 1] % mod);
}
inv[n - 1] = BigInteger.valueOf(fact[n - 1]).modInverse(BigInteger.valueOf(mod)).intValue();
for (int i = n - 2; i >= 1; i--) {
inv[i] = (int) ((long) inv[i + 1] * (i + 1) % mod);
}
}
public Factorial(int limit, int mod) {
this(new int[limit + 1], new int[limit + 1], mod);
}
public int fact(int n) {
return fact[n];
}
public int invFact(int n) {
return inv[n];
}
}
static class Buffer<T> {
private Deque<T> deque;
private Supplier<T> supplier;
private Consumer<T> cleaner;
private int allocTime;
private int releaseTime;
public Buffer(Supplier<T> supplier) {
this(supplier, (x) -> {
});
}
public Buffer(Supplier<T> supplier, Consumer<T> cleaner) {
this(supplier, cleaner, 0);
}
public Buffer(Supplier<T> supplier, Consumer<T> cleaner, int exp) {
this.supplier = supplier;
this.cleaner = cleaner;
deque = new ArrayDeque<>(exp);
}
public T alloc() {
allocTime++;
return deque.isEmpty() ? supplier.get() : deque.removeFirst();
}
public void release(T e) {
releaseTime++;
cleaner.accept(e);
deque.addLast(e);
}
}
static class Power implements InverseNumber {
final Modular modular;
int modVal;
public Power(Modular modular) {
this.modular = modular;
this.modVal = modular.getMod();
}
public Power(int mod) {
this(new Modular(mod));
}
public int pow(int x, long n) {
if (n == 0) {
return modular.valueOf(1);
}
long r = pow(x, n >> 1);
r = r * r % modVal;
if ((n & 1) == 1) {
r = r * x % modVal;
}
return (int) r;
}
public int pow(int x, int n) {
if (n == 0) {
return modular.valueOf(1);
}
long r = pow(x, n >> 1);
r = r * r % modVal;
if ((n & 1) == 1) {
r = r * x % modVal;
}
return (int) r;
}
public int inverseByFermat(int x) {
return pow(x, modVal - 2);
}
public int inversePower(int x, long n) {
n = DigitUtils.mod(-n, modVal - 1);
return pow(x, n);
}
}
static class SequenceUtils {
public static void swap(int[] data, int i, int j) {
int tmp = data[i];
data[i] = data[j];
data[j] = tmp;
}
public static void reverse(int[] data, int l, int r) {
while (l < r) {
swap(data, l, r);
l++;
r--;
}
}
public static boolean equal(int[] a, int al, int ar, int[] b, int bl, int br) {
if ((ar - al) != (br - bl)) {
return false;
}
for (int i = al, j = bl; i <= ar; i++, j++) {
if (a[i] != b[j]) {
return false;
}
}
return true;
}
}
static class Debug {
private boolean offline;
private PrintStream out = System.err;
static int[] empty = new int[0];
public Debug(boolean enable) {
offline = enable && System.getSecurityManager() == null;
}
public Debug debug(String name, Object x) {
return debug(name, x, empty);
}
public Debug debug(String name, Object x, int... indexes) {
if (offline) {
if (x == null || !x.getClass().isArray()) {
out.append(name);
for (int i : indexes) {
out.printf("[%d]", i);
}
out.append("=").append("" + x);
out.println();
} else {
indexes = Arrays.copyOf(indexes, indexes.length + 1);
if (x instanceof byte[]) {
byte[] arr = (byte[]) x;
for (int i = 0; i < arr.length; i++) {
indexes[indexes.length - 1] = i;
debug(name, arr[i], indexes);
}
} else if (x instanceof short[]) {
short[] arr = (short[]) x;
for (int i = 0; i < arr.length; i++) {
indexes[indexes.length - 1] = i;
debug(name, arr[i], indexes);
}
} else if (x instanceof boolean[]) {
boolean[] arr = (boolean[]) x;
for (int i = 0; i < arr.length; i++) {
indexes[indexes.length - 1] = i;
debug(name, arr[i], indexes);
}
} else if (x instanceof char[]) {
char[] arr = (char[]) x;
for (int i = 0; i < arr.length; i++) {
indexes[indexes.length - 1] = i;
debug(name, arr[i], indexes);
}
} else if (x instanceof int[]) {
int[] arr = (int[]) x;
for (int i = 0; i < arr.length; i++) {
indexes[indexes.length - 1] = i;
debug(name, arr[i], indexes);
}
} else if (x instanceof float[]) {
float[] arr = (float[]) x;
for (int i = 0; i < arr.length; i++) {
indexes[indexes.length - 1] = i;
debug(name, arr[i], indexes);
}
} else if (x instanceof double[]) {
double[] arr = (double[]) x;
for (int i = 0; i < arr.length; i++) {
indexes[indexes.length - 1] = i;
debug(name, arr[i], indexes);
}
} else if (x instanceof long[]) {
long[] arr = (long[]) x;
for (int i = 0; i < arr.length; i++) {
indexes[indexes.length - 1] = i;
debug(name, arr[i], indexes);
}
} else {
Object[] arr = (Object[]) x;
for (int i = 0; i < arr.length; i++) {
indexes[indexes.length - 1] = i;
debug(name, arr[i], indexes);
}
}
}
}
return this;
}
}
static class Factorization {
public static IntegerArrayList factorizeNumberPrime(int x) {
IntegerArrayList ans = new IntegerArrayList();
for (int i = 2; i * i <= x; i++) {
if (x % i != 0) {
continue;
}
ans.add(i);
while (x % i == 0) {
x /= i;
}
}
if (x > 1) {
ans.add(x);
}
return ans;
}
}
static interface InverseNumber {
}
static class PrimitiveRoot {
private int[] factors;
private int mod;
private Power pow;
int phi;
public PrimitiveRoot(int x) {
phi = x - 1;
mod = x;
pow = new Power(mod);
factors = Factorization.factorizeNumberPrime(phi).toArray();
}
public int findMinPrimitiveRoot() {
if (mod == 2) {
return 1;
}
return findMinPrimitiveRoot(2);
}
private int findMinPrimitiveRoot(int since) {
for (int i = since; i < mod; i++) {
boolean flag = true;
for (int f : factors) {
if (pow.pow(i, phi / f) == 1) {
flag = false;
break;
}
}
if (flag) {
return i;
}
}
return -1;
}
}
static class DigitUtils {
private DigitUtils() {
}
public static int mod(long x, int mod) {
x %= mod;
if (x < 0) {
x += mod;
}
return (int) x;
}
public static int mod(int x, int mod) {
x %= mod;
if (x < 0) {
x += mod;
}
return x;
}
public static int modsub(int a, int b, int mod) {
int ans = a - b;
if (ans < 0) {
ans += mod;
}
return ans;
}
public static int modplus(int a, int b, int mod) {
int ans = a + b;
if (ans >= mod) {
ans -= mod;
}
return ans;
}
}
static class Log2 {
public static int ceilLog(int x) {
return 32 - Integer.numberOfLeadingZeros(x - 1);
}
}
static class Polynomials {
public static Buffer<IntegerArrayList> listBuffer = new Buffer<>(IntegerArrayList::new, list -> list.clear());
public static int rankOf(IntegerArrayList p) {
int[] data = p.getData();
int r = p.size() - 1;
while (r >= 0 && data[r] == 0) {
r--;
}
return Math.max(0, r);
}
public static void normalize(IntegerArrayList list) {
list.retain(rankOf(list) + 1);
}
}
static class FastInput {
private final InputStream is;
private byte[] buf = new byte[1 << 13];
private int bufLen;
private int bufOffset;
private int next;
public FastInput(InputStream is) {
this.is = is;
}
public void populate(int[] data) {
for (int i = 0; i < data.length; i++) {
data[i] = readInt();
}
}
private int read() {
while (bufLen == bufOffset) {
bufOffset = 0;
try {
bufLen = is.read(buf);
} catch (IOException e) {
bufLen = -1;
}
if (bufLen == -1) {
return -1;
}
}
return buf[bufOffset++];
}
public void skipBlank() {
while (next >= 0 && next <= 32) {
next = read();
}
}
public int readInt() {
int sign = 1;
skipBlank();
if (next == '+' || next == '-') {
sign = next == '+' ? 1 : -1;
next = read();
}
int val = 0;
if (sign == 1) {
while (next >= '0' && next <= '9') {
val = val * 10 + next - '0';
next = read();
}
} else {
while (next >= '0' && next <= '9') {
val = val * 10 - next + '0';
next = read();
}
}
return val;
}
public long readLong() {
int sign = 1;
skipBlank();
if (next == '+' || next == '-') {
sign = next == '+' ? 1 : -1;
next = read();
}
long val = 0;
if (sign == 1) {
while (next >= '0' && next <= '9') {
val = val * 10 + next - '0';
next = read();
}
} else {
while (next >= '0' && next <= '9') {
val = val * 10 - next + '0';
next = read();
}
}
return val;
}
}
static class IntegerArrayList implements Cloneable {
private int size;
private int cap;
private int[] data;
private static final int[] EMPTY = new int[0];
public int[] getData() {
return data;
}
public IntegerArrayList(int cap) {
this.cap = cap;
if (cap == 0) {
data = EMPTY;
} else {
data = new int[cap];
}
}
public IntegerArrayList(IntegerArrayList list) {
this.size = list.size;
this.cap = list.cap;
this.data = Arrays.copyOf(list.data, size);
}
public IntegerArrayList() {
this(0);
}
public void reverse(int l, int r) {
SequenceUtils.reverse(data, l, r);
}
public void reverse() {
reverse(0, size - 1);
}
public void ensureSpace(int req) {
if (req > cap) {
while (cap < req) {
cap = Math.max(cap + 10, 2 * cap);
}
data = Arrays.copyOf(data, cap);
}
}
private void checkRange(int i) {
if (i < 0 || i >= size) {
throw new ArrayIndexOutOfBoundsException();
}
}
public int get(int i) {
checkRange(i);
return data[i];
}
public void add(int x) {
ensureSpace(size + 1);
data[size++] = x;
}
public void addAll(int[] x, int offset, int len) {
ensureSpace(size + len);
System.arraycopy(x, offset, data, size, len);
size += len;
}
public void addAll(IntegerArrayList list) {
addAll(list.data, 0, list.size);
}
public void expandWith(int x, int len) {
ensureSpace(len);
while (size < len) {
data[size++] = x;
}
}
public void retain(int n) {
if (n < 0) {
throw new IllegalArgumentException();
}
if (n >= size) {
return;
}
size = n;
}
public void set(int i, int x) {
checkRange(i);
data[i] = x;
}
public int size() {
return size;
}
public int[] toArray() {
return Arrays.copyOf(data, size);
}
public void clear() {
size = 0;
}
public String toString() {
return Arrays.toString(toArray());
}
public boolean equals(Object obj) {
if (!(obj instanceof IntegerArrayList)) {
return false;
}
IntegerArrayList other = (IntegerArrayList) obj;
return SequenceUtils.equal(data, 0, size - 1, other.data, 0, other.size - 1);
}
public int hashCode() {
int h = 1;
for (int i = 0; i < size; i++) {
h = h * 31 + Integer.hashCode(data[i]);
}
return h;
}
public IntegerArrayList clone() {
IntegerArrayList ans = new IntegerArrayList();
ans.addAll(this);
return ans;
}
}
static class FastOutput implements AutoCloseable, Closeable, Appendable {
private StringBuilder cache = new StringBuilder(10 << 20);
private final Writer os;
public FastOutput append(CharSequence csq) {
cache.append(csq);
return this;
}
public FastOutput append(CharSequence csq, int start, int end) {
cache.append(csq, start, end);
return this;
}
public FastOutput(Writer os) {
this.os = os;
}
public FastOutput(OutputStream os) {
this(new OutputStreamWriter(os));
}
public FastOutput append(char c) {
cache.append(c);
return this;
}
public FastOutput append(int c) {
cache.append(c);
return this;
}
public FastOutput println(int c) {
return append(c).println();
}
public FastOutput println() {
cache.append(System.lineSeparator());
return this;
}
public FastOutput flush() {
try {
os.append(cache);
os.flush();
cache.setLength(0);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return this;
}
public void close() {
flush();
try {
os.close();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
public String toString() {
return cache.toString();
}
}
static class Modular {
int m;
public int getMod() {
return m;
}
public Modular(int m) {
this.m = m;
}
public Modular(long m) {
this.m = (int) m;
if (this.m != m) {
throw new IllegalArgumentException();
}
}
public Modular(double m) {
this.m = (int) m;
if (this.m != m) {
throw new IllegalArgumentException();
}
}
public int valueOf(int x) {
x %= m;
if (x < 0) {
x += m;
}
return x;
}
public String toString() {
return "mod " + m;
}
}
static class NumberTheoryTransform {
private int mod;
private Power power;
private int g;
private int[] wCache = new int[30];
private int[] invCache = new int[30];
public static Buffer<IntegerArrayList> listBuffer = Polynomials.listBuffer;
public NumberTheoryTransform(int mod) {
this(mod, mod == 998244353 ? 3 : new PrimitiveRoot(mod).findMinPrimitiveRoot());
}
public NumberTheoryTransform(int mod, int g) {
this.mod = mod;
this.power = new Power(mod);
this.g = g;
for (int i = 0, until = wCache.length; i < until; i++) {
int s = 1 << i;
wCache[i] = power.pow(this.g, (mod - 1) / 2 / s);
invCache[i] = power.inverseByFermat(s);
}
}
public void dotMul(int[] a, int[] b, int[] c, int m) {
for (int i = 0, n = 1 << m; i < n; i++) {
c[i] = (int) ((long) a[i] * b[i] % mod);
}
}
public void dft(int[] p, int m) {
int n = 1 << m;
int shift = 32 - Integer.numberOfTrailingZeros(n);
for (int i = 1; i < n; i++) {
int j = Integer.reverse(i << shift);
if (i < j) {
int temp = p[i];
p[i] = p[j];
p[j] = temp;
}
}
int w = 0;
int t = 0;
for (int d = 0; d < m; d++) {
int w1 = wCache[d];
int s = 1 << d;
int s2 = s << 1;
for (int i = 0; i < n; i += s2) {
w = 1;
for (int j = 0; j < s; j++) {
int a = i + j;
int b = a + s;
t = (int) ((long) w * p[b] % mod);
p[b] = DigitUtils.modsub(p[a], t, mod);
p[a] = DigitUtils.modplus(p[a], t, mod);
w = (int) ((long) w * w1 % mod);
}
}
}
}
public void idft(int[] p, int m) {
dft(p, m);
int n = 1 << m;
long invN = invCache[m];
p[0] = (int) ((long) p[0] * invN % mod);
p[n / 2] = (int) (p[n / 2] * invN % mod);
for (int i = 1, until = n / 2; i < until; i++) {
int a = p[n - i];
p[n - i] = (int) (p[i] * invN % mod);
p[i] = (int) (a * invN % mod);
}
}
private IntegerArrayList clone(IntegerArrayList list) {
Polynomials.normalize(list);
IntegerArrayList ans = listBuffer.alloc();
ans.addAll(list);
return ans;
}
public void deltaNTT(IntegerArrayList a, IntegerArrayList b, IntegerArrayList c) {
a = clone(a);
b = clone(b);
int n = a.size();
b.retain(n);
a.reverse();
int m = Log2.ceilLog(n + n - 1);
a.expandWith(0, 1 << m);
b.expandWith(0, 1 << m);
c.clear();
c.expandWith(0, 1 << m);
dft(a.getData(), m);
dft(b.getData(), m);
dotMul(a.getData(), b.getData(), c.getData(), m);
idft(c.getData(), m);
c.retain(n);
c.reverse();
Polynomials.normalize(c);
listBuffer.release(a);
listBuffer.release(b);
}
}
}
| Java | ["2 1\n0 0 1", "2 2\n0 0 1", "9 350\n3 31 314 3141 31415 314159 3141592 31415926 314159265 649178508"] | 2 seconds | ["332748118 332748118 332748118", "942786334 610038216 443664157", "822986014 12998613 84959018 728107923 939229297 935516344 27254497 413831286 583600448 442738326"] | NoteIn the first case, we start with number 2. After one step, it will be 0, 1 or 2 with probability 1/3 each.In the second case, the number will remain 2 with probability 1/9. With probability 1/9 it stays 2 in the first round and changes to 1 in the next, and with probability 1/6 changes to 1 in the first round and stays in the second. In all other cases the final integer is 0. | Java 8 | standard input | [
"fft",
"math",
"matrices"
] | 0642a91cb581e0c39ed37db4d3dbe9b2 | The first line contains two integers, N (1ββ€βNββ€β105)Β β the maximum number written on the blackboardΒ β and M (0ββ€βMββ€β1018)Β β the number of steps to perform. The second line contains Nβ+β1 integers P0,βP1,β...,βPN (0ββ€βPiβ<β998244353), where Pi describes the probability that the starting number is i. We can express this probability as irreducible fraction Pβ/βQ, then . It is guaranteed that the sum of all Pis equals 1 (modulo 998244353). | 3,100 | Output a single line of Nβ+β1 integers, where Ri is the probability that the final number after M steps is i. It can be proven that the probability may always be expressed as an irreducible fraction Pβ/βQ. You are asked to output . | standard output | |
PASSED | d0743c81985225c285d6149d28585241 | train_003.jsonl | 1520696100 | There is a number x initially written on a blackboard. You repeat the following action a fixed amount of times: take the number x currently written on a blackboard and erase it select an integer uniformly at random from the range [0,βx] inclusive, and write it on the blackboard Determine the distribution of final number given the distribution of initial number and the number of steps. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Deque;
import java.util.function.Supplier;
import java.io.OutputStreamWriter;
import java.math.BigInteger;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Collection;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.function.Consumer;
import java.io.Closeable;
import java.io.Writer;
import java.util.ArrayDeque;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) throws Exception {
Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 29);
thread.start();
thread.join();
}
static class TaskAdapter implements Runnable {
@Override
public void run() {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
FastInput in = new FastInput(inputStream);
FastOutput out = new FastOutput(outputStream);
EPerpetualSubtraction solver = new EPerpetualSubtraction();
solver.solve(1, in, out);
out.close();
}
}
static class EPerpetualSubtraction {
int mod = 998244353;
Modular modular = new Modular(mod);
Power pow = new Power(modular);
Debug debug = new Debug(true);
NumberTheoryTransform ntt = new NumberTheoryTransform(modular);
public void solve(int testNumber, FastInput in, FastOutput out) {
int n = in.readInt();
long m = in.readLong();
int[] p = new int[n + 1];
in.populate(p);
Factorial factorial = new Factorial(n + 1, mod);
int[] p0 = p;
int[] p1 = new int[n + 1];
int[] p2 = new int[n + 1];
int[] p3 = new int[n + 1];
{
IntegerArrayList a = Polynomials.listBuffer.alloc();
IntegerArrayList b = Polynomials.listBuffer.alloc();
IntegerArrayList c = Polynomials.listBuffer.alloc();
a.expandWith(0, n + 1);
b.expandWith(0, n + 1);
for (int i = 0; i <= n; i++) {
a.set(i, (int) ((long) factorial.fact(i) * p0[i] % mod));
b.set(i, factorial.invFact(i));
}
ntt.deltaNTT(a, b, c);
c.expandWith(0, n + 1);
for (int i = 0; i <= n; i++) {
p1[i] = (int) ((long) c.get(i) * factorial.invFact(i) % mod);
}
Polynomials.listBuffer.release(a);
Polynomials.listBuffer.release(b);
Polynomials.listBuffer.release(c);
}
for (int i = 0; i <= n; i++) {
p2[i] = (int) ((long) pow.inversePower(i + 1, m) * p1[i] % mod);
}
{
IntegerArrayList a = Polynomials.listBuffer.alloc();
IntegerArrayList b = Polynomials.listBuffer.alloc();
IntegerArrayList c = Polynomials.listBuffer.alloc();
a.expandWith(0, n + 1);
b.expandWith(0, n + 1);
for (int i = 0; i <= n; i++) {
a.set(i, (int) ((long) factorial.fact(i) * p2[i] % mod));
b.set(i, DigitUtils.mod((i % 2 == 0 ? 1 : -1) * factorial.invFact(i), mod));
}
ntt.deltaNTT(a, b, c);
c.expandWith(0, n + 1);
for (int i = 0; i <= n; i++) {
p3[i] = (int) ((long) c.get(i) * factorial.invFact(i) % mod);
}
Polynomials.listBuffer.release(a);
Polynomials.listBuffer.release(b);
Polynomials.listBuffer.release(c);
}
for (int i = 0; i <= n; i++) {
out.println(p3[i]);
}
debug.debug("p0", p0);
debug.debug("p1", p1);
debug.debug("p2", p2);
debug.debug("p3", p3);
}
}
static class PrimitiveRoot {
private int[] factors;
private Modular mod;
private Power pow;
int phi;
public PrimitiveRoot(Modular x) {
phi = x.getMod() - 1;
mod = x;
pow = new Power(mod);
//factors = rho.findAllFactors(phi).keySet().stream().mapToInt(Integer::intValue).toArray();
factors = Factorization.factorizeNumberPrime(phi).toArray();
}
public PrimitiveRoot(int x) {
this(new Modular(x));
}
public int findMinPrimitiveRoot() {
if (mod.getMod() == 2) {
return 1;
}
return findMinPrimitiveRoot(2);
}
private int findMinPrimitiveRoot(int since) {
for (int i = since; i < mod.m; i++) {
boolean flag = true;
for (int f : factors) {
if (pow.pow(i, phi / f) == 1) {
flag = false;
break;
}
}
if (flag) {
return i;
}
}
return -1;
}
}
static class FastInput {
private final InputStream is;
private byte[] buf = new byte[1 << 13];
private int bufLen;
private int bufOffset;
private int next;
public FastInput(InputStream is) {
this.is = is;
}
public void populate(int[] data) {
for (int i = 0; i < data.length; i++) {
data[i] = readInt();
}
}
private int read() {
while (bufLen == bufOffset) {
bufOffset = 0;
try {
bufLen = is.read(buf);
} catch (IOException e) {
bufLen = -1;
}
if (bufLen == -1) {
return -1;
}
}
return buf[bufOffset++];
}
public void skipBlank() {
while (next >= 0 && next <= 32) {
next = read();
}
}
public int readInt() {
int sign = 1;
skipBlank();
if (next == '+' || next == '-') {
sign = next == '+' ? 1 : -1;
next = read();
}
int val = 0;
if (sign == 1) {
while (next >= '0' && next <= '9') {
val = val * 10 + next - '0';
next = read();
}
} else {
while (next >= '0' && next <= '9') {
val = val * 10 - next + '0';
next = read();
}
}
return val;
}
public long readLong() {
int sign = 1;
skipBlank();
if (next == '+' || next == '-') {
sign = next == '+' ? 1 : -1;
next = read();
}
long val = 0;
if (sign == 1) {
while (next >= '0' && next <= '9') {
val = val * 10 + next - '0';
next = read();
}
} else {
while (next >= '0' && next <= '9') {
val = val * 10 - next + '0';
next = read();
}
}
return val;
}
}
static class Modular {
int m;
public int getMod() {
return m;
}
public Modular(int m) {
this.m = m;
}
public Modular(long m) {
this.m = (int) m;
if (this.m != m) {
throw new IllegalArgumentException();
}
}
public Modular(double m) {
this.m = (int) m;
if (this.m != m) {
throw new IllegalArgumentException();
}
}
public int valueOf(int x) {
x %= m;
if (x < 0) {
x += m;
}
return x;
}
public int valueOf(long x) {
x %= m;
if (x < 0) {
x += m;
}
return (int) x;
}
public int mul(int x, int y) {
return valueOf((long) x * y);
}
public int plus(int x, int y) {
return valueOf(x + y);
}
public String toString() {
return "mod " + m;
}
}
static class Factorial {
int[] fact;
int[] inv;
int mod;
public Factorial(int[] fact, int[] inv, int mod) {
this.mod = mod;
this.fact = fact;
this.inv = inv;
fact[0] = inv[0] = 1;
int n = Math.min(fact.length, mod);
for (int i = 1; i < n; i++) {
fact[i] = i;
fact[i] = (int) ((long) fact[i] * fact[i - 1] % mod);
}
inv[n - 1] = BigInteger.valueOf(fact[n - 1]).modInverse(BigInteger.valueOf(mod)).intValue();
for (int i = n - 2; i >= 1; i--) {
inv[i] = (int) ((long) inv[i + 1] * (i + 1) % mod);
}
}
public Factorial(int limit, int mod) {
this(new int[limit + 1], new int[limit + 1], mod);
}
public int fact(int n) {
return fact[n];
}
public int invFact(int n) {
return inv[n];
}
}
static class Log2 {
public static int ceilLog(int x) {
return 32 - Integer.numberOfLeadingZeros(x - 1);
}
}
static class FastOutput implements AutoCloseable, Closeable, Appendable {
private StringBuilder cache = new StringBuilder(10 << 20);
private final Writer os;
public FastOutput append(CharSequence csq) {
cache.append(csq);
return this;
}
public FastOutput append(CharSequence csq, int start, int end) {
cache.append(csq, start, end);
return this;
}
public FastOutput(Writer os) {
this.os = os;
}
public FastOutput(OutputStream os) {
this(new OutputStreamWriter(os));
}
public FastOutput append(char c) {
cache.append(c);
return this;
}
public FastOutput append(int c) {
cache.append(c);
return this;
}
public FastOutput println(int c) {
return append(c).println();
}
public FastOutput println() {
cache.append(System.lineSeparator());
return this;
}
public FastOutput flush() {
try {
os.append(cache);
os.flush();
cache.setLength(0);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return this;
}
public void close() {
flush();
try {
os.close();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
public String toString() {
return cache.toString();
}
}
static class IntegerArrayList implements Cloneable {
private int size;
private int cap;
private int[] data;
private static final int[] EMPTY = new int[0];
public int[] getData() {
return data;
}
public IntegerArrayList(int cap) {
this.cap = cap;
if (cap == 0) {
data = EMPTY;
} else {
data = new int[cap];
}
}
public IntegerArrayList(IntegerArrayList list) {
this.size = list.size;
this.cap = list.cap;
this.data = Arrays.copyOf(list.data, size);
}
public IntegerArrayList() {
this(0);
}
public void reverse(int l, int r) {
SequenceUtils.reverse(data, l, r);
}
public void reverse() {
reverse(0, size - 1);
}
public void ensureSpace(int req) {
if (req > cap) {
while (cap < req) {
cap = Math.max(cap + 10, 2 * cap);
}
data = Arrays.copyOf(data, cap);
}
}
private void checkRange(int i) {
if (i < 0 || i >= size) {
throw new ArrayIndexOutOfBoundsException();
}
}
public int get(int i) {
checkRange(i);
return data[i];
}
public void add(int x) {
ensureSpace(size + 1);
data[size++] = x;
}
public void addAll(int[] x, int offset, int len) {
ensureSpace(size + len);
System.arraycopy(x, offset, data, size, len);
size += len;
}
public void addAll(IntegerArrayList list) {
addAll(list.data, 0, list.size);
}
public void expandWith(int x, int len) {
ensureSpace(len);
while (size < len) {
data[size++] = x;
}
}
public void retain(int n) {
if (n < 0) {
throw new IllegalArgumentException();
}
if (n >= size) {
return;
}
size = n;
}
public void set(int i, int x) {
checkRange(i);
data[i] = x;
}
public int size() {
return size;
}
public int[] toArray() {
return Arrays.copyOf(data, size);
}
public void clear() {
size = 0;
}
public String toString() {
return Arrays.toString(toArray());
}
public boolean equals(Object obj) {
if (!(obj instanceof IntegerArrayList)) {
return false;
}
IntegerArrayList other = (IntegerArrayList) obj;
return SequenceUtils.equal(data, 0, size - 1, other.data, 0, other.size - 1);
}
public int hashCode() {
int h = 1;
for (int i = 0; i < size; i++) {
h = h * 31 + Integer.hashCode(data[i]);
}
return h;
}
public IntegerArrayList clone() {
IntegerArrayList ans = new IntegerArrayList();
ans.addAll(this);
return ans;
}
}
static class Buffer<T> {
private Deque<T> deque;
private Supplier<T> supplier;
private Consumer<T> cleaner;
private int allocTime;
private int releaseTime;
public Buffer(Supplier<T> supplier) {
this(supplier, (x) -> {
});
}
public Buffer(Supplier<T> supplier, Consumer<T> cleaner) {
this(supplier, cleaner, 0);
}
public Buffer(Supplier<T> supplier, Consumer<T> cleaner, int exp) {
this.supplier = supplier;
this.cleaner = cleaner;
deque = new ArrayDeque<>(exp);
}
public T alloc() {
allocTime++;
return deque.isEmpty() ? supplier.get() : deque.removeFirst();
}
public void release(T e) {
releaseTime++;
cleaner.accept(e);
deque.addLast(e);
}
}
static class Polynomials {
public static Buffer<IntegerArrayList> listBuffer = new Buffer<>(IntegerArrayList::new, list -> list.clear());
public static int rankOf(IntegerArrayList p) {
int[] data = p.getData();
int r = p.size() - 1;
while (r >= 0 && data[r] == 0) {
r--;
}
return Math.max(0, r);
}
public static void normalize(IntegerArrayList list) {
list.retain(rankOf(list) + 1);
}
}
static class Power implements InverseNumber {
final Modular modular;
int modVal;
public Power(Modular modular) {
this.modular = modular;
this.modVal = modular.getMod();
}
public int pow(int x, long n) {
if (n == 0) {
return modular.valueOf(1);
}
long r = pow(x, n >> 1);
r = r * r % modVal;
if ((n & 1) == 1) {
r = r * x % modVal;
}
return (int) r;
}
public int pow(int x, int n) {
if (n == 0) {
return modular.valueOf(1);
}
long r = pow(x, n >> 1);
r = r * r % modVal;
if ((n & 1) == 1) {
r = r * x % modVal;
}
return (int) r;
}
public int inverseByFermat(int x) {
return pow(x, modVal - 2);
}
public int inversePower(int x, long n) {
n = DigitUtils.mod(-n, modVal - 1);
return pow(x, n);
}
}
static class NumberTheoryTransform {
private Modular modular;
private int modVal;
private Power power;
private int g;
private int[] wCache = new int[30];
private int[] invCache = new int[30];
public static Buffer<IntegerArrayList> listBuffer = Polynomials.listBuffer;
public NumberTheoryTransform(Modular mod) {
this(mod, mod.getMod() == 998244353 ? 3 : new PrimitiveRoot(mod.getMod()).findMinPrimitiveRoot());
}
public NumberTheoryTransform(Modular mod, int g) {
this.modular = mod;
this.modVal = mod.getMod();
this.power = new Power(mod);
this.g = g;
for (int i = 0, until = wCache.length; i < until; i++) {
int s = 1 << i;
wCache[i] = power.pow(this.g, (modular.getMod() - 1) / 2 / s);
invCache[i] = power.inverseByFermat(s);
}
}
public void dotMul(int[] a, int[] b, int[] c, int m) {
for (int i = 0, n = 1 << m; i < n; i++) {
c[i] = modular.mul(a[i], b[i]);
}
}
public void dft(int[] p, int m) {
int n = 1 << m;
int shift = 32 - Integer.numberOfTrailingZeros(n);
for (int i = 1; i < n; i++) {
int j = Integer.reverse(i << shift);
if (i < j) {
int temp = p[i];
p[i] = p[j];
p[j] = temp;
}
}
int w = 0;
int t = 0;
for (int d = 0; d < m; d++) {
int w1 = wCache[d];
int s = 1 << d;
int s2 = s << 1;
for (int i = 0; i < n; i += s2) {
w = 1;
for (int j = 0; j < s; j++) {
int a = i + j;
int b = a + s;
t = modular.mul(w, p[b]);
p[b] = modular.plus(p[a], -t);
p[a] = modular.plus(p[a], t);
w = modular.mul(w, w1);
}
}
}
}
public void idft(int[] p, int m) {
dft(p, m);
int n = 1 << m;
int invN = invCache[m];
p[0] = modular.mul(p[0], invN);
p[n / 2] = modular.mul(p[n / 2], invN);
for (int i = 1, until = n / 2; i < until; i++) {
int a = p[n - i];
p[n - i] = modular.mul(p[i], invN);
p[i] = modular.mul(a, invN);
}
}
private IntegerArrayList clone(IntegerArrayList list) {
Polynomials.normalize(list);
IntegerArrayList ans = listBuffer.alloc();
ans.addAll(list);
return ans;
}
public void deltaNTT(IntegerArrayList a, IntegerArrayList b, IntegerArrayList c) {
a = clone(a);
b = clone(b);
int n = a.size();
b.retain(n);
a.reverse();
int m = Log2.ceilLog(n + n - 1);
a.expandWith(0, 1 << m);
b.expandWith(0, 1 << m);
c.clear();
c.expandWith(0, 1 << m);
dft(a.getData(), m);
dft(b.getData(), m);
dotMul(a.getData(), b.getData(), c.getData(), m);
idft(c.getData(), m);
c.retain(n);
c.reverse();
Polynomials.normalize(c);
listBuffer.release(a);
listBuffer.release(b);
}
}
static class SequenceUtils {
public static void swap(int[] data, int i, int j) {
int tmp = data[i];
data[i] = data[j];
data[j] = tmp;
}
public static void reverse(int[] data, int l, int r) {
while (l < r) {
swap(data, l, r);
l++;
r--;
}
}
public static boolean equal(int[] a, int al, int ar, int[] b, int bl, int br) {
if ((ar - al) != (br - bl)) {
return false;
}
for (int i = al, j = bl; i <= ar; i++, j++) {
if (a[i] != b[j]) {
return false;
}
}
return true;
}
}
static interface InverseNumber {
}
static class Factorization {
public static IntegerArrayList factorizeNumberPrime(int x) {
IntegerArrayList ans = new IntegerArrayList();
for (int i = 2; i * i <= x; i++) {
if (x % i != 0) {
continue;
}
ans.add(i);
while (x % i == 0) {
x /= i;
}
}
if (x > 1) {
ans.add(x);
}
return ans;
}
}
static class DigitUtils {
private DigitUtils() {
}
public static int mod(long x, int mod) {
x %= mod;
if (x < 0) {
x += mod;
}
return (int) x;
}
public static int mod(int x, int mod) {
x %= mod;
if (x < 0) {
x += mod;
}
return x;
}
}
static class Debug {
private boolean offline;
private PrintStream out = System.err;
static int[] empty = new int[0];
public Debug(boolean enable) {
offline = enable && System.getSecurityManager() == null;
}
public Debug debug(String name, Object x) {
return debug(name, x, empty);
}
public Debug debug(String name, Object x, int... indexes) {
if (offline) {
if (x == null || !x.getClass().isArray()) {
out.append(name);
for (int i : indexes) {
out.printf("[%d]", i);
}
out.append("=").append("" + x);
out.println();
} else {
indexes = Arrays.copyOf(indexes, indexes.length + 1);
if (x instanceof byte[]) {
byte[] arr = (byte[]) x;
for (int i = 0; i < arr.length; i++) {
indexes[indexes.length - 1] = i;
debug(name, arr[i], indexes);
}
} else if (x instanceof short[]) {
short[] arr = (short[]) x;
for (int i = 0; i < arr.length; i++) {
indexes[indexes.length - 1] = i;
debug(name, arr[i], indexes);
}
} else if (x instanceof boolean[]) {
boolean[] arr = (boolean[]) x;
for (int i = 0; i < arr.length; i++) {
indexes[indexes.length - 1] = i;
debug(name, arr[i], indexes);
}
} else if (x instanceof char[]) {
char[] arr = (char[]) x;
for (int i = 0; i < arr.length; i++) {
indexes[indexes.length - 1] = i;
debug(name, arr[i], indexes);
}
} else if (x instanceof int[]) {
int[] arr = (int[]) x;
for (int i = 0; i < arr.length; i++) {
indexes[indexes.length - 1] = i;
debug(name, arr[i], indexes);
}
} else if (x instanceof float[]) {
float[] arr = (float[]) x;
for (int i = 0; i < arr.length; i++) {
indexes[indexes.length - 1] = i;
debug(name, arr[i], indexes);
}
} else if (x instanceof double[]) {
double[] arr = (double[]) x;
for (int i = 0; i < arr.length; i++) {
indexes[indexes.length - 1] = i;
debug(name, arr[i], indexes);
}
} else if (x instanceof long[]) {
long[] arr = (long[]) x;
for (int i = 0; i < arr.length; i++) {
indexes[indexes.length - 1] = i;
debug(name, arr[i], indexes);
}
} else {
Object[] arr = (Object[]) x;
for (int i = 0; i < arr.length; i++) {
indexes[indexes.length - 1] = i;
debug(name, arr[i], indexes);
}
}
}
}
return this;
}
}
}
| Java | ["2 1\n0 0 1", "2 2\n0 0 1", "9 350\n3 31 314 3141 31415 314159 3141592 31415926 314159265 649178508"] | 2 seconds | ["332748118 332748118 332748118", "942786334 610038216 443664157", "822986014 12998613 84959018 728107923 939229297 935516344 27254497 413831286 583600448 442738326"] | NoteIn the first case, we start with number 2. After one step, it will be 0, 1 or 2 with probability 1/3 each.In the second case, the number will remain 2 with probability 1/9. With probability 1/9 it stays 2 in the first round and changes to 1 in the next, and with probability 1/6 changes to 1 in the first round and stays in the second. In all other cases the final integer is 0. | Java 8 | standard input | [
"fft",
"math",
"matrices"
] | 0642a91cb581e0c39ed37db4d3dbe9b2 | The first line contains two integers, N (1ββ€βNββ€β105)Β β the maximum number written on the blackboardΒ β and M (0ββ€βMββ€β1018)Β β the number of steps to perform. The second line contains Nβ+β1 integers P0,βP1,β...,βPN (0ββ€βPiβ<β998244353), where Pi describes the probability that the starting number is i. We can express this probability as irreducible fraction Pβ/βQ, then . It is guaranteed that the sum of all Pis equals 1 (modulo 998244353). | 3,100 | Output a single line of Nβ+β1 integers, where Ri is the probability that the final number after M steps is i. It can be proven that the probability may always be expressed as an irreducible fraction Pβ/βQ. You are asked to output . | standard output | |
PASSED | cbd97c0e865495fabf2412837737e9b5 | train_003.jsonl | 1548254100 | You are given two segments $$$[l_1; r_1]$$$ and $$$[l_2; r_2]$$$ on the $$$x$$$-axis. It is guaranteed that $$$l_1 < r_1$$$ and $$$l_2 < r_2$$$. Segments may intersect, overlap or even coincide with each other. The example of two segments on the $$$x$$$-axis. Your problem is to find two integers $$$a$$$ and $$$b$$$ such that $$$l_1 \le a \le r_1$$$, $$$l_2 \le b \le r_2$$$ and $$$a \ne b$$$. In other words, you have to choose two distinct integer points in such a way that the first point belongs to the segment $$$[l_1; r_1]$$$ and the second one belongs to the segment $$$[l_2; r_2]$$$.It is guaranteed that the answer exists. If there are multiple answers, you can print any of them.You have to answer $$$q$$$ independent queries. | 256 megabytes | import java.util.Scanner;
public class two_distinct_points {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t>0)
{
int l1 = sc.nextInt();
int r1 = sc.nextInt();
int l2 = sc.nextInt();
int r2 = sc.nextInt();
while(true)
if(l1!=r2){
System.out.println(l1+ " " + r2);
break;
} else {
l1 = l1+1;
l2 = l2+1;
}
t--;
}
sc.close();
}
}
| Java | ["5\n1 2 1 2\n2 6 3 4\n2 4 1 3\n1 2 1 3\n1 4 5 8"] | 1 second | ["2 1\n3 4\n3 2\n1 2\n3 7"] | null | Java 11 | standard input | [
"implementation"
] | cdafe800094113515e1de1acb60c4bb5 | The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) β the number of queries. Each of the next $$$q$$$ lines contains four integers $$$l_{1_i}, r_{1_i}, l_{2_i}$$$ and $$$r_{2_i}$$$ ($$$1 \le l_{1_i}, r_{1_i}, l_{2_i}, r_{2_i} \le 10^9, l_{1_i} < r_{1_i}, l_{2_i} < r_{2_i}$$$) β the ends of the segments in the $$$i$$$-th query. | 800 | Print $$$2q$$$ integers. For the $$$i$$$-th query print two integers $$$a_i$$$ and $$$b_i$$$ β such numbers that $$$l_{1_i} \le a_i \le r_{1_i}$$$, $$$l_{2_i} \le b_i \le r_{2_i}$$$ and $$$a_i \ne b_i$$$. Queries are numbered in order of the input. It is guaranteed that the answer exists. If there are multiple answers, you can print any. | standard output | |
PASSED | 41a1dd744cdb71514a99705c2fe1ed19 | train_003.jsonl | 1548254100 | You are given two segments $$$[l_1; r_1]$$$ and $$$[l_2; r_2]$$$ on the $$$x$$$-axis. It is guaranteed that $$$l_1 < r_1$$$ and $$$l_2 < r_2$$$. Segments may intersect, overlap or even coincide with each other. The example of two segments on the $$$x$$$-axis. Your problem is to find two integers $$$a$$$ and $$$b$$$ such that $$$l_1 \le a \le r_1$$$, $$$l_2 \le b \le r_2$$$ and $$$a \ne b$$$. In other words, you have to choose two distinct integer points in such a way that the first point belongs to the segment $$$[l_1; r_1]$$$ and the second one belongs to the segment $$$[l_2; r_2]$$$.It is guaranteed that the answer exists. If there are multiple answers, you can print any of them.You have to answer $$$q$$$ independent queries. | 256 megabytes | import java.io.*;
import java.util.*;
public class Twodistinctpoints
{
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int numofqueries = Integer.parseInt(st.nextToken());
while(numofqueries != 0)
{
st = new StringTokenizer(br.readLine());
int lb1 = Integer.parseInt(st.nextToken());
int ub1 = Integer.parseInt(st.nextToken());
int lb2 = Integer.parseInt(st.nextToken());
int ub2 = Integer.parseInt(st.nextToken());
if(lb1==lb2 && ub1==ub2 || (lb1==lb2 && (ub1>ub2 || ub1<ub2)) || ((lb1>lb2 || lb1<lb2) && ub1==ub2))
System.out.println(lb1 + " " + ub2);
else
System.out.println(lb1 + " " + lb2);
numofqueries--;
}
}
}
| Java | ["5\n1 2 1 2\n2 6 3 4\n2 4 1 3\n1 2 1 3\n1 4 5 8"] | 1 second | ["2 1\n3 4\n3 2\n1 2\n3 7"] | null | Java 11 | standard input | [
"implementation"
] | cdafe800094113515e1de1acb60c4bb5 | The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) β the number of queries. Each of the next $$$q$$$ lines contains four integers $$$l_{1_i}, r_{1_i}, l_{2_i}$$$ and $$$r_{2_i}$$$ ($$$1 \le l_{1_i}, r_{1_i}, l_{2_i}, r_{2_i} \le 10^9, l_{1_i} < r_{1_i}, l_{2_i} < r_{2_i}$$$) β the ends of the segments in the $$$i$$$-th query. | 800 | Print $$$2q$$$ integers. For the $$$i$$$-th query print two integers $$$a_i$$$ and $$$b_i$$$ β such numbers that $$$l_{1_i} \le a_i \le r_{1_i}$$$, $$$l_{2_i} \le b_i \le r_{2_i}$$$ and $$$a_i \ne b_i$$$. Queries are numbered in order of the input. It is guaranteed that the answer exists. If there are multiple answers, you can print any. | standard output | |
PASSED | 58057c0dd05588193684a969e3ea77f5 | train_003.jsonl | 1548254100 | You are given two segments $$$[l_1; r_1]$$$ and $$$[l_2; r_2]$$$ on the $$$x$$$-axis. It is guaranteed that $$$l_1 < r_1$$$ and $$$l_2 < r_2$$$. Segments may intersect, overlap or even coincide with each other. The example of two segments on the $$$x$$$-axis. Your problem is to find two integers $$$a$$$ and $$$b$$$ such that $$$l_1 \le a \le r_1$$$, $$$l_2 \le b \le r_2$$$ and $$$a \ne b$$$. In other words, you have to choose two distinct integer points in such a way that the first point belongs to the segment $$$[l_1; r_1]$$$ and the second one belongs to the segment $$$[l_2; r_2]$$$.It is guaranteed that the answer exists. If there are multiple answers, you can print any of them.You have to answer $$$q$$$ independent queries. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
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;
}
}
public static void main(String[] args)
{
FastReader s=new FastReader();
int q=s.nextInt();
while(q-->0)
{
long l1=s.nextLong();
long r1=s.nextLong();
long l2=s.nextLong();
long r2=s.nextLong();
if(r1!=l2)
System.out.println(r1+" "+l2);
else{
System.out.println(l1+" "+r2);
}
}
}
} | Java | ["5\n1 2 1 2\n2 6 3 4\n2 4 1 3\n1 2 1 3\n1 4 5 8"] | 1 second | ["2 1\n3 4\n3 2\n1 2\n3 7"] | null | Java 11 | standard input | [
"implementation"
] | cdafe800094113515e1de1acb60c4bb5 | The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) β the number of queries. Each of the next $$$q$$$ lines contains four integers $$$l_{1_i}, r_{1_i}, l_{2_i}$$$ and $$$r_{2_i}$$$ ($$$1 \le l_{1_i}, r_{1_i}, l_{2_i}, r_{2_i} \le 10^9, l_{1_i} < r_{1_i}, l_{2_i} < r_{2_i}$$$) β the ends of the segments in the $$$i$$$-th query. | 800 | Print $$$2q$$$ integers. For the $$$i$$$-th query print two integers $$$a_i$$$ and $$$b_i$$$ β such numbers that $$$l_{1_i} \le a_i \le r_{1_i}$$$, $$$l_{2_i} \le b_i \le r_{2_i}$$$ and $$$a_i \ne b_i$$$. Queries are numbered in order of the input. It is guaranteed that the answer exists. If there are multiple answers, you can print any. | standard output | |
PASSED | af9e8bdbe84dbdc5c36fddf8a95cb054 | train_003.jsonl | 1548254100 | You are given two segments $$$[l_1; r_1]$$$ and $$$[l_2; r_2]$$$ on the $$$x$$$-axis. It is guaranteed that $$$l_1 < r_1$$$ and $$$l_2 < r_2$$$. Segments may intersect, overlap or even coincide with each other. The example of two segments on the $$$x$$$-axis. Your problem is to find two integers $$$a$$$ and $$$b$$$ such that $$$l_1 \le a \le r_1$$$, $$$l_2 \le b \le r_2$$$ and $$$a \ne b$$$. In other words, you have to choose two distinct integer points in such a way that the first point belongs to the segment $$$[l_1; r_1]$$$ and the second one belongs to the segment $$$[l_2; r_2]$$$.It is guaranteed that the answer exists. If there are multiple answers, you can print any of them.You have to answer $$$q$$$ independent queries. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Main
{
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
int q=s.nextInt();
while(q-->0)
{
long l1=s.nextLong();
long r1=s.nextLong();
long l2=s.nextLong();
long r2=s.nextLong();
if(r1!=l2)
System.out.println(r1+" "+l2);
else{
System.out.println(l1+" "+r2);
}
}
}
} | Java | ["5\n1 2 1 2\n2 6 3 4\n2 4 1 3\n1 2 1 3\n1 4 5 8"] | 1 second | ["2 1\n3 4\n3 2\n1 2\n3 7"] | null | Java 11 | standard input | [
"implementation"
] | cdafe800094113515e1de1acb60c4bb5 | The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) β the number of queries. Each of the next $$$q$$$ lines contains four integers $$$l_{1_i}, r_{1_i}, l_{2_i}$$$ and $$$r_{2_i}$$$ ($$$1 \le l_{1_i}, r_{1_i}, l_{2_i}, r_{2_i} \le 10^9, l_{1_i} < r_{1_i}, l_{2_i} < r_{2_i}$$$) β the ends of the segments in the $$$i$$$-th query. | 800 | Print $$$2q$$$ integers. For the $$$i$$$-th query print two integers $$$a_i$$$ and $$$b_i$$$ β such numbers that $$$l_{1_i} \le a_i \le r_{1_i}$$$, $$$l_{2_i} \le b_i \le r_{2_i}$$$ and $$$a_i \ne b_i$$$. Queries are numbered in order of the input. It is guaranteed that the answer exists. If there are multiple answers, you can print any. | standard output | |
PASSED | a37f6779afc33704cfa3b6020dcce857 | train_003.jsonl | 1548254100 | You are given two segments $$$[l_1; r_1]$$$ and $$$[l_2; r_2]$$$ on the $$$x$$$-axis. It is guaranteed that $$$l_1 < r_1$$$ and $$$l_2 < r_2$$$. Segments may intersect, overlap or even coincide with each other. The example of two segments on the $$$x$$$-axis. Your problem is to find two integers $$$a$$$ and $$$b$$$ such that $$$l_1 \le a \le r_1$$$, $$$l_2 \le b \le r_2$$$ and $$$a \ne b$$$. In other words, you have to choose two distinct integer points in such a way that the first point belongs to the segment $$$[l_1; r_1]$$$ and the second one belongs to the segment $$$[l_2; r_2]$$$.It is guaranteed that the answer exists. If there are multiple answers, you can print any of them.You have to answer $$$q$$$ independent queries. | 256 megabytes | // package cp;
import java.io.*;
import java.math.*;
import java.util.*;
public class Cf_three {
long gcd(long a,long b) {if(b==0)return a;else return gcd(b,a%b);}
void swap(long a,long b) {long temp=a;a=b;b=temp;}
public static void main(String[] args) throws IOException {
PrintWriter out = new PrintWriter(System.out);
Readers.init(System.in);
int q=Readers.nextInt();
for (int i = 0; i < q; i++) {
int l1=Readers.nextInt();
int r1=Readers.nextInt();
int l2=Readers.nextInt();
int r2=Readers.nextInt();
if(l1==r2)System.out.println(l1 +" "+l2);
else System.out.println(l1 + " "+r2);
}
out.flush();
}
}
class Readers {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(
new InputStreamReader(input) );
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while ( ! tokenizer.hasMoreTokens() ) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(
reader.readLine() );
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt( next() );
}
static double nextDouble() throws IOException {
return Double.parseDouble( next() );
}
static long nextLong() throws IOException{
return Long.parseLong(next());
}
} | Java | ["5\n1 2 1 2\n2 6 3 4\n2 4 1 3\n1 2 1 3\n1 4 5 8"] | 1 second | ["2 1\n3 4\n3 2\n1 2\n3 7"] | null | Java 11 | standard input | [
"implementation"
] | cdafe800094113515e1de1acb60c4bb5 | The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) β the number of queries. Each of the next $$$q$$$ lines contains four integers $$$l_{1_i}, r_{1_i}, l_{2_i}$$$ and $$$r_{2_i}$$$ ($$$1 \le l_{1_i}, r_{1_i}, l_{2_i}, r_{2_i} \le 10^9, l_{1_i} < r_{1_i}, l_{2_i} < r_{2_i}$$$) β the ends of the segments in the $$$i$$$-th query. | 800 | Print $$$2q$$$ integers. For the $$$i$$$-th query print two integers $$$a_i$$$ and $$$b_i$$$ β such numbers that $$$l_{1_i} \le a_i \le r_{1_i}$$$, $$$l_{2_i} \le b_i \le r_{2_i}$$$ and $$$a_i \ne b_i$$$. Queries are numbered in order of the input. It is guaranteed that the answer exists. If there are multiple answers, you can print any. | standard output | |
PASSED | 268b4ce5b72259c8e8b7c6dedf364cf4 | train_003.jsonl | 1548254100 | You are given two segments $$$[l_1; r_1]$$$ and $$$[l_2; r_2]$$$ on the $$$x$$$-axis. It is guaranteed that $$$l_1 < r_1$$$ and $$$l_2 < r_2$$$. Segments may intersect, overlap or even coincide with each other. The example of two segments on the $$$x$$$-axis. Your problem is to find two integers $$$a$$$ and $$$b$$$ such that $$$l_1 \le a \le r_1$$$, $$$l_2 \le b \le r_2$$$ and $$$a \ne b$$$. In other words, you have to choose two distinct integer points in such a way that the first point belongs to the segment $$$[l_1; r_1]$$$ and the second one belongs to the segment $$$[l_2; r_2]$$$.It is guaranteed that the answer exists. If there are multiple answers, you can print any of them.You have to answer $$$q$$$ independent queries. | 256 megabytes | import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class CodeChef
{
public static void main(String[] args) throws IOException
{
Scanner scan = new Scanner(System.in);
int testcases = scan.nextInt();
for(int m=0; m<testcases; m++)
{
int l1 = scan.nextInt();
int r1 = scan.nextInt();
int l2 = scan.nextInt();
int r2 = scan.nextInt();
if(l1==l2)
{
System.out.println(l1+" "+r2);
}
else System.out.println(l1+" "+l2);
}
}
} | Java | ["5\n1 2 1 2\n2 6 3 4\n2 4 1 3\n1 2 1 3\n1 4 5 8"] | 1 second | ["2 1\n3 4\n3 2\n1 2\n3 7"] | null | Java 11 | standard input | [
"implementation"
] | cdafe800094113515e1de1acb60c4bb5 | The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) β the number of queries. Each of the next $$$q$$$ lines contains four integers $$$l_{1_i}, r_{1_i}, l_{2_i}$$$ and $$$r_{2_i}$$$ ($$$1 \le l_{1_i}, r_{1_i}, l_{2_i}, r_{2_i} \le 10^9, l_{1_i} < r_{1_i}, l_{2_i} < r_{2_i}$$$) β the ends of the segments in the $$$i$$$-th query. | 800 | Print $$$2q$$$ integers. For the $$$i$$$-th query print two integers $$$a_i$$$ and $$$b_i$$$ β such numbers that $$$l_{1_i} \le a_i \le r_{1_i}$$$, $$$l_{2_i} \le b_i \le r_{2_i}$$$ and $$$a_i \ne b_i$$$. Queries are numbered in order of the input. It is guaranteed that the answer exists. If there are multiple answers, you can print any. | standard output | |
PASSED | 9c4bcd3d56004f4691f8603f64b55828 | train_003.jsonl | 1344958200 | One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B, then student B is an archenemy to student A.The students want to split so as no two archenemies were in one team. If splitting in the required manner is impossible, some students will have to sit on the bench.Determine the minimum number of students you will have to send to the bench in order to form the two teams in the described manner and begin the game at last. | 256 megabytes | import java.util.*;
public class cf216b {
static int n, numColors = 0;
static ArrayList<Integer>[] g;
static int[] color;
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
n = in.nextInt();
int m = in.nextInt();
g = new ArrayList[n];
color = new int[n];
Arrays.fill(color, -1);
for(int i=0; i<n; i++)
g[i] = new ArrayList<Integer>();
for(int i=0; i<m; i++) {
int a = in.nextInt()-1;
int b = in.nextInt()-1;
g[a].add(b);
g[b].add(a);
}
for(int i=0; i<n; i++)
if(color[i] == -1)
color(i,numColors++);
boolean[] ring = new boolean[numColors];
int[] size = new int[numColors];
Arrays.fill(ring,true);
for(int i=0; i<n; i++) {
if(g[i].size() < 2)
ring[color[i]] = false;
size[color[i]]++;
}
int ans = 0;
for(int i=0; i<numColors; i++)
if(ring[i] && size[i]%2==1)
ans++;
if((n-ans)%2==1)
ans++;
System.out.println(ans);
}
static void color(int x, int c) {
if(color[x] != -1) return;
color[x] = c;
for(int y : g[x])
color(y,c);
}
}
| Java | ["5 4\n1 2\n2 4\n5 3\n1 4", "6 2\n1 4\n3 4", "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4"] | 2 seconds | ["1", "0", "2"] | null | Java 6 | standard input | [
"implementation",
"dfs and similar"
] | a0e55bfbdeb3dc550e1f86b9fa7cb06d | The first line contains two integers n and m (2ββ€βnββ€β100, 1ββ€βmββ€β100) β the number of students and the number of pairs of archenemies correspondingly. Next m lines describe enmity between students. Each enmity is described as two numbers ai and bi (1ββ€βai,βbiββ€βn, aiββ βbi) β the indexes of the students who are enemies to each other. Each enmity occurs in the list exactly once. It is guaranteed that each student has no more than two archenemies. You can consider the students indexed in some manner with distinct integers from 1 to n. | 1,700 | Print a single integer β the minimum number of students you will have to send to the bench in order to start the game. | standard output | |
PASSED | 2dc9e53822f52433a26f8af341a8b36c | train_003.jsonl | 1344958200 | One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B, then student B is an archenemy to student A.The students want to split so as no two archenemies were in one team. If splitting in the required manner is impossible, some students will have to sit on the bench.Determine the minimum number of students you will have to send to the bench in order to form the two teams in the described manner and begin the game at last. | 256 megabytes | import java.util.*;
import java.lang.reflect.Array;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
public class Main {
//ArrayList<Integer> lis = new ArrayList<Integer>();
//ArrayList<String> lis = new ArrayList<String>();
//ArrayList<test> lis = new ArrayList<test>();
// static long sum=0;
// static boolean f=false;
//static String s[],r="";
// static int dx[]={1,-1,0,0,1,1,-1,-1};
// static int dy[]={0,0,1,-1,1,-1,1,-1},n,m,w=0;
static int N,r;
static boolean b[][],c[],h;
public static void main(String[] args) {
//googlein.txt C-small-attempt0.in
// Scanner sc =new Scanner(new File("file.txt"));
Scanner sc =new Scanner(System.in);
//File file = new File("file.txt");
// PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file)));
// sc.useDelimiter("(\\s)+|[,]");
while(sc.hasNext()){
//long sum=0;
// int m=sc.nextInt(),n=sc.nextInt(),k=sc.nextInt(),r=0;
int n=sc.nextInt(),m=sc.nextInt();
b=new boolean[n][n];
c=new boolean[n];
r=0;
for(int i=0;i<m;i++){
int x=sc.nextInt()-1,y=sc.nextInt()-1;
b[x][y]=b[y][x]=true;
}
N=n;
int ki=0,ii=0;
for(int i=0;i<n;i++){
h=false;
if(!c[i] ){
c[i]=true;
int g=rep(i,-1);
//db(i,g,h);
if(g==1) {ii++; continue;}
if(g%2==1 ){if(h)r++; else ki++;}
}
}
System.out.println((ki+ii)%2+r);
}
}
// db("Case #"+(k)+": "+c);
// pw.println("Case #"+(k)+": "+c);
//pw.flush();
//pw.close();
static int rep(int k,int pr){
int s=1;
//db(k,pr);
for(int i=0;i<N; i++){
if(i!=pr && c[i] && b[k][i] ){
c[i]=true;
h=true;
return s;
}
if(!c[i] && b[k][i] ){
c[i]=true;
s+=rep(i,k);
}
}
// db(s);
return s;
}
static void db(Object... os){
System.err.println(Arrays.deepToString(os));
}
}
| Java | ["5 4\n1 2\n2 4\n5 3\n1 4", "6 2\n1 4\n3 4", "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4"] | 2 seconds | ["1", "0", "2"] | null | Java 6 | standard input | [
"implementation",
"dfs and similar"
] | a0e55bfbdeb3dc550e1f86b9fa7cb06d | The first line contains two integers n and m (2ββ€βnββ€β100, 1ββ€βmββ€β100) β the number of students and the number of pairs of archenemies correspondingly. Next m lines describe enmity between students. Each enmity is described as two numbers ai and bi (1ββ€βai,βbiββ€βn, aiββ βbi) β the indexes of the students who are enemies to each other. Each enmity occurs in the list exactly once. It is guaranteed that each student has no more than two archenemies. You can consider the students indexed in some manner with distinct integers from 1 to n. | 1,700 | Print a single integer β the minimum number of students you will have to send to the bench in order to start the game. | standard output | |
PASSED | bcac6058c491b07416f04144dddc6a7a | train_003.jsonl | 1344958200 | One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B, then student B is an archenemy to student A.The students want to split so as no two archenemies were in one team. If splitting in the required manner is impossible, some students will have to sit on the bench.Determine the minimum number of students you will have to send to the bench in order to form the two teams in the described manner and begin the game at last. | 256 megabytes |
import java.awt.Point;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.Queue;
import java.util.StringTokenizer;
public class FormingTeams {
void run() throws Exception {
BufferedReader bfd = new BufferedReader(
new InputStreamReader(System.in));
StringTokenizer tk = new StringTokenizer(bfd.readLine());
int n = Integer.parseInt(tk.nextToken());
int m = Integer.parseInt(tk.nextToken());
boolean adj[][] = new boolean[n][n];
for (int i = 0; i < m; ++i) {
tk = new StringTokenizer(bfd.readLine());
int a = Integer.parseInt(tk.nextToken()) - 1;
int b = Integer.parseInt(tk.nextToken()) - 1;
adj[a][b] = adj[b][a] = true;
}
int cnt = 0;
boolean vis[] = new boolean[n];
for (int i = 0; i < n; ++i) {
if(!vis[i]) {
vis[i] = true;
// bfs from here
HashMap<Integer, Integer> id2clr = new HashMap<Integer, Integer>();
Queue<Point> q = new LinkedList<Point>(); // point of int,clr
q.add(new Point(i, 1));
vis[i] = true;
id2clr.put(i, 1);
while(!q.isEmpty()) {
Point frnt = q.poll();
for (int j = 0; j < n; ++j) {
if(!vis[j] && adj[frnt.x][j]) {
Point p = new Point(j, 1 - frnt.y);
q.add(p);
vis[j] = true;
id2clr.put(j, 1 - frnt.y);
}
}
}
boolean ok = true;
for (Entry<Integer, Integer> e: id2clr.entrySet()) {
int id = e.getKey();
int clr = e.getValue();
for (int j = 0; j < n; ++j) {
if (adj[id][j] && id2clr.containsKey(j) && id2clr.get(j)==clr)
ok = false;
}
}
if(!ok) ++cnt;
}
}
if(((n - cnt) & 1) != 0)
cnt++;
System.out.println(cnt);
}
public static void main(String[] args) throws Exception {
new FormingTeams().run();
}
}
| Java | ["5 4\n1 2\n2 4\n5 3\n1 4", "6 2\n1 4\n3 4", "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4"] | 2 seconds | ["1", "0", "2"] | null | Java 6 | standard input | [
"implementation",
"dfs and similar"
] | a0e55bfbdeb3dc550e1f86b9fa7cb06d | The first line contains two integers n and m (2ββ€βnββ€β100, 1ββ€βmββ€β100) β the number of students and the number of pairs of archenemies correspondingly. Next m lines describe enmity between students. Each enmity is described as two numbers ai and bi (1ββ€βai,βbiββ€βn, aiββ βbi) β the indexes of the students who are enemies to each other. Each enmity occurs in the list exactly once. It is guaranteed that each student has no more than two archenemies. You can consider the students indexed in some manner with distinct integers from 1 to n. | 1,700 | Print a single integer β the minimum number of students you will have to send to the bench in order to start the game. | standard output | |
PASSED | d93549fe61223a025bcc80cacb8973fb | train_003.jsonl | 1344958200 | One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B, then student B is an archenemy to student A.The students want to split so as no two archenemies were in one team. If splitting in the required manner is impossible, some students will have to sit on the bench.Determine the minimum number of students you will have to send to the bench in order to form the two teams in the described manner and begin the game at last. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class B {
int n, m, res;
boolean[][] a;
int[] u;
void f(int k){
boolean A = true, B = true;
for(int i=0;i<n;i++){
if(a[k][i]&&0==u[i])A = false;
if(a[k][i]&&1==u[i])B = false;
}
if(!A&&!B)return;
u[k] = A?0:1;
res++;
for(int i=0;i<n;i++)if(a[k][i]&&u[i]==-1)f(i);
}
void run(){
Scanner sc = new Scanner(System.in);
n = sc.nextInt(); m = sc.nextInt();
a = new boolean[n][n];
while(m--!=0){
int s = sc.nextInt()-1, t = sc.nextInt()-1;
a[s][t] = a[t][s] = true;
}
u = new int[n];
Arrays.fill(u, -1);
for(int i=0;i<n;i++)if(u[i]==-1)f(i);
int num = 0;
for(int i:u)if(i==-1)num++;
System.out.println((num+(res&1)));
}
void debug(Object...o){
System.out.println(Arrays.deepToString(o));
}
public static void main(String[] args) {
new B().run();
}
} | Java | ["5 4\n1 2\n2 4\n5 3\n1 4", "6 2\n1 4\n3 4", "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4"] | 2 seconds | ["1", "0", "2"] | null | Java 6 | standard input | [
"implementation",
"dfs and similar"
] | a0e55bfbdeb3dc550e1f86b9fa7cb06d | The first line contains two integers n and m (2ββ€βnββ€β100, 1ββ€βmββ€β100) β the number of students and the number of pairs of archenemies correspondingly. Next m lines describe enmity between students. Each enmity is described as two numbers ai and bi (1ββ€βai,βbiββ€βn, aiββ βbi) β the indexes of the students who are enemies to each other. Each enmity occurs in the list exactly once. It is guaranteed that each student has no more than two archenemies. You can consider the students indexed in some manner with distinct integers from 1 to n. | 1,700 | Print a single integer β the minimum number of students you will have to send to the bench in order to start the game. | standard output | |
PASSED | a7868d9de2c2f30cd73a3744f98d100c | train_003.jsonl | 1344958200 | One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B, then student B is an archenemy to student A.The students want to split so as no two archenemies were in one team. If splitting in the required manner is impossible, some students will have to sit on the bench.Determine the minimum number of students you will have to send to the bench in order to form the two teams in the described manner and begin the game at last. | 256 megabytes | import java.awt.*;
import java.awt.geom.*;
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
/*
br = new BufferedReader(new FileReader("input.txt"));
pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
br = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
*/
public class Main {
private static BufferedReader br;
private static StringTokenizer st;
private static PrintWriter pw;
static boolean[][] grid;
static boolean[] seen;
static boolean[] processed;
static int ret = 0;
public static void main(String[] args) throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
int n = readInt();
int m = readInt();
ret = 0;
seen = new boolean[n];
processed = new boolean[n];
grid = new boolean[n][n];
for(int i = 0; i < m; i++) {
int a = readInt();
int b = readInt();
a--;
b--;
grid[a][b] = grid[b][a] = true;
}
for(int i = 0; i < n; i++) {
dfs(-1, i, 0);
}
if(n%2 != ret%2)
ret++;
pw.println(ret);
pw.close();
}
public static void dfs(int from, int curr, int depth) {
if(processed[curr])
return;
if(seen[curr]) {
if(depth == 1)
ret++;
}
else {
seen[curr] = true;
for(int j = 0; j < grid[curr].length; j++) {
if(grid[curr][j] && j != from) {
dfs(curr, j, depth^1);
}
}
processed[curr] = true;
}
}
/* NOTEBOOK CODE */
public static void loadArray(int[][] grid) throws IOException {
for(int[] a: grid)
loadArray(a);
}
public static void loadArray(int[] in) throws IOException {
for(int i = 0; i < in.length; i++)
in[i] = readInt();
}
public static void loadArray(long[] in) throws IOException {
for(int i = 0; i < in.length; i++)
in[i] = readLong();
}
private static long readLong() throws IOException {
return Long.parseLong(nextToken());
}
private static double readDouble() throws IOException {
return Double.parseDouble(nextToken());
}
private static int readInt() throws IOException {
return Integer.parseInt(nextToken());
}
private static String nextToken() throws IOException {
while(st == null || !st.hasMoreTokens()) {
if(!br.ready()) {
pw.close();
System.exit(0);
}
st = new StringTokenizer(br.readLine().trim());
}
return st.nextToken();
}
} | Java | ["5 4\n1 2\n2 4\n5 3\n1 4", "6 2\n1 4\n3 4", "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4"] | 2 seconds | ["1", "0", "2"] | null | Java 6 | standard input | [
"implementation",
"dfs and similar"
] | a0e55bfbdeb3dc550e1f86b9fa7cb06d | The first line contains two integers n and m (2ββ€βnββ€β100, 1ββ€βmββ€β100) β the number of students and the number of pairs of archenemies correspondingly. Next m lines describe enmity between students. Each enmity is described as two numbers ai and bi (1ββ€βai,βbiββ€βn, aiββ βbi) β the indexes of the students who are enemies to each other. Each enmity occurs in the list exactly once. It is guaranteed that each student has no more than two archenemies. You can consider the students indexed in some manner with distinct integers from 1 to n. | 1,700 | Print a single integer β the minimum number of students you will have to send to the bench in order to start the game. | standard output | |
PASSED | 3208a3058fcbf5fa96c784bb62deb702 | train_003.jsonl | 1344958200 | One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B, then student B is an archenemy to student A.The students want to split so as no two archenemies were in one team. If splitting in the required manner is impossible, some students will have to sit on the bench.Determine the minimum number of students you will have to send to the bench in order to form the two teams in the described manner and begin the game at last. | 256 megabytes | import java.util.*;
public class Main{
int n,m;
boolean g[][];
int []col;
public void run(){
Scanner in = new Scanner(System.in);
n = in.nextInt();
m = in.nextInt();
g = new boolean[n][n];
for(int i=0;i<m;i++){
int a = in.nextInt()-1;
int b = in.nextInt()-1;
g[a][b] = g[b][a] = true;
}
int ret = 0;
col = new int[n];
Arrays.fill(col, -1);
for(int i=0;i<n;i++)
if (col[i] == -1)
if (!dfs(i, 0)) ret++;
if ((n - ret)%2 != 0) ret++;
System.out.println(ret);
}
private boolean dfs(int x, int c){
if (col[x] != -1) return col[x] == c;
col[x] = c;
boolean ret = true;
for(int i=0;i<n;i++)
if (g[x][i])
ret&=dfs(i, 1-c);
return ret;
}
public static void main(String[] args) {
new Main().run();
}
} | Java | ["5 4\n1 2\n2 4\n5 3\n1 4", "6 2\n1 4\n3 4", "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4"] | 2 seconds | ["1", "0", "2"] | null | Java 6 | standard input | [
"implementation",
"dfs and similar"
] | a0e55bfbdeb3dc550e1f86b9fa7cb06d | The first line contains two integers n and m (2ββ€βnββ€β100, 1ββ€βmββ€β100) β the number of students and the number of pairs of archenemies correspondingly. Next m lines describe enmity between students. Each enmity is described as two numbers ai and bi (1ββ€βai,βbiββ€βn, aiββ βbi) β the indexes of the students who are enemies to each other. Each enmity occurs in the list exactly once. It is guaranteed that each student has no more than two archenemies. You can consider the students indexed in some manner with distinct integers from 1 to n. | 1,700 | Print a single integer β the minimum number of students you will have to send to the bench in order to start the game. | standard output | |
PASSED | 6b5c91d033f872946632cda138cf9d50 | train_003.jsonl | 1344958200 | One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B, then student B is an archenemy to student A.The students want to split so as no two archenemies were in one team. If splitting in the required manner is impossible, some students will have to sit on the bench.Determine the minimum number of students you will have to send to the bench in order to form the two teams in the described manner and begin the game at last. | 256 megabytes | import java.util.*;
public class Main{
int n,m;
boolean g[][];
boolean []used;
int []col, comp;
public void run(){
Scanner in = new Scanner(System.in);
n = in.nextInt();
m = in.nextInt();
g = new boolean[n][n];
for(int i=0;i<m;i++){
int a = in.nextInt()-1;
int b = in.nextInt()-1;
g[a][b] = g[b][a] = true;
}
int f1 = 0, f2 = 0, ret = 0, c = 0;
col = new int[n];
comp = new int[n];
used = new boolean[n];
for(int i=0;i<n;i++){
if (!used[i]){
Arrays.fill(col, -1);
c++;
dfs(i, 0, c);
int b = 0, w = 0, all = 0;
for(int j=0;j<n;j++){
if (col[j] == 0) b++;
if (col[j] == 1) w++;
if (comp[j] == c) all++;
}
//System.out.println(Arrays.toString(col));
//System.out.println(b + " " + w + " " + all);
if (f1 > f2){
f1+=Math.min(b, w);
f2+=Math.max(b, w);
}else{
f1+=Math.max(b, w);
f2+=Math.min(b, w);
}
ret+=all - b - w;
}
}
System.out.println(ret+Math.abs(f1 - f2));
}
private void dfs(int x, int c, int l){
used[x] = true;
col[x] = c;
comp[x] = l;
for(int i=0;i<n;i++){
if (g[x][i]){
if (used[i]){
if (col[i] == c){
col[x] = -1;
return;
}
}else{
dfs(i, 1-c, l);
}
}
}
}
public static void main(String[] args) {
new Main().run();
}
} | Java | ["5 4\n1 2\n2 4\n5 3\n1 4", "6 2\n1 4\n3 4", "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4"] | 2 seconds | ["1", "0", "2"] | null | Java 6 | standard input | [
"implementation",
"dfs and similar"
] | a0e55bfbdeb3dc550e1f86b9fa7cb06d | The first line contains two integers n and m (2ββ€βnββ€β100, 1ββ€βmββ€β100) β the number of students and the number of pairs of archenemies correspondingly. Next m lines describe enmity between students. Each enmity is described as two numbers ai and bi (1ββ€βai,βbiββ€βn, aiββ βbi) β the indexes of the students who are enemies to each other. Each enmity occurs in the list exactly once. It is guaranteed that each student has no more than two archenemies. You can consider the students indexed in some manner with distinct integers from 1 to n. | 1,700 | Print a single integer β the minimum number of students you will have to send to the bench in order to start the game. | standard output | |
PASSED | cb93969ab21d5016158954ccbd8a88b1 | train_003.jsonl | 1344958200 | One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B, then student B is an archenemy to student A.The students want to split so as no two archenemies were in one team. If splitting in the required manner is impossible, some students will have to sit on the bench.Determine the minimum number of students you will have to send to the bench in order to form the two teams in the described manner and begin the game at last. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class fasi {
/**
* @param args
* @throws IOException
*/
static int color[];
static boolean v[];
static int ft;
static int st;
public static int check(boolean[][] adj, int start) {
// int[] color = new int[adj.length];
// 0 unvisited , 1 first set , 2 second set
int count = 0;
if (color[start] == 0) {
// System.out.println();
Queue<Integer> q = new LinkedList<Integer>();
q.add(start);
color[start] = 1;
while (!q.isEmpty()) {
int front = q.poll();
//System.out.println(front);
int expected = -1;
if (color[front] == 1)
{
ft++;
expected = 2;
}
else{
st++;
// color = 2
expected = 1;
}
for (int i = 0; i < adj[front].length; i++) {
if (adj[front][i]) {
//System.out.println(i);
if (color[i] != 0) {
if (color[i] != expected)
{
//System.out.println(i);
count++;
}
} else {
color[i] = expected;
q.add(i);
}
}
}
}
}
//System.out.println(ft +" "+st);
return count;
}
public static void main(String[] args) throws IOException {
// BufferedReader reader=new BufferedReader(new
// InputStreamReader(System.in));
// reader.readLine();
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
v=new boolean [n+1];
boolean adj[][] = new boolean[n+1][n+1];
for (int i = 0; i < k; i++) {
int s = sc.nextInt();
int e = sc.nextInt();
adj[s][e] = true;
adj[e][s]=true;
//System.out.println(s+" "+e);
v[s]=true;
v[e]=true;
}
color=new int[n+1];
int sum=0;
int s=0;
for(int i=1;i<n+1;i++)
if(v[i])
s++;
for(int i=1;i<=n;i++)if(v[i]){
//System.out.println(i+" "+check(adj,i));
//System.out.println("koko");
sum+=check(adj,i);
}
sum=sum/2;
//System.out.println(ft+" "+st);
//System.out.println(sum);
if(sum==0)
{
if(ft==st)
System.out.println((Math.abs(n-s)%2));
else
System.out.println((Math.abs(n-(ft+st+Math.abs(ft-st)))%2));
}else
{
int count=ft+st-sum;
count=count+(n-s);
if((count%2)==0)
System.out.println(sum);
else
System.out.println((sum+(count%2)));
}
}
} | Java | ["5 4\n1 2\n2 4\n5 3\n1 4", "6 2\n1 4\n3 4", "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4"] | 2 seconds | ["1", "0", "2"] | null | Java 6 | standard input | [
"implementation",
"dfs and similar"
] | a0e55bfbdeb3dc550e1f86b9fa7cb06d | The first line contains two integers n and m (2ββ€βnββ€β100, 1ββ€βmββ€β100) β the number of students and the number of pairs of archenemies correspondingly. Next m lines describe enmity between students. Each enmity is described as two numbers ai and bi (1ββ€βai,βbiββ€βn, aiββ βbi) β the indexes of the students who are enemies to each other. Each enmity occurs in the list exactly once. It is guaranteed that each student has no more than two archenemies. You can consider the students indexed in some manner with distinct integers from 1 to n. | 1,700 | Print a single integer β the minimum number of students you will have to send to the bench in order to start the game. | standard output | |
PASSED | 745ddaec5fa41702473503abc1d90207 | train_003.jsonl | 1344958200 | One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B, then student B is an archenemy to student A.The students want to split so as no two archenemies were in one team. If splitting in the required manner is impossible, some students will have to sit on the bench.Determine the minimum number of students you will have to send to the bench in order to form the two teams in the described manner and begin the game at last. | 256 megabytes | import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.*;
public class B
{
BufferedReader in;
PrintStream out;
StringTokenizer tok;
public B() throws NumberFormatException, IOException
{
in = new BufferedReader(new InputStreamReader(System.in));
//in = new BufferedReader(new FileReader("in.txt"));
out = System.out;
run();
}
List<Integer>[] G;
boolean[] mark;
int DFS()
{
int ans = 0;
for(int i = 0; i < G.length; i++)
{
if(!mark[i])
{
if(DFS_Visit(i))ans++;
}
}
return ans;
}
boolean DFS_Visit(int s)
{
if(G[s].size()==0) return false;
mark[s] = true;
int cnt=2;
int cur = G[s].get(0);
int prev = s;
while(G[cur].size()==2)
{
mark[cur] = true;
int tmp = cur;
cur = (G[cur].get(0)!=prev)? G[cur].get(0):G[cur].get(1);
if(cur!= s)
cnt++;
else break;
prev = tmp;
}
mark[cur] = true;
return cur==s && cnt%2==1;
}
void run() throws NumberFormatException, IOException
{
int n = nextInt();
int m = nextInt();
G = new ArrayList[n];
mark = new boolean[n];
for(int i = 0; i < n; i++)
G[i] = new ArrayList<Integer>();
for(int i = 0; i < m; i++)
{
int u = nextInt()-1;
int v = nextInt()-1;
G[u].add(v);
G[v].add(u);
}
int ans = DFS();
out.println(ans + (n-ans)%2);
}
public static void main(String[] args) throws NumberFormatException, IOException
{
new B();
}
String nextToken() throws IOException
{
if(tok ==null || !tok.hasMoreTokens()) tok = new StringTokenizer(in.readLine());
return tok.nextToken();
}
int nextInt() throws NumberFormatException, IOException
{
return Integer.parseInt(nextToken());
}
long nextLong() throws NumberFormatException, IOException
{
return Long.parseLong(nextToken());
}
double nextDouble() throws NumberFormatException, IOException
{
return Double.parseDouble(nextToken());
}
}
| Java | ["5 4\n1 2\n2 4\n5 3\n1 4", "6 2\n1 4\n3 4", "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4"] | 2 seconds | ["1", "0", "2"] | null | Java 6 | standard input | [
"implementation",
"dfs and similar"
] | a0e55bfbdeb3dc550e1f86b9fa7cb06d | The first line contains two integers n and m (2ββ€βnββ€β100, 1ββ€βmββ€β100) β the number of students and the number of pairs of archenemies correspondingly. Next m lines describe enmity between students. Each enmity is described as two numbers ai and bi (1ββ€βai,βbiββ€βn, aiββ βbi) β the indexes of the students who are enemies to each other. Each enmity occurs in the list exactly once. It is guaranteed that each student has no more than two archenemies. You can consider the students indexed in some manner with distinct integers from 1 to n. | 1,700 | Print a single integer β the minimum number of students you will have to send to the bench in order to start the game. | standard output | |
PASSED | bac1b02f6ed623a32c664162ddaf2131 | train_003.jsonl | 1344958200 | One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B, then student B is an archenemy to student A.The students want to split so as no two archenemies were in one team. If splitting in the required manner is impossible, some students will have to sit on the bench.Determine the minimum number of students you will have to send to the bench in order to form the two teams in the described manner and begin the game at last. | 256 megabytes | import java.util.Scanner;
public class B {
static boolean[]used;
static int[][]a;
static int cnt = 0, n;
static boolean circle = false;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
int m = sc.nextInt();
a = new int[n+1][n+1];
for (int i = 1; i <= m; i++) {
int v1 = sc.nextInt();
int v2 = sc.nextInt();
a[v1][v2] = a[v2][v1] = 1;
}
used = new boolean[n+1];
int s1 = 0, s2 = 0;
for (int i = 1; i <= n; i++) {
if (!used[i]) {
cnt = 0;
circle = false;
dfs(i, 0);
if (circle && cnt % 2==1)
cnt --;
if (cnt % 2==0) {
s1 += cnt/2;
s2 += cnt/2;
}
else {
if (s1 > s2) {
s1 += cnt/2;
s2 += cnt/2+1;
}
else {
s2 += cnt/2;
s1 += cnt/2+1;
}
}
}
}
cnt = 0;
for (int i = 1; i <= n; i++) {
if (!used[i])
cnt++;
}
if (s1 != s2 && cnt > 0) {
if (s1 < s2)
s1++;
else
s2++;
cnt--;
}
s1 += cnt/2;
s2 += cnt/2;
System.out.println(n-2*Math.min(s1, s2));
}
private static void dfs(int v, int p) {
cnt++;
used[v] = true;
for (int i = 1; i <= n; i++) {
if (a[v][i]==1) {
if (i==p)
continue;
if (used[i])
circle = true;
else
dfs(i, v);
}
}
}
}
| Java | ["5 4\n1 2\n2 4\n5 3\n1 4", "6 2\n1 4\n3 4", "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4"] | 2 seconds | ["1", "0", "2"] | null | Java 6 | standard input | [
"implementation",
"dfs and similar"
] | a0e55bfbdeb3dc550e1f86b9fa7cb06d | The first line contains two integers n and m (2ββ€βnββ€β100, 1ββ€βmββ€β100) β the number of students and the number of pairs of archenemies correspondingly. Next m lines describe enmity between students. Each enmity is described as two numbers ai and bi (1ββ€βai,βbiββ€βn, aiββ βbi) β the indexes of the students who are enemies to each other. Each enmity occurs in the list exactly once. It is guaranteed that each student has no more than two archenemies. You can consider the students indexed in some manner with distinct integers from 1 to n. | 1,700 | Print a single integer β the minimum number of students you will have to send to the bench in order to start the game. | standard output | |
PASSED | 8faf6604c03038ab32e827fc39d6bfe6 | train_003.jsonl | 1344958200 | One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B, then student B is an archenemy to student A.The students want to split so as no two archenemies were in one team. If splitting in the required manner is impossible, some students will have to sit on the bench.Determine the minimum number of students you will have to send to the bench in order to form the two teams in the described manner and begin the game at last. | 256 megabytes | import java.util.ArrayList;
import java.util.Scanner;
public class Teams {
static int[] teams;
static boolean[] seen;
static ArrayList<Integer>[] map;
public static void main(String[] args)
{
Scanner br=new Scanner(System.in);
int n=br.nextInt();
map=new ArrayList[n];
for(int i=0;i<n;i++)
map[i]=new ArrayList<Integer>();
int m=br.nextInt();
for(int i=0;i<m;i++)
{
int a=br.nextInt()-1,b=br.nextInt()-1;
map[a].add(b);
map[b].add(a);
}
teams=new int[n];
seen=new boolean[n];
int count=0;
for(int i=0;i<n;i++)
{
if(!seen[i]&&dfs(i,0))
count++;
}
if((n-count)%2==1)
count++;
System.out.println(count);
}
static boolean dfs(int index,int team)
{
// System.out.println(index+" "+team);
if(teams[index]!=0)
{
if(teams[index]!=team+1)
{
// System.out.println("Returned true");
return true;
}
}
if(seen[index])
return false;
seen[index]=true;
teams[index]=team+1;
boolean ret=false;
for(int n:map[index])
{
ret|=dfs(n,1-team);
}
return ret;
}
}
| Java | ["5 4\n1 2\n2 4\n5 3\n1 4", "6 2\n1 4\n3 4", "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4"] | 2 seconds | ["1", "0", "2"] | null | Java 6 | standard input | [
"implementation",
"dfs and similar"
] | a0e55bfbdeb3dc550e1f86b9fa7cb06d | The first line contains two integers n and m (2ββ€βnββ€β100, 1ββ€βmββ€β100) β the number of students and the number of pairs of archenemies correspondingly. Next m lines describe enmity between students. Each enmity is described as two numbers ai and bi (1ββ€βai,βbiββ€βn, aiββ βbi) β the indexes of the students who are enemies to each other. Each enmity occurs in the list exactly once. It is guaranteed that each student has no more than two archenemies. You can consider the students indexed in some manner with distinct integers from 1 to n. | 1,700 | Print a single integer β the minimum number of students you will have to send to the bench in order to start the game. | standard output | |
PASSED | 1a7eca4e6cdb393c5d0cff2bfd087bbb | train_003.jsonl | 1344958200 | One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B, then student B is an archenemy to student A.The students want to split so as no two archenemies were in one team. If splitting in the required manner is impossible, some students will have to sit on the bench.Determine the minimum number of students you will have to send to the bench in order to form the two teams in the described manner and begin the game at last. | 256 megabytes | import java.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author Erik Odenman
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
TaskB solver = new TaskB();
solver.solve(1, in, out);
out.close();
}
}
class TaskB {
static int[] deg;
static boolean cycle;
static boolean[] visited;
static boolean[][] enemies;
static int n;
public void solve(int testNumber, InputReader in, OutputWriter out) {
n = in.getInt();
int m = in.getInt();
enemies = new boolean[n][n];
deg = new int[n];
for (int i = 0; i < m; i++) {
int a = in.getInt() - 1;
int b = in.getInt() - 1;
deg[a]++;
deg[b]++;
enemies[a][b] = enemies[b][a] = true;
}
int res = 0;
visited = new boolean[n];
int tot = 0;
for (int i = 0; i < n; i++) {
if (!visited[i]) {
cycle = true;
int cnt = dfs(i);
if (cycle && cnt % 2 == 1) {
cnt--;
}
tot += cnt;
}
}
if (tot % 2 == 1) tot--;
out.println(n - tot);
}
static int dfs(int v) {
visited[v] = true;
cycle &= deg[v] == 2;
int res = 1;
for (int i = 0; i < n; i++) {
if (!visited[i] && enemies[v][i]) {
res += dfs(i);
}
}
return res;
}
}
class InputReader {
private BufferedReader in;
private StringTokenizer st;
String token;
public InputReader(InputStream inStream) {
in = new BufferedReader(new InputStreamReader(inStream));
}
public int getInt() {
return Integer.parseInt(next());
}
public String next() {
String res = peekToken();
token = null;
return res;
}
public String peekToken() {
if (token != null) return token;
while (st == null || !st.hasMoreTokens()) {
String line = null;
try {
line = in.readLine();
} catch (IOException e) {
throw new RuntimeException("No more tokens was found");
}
if (line == null) return null;
st = new StringTokenizer(line);
}
return token = st.nextToken();
}
}
class OutputWriter {
PrintWriter out;
public OutputWriter(OutputStream outStream) {
out = new PrintWriter(outStream);
}
public OutputWriter(Writer writer) {
out = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) out.print(' ');
out.print(objects[i]);
}
}
public void println(Object... objects) {
print(objects);
out.println();
}
public void close() {
out.close();
}
}
| Java | ["5 4\n1 2\n2 4\n5 3\n1 4", "6 2\n1 4\n3 4", "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4"] | 2 seconds | ["1", "0", "2"] | null | Java 6 | standard input | [
"implementation",
"dfs and similar"
] | a0e55bfbdeb3dc550e1f86b9fa7cb06d | The first line contains two integers n and m (2ββ€βnββ€β100, 1ββ€βmββ€β100) β the number of students and the number of pairs of archenemies correspondingly. Next m lines describe enmity between students. Each enmity is described as two numbers ai and bi (1ββ€βai,βbiββ€βn, aiββ βbi) β the indexes of the students who are enemies to each other. Each enmity occurs in the list exactly once. It is guaranteed that each student has no more than two archenemies. You can consider the students indexed in some manner with distinct integers from 1 to n. | 1,700 | Print a single integer β the minimum number of students you will have to send to the bench in order to start the game. | standard output | |
PASSED | c2ffd710d5f137920e84696ae1c66490 | train_003.jsonl | 1344958200 | One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B, then student B is an archenemy to student A.The students want to split so as no two archenemies were in one team. If splitting in the required manner is impossible, some students will have to sit on the bench.Determine the minimum number of students you will have to send to the bench in order to form the two teams in the described manner and begin the game at last. | 256 megabytes | import java.io.*;
import java.util.*;
import static java.lang.Math.*;
public class B extends B_Problem {
int n, m, kick;
ArrayList<Integer>[] g;
int[] col;
void solve() {
n = nextInt();
m = nextInt();
g = new ArrayList[n];
for (int i = 0; i < n; i++)
g[i] = new ArrayList<Integer>(0);
for (int i = 0; i < m; i++) {
int x = nextInt() - 1, y = nextInt() - 1;
g[x].add(y);
g[y].add(x);
}
col = new int[n];
for (int i = 0; i < n; i++)
if (col[i] == 0)
dfs(i, 1, -1);
kick /= 2;
if ((n - kick) % 2 == 1)
kick++;
print(kick);
}
void dfs(int v, int c, int p) {
col[v] = c;
for (int next : g[v]) {
if (p == next)
continue;
if (col[next] == 0)
dfs(next, 3 - c, v);
else if (col[next] == col[v])
kick++;
}
}
public static void main(String[] args) {
new Thread(null, new Runnable() {
public void run() {
new B_Solution().run();
}
}, "<3", 1 << 23).start();
}
}
abstract class B_Problem {
abstract void solve();
BufferedReader in;
PrintWriter out;
StringTokenizer tokenizer;
void init(boolean oj) {
Reader reader = null;
Writer writer = null;
if (oj) {
reader = new InputStreamReader(System.in);
writer = new OutputStreamWriter(System.out);
} else
try {
reader = new FileReader("input.txt");
writer = new FileWriter("output.txt");
} catch (Exception e) {
e.printStackTrace();
}
in = new BufferedReader(reader);
out = new PrintWriter(writer);
}
void exit() {
out.close();
System.exit(0);
}
void print(Object... obj) {
for (int i = 0; i < obj.length; i++) {
if (i != 0)
out.print(" ");
out.print(obj[i]);
}
}
void println(Object... obj) {
print(obj);
print("\n");
}
String nextLine() {
try {
return in.readLine();
} catch (Exception e) {
return "EOF";
}
}
String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens())
tokenizer = new StringTokenizer(nextLine());
return tokenizer.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
}
class B_Solution implements Runnable {
private boolean oj;
private long beginTime, beginMem, endTime, endMem;
public void start() {
oj = System.getProperty("ONLINE_JUDGE") != null;
if (!oj) {
beginTime = System.currentTimeMillis();
beginMem = totalMemory() - freeMemory();
}
}
public void finish() {
if (!oj) {
endMem = totalMemory() - freeMemory();
endTime = System.currentTimeMillis();
double mbUsed = 1d * (endMem - beginMem) / 8 / 1024 / 1024;
double msPass = 1d * (endTime - beginTime) / 1000;
System.out.println("Memory used = " + mbUsed + " mb");
System.out.println("Running time = " + msPass + " s");
}
}
public void run() {
this.start();
B_Problem problem = new B();
problem.init(oj);
problem.solve();
problem.out.close();
this.finish();
}
public long totalMemory() {
return Runtime.getRuntime().totalMemory();
}
public long freeMemory() {
return Runtime.getRuntime().freeMemory();
}
} | Java | ["5 4\n1 2\n2 4\n5 3\n1 4", "6 2\n1 4\n3 4", "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4"] | 2 seconds | ["1", "0", "2"] | null | Java 6 | standard input | [
"implementation",
"dfs and similar"
] | a0e55bfbdeb3dc550e1f86b9fa7cb06d | The first line contains two integers n and m (2ββ€βnββ€β100, 1ββ€βmββ€β100) β the number of students and the number of pairs of archenemies correspondingly. Next m lines describe enmity between students. Each enmity is described as two numbers ai and bi (1ββ€βai,βbiββ€βn, aiββ βbi) β the indexes of the students who are enemies to each other. Each enmity occurs in the list exactly once. It is guaranteed that each student has no more than two archenemies. You can consider the students indexed in some manner with distinct integers from 1 to n. | 1,700 | Print a single integer β the minimum number of students you will have to send to the bench in order to start the game. | standard output | |
PASSED | dfd3e762d7a1fc5ebffda58889c9c0b3 | train_003.jsonl | 1344958200 | One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B, then student B is an archenemy to student A.The students want to split so as no two archenemies were in one team. If splitting in the required manner is impossible, some students will have to sit on the bench.Determine the minimum number of students you will have to send to the bench in order to form the two teams in the described manner and begin the game at last. | 256 megabytes | import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner r = new Scanner(System.in);
int N = r.nextInt();
int M = r.nextInt();
g = new ArrayList[N];
for(int i = 0; i < N; i++)
g[i] = new ArrayList<Integer>();
for(int k = 0; k < M; k++){
int i = r.nextInt() - 1;
int j = r.nextInt() - 1;
g[i].add(j);
g[j].add(i);
}
v = new boolean[N];
set = new HashSet<Integer>();
int ret = 0;
int mod = 0;
ML:for(int i = 0; i < N; i++)if(!v[i]){
set.clear();
dfs(i);
if(set.size() == 1){mod++;}
else if(set.size() % 2 == 0)continue;
else if(set.size() % 2 != 0){
for(int x : set)
if(g[x].size() == 1){
mod++;
continue ML;
}
ret++;
}
}
System.out.println(ret + (mod % 2));
}
private static void dfs(int i) {
set.add(i);
v[i] = true;
for(int j : g[i])if(!v[j])
dfs(j);
}
static ArrayList<Integer>[] g;
static HashSet<Integer> set;
static boolean[] v;
}
| Java | ["5 4\n1 2\n2 4\n5 3\n1 4", "6 2\n1 4\n3 4", "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4"] | 2 seconds | ["1", "0", "2"] | null | Java 6 | standard input | [
"implementation",
"dfs and similar"
] | a0e55bfbdeb3dc550e1f86b9fa7cb06d | The first line contains two integers n and m (2ββ€βnββ€β100, 1ββ€βmββ€β100) β the number of students and the number of pairs of archenemies correspondingly. Next m lines describe enmity between students. Each enmity is described as two numbers ai and bi (1ββ€βai,βbiββ€βn, aiββ βbi) β the indexes of the students who are enemies to each other. Each enmity occurs in the list exactly once. It is guaranteed that each student has no more than two archenemies. You can consider the students indexed in some manner with distinct integers from 1 to n. | 1,700 | Print a single integer β the minimum number of students you will have to send to the bench in order to start the game. | standard output | |
PASSED | b779c25e6450bce9b5389608b3032216 | train_003.jsonl | 1344958200 | One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B, then student B is an archenemy to student A.The students want to split so as no two archenemies were in one team. If splitting in the required manner is impossible, some students will have to sit on the bench.Determine the minimum number of students you will have to send to the bench in order to form the two teams in the described manner and begin the game at last. | 256 megabytes | import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
public class ProblemB {
private static ArrayList<Integer>[] students;
private static boolean[] labels;
private static int allOddCycles = 0;
private static void dfs(int v, LinkedList<Integer> path) {
labels[v] = true;
path.push(v);
for (int next : students[v]) {
if (!labels[next]) {
dfs(next, path);
} else {
if (path.peek() != next) {
int index = path.indexOf(next);
if ((index + 1) % 2 == 1) {
allOddCycles++;
}
}
}
}
path.pop();
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
students = new ArrayList[n];
labels = new boolean[n];
Arrays.fill(labels, false);
HashSet<Integer> actualStudents = new HashSet<Integer>();
for (int i = 0; i < n; i++) {
students[i] = new ArrayList();
}
int counter = 0;
for (int i = 0; i < m; i++) {
int a = sc.nextInt() - 1;
int b = sc.nextInt() - 1;
actualStudents.add(a);
actualStudents.add(b);
students[a].add(b);
students[b].add(a);
}
for (int i : actualStudents) {
if (!labels[i])
dfs(i, new LinkedList<Integer>());
}
counter = allOddCycles;
if ((n - counter) % 2 == 1) {
counter += 1;
}
System.out.println(counter);
}
} | Java | ["5 4\n1 2\n2 4\n5 3\n1 4", "6 2\n1 4\n3 4", "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4"] | 2 seconds | ["1", "0", "2"] | null | Java 6 | standard input | [
"implementation",
"dfs and similar"
] | a0e55bfbdeb3dc550e1f86b9fa7cb06d | The first line contains two integers n and m (2ββ€βnββ€β100, 1ββ€βmββ€β100) β the number of students and the number of pairs of archenemies correspondingly. Next m lines describe enmity between students. Each enmity is described as two numbers ai and bi (1ββ€βai,βbiββ€βn, aiββ βbi) β the indexes of the students who are enemies to each other. Each enmity occurs in the list exactly once. It is guaranteed that each student has no more than two archenemies. You can consider the students indexed in some manner with distinct integers from 1 to n. | 1,700 | Print a single integer β the minimum number of students you will have to send to the bench in order to start the game. | standard output | |
PASSED | c33ddd3e5351dfffb7f87cb0abc57a00 | train_003.jsonl | 1344958200 | One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B, then student B is an archenemy to student A.The students want to split so as no two archenemies were in one team. If splitting in the required manner is impossible, some students will have to sit on the bench.Determine the minimum number of students you will have to send to the bench in order to form the two teams in the described manner and begin the game at last. | 256 megabytes | import java.util.Scanner;
public class CF216B {
static int n;
static int m;
static int [][]G;
static int []visited;
static int c;
static int d;
static int start;
public static void DFS(int depth, int id)
{
if (visited[id]!=-1) {
return;
}
visited[id] = c;
for (int i=0; i!=n; i++) {
if(G[id][i]==1) {
if (visited[i]==-1)
DFS(depth+1, i);
else if(depth%2==0 && i==start)
d++;
}
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
m = sc.nextInt();
G = new int[n][n];
for (int i=0; i!=m; i++) {
int s = sc.nextInt(), e = sc.nextInt();
G[s-1][e-1] = 1;
G[e-1][s-1] = 1;
}
visited = new int[n];
for (int i=0; i!=n; i++) {
visited[i] = -1;
}
c = 0;
d = 0;
for (int i=0; i!=n; i++) {
start = i;
if(visited[i]==-1) {
DFS(0, i);
}
else
c++;
}
// System.out.println(d);
if ( (n-d)%2==0 )
System.out.println(d);
else
System.out.println(d+1);
// for(int i=0; i!=n; i++) {
// System.out.print(visited[i] + " ");
// }
// System.out.println();
}
}
| Java | ["5 4\n1 2\n2 4\n5 3\n1 4", "6 2\n1 4\n3 4", "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4"] | 2 seconds | ["1", "0", "2"] | null | Java 6 | standard input | [
"implementation",
"dfs and similar"
] | a0e55bfbdeb3dc550e1f86b9fa7cb06d | The first line contains two integers n and m (2ββ€βnββ€β100, 1ββ€βmββ€β100) β the number of students and the number of pairs of archenemies correspondingly. Next m lines describe enmity between students. Each enmity is described as two numbers ai and bi (1ββ€βai,βbiββ€βn, aiββ βbi) β the indexes of the students who are enemies to each other. Each enmity occurs in the list exactly once. It is guaranteed that each student has no more than two archenemies. You can consider the students indexed in some manner with distinct integers from 1 to n. | 1,700 | Print a single integer β the minimum number of students you will have to send to the bench in order to start the game. | standard output | |
PASSED | 91fabe871a4f889ef2135a22367dd74d | train_003.jsonl | 1344958200 | One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B, then student B is an archenemy to student A.The students want to split so as no two archenemies were in one team. If splitting in the required manner is impossible, some students will have to sit on the bench.Determine the minimum number of students you will have to send to the bench in order to form the two teams in the described manner and begin the game at last. | 256 megabytes | import java.io.*;
import java.util.*;
import java.awt.*;
import static java.lang.Math.*;
public class teams {
static void dbg(Object...os) {
System.err.println(Arrays.deepToString(os));
}
static BufferedReader input;
static StringTokenizer _stk;
static String readln() throws IOException {
String l = input.readLine();
if(l!=null) _stk = new StringTokenizer(l," ");
return l;
}
static String next() { return _stk.nextToken(); };
static int nextInt() { return Integer.parseInt(next()); }
public static void main(String[] args) throws IOException {
Locale.setDefault(Locale.US);
input = new BufferedReader(new InputStreamReader(System.in));
readln();
int N = nextInt();
int E = nextInt();
StronglyCC alg = new StronglyCC(N);
for(int i=0; i<E; i++) {
readln();
int a=nextInt()-1, b=nextInt()-1;
alg.grafo[a].add(b);
alg.grafo[b].add(a);
}
alg.run();
int quedan=N;
for(LinkedList<Integer> scc:alg.sccs) {
//System.err.println("scc size="+scc.size());
if(scc.size()>1 && scc.size()%2!=0) quedan--;
}
if(quedan%2!=0) quedan--;
System.out.println(N-quedan);
}
static class StronglyCC {
int N, curIndex;
LinkedList<Integer> stack = new LinkedList<Integer>();
int instack[], index[], lowlink[];
TreeSet<Integer> grafo[];
LinkedList<LinkedList<Integer>> sccs = new LinkedList<LinkedList<Integer>>();
StronglyCC(int n) {
N = n;
grafo = new TreeSet[N];
for(int i=0; i<N; i++) grafo[i]=new TreeSet<Integer>();
instack = new int[N];
index = new int[N];
lowlink = new int[N];
for(int i=0; i<N; i++) index[i] = lowlink[i] = -1;
}
void run() {
for(int i=0; i<N; i++)
if(index[i]==-1)
tarjan(i);
}
HashSet<Point> used = new HashSet<Point>();
void tarjan(int v) {
index[v] = lowlink[v] = curIndex;
curIndex ++;
stack.push(v);
instack[v]++;
//for(int j=0; j<N; j++) if(grafo[v][j]){
for(int x : grafo[v]) {
Point key = new Point(min(x,v),max(x,v));
if(used.contains(key)) continue;
used.add(key);
if(index[x]==-1) {
tarjan(x);
lowlink[v] = Math.min(lowlink[v], lowlink[x]);
}
else if(instack[x]>0)
lowlink[v] = Math.min(lowlink[v], index[x]);
}
if(lowlink[v]==index[v]) {
LinkedList<Integer> scc = new LinkedList<Integer>(); int x;
do {
x = stack.pop(); instack[x]--; scc.add(x);
} while(x!=v);
sccs.add(scc);
}
}
}
}
| Java | ["5 4\n1 2\n2 4\n5 3\n1 4", "6 2\n1 4\n3 4", "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4"] | 2 seconds | ["1", "0", "2"] | null | Java 6 | standard input | [
"implementation",
"dfs and similar"
] | a0e55bfbdeb3dc550e1f86b9fa7cb06d | The first line contains two integers n and m (2ββ€βnββ€β100, 1ββ€βmββ€β100) β the number of students and the number of pairs of archenemies correspondingly. Next m lines describe enmity between students. Each enmity is described as two numbers ai and bi (1ββ€βai,βbiββ€βn, aiββ βbi) β the indexes of the students who are enemies to each other. Each enmity occurs in the list exactly once. It is guaranteed that each student has no more than two archenemies. You can consider the students indexed in some manner with distinct integers from 1 to n. | 1,700 | Print a single integer β the minimum number of students you will have to send to the bench in order to start the game. | standard output | |
PASSED | f4856570ccfe860704b70a1c01b689a5 | train_003.jsonl | 1344958200 | One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B, then student B is an archenemy to student A.The students want to split so as no two archenemies were in one team. If splitting in the required manner is impossible, some students will have to sit on the bench.Determine the minimum number of students you will have to send to the bench in order to form the two teams in the described manner and begin the game at last. | 256 megabytes | import java.util.List;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.math.BigInteger;
import java.util.Collections;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author Egor Kulikov (egor@egork.net)
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
TaskB solver = new TaskB();
solver.solve(1, in, out);
out.close();
}
}
class TaskB {
public void solve(int testNumber, InputReader in, OutputWriter out) {
int count = in.readInt();
int edgeCount = in.readInt();
int[] first = new int[edgeCount];
int[] second = new int[edgeCount];
IOUtils.readIntArrays(in, first, second);
MiscUtils.decreaseByOne(first, second);
IndependentSetSystem setSystem = new RecursiveIndependentSetSystem(count);
for (int i = 0; i < edgeCount; i++)
setSystem.join(first[i], second[i]);
int[] vertices = new int[count];
int[] edges = new int[count];
for (int i = 0; i < count; i++)
vertices[setSystem.get(i)]++;
for (int i : first)
edges[setSystem.get(i)]++;
int answer = 0;
int odd = 0;
for (int i = 0; i < count; i++) {
if (vertices[i] == edges[i])
answer += vertices[i] & 1;
else
odd += vertices[i] & 1;
}
answer += odd & 1;
out.printLine(answer);
}
}
class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int readInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object...objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
public void printLine(Object...objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
}
class IOUtils {
public static void readIntArrays(InputReader in, int[]... arrays) {
for (int i = 0; i < arrays[0].length; i++) {
for (int j = 0; j < arrays.length; j++)
arrays[j][i] = in.readInt();
}
}
}
class MiscUtils {
public static void decreaseByOne(int[]...arrays) {
for (int[] array : arrays) {
for (int i = 0; i < array.length; i++)
array[i]--;
}
}
}
interface IndependentSetSystem {
public boolean join(int first, int second);
public int get(int index);
public static interface Listener {
public void joined(int joinedRoot, int root);
}
}
class RecursiveIndependentSetSystem implements IndependentSetSystem {
private final int[] color;
private int setCount;
private Listener listener;
public RecursiveIndependentSetSystem(int size) {
color = new int[size];
for (int i = 0; i < size; i++)
color[i] = i;
setCount = size;
}
public RecursiveIndependentSetSystem(RecursiveIndependentSetSystem other) {
color = other.color.clone();
setCount = other.setCount;
}
public boolean join(int first, int second) {
first = get(first);
second = get(second);
if (first == second)
return false;
setCount--;
color[second] = first;
if (listener != null)
listener.joined(second, first);
return true;
}
public int get(int index) {
if (color[index] == index)
return index;
return color[index] = get(color[index]);
}
}
| Java | ["5 4\n1 2\n2 4\n5 3\n1 4", "6 2\n1 4\n3 4", "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4"] | 2 seconds | ["1", "0", "2"] | null | Java 6 | standard input | [
"implementation",
"dfs and similar"
] | a0e55bfbdeb3dc550e1f86b9fa7cb06d | The first line contains two integers n and m (2ββ€βnββ€β100, 1ββ€βmββ€β100) β the number of students and the number of pairs of archenemies correspondingly. Next m lines describe enmity between students. Each enmity is described as two numbers ai and bi (1ββ€βai,βbiββ€βn, aiββ βbi) β the indexes of the students who are enemies to each other. Each enmity occurs in the list exactly once. It is guaranteed that each student has no more than two archenemies. You can consider the students indexed in some manner with distinct integers from 1 to n. | 1,700 | Print a single integer β the minimum number of students you will have to send to the bench in order to start the game. | standard output | |
PASSED | ac2983089f314a7f97b4811200c5794d | train_003.jsonl | 1344958200 | One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B, then student B is an archenemy to student A.The students want to split so as no two archenemies were in one team. If splitting in the required manner is impossible, some students will have to sit on the bench.Determine the minimum number of students you will have to send to the bench in order to form the two teams in the described manner and begin the game at last. | 256 megabytes | import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;
public class Main {
private static ArrayList <ArrayList <Integer>> graph = new ArrayList <ArrayList <Integer>>();
private static HashSet <Integer> visited = new HashSet <Integer>();
private static boolean flag;
private static int n,m;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
for (int i = 0; i < n; ++i)
graph.add(new ArrayList <Integer> ());
for (int i = 0; i < m; ++i)
{
int tempi = sc.nextInt()-1;
int tempj = sc.nextInt()-1;
graph.get(tempi).add(tempj);
graph.get(tempj).add(tempi);
}
int minus = 0;
for (int i = 0; i < n; ++i)
{
flag = false;
dfs(i,1,-1);
if (flag)
minus++;
}
System.out.println( (((n-minus)%2) == 0) ? minus: (minus+1));
}
private static void dfs(int v, int d, int predok) {
visited.add(v);
for (int i = 0; i < graph.get(v).size(); ++i)
if (!visited.contains(graph.get(v).get(i)))
dfs(graph.get(v).get(i),d+1,v);
else
if (predok != graph.get(v).get(i))
if (d%2==1 && d!=1)
flag = true;
}
}
| Java | ["5 4\n1 2\n2 4\n5 3\n1 4", "6 2\n1 4\n3 4", "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4"] | 2 seconds | ["1", "0", "2"] | null | Java 6 | standard input | [
"implementation",
"dfs and similar"
] | a0e55bfbdeb3dc550e1f86b9fa7cb06d | The first line contains two integers n and m (2ββ€βnββ€β100, 1ββ€βmββ€β100) β the number of students and the number of pairs of archenemies correspondingly. Next m lines describe enmity between students. Each enmity is described as two numbers ai and bi (1ββ€βai,βbiββ€βn, aiββ βbi) β the indexes of the students who are enemies to each other. Each enmity occurs in the list exactly once. It is guaranteed that each student has no more than two archenemies. You can consider the students indexed in some manner with distinct integers from 1 to n. | 1,700 | Print a single integer β the minimum number of students you will have to send to the bench in order to start the game. | standard output | |
PASSED | 94e7b07b2ba1e92bc46a8dc637f59de4 | train_003.jsonl | 1344958200 | One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B, then student B is an archenemy to student A.The students want to split so as no two archenemies were in one team. If splitting in the required manner is impossible, some students will have to sit on the bench.Determine the minimum number of students you will have to send to the bench in order to form the two teams in the described manner and begin the game at last. | 256 megabytes | /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.util.Scanner;
/**
*
* @author JuanCarlos
*/
public class Main {
/**
* @param args the command line arguments
*/
static int ady [][]=new int[101][101];
static int g[]=new int[101];
static int cuenta;
static int usa[]=new int[101];
public static void dfs(int x)
{
int t;
cuenta++;
usa[x]=1;
for(t=0;t<g[x];t++)
if(usa[ady[x][t]]==0)
dfs(ady[x][t]);
}
public static void main(String[] args) {
int x,y,tot=0,n,m;
Scanner in=new Scanner(System.in);
n=in.nextInt();
m=in.nextInt();
for(int k=0;k<m;k++)
{
x=in.nextInt();
y=in.nextInt();
ady[x][g[x]]=y;
ady[y][g[y]]=x;
g[x]++;
g[y]++;
}
for(int k=1;k<=n;k++)
{
if(g[k]==1&&usa[k]==0)
{
cuenta=0;
dfs(k);
tot+=cuenta;
}
else
if(g[k]==0&&usa[k]==0)
{
usa[k]=1;
tot++;
}
}
for(int k=1;k<=n;k++)
if(usa[k]==0)
{
cuenta=0;
dfs(k);
cuenta-=cuenta%2;
tot+=cuenta;
}
tot=tot-(tot%2);
System.out.println(n-tot);
}
}
| Java | ["5 4\n1 2\n2 4\n5 3\n1 4", "6 2\n1 4\n3 4", "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4"] | 2 seconds | ["1", "0", "2"] | null | Java 6 | standard input | [
"implementation",
"dfs and similar"
] | a0e55bfbdeb3dc550e1f86b9fa7cb06d | The first line contains two integers n and m (2ββ€βnββ€β100, 1ββ€βmββ€β100) β the number of students and the number of pairs of archenemies correspondingly. Next m lines describe enmity between students. Each enmity is described as two numbers ai and bi (1ββ€βai,βbiββ€βn, aiββ βbi) β the indexes of the students who are enemies to each other. Each enmity occurs in the list exactly once. It is guaranteed that each student has no more than two archenemies. You can consider the students indexed in some manner with distinct integers from 1 to n. | 1,700 | Print a single integer β the minimum number of students you will have to send to the bench in order to start the game. | standard output | |
PASSED | a16d7cc7403b5f6e9ec69684ea15aecd | train_003.jsonl | 1344958200 | One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B, then student B is an archenemy to student A.The students want to split so as no two archenemies were in one team. If splitting in the required manner is impossible, some students will have to sit on the bench.Determine the minimum number of students you will have to send to the bench in order to form the two teams in the described manner and begin the game at last. | 256 megabytes | import java.util.*;
import java.io.*;
public class hercules {
static boolean used[];
static ArrayList<Integer>temp[];
static int colour[];
public static void dfs(int a,int val){
used[a]=true;
colour[a]=val;
for(int x:temp[a]){
if(!used[x])
dfs(x,val);
}
}
public static void main(String [] args)throws Exception{
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer(bf.readLine());
int n=Integer.parseInt(st.nextToken());
int m=Integer.parseInt(st.nextToken());
temp=new ArrayList[n+1];
for(int i=0;i<=n;i++)
temp[i]=new ArrayList();
for(int i=1;i<=m;i++){
st=new StringTokenizer(bf.readLine());
int x=Integer.parseInt(st.nextToken());
int y=Integer.parseInt(st.nextToken());
temp[x].add(y);temp[y].add(x);
}
used=new boolean [n+1];
colour=new int[n+1];
int val=0;
for(int i=1;i<=n;i++){
if(!used[i])
dfs(i,++val);
}
int size[]=new int[val+1];
boolean check[]=new boolean[val+1];
Arrays.fill(check,true);
//System.out.println(temp[4]);
for(int i=1;i<=n;i++){
if(temp[i].size()<2)check[colour[i]]=false;
size[colour[i]]++;
}
//for(int i=1;i<=val;i++)System.out.println(colour[i]+" "+size[i]+" "+check[i]);
int ans=0;
for(int i=1;i<=val;i++){
if(check[i] && size[i]%2==1)ans++;
}
if((n-ans)%2==1)ans++;
System.out.print(ans);
}
}
| Java | ["5 4\n1 2\n2 4\n5 3\n1 4", "6 2\n1 4\n3 4", "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4"] | 2 seconds | ["1", "0", "2"] | null | Java 6 | standard input | [
"implementation",
"dfs and similar"
] | a0e55bfbdeb3dc550e1f86b9fa7cb06d | The first line contains two integers n and m (2ββ€βnββ€β100, 1ββ€βmββ€β100) β the number of students and the number of pairs of archenemies correspondingly. Next m lines describe enmity between students. Each enmity is described as two numbers ai and bi (1ββ€βai,βbiββ€βn, aiββ βbi) β the indexes of the students who are enemies to each other. Each enmity occurs in the list exactly once. It is guaranteed that each student has no more than two archenemies. You can consider the students indexed in some manner with distinct integers from 1 to n. | 1,700 | Print a single integer β the minimum number of students you will have to send to the bench in order to start the game. | standard output | |
PASSED | abbbdfdd50e994341841b505c6633ca8 | train_003.jsonl | 1344958200 | One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B, then student B is an archenemy to student A.The students want to split so as no two archenemies were in one team. If splitting in the required manner is impossible, some students will have to sit on the bench.Determine the minimum number of students you will have to send to the bench in order to form the two teams in the described manner and begin the game at last. | 256 megabytes | import java.util.Scanner;
public class TeamBuilding {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// int n = 50, m = 48;
// int[] s = {33, 1, 43, 1, 42,31, 14, 34, 38, 46, 49, 8, 27, 26, 15, 27, 9, 18, 35, 32, 23, 36, 16, 39, 40, 11, 21, 10, 30, 20, 24, 43, 22, 41, 50, 25, 5, 34, 12, 8, 44, 25, 12, 39, 42, 45, 50, 13};
// int[] f = {21, 46, 37, 48, 32, 45, 29, 28, 19, 48, 31, 3, 23, 37, 9, 17, 35, 7, 15, 4, 17, 22, 33, 6, 13, 6, 16, 40, 36, 5, 3, 26, 30, 20, 38, 29, 41, 44, 7, 24, 28, 14, 18, 11, 4, 49, 19, 10};
int n = sc.nextInt();
int m = sc.nextInt();
int[] s = new int[n];
int[] f = new int[n];
int[] a = new int[n + 1];
boolean[] vis = new boolean[n + 1];
for(int i = 0; i < m; ++i) {
int st = s[i] = sc.nextInt();
int fin = f[i] = sc.nextInt();
a[st] ^= fin;
a[fin] ^= st;
}
int c = 0, z = 0, p = 0, sum = 0;
for(int j = 0; j < m; ++j) {
if((z = a[s[j]] ^ f[j]) != 0) a[s[j]] = z;
int count = 0;
int i = s[j];
if(vis[i]) continue;
for(; !vis[i]; i = a[i]) {
vis[i] = true;
if((z = a[a[i]] ^ i) != 0) a[a[i]] = z;
count++;
}
sum += count;
if(i != s[j] && count % 2 == 1) p++;
if(i == s[j] && count % 2 == 1) c++;
}
boolean noRelEven = (n - sum) % 2 == 0;
if(noRelEven && p % 2 == 1) {
c += 1;
} else if(!noRelEven && p % 2 == 0) {
c += 1;
}
System.out.println(c);
}
}
| Java | ["5 4\n1 2\n2 4\n5 3\n1 4", "6 2\n1 4\n3 4", "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4"] | 2 seconds | ["1", "0", "2"] | null | Java 6 | standard input | [
"implementation",
"dfs and similar"
] | a0e55bfbdeb3dc550e1f86b9fa7cb06d | The first line contains two integers n and m (2ββ€βnββ€β100, 1ββ€βmββ€β100) β the number of students and the number of pairs of archenemies correspondingly. Next m lines describe enmity between students. Each enmity is described as two numbers ai and bi (1ββ€βai,βbiββ€βn, aiββ βbi) β the indexes of the students who are enemies to each other. Each enmity occurs in the list exactly once. It is guaranteed that each student has no more than two archenemies. You can consider the students indexed in some manner with distinct integers from 1 to n. | 1,700 | Print a single integer β the minimum number of students you will have to send to the bench in order to start the game. | standard output | |
PASSED | 70046823158e16867dacf0ba8821bf80 | train_003.jsonl | 1344958200 | One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B, then student B is an archenemy to student A.The students want to split so as no two archenemies were in one team. If splitting in the required manner is impossible, some students will have to sit on the bench.Determine the minimum number of students you will have to send to the bench in order to form the two teams in the described manner and begin the game at last. | 256 megabytes | import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
public class B {
Scanner sc = new Scanner(System.in);
boolean [][] g;
boolean [] used;
int [] deg;
void doIt()
{
int n = sc.nextInt();
int m = sc.nextInt();
g = new boolean[n][n];
used = new boolean[n];
deg = new int[n];
for(int i = 0; i < m; i++) {
int a = sc.nextInt() - 1;
int b = sc.nextInt() - 1;
g[a][b] = g[b][a] = true;
deg[a]++;
deg[b]++;
}
int ans = 0, rem = 0;
// deg == 0
for(int i = 0; i < n; i++) {
if(deg[i] == 0) {
used[i] = true;
ans++;
}
}
//System.out.println(ans);
// deg == 1
for(int i = 0; i < n; i++) {
if(deg[i] == 1 && used[i] == false) {
int old = i;
used[i] = true; ans++;
while(true) {
int nxt = -1;
for(int j = 0; j < n; j++) {
if(g[old][j] && used[j] == false) {
nxt = j;
break;
}
}
used[nxt] = true; ans++;
if(deg[nxt] == 1) break;
old = nxt;
}
}
}
//System.out.println(ans);
//debug(deg);
for(int i = 0; i < n; i++) {
//System.out.print("" + i + ":"); debug(used);
if(deg[i] == 2 && used[i] == false) {
int tmp = 0;
int old = i;
used[i] = true; tmp++;
while(true) {
int nxt = -1;
for(int j = 0; j < n; j++) {
if(g[old][j] && used[j] == false) {
nxt = j;
break;
}
}
if(nxt == -1) {
break;
}
used[nxt] = true; tmp++;
old = nxt;
}
//System.out.println("T" + tmp);
rem += (tmp % 2);
}
}
rem += (ans % 2);
System.out.println(rem);
}
public static void main(String[] args) {
new B().doIt();
}
void debug(Object...os) {
System.err.println(deepToString(os));
}
}
| Java | ["5 4\n1 2\n2 4\n5 3\n1 4", "6 2\n1 4\n3 4", "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4"] | 2 seconds | ["1", "0", "2"] | null | Java 6 | standard input | [
"implementation",
"dfs and similar"
] | a0e55bfbdeb3dc550e1f86b9fa7cb06d | The first line contains two integers n and m (2ββ€βnββ€β100, 1ββ€βmββ€β100) β the number of students and the number of pairs of archenemies correspondingly. Next m lines describe enmity between students. Each enmity is described as two numbers ai and bi (1ββ€βai,βbiββ€βn, aiββ βbi) β the indexes of the students who are enemies to each other. Each enmity occurs in the list exactly once. It is guaranteed that each student has no more than two archenemies. You can consider the students indexed in some manner with distinct integers from 1 to n. | 1,700 | Print a single integer β the minimum number of students you will have to send to the bench in order to start the game. | standard output | |
PASSED | d6ec2d908d701f47997e87110a9c0da8 | train_003.jsonl | 1344958200 | One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B, then student B is an archenemy to student A.The students want to split so as no two archenemies were in one team. If splitting in the required manner is impossible, some students will have to sit on the bench.Determine the minimum number of students you will have to send to the bench in order to form the two teams in the described manner and begin the game at last. | 256 megabytes | import java.util.*;
import java.io.*;
public class a {
public static void main(String[] args) throws IOException
{
//Scanner input = new Scanner(new File("input.txt"));
//PrintWriter out = new PrintWriter(new File("output.txt"));
input.init(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = input.nextInt(), m = input.nextInt();
g = new ArrayList[n];
for(int i = 0; i<n; i++) g[i] = new ArrayList<Integer>();
int[] as = new int[m], bs = new int[m];
for(int i = 0; i<m; i++)
{
int a = input.nextInt()-1, b = input.nextInt()-1;
as[i] = a;
bs[i] = b;
g[a].add(b);
g[b].add(a);
}
scc();
int[] sizes = new int[count];
int[] edgeCounts = new int[count];
for(int i = 0; i<m; i++)
{
edgeCounts[id[as[i]]]++;
edgeCounts[id[bs[i]]]++;
}
for(int i = 0; i<n; i++) sizes[id[i]]++;
int res = 0;
for(int i = 0; i<count; i++) if(sizes[i]%2 == 1 && sizes[i]!= 1 && edgeCounts[i] == 2*sizes[i]) res++;
if((n-res)%2==1) res++;
out.println(res);
out.close();
}
static ArrayList<Integer>[] g;
static boolean[] marked;
static int[] id, low, stk;
static int pre, count;
static void scc()
{
id = new int[g.length]; low = new int[g.length]; stk = new int[g.length+1];
pre = count = 0;
marked = new boolean[g.length];
for(int i =0; i<g.length; i++)
if(!marked[i]) dfs(i);
}
static void dfs(int i)
{
marked[stk[++stk[0]]=i] = true;
int min = low[i] = pre++;
for(int j: g[i])
{
if(!marked[j]) dfs(j);
if(low[j] < min) min = low[j];
}
if(min < low[i]) low[i] = min;
else
{
while(stk[stk[0]] != i)
{
int j =stk[stk[0]--];
id[j] = count;
low[j] = g.length;
}
id[stk[stk[0]--]] = count++;
low[i] = g.length;
}
}
static class input {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(
new InputStreamReader(input) );
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while ( ! tokenizer.hasMoreTokens() ) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(
reader.readLine() );
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt( next() );
}
static double nextDouble() throws IOException {
return Double.parseDouble( next() );
}
static long nextLong() throws IOException {
return Long.parseLong( next() );
}
static String nextLine() throws IOException {
return reader.readLine();
}
}
} | Java | ["5 4\n1 2\n2 4\n5 3\n1 4", "6 2\n1 4\n3 4", "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4"] | 2 seconds | ["1", "0", "2"] | null | Java 6 | standard input | [
"implementation",
"dfs and similar"
] | a0e55bfbdeb3dc550e1f86b9fa7cb06d | The first line contains two integers n and m (2ββ€βnββ€β100, 1ββ€βmββ€β100) β the number of students and the number of pairs of archenemies correspondingly. Next m lines describe enmity between students. Each enmity is described as two numbers ai and bi (1ββ€βai,βbiββ€βn, aiββ βbi) β the indexes of the students who are enemies to each other. Each enmity occurs in the list exactly once. It is guaranteed that each student has no more than two archenemies. You can consider the students indexed in some manner with distinct integers from 1 to n. | 1,700 | Print a single integer β the minimum number of students you will have to send to the bench in order to start the game. | standard output | |
PASSED | 2c51133c11be087389f6ba5dbd134e35 | train_003.jsonl | 1344958200 | One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B, then student B is an archenemy to student A.The students want to split so as no two archenemies were in one team. If splitting in the required manner is impossible, some students will have to sit on the bench.Determine the minimum number of students you will have to send to the bench in order to form the two teams in the described manner and begin the game at last. | 256 megabytes | import java.util.Scanner;
public class BB {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int b[] = new int [n+2];
int c[] = new int [n+2];
boolean a[][] = new boolean [n+1][n+1];
for (int i = 1; i <= m; i++) {
int x = sc.nextInt();
int y = sc.nextInt();
a[x][y] = true;
a[y][x] = true;
b[i] = y;
c[i] = x;
}
// System.out.println("hb");
int ans = 0;
for (int i = 1; i <= m; i++) {
// System.out.println(b[i]);
if (b[i] != 0){
int x = b[i];
int y = c[i];
int count = 1;
a[y][x] = false;
a[x][y] = false;
int q = 0;
while (x != y && q != n) {
q++;
for (int j = 1; j <= n; j++) {
for (int j2 = j+1; j2 <= n; j2++) {
if (a[j][j2] == true && (x == j || x == j2)){
a[j][j2] = false;
x = (x==j)? j2:j;
// System.out.println(j+" "+j2);
count++;
}
}
}
}
// System.out.println(count);
if (count%2 == 1 && count > 2 && x==y){
ans++;
}
}
}
if ((n-ans)%2 == 1){
ans++;
}
System.out.println(ans);
}
}
| Java | ["5 4\n1 2\n2 4\n5 3\n1 4", "6 2\n1 4\n3 4", "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4"] | 2 seconds | ["1", "0", "2"] | null | Java 6 | standard input | [
"implementation",
"dfs and similar"
] | a0e55bfbdeb3dc550e1f86b9fa7cb06d | The first line contains two integers n and m (2ββ€βnββ€β100, 1ββ€βmββ€β100) β the number of students and the number of pairs of archenemies correspondingly. Next m lines describe enmity between students. Each enmity is described as two numbers ai and bi (1ββ€βai,βbiββ€βn, aiββ βbi) β the indexes of the students who are enemies to each other. Each enmity occurs in the list exactly once. It is guaranteed that each student has no more than two archenemies. You can consider the students indexed in some manner with distinct integers from 1 to n. | 1,700 | Print a single integer β the minimum number of students you will have to send to the bench in order to start the game. | standard output | |
PASSED | 5c0013a8841bb6fd5dc0a3698ccf82ac | train_003.jsonl | 1344958200 | One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B, then student B is an archenemy to student A.The students want to split so as no two archenemies were in one team. If splitting in the required manner is impossible, some students will have to sit on the bench.Determine the minimum number of students you will have to send to the bench in order to form the two teams in the described manner and begin the game at last. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class B {
public static void main(String[] args) throws IOException {
BufferedReader buf = new BufferedReader(
new InputStreamReader(System.in));
String[] in = buf.readLine().split(" ");
int n = Integer.parseInt(in[0]);
int m = Integer.parseInt(in[1]);
boolean[] v = new boolean[n];
boolean[][] matrix = new boolean[n][n];
for (int i = 0; i < m; i++) {
in = buf.readLine().split(" ");
int x = Integer.parseInt(in[0]) - 1;
int y = Integer.parseInt(in[1]) - 1;
matrix[x][y] = true;
matrix[y][x] = true;
v[x] = true;
v[y] = true;
}
boolean[] v2 = new boolean[n];
int count = 0;
for (int i = 0; i < n; i++)
if (v[i] && !v2[i]) {
int x = dfs(matrix, i, 0, v2, -1);
if (x % 2 != 0)
count++;
}
if ((n - count) % 2 != 0)
count++;
System.out.println(count);
}
private static int dfs(boolean[][] matrix, int i, int len, boolean[] v2,
int prev) {
if (v2[i])
return len;
else {
v2[i] = true;
for (int j = 0; j < matrix.length; j++)
if (matrix[i][j] && j != prev) {
int x = dfs(matrix, j, len + 1, v2, i);
if (x != 0)
return x;
}
}
return 0;
}
}
| Java | ["5 4\n1 2\n2 4\n5 3\n1 4", "6 2\n1 4\n3 4", "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4"] | 2 seconds | ["1", "0", "2"] | null | Java 6 | standard input | [
"implementation",
"dfs and similar"
] | a0e55bfbdeb3dc550e1f86b9fa7cb06d | The first line contains two integers n and m (2ββ€βnββ€β100, 1ββ€βmββ€β100) β the number of students and the number of pairs of archenemies correspondingly. Next m lines describe enmity between students. Each enmity is described as two numbers ai and bi (1ββ€βai,βbiββ€βn, aiββ βbi) β the indexes of the students who are enemies to each other. Each enmity occurs in the list exactly once. It is guaranteed that each student has no more than two archenemies. You can consider the students indexed in some manner with distinct integers from 1 to n. | 1,700 | Print a single integer β the minimum number of students you will have to send to the bench in order to start the game. | standard output | |
PASSED | 97bb2ed611333c468bc888f065d664ae | train_003.jsonl | 1344958200 | One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B, then student B is an archenemy to student A.The students want to split so as no two archenemies were in one team. If splitting in the required manner is impossible, some students will have to sit on the bench.Determine the minimum number of students you will have to send to the bench in order to form the two teams in the described manner and begin the game at last. | 256 megabytes | import java.util.Scanner;
public class Prob216B {
public static void main(String[] Args) {
Scanner in = new Scanner(System.in);
int students = in.nextInt();
int pairs = in.nextInt();
int[][] arch = new int[students][3];
for (int i = 0; i < students; i++)
arch[i] = new int[] { 0, -1, -1 };
for (int i = 0; i < pairs; i++) {
int a = in.nextInt() - 1;
int b = in.nextInt() - 1;
arch[a][++arch[a][0]] = b;
arch[b][++arch[b][0]] = a;
}
int answer = 0;
boolean[] visited = new boolean[students];
for (int i = 0; i < students; i++)
if (!visited[i] && arch[i][0] == 2) {
int ar1 = arch[i][1];
int ar2 = arch[i][2];
// odd ring
int nodesInARing = 2;
boolean ok = true;
int prev = i;
while (true) {
nodesInARing++;
if (arch[ar1][0] != 2) {
ok = false;
break;
}
if (arch[ar1][1] + arch[ar1][2] - prev != ar2) {
int temp = ar1;
ar1 = arch[ar1][1] + arch[ar1][2] - prev;
prev = temp;
} else {
break;
}
}
if (ok && nodesInARing % 2 == 1) {
answer++;
ar1 = arch[i][1];
prev = i;
while (!visited[ar1]) {
visited[ar1] = true;
int temp = ar1;
ar1 = arch[ar1][1] + arch[ar1][2] - prev;
prev = temp;
}
}
visited[i] = true;
}
if ((students - answer) % 2 == 0)
System.out.println(answer);
else
System.out.println(answer + 1);
}
} | Java | ["5 4\n1 2\n2 4\n5 3\n1 4", "6 2\n1 4\n3 4", "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4"] | 2 seconds | ["1", "0", "2"] | null | Java 6 | standard input | [
"implementation",
"dfs and similar"
] | a0e55bfbdeb3dc550e1f86b9fa7cb06d | The first line contains two integers n and m (2ββ€βnββ€β100, 1ββ€βmββ€β100) β the number of students and the number of pairs of archenemies correspondingly. Next m lines describe enmity between students. Each enmity is described as two numbers ai and bi (1ββ€βai,βbiββ€βn, aiββ βbi) β the indexes of the students who are enemies to each other. Each enmity occurs in the list exactly once. It is guaranteed that each student has no more than two archenemies. You can consider the students indexed in some manner with distinct integers from 1 to n. | 1,700 | Print a single integer β the minimum number of students you will have to send to the bench in order to start the game. | standard output | |
PASSED | 522145e6cbb25c4150df6f685526f34c | train_003.jsonl | 1344958200 | One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B, then student B is an archenemy to student A.The students want to split so as no two archenemies were in one team. If splitting in the required manner is impossible, some students will have to sit on the bench.Determine the minimum number of students you will have to send to the bench in order to form the two teams in the described manner and begin the game at last. | 256 megabytes |
import java.util.Scanner;
public class Main {
static int[][] enemy;
static int[] enemies;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
enemy = new int[n][2];
enemies = new int[n];
int m = sc.nextInt();
for(int i = 0; i<n; i++)
for(int j = 0; j<2; j++)
enemy[i][j] = -1;
for(int i = 0; i<m; i++){
int a = sc.nextInt()-1;
int b = sc.nextInt()-1;
enemy[a][enemies[a]++] = b;
enemy[b][enemies[b]++] = a;
}
int none = 0;
int oddPaths = 0;
int oddCycles = 0;
for(int i = 0; i<n; i++){
if(enemies[i] == 0){
none++;
enemies[i] = -1;
} else if(enemies[i] == 1){
int length = 1;
int prev = i;
enemies[i] = -1;
int at = enemy[i][0];
while(enemies[at] == 2){
enemies[at] = -1;
length++;
int pprev = prev;
prev = at;
if(enemy[at][0] == pprev){
at = enemy[at][1];
} else {
at = enemy[at][0];
}
}
length++;
enemies[at] = -1;
if(length%2 == 0){
continue;
} else {
oddPaths++;
}
}
}
for(int i = 0; i<n; i++){
if(enemies[i] == 2){
enemies[i] = -1;
int prev = i;
int at = enemy[i][0];
int length = 1;
while(at != i){
enemies[at] = -1;
length++;
int pprev = prev;
prev = at;
if(enemy[at][0] == pprev){
at = enemy[at][1];
} else {
at = enemy[at][0];
}
}
if(length%2 == 0){
continue;
} else {
oddCycles++;
}
}
}
System.out.println(oddCycles + (none+oddPaths)%2);
}
}
| Java | ["5 4\n1 2\n2 4\n5 3\n1 4", "6 2\n1 4\n3 4", "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4"] | 2 seconds | ["1", "0", "2"] | null | Java 6 | standard input | [
"implementation",
"dfs and similar"
] | a0e55bfbdeb3dc550e1f86b9fa7cb06d | The first line contains two integers n and m (2ββ€βnββ€β100, 1ββ€βmββ€β100) β the number of students and the number of pairs of archenemies correspondingly. Next m lines describe enmity between students. Each enmity is described as two numbers ai and bi (1ββ€βai,βbiββ€βn, aiββ βbi) β the indexes of the students who are enemies to each other. Each enmity occurs in the list exactly once. It is guaranteed that each student has no more than two archenemies. You can consider the students indexed in some manner with distinct integers from 1 to n. | 1,700 | Print a single integer β the minimum number of students you will have to send to the bench in order to start the game. | standard output | |
PASSED | 17b64a84c640069eeb874509833152d0 | train_003.jsonl | 1344958200 | One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B, then student B is an archenemy to student A.The students want to split so as no two archenemies were in one team. If splitting in the required manner is impossible, some students will have to sit on the bench.Determine the minimum number of students you will have to send to the bench in order to form the two teams in the described manner and begin the game at last. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
public class B216 {
static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
static PrintWriter out = new PrintWriter(System.out);
static int nextInt() throws Exception {
in.nextToken();
return (int)in.nval;
}
static String nextString() throws Exception {
in.nextToken();
return in.sval;
}
public static void main(String[] args) throws Exception {
int n = nextInt(), m = nextInt();
boolean[][] g = new boolean[n][n];
for (int i = 0; i < m; i++) {
int a = nextInt()-1, b = nextInt()-1;
g[a][b] = g[b][a] = true;
}
int[] clr = new int[n];
int ans = 0;
for (int i = 0; i < n; i++)
if (clr[i] == 0 && !color(i, g, clr, 1)) {
ans++;
}
if ((n-ans)%2 == 1) ans++;
out.println(ans);
out.flush();
}
static boolean color(int x, boolean[][] g, int[] clr, int c) {
if (clr[x] != 0) return clr[x] == c;
clr[x] = c;
boolean res = true;
for (int i = 0; i < g[x].length; i++) if (g[x][i]) {
res &= color(i, g, clr, -c);
}
return res;
}
}
| Java | ["5 4\n1 2\n2 4\n5 3\n1 4", "6 2\n1 4\n3 4", "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4"] | 2 seconds | ["1", "0", "2"] | null | Java 6 | standard input | [
"implementation",
"dfs and similar"
] | a0e55bfbdeb3dc550e1f86b9fa7cb06d | The first line contains two integers n and m (2ββ€βnββ€β100, 1ββ€βmββ€β100) β the number of students and the number of pairs of archenemies correspondingly. Next m lines describe enmity between students. Each enmity is described as two numbers ai and bi (1ββ€βai,βbiββ€βn, aiββ βbi) β the indexes of the students who are enemies to each other. Each enmity occurs in the list exactly once. It is guaranteed that each student has no more than two archenemies. You can consider the students indexed in some manner with distinct integers from 1 to n. | 1,700 | Print a single integer β the minimum number of students you will have to send to the bench in order to start the game. | standard output | |
PASSED | e70be21dbeb6ca104e3c67cc853f3afe | train_003.jsonl | 1330536600 | One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides, any two neighboring parts were painted different colors, that is, the red and the blue color were alternating, i. e. followed one after the other. The outer area of the wall (the area that lied outside all circles) was painted blue. Help Sherlock Holmes determine the total area of red parts of the wall.Let us remind you that two circles are called concentric if their centers coincide. Several circles are called concentric if any two of them are concentric. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int n = cin.nextInt( );
double temp, pi = 3.141592653589793;
double[] array = new double[n];
for( int i=0; i<n; i++ )
array[i] = Double.parseDouble( cin.next( ) );
for( int i=0; i<n; i++ )
for( int j=0; j<i; j++ )
if( array[i] > array[j] ){
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
temp = 0.0;
for( int i=0; i<n; i++ ){
if( i%2 == 0 )
temp = temp+(array[i]*array[i]);
else
temp = temp-(array[i]*array[i]);
}
temp *= pi;
System.out.println( temp );
}
} | Java | ["1\n1", "3\n1 4 2"] | 2 seconds | ["3.1415926536", "40.8407044967"] | NoteIn the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals ΟβΓβ12β=βΟ.In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the second and the third circles is painted red. Part between the first and the third is painted blue. And, finally, the inner part of the first circle is painted red. Overall there are two red parts: the ring between the second and the third circles and the inner part of the first circle. Total area of the red parts is equal (ΟβΓβ42β-βΟβΓβ22)β+βΟβΓβ12β=βΟβΓβ12β+βΟβ=β13Ο | Java 7 | standard input | [
"sortings",
"geometry"
] | 48b9c68380d3bd64bbc69d921a098641 | The first line contains the single integer n (1ββ€βnββ€β100). The second line contains n space-separated integers ri (1ββ€βriββ€β1000) β the circles' radii. It is guaranteed that all circles are different. | 1,000 | Print the single real number β total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10β-β4. | standard output | |
PASSED | 8e5a2f4ac88116c62cd0efdd778ba1c6 | train_003.jsonl | 1330536600 | One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides, any two neighboring parts were painted different colors, that is, the red and the blue color were alternating, i. e. followed one after the other. The outer area of the wall (the area that lied outside all circles) was painted blue. Help Sherlock Holmes determine the total area of red parts of the wall.Let us remind you that two circles are called concentric if their centers coincide. Several circles are called concentric if any two of them are concentric. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int n = cin.nextInt( );
double temp, pi = 3.141592653589793;
double[] array = new double[n];
for( int i=0; i<n; i++ )
array[i] = Double.parseDouble( cin.next( ) );
for( int i=0; i<n; i++ )
for( int j=0; j<i; j++ )
if( array[i] > array[j] ){
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
temp = 0.0;
for( int i=0; i<n; i++ ){
if( i%2 == 0 )
temp = temp+(array[i]*array[i]);
else
temp = temp-(array[i]*array[i]);
}
temp *= pi;
System.out.println( temp );
}
} | Java | ["1\n1", "3\n1 4 2"] | 2 seconds | ["3.1415926536", "40.8407044967"] | NoteIn the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals ΟβΓβ12β=βΟ.In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the second and the third circles is painted red. Part between the first and the third is painted blue. And, finally, the inner part of the first circle is painted red. Overall there are two red parts: the ring between the second and the third circles and the inner part of the first circle. Total area of the red parts is equal (ΟβΓβ42β-βΟβΓβ22)β+βΟβΓβ12β=βΟβΓβ12β+βΟβ=β13Ο | Java 7 | standard input | [
"sortings",
"geometry"
] | 48b9c68380d3bd64bbc69d921a098641 | The first line contains the single integer n (1ββ€βnββ€β100). The second line contains n space-separated integers ri (1ββ€βriββ€β1000) β the circles' radii. It is guaranteed that all circles are different. | 1,000 | Print the single real number β total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10β-β4. | standard output | |
PASSED | 64b4df4d39b1a57c2ad31fbe1c4751a8 | train_003.jsonl | 1330536600 | One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides, any two neighboring parts were painted different colors, that is, the red and the blue color were alternating, i. e. followed one after the other. The outer area of the wall (the area that lied outside all circles) was painted blue. Help Sherlock Holmes determine the total area of red parts of the wall.Let us remind you that two circles are called concentric if their centers coincide. Several circles are called concentric if any two of them are concentric. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
public class ProblemB {
public static void main(String[] args) {
InputReader in = new InputReader();
PrintWriter out = new PrintWriter(System.out);
new ProblemB().solve(in, out);
out.close();
}
public void solve(InputReader in, PrintWriter out) {
int n = in.nextInt();
int[] r = new int[n];
for (int i = 0; i < n; i++) {
r[i] = in.nextInt();
}
Arrays.sort(r);
double res = 0.0;
for (int i = n - 1; i >= 1; i -= 2) {
res += Math.PI * r[i] * r[i] - Math.PI * r[i - 1] * r[i - 1];
}
if (n % 2 == 1) {
res += Math.PI * r[0] * r[0];
}
out.println(res);
}
static class InputReader {
public BufferedReader br;
public StringTokenizer st;
public InputReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return st.nextToken();
}
public 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 | ["1\n1", "3\n1 4 2"] | 2 seconds | ["3.1415926536", "40.8407044967"] | NoteIn the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals ΟβΓβ12β=βΟ.In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the second and the third circles is painted red. Part between the first and the third is painted blue. And, finally, the inner part of the first circle is painted red. Overall there are two red parts: the ring between the second and the third circles and the inner part of the first circle. Total area of the red parts is equal (ΟβΓβ42β-βΟβΓβ22)β+βΟβΓβ12β=βΟβΓβ12β+βΟβ=β13Ο | Java 7 | standard input | [
"sortings",
"geometry"
] | 48b9c68380d3bd64bbc69d921a098641 | The first line contains the single integer n (1ββ€βnββ€β100). The second line contains n space-separated integers ri (1ββ€βriββ€β1000) β the circles' radii. It is guaranteed that all circles are different. | 1,000 | Print the single real number β total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10β-β4. | standard output | |
PASSED | e2d4fb631d2180a8559af88e6881effe | train_003.jsonl | 1330536600 | One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides, any two neighboring parts were painted different colors, that is, the red and the blue color were alternating, i. e. followed one after the other. The outer area of the wall (the area that lied outside all circles) was painted blue. Help Sherlock Holmes determine the total area of red parts of the wall.Let us remind you that two circles are called concentric if their centers coincide. Several circles are called concentric if any two of them are concentric. | 256 megabytes | import java.util.*;
public class Trace {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] rs = new int[n];
for (int i = 0; i < n; i++)
rs[i] = sc.nextInt();
sc.close();
Arrays.sort(rs);
double res = 0, pi = Math.PI;
int sign = 1;
for (int i = n - 1; i >= 0; i--) {
res += (pi * rs[i] * rs[i]) * sign;
sign *= -1;
}
System.out.println(res);
}
}
| Java | ["1\n1", "3\n1 4 2"] | 2 seconds | ["3.1415926536", "40.8407044967"] | NoteIn the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals ΟβΓβ12β=βΟ.In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the second and the third circles is painted red. Part between the first and the third is painted blue. And, finally, the inner part of the first circle is painted red. Overall there are two red parts: the ring between the second and the third circles and the inner part of the first circle. Total area of the red parts is equal (ΟβΓβ42β-βΟβΓβ22)β+βΟβΓβ12β=βΟβΓβ12β+βΟβ=β13Ο | Java 7 | standard input | [
"sortings",
"geometry"
] | 48b9c68380d3bd64bbc69d921a098641 | The first line contains the single integer n (1ββ€βnββ€β100). The second line contains n space-separated integers ri (1ββ€βriββ€β1000) β the circles' radii. It is guaranteed that all circles are different. | 1,000 | Print the single real number β total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10β-β4. | standard output | |
PASSED | f8d398280039ccafe81916a875f7d823 | train_003.jsonl | 1330536600 | One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides, any two neighboring parts were painted different colors, that is, the red and the blue color were alternating, i. e. followed one after the other. The outer area of the wall (the area that lied outside all circles) was painted blue. Help Sherlock Holmes determine the total area of red parts of the wall.Let us remind you that two circles are called concentric if their centers coincide. Several circles are called concentric if any two of them are concentric. | 256 megabytes | import java.io.*;
import java.util.*;
public class Intueor {
public static void main(String[] args) throws Exception {
new Main().run();
}
}
class Cmp implements Comparator<Integer> {
public int compare(Integer x, Integer y) {
if(x > y)
return -1;
return 1;
}
}
class Main {
BufferedReader reader;
Integer[] r;
StringTokenizer st;
void run() throws Exception {
reader = new BufferedReader(new InputStreamReader(System.in));
Integer n = Integer.parseInt(reader.readLine());
r = new Integer[n];
st = new StringTokenizer(reader.readLine());
for (Integer i = 0; i < n; i++)
r[i] = Integer.parseInt(st.nextToken());
Arrays.sort(r, new Cmp());
double res = 0.0;
for (Integer i = 0; i < n; i++)
if (i % 2 == 0)
res += Math.PI * r[i] * r[i];
else
res -= Math.PI * r[i] * r[i];
System.out.printf("%.10f", res);
}
} | Java | ["1\n1", "3\n1 4 2"] | 2 seconds | ["3.1415926536", "40.8407044967"] | NoteIn the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals ΟβΓβ12β=βΟ.In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the second and the third circles is painted red. Part between the first and the third is painted blue. And, finally, the inner part of the first circle is painted red. Overall there are two red parts: the ring between the second and the third circles and the inner part of the first circle. Total area of the red parts is equal (ΟβΓβ42β-βΟβΓβ22)β+βΟβΓβ12β=βΟβΓβ12β+βΟβ=β13Ο | Java 7 | standard input | [
"sortings",
"geometry"
] | 48b9c68380d3bd64bbc69d921a098641 | The first line contains the single integer n (1ββ€βnββ€β100). The second line contains n space-separated integers ri (1ββ€βriββ€β1000) β the circles' radii. It is guaranteed that all circles are different. | 1,000 | Print the single real number β total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10β-β4. | standard output | |
PASSED | e56181240f67a937721c8439402f34ab | train_003.jsonl | 1330536600 | One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides, any two neighboring parts were painted different colors, that is, the red and the blue color were alternating, i. e. followed one after the other. The outer area of the wall (the area that lied outside all circles) was painted blue. Help Sherlock Holmes determine the total area of red parts of the wall.Let us remind you that two circles are called concentric if their centers coincide. Several circles are called concentric if any two of them are concentric. | 256 megabytes | import java.io.*;
import java.util.*;
import java.util.Map.Entry;
public class Main {
static BufferedReader br;
static PrintWriter out;
static StringTokenizer st;
static void solve() throws Exception {
int n = nextInt();
Integer[] r = new Integer[n + 1];
for(int i = 0; i < n; i++){
r[i] = nextInt();
}
r[n] = 0;
Arrays.sort(r, Collections.reverseOrder());
double ans = 0.0;
for(int i = 1; i <= n; i++){
if(i % 2 != 0){
ans += (Math.PI * r[i - 1] * r[i - 1] - Math.PI * r[i] * r[i]);
}
}
out.println(ans);
}
static int nextInt() throws IOException {
return Integer.parseInt(next());
}
static long nextLong() throws IOException {
return Long.parseLong(next());
}
static double nextDouble() throws IOException {
return Double.parseDouble(next());
}
static String next() throws IOException {
while (st == null || !st.hasMoreTokens()) {
String line = br.readLine();
if (line == null) {
return null;
}
st = new StringTokenizer(line);
}
return st.nextToken();
}
public static void main(String[] args) {
try {
File file = new File("fn.in");
InputStream input = System.in;
OutputStream output = System.out;
if(file.canRead()){
input = new FileInputStream(file);
output = new FileOutputStream("fn.out");
}
br = new BufferedReader(new InputStreamReader(input));
out = new PrintWriter(new PrintStream(output));
solve();
out.close();
br.close();
} catch (Throwable t) {
t.printStackTrace();
}
}
} | Java | ["1\n1", "3\n1 4 2"] | 2 seconds | ["3.1415926536", "40.8407044967"] | NoteIn the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals ΟβΓβ12β=βΟ.In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the second and the third circles is painted red. Part between the first and the third is painted blue. And, finally, the inner part of the first circle is painted red. Overall there are two red parts: the ring between the second and the third circles and the inner part of the first circle. Total area of the red parts is equal (ΟβΓβ42β-βΟβΓβ22)β+βΟβΓβ12β=βΟβΓβ12β+βΟβ=β13Ο | Java 7 | standard input | [
"sortings",
"geometry"
] | 48b9c68380d3bd64bbc69d921a098641 | The first line contains the single integer n (1ββ€βnββ€β100). The second line contains n space-separated integers ri (1ββ€βriββ€β1000) β the circles' radii. It is guaranteed that all circles are different. | 1,000 | Print the single real number β total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10β-β4. | standard output | |
PASSED | 711fc8d2d86814622d0938e5ad66b03b | train_003.jsonl | 1330536600 | One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides, any two neighboring parts were painted different colors, that is, the red and the blue color were alternating, i. e. followed one after the other. The outer area of the wall (the area that lied outside all circles) was painted blue. Help Sherlock Holmes determine the total area of red parts of the wall.Let us remind you that two circles are called concentric if their centers coincide. Several circles are called concentric if any two of them are concentric. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Trace {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int x= Integer.parseInt(br.readLine());
StringTokenizer st = new StringTokenizer(br.readLine());
int a[]=new int[x+1];
for(int i=1;i<x+1;i++){
a[i]=Integer.parseInt(st.nextToken());
}
double total = 0;
Arrays.sort(a);
for(int i =a.length-1;i>0;i-=2){
total+= Math.PI*a[i]*a[i];
total-=Math.PI*a[i-1]*a[i-1];
}
System.out.println(total);
}
}
| Java | ["1\n1", "3\n1 4 2"] | 2 seconds | ["3.1415926536", "40.8407044967"] | NoteIn the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals ΟβΓβ12β=βΟ.In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the second and the third circles is painted red. Part between the first and the third is painted blue. And, finally, the inner part of the first circle is painted red. Overall there are two red parts: the ring between the second and the third circles and the inner part of the first circle. Total area of the red parts is equal (ΟβΓβ42β-βΟβΓβ22)β+βΟβΓβ12β=βΟβΓβ12β+βΟβ=β13Ο | Java 7 | standard input | [
"sortings",
"geometry"
] | 48b9c68380d3bd64bbc69d921a098641 | The first line contains the single integer n (1ββ€βnββ€β100). The second line contains n space-separated integers ri (1ββ€βriββ€β1000) β the circles' radii. It is guaranteed that all circles are different. | 1,000 | Print the single real number β total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10β-β4. | standard output | |
PASSED | 1bde1bfbc0aab235cac309bf369c41bf | train_003.jsonl | 1330536600 | One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides, any two neighboring parts were painted different colors, that is, the red and the blue color were alternating, i. e. followed one after the other. The outer area of the wall (the area that lied outside all circles) was painted blue. Help Sherlock Holmes determine the total area of red parts of the wall.Let us remind you that two circles are called concentric if their centers coincide. Several circles are called concentric if any two of them are concentric. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class practice {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
double pi = Math.PI;
int [] c = new int[n];
for(int i = 0; i<n; i++) c[i] = sc.nextInt();
Arrays.sort(c);
double redArea = 0;
for(int i = n-1; i>=0; i-=2) {
if(i!=0)
redArea += pi * Math.pow(c[i], 2) - (pi * Math.pow(c[i-1],2));
else
redArea += pi * Math.pow(c[i],2);
}
System.out.println(redArea);
}
} | Java | ["1\n1", "3\n1 4 2"] | 2 seconds | ["3.1415926536", "40.8407044967"] | NoteIn the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals ΟβΓβ12β=βΟ.In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the second and the third circles is painted red. Part between the first and the third is painted blue. And, finally, the inner part of the first circle is painted red. Overall there are two red parts: the ring between the second and the third circles and the inner part of the first circle. Total area of the red parts is equal (ΟβΓβ42β-βΟβΓβ22)β+βΟβΓβ12β=βΟβΓβ12β+βΟβ=β13Ο | Java 7 | standard input | [
"sortings",
"geometry"
] | 48b9c68380d3bd64bbc69d921a098641 | The first line contains the single integer n (1ββ€βnββ€β100). The second line contains n space-separated integers ri (1ββ€βriββ€β1000) β the circles' radii. It is guaranteed that all circles are different. | 1,000 | Print the single real number β total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10β-β4. | standard output | |
PASSED | bf50ad48547718d1421494f96ebb64f2 | train_003.jsonl | 1330536600 | One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides, any two neighboring parts were painted different colors, that is, the red and the blue color were alternating, i. e. followed one after the other. The outer area of the wall (the area that lied outside all circles) was painted blue. Help Sherlock Holmes determine the total area of red parts of the wall.Let us remind you that two circles are called concentric if their centers coincide. Several circles are called concentric if any two of them are concentric. | 256 megabytes | import java.io.*;
import java.util.*;
public class Trace {
public static void main(String[]args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int [] radii = new int[n];
StringTokenizer st = new StringTokenizer(br.readLine());
for (int i = 0; i < n; i++) {
radii[i] = Integer.parseInt(st.nextToken());
}
Arrays.sort(radii);
int x = 0;
int i = n-1;
double red = 0;
while (i >= 0) {
if (x % 2 == 0) {
red += Math.PI*radii[i]*radii[i];
} else {
red -= Math.PI*radii[i]*radii[i];
}
x++;
i--;
}
System.out.println(red);
}
}
| Java | ["1\n1", "3\n1 4 2"] | 2 seconds | ["3.1415926536", "40.8407044967"] | NoteIn the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals ΟβΓβ12β=βΟ.In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the second and the third circles is painted red. Part between the first and the third is painted blue. And, finally, the inner part of the first circle is painted red. Overall there are two red parts: the ring between the second and the third circles and the inner part of the first circle. Total area of the red parts is equal (ΟβΓβ42β-βΟβΓβ22)β+βΟβΓβ12β=βΟβΓβ12β+βΟβ=β13Ο | Java 7 | standard input | [
"sortings",
"geometry"
] | 48b9c68380d3bd64bbc69d921a098641 | The first line contains the single integer n (1ββ€βnββ€β100). The second line contains n space-separated integers ri (1ββ€βriββ€β1000) β the circles' radii. It is guaranteed that all circles are different. | 1,000 | Print the single real number β total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10β-β4. | standard output | |
PASSED | 9ef29b87335c6256e8f7eb7c4e305e2f | train_003.jsonl | 1330536600 | One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides, any two neighboring parts were painted different colors, that is, the red and the blue color were alternating, i. e. followed one after the other. The outer area of the wall (the area that lied outside all circles) was painted blue. Help Sherlock Holmes determine the total area of red parts of the wall.Let us remind you that two circles are called concentric if their centers coincide. Several circles are called concentric if any two of them are concentric. | 256 megabytes | /*
/**
*
* @author Hendry
*/
import java.util.*;
public class Main {
static Scanner scan;
public static void main(String[] args) {
scan = new Scanner(System.in);
int n = scan.nextInt();
double sum = 0.0;
int []circles = new int[n];
for(int i = 0; i < n; i++)
{
circles[i] = scan.nextInt();
}
Arrays.sort(circles);
if(n % 2 == 0 || n == 1)
{
for(int i = 0; i < n; i++)
{
if(i % 2 == 0)
{
sum += circles[i] * circles[i];
}
else sum -= circles[i] * circles[i];
}
}
else
{
for(int i = 0; i < n; i++)
{
if(i % 2 == 0)
{
sum -= circles[i] * circles[i];
}
else sum += circles[i] * circles[i];
}
}
System.out.println(Math.abs(sum * Math.PI));
}
} | Java | ["1\n1", "3\n1 4 2"] | 2 seconds | ["3.1415926536", "40.8407044967"] | NoteIn the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals ΟβΓβ12β=βΟ.In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the second and the third circles is painted red. Part between the first and the third is painted blue. And, finally, the inner part of the first circle is painted red. Overall there are two red parts: the ring between the second and the third circles and the inner part of the first circle. Total area of the red parts is equal (ΟβΓβ42β-βΟβΓβ22)β+βΟβΓβ12β=βΟβΓβ12β+βΟβ=β13Ο | Java 7 | standard input | [
"sortings",
"geometry"
] | 48b9c68380d3bd64bbc69d921a098641 | The first line contains the single integer n (1ββ€βnββ€β100). The second line contains n space-separated integers ri (1ββ€βriββ€β1000) β the circles' radii. It is guaranteed that all circles are different. | 1,000 | Print the single real number β total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10β-β4. | standard output | |
PASSED | c3107deef3144d9c33929a5de1f22eb8 | train_003.jsonl | 1330536600 | One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides, any two neighboring parts were painted different colors, that is, the red and the blue color were alternating, i. e. followed one after the other. The outer area of the wall (the area that lied outside all circles) was painted blue. Help Sherlock Holmes determine the total area of red parts of the wall.Let us remind you that two circles are called concentric if their centers coincide. Several circles are called concentric if any two of them are concentric. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class Main1 {
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
int n= scan.nextInt();
float cad[]= new float[n];
for (int i = 0; i < n; i++) {
cad[i]=scan.nextFloat();
}
Arrays.sort(cad);
double total=0;
boolean asdas = false;
for (int i = cad.length-1; i >0; i=i-2) {
if((i-1)==0)
asdas=true;
total+= (Math.PI*(cad[i]*cad[i]))-(Math.PI*(cad[i-1]*cad[i-1]));
}
if(!asdas)
total+= (Math.PI*(cad[0]*cad[0]));
System.out.println(total);
}
} | Java | ["1\n1", "3\n1 4 2"] | 2 seconds | ["3.1415926536", "40.8407044967"] | NoteIn the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals ΟβΓβ12β=βΟ.In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the second and the third circles is painted red. Part between the first and the third is painted blue. And, finally, the inner part of the first circle is painted red. Overall there are two red parts: the ring between the second and the third circles and the inner part of the first circle. Total area of the red parts is equal (ΟβΓβ42β-βΟβΓβ22)β+βΟβΓβ12β=βΟβΓβ12β+βΟβ=β13Ο | Java 7 | standard input | [
"sortings",
"geometry"
] | 48b9c68380d3bd64bbc69d921a098641 | The first line contains the single integer n (1ββ€βnββ€β100). The second line contains n space-separated integers ri (1ββ€βriββ€β1000) β the circles' radii. It is guaranteed that all circles are different. | 1,000 | Print the single real number β total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10β-β4. | standard output | |
PASSED | 15e42daa14e22d03e27356665abb4054 | train_003.jsonl | 1330536600 | One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides, any two neighboring parts were painted different colors, that is, the red and the blue color were alternating, i. e. followed one after the other. The outer area of the wall (the area that lied outside all circles) was painted blue. Help Sherlock Holmes determine the total area of red parts of the wall.Let us remind you that two circles are called concentric if their centers coincide. Several circles are called concentric if any two of them are concentric. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class Main1 {
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
int n= scan.nextInt();
float cad[]= new float[n];
for (int i = 0; i < n; i++) {
cad[i]=scan.nextFloat();
}
Arrays.sort(cad);
double total=0;
boolean asdas = false;
for (int i = cad.length-1; i >0; i=i-2) {
if((i-1)==0)
asdas=true;
total+= (Math.PI*(cad[i]*cad[i]))-(Math.PI*(cad[i-1]*cad[i-1]));
}
if(!asdas)
total+= (Math.PI*(cad[0]*cad[0]));
System.out.println(total);
}
} | Java | ["1\n1", "3\n1 4 2"] | 2 seconds | ["3.1415926536", "40.8407044967"] | NoteIn the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals ΟβΓβ12β=βΟ.In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the second and the third circles is painted red. Part between the first and the third is painted blue. And, finally, the inner part of the first circle is painted red. Overall there are two red parts: the ring between the second and the third circles and the inner part of the first circle. Total area of the red parts is equal (ΟβΓβ42β-βΟβΓβ22)β+βΟβΓβ12β=βΟβΓβ12β+βΟβ=β13Ο | Java 7 | standard input | [
"sortings",
"geometry"
] | 48b9c68380d3bd64bbc69d921a098641 | The first line contains the single integer n (1ββ€βnββ€β100). The second line contains n space-separated integers ri (1ββ€βriββ€β1000) β the circles' radii. It is guaranteed that all circles are different. | 1,000 | Print the single real number β total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10β-β4. | standard output | |
PASSED | 11bc44426b0d7c7d42de3fc95b839da4 | train_003.jsonl | 1330536600 | One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides, any two neighboring parts were painted different colors, that is, the red and the blue color were alternating, i. e. followed one after the other. The outer area of the wall (the area that lied outside all circles) was painted blue. Help Sherlock Holmes determine the total area of red parts of the wall.Let us remind you that two circles are called concentric if their centers coincide. Several circles are called concentric if any two of them are concentric. | 256 megabytes |
import java.io.DataInputStream;
import java.io.IOException;
import java.util.Arrays;
public class Case {
static class InputReader {
final private int B_SIZE = 1 << 16;
private DataInputStream d;
private byte[] buffer;
private int pointer, bytes;
public InputReader() {
d = new DataInputStream(System.in);
buffer = new byte[B_SIZE];
pointer = bytes = 0;
}
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;
}
private void fillBuffer() throws IOException {
bytes = d.read(buffer, pointer = 0, B_SIZE);
if (bytes == -1)
buffer[0] = -1;
}
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;
}
public String readLine() throws IOException {
byte[] buf = new byte[1024];
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
private byte read() throws IOException {
if (pointer == bytes)
fillBuffer();
return buffer[pointer++];
}
public void close() throws IOException {
if (d == null)
return;
d.close();
}
}
public static void main(String args[]) throws IOException{
InputReader r=new InputReader();
int n=r.nextInt();
int rad[]=new int[n];
for(int i=0;i<n;i++)
{
rad[i]=r.nextInt();
}
Arrays.sort(rad);
int flag=1;int sum=0;
for(int i=n-1;i>=0;i--)
{
sum=sum+(flag*rad[i]*rad[i]);
if(flag==1)
flag=-1;
else
flag=1;
}
System.out.println(Math.PI*sum);
}
}
| Java | ["1\n1", "3\n1 4 2"] | 2 seconds | ["3.1415926536", "40.8407044967"] | NoteIn the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals ΟβΓβ12β=βΟ.In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the second and the third circles is painted red. Part between the first and the third is painted blue. And, finally, the inner part of the first circle is painted red. Overall there are two red parts: the ring between the second and the third circles and the inner part of the first circle. Total area of the red parts is equal (ΟβΓβ42β-βΟβΓβ22)β+βΟβΓβ12β=βΟβΓβ12β+βΟβ=β13Ο | Java 7 | standard input | [
"sortings",
"geometry"
] | 48b9c68380d3bd64bbc69d921a098641 | The first line contains the single integer n (1ββ€βnββ€β100). The second line contains n space-separated integers ri (1ββ€βriββ€β1000) β the circles' radii. It is guaranteed that all circles are different. | 1,000 | Print the single real number β total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10β-β4. | standard output | |
PASSED | eba6bbf27ae3bd0e844e82058c8fcabc | train_003.jsonl | 1330536600 | One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides, any two neighboring parts were painted different colors, that is, the red and the blue color were alternating, i. e. followed one after the other. The outer area of the wall (the area that lied outside all circles) was painted blue. Help Sherlock Holmes determine the total area of red parts of the wall.Let us remind you that two circles are called concentric if their centers coincide. Several circles are called concentric if any two of them are concentric. | 256 megabytes | import java.io.BufferedOutputStream;
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.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.StringTokenizer;
public class Main
{
public static void main(String args[]) throws IOException
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
int n = Integer.parseInt(in.readLine());
int radios[] = new int[n];
StringTokenizer datos = new StringTokenizer(in.readLine());
for(int i=0;i<n;i++) radios[i] = Integer.parseInt(datos.nextToken());
Arrays.sort(radios);
int res = 0;
boolean flag = true;
for(int i=n-1;i>=0;i--){
if(flag) res+=radios[i] * radios[i];
else res-=radios[i] * radios[i];
flag = !flag;
}
out.println(res * Math.PI);
out.flush();
}
} | Java | ["1\n1", "3\n1 4 2"] | 2 seconds | ["3.1415926536", "40.8407044967"] | NoteIn the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals ΟβΓβ12β=βΟ.In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the second and the third circles is painted red. Part between the first and the third is painted blue. And, finally, the inner part of the first circle is painted red. Overall there are two red parts: the ring between the second and the third circles and the inner part of the first circle. Total area of the red parts is equal (ΟβΓβ42β-βΟβΓβ22)β+βΟβΓβ12β=βΟβΓβ12β+βΟβ=β13Ο | Java 7 | standard input | [
"sortings",
"geometry"
] | 48b9c68380d3bd64bbc69d921a098641 | The first line contains the single integer n (1ββ€βnββ€β100). The second line contains n space-separated integers ri (1ββ€βriββ€β1000) β the circles' radii. It is guaranteed that all circles are different. | 1,000 | Print the single real number β total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10β-β4. | standard output | |
PASSED | e9f1201c2ecd53cbcdbc19b9d7a89c1a | train_003.jsonl | 1330536600 | One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides, any two neighboring parts were painted different colors, that is, the red and the blue color were alternating, i. e. followed one after the other. The outer area of the wall (the area that lied outside all circles) was painted blue. Help Sherlock Holmes determine the total area of red parts of the wall.Let us remind you that two circles are called concentric if their centers coincide. Several circles are called concentric if any two of them are concentric. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
public void solve() throws IOException {
int n=nextInt();
int []rad = new int[n];
for (int i=0; i<n; i++) {
rad[i]=nextInt();
}
Arrays.sort(rad);
boolean include=false;
if (n%2==1) include=true;
double answer=0.0;
for (int i=0; i<n; i++) {
double currentRound=0.0;
if (i==0) {
currentRound=Math.PI*rad[i]*rad[i];
} else {
currentRound=Math.PI*(rad[i]*rad[i]-rad[i-1]*rad[i-1]);
}
if (include) {
answer+=currentRound;
include=false;
} else {
include=true;
}
}
out.println(answer);
}
public static void main(String[] args) throws IOException {
new Main().run();
}
final String fileIn = "test.in";
final String fileOut = "output.txt";
BufferedReader in;
PrintWriter out;
StringTokenizer st = new StringTokenizer("");
private void run() throws IOException {
// if (new File(fileIn).exists())
// in = new BufferedReader(new FileReader(fileIn));
// else {
in = new BufferedReader(new InputStreamReader(System.in)); // ΡΡΠ°Π½Π΄Π°ΡΡΠ½ΡΠΉ Π²Π²ΠΎΠ΄
// }
// if (new File(fileOut).exists()) {
// out = new PrintWriter(new FileWriter(fileOut));
// } else {
out = new PrintWriter(System.out); // ΡΡΠ°Π½Π΄Π°ΡΡΠ½ΡΠΉ Π²ΡΠ²ΠΎΠ΄
// }
solve();
in.close();
out.close();
}
String nextToken() throws IOException {
while (!st.hasMoreTokens())
st = new StringTokenizer(in.readLine());
return st.nextToken();
}
int gcd(int a, int b) {
return (b == 0 ? a : gcd(b, a % b));
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
String nextLine() throws IOException {
st = new StringTokenizer("");
return in.readLine();
}
boolean EOF() throws IOException {
while (!st.hasMoreTokens()) {
String s = in.readLine();
if (s == null)
return true;
st = new StringTokenizer(s);
}
return false;
}
} | Java | ["1\n1", "3\n1 4 2"] | 2 seconds | ["3.1415926536", "40.8407044967"] | NoteIn the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals ΟβΓβ12β=βΟ.In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the second and the third circles is painted red. Part between the first and the third is painted blue. And, finally, the inner part of the first circle is painted red. Overall there are two red parts: the ring between the second and the third circles and the inner part of the first circle. Total area of the red parts is equal (ΟβΓβ42β-βΟβΓβ22)β+βΟβΓβ12β=βΟβΓβ12β+βΟβ=β13Ο | Java 7 | standard input | [
"sortings",
"geometry"
] | 48b9c68380d3bd64bbc69d921a098641 | The first line contains the single integer n (1ββ€βnββ€β100). The second line contains n space-separated integers ri (1ββ€βriββ€β1000) β the circles' radii. It is guaranteed that all circles are different. | 1,000 | Print the single real number β total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10β-β4. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.