제출 #439943

#제출 시각아이디문제언어결과실행 시간메모리
439943dongliu0426Aliens (IOI16_aliens)C++14
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define N 300000 #define INF 0x3f3f3f3f3f3f3f3f int n, k, a[N + 1]; pair<long double, int> dp[N + 1][2]; template<class T, class U> T lastTrue(T lo, T hi, U f) { assert(lo <= hi); --lo; /* assuming f is decreasing */ while (lo < hi) { /* find last index such that f is true */ T mid = lo + (hi - lo + 1) / 2; f(mid) ? lo = mid : hi = mid - 1; } return lo; } int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; ++i) scanf("%d", a + i); auto check = [&](long double penalty) { dp[0][0] = {0, 0}, dp[0][1] = {-INF, 0}; for (int i = 1; i <= n; ++i) { pair<long double, int> last = max(dp[i - 1][0], dp[i - 1][1]); dp[i][0] = max(make_pair(last.first - penalty, last.second + 1), last); dp[i][1] = max(make_pair(dp[i - 1][1].first + a[i], dp[i - 1][1].second), make_pair(dp[i - 1][0].first + a[i] - penalty, dp[i - 1][0].second + 1)); } return max(dp[n][0], dp[n][1]).second >= k; }; long double lower = 0, upper = INF; for (int it = 0; it < 100; ++it) { long double mid = (lower + upper) / 2; if (check(mid)) { lower = mid; } else { upper = mid; } } long double penalty = lower; check(penalty); printf("%lld\n", (long long) round(penalty * k + max(dp[n][0], dp[n][1]).first)); }

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

aliens.cpp: In function 'int main()':
aliens.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |  scanf("%d%d", &n, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~
aliens.cpp:21:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |   scanf("%d", a + i);
      |   ~~~~~^~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccHJsvsq.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccSQWVzr.o:aliens.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccHJsvsq.o: in function `main':
grader.cpp:(.text.startup+0xf0): undefined reference to `take_photos(int, int, int, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status