제출 #1046614

#제출 시각아이디문제언어결과실행 시간메모리
1046614vanea수열 (APIO14_sequence)C++14
0 / 100
16 ms131072 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { freopen("sequence.in", "r", stdin); freopen("sequence.out", "w", stdout); int n, k; cin >> n >> k; vector<ll> v(n+1); for(int i = 1; i <= n; i++) { cin >> v[i]; } vector<ll> pref(n+1), suf(n+2); for(int i = 1; i <= n; i++) { pref[i] = pref[i-1]+v[i]; } for(int i = n; i>=1; i--) { suf[i] = suf[i+1]+v[i]; } vector<vector<array<ll, 2>>> dp(n+1, vector<array<ll, 2>>(k+1)); ll ans = 0; for(int i = 1; i < n; i++) { for(int j = 1; j <= min(k, i); j++) { array<ll, 2> f = dp[i-1][j]; f[1]+=v[i]; array<ll, 2> s = dp[i-1][j-1]; s[1] += v[i]; s[0] += (s[1] * suf[i+1]); s[1] = 0; dp[i][j] = max(f, s); ans = max(ans, dp[i][j][0]); } } cout << ans; return 0; }

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

sequence.cpp: In function 'int main()':
sequence.cpp:7:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |     freopen("sequence.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
sequence.cpp:8:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |     freopen("sequence.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...