結果
| 問題 |
No.2182 KODOKU Stone
|
| コンテスト | |
| ユーザー |
MasKoaTS
|
| 提出日時 | 2022-10-12 17:06:36 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,524 bytes |
| コンパイル時間 | 2,503 ms |
| コンパイル使用メモリ | 207,060 KB |
| 最終ジャッジ日時 | 2025-02-08 02:02:19 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 35 WA * 2 |
ソースコード
#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;
}
MasKoaTS