답안 #465025

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
465025 2021-08-14T21:12:14 Z TeaTime Money (IZhO17_money) C++17
0 / 100
1 ms 332 KB
//#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <unordered_map>

using namespace std;

#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

typedef long long ll;
typedef long double ld;

#define int ll

const ll SZ = 1e6 + 10, INF = 1e9;
ll n, m, q;
vector<ll> vec;
ll cnt_all[SZ], cnt[SZ], nxt[SZ], pr[SZ];

signed main() {
    fastInp;

    cin >> n;

    vec.resize(n);
    ll ans = 0;
    for (auto& c : vec) cin >> c;

    multiset<ll> er;

    vector<ll> vec2;
    for (int i = 0; i < n; i++) {
        er.insert(vec[i]);
        vec2.push_back(vec[i]);
        cnt_all[vec[i]]++;
    }

    sort(vec2.begin(), vec2.end());
    auto it = unique(vec2.begin(), vec2.end());
    vec2.erase(it, vec2.end());

    for (int i = 0; i < vec2.size(); i++) {
        if (i > 0) {
            pr[vec2[i]] = vec2[i - 1];
        }
        if (i < vec2.size()) {
            nxt[vec2[i]] = vec2[i + 1];
        }
    }
    er.insert(INF);

    if (er.size() != n + 1) return 1;

    while (vec.size()) {
        ans++;
        ll cur = vec.back();
        vector<ll> ltr;
        ltr.push_back(cur);
        vec.pop_back();
        ll ths = 1;
        cnt[cur]++;
        while (vec.size() > 0) {
            if (vec.back() == cur) {
                ltr.push_back(vec.back());
                cur = vec.back();
                cnt[cur]++;
                vec.pop_back();
                continue;
            }
            ll q = nxt[vec.back()];
            if (vec.size() > 0 && q == cur && (ths == 1 || cnt[cur] == cnt_all[cur])) {
                ltr.push_back(vec.back());
                cur = vec.back();
                cnt[cur]++;
                vec.pop_back();
                ths++;
            } else {
                break;
            }
        }

        for (auto c : ltr) {
            if (cnt[c] == cnt_all[c]) {
                pr[nxt[c]] = pr[c];
                nxt[pr[c]] = nxt[c];
            }
        }
    }

    if (er.size() != 1) return 1;
    cout << ans;

    return 0;
}

Compilation message

money.cpp: In function 'int main()':
money.cpp:48:23: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     for (int i = 0; i < vec2.size(); i++) {
      |                     ~~^~~~~~~~~~~~~
money.cpp:52:15: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         if (i < vec2.size()) {
      |             ~~^~~~~~~~~~~~~
money.cpp:58:19: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   58 |     if (er.size() != n + 1) return 1;
      |         ~~~~~~~~~~^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 332 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 332 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 332 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 332 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -