結果
問題 | No.1288 yuki collection |
ユーザー | m_tsubasa |
提出日時 | 2020-11-13 23:13:13 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,530 bytes |
コンパイル時間 | 2,656 ms |
コンパイル使用メモリ | 224,840 KB |
実行使用メモリ | 75,136 KB |
最終ジャッジ日時 | 2024-07-22 22:11:08 |
合計ジャッジ時間 | 49,727 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 | 3 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 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 | 3 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 3 ms
6,944 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 3 ms
6,940 KB |
testcase_13 | AC | 2,561 ms
34,684 KB |
testcase_14 | AC | 2,535 ms
34,816 KB |
testcase_15 | AC | 1,778 ms
29,248 KB |
testcase_16 | AC | 1,826 ms
29,464 KB |
testcase_17 | AC | 2,530 ms
34,048 KB |
testcase_18 | AC | 2,496 ms
34,748 KB |
testcase_19 | AC | 2,489 ms
34,300 KB |
testcase_20 | AC | 2,559 ms
35,344 KB |
testcase_21 | AC | 3,361 ms
47,392 KB |
testcase_22 | AC | 3,358 ms
47,188 KB |
testcase_23 | AC | 3,319 ms
46,824 KB |
testcase_24 | AC | 2,692 ms
35,096 KB |
testcase_25 | AC | 2,505 ms
35,432 KB |
testcase_26 | AC | 2,575 ms
35,472 KB |
testcase_27 | AC | 704 ms
20,864 KB |
testcase_28 | AC | 1,094 ms
28,492 KB |
testcase_29 | AC | 1,154 ms
31,260 KB |
testcase_30 | AC | 111 ms
32,512 KB |
testcase_31 | AC | 152 ms
33,664 KB |
testcase_32 | AC | 159 ms
32,896 KB |
testcase_33 | TLE | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
ソースコード
#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); } pd.add(2 * n, 2 * n + 1, n, 4e9); return 4LL * n * (int)1e9 - pd.solve(2 * n, 2 * n + 1, n); }