結果
| 問題 |
No.2182 KODOKU Stone
|
| コンテスト | |
| ユーザー |
MasKoaTS
|
| 提出日時 | 2022-12-15 18:46:22 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 472 ms / 2,000 ms |
| コード長 | 1,703 bytes |
| コンパイル時間 | 2,902 ms |
| コンパイル使用メモリ | 207,452 KB |
| 最終ジャッジ日時 | 2025-02-09 13:58:17 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 37 |
ソースコード
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define lb(v, a) (int)(lower_bound(all(v), a) - v.begin())
using namespace std;
template <class T> using V = vector<T>;
bool check(int& N, V<int>& K, V<V<int> >& A, int& m) {
V<int> P = {};
int q_max = 0;
for (int i = 0; i < N; ++i) {
int s = A[i].size() - lb(A[i], m);
if (s < A[i].size()) {
P.push_back(s);
}
else if (q_max < s) {
q_max = s;
}
}
if (P.empty()) {
return true;
}
sort(all(P));
multiset<int> mst = {};
for (int i = N - 1; i >= P.size(); --i) {
mst.insert(K[i]);
}
if (mst.empty() == false and q_max >= *mst.begin()) {
return true;
}
for (int i = P.size() - 1; i >= 0; --i) {
int u = mst.empty() ? K[i] : min(*mst.begin(), K[i]);
if (P[i] >= u) {
return true;
}
else if (P[i] < u - 1) {
return false;
}
else if (mst.empty() == false and P[i] == *mst.begin() - 1 and q_max >= K[i]) {
return true;
}
else if (i == 0) {
return false;
}
else if (mst.empty() or P[i] < *mst.begin() - 1) {
continue;
}
mst.erase(mst.begin());
mst.insert(K[i]);
}
return true;
}
int main(void) {
int N; cin >> N;
V<int> K(N);
for (int i = 0; i < N; ++i) {
cin >> K[i];
}
V<int> T(N);
V<V<int> > A(N, V<int>({}));
V<int> st = {};
for (int i = 0; i < N; ++i) {
cin >> T[i];
for (int j = 0; j < T[i]; ++j) {
int a; cin >> a;
A[i].push_back(a);
st.push_back(a);
}
sort(all(A[i]));
}
st.erase(unique(all(st)), st.end());
sort(all(st));
int ok = 0, ng = st.size();
while (ng - ok > 1) {
int t = (ok + ng) >> 1;
if (check(N, K, A, st[t])) {
ok = t;
}
else {
ng = t;
}
}
int ans = st[ok];
cout << ans << endl;
return 0;
}
MasKoaTS