제출 #196909

#제출 시각아이디문제언어결과실행 시간메모리
196909quocnguyen1012수열 (APIO14_sequence)C++14
0 / 100
2015 ms61656 KiB
#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back

using namespace std;
typedef long long ll;

const int maxn = 1e5 + 5;

ll f[maxn][205];
int N, a[maxn], K;
int trace[maxn][205];
ll sum[maxn];

bool Max(ll & a, ll b)
{
  if (a < b){
    a = b;
    return true;
  }
  return false;
}

signed main(void)
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  if (fopen("A.INP", "r")){
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  }
  cin >> N >> K;
  for (int i = 1; i <= N; ++i){
    cin >> a[i];
    sum[i] = sum[i - 1] + a[i];
  }
  for (int j = 1; j <= K; ++j){
    for (int i = 1; i <= N; ++i){
      for (int k = 0; k < i; ++k){
        if(Max(f[i][j], f[k][j - 1] + 1ll * (sum[i] - sum[k]) * sum[k])){
          trace[i][j] = k;
        }
      }
    }
  }
  cout << f[N][K] << '\n';
  vector<int> need;
  for (int i = K; i >= 1; --i){
    need.pb(trace[N][i]);
    N = trace[N][i];
  }
  cout << need.size() << '\n';
  for (auto it : need) cout << it << ' ';
}

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

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