結果
| 問題 |
No.697 池の数はいくつか
|
| ユーザー |
tnakao0123
|
| 提出日時 | 2018-06-18 17:04:59 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 1,104 ms / 6,000 ms |
| コード長 | 1,437 bytes |
| コンパイル時間 | 1,658 ms |
| コンパイル使用メモリ | 89,148 KB |
| 実行使用メモリ | 21,120 KB |
| 最終ジャッジ日時 | 2024-11-08 07:54:12 |
| 合計ジャッジ時間 | 10,228 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:48:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
48 | scanf("%d%d", &h, &w);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:53:12: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
53 | scanf("%d", &a);
| ~~~~~^~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-
*
* 697.cc: No.697 池の数はいくつか - yukicoder
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
/* constant */
const int MAX_H = 3000;
const int MAX_W = 3000;
const int dxs[] = { 1, 0, -1, 0 }, dys[] = { 0, -1, 0, 1 };
/* typedef */
typedef pair<int,int> pii;
/* global variables */
bool flds[MAX_H][MAX_W], used[MAX_H][MAX_W];
/* subroutines */
/* main */
int main() {
int h, w;
scanf("%d%d", &h, &w);
for (int y = 0; y < h; y++)
for (int x = 0; x < w; x++) {
int a;
scanf("%d", &a);
flds[y][x] = (a > 0);
}
int cnt = 0;
for (int y = 0; y < h; y++)
for (int x = 0; x < w; x++)
if (flds[y][x] && ! used[y][x]) {
cnt++;
used[y][x] = true;
queue<pii> q;
q.push(pii(x, y));
while (! q.empty()) {
pii u = q.front(); q.pop();
int &ux = u.first, &uy = u.second;
for (int di = 0; di < 4; di++) {
int vx = ux + dxs[di], vy = uy + dys[di];
if (vx >= 0 && vx < w && vy >= 0 && vy < h &&
flds[vy][vx] && ! used[vy][vx]) {
used[vy][vx] = true;
q.push(pii(vx, vy));
}
}
}
}
printf("%d\n", cnt);
return 0;
}
tnakao0123