제출 #501031

#제출 시각아이디문제언어결과실행 시간메모리
501031Ziel수열 (APIO14_sequence)C++17
50 / 100
2083 ms21560 KiB
/** * LES GREATEABLES BRO TEAM **/ #pragma GCC optimization("g", on) #pragma GCC optimize ("inline") #pragma GCC optimization("03") #pragma GCC optimization("unroll-loops") #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; using ll = long long; #define sz(x) (int)x.size() const bool FLAG = false; void setIO(const string &f = ""); #define int ll const ll INF = 1e17+456; int n, k; ll dp[210][100013], a[100013], p[100013], last[210][100013]; void solve() { cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; p[i] = p[i - 1] + a[i]; for (int j = 0; j <= k; j++) dp[j][i] = -1; } for (int i = 1; i <= n; i++) { dp[1][i] = p[i] * p[n] - p[i] * p[i]; last[1][i] = n + 1; } for (int j = 2; j <= k; j++) { for (int i = 1; i <= n; i++) { for (int ii = i + 1; ii <= n; ii++) { if (dp[j - 1][ii] - p[i] * p[i] + p[ii] * p[i] > dp[j][i]) { dp[j][i] = dp[j - 1][ii] - p[i] * p[i] + p[ii] * p[i]; last[j][i] = ii; } } } } ll ans = dp[k][1], cur = 1; for (int i = 2; i <= n; i++) if (ans < dp[k][i]) ans = dp[k][i], cur = i; cout << ans << '\n'; for (int i = k; i >= 1; i--) cout << cur << ' ', cur = last[i][cur]; } signed main() { setIO(); int tt = 1; if (FLAG) { cin >> tt; } while (tt--) { solve(); } return 0; } void setIO(const string &f) { ios_base::sync_with_stdio(false); cin.tie(nullptr); if (fopen((f + ".in").c_str(), "r")) { freopen((f + ".in").c_str(), "r", stdin); freopen((f + ".out").c_str(), "w", stdout); } }

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

sequence.cpp:5: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    5 | #pragma GCC optimization("g", on)
      | 
sequence.cpp:7: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    7 | #pragma GCC optimization("03")
      | 
sequence.cpp:8: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    8 | #pragma GCC optimization("unroll-loops")
      | 
sequence.cpp:9: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
    9 | #pragma comment(linker, "/stack:200000000")
      | 
sequence.cpp: In function 'void setIO(const string&)':
sequence.cpp:74:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |         freopen((f + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sequence.cpp:75:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |         freopen((f + ".out").c_str(), "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...