| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 259636 | lyc | Santa Claus (RMI19_santa) | C++14 | 1099 ms | 1656 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for (int i=(a);i>=(b);--i)
const int mxN = 96068 + 5;
int T, N, X[mxN], H[mxN], V[mxN];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> T;
while (T--) {
cin >> N;
FOR(i,1,N){ cin >> X[i]; }
FOR(i,1,N){ cin >> H[i]; }
FOR(i,1,N){ cin >> V[i]; }
int totElf = 0;
FOR(i,1,N) if (H[i] == 0) ++totElf;
FOR(i,1,N){
int ans = -1;
X[0] = -1;
FOR(k,0,N){
if (X[k] > X[i]) break;
int cnt = 0;
multiset<int> gifts;
multiset<int> received;
int rt = -1;
FOR(j,1,N){
if (X[j] > X[i]) break;
rt = j;
if (H[j] == 0) {
gifts.insert(V[j]);
++cnt;
} else if (X[j] <= X[k]) {
auto it = gifts.lower_bound(V[j]);
if (it != gifts.end()) {
gifts.erase(it);
received.insert(j);
}
}
}
if (cnt != totElf) break;
//~ if (k < 5) continue;
int lt = -1;
RFOR(j,rt,1){
if (H[j] == 1 && received.count(j) == 0) {
auto it = gifts.lower_bound(V[j]);
//~ if (it != gifts.end()) TRACE(j _ V[j] _ *it);
if (it != gifts.end()) gifts.erase(it);
if (gifts.empty()) { lt = j; break; }
}
}
if (lt != -1) {
int cur = 2*X[rt]-X[lt];
//~ TRACE(k _ cur);
if (ans == -1 || ans > cur) ans = cur;
} //else TRACE("");
}
cout << ans << ' ';
}
cout << '\n';
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
