Submission #839191

#TimeUsernameProblemLanguageResultExecution timeMemory
839191anha3k25cvpZalmoxis (BOI18_zalmoxis)C++14
70 / 100
488 ms69072 KiB
#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_ = n; n += k; for (int i = 1; i <= cnt; i ++) { if (a[pos] == mi && pos > n_) { int x = n - cnt + 1, k = 0; for (; (1 << k) < x; k ++); a[pos] -= k; int y = (1 << k) - x; for (int j = 1; j <= x; j ++) if (j <= y) cout << a[pos] + 1 << ' '; else cout << a[pos] << ' '; n = cnt; } else cout << a[pos] << ' '; pos = c[pos]; } return 0; }

Compilation message (stderr)

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);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...