結果

問題 No.2182 KODOKU Stone
ユーザー MasKoaTSMasKoaTS
提出日時 2022-10-12 17:06:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,524 bytes
コンパイル時間 2,392 ms
コンパイル使用メモリ 207,680 KB
実行使用メモリ 11,268 KB
最終ジャッジ日時 2024-04-26 21:06:47
合計ジャッジ時間 5,831 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 109 ms
11,264 KB
testcase_12 AC 131 ms
11,012 KB
testcase_13 AC 40 ms
5,376 KB
testcase_14 AC 39 ms
5,376 KB
testcase_15 AC 139 ms
11,268 KB
testcase_16 AC 125 ms
11,264 KB
testcase_17 AC 48 ms
5,376 KB
testcase_18 AC 101 ms
9,852 KB
testcase_19 AC 72 ms
6,404 KB
testcase_20 AC 92 ms
8,628 KB
testcase_21 AC 42 ms
5,376 KB
testcase_22 AC 39 ms
5,376 KB
testcase_23 WA -
testcase_24 AC 51 ms
5,376 KB
testcase_25 AC 30 ms
5,376 KB
testcase_26 AC 29 ms
5,376 KB
testcase_27 AC 30 ms
5,376 KB
testcase_28 AC 84 ms
7,904 KB
testcase_29 AC 105 ms
9,276 KB
testcase_30 AC 115 ms
10,188 KB
testcase_31 AC 84 ms
7,728 KB
testcase_32 AC 87 ms
7,708 KB
testcase_33 AC 98 ms
8,760 KB
testcase_34 AC 57 ms
5,376 KB
testcase_35 AC 101 ms
8,824 KB
testcase_36 AC 25 ms
5,376 KB
testcase_37 AC 112 ms
10,160 KB
testcase_38 WA -
testcase_39 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, l, n) for (int i = (l); i < (n); i++)
#define all(x) x.begin(), x.end()
#define last(v) v[v.size() - 1]
using namespace std;
template <class T>	using V = vector<T>;

int N;
V<int> K;
V<int> T;
V<V<int> > A;
V<int> normal;
V<int> full;

bool check(int mid);
bool check_2(int t);


int main(void) {
	cin >> N;
	K = V<int>(N);
	rep(i, 0, N) {
		cin >> K[i];
	}
	T = V<int>(N);
	A = V<V<int> >(N, V<int>({}));
	V<int> st = {};
	rep(i, 0, N) {
		cin >> T[i];
		rep(j, 0, T[i]) {
			int a;	cin >> a;
			A[i].push_back(a);
			st.push_back(a);
		}
	}
	st.erase(unique(all(st)), st.end());
	sort(all(st));

	int ok = 0, ng = st.size();
	while (ng - ok > 1) {
		int mid = (ok + ng) >> 1;

		if (check(st[mid])) {
			ok = mid;
		}
		else {
			ng = mid;
		}
	}

	int ans = st[ok];
	cout << ans << endl;

	return 0;
}


bool check(int mid) {
	normal = {};	full = {};
	for (V<int>& va : A) {
		int s = 0;
		for (int a : va) {
			s += (a >= mid);
		}
		if (s == va.size()) {
			full.push_back(s);
		}
		else {
			normal.push_back(s);
		}
	}
	sort(all(normal));
	sort(all(full), greater<int>());

	return check_2(N - 1);
}


bool check_2(int t) {
	if (t == -1) {
		return true;
	}

	int k = K[t];
	int a = (normal.empty() == false) ? last(normal) : -1;
	int b = (full.empty() == false) ? full[0] : -1;
	if (max(a, b) >= k) {
		return true;
	}
	if (t > 0 and a == k - 1) {
		normal.pop_back();
		return check_2(t - 1);
	}
	if (b >= 0) {
		full.pop_back();
		return check_2(t - 1);
	}
	return false;
}
0