Submission #37364

# Submission time Handle Problem Language Result Execution time Memory
37364 2017-12-24T16:48:31 Z HardNut Money (IZhO17_money) C++14
0 / 100
0 ms 5924 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 5;

typedef long long ll;

int n, a[N], ans;
set<pair<int, int>> st;

int main() {
    freopen("money.in", "r", stdin);
    freopen("money.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = 1; i <= n; i++) {
        st.insert({a[i], i});
        auto id = st.find({a[i], i});
        if (id == st.begin()) {
            ans++;
            continue;
        }
        id--;
        if ((*id).second == i - 1) {
            continue;
        }
        id = st.upper_bound({a[i], 0});
        if (id == st.begin()) {
            ans++;
            continue;
        }
        id--;
        if ((*id).second == i - 1) {
            continue;
        }
        ans++;
    }
    cout << ans;
}
/**
5
3 3 2 3 1
1 2 3 3 3
**/

Compilation message

money.cpp: In function 'int main()':
money.cpp:13:36: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("money.in", "r", stdin);
                                    ^
money.cpp:14:38: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("money.out", "w", stdout);
                                      ^
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 5924 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 5924 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 5924 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 5924 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
2 Halted 0 ms 0 KB -