제출 #707428

#제출 시각아이디문제언어결과실행 시간메모리
707428DennisTran수열 (APIO14_sequence)C++17
0 / 100
11 ms4436 KiB
#include <bits/stdc++.h> #define FOR(i, x, y) for (int i = x; i < y; i++) typedef long long ll; using namespace std; int n, k; int where[201][100001]; ll pref[100001]{0}, dp[2][100001], q[100001], l = 1, r = 1; bool case1(int x, int y, int i) { return (dp[0][y] - dp[0][x] >= (pref[y] - pref[x]) * (pref[n] - pref[i])); } bool case2(int x, int y, int i) { return ((dp[0][y] - dp[0][x]) * (pref[i] - pref[y]) <= (dp[0][i] - dp[0][y]) * (pref[y] - pref[x])); } #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".ans", "w", stdout); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); file("TASK"); cin >> n >> k; FOR(i, 1, n + 1) { int x; cin >> x; pref[i] = pref[i - 1] + x; } fill(dp[0], dp[0] + n + 1, 0); FOR(i, 1, k + 1) { q[r++] = 0; FOR(j, 1, n + 1) { while (r - l > 1 && case1(q[l], q[l + 1], j)) l++; ll x = q[l]; dp[1][j] = dp[0][x] + (pref[j] - pref[x]) * (pref[n] - pref[j]); where[i][j] = x; while (r - l > 1 && case2(q[r - 2], q[r - 1], j)) r--; q[r++] = j; } l = r = 1; FOR(j, 1, n + 1) dp[0][j] = dp[1][j]; } ll mx = -1; int indx = -1; FOR(i, 1, n + 1) { if (dp[0][i] > mx) mx = dp[0][i], indx = i; } cout << mx << '\n'; return 0; }

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

sequence.cpp: In function 'int main()':
sequence.cpp:49:6: warning: variable 'indx' set but not used [-Wunused-but-set-variable]
   49 |  int indx = -1;
      |      ^~~~
sequence.cpp:18:58: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 | #define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".ans", "w", stdout); }
      |                                                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sequence.cpp:23:2: note: in expansion of macro 'file'
   23 |  file("TASK");
      |  ^~~~
sequence.cpp:18:91: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 | #define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".ans", "w", stdout); }
      |                                                                                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sequence.cpp:23:2: note: in expansion of macro 'file'
   23 |  file("TASK");
      |  ^~~~
#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...