結果

問題 No.918 LISGRID
ユーザー QCFiumQCFium
提出日時 2019-11-01 16:45:27
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 1,146 bytes
コンパイル時間 1,610 ms
コンパイル使用メモリ 172,436 KB
実行使用メモリ 13,052 KB
最終ジャッジ日時 2023-10-13 00:52:22
合計ジャッジ時間 5,160 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,288 KB
testcase_01 AC 26 ms
10,876 KB
testcase_02 AC 12 ms
8,724 KB
testcase_03 AC 14 ms
8,948 KB
testcase_04 AC 12 ms
8,600 KB
testcase_05 AC 35 ms
11,420 KB
testcase_06 AC 32 ms
11,228 KB
testcase_07 AC 46 ms
12,664 KB
testcase_08 AC 27 ms
10,664 KB
testcase_09 AC 36 ms
11,560 KB
testcase_10 AC 35 ms
11,520 KB
testcase_11 AC 36 ms
11,636 KB
testcase_12 AC 38 ms
11,836 KB
testcase_13 AC 32 ms
11,048 KB
testcase_14 AC 42 ms
12,380 KB
testcase_15 AC 48 ms
13,052 KB
testcase_16 AC 19 ms
9,592 KB
testcase_17 AC 20 ms
9,936 KB
testcase_18 AC 19 ms
9,664 KB
testcase_19 AC 8 ms
8,092 KB
testcase_20 AC 26 ms
10,344 KB
testcase_21 AC 9 ms
8,128 KB
testcase_22 AC 7 ms
7,832 KB
testcase_23 AC 16 ms
9,372 KB
testcase_24 AC 4 ms
7,416 KB
testcase_25 AC 4 ms
7,172 KB
testcase_26 AC 3 ms
7,136 KB
testcase_27 AC 3 ms
7,144 KB
testcase_28 AC 4 ms
7,220 KB
testcase_29 AC 4 ms
7,152 KB
testcase_30 AC 4 ms
7,168 KB
testcase_31 AC 4 ms
7,232 KB
testcase_32 AC 4 ms
7,144 KB
testcase_33 AC 4 ms
7,188 KB
testcase_34 AC 4 ms
7,368 KB
testcase_35 AC 5 ms
7,668 KB
testcase_36 AC 4 ms
7,352 KB
testcase_37 AC 24 ms
10,320 KB
testcase_38 AC 17 ms
9,416 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