답안 #88142

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
88142 2018-12-04T03:45:27 Z jasony123123 Kralj (COCI16_kralj) C++11
140 / 140
919 ms 127272 KB
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define FOR(i,start,end) for(int i=start;i<(int)(end);i++)
#define FORE(i,start,end) for(int i=start;i<=(int)end;i++)
#define RFOR(i,start,end) for(int i = start; i>end; i--)
#define RFORE(i,start,end) for(int i = start; i>=end; i--)
#define all(a) a.begin(), a.end()
#define mt make_tuple
#define v vector
#define sf scanf
#define pf printf
#define dvar(x) cout << #x << " := " << x << "\n"
#define darr(x,n) FOR(i,0,n) cout << #x << "[" << i << "]" << " := " << x[i] << "\n"
typedef long long ll;
typedef long double ld;
typedef pair<int, int > pii;
typedef pair<ll, ll> pll;
//template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> void minn(T &a, T b) { a = min(a, b); }
template<class T> void maxx(T &a, T b) { a = max(a, b); }
const ll MOD = 1000000007LL;
const ll PRIME = 105943LL;
const int INF = 1 << 20;
void io() {
#ifdef LOCAL_PROJECT 
	freopen("input.in", "r", stdin); freopen("output.out", "w", stdout);
#else 
	/* online submission */
#endif 
	ios_base::sync_with_stdio(false); cin.tie(NULL);
}
/**************************COCI 2016-2017 #5*********************************/
const int MAXN = 500000;
int N;
v<int> elves[MAXN];
int dwarf[MAXN];

int findStart() {
	pii ans = { INF, INF }; // min prefsum, idx
	int prefsz[MAXN];
	FOR(i, 0, N) {
		prefsz[i] = (i > 0 ? prefsz[i - 1] : 0) + elves[i].size() - 1;
		minn(ans, { (i > 0 ? prefsz[i - 1] : 0), i });
	}
	return ans.second;
}

void input() {
	cin >> N;
	int adv[MAXN];
	FOR(i, 0, N) {
		cin >> adv[i];
		adv[i]--;
	}
	FOR(i, 0, N) cin >> dwarf[i];
	FOR(i, 0, N) {
		int elv;
		cin >> elv;
		elves[adv[i]].push_back(elv);
	}
}

int main() {
	io();
	input();
	int ans = 0;
	int start = findStart();
	assert(start < N);
	set<int> avai;
	int i = start;
	while (1) {
		// evaluate cur
		for (int ep : elves[i])
			avai.insert(ep);
		assert(avai.size() > 0);
		auto it = avai.upper_bound(dwarf[i]);
		if (it == avai.end()) { // no availble elves greater than dwarf i
			avai.erase(avai.begin());
		}
		else { // it is greater
			ans++;
			avai.erase(it);
		}
		// move cur forward
		i++;
		i %= N;
		// break if at start again
		if (i == start)
			break;
	}
	cout << ans << "\n";
	return 0;
}

/*
...
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 919 ms 44264 KB Output is correct
2 Correct 658 ms 51876 KB Output is correct
3 Correct 651 ms 67276 KB Output is correct
4 Correct 844 ms 77832 KB Output is correct
5 Correct 458 ms 77832 KB Output is correct
6 Correct 444 ms 78536 KB Output is correct
7 Correct 532 ms 93624 KB Output is correct
8 Correct 413 ms 104168 KB Output is correct
9 Correct 513 ms 117868 KB Output is correct
10 Correct 444 ms 127272 KB Output is correct