結果
問題 | No.1288 yuki collection |
ユーザー | snow39 |
提出日時 | 2020-11-13 23:19:28 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
CE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 3,367 bytes |
コンパイル時間 | 805 ms |
コンパイル使用メモリ | 96,968 KB |
最終ジャッジ日時 | 2024-11-14 23:54:32 |
合計ジャッジ時間 | 1,615 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In constructor 'MinCostFlow<flow_t, cost_t>::MinCostFlow(int)': main.cpp:36:37: error: 'numeric_limits' was not declared in this scope 36 | MinCostFlow(int V) : graph(V),INF(numeric_limits< cost_t >::max()) {} | ^~~~~~~~~~~~~~ main.cpp:36:60: error: expected primary-expression before '>' token 36 | MinCostFlow(int V) : graph(V),INF(numeric_limits< cost_t >::max()) {} | ^ main.cpp:36:66: error: no matching function for call to 'max()' 36 | MinCostFlow(int V) : graph(V),INF(numeric_limits< cost_t >::max()) {} | ~~~~~^~ In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/string:50, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/locale_classes.h:40, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/ios_base.h:41, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ios:42, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ostream:38, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/iostream:39, from main.cpp:1: /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)' 254 | max(const _Tp& __a, const _Tp& __b) | ^~~ /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_algobase.h:254:5: note: template argument deduction/substitution failed: main.cpp:36:66: note: candidate expects 2 arguments, 0 provided 36 | MinCostFlow(int V) : graph(V),INF(numeric_limits< cost_t >::max()) {} | ~~~~~^~ /home/linuxbrew/.linuxbrew/Ce
ソースコード
#include <iostream> #include <algorithm> #include <string> #include <vector> #include <cmath> #include <map> #include <queue> #include <iomanip> #include <set> #include <tuple> #define mkp make_pair #define mkt make_tuple #define rep(i,n) for(int i = 0; i < (n); ++i) #define all(v) v.begin(),v.end() using namespace std; typedef long long ll; const ll MOD=1e9+7; template<class T> void chmin(T &a,const T &b){if(a>b) a=b;} template<class T> void chmax(T &a,const T &b){if(a<b) a=b;} template< typename flow_t, typename cost_t > struct MinCostFlow { const cost_t INF; struct edge { int to; flow_t cap; cost_t cost; int rev; bool isrev; }; vector<vector<edge>> graph; vector<cost_t> potential,min_cost; vector<int> prevv,preve; MinCostFlow(int V) : graph(V),INF(numeric_limits< cost_t >::max()) {} void add_edge(int from,int to,flow_t cap,cost_t cost){ graph[from].emplace_back((edge){to,cap,cost,(int)graph[to].size(),false}); graph[to].emplace_back((edge){from,0,-cost,(int)graph[from].size()-1,true}); } cost_t min_cost_flow(int s,int t,flow_t f){ int V=(int)graph.size(); cost_t ret=0; using Pi = pair<cost_t,int>; priority_queue<Pi,vector<Pi>,greater<Pi>> PQ; potential.assign(V,0); preve.assign(V,-1); prevv.assign(V,-1); while(f>0){ min_cost.assign(V,INF); PQ.emplace(0,s); min_cost[s]=0; while(!PQ.empty()){ cost_t d; int now; tie(d,now)=PQ.top(); PQ.pop(); if(min_cost[now]<d) continue; for(int i=0;i<graph[now].size();i++){ edge &e=graph[now][i]; cost_t nextCost=min_cost[now]+(e.cost+potential[now]-potential[e.to]); if(e.cap>0&&min_cost[e.to]>nextCost){ min_cost[e.to]=nextCost; prevv[e.to]=now; preve[e.to]=i; PQ.emplace(min_cost[e.to],e.to); } } } if(min_cost[t]==INF) return -1; for(int v=0;v<V;v++) potential[v]+=min_cost[v]; flow_t addflow=f; for(int v=t;v!=s;v=prevv[v]){ addflow=min(addflow,graph[prevv[v]][preve[v]].cap); } f-=addflow; ret+=addflow*potential[t]; for(int v=t;v!=s;v=prevv[v]){ edge &e=graph[prevv[v]][preve[v]]; e.cap-=addflow; graph[v][e.rev].cap+=addflow; } } return ret; } }; const int L=500; string P="yuki"; const ll INF=1e9; int main(){ cin.tie(0); ios::sync_with_stdio(false); int N; cin>>N; string S; cin>>S; vector<ll> V(N); rep(i,N) cin>>V[i]; MinCostFlow<int,ll> mcf(N+2); int s=N; int t=N+1; vector<vector<int>> v(4); rep(i,N){ rep(j,4) if(S[i]==P[j]) v[j].push_back(i); } int M=N/4; for(int j=0;j<4;j++){ for(int i=0;i+1<v[j].size();i++){ mcf.add_edge(v[j][i],v[j][i+1],M,0); } if(j==3){ for(int i=0;i<v[j].size();i++) mcf.add_edge(v[j][i],t,1,INF-V[v[j][i]]); }else{ for(int i=0;i<v[j].size();i++){ int z=lower_bound(all(v[j+1]),v[j][i])-v[j+1].begin(); if(z<v[j+1].size()) mcf.add_edge(v[j][i],v[j+1][z],1,INF-V[v[j][i]]); } } } if(v[0].size()) mcf.add_edge(s,v[0][0],M,0); mcf.add_edge(s,t,M,4*INF-0); ll ans=mcf.min_cost_flow(s,t,M); ans=-(ans-INF*M*4); cout<<ans<<endl; return 0; }