結果
問題 | No.697 池の数はいくつか |
ユーザー | dnish |
提出日時 | 2018-06-23 01:19:47 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,535 ms / 6,000 ms |
コード長 | 1,737 bytes |
コンパイル時間 | 1,755 ms |
コンパイル使用メモリ | 170,204 KB |
実行使用メモリ | 38,976 KB |
最終ジャッジ日時 | 2024-04-25 20:10:33 |
合計ジャッジ時間 | 13,049 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 1 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 2 ms
6,944 KB |
testcase_07 | AC | 2 ms
6,944 KB |
testcase_08 | AC | 1 ms
6,944 KB |
testcase_09 | AC | 2 ms
6,944 KB |
testcase_10 | AC | 2 ms
6,944 KB |
testcase_11 | AC | 1 ms
6,940 KB |
testcase_12 | AC | 1 ms
6,940 KB |
testcase_13 | AC | 1 ms
6,940 KB |
testcase_14 | AC | 1 ms
6,944 KB |
testcase_15 | AC | 1 ms
6,940 KB |
testcase_16 | AC | 2 ms
6,944 KB |
testcase_17 | AC | 1 ms
6,944 KB |
testcase_18 | AC | 2 ms
6,940 KB |
testcase_19 | AC | 2 ms
6,944 KB |
testcase_20 | AC | 1 ms
6,940 KB |
testcase_21 | AC | 2 ms
6,944 KB |
testcase_22 | AC | 2 ms
6,944 KB |
testcase_23 | AC | 1 ms
6,944 KB |
testcase_24 | AC | 155 ms
16,056 KB |
testcase_25 | AC | 154 ms
15,056 KB |
testcase_26 | AC | 158 ms
15,868 KB |
testcase_27 | AC | 161 ms
14,984 KB |
testcase_28 | AC | 155 ms
15,176 KB |
testcase_29 | AC | 1,421 ms
38,876 KB |
testcase_30 | AC | 1,405 ms
38,808 KB |
testcase_31 | AC | 1,535 ms
38,976 KB |
testcase_32 | AC | 1,431 ms
38,836 KB |
testcase_33 | AC | 1,423 ms
38,872 KB |
testcase_34 | AC | 1,442 ms
38,768 KB |
ソースコード
#include "bits/stdc++.h" #define REP(i,n,N) for(int i=(n); i<(N); i++) #define RREP(i,n,N) for(ll i=(N-1); i>=n; i--) #define CK(n,a,b) ((a)<=(n)&&(n)<(b)) #define ALL(v) (v).begin(),(v).end() #define p(s) cout<<(s)<<endl #define p2(a,b) cout<<(a)<<" "<<(b)<<endl #define v2(T) vector<vector<T>> typedef long long ll; using namespace std; const ll mod= 1e10; int dx[4] = { 0, 1, 0, -1 }; int dy[4] = { -1, 0, 1, 0 }; int H; //フィールドの高さ int W; //フィールドの幅 int start_y, start_x; //開始座標 const int NODE_SIZE = 3010; int field[NODE_SIZE][NODE_SIZE]; //格子状のフィールド (string) //幅優先探索 (フィールド: 配列/string) void bfs_field() { queue<pair<int,int>> q; //<座標(y,x)> q.push({start_y, start_x}); //開始ノードを追加 while(!q.empty()){ int cur_y = q.front().first; int cur_x = q.front().second; q.pop(); if(field[cur_y][cur_x]==0) continue; field[cur_y][cur_x]=0; REP(k,0,4){ int next_y = cur_y + dy[k]; int next_x = cur_x + dx[k]; if(!CK(next_y,0,H) || !CK(next_x,0,W)) continue; //範囲外 /* ここに問題ごとの条件 */ if(field[next_y][next_x]){ //未到達の座標だけpush. q.push({next_y, next_x}); } } } } int main(){ cin>>H>>W; REP(i,0,H) { REP(j, 0, W) { cin >> field[i][j]; } } int ans=0; REP(i,0,H){ REP(j,0,W){ if(field[i][j]){ start_y = i; start_x = j; bfs_field(); ans++; } } } p(ans); return 0; }