# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
513773 |
2022-01-17T15:35:10 Z |
Mazaalai |
Money (IZhO17_money) |
C++17 |
|
4 ms |
336 KB |
#include <bits/stdc++.h>
#define pb push_back
#define LINE "-----------------\n"
#define ALL(x) x.begin(),x.end()
using namespace std;
int n, m;
vector <int> nums, sorted;
const int N = 1e6 + 5;
const int M = 1e6 + 1;
int cnt[N], nx[N], pv[N];
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
cin >> n;
for (int i = 0; i < n; i++) {
int x; cin >> x;
cnt[x]++;
nums.pb(x);
// sorted.pb(x);
}
// sort(ALL(sorted));
for (int i = 1; i < M; i++) {
if (cnt[i] > 0) sorted.pb(i);
}
nx[0] = sorted[0];
pv[sorted[0]] = 0;
for (int i = 0; i < n - 1; i++) {
// if (sorted[i] != sorted[i+1]) {
nx[sorted[i]] = sorted[i+1];
pv[sorted[i+1]] = sorted[i];
// }
}
nx[sorted.back()] = M;
pv[M] = sorted.back();
int ans = 0;
for (int i = n - 1, j, curCnt, a, b; i >= 0; i--) {
curCnt = 1;
bool border = 1;
for (j = i-1; j >= 0; j--) {
if (nums[j] == nums[j+1]) {
curCnt++;
continue;
} else {
if (nx[nums[j]] != nums[j+1]) break;
if (!border && curCnt != cnt[nums[j+1]]) break;
cnt[nums[j+1]] -= curCnt;
if (cnt[nums[j+1]] == 0) {
a = pv[nums[j+1]], b = nx[nums[j+1]];
nx[a] = b;
pv[b] = a;
}
border = 0;
curCnt = 1;
}
}
cnt[nums[j+1]] -= curCnt;
if (cnt[nums[j+1]] == 0) {
a = pv[nums[j+1]], b = nx[nums[j+1]];
nx[a] = b;
pv[b] = a;
}
ans++;
i = j+1;
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
332 KB |
Output is correct |
2 |
Correct |
4 ms |
332 KB |
Output is correct |
3 |
Correct |
4 ms |
332 KB |
Output is correct |
4 |
Correct |
4 ms |
332 KB |
Output is correct |
5 |
Correct |
3 ms |
332 KB |
Output is correct |
6 |
Correct |
4 ms |
332 KB |
Output is correct |
7 |
Correct |
4 ms |
336 KB |
Output is correct |
8 |
Correct |
4 ms |
332 KB |
Output is correct |
9 |
Correct |
4 ms |
332 KB |
Output is correct |
10 |
Correct |
4 ms |
332 KB |
Output is correct |
11 |
Correct |
4 ms |
332 KB |
Output is correct |
12 |
Correct |
4 ms |
332 KB |
Output is correct |
13 |
Correct |
4 ms |
332 KB |
Output is correct |
14 |
Correct |
4 ms |
332 KB |
Output is correct |
15 |
Correct |
4 ms |
332 KB |
Output is correct |
16 |
Correct |
4 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
332 KB |
Output is correct |
2 |
Correct |
4 ms |
332 KB |
Output is correct |
3 |
Correct |
4 ms |
332 KB |
Output is correct |
4 |
Correct |
4 ms |
332 KB |
Output is correct |
5 |
Correct |
3 ms |
332 KB |
Output is correct |
6 |
Correct |
4 ms |
332 KB |
Output is correct |
7 |
Correct |
4 ms |
336 KB |
Output is correct |
8 |
Correct |
4 ms |
332 KB |
Output is correct |
9 |
Correct |
4 ms |
332 KB |
Output is correct |
10 |
Correct |
4 ms |
332 KB |
Output is correct |
11 |
Correct |
4 ms |
332 KB |
Output is correct |
12 |
Correct |
4 ms |
332 KB |
Output is correct |
13 |
Correct |
4 ms |
332 KB |
Output is correct |
14 |
Correct |
4 ms |
332 KB |
Output is correct |
15 |
Correct |
4 ms |
332 KB |
Output is correct |
16 |
Correct |
4 ms |
332 KB |
Output is correct |
17 |
Incorrect |
4 ms |
332 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
332 KB |
Output is correct |
2 |
Correct |
4 ms |
332 KB |
Output is correct |
3 |
Correct |
4 ms |
332 KB |
Output is correct |
4 |
Correct |
4 ms |
332 KB |
Output is correct |
5 |
Correct |
3 ms |
332 KB |
Output is correct |
6 |
Correct |
4 ms |
332 KB |
Output is correct |
7 |
Correct |
4 ms |
336 KB |
Output is correct |
8 |
Correct |
4 ms |
332 KB |
Output is correct |
9 |
Correct |
4 ms |
332 KB |
Output is correct |
10 |
Correct |
4 ms |
332 KB |
Output is correct |
11 |
Correct |
4 ms |
332 KB |
Output is correct |
12 |
Correct |
4 ms |
332 KB |
Output is correct |
13 |
Correct |
4 ms |
332 KB |
Output is correct |
14 |
Correct |
4 ms |
332 KB |
Output is correct |
15 |
Correct |
4 ms |
332 KB |
Output is correct |
16 |
Correct |
4 ms |
332 KB |
Output is correct |
17 |
Incorrect |
4 ms |
332 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
332 KB |
Output is correct |
2 |
Correct |
4 ms |
332 KB |
Output is correct |
3 |
Correct |
4 ms |
332 KB |
Output is correct |
4 |
Correct |
4 ms |
332 KB |
Output is correct |
5 |
Correct |
3 ms |
332 KB |
Output is correct |
6 |
Correct |
4 ms |
332 KB |
Output is correct |
7 |
Correct |
4 ms |
336 KB |
Output is correct |
8 |
Correct |
4 ms |
332 KB |
Output is correct |
9 |
Correct |
4 ms |
332 KB |
Output is correct |
10 |
Correct |
4 ms |
332 KB |
Output is correct |
11 |
Correct |
4 ms |
332 KB |
Output is correct |
12 |
Correct |
4 ms |
332 KB |
Output is correct |
13 |
Correct |
4 ms |
332 KB |
Output is correct |
14 |
Correct |
4 ms |
332 KB |
Output is correct |
15 |
Correct |
4 ms |
332 KB |
Output is correct |
16 |
Correct |
4 ms |
332 KB |
Output is correct |
17 |
Incorrect |
4 ms |
332 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |