結果
問題 | No.1288 yuki collection |
ユーザー | m_tsubasa |
提出日時 | 2020-11-13 23:48:49 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 336 ms / 5,000 ms |
コード長 | 2,702 bytes |
コンパイル時間 | 3,063 ms |
コンパイル使用メモリ | 225,516 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-22 22:20:08 |
合計ジャッジ時間 | 10,021 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 3 ms
6,816 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 3 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,944 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 3 ms
6,940 KB |
testcase_10 | AC | 3 ms
6,940 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 2 ms
6,940 KB |
testcase_13 | AC | 265 ms
6,944 KB |
testcase_14 | AC | 260 ms
6,940 KB |
testcase_15 | AC | 210 ms
6,944 KB |
testcase_16 | AC | 209 ms
6,940 KB |
testcase_17 | AC | 267 ms
6,940 KB |
testcase_18 | AC | 272 ms
6,940 KB |
testcase_19 | AC | 270 ms
6,940 KB |
testcase_20 | AC | 273 ms
6,944 KB |
testcase_21 | AC | 268 ms
6,940 KB |
testcase_22 | AC | 271 ms
6,944 KB |
testcase_23 | AC | 276 ms
6,940 KB |
testcase_24 | AC | 276 ms
6,944 KB |
testcase_25 | AC | 269 ms
6,944 KB |
testcase_26 | AC | 269 ms
6,940 KB |
testcase_27 | AC | 126 ms
6,940 KB |
testcase_28 | AC | 143 ms
6,944 KB |
testcase_29 | AC | 129 ms
6,940 KB |
testcase_30 | AC | 22 ms
6,944 KB |
testcase_31 | AC | 25 ms
6,944 KB |
testcase_32 | AC | 26 ms
6,940 KB |
testcase_33 | AC | 226 ms
6,940 KB |
testcase_34 | AC | 283 ms
6,940 KB |
testcase_35 | AC | 266 ms
6,940 KB |
testcase_36 | AC | 336 ms
6,940 KB |
testcase_37 | AC | 325 ms
6,944 KB |
testcase_38 | AC | 179 ms
6,944 KB |
testcase_39 | AC | 181 ms
6,944 KB |
testcase_40 | AC | 17 ms
6,940 KB |
testcase_41 | AC | 2 ms
6,940 KB |
testcase_42 | AC | 2 ms
6,940 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; template <class T> struct Primal_Dual { using Pa = pair<T, int>; long long infinity = (long long)(1e16); struct edge { int to; T cap, cost; int rev; }; int v; vector<vector<edge>> edges; vector<T> h; vector<T> dist; vector<int> prevv, preve; Primal_Dual(int vsize = 1) { v = vsize; edges.resize(v); h.resize(v); dist.resize(v); prevv.resize(v); preve.resize(v); } bool add(int from, int to, T cap, T cost) { edges[from].push_back((edge){to, cap, cost, (int)edges[to].size()}); edges[to].push_back((edge){from, 0, -cost, (int)edges[from].size() - 1}); return 1; } T solve(int s, int t, T f) { T ans = 0; h.assign(v, 0); while (f > 0) { priority_queue<Pa, vector<Pa>, greater<Pa>> qu; dist.assign(v, infinity); dist[s] = 0; qu.push({0, s}); while (!qu.empty()) { Pa now = qu.top(); qu.pop(); int nowv = now.second; if (dist[nowv] < now.first) continue; for (int i = 0; i < (int)edges[nowv].size(); ++i) { edge &e = edges[nowv][i]; if (e.cap > 0 && dist[e.to] > dist[nowv] + e.cost + h[nowv] - h[e.to]) { dist[e.to] = dist[nowv] + e.cost + h[nowv] - h[e.to]; prevv[e.to] = nowv; preve[e.to] = i; qu.push({dist[e.to], e.to}); } } } if (dist[t] == infinity) return -1; for (int i = 0; i < v; ++i) h[i] += dist[i]; T d = f; for (int i = t; i != s; i = prevv[i]) d = min(d, edges[prevv[i]][preve[i]].cap); f -= d; ans += d * h[t]; for (int i = t; i != s; i = prevv[i]) { edge &e = edges[prevv[i]][preve[i]]; e.cap -= d; edges[i][e.rev].cap += d; } } return ans; } }; int n; vector<int> v; string s; map<char, int> mp; long long solve(); int main() { for (int i = 0; i < 4; ++i) mp["yuki"[i]] = i; cin >> n >> s; v.resize(n); for (auto &p : v) cin >> p; cout << solve() << endl; return 0; } long long solve() { Primal_Dual<long long> pd(2 * n + 2); for (int i = 0; i < n; ++i) { pd.add(i, i + n, 1, (int)1e9 - v[i]); if (s[i] == 'y') pd.add(2 * n, i, 1, 0); if (s[i] == 'i') pd.add(i + n, 2 * n + 1, 1, 0); for (int j = i + 1; j < n; ++j) if (mp[s[i]] + 1 == mp[s[j]]) { pd.add(i + n, j, 1, 0); break; } for (int j = i + 1; j < n; ++j) if (mp[s[i]] == mp[s[j]]) { pd.add(i, j, n + 1, 0); break; } } pd.add(2 * n, 2 * n + 1, n / 4, 4e9); return 4LL * (n / 4) * (int)1e9 - pd.solve(2 * n, 2 * n + 1, n / 4); }