Submission #1047654

#TimeUsernameProblemLanguageResultExecution timeMemory
1047654dilanyanText editor (CEOI24_editor)C++17
0 / 100
8 ms47708 KiB
//-------------dilanyan------------\\ #define _CRT_SECURE_NO_WARNINGS #include<bits/stdc++.h> #include<stdio.h> using namespace std; //------------------Kargpefines--------------------\\ #define ll long long #define pb push_back #define all(u) (u).begin(), (u).end() #define pqueue priority_queue #define upper upper_bound #define lower lower_bound #define umap unordered_map #define uset unordered_set void KarginSet(string name = "") { ios_base::sync_with_stdio(false); cin.tie(NULL); if (name.size()) { freopen((name + ".in").c_str(), "r", stdin); freopen((name + ".out").c_str(), "w", stdout); } } //-------------------KarginConstants------------------\\ const ll mod = 1e9 + 7; const ll inf = 2e9; //-------------------KarginCode-----------------------\\ const int N = 2000005, M = 1000005; int l[N]; vector<pair<int, ll>> g[N]; void KarginSolve() { int n, sl, sc, el, ec; cin >> n >> sl >> sc >> el >> ec; sc--, ec--; for (int i = 1;i <= n;i++) cin >> l[i]; if (el == n) { cout << el - sl << '\n'; } for (int i = 2;i <= n;i++) { g[i].pb({ i - 1,1 }), g[i - 1].pb({ i,1 }); } stack<int> st; for (int i = 1; i <= n;i++) { while (!st.empty() && l[st.top()] > l[i]) st.pop(); if (!st.empty()) { g[n + i].pb({ n + st.top(),i - st.top() }); } st.push(i); } while (!st.empty()) st.pop(); for (int i = n;i >= 1;i--) { while (!st.empty() && l[st.top()] > l[i]) st.pop(); if (!st.empty()) { g[n + i].pb({ n + st.top(),st.top() - i }); } st.push(i); } for (int i = 1;i < n;i++) { g[i + 1].pb({ n + i,1 }); g[n + i].pb({ i + 1,1 }); } pqueue<pair<ll, int>> pq; vector<ll> d(2 * n + 1, inf); vector<bool> vis(2 * n + 1, false); pq.push({ -sc,sl }); d[sl] = sc; for (int i = sl;i <= n;i++) { if (l[i] < sc) break; pq.push({ -(l[i] - sc + i - sl), n + i}); d[n + i] = l[i] - sc + i - sl; } for (int i = sl - 1;i >= 1;i--) { if (l[i] < sc) break; pq.push({ -(l[i] - sc + sl - i), n + i }); d[n + i] = l[i] - sc + sl - i; } while (!pq.empty()) { int u = pq.top().second; pq.pop(); if (vis[u]) continue; vis[u] = true; for (auto it : g[u]) { int v = it.first, w = it.second; if (d[v] > d[u] + w) { d[v] = d[u] + w; pq.push({ -d[v], v }); } } } ll ans = inf; for (int i = 1;i < 2 * n;i++) { //cout << i << ' ' << d[i] << '\n'; if (i <= n) ans = min(ans, d[i] + ec + abs(i - el)); else ans = min(ans, l[i - n] - ec + d[i] + abs(i - n - el)); } cout << ans << '\n'; } int main() { KarginSet(); int test = 1; //cin >> test; while (test--) { KarginSolve(); } return 0; }

Compilation message (stderr)

Main.cpp:1:1: warning: multi-line comment [-Wcomment]
    1 | //-------------dilanyan------------\\
      | ^
Main.cpp:8:1: warning: multi-line comment [-Wcomment]
    8 | //------------------Kargpefines--------------------\\
      | ^
Main.cpp:27:1: warning: multi-line comment [-Wcomment]
   27 | //-------------------KarginConstants------------------\\
      | ^
Main.cpp:32:1: warning: multi-line comment [-Wcomment]
   32 | //-------------------KarginCode-----------------------\\
      | ^
Main.cpp: In function 'void KarginSet(std::string)':
Main.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         freopen((name + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         freopen((name + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...