제출 #575903

#제출 시각아이디문제언어결과실행 시간메모리
575903JovanBDischarging (NOI20_discharging)C++17
20 / 100
114 ms8212 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const int N = 1000000; const ll INF = 1000000000000000000LL; ll a[N+5]; ll dp[N+5]; struct line{ ll k, n; ll eval(int x){ return k*x + n; } ld intersect(line h){ return (ld)(n - h.n)/(h.k - k); } }; deque <line> dq; void dodaj(line g){ while(dq.size() >= 2){ line b = dq.back(); dq.pop_back(); line a = dq.back(); dq.pop_back(); if(a.intersect(g) > a.intersect(b)) break; dq.push_back(a); } dq.push_back(g); } ll query(int x){ while(dq.size() >= 2 && dq[0].eval(x) >= dq[1].eval(x)) dq.pop_front(); return dq.front().eval(x); } int main(){ ios_base::sync_with_stdio(false), cin.tie(0); cout.precision(10); cout << fixed; int n; cin >> n; for(int i=1; i<=n; i++){ cin >> a[i]; } reverse(a+1, a+1+n); vector <pair <int, int>> vec; for(int i=n; i>=1; i--){ if(vec.empty() || vec.back().second < a[i]){ vec.push_back({i, a[i]}); } } reverse(vec.begin(), vec.end()); for(int i=0; i<vec.size(); i++){ int id, h; tie(id, h) = vec[i]; line g; g.k = a[id]; g.n = 0; if(i) g.n = dp[i-1]; dodaj(g); dp[i] = query(id); } cout << dp[vec.size() - 1] << "\n"; return 0; }

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

Discharging.cpp: In function 'int main()':
Discharging.cpp:58:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |     for(int i=0; i<vec.size(); 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...