# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
796156 |
2023-07-28T07:11:10 Z |
이동현(#10071) |
Security Guard (JOI23_guard) |
C++17 |
|
57 ms |
8148 KB |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define int long long
using namespace std;
const int NS = (int)2e5 + 4;
int n, m, q;
int l[NS], r[NS], a[NS], srt[NS], chk[NS];
int fdl(int x){
return (x == l[x] ? x : l[x] = fdl(l[x]));
}
int fdr(int x){
return (x == r[x] ? x : r[x] = fdr(r[x]));
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
iota(l, l + NS, 0);
iota(r, r + NS, 0);
cin >> n >> m >> q;
int ans = 0;
for(int i = 1; i <= n; ++i){
cin >> a[i];
if(i > 1){
ans += min(a[i - 1], a[i]);
}
}
iota(srt, srt + NS, 0);
sort(srt + 1, srt + n + 1, [&](int x, int y){return a[x] > a[y];});
int gr = 1;
for(int i = 1; i <= n; ++i){
int now = srt[i];
chk[now] = 1;
if(now > 1 && now < n) ++gr;
if(chk[now - 1]){
--gr;
}
if(chk[now + 1]){
--gr;
}
if(i == n || a[srt[i]] != a[srt[i + 1]]){
// cout << i << ' ' << now << ' ' << ans << ' ' << gr << endl;
ans += gr;
}
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
19 ms |
8104 KB |
Output is correct |
3 |
Correct |
26 ms |
8128 KB |
Output is correct |
4 |
Correct |
20 ms |
8084 KB |
Output is correct |
5 |
Correct |
24 ms |
8020 KB |
Output is correct |
6 |
Correct |
20 ms |
8132 KB |
Output is correct |
7 |
Correct |
22 ms |
8148 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
19 ms |
8104 KB |
Output is correct |
3 |
Correct |
26 ms |
8128 KB |
Output is correct |
4 |
Correct |
20 ms |
8084 KB |
Output is correct |
5 |
Correct |
24 ms |
8020 KB |
Output is correct |
6 |
Correct |
20 ms |
8132 KB |
Output is correct |
7 |
Correct |
22 ms |
8148 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
10 |
Incorrect |
57 ms |
8056 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
19 ms |
8104 KB |
Output is correct |
3 |
Correct |
26 ms |
8128 KB |
Output is correct |
4 |
Correct |
20 ms |
8084 KB |
Output is correct |
5 |
Correct |
24 ms |
8020 KB |
Output is correct |
6 |
Correct |
20 ms |
8132 KB |
Output is correct |
7 |
Correct |
22 ms |
8148 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
10 |
Incorrect |
57 ms |
8056 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
19 ms |
8104 KB |
Output is correct |
3 |
Correct |
26 ms |
8128 KB |
Output is correct |
4 |
Correct |
20 ms |
8084 KB |
Output is correct |
5 |
Correct |
24 ms |
8020 KB |
Output is correct |
6 |
Correct |
20 ms |
8132 KB |
Output is correct |
7 |
Correct |
22 ms |
8148 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
10 |
Incorrect |
57 ms |
8056 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4948 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4948 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
19 ms |
8104 KB |
Output is correct |
3 |
Correct |
26 ms |
8128 KB |
Output is correct |
4 |
Correct |
20 ms |
8084 KB |
Output is correct |
5 |
Correct |
24 ms |
8020 KB |
Output is correct |
6 |
Correct |
20 ms |
8132 KB |
Output is correct |
7 |
Correct |
22 ms |
8148 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
10 |
Incorrect |
57 ms |
8056 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |