結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,424 KB
testcase_01 AC 1 ms
5,432 KB
testcase_02 AC 2 ms
5,648 KB
testcase_03 AC 2 ms
5,436 KB
testcase_04 AC 5 ms
5,396 KB
testcase_05 AC 35 ms
7,460 KB
testcase_06 AC 294 ms
9,548 KB
testcase_07 AC 2 ms
5,468 KB
testcase_08 AC 2 ms
5,392 KB
testcase_09 AC 2 ms
5,400 KB
testcase_10 AC 3 ms
5,404 KB
testcase_11 AC 4 ms
5,416 KB
testcase_12 WA -
testcase_13 AC 288 ms
13,644 KB
testcase_14 AC 2 ms
5,384 KB
testcase_15 AC 2 ms
5,416 KB
testcase_16 AC 1 ms
5,432 KB
testcase_17 AC 1 ms
5,428 KB
testcase_18 AC 2 ms
5,520 KB
testcase_19 AC 4 ms
5,444 KB
testcase_20 WA -
testcase_21 AC 291 ms
13,684 KB
testcase_22 AC 287 ms
13,684 KB
testcase_23 AC 284 ms
13,720 KB
testcase_24 AC 294 ms
13,660 KB
testcase_25 AC 290 ms
13,640 KB
testcase_26 AC 2 ms
5,488 KB
testcase_27 AC 1 ms
5,380 KB
testcase_28 AC 71 ms
9,572 KB
testcase_29 AC 2 ms
5,440 KB
testcase_30 AC 2 ms
5,424 KB
testcase_31 AC 70 ms
13,656 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 AC 2 ms
5,448 KB
testcase_49 AC 2 ms
5,404 KB
testcase_50 AC 2 ms
5,388 KB
testcase_51 WA -
testcase_52 AC 2 ms
5,484 KB
testcase_53 WA -
testcase_54 AC 2 ms
5,708 KB
testcase_55 WA -
testcase_56 AC 3 ms
5,500 KB
testcase_57 WA -
testcase_58 AC 4 ms
5,488 KB
testcase_59 AC 6 ms
5,504 KB
testcase_60 AC 11 ms
5,444 KB
testcase_61 AC 12 ms
5,476 KB
testcase_62 AC 13 ms
5,636 KB
testcase_63 AC 12 ms
5,500 KB
testcase_64 WA -
testcase_65 AC 2 ms
5,516 KB
testcase_66 WA -
testcase_67 AC 2 ms
5,420 KB
testcase_68 AC 2 ms
5,448 KB
testcase_69 AC 3 ms
5,436 KB
testcase_70 AC 4 ms
5,432 KB
testcase_71 AC 7 ms
5,560 KB
testcase_72 AC 2 ms
5,384 KB
testcase_73 AC 2 ms
5,392 KB
testcase_74 AC 2 ms
5,560 KB
testcase_75 AC 2 ms
5,372 KB
testcase_76 AC 2 ms
5,404 KB
testcase_77 AC 2 ms
5,428 KB
testcase_78 AC 1 ms
4,348 KB
testcase_79 AC 1 ms
4,352 KB
testcase_80 AC 1 ms
4,348 KB
testcase_81 AC 2 ms
5,428 KB
testcase_82 AC 2 ms
5,428 KB
testcase_83 AC 2 ms
5,460 KB
testcase_84 AC 115 ms
9,532 KB
testcase_85 AC 133 ms
13,660 KB
testcase_86 AC 2 ms
4,352 KB
testcase_87 AC 1 ms
4,348 KB
testcase_88 AC 108 ms
4,352 KB
testcase_89 AC 99 ms
7,644 KB
testcase_90 WA -
testcase_91 AC 2 ms
5,564 KB
testcase_92 AC 2 ms
5,380 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