Submission #855402

#TimeUsernameProblemLanguageResultExecution timeMemory
855402vjudge1Split the sequence (APIO14_sequence)C++17
0 / 100
2 ms856 KiB
#include <bits/stdc++.h> #pragma GCC optimize("unroll-loops") #pragma GCC optimize("Ofast") using namespace std; using lol= long long int; typedef long long ll; typedef long double ld; typedef long long unsigned lli; // #define _MAXM 16000 #define cl clear #define int ll #define db double #define pb push_back #define ers erase #define ds resize #define W INT_MIN #define mp make_pair #define pll pair< long , long > #define pii pair<ll, ll> #define bc back() mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count()); #define doc (clock() * 1.0 / CLOCKS_PER_SEC) < 1.0 #define all(v) v.begin(),v.end() const int MAX = 100 + 5; const int LOG = 18; const ll INF = 1e9 + 7; const ll inf = 1e18; const int maxn = 1e5+5; const double me = 1e-9; const double PI=acos(-1.0); const int M= 1e6; const int mod = 998244353; const int mxn=2e5+3; const int MAXA = 1e6 + 10; const int MOD = 1e9 + 7; const int DN = 4008; const int N = 1e5 + 123; int n, k; void kick(){ cin >> n >> k; vector< int > a(n+ 1); int sum = 0; for(int i = 1; i <= n; i++){ cin >> a[i]; sum += a[i]; a[i] += a[i - 1]; } k++; vector<vector<int>> dp(n + 1, vector<int>(k + 1, INF)); vector<vector<int>> par(n + 1, vector<int>(k + 1, -1)); dp[0][0] = 0; for (int i = 1; i <= n; i++){ for (int j = 1; j <= k; j++){ for (int i1 = 0; i1 < i; i1++){ int val = dp[i1][j - 1] + (a[i] - a[i1]) * (a[i] - a[i1]); if (val < dp[i][j]){ dp[i][j] = val; par[i][j] = i1; } } } } int res = (sum * sum) - (dp[n][k]); res /= 2; cout << res << '\n'; vector <int> ans; int i = n; while (par[i][k] != 0){ i = par[i][k]; k--; ans.push_back(i); } reverse(ans.begin(), ans.end()); for (auto x : ans){ cout << x << " "; } cout << '\n'; } signed main(){ #ifndef ONLINE_JUDGE freopen("input.in", "r" ,stdin); freopen("output.in", "w", stdout); #endif ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); int T = 1; // cin >> T; // cout.flush(); while(T--){ kick(); } return 0; }

Compilation message (stderr)

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