結果

問題 No.1123 Afforestation
ユーザー e869120e869120
提出日時 2020-07-03 00:12:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,073 bytes
コンパイル時間 2,382 ms
コンパイル使用メモリ 78,844 KB
実行使用メモリ 13,780 KB
最終ジャッジ日時 2023-10-14 23:33:24
合計ジャッジ時間 18,063 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,420 KB
testcase_01 AC 2 ms
5,592 KB
testcase_02 AC 1 ms
5,420 KB
testcase_03 AC 2 ms
5,428 KB
testcase_04 AC 5 ms
5,384 KB
testcase_05 AC 36 ms
7,540 KB
testcase_06 AC 295 ms
9,516 KB
testcase_07 AC 2 ms
5,552 KB
testcase_08 AC 1 ms
5,444 KB
testcase_09 AC 2 ms
5,356 KB
testcase_10 AC 2 ms
5,696 KB
testcase_11 AC 3 ms
5,420 KB
testcase_12 WA -
testcase_13 AC 295 ms
13,632 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 2 ms
5,508 KB
testcase_17 WA -
testcase_18 AC 2 ms
5,428 KB
testcase_19 AC 5 ms
5,508 KB
testcase_20 AC 35 ms
9,584 KB
testcase_21 AC 290 ms
13,780 KB
testcase_22 AC 293 ms
13,732 KB
testcase_23 AC 294 ms
13,712 KB
testcase_24 AC 296 ms
13,676 KB
testcase_25 AC 296 ms
13,760 KB
testcase_26 AC 2 ms
5,540 KB
testcase_27 AC 2 ms
5,672 KB
testcase_28 AC 72 ms
9,692 KB
testcase_29 AC 2 ms
5,424 KB
testcase_30 AC 2 ms
5,456 KB
testcase_31 AC 72 ms
13,708 KB
testcase_32 AC 2 ms
5,432 KB
testcase_33 AC 2 ms
5,432 KB
testcase_34 WA -
testcase_35 AC 3 ms
5,436 KB
testcase_36 AC 2 ms
5,492 KB
testcase_37 WA -
testcase_38 AC 2 ms
5,668 KB
testcase_39 WA -
testcase_40 AC 2 ms
5,476 KB
testcase_41 WA -
testcase_42 AC 4 ms
5,508 KB
testcase_43 WA -
testcase_44 AC 11 ms
5,724 KB
testcase_45 AC 11 ms
5,548 KB
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 WA -
testcase_69 WA -
testcase_70 WA -
testcase_71 WA -
testcase_72 AC 2 ms
5,444 KB
testcase_73 AC 2 ms
5,524 KB
testcase_74 AC 2 ms
5,412 KB
testcase_75 AC 2 ms
5,684 KB
testcase_76 AC 2 ms
5,376 KB
testcase_77 AC 2 ms
5,484 KB
testcase_78 AC 2 ms
4,356 KB
testcase_79 AC 2 ms
4,352 KB
testcase_80 AC 1 ms
4,352 KB
testcase_81 AC 2 ms
5,560 KB
testcase_82 AC 2 ms
5,432 KB
testcase_83 AC 2 ms
5,460 KB
testcase_84 AC 104 ms
9,572 KB
testcase_85 AC 124 ms
13,644 KB
testcase_86 AC 2 ms
4,352 KB
testcase_87 AC 2 ms
4,348 KB
testcase_88 AC 98 ms
4,348 KB
testcase_89 AC 100 ms
7,504 KB
testcase_90 WA -
testcase_91 AC 2 ms
5,416 KB
testcase_92 AC 2 ms
5,340 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#pragma warning (disable: 4996)

// 入力
int H, A[2509];
int W, B[2509];
int K, X[19], Y[19];

// その他
int Answer[2509][2509];
bool used[2509][2509];
bool forced[2509][2509];

int main() {
	// 入力
	cin >> H >> W;
	for (int i = 1; i <= H; i++) cin >> A[i];
	for (int i = 1; i <= W; i++) cin >> B[i];
	cin >> K;
	for (int i = 1; i <= K; i++) cin >> X[i] >> Y[i];

	// 貪欲法
	vector<pair<int, int>> CA, CB;
	for (int i = 1; i <= K; i++) forced[X[i]][Y[i]] = true;
	for (int i = 1; i <= H; i++) CA.push_back(make_pair(A[i], -i));
	for (int i = 1; i <= W; i++) CB.push_back(make_pair(B[i], -i));
	sort(CA.begin(), CA.end()); reverse(CA.begin(), CA.end());
	sort(CB.begin(), CB.end()); reverse(CB.begin(), CB.end());
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < CA[i].first; j++) used[-CA[i].second][-CB[j].second] = true;
		for (int j = 0; j < CA[i].first; j++) CB[j].first -= 1;
		sort(CB.begin(), CB.end()); reverse(CB.begin(), CB.end());
	}
	if (CB[0].first >= 1) {
		printf(":(\n");
		return 0;
	}

	// 判定
	int SA = 0; for (int i = 1; i <= H; i++) SA += A[i];
	int SB = 0; for (int i = 1; i <= W; i++) SB += B[i];
	if (SA != SB) {
		printf(":(\n");
		return 0;
	}

	// 書き換え
	for (int i = 1; i <= K; i++) {
		if (used[X[i]][Y[i]] == false) continue;
		bool flag = false;
		for (int j = 1; j <= H; j++) {
			for (int k = 1; k <= W; k++) {
				if (used[X[i]][k] == true || forced[X[i]][k] == true) continue;
				if (used[j][Y[i]] == true || forced[j][Y[i]] == true) continue;
				if (used[j][k] == false) continue;
				flag = true;
				used[X[i]][k] = true;
				used[j][Y[i]] = true;
				used[j][k] = false;
				break;
			}
			if (flag == true) break;
		}
		if (flag == false) {
			cout << ":(" << endl;
			return 0;
		}
	}

	// 出力
	printf("Yay!\n");
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			if (forced[i][j] == true) printf("x");
			else if (used[i][j] == true) printf("o");
			else printf(".");
		}
		printf("\n");
	}
	return 0;
}
0