結果

問題 No.918 LISGRID
ユーザー QCFium
提出日時 2019-11-01 16:45:27
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 1,146 bytes
コンパイル時間 2,353 ms
コンパイル使用メモリ 173,880 KB
実行使用メモリ 13,184 KB
最終ジャッジ日時 2024-09-14 22:46:00
合計ジャッジ時間 4,981 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

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