답안 #295161

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
295161 2020-09-09T14:01:46 Z shivensinha4 Kralj (COCI16_kralj) C++17
0 / 140
2000 ms 39288 KB
#include <bits/stdc++.h> 
using namespace std; 
#define for_(i, s, e) for (int i = s; i < (int) e; i++)
#define for__(i, s, e) for (ll i = s; i < e; i++)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define endl '\n'


int main() {
	#ifdef shiven
	freopen("test.in", "r", stdin);
	#endif
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n; cin >> n;
	vi adv(n), a(n), b(n), advPref(n);
	vector<vi> elfHere(n);
	for_(i, 0, n) {
		cin >> adv[i];
		adv[i] -= 1;
		advPref[adv[i]] += 1;
		elfHere[adv[i]].push_back(i);
	}
	for_(i, 0, n) cin >> a[i];
	for_(i, 0, n) cin >> b[i];
	
	int mn = INT_MAX, mnIdx = -1;
	for_(i, 0, n) {
		if (i > 0) adv[i] += adv[i-1];
		if (adv[i]-i < mn) {
			mn = adv[i]-i;
			mnIdx = i;
		}
	}

	int ans = 0;
	set<int> s;
	for_(idx, 0, n) {
		int i = (mnIdx + i);
		if (i >= n) i -= n;
		for (auto j: elfHere[i]) s.insert(b[j]);
		auto pt = s.lower_bound(a[i]);
		if (pt == s.end()) {
			s.erase(s.begin());
		} else {
			ans += 1;
			s.erase(pt);
		}
	}
	
	cout << ans << endl;

	return 0;
}

Compilation message

kralj.cpp: In function 'int main()':
kralj.cpp:43:7: warning: 'i' may be used uninitialized in this function [-Wmaybe-uninitialized]
   43 |   int i = (mnIdx + i);
      |       ^
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2057 ms 26228 KB Time limit exceeded
2 Execution timed out 2061 ms 25204 KB Time limit exceeded
3 Execution timed out 2098 ms 31340 KB Time limit exceeded
4 Execution timed out 2056 ms 31596 KB Time limit exceeded
5 Execution timed out 2090 ms 33016 KB Time limit exceeded
6 Execution timed out 2074 ms 32760 KB Time limit exceeded
7 Execution timed out 2101 ms 37240 KB Time limit exceeded
8 Execution timed out 2092 ms 34168 KB Time limit exceeded
9 Execution timed out 2101 ms 39288 KB Time limit exceeded
10 Execution timed out 2043 ms 35832 KB Time limit exceeded