結果
| 問題 |
No.697 池の数はいくつか
|
| ユーザー |
horiesiniti
|
| 提出日時 | 2018-06-11 03:16:53 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 880 ms / 6,000 ms |
| コード長 | 1,149 bytes |
| コンパイル時間 | 4,251 ms |
| コンパイル使用メモリ | 78,864 KB |
| 最終ジャッジ日時 | 2025-01-05 12:25:11 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:30:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
30 | scanf("%d %d",&h,&w);
| ~~~~~^~~~~~~~~~~~~~~
main.cpp:35:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
35 | scanf("%d",&ms[now][x]);
| ~~~~~^~~~~~~~~~~~~~~~~~
ソースコード
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string.h>
#include <set>
using namespace std;
vector<int> vec,vec2;
set<int> ss;
int f(int p){
if(p==vec[p]){
return p;
}else{
int p2=f(vec[p]);
vec[p]=p2;
return p2;
}
}
int main() {
// your code goes here
int h,w;
int ms[2][3001];
int cs[2][3001];
int c=0;
memset(cs,0,sizeof(cs));
memset(ms,0,sizeof(ms));
scanf("%d %d",&h,&w);
for(int y=0;y<h;y++){
int now=y%2;
int old=(y+1)%2;
for(int x=0;x<w;x++){
scanf("%d",&ms[now][x]);
}
for(int x=0;x<w;x++){
if(ms[now][x]==0)continue;
int ml,mu;
if(x-1<0){
ml=0;
}else{
ml=ms[now][x-1];
}
if(y-1<0){
mu=0;
}else{
mu=ms[old][x];
}
if(ml==0&&mu==0){
vec.push_back(c);
vec2.push_back(0);
cs[now][x]=c;
c++;
}else if(ml==0){
cs[now][x]=cs[old][x];
}else if(mu==0){
cs[now][x]=cs[now][x-1];
}else{
cs[now][x]=cs[old][x];
vec[f(cs[now][x-1])]=f(cs[old][x]);
}
}
}
for(int i=0;i<vec.size();i++){
vec2[f(i)]=1;
}
int ans=0;
for(int i=0;i<vec.size();i++){
ans+=vec2[i];
}
printf("%d\n",ans);
return 0;
}
horiesiniti