제출 #1289505

#제출 시각아이디문제언어결과실행 시간메모리
1289505ArtFeast (NOI19_feast)C++17
18 / 100
66 ms10916 KiB
// - Art - #include <bits/stdc++.h> #define el cout << '\n' #define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i) #define REV(i, b, a) for (int i = (b), _a = (a); i >= _a; --i) #define REP(i, c) for (int i = 0, _c = (c); i < _c; ++i) const int N = 3e5 + 7; using namespace std; int n, k, a[N]; pair<long long, int> best(pair<long long, int> a, pair<long long, int> b) { auto &[v1, c1] = a; auto &[v2, c2] = b; if (v1 > v2) { return a; } else if (v1 < v2) { return b; } return {v1, min(c1, c2)}; } pair<long long, int> dp[N][2]; // first: val, second: cnt pair<long long, int> Lagrangian(long long lamda) { dp[0][0] = {0, 0}; dp[0][1] = {-1e18, 0}; /// Lỗi 1: không khởi gán FOR (i, 1, n) { dp[i][0] = best(dp[i - 1][0], dp[i - 1][1]); dp[i][1] = best(make_pair(dp[i - 1][0].first + a[i] - lamda, dp[i - 1][0].second + 1), /// đoạn mới -> chịu phạt make_pair(dp[i - 1][1].first + a[i], dp[i - 1][1].second)); } return best(dp[n][0], dp[n][1]); } int main() { #define name "art" if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> k; FOR (i, 1, n) { cin >> a[i]; } long long l = 0, r = 3e13, lamda = 3e13; while (l <= r) { long long m = l + (r - l) / 2; if (Lagrangian(m).second >= k) { l = m + 1; lamda = m; } else { r = m - 1; } } cout << Lagrangian(lamda).first + lamda * k, el; return 0; }

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

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