Submission #37370

# Submission time Handle Problem Language Result Execution time Memory
37370 2017-12-24T17:49:43 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, lst;
set<pair<int, int>> st;
bool us;

int main() {
//    freopen("money.in", "r", stdin);
//    freopen("money.out", "w", stdout);
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    }
    for (int i = 1; i <= n; i++) {
        st.insert({a[i], i});
        if (lst == a[i]) {
            if (us)
                st.erase({a[i], i});
            continue;
        }
        us = 0;
        lst = a[i];
        auto id = st.find({a[i], i});
        if (id == st.begin()) {
            ans++;
            continue;
        }
        id--;
        if ((*id).second == i - 1) {
            continue;
        }
        id = st.lower_bound({a[i], -1});
        if (id == st.begin()) {
            ans++;
            continue;
        }
        id--;
        if ((*id).second == i - 1) {
            us = 1;
            st.erase({a[i], i});
            continue;
        }
        ans++;
    }
    printf("%d", &ans);
}
/**
6
1 5 2 5 5 6
**/

Compilation message

money.cpp: In function 'int main()':
money.cpp:51:22: warning: format '%d' expects argument of type 'int', but argument 2 has type 'int*' [-Wformat=]
     printf("%d", &ans);
                      ^
money.cpp:16:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
                    ^
money.cpp:18:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i]);
                           ^
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 5924 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 5924 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 5924 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 5924 KB Output isn't correct
2 Halted 0 ms 0 KB -