結果
| 問題 |
No.1117 数列分割
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-07-17 22:23:39 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,246 bytes |
| コンパイル時間 | 1,836 ms |
| コンパイル使用メモリ | 172,296 KB |
| 実行使用メモリ | 93,056 KB |
| 最終ジャッジ日時 | 2024-11-30 03:31:11 |
| 合計ジャッジ時間 | 44,088 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 15 WA * 3 TLE * 8 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i ++)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;
struct Debug {
template<class T> static void print_value(T value,const char* name) {
cout << name << ": " << value << '\n';
}
template<class T> static void print_vector(vector<T> &vec,const char* name) {
for (int i = 0;i < vec.size();++i) {
cout << " " << name;
printf("[%d]: ",i);
cout << vec[i];
}
cout << '\n';
}
template<class T> static void print_2dvector(vector<vector<T>> &vec,const char* name) {
for (int i = 0;i < vec.size();++i) {
for (int j = 0;j < vec[i].size();++j) {
cout << " " << name;
printf("[%d][%d]: ",i,j);
cout << vec[i][j];
}
cout << '\n';
}
}
template<class T> static void print_set(set<T> &st,const char* name) {
int i = 0;
for (auto itr = st.begin();itr != st.end(); ++itr,++i) {
cout << " " << name;
printf("[%d]: ",i);
cout << *itr;
}
cout << '\n';
}
template<class T1,class T2>
static void print_map(map<T1,T2> &mp,const char* name) {
for (auto p: mp) {
cout << " " << name << '[' << p.first << ']' << ": " << p.second;
}
cout << '\n';
}
};
int main() {
int N,K,M; cin >> N >> K >> M;
vector<ll> A(N + 1);
rep(i,N) cin >> A[i + 1];
rep(i,N) A[i + 1] += A[i];
vector<vector<ll>> dp(K + 1,vector<ll>(N + 1,0));
rep(i,N) dp[1][i + 1] = abs(A[i + 1] - A[0]);
for (int i = 1;i < K;++i){
rep(j,N) {
for (int k = max(j - M,0);k <= j;++k) {
dp[i + 1][j + 1] = max(dp[i + 1][j + 1],dp[i][k] + abs(A[j + 1] - A[k]));
}
}
}
//Debug::print_vector(A,"A");
//Debug::print_2dvector(dp,"dp");
cout << dp.back().back() << '\n';
return 0;
}