제출 #869316

#제출 시각아이디문제언어결과실행 시간메모리
869316prohacker수열 (APIO14_sequence)C++14
28 / 100
147 ms5464 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double using namespace std; const int N = 1010; const int INF = INT_MAX; const int mod = 1e9+7; int n,m; ll dp[N][210],ans; int s[N],trace[N][210]; stack<int> st; int get(int l, int r) { return s[r] - s[l-1]; } signed main() { if (fopen("task.inp", "r")) { freopen("task.inp", "r", stdin); freopen("task.out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for(int i = 1 ; i <= n ; i++) { int x; cin >> x; s[i] = s[i-1] + x; } s[n+1] = s[n]; for(int k = 1 ; k <= m+1 ; k++) { for(int i = 1 ; i <= n ; i++) { for(int j = 0 ; j < i ; j++) { if(dp[j][k-1]+1LL*(s[i]-s[j])*(s[n]-s[i]) > dp[i][k]) { dp[i][k] = dp[j][k-1]+1LL*(s[i]-s[j])*(s[n]-s[i]); trace[i][k] = j; } } } } cout << dp[n][m+1] << '\n'; while(m+1 > 1) { n = trace[n][m+1]; cout << n << " "; // st.push(n); m--; } // while(!st.empty()) { // cout << st.top() << " "; // st.pop(); // } return 0; }

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

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