제출 #1265874

#제출 시각아이디문제언어결과실행 시간메모리
1265874minggaDischarging (NOI20_discharging)C++20
0 / 100
75 ms8260 KiB
// Author: caption_mingle #include "bits/stdc++.h" using namespace std; #define ln "\n" #define pb push_back #define fi first #define se second #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define ll long long const int mod = 1e9 + 7; const int inf = 2e9; const int N = 1e6 + 7; int n, a[N], dp[N]; double ite(pair<double, double> A, pair<double, double> B) { // cerr << A.fi << ' ' << A.se << ' ' << B.fi << ' ' << B.se << ln; return (B.se - A.se) / (A.fi - B.fi); } bool bad(pair<double, double> A, pair<double, double> B, pair<double, double> C) { return ite(A, B) >= ite(A, C); } signed main() { cin.tie(0) -> sync_with_stdio(0); #define task "" if(fopen(task ".INP", "r")) { freopen(task ".INP", "r", stdin); freopen(task ".OUT", "w", stdout); } cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]; vector<pair<double, double>> hull; hull.pb({n, 0}); int mx = 0; for(int i = 1; i <= n; i++) { mx = max(mx, a[i]); while(sz(hull) >= 2) { if(ite(hull[sz(hull) - 2], hull.back()) >= mx) hull.pop_back(); else break; } dp[i] = hull.back().fi * mx + hull.back().se; while(sz(hull) >= 2) { if(bad(hull[sz(hull) - 2], hull.back(), make_pair(n - i, dp[i]))) hull.pop_back(); else break; } hull.pb({n - i, dp[i]}); } cout << dp[n] << ln; cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC; }

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

Discharging.cpp: In function 'int main()':
Discharging.cpp:31:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |                 freopen(task ".INP", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Discharging.cpp:32:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |                 freopen(task ".OUT", "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...