結果
| 問題 |
No.697 池の数はいくつか
|
| ユーザー |
IL_msta
|
| 提出日時 | 2018-06-12 20:04:55 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,386 bytes |
| コンパイル時間 | 1,776 ms |
| コンパイル使用メモリ | 124,508 KB |
| 実行使用メモリ | 46,628 KB |
| 最終ジャッジ日時 | 2024-11-25 13:32:52 |
| 合計ジャッジ時間 | 69,889 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 TLE * 9 |
ソースコード
#define _USE_MATH_DEFINES
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>
#include <string>
#include <cstring>
#include <vector>
#include <bitset>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>
#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;
int R,C;
vector<vector<int> > fld;
int index(int r,int c){
return r*C+c;
}
int dr[] = {0,1,0,-1};
int dc[] = {1,0,-1,0};
void cal(int r,int c,int color){
vector<vector<bool> > visit(R,vector<bool>(C,false) );
vector<int> start(2);
start[0] = r;
start[1] = c;
queue< vector<int> > now,next,zero;
//visit[index(start[0],start[1]) ] = true;
visit[start[0]][start[1]] = true;
fld[start[0]][start[1]] = color;
next.push( start );
vector<int> temp(2);
while(next.size()){
now = next;
next = zero;
while(now.size()){
vector<int> dat = now.front();
now.pop();
for(int k=0;k<4;++k){
int rr = dat[0] + dr[k];
int cc = dat[1] + dc[k];
if(rr<0 || R<= rr || cc<0 || C<= cc){
continue;//範囲外
}
if(fld[rr][cc] == 0){//水じゃない
continue;
}
if(fld[rr][cc]==-1){//隣接した水
if(visit[rr][cc]==false){//未使用
visit[rr][cc] = true;
fld[rr][cc] = color;
temp[0] = rr;
temp[1] = cc;
next.push(temp);
}
}
}
}
}
}
void solve(){
cin>>R>>C;
fld=vector<vector<int> >(R,vector<int>(C,0));
for(int r=0;r<R;++r){
for(int c=0;c<C;++c){
int ter;
cin>>ter;
if(ter){
fld[r][c]=-1;
}
}
}
int ans = 0;
for(int r=0;r<R;++r){
for(int c=0;c<C;++c){
if(fld[r][c]==-1){
++ans;
cal(r,c,ans);
}
}
}
cout << ans << endl;
}
#pragma region main
signed main(void){
std::cin.tie(0);
std::ios::sync_with_stdio(false);
std::cout << std::fixed;//小数を10進数表示
cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別
solve();
}
#pragma endregion //main()
IL_msta