# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
661472 | as111 | Kralj (COCI16_kralj) | C++14 | 810 ms | 54908 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <set>
#define MAXN 500000
using namespace std;
int N;
int dwarves[MAXN+5];
int elves[MAXN+5];
int A[MAXN+5];
int net[MAXN+5]; // net amount of elves
vector <int> matches[MAXN+5];
int ans;
set <int> curr;
void solve(int start) {
ans = 0;
for (int i = start, j = 0; j < N; j++, i = (i + 1) % N) {
for (auto e : matches[i]) curr.insert(e); // all that start here
auto it = curr.upper_bound(dwarves[i]); // number right above used
if (it == curr.end()) {
curr.erase(curr.begin());
}
else {// bottom can't be used
ans++;
curr.erase(it); // use the number right above
}
}
}
int main() {
cin >> N;
for (int i = 0; i < N; i++) {
cin >> A[i]; A[i]--;// 0 based
}
for (int i = 0; i < N; i++) {
cin >> dwarves[i];
}
fill(net, net + MAXN, -1); // each empty space starts at -1, even out to 0
for (int i = 0; i < N; i++) {
cin >> elves[i];
net[A[i]]++;
matches[A[i]].push_back(elves[i]);
}
int pos = -1;
int mn = MAXN+1;//min
for (int i = 0; i < N; i++) {
if (i!=0) net[i] += net[i - 1];
if (net[i] < mn) {
mn = net[i];
pos = i;
}
}
int start = (pos + 1) % N; // start right after most negative spot
solve(start);
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |