제출 #1073035

#제출 시각아이디문제언어결과실행 시간메모리
1073035KasymK수열 (APIO14_sequence)C++17
11 / 100
116 ms2800 KiB
#include "bits/stdc++.h" using namespace std; #define ff first #define ss second #define all(v) v.begin(), v.end() #define ll long long #define pb push_back #define pii pair<int, int> #define pli pair<ll, int> #define wr puts("----------------") template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;} template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;} const int N = 1005; const int K = 205; int v[N], par[N], id[N][K]; ll dp[N][K]; int main(){ // freopen("file.txt", "r", stdin); int n, k; scanf("%d%d", &n, &k); for(int i = 1; i <= n; ++i){ int x; scanf("%d", &x); v[i] = x; } for(int i = 1; i <= n; ++i) par[i] = par[i-1]+v[i]; for(int i = 1; i <= n; ++i) for(int j = 0; j < i; ++j) for(int x = 1; x <= min(k, i); ++x) if(umax(dp[i][x], dp[j][x-1]+(par[i]-par[j])*(par[n]-par[i]))) id[i][x] = j; ll answer = 0; for(int i = 1; i <= n; ++i) umax(answer, dp[i][k]); int d = 0, x = k; for(int i = 1; i <= n; ++i) if(dp[i][k] == answer){ d = i; break; } vector<int> A; while(x){ A.pb(d); d = id[d][x]; --x; } for(int &i : A) if(i == 0) i = 1; printf("%lld\n", answer); for(int i = k-1; i >= 0; --i) printf("%d ", A[i]); puts(""); return 0; }

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

sequence.cpp: In function 'int main()':
sequence.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |     scanf("%d%d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~
sequence.cpp:24:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         scanf("%d", &x);
      |         ~~~~~^~~~~~~~~~
#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...