Submission #1106863

#TimeUsernameProblemLanguageResultExecution timeMemory
1106863InvMODSplit the sequence (APIO14_sequence)C++14
0 / 100
2037 ms2368 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define gcd __gcd #define sz(v) (int) v.size() #define pb push_back #define pi pair<int,int> #define all(v) (v).begin(), (v).end() #define compact(v) (v).erase(unique(all(v)), (v).end()) #define FOR(i, a, b) for(int i = (a); i <= (b); i++) #define dbg(x) "[" #x " = " << (x) << "]" ///#define int long long using ll = long long; using ld = long double; using ull = unsigned long long; template<typename T> bool ckmx(T& a, const T& b){if(a < b) return a = b, true; return false;} template<typename T> bool ckmn(T& a, const T& b){if(a > b) return a = b, true; return false;} const int N = 1e5+5; const int K = 2e2+5; ll n, k, a[N], pref[N], dp[K][N]; namespace Brute{ const int N = 1e3+5; ll dp[K][N]; void process() { for(int i = 1; i <= n; i++){ dp[0][i] = 0; for(int j = 1; j <= k; j++){ for(int x = j+1; x <= i; x++){ dp[j][i] = max(dp[j][i], dp[j-1][x-1] + (pref[i] - pref[x-1]) * pref[x-1]); } } } cout << dp[k][n] <<"\n"; return; } } void solve() { cin >> n >> k; for(int i = 1; i <= n; i++){ cin >> a[i]; pref[i] = a[i] + pref[i-1]; } Brute::process(); } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define name "InvMOD" if(fopen(name".INP", "r")){ freopen(name".INP","r",stdin); freopen(name".OUT","w",stdout); } int t = 1; //cin >> t; while(t--) solve(); return 0; }

Compilation message (stderr)

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