提出 #3987675


ソースコード 拡げる

#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

LL H, W;
std::vector<std::string>S;
std::vector<std::vector<bool>>vis;
std::vector<std::pair<LL, LL>>memo;

LL dx[] = { -1,0,0,1 }, dy[] = { 0,-1,1,0 };
void f(LL i, LL j)
{
	if (vis[i][j]) return;
	vis[i][j] = true;
	memo.push_back(std::make_pair(i, j));
	rep(k, 4)
	{
		LL x = i + dx[k], y = j + dy[k];
		if (x < 0 || H <= x || y < 0 || W <= y) continue;
		if (S[x][y] != S[i][j]) f(x, y);
	}
}

int main()
{
	in >> H >> W;
	S.resize(H);
	rep(i, H) in >> S[i];

	vis.resize(H);
	rep(i, H) vis[i].resize(W, false);

	LL ans = 0;
	rep(i, H)
	{
		rep(j, W)
		{
			if (!vis[i][j])
			{
				memo.clear();
				f(i, j);
				LL cnt1 = 0, cnt2 = 0;
				for (auto k : memo)
				{
					if (S[k.first][k.second] == '#') ++cnt1;
					else ++cnt2;
				}
				ans += cnt1 * cnt2;
			}
		}
	}

	out << ans << std::endl;
}

提出情報

提出日時
問題 C - Alternating Path
ユーザ babcs2035
言語 C++14 (GCC 5.4.1)
得点 300
コード長 994 Byte
結果 AC
実行時間 20 ms
メモリ 18540 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 300 / 300
結果
AC × 3
AC × 15
セット名 テストケース
Sample sample-01.txt, sample-02.txt, sample-03.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, sample-01.txt, sample-02.txt, sample-03.txt
ケース名 結果 実行時間 メモリ
01.txt AC 6 ms 384 KiB
02.txt AC 12 ms 512 KiB
03.txt AC 2 ms 256 KiB
04.txt AC 9 ms 512 KiB
05.txt AC 20 ms 18540 KiB
06.txt AC 20 ms 17136 KiB
07.txt AC 17 ms 13040 KiB
08.txt AC 10 ms 1152 KiB
09.txt AC 11 ms 1024 KiB
10.txt AC 1 ms 256 KiB
11.txt AC 1 ms 256 KiB
12.txt AC 1 ms 256 KiB
sample-01.txt AC 1 ms 256 KiB
sample-02.txt AC 1 ms 256 KiB
sample-03.txt AC 1 ms 256 KiB