Submission #2244730
Source Code Expand
import java.util.Scanner;
public class Main {
public static int N;
public static int M;
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
// 行
N = sc.nextInt();
// 列
M = sc.nextInt();
// カード
boolean cards[][] = new boolean[N][M];
initializeCards(cards);
for(int i = 0; i < N ; i++) {
for(int j = 0; j < M; j++) {
manipulate(cards, i, j);
}
}
// debugCards(cards);
// 出力
System.out.println(countCards(cards));
}
private static void initializeCards(boolean[][] cards) {
for(int i = 0; i < N ; i++) {
for(int j = 0; j < M; j++) {
cards[i][j] = true;
}
}
}
private static void debugCards(boolean[][] cards) {
for(int i = 0; i < N ; i++) {
for(int j = 0; j < M; j++) {
System.out.print(cards[i][j]);
}
}
}
private static int countCards(boolean[][] cards) {
int falseNumber = 0;
for(int i = 0; i < N ; i++) {
for(int j = 0; j < M; j++) {
if(cards[i][j] == false) falseNumber = falseNumber + 1;
}
}
return falseNumber;
}
private static void flip(boolean[][] cards, int x, int y){
if( x >= 0 && x < N && y >= 0 && y < M) {
cards[x][y] = (cards[x][y] == true) ? false : true;
}
}
private static void manipulate(boolean[][] cards, int x, int y) {
// 上の行
flip(cards, x - 1, y - 1);
flip(cards, x, y -1 );
flip(cards, x + 1, y -1 );
// 真ん中の行
flip(cards, x - 1, y);
flip(cards, x, y);
flip(cards, x + 1, y);
// 下の行
flip(cards, x - 1, y + 1);
flip(cards, x, y + 1);
flip(cards, x + 1, y + 1);
}
}
Submission Info
Submission Time |
|
Task |
C - Flip,Flip, and Flip...... |
User |
mwktk |
Language |
Java7 (OpenJDK 1.7.0) |
Score |
0 |
Code Size |
1708 Byte |
Status |
RE |
Exec Time |
474 ms |
Memory |
708180 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 300 |
Status |
|
|
Set Name |
Test Cases |
Sample |
s1.txt, s2.txt, s3.txt |
All |
01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, s1.txt, s2.txt, s3.txt |
Case Name |
Status |
Exec Time |
Memory |
01.txt |
AC |
93 ms |
18772 KB |
02.txt |
RE |
118 ms |
41556 KB |
03.txt |
RE |
120 ms |
40020 KB |
04.txt |
MLE |
474 ms |
708180 KB |
05.txt |
RE |
119 ms |
41812 KB |
06.txt |
AC |
94 ms |
16980 KB |
07.txt |
RE |
120 ms |
43988 KB |
s1.txt |
AC |
94 ms |
20820 KB |
s2.txt |
AC |
94 ms |
18772 KB |
s3.txt |
AC |
138 ms |
21952 KB |