結果
| 問題 | No.3558 Dominoes, Black and White |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-06-18 22:54:42 |
| 言語 | Java (openjdk 25.0.2) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,764 bytes |
| 記録 | |
| コンパイル時間 | 2,873 ms |
| コンパイル使用メモリ | 83,904 KB |
| 実行使用メモリ | 163,088 KB |
| 最終ジャッジ日時 | 2026-06-18 22:55:19 |
| 合計ジャッジ時間 | 9,431 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_1 |
(要ログイン)
| サブタスク | 配点 | 結果 |
|---|---|---|
| 部分点 | 10 % | AC * 30 |
| 満点 | 90 % | AC * 31 TLE * 1 -- * 57 |
| 合計 | 10 点 |
ソースコード
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class No3558 {
public static String[][] str;
public static void main(String[] args) throws IOException{
String[] strings = readStr();
int n = Integer.parseInt(strings[0]);
str = new String[strings.length-1][strings[1].length()];
for(int i = 1;i < strings.length;i++) {
str[i-1] = strings[i].split("");
}
int[] lxy = new int[2], rxy = new int[2] ;
int count = 0;
lxy = getXY("#");
rxy = getXY(".");
while(!check(lxy, rxy)) {
count += Math.abs(rxy[0] - lxy[0]) + Math.abs(rxy[1] - lxy[1]);
str[lxy[1]][lxy[0]] = ".";
str[rxy[1]][rxy[0]] = "#";
lxy = getXY("#");
rxy = getXY(".");
}
System.out.println(count);
}
public static boolean check(int[] lxy,int[] rxy) {
boolean result = false;
if(lxy[0] == -1 && lxy[1] == -1 && rxy[0] == -1 && rxy[1] == -1) {
result = true;
}
return result;
}
public static int[] getXY(String bw) {
int[] resultXY = {-1 , -1};
boolean flg = false;
int sx = 0;
if(".".equals(bw)) {
sx = str.length;
}
for(int y = 0;y < str.length;y++) {
for(int x = sx;x < str.length + sx;x++) {
if(bw.equals(str[y][x])) {
resultXY[0] = x;
resultXY[1] = y;
flg = true;
break;
}
}
if(flg) {
break;
}
}
return resultXY;
}
public static String[] readStr() throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
ArrayList<String> list = new ArrayList<>();
do {
list.add(br.readLine());
}while(br.ready());
br.close();
String[] text = new String[list.size()];
list.toArray(text);
return text;
}
}