Submission #337130

#TimeUsernameProblemLanguageResultExecution timeMemory
337130bigDuckSplit the sequence (APIO14_sequence)C++14
0 / 100
55 ms9136 KiB
#include<bits/stdc++.h> using namespace std; #define INIT ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define mp make_pair #define pb push_back #define ft first #define sc second #define ll long long #define pii pair<int, int> #define count_bits __builtin_popcount #define int ll int t, n, m, k, a[300010], q, l, r; int dp[1010][210]; int p[1010]; int32_t main(){ INIT scanf("%d", &n); scanf("%d" , &k); for(int i=1; i<=n ;i++){ scanf("%d", &a[i]); p[i]=p[i-1]+a[i]; } dp[0][0]=0; k++; for(int i=1; i<=n; i++){ for(int g=0; g<=k; g++){ dp[i][g]=-1; } for(int j=i-1; j>=0; j--){ for(int g=0; g<k; g++){ if(dp[j][g]==-1){continue;} if(dp[i][g+1]==(-1)){ dp[i][g+1]=dp[j][g]+(p[i]-p[j])*(p[i]-p[j]); } else{ dp[i][g+1]=min(dp[i][g+1], dp[j][g]+(p[i]-p[j])*(p[i]-p[j])); } } } } printf("%d", ( ((p[n]*p[n])-dp[n][k])/2 )); return 0; }

Compilation message (stderr)

sequence.cpp: In function 'int32_t main()':
sequence.cpp:22:9: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   22 | scanf("%d", &n);
      |        ~^   ~~
      |         |   |
      |         |   long long int*
      |         int*
      |        %lld
sequence.cpp:23:9: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   23 | scanf("%d" , &k);
      |        ~^    ~~
      |         |    |
      |         int* long long int*
      |        %lld
sequence.cpp:25:13: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   25 |     scanf("%d", &a[i]);
      |            ~^   ~~~~~
      |             |   |
      |             |   long long int*
      |             int*
      |            %lld
sequence.cpp:49:10: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
   49 | printf("%d", ( ((p[n]*p[n])-dp[n][k])/2   ));
      |         ~^   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |          |                           |
      |          int                         long long int
      |         %lld
sequence.cpp:22:6: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   22 | scanf("%d", &n);
      | ~~~~~^~~~~~~~~~
sequence.cpp:23:6: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   23 | scanf("%d" , &k);
      | ~~~~~^~~~~~~~~~~
sequence.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   25 |     scanf("%d", &a[i]);
      |     ~~~~~^~~~~~~~~~~~~
#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...