結果

問題 No.918 LISGRID
ユーザー msm1993msm1993
提出日時 2020-03-31 18:03:55
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 1,146 bytes
コンパイル時間 2,856 ms
コンパイル使用メモリ 172,604 KB
実行使用メモリ 12,984 KB
最終ジャッジ日時 2023-09-07 03:22:53
合計ジャッジ時間 9,919 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,224 KB
testcase_01 AC 25 ms
10,844 KB
testcase_02 AC 12 ms
8,580 KB
testcase_03 AC 14 ms
9,084 KB
testcase_04 AC 12 ms
8,540 KB
testcase_05 AC 32 ms
11,496 KB
testcase_06 AC 30 ms
11,204 KB
testcase_07 AC 42 ms
12,700 KB
testcase_08 AC 27 ms
10,772 KB
testcase_09 AC 33 ms
11,748 KB
testcase_10 AC 36 ms
11,596 KB
testcase_11 AC 32 ms
11,780 KB
testcase_12 AC 35 ms
11,840 KB
testcase_13 AC 30 ms
11,176 KB
testcase_14 AC 40 ms
12,404 KB
testcase_15 AC 49 ms
12,984 KB
testcase_16 AC 20 ms
9,724 KB
testcase_17 AC 21 ms
9,716 KB
testcase_18 AC 19 ms
9,636 KB
testcase_19 AC 9 ms
8,024 KB
testcase_20 AC 26 ms
10,536 KB
testcase_21 AC 9 ms
8,196 KB
testcase_22 AC 7 ms
7,756 KB
testcase_23 AC 16 ms
9,312 KB
testcase_24 AC 5 ms
7,600 KB
testcase_25 AC 4 ms
7,504 KB
testcase_26 AC 4 ms
7,160 KB
testcase_27 AC 3 ms
7,148 KB
testcase_28 AC 3 ms
7,208 KB
testcase_29 AC 3 ms
7,240 KB
testcase_30 AC 3 ms
7,212 KB
testcase_31 AC 3 ms
7,224 KB
testcase_32 AC 4 ms
7,364 KB
testcase_33 AC 4 ms
7,232 KB
testcase_34 AC 5 ms
7,400 KB
testcase_35 AC 5 ms
7,680 KB
testcase_36 AC 4 ms
7,400 KB
testcase_37 AC 27 ms
10,352 KB
testcase_38 AC 17 ms
9,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
std::vector<std::pair<int, int> > hen[400][400];
int ord[400][400];
bool used[400][400];
int head = 0;
void dfs(int x, int y) {
	for (auto &j : hen[x][y]) {
		if (used[j.first][j.second]) continue;
		used[j.first][j.second] = true;
		dfs(j.first, j.second);
	}
	ord[x][y] = head++;
}

int main() {
	int h = ri(), w = ri();
	int a[h], b[w];
	for (int i = 0; i < h; i++) a[i] = ri() - 1;
	for (int i = 0; i < w; i++) b[i] = ri() - 1;
	std::sort(a, a + h, std::greater<>());
	std::sort(b, b + w, std::greater<>());
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < a[i]; j++) hen[i][j].push_back({i, j + 1});
		for (int j = a[i]; j + 1 < w; j++) hen[i][j + 1].push_back({i, j});
	}
	for (int i = 0; i < w; i++) {
		for (int j = 0; j < b[i]; j++) hen[j][i].push_back({j + 1, i});
		for (int j = b[i]; j + 1 < h; j++) hen[j + 1][i].push_back({j, i});
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (!used[i][j]) {
				used[i][j] = true;
				dfs(i, j);
			}
			std::cout << h * w - ord[i][j] << " ";
		}
		std::cout << std::endl;
	}
	
	return 0;
}
0