Submission #796158

# Submission time Handle Problem Language Result Execution time Memory
796158 2023-07-28T07:12:33 Z 이동현(#10071) Security Guard (JOI23_guard) C++17
0 / 100
15 ms 5000 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 a[NS], srt[NS], chk[NS];

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(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] || 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 1876 KB Output is correct
2 Incorrect 15 ms 5000 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1876 KB Output is correct
2 Incorrect 15 ms 5000 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1876 KB Output is correct
2 Incorrect 15 ms 5000 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1876 KB Output is correct
2 Incorrect 15 ms 5000 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1876 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1876 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1876 KB Output is correct
2 Incorrect 15 ms 5000 KB Output isn't correct
3 Halted 0 ms 0 KB -