Submission #422909

#TimeUsernameProblemLanguageResultExecution timeMemory
422909maomao90Safety (NOI18_safety)C++17
100 / 100
71 ms6260 KiB
#include <bits/stdc++.h> using namespace std; template <class T> inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;} template <class T> inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;} #define REP(i, s, e) for (int i = s; i < e; i++) #define RREP(i, s, e) for (int i = s; i >= e; i--) typedef long long ll; typedef long double ld; #define MP make_pair #define FI first #define SE second typedef pair<int, int> ii; typedef pair<ll, ll> pll; #define MT make_tuple typedef tuple<int, int, int> iii; #define ALL(_a) _a.begin(), _a.end() #define pb emplace_back typedef vector<int> vi; typedef vector<ll> vll; typedef vector<ii> vii; #define INF 1000000005 #define LINF 1000000000000000005 #define MOD 1000000007 #define MAXN 200005 int n, h; int s[MAXN]; priority_queue<ll> lft; priority_queue<ll, vll, greater<ll>> rht; ll c; ll lazy; int main() { scanf("%d%d", &n, &h); REP (i, 0, n) { scanf("%d", &s[i]); } rht.push(s[0]); lft.push(s[0]); REP (i, 1, n) { lazy += h; ll lv = lft.top() - lazy, rv = rht.top() + lazy; if (s[i] >= lv && s[i] <= rv) { lft.push(s[i] + lazy); rht.push(s[i] - lazy); } else if (s[i] < lv) { lft.pop(); lft.push(s[i] + lazy); lft.push(s[i] + lazy); c += lv - s[i]; rht.push(lv - lazy); } else { rht.pop(); rht.push(s[i] - lazy); rht.push(s[i] - lazy); c += s[i] - rv; lft.push(rv + lazy); } //printf(" %lld\n", c); //auto tmp = lft; //while (!tmp.empty()) { //printf("%lld\n", tmp.top() - lazy); tmp.pop(); //} //printf("\n"); //auto tmpp = rht; //while (!tmpp.empty()) { //printf("%lld\n", tmpp.top() + lazy); tmpp.pop(); //} //printf("\n"); } printf("%lld\n", c); return 0; }

Compilation message (stderr)

safety.cpp: In function 'int main()':
safety.cpp:38:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |  scanf("%d%d", &n, &h);
      |  ~~~~~^~~~~~~~~~~~~~~~
safety.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |   scanf("%d", &s[i]);
      |   ~~~~~^~~~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...