結果
問題 |
No.697 池の数はいくつか
|
ユーザー |
![]() |
提出日時 | 2018-06-09 18:37:23 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 983 ms / 6,000 ms |
コード長 | 1,654 bytes |
コンパイル時間 | 1,684 ms |
コンパイル使用メモリ | 95,744 KB |
実行使用メモリ | 24,448 KB |
最終ジャッジ日時 | 2024-11-08 07:36:35 |
合計ジャッジ時間 | 9,552 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:47:12: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 47 | scanf("%d",&a); | ~~~~~^~~~~~~~~
ソースコード
#include <algorithm> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <memory> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> #include <iomanip> using namespace std; typedef long long ll; #define sz size() #define pb push_back #define mp make_pair #define fi first #define se second #define all(c) (c).begin(), (c).end() #define rep(i,a,b) for(ll i=(a);i<(b);++i) #define per(i,a,b) for(ll i=(b-1);i>=(a);--i) #define clr(a, b) memset((a), (b) ,sizeof(a)) #define ctos(c) string(1,c) #define print(x) cout<<#x<<" = "<<x<<endl; #define MOD 1000000007 char d[10001][10001]; int main() { short h,w; cin>>h>>w; rep(y,0,h){ rep(x,0,w){ int a; scanf("%d",&a); d[y][x] = a; } } int ans = 0; short dy[4] = {0,0,-1,1}; short dx[4] = {-1,1,0,0}; rep(y,0,h){ rep(x,0,w){ if(d[y][x]==0)continue; d[y][x] = 0; ans++; queue<short> q1; queue<short> q2; q1.push(y); q2.push(x); while(!q1.empty()){ short y1 = q1.front();q1.pop(); short x1 = q2.front();q2.pop(); rep(i,0,4){ short y2 = y1 + dy[i]; short x2 = x1 + dx[i]; if(y2<0)continue; if(y2>=h)continue; if(x2<0)continue; if(x2>=w)continue; if(d[y2][x2]==0)continue; d[y2][x2] = 0; q1.push(y2); q2.push(x2); } } } } cout << ans << endl; return 0; }