제출 #1124374

#제출 시각아이디문제언어결과실행 시간메모리
1124374tuannmSafety (NOI18_safety)C++20
100 / 100
44 ms4452 KiB
#include<bits/stdc++.h> #define ii pair<int, int> #define ll pair<long long, long long> #define fi first #define se second #define pb push_back using namespace std; const int mod[2] = {1000000007, 998244353}; const int N = 2e5 + 1; const string NAME = ""; int n, h, s[N]; void inp(){ cin >> n >> h; for(int i = 1; i <= n; ++i) cin >> s[i]; } void solve(){ priority_queue<long long> pqL, pqR; long long ans = 0; pqL.push(s[1]); pqR.push(-s[1]); for(int i = 2; i <= n; ++i){ long long cost = 1LL * h * (i - 1); long long leftBound = pqL.top() - cost; long long rightBound = cost - pqR.top(); if(s[i] < leftBound){ pqL.push(cost + s[i]); pqL.push(cost + s[i]); pqL.pop(); pqR.push(cost - leftBound); ans += abs(leftBound - s[i]); } else if(s[i] > rightBound){ pqR.push(cost - s[i]); pqR.push(cost - s[i]); pqR.pop(); pqL.push(cost + rightBound); ans += abs(rightBound - s[i]); } else{ pqL.push(cost + s[i]); pqR.push(cost - s[i]); } } cout << ans; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen((NAME + ".inp").c_str(), "r")){ freopen((NAME + ".inp").c_str(), "r", stdin); freopen((NAME + ".out").c_str(), "w", stdout); } inp(); solve(); }

컴파일 시 표준 에러 (stderr) 메시지

safety.cpp: In function 'int main()':
safety.cpp:63:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         freopen((NAME + ".inp").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
safety.cpp:64:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |         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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...