結果
問題 | No.1117 数列分割 |
ユーザー | sak |
提出日時 | 2020-07-19 23:33:14 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,014 bytes |
コンパイル時間 | 2,259 ms |
コンパイル使用メモリ | 210,964 KB |
実行使用メモリ | 73,960 KB |
最終ジャッジ日時 | 2024-05-09 23:40:35 |
合計ジャッジ時間 | 7,257 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 24 ms
8,936 KB |
testcase_04 | AC | 18 ms
8,192 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 20 ms
7,724 KB |
testcase_09 | AC | 7 ms
5,376 KB |
testcase_10 | AC | 22 ms
7,808 KB |
testcase_11 | AC | 100 ms
21,760 KB |
testcase_12 | AC | 104 ms
23,168 KB |
testcase_13 | AC | 130 ms
30,980 KB |
testcase_14 | AC | 155 ms
32,128 KB |
testcase_15 | AC | 171 ms
39,156 KB |
testcase_16 | AC | 224 ms
43,776 KB |
testcase_17 | WA | - |
testcase_18 | AC | 284 ms
73,796 KB |
testcase_19 | AC | 428 ms
73,856 KB |
testcase_20 | AC | 188 ms
37,436 KB |
testcase_21 | AC | 424 ms
73,960 KB |
testcase_22 | AC | 421 ms
72,832 KB |
testcase_23 | AC | 419 ms
72,832 KB |
testcase_24 | AC | 421 ms
71,808 KB |
testcase_25 | AC | 410 ms
71,708 KB |
testcase_26 | AC | 2 ms
5,376 KB |
testcase_27 | WA | - |
testcase_28 | WA | - |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> p_ll; template<class T> void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; } #define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++) #define all(vec) vec.begin(), vec.end() #define rep(i,N) repr(i,0,N) #define per(i,N) for (int i=(int)N-1; i>=0; i--) const ll MOD = pow(10,9)+7; const ll LLINF = pow(2,61)-1; const int INF = pow(2,30)-1; vector<ll> fac; void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; } ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; } ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; } ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); } ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } int main() { ll N, K, M; cin >> N >> K >> M; ll A[N]; rep(i,N) cin >> A[i]; ll sum[N+1] = {}; rep(i,N) sum[i+1] = sum[i] + A[i]; ll dp[N+1][K+1] = {}; rep(i,N+1) rep(j,K+1) dp[i][j] = -1*100; dp[0][0] = 0; repr(j,1,K+1) { deque<ll> deq1, deq2; repr(i,1,N+1) { if (deq1.size()&&deq1.front()<=(i-1)-M) deq1.pop_front(); while (deq1.size()&&(dp[deq1.back()][j-1]-sum[deq1.back()]<dp[i-1][j-1]-sum[i-1])) deq1.pop_back(); deq1.push_back(i-1); if (deq2.size()&&deq2.front()<=(i-1)-M) deq2.pop_front(); while (deq2.size()&&(dp[deq2.back()][j-1]+sum[deq2.back()]<dp[i-1][j-1]+sum[i-1])) deq2.pop_back(); deq2.push_back(i-1); dp[i][j] = max(dp[i][j], dp[deq1.front()][j-1]-sum[deq1.front()] + sum[i]); dp[i][j] = max(dp[i][j], dp[deq2.front()][j-1]+sum[deq2.front()] - sum[i]); // cout << i << "," << j << endl; // for (auto x: deq1) cout << x << " "; cout << endl; } } // rep(j,K+1) { rep(i,N+1) cout << dp[i][j] << " "; cout << endl; } ll result = dp[N][K]; cout << result << endl; return 0; }