結果

問題 No.697 池の数はいくつか
ユーザー 👑 horiesinitihoriesiniti
提出日時 2018-06-11 03:13:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,104 ms / 6,000 ms
コード長 1,067 bytes
コンパイル時間 549 ms
コンパイル使用メモリ 69,208 KB
実行使用メモリ 36,644 KB
最終ジャッジ日時 2024-04-25 20:02:15
合計ジャッジ時間 9,209 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 1 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 1 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 1 ms
6,944 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 1 ms
6,944 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 1 ms
6,940 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 1 ms
6,944 KB
testcase_24 AC 120 ms
6,940 KB
testcase_25 AC 119 ms
7,032 KB
testcase_26 AC 119 ms
7,032 KB
testcase_27 AC 119 ms
7,160 KB
testcase_28 AC 120 ms
7,036 KB
testcase_29 AC 775 ms
6,944 KB
testcase_30 AC 1,104 ms
36,644 KB
testcase_31 AC 780 ms
6,940 KB
testcase_32 AC 1,102 ms
36,016 KB
testcase_33 AC 1,103 ms
36,080 KB
testcase_34 AC 1,104 ms
36,532 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:68:18: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘std::set<int>::size_type’ {aka ‘long unsigned int’} [-Wformat=]
   68 |         printf("%d\n",ss.size());
      |                 ~^    ~~~~~~~~~
      |                  |           |
      |                  int         std::set<int>::size_type {aka long unsigned int}
      |                 %ld
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]);
      |                         ~~~~~^~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <iostream>
#include <stdio.h>
#include <vector>
#include <string.h>
#include <set>

using namespace std;
vector<int> vec;
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);
				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++){
		ss.insert(f(i));
	}
	printf("%d\n",ss.size());
	return 0;
}
0