結果
| 問題 | No.697 池の数はいくつか |
| ユーザー |
kokatsu
|
| 提出日時 | 2021-10-26 19:04:31 |
| 言語 | D (dmd 2.111.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,140 bytes |
| 記録 | |
| コンパイル時間 | 2,590 ms |
| コンパイル使用メモリ | 208,128 KB |
| 実行使用メモリ | 512,612 KB |
| 最終ジャッジ日時 | 2024-06-22 13:00:14 |
| 合計ジャッジ時間 | 17,852 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 MLE * 1 -- * 8 |
ソースコード
import std;
struct Grid {
int x;
int y;
}
void main() {
int H, W;
readf("%d %d\n", H, W);
auto A = new int[][](H, W);
foreach (i; 0 .. H) {
A[i] = readln.chomp.split.to!(int[]);
}
auto move = [
Grid(-1, 0),
Grid(0, 1),
Grid(1, 0),
Grid(0, -1)
];
Grid[] que;
int res;
foreach (i; 0 .. H) {
foreach (j; 0 .. W) {
if (A[i][j] == 0) {
continue;
}
++res;
que ~= Grid(i, j);
while (!que.empty) {
auto f = que.front;
que.popFront;
A[f.x][f.y] = 0;
foreach (m; move) {
auto next = f;
next.x += m.x, next.y += m.y;
if (next.x < 0 || next.x >= H || next.y < 0 || next.y >= W) {
continue;
}
if (A[next.x][next.y] == 0) {
continue;
}
que ~= next;
}
}
}
}
res.writeln;
}
kokatsu