結果
問題 | No.1288 yuki collection |
ユーザー | milanis48663220 |
提出日時 | 2020-11-13 23:59:32 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 4,032 bytes |
コンパイル時間 | 1,077 ms |
コンパイル使用メモリ | 96,064 KB |
実行使用メモリ | 16,960 KB |
最終ジャッジ日時 | 2024-07-22 22:20:39 |
合計ジャッジ時間 | 13,539 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | TLE | - |
testcase_01 | -- | - |
testcase_02 | -- | - |
testcase_03 | -- | - |
testcase_04 | -- | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
コンパイルメッセージ
main.cpp: In member function 'void MinCostFlow::add_edge(int, int, ll, ll)': main.cpp:39:63: warning: narrowing conversion of '(&((MinCostFlow*)this)->MinCostFlow::G.std::vector<std::vector<edge> >::operator[](((std::vector<std::vector<edge> >::size_type)to)))->std::vector<edge>::size()' from 'std::vector<edge>::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing] 39 | G[from].push_back((edge){to, cap, cost, G[to].size()}); | ~~~~~~~~~~^~ main.cpp:40:66: warning: narrowing conversion of '((&((MinCostFlow*)this)->MinCostFlow::G.std::vector<std::vector<edge> >::operator[](((std::vector<std::vector<edge> >::size_type)from)))->std::vector<edge>::size() - 1)' from 'std::vector<edge>::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing] 40 | G[to].push_back((edge){from, 0, -cost, G[from].size()-1}); | ~~~~~~~~~~~~~~^~
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <set> #include <map> #include <cassert> #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; const ll INF = 1e18; struct edge{ int to; ll cap, cost; int rev; }; class MinCostFlow{ public: int V; // 頂点数 vector<vector<edge>> G; MinCostFlow(int v){ V = v; G = vector<vector<edge>>(v, vector<edge>()); dist = vector<ll>(v); preve = vector<int>(v); prevv = vector<int>(v); } void add_edge(int from, int to, ll cap, ll cost){ G[from].push_back((edge){to, cap, cost, G[to].size()}); G[to].push_back((edge){from, 0, -cost, G[from].size()-1}); } ll min_cost_flow(int s, int t, int f){ ll res = 0; while(f > 0){ fill(dist.begin(), dist.end(), INF); dist[s] = 0; for(int v = 0; v < V; v++){ for(int i = 0; i < G[v].size(); i++){ edge &e = G[v][i]; if(e.cap > 0 && dist[e.to] > dist[i]+e.cost){ dist[e.to] = dist[v]+e.cost; prevv[e.to] = v; preve[e.to] = i; } } } if(dist[t] == INF){ return -1; } ll d = f; for(int v = t; v != s; v = prevv[v]){ d = min(d, G[prevv[v]][preve[v]].cap); } f -= d; res += d*dist[t]; for(int v = t; v != s; v = prevv[v]){ edge &e = G[prevv[v]][preve[v]]; e.cap -= d; G[v][e.rev].cap += d; } } return res; } private: vector<ll> dist; vector<int> prevv, preve; }; int n; string s; ll v[2000]; void input(){ cin >> n >> s; for(int i = 0; i < n; i++) cin >> v[i]; } int idx_from(int i){ return i+1; } int idx_to(int i){ return i+n+1; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; input(); MinCostFlow mcf(2*n+2); int f = 0, t = 2*n+1; int cnty = 0; for(int i = 0; i < n; i++){ mcf.add_edge(idx_from(i), idx_to(i), 1, 0); if(s[i] == 'y'){ cnty++; mcf.add_edge(0, idx_from(i), 1, 0); mcf.add_edge(idx_to(i), t, 1, 0); } if(s[i] == 'i'){ mcf.add_edge(idx_to(i), t, 1, -v[i]); } for(int j = i+1; j < n; j++){ bool find_same = false; bool find_after = false; if(!find_after){ if(s[i] == 'y' && s[j] == 'u'){ mcf.add_edge(idx_to(i), idx_from(j), 1, -v[i]); find_after = true; } if(s[i] == 'u' && s[j] == 'k'){ mcf.add_edge(idx_to(i), idx_from(j), 1, -v[i]); find_after = true; } if(s[i] == 'k' && s[j] == 'i'){ mcf.add_edge(idx_to(i), idx_from(j), 1, -v[i]); find_after = true; } } if(!find_same){ if(s[i] == s[j]){ mcf.add_edge(idx_to(i), idx_from(j), 1, 0); find_same = true; } } } } cout << -mcf.min_cost_flow(f, t, cnty) << endl; }