답안 #838696

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
838696 2023-08-27T15:21:04 Z anha3k25cvp Zalmoxis (BOI18_zalmoxis) C++14
55 / 100
486 ms 71092 KB
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define dl double
#define st first
#define nd second
#define II pair <int, int>

using namespace std;

const int N = 5 + 1e5;
const int inf = 7 + 1e9;

int main() {
#define TASKNAME ""
    ios_base :: sync_with_stdio (0);
    cin.tie (0);
    if ( fopen( TASKNAME".inp", "r" ) ) {
        freopen (TASKNAME".inp", "r", stdin);
        freopen (TASKNAME".out", "w", stdout);
    }
    int n, k;
    cin >> n >> k;
    vector <int> a(n + k + 1, 0), nex(n + 1, 0), last(n + 1, 0);
    set <II> q;
    int mi = inf;
    for (int i = 1; i <= n; i ++) {
        cin >> a[i];
        mi = min(mi, a[i]);
        q.insert({a[i], i});
        last[i] = i;
        if (i < n)
            nex[i] = i + 1;
    }
    int cnt = n;
    vector <int> c(n + k + 1, 0), b = a;
    while (!q.empty()) {
        int val = q.begin() -> st, u = q.begin() -> nd;
        q.erase(q.begin());
        if (val == 30)
            break;
        int v = nex[u];
        if (v && b[v] == b[u]) {
            q.erase(q.begin());
            c[last[u]] = v;
            last[u] = last[v];
            nex[u] = nex[v];
            q.insert({b[u] = val + 1, u});
        }
        else {
            a[++ cnt] = val;
            c[last[u]] = cnt;
            last[u] = cnt;
            q.insert({b[u] = val + 1, u});
        }
    }
    int pos = 1;
    n += k;
    for (int i = 1; i <= cnt; i ++) {
        if (a[pos] == mi) {
            int val = mi;
            while (n > cnt) {
                val --;
                cout << val << ' ';
                n --;
            }
            cout << val << ' ';
        }
        else
            cout << a[pos] << ' ';
        pos = c[pos];
    }
    return 0;
}

Compilation message

zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:19:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         freopen (TASKNAME".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
zalmoxis.cpp:20:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen (TASKNAME".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 448 ms 70956 KB Output is correct
2 Correct 475 ms 70900 KB Output is correct
3 Correct 464 ms 70988 KB Output is correct
4 Correct 462 ms 71044 KB Output is correct
5 Correct 468 ms 70960 KB Output is correct
6 Correct 473 ms 71092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 469 ms 70884 KB doesn't contain S as a subsequence
2 Correct 447 ms 70896 KB Output is correct
3 Incorrect 462 ms 70864 KB doesn't contain S as a subsequence
4 Incorrect 465 ms 70928 KB doesn't contain S as a subsequence
5 Incorrect 460 ms 70960 KB doesn't contain S as a subsequence
6 Incorrect 457 ms 70952 KB doesn't contain S as a subsequence
7 Incorrect 486 ms 70956 KB doesn't contain S as a subsequence
8 Incorrect 462 ms 71052 KB doesn't contain S as a subsequence
9 Correct 397 ms 59960 KB Output is correct
10 Incorrect 186 ms 34500 KB doesn't contain S as a subsequence
11 Incorrect 279 ms 44364 KB doesn't contain S as a subsequence
12 Correct 60 ms 19876 KB Output is correct
13 Correct 62 ms 20044 KB Output is correct
14 Correct 63 ms 19960 KB Output is correct