제출 #575905

#제출 시각아이디문제언어결과실행 시간메모리
575905JovanBDischarging (NOI20_discharging)C++17
0 / 100
2 ms596 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; } ll intersect(line h){ return floor((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)){ dq.push_back(a); dq.push_back(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; freopen("input.txt", "r", stdin); 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:63: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]
   63 |     for(int i=0; i<vec.size(); i++){
      |                  ~^~~~~~~~~~~
Discharging.cpp:49:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |     freopen("input.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...