結果
問題 | No.2423 Merge Stones |
ユーザー | shobonvip |
提出日時 | 2023-08-12 15:20:59 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 3,298 ms / 4,000 ms |
コード長 | 2,176 bytes |
コンパイル時間 | 3,338 ms |
コンパイル使用メモリ | 224,936 KB |
実行使用メモリ | 28,252 KB |
最終ジャッジ日時 | 2024-11-20 01:38:59 |
合計ジャッジ時間 | 118,745 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 7 ms
26,116 KB |
testcase_01 | AC | 7 ms
26,136 KB |
testcase_02 | AC | 7 ms
26,000 KB |
testcase_03 | AC | 7 ms
26,020 KB |
testcase_04 | AC | 6 ms
25,976 KB |
testcase_05 | AC | 7 ms
25,996 KB |
testcase_06 | AC | 7 ms
26,008 KB |
testcase_07 | AC | 7 ms
28,144 KB |
testcase_08 | AC | 7 ms
26,016 KB |
testcase_09 | AC | 7 ms
26,136 KB |
testcase_10 | AC | 8 ms
26,108 KB |
testcase_11 | AC | 589 ms
27,260 KB |
testcase_12 | AC | 2,082 ms
27,452 KB |
testcase_13 | AC | 2,107 ms
27,084 KB |
testcase_14 | AC | 2,096 ms
27,136 KB |
testcase_15 | AC | 2,081 ms
27,212 KB |
testcase_16 | AC | 2,010 ms
27,316 KB |
testcase_17 | AC | 2,026 ms
27,180 KB |
testcase_18 | AC | 2,129 ms
27,412 KB |
testcase_19 | AC | 2,108 ms
27,176 KB |
testcase_20 | AC | 2,117 ms
27,100 KB |
testcase_21 | AC | 2,133 ms
27,192 KB |
testcase_22 | AC | 2,112 ms
27,156 KB |
testcase_23 | AC | 2,113 ms
27,172 KB |
testcase_24 | AC | 2,091 ms
27,096 KB |
testcase_25 | AC | 2,014 ms
27,200 KB |
testcase_26 | AC | 2,016 ms
27,296 KB |
testcase_27 | AC | 2,063 ms
27,284 KB |
testcase_28 | AC | 1,983 ms
27,136 KB |
testcase_29 | AC | 2,119 ms
27,240 KB |
testcase_30 | AC | 2,096 ms
27,100 KB |
testcase_31 | AC | 2,095 ms
27,124 KB |
testcase_32 | AC | 2,078 ms
28,252 KB |
testcase_33 | AC | 2,011 ms
27,552 KB |
testcase_34 | AC | 2,102 ms
27,584 KB |
testcase_35 | AC | 2,056 ms
27,260 KB |
testcase_36 | AC | 2,060 ms
27,140 KB |
testcase_37 | AC | 2,069 ms
27,196 KB |
testcase_38 | AC | 2,092 ms
27,068 KB |
testcase_39 | AC | 2,124 ms
27,100 KB |
testcase_40 | AC | 2,077 ms
27,368 KB |
testcase_41 | AC | 2,022 ms
27,192 KB |
testcase_42 | AC | 2,027 ms
27,684 KB |
testcase_43 | AC | 2,199 ms
27,232 KB |
testcase_44 | AC | 2,046 ms
27,292 KB |
testcase_45 | AC | 2,147 ms
27,148 KB |
testcase_46 | AC | 2,111 ms
27,096 KB |
testcase_47 | AC | 2,044 ms
27,132 KB |
testcase_48 | AC | 2,072 ms
27,260 KB |
testcase_49 | AC | 2,112 ms
27,104 KB |
testcase_50 | AC | 2,023 ms
27,184 KB |
testcase_51 | AC | 1,595 ms
27,132 KB |
testcase_52 | AC | 1,570 ms
27,128 KB |
testcase_53 | AC | 1,586 ms
27,220 KB |
testcase_54 | AC | 1,569 ms
27,408 KB |
testcase_55 | AC | 1,625 ms
27,276 KB |
testcase_56 | AC | 2,125 ms
27,128 KB |
testcase_57 | AC | 2,072 ms
27,216 KB |
testcase_58 | AC | 2,005 ms
27,252 KB |
testcase_59 | AC | 2,033 ms
27,220 KB |
testcase_60 | AC | 2,087 ms
27,088 KB |
testcase_61 | AC | 767 ms
27,232 KB |
testcase_62 | AC | 568 ms
27,172 KB |
testcase_63 | AC | 846 ms
27,852 KB |
testcase_64 | AC | 601 ms
27,200 KB |
testcase_65 | AC | 607 ms
27,340 KB |
testcase_66 | AC | 662 ms
27,192 KB |
testcase_67 | AC | 580 ms
27,184 KB |
testcase_68 | AC | 631 ms
27,668 KB |
testcase_69 | AC | 578 ms
27,220 KB |
testcase_70 | AC | 1,189 ms
27,036 KB |
testcase_71 | AC | 3,298 ms
27,368 KB |
testcase_72 | AC | 3,257 ms
27,288 KB |
ソースコード
#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include<bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--) template <typename T> bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template <typename T> bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template <typename T> T max(vector<T> &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]); return ret; } template <typename T> T min(vector<T> &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]); return ret; } template <typename T> T sum(vector<T> &a){ T ret = 0; for (int i=0; i<(int)a.size(); i++) ret += a[i]; return ret; } bool dp[52][700][700]; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n, f; cin >> n >> f; vector<ll> a(2*n); vector<int> c(2*n); rep(i,0,n){ cin >> a[i]; a[i+n] = a[i]; } rep(i,0,n){ cin >> c[i]; c[i]--; c[i+n] = c[i]; } rep(i,0,50){ rep(j,0,2*n){ rep(k,0,2*n+1){ dp[i][j][k] = false; } } } rep(i,0,2*n){ dp[c[i]][i][i+1] = true; } rep(len,2,n+1){ rep(i,0,2*n+1-len){ if (i >= n){ rep(k,0,50){ dp[k][i][i+len] = dp[k][i-n][i-n+len]; } continue; } rep(k,0,50){ rep(j,i+1,i+len){ if (dp[k][i][i+len]) break; if (!dp[k][i][j]) continue; rep(l,max(0,k-f),min(50,k+f+1)){ if (dp[l][j][i+len]){ dp[k][i][i+len] = true; break; } } } rep(j,i+1,i+len){ if (dp[k][i][i+len]) break; if (!dp[k][j][i+len]) continue; rep(l,max(0,k-f),min(50,k+f+1)){ if (dp[l][i][j]){ dp[k][i][i+len] = true; break; } } } } } } vector<ll> rui(2*n+1); rep(i,0,2*n){ rui[i+1] += rui[i] + a[i]; } ll ans = -1e18; rep(i,0,50){ rep(j,0,2*n){ rep(k,0,2*n+1){ if (dp[i][j][k]){ chmax(ans, rui[k] - rui[j]); } } } } cout << ans << '\n'; }