Submission #2211784
Source Code Expand
#include <iostream> #include <sstream> #include <fstream> #include <string> #include <vector> #include <deque> #include <queue> #include <stack> #include <set> #include <map> #include <algorithm> #include <functional> #include <utility> #include <bitset> #include <cmath> #include <cstdlib> #include <ctime> #include <cstdio> using namespace std; #define REP(i,n) for((i)=0;(i)<(int)(n);(i)++) #define snuke(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++) #define COST_INF (1LL<<60) #define CAP_INF (1LL<<60) template <typename T> class MinCostFlow{ private: struct edge{int to; T cap; T cost; int rev;}; int V; vector <vector <edge> > adj; vector <T> pot; pair <T, T> dijkstra(int s, int t, T FLOW_BOUND){ int i; vector <int> used(V, 0); vector <T> dist(V, COST_INF); vector <pair <int, int> > path(V, make_pair(-1, -1)); priority_queue <pair <T, int> > q; dist[s] = 0; q.push(make_pair(0, s)); while(!q.empty()){ int x = q.top().second; q.pop(); if(used[x]) continue; used[x] = true; REP(i,adj[x].size()){ edge e = adj[x][i]; int y = e.to; if(e.cap > 0){ T d = dist[x] + e.cost + pot[x] - pot[y]; if(d < dist[y] && !used[y]){ dist[y] = d; path[y] = make_pair(x, i); q.push(make_pair(-d, y)); } } } } REP(i,V) pot[i] += dist[i]; if(dist[t] == COST_INF) return make_pair(0, 0); T f = FLOW_BOUND; T sum = 0; int x = t; while(x != s){ int y = path[x].first; int id = path[x].second; sum += adj[y][id].cost; f = min(f, adj[y][id].cap); x = y; } x = t; while(x != s){ int y = path[x].first; int id = path[x].second; adj[y][id].cap -= f; int id2 = adj[y][id].rev; adj[x][id2].cap += f; x = y; } return make_pair(f, f * sum); } public: MinCostFlow(int n){ V = n; adj.resize(V, vector <edge>(0)); pot.resize(V, 0); } void add_edge(int s, int t, T f, T c){ edge e1 = {t, f, c, adj[t].size()}; edge e2 = {s, 0, -c, adj[s].size()}; adj[s].push_back(e1); adj[t].push_back(e2); } pair <T, T> mincostflow(int s, int t, T FLOW_BOUND = (1LL<<59)){ pair <T, T> ans = make_pair(0LL, 0LL); while(FLOW_BOUND > 0){ pair <T, T> tmp = dijkstra(s, t, FLOW_BOUND); if(tmp.first == 0) break; ans.first += tmp.first; ans.second += tmp.second; FLOW_BOUND -= tmp.first; } return ans; } }; int main(){ int nn; scanf("%d",&nn); MinCostFlow<long long int> mcf(nn+2); for(int i=0; i<nn; i++){ long long int x; scanf("%lld",&x); mcf.add_edge(nn, i, x, 0); } for(int i=0; i<nn; i++){ long long int x; scanf("%lld",&x); mcf.add_edge(i, nn+1, x, 0); } for(int i=1; i<nn; i++){ mcf.add_edge(i-1, i, CAP_INF, 1); mcf.add_edge(i, i-1, CAP_INF, 1); } printf("%lld\n",mcf.mincostflow(nn, nn+1).second); return 0; }
Submission Info
Submission Time | |
---|---|
Task | H - WAAAAAAAAAAAAALL |
User | vjudge5 |
Language | C++14 (GCC 5.4.1) |
Score | 60 |
Code Size | 3223 Byte |
Status | TLE |
Exec Time | 2110 ms |
Memory | 42508 KB |
Compile Error
./Main.cpp: In instantiation of ‘void MinCostFlow<T>::add_edge(int, int, T, T) [with T = long long int]’: ./Main.cpp:136:27: required from here ./Main.cpp:106:38: warning: narrowing conversion of ‘(&((MinCostFlow<long long int>*)this)->MinCostFlow<long long int>::adj.std::vector<_Tp, _Alloc>::operator[]<std::vector<MinCostFlow<long long int>::edge, std::allocator<MinCostFlow<long long int>::edge> >, std::allocator<std::vector<MinCostFlow<long long int>::edge, std::allocator<MinCostFlow<long long int>::edge> > > >(((std::vector<std::vector<MinCostFlow<long long int>::edge, std::allocator<MinCostFlow<long long int>::edge> >, std::allocator<std::vector<MinCostFlow<long long int>::edge, std::allocator<MinCostFlow<long long int>::edge> > > >::size_type)t)))->std::vector<_Tp, _Alloc>::size<MinCostFlow<long long int>::edge, std::allocator<MinCostFlow<long long int>::edge> >()’ from ‘std::vector<MinCostFlow<long long int>::edge, std::allocator<MinCostFlow<long long int>::edge> >::size_type {aka long unsigned int}’ ...
Judge Result
Set Name | Subtask1 | Subtask2 | All | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 30 / 30 | 30 / 30 | 0 / 140 | ||||||||
Status |
|
|
|
Set Name | Test Cases |
---|---|
Subtask1 | 00_00_sample.txt, 00_01_sample.txt, 00_02_sample.txt, 00_03_random.txt, 00_04_random.txt, 00_05_random.txt, 00_06_random.txt, 00_07_random.txt, 00_08_random.txt, 00_09_random.txt, 00_10_random.txt, 00_11_random.txt, 00_12_random.txt, 00_13_random.txt, 00_14_random.txt, 00_15_random.txt, 00_16_random.txt, 00_17_random.txt, 00_18_random.txt, 00_19_random.txt, 00_20_random.txt, 00_21_random.txt, 00_22_random.txt, 00_23_freedom.txt, 00_24_freedom.txt, 00_25_freedom.txt, 00_26_full.txt, 00_27_full.txt, 00_28_full.txt, 00_29_min.txt, 00_30_min.txt, 00_31_min.txt, 00_32_max.txt, 00_33_max.txt, 00_34_max.txt, 00_35_max.txt, 00_36_max.txt |
Subtask2 | 01_37_sample.txt, 01_38_sample.txt, 01_39_random.txt, 01_40_random.txt, 01_41_random.txt, 01_42_random.txt, 01_43_random.txt, 01_44_random.txt, 01_45_random.txt, 01_46_random.txt, 01_47_random.txt, 01_48_random.txt, 01_49_random.txt, 01_50_random.txt, 01_51_random.txt, 01_52_random.txt, 01_53_random.txt, 01_54_random.txt, 01_55_random.txt, 01_56_random.txt, 01_57_random.txt, 01_58_random.txt, 01_59_freedom.txt, 01_60_freedom.txt, 01_61_freedom.txt, 01_62_full.txt, 01_63_full.txt, 01_64_full.txt, 01_65_min.txt, 01_66_min.txt, 01_67_min.txt, 01_68_max.txt, 01_69_max.txt, 01_70_max.txt, 01_71_max.txt, 01_72_max.txt |
All | 00_00_sample.txt, 00_01_sample.txt, 00_02_sample.txt, 00_03_random.txt, 00_04_random.txt, 00_05_random.txt, 00_06_random.txt, 00_07_random.txt, 00_08_random.txt, 00_09_random.txt, 00_10_random.txt, 00_11_random.txt, 00_12_random.txt, 00_13_random.txt, 00_14_random.txt, 00_15_random.txt, 00_16_random.txt, 00_17_random.txt, 00_18_random.txt, 00_19_random.txt, 00_20_random.txt, 00_21_random.txt, 00_22_random.txt, 00_23_freedom.txt, 00_24_freedom.txt, 00_25_freedom.txt, 00_26_full.txt, 00_27_full.txt, 00_28_full.txt, 00_29_min.txt, 00_30_min.txt, 00_31_min.txt, 00_32_max.txt, 00_33_max.txt, 00_34_max.txt, 00_35_max.txt, 00_36_max.txt, 01_37_sample.txt, 01_38_sample.txt, 01_39_random.txt, 01_40_random.txt, 01_41_random.txt, 01_42_random.txt, 01_43_random.txt, 01_44_random.txt, 01_45_random.txt, 01_46_random.txt, 01_47_random.txt, 01_48_random.txt, 01_49_random.txt, 01_50_random.txt, 01_51_random.txt, 01_52_random.txt, 01_53_random.txt, 01_54_random.txt, 01_55_random.txt, 01_56_random.txt, 01_57_random.txt, 01_58_random.txt, 01_59_freedom.txt, 01_60_freedom.txt, 01_61_freedom.txt, 01_62_full.txt, 01_63_full.txt, 01_64_full.txt, 01_65_min.txt, 01_66_min.txt, 01_67_min.txt, 01_68_max.txt, 01_69_max.txt, 01_70_max.txt, 01_71_max.txt, 01_72_max.txt, 02_100_min.txt, 02_101_min.txt, 02_102_max.txt, 02_103_max.txt, 02_104_max.txt, 02_105_max.txt, 02_106_max.txt, 02_73_random.txt, 02_74_random.txt, 02_75_random.txt, 02_76_random.txt, 02_77_random.txt, 02_78_random.txt, 02_79_random.txt, 02_80_random.txt, 02_81_random.txt, 02_82_random.txt, 02_83_random.txt, 02_84_random.txt, 02_85_random.txt, 02_86_random.txt, 02_87_random.txt, 02_88_random.txt, 02_89_random.txt, 02_90_random.txt, 02_91_random.txt, 02_92_random.txt, 02_93_freedom.txt, 02_94_freedom.txt, 02_95_freedom.txt, 02_96_full.txt, 02_97_full.txt, 02_98_full.txt, 02_99_min.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00_00_sample.txt | AC | 1 ms | 256 KB |
00_01_sample.txt | AC | 1 ms | 256 KB |
00_02_sample.txt | AC | 1 ms | 256 KB |
00_03_random.txt | AC | 1 ms | 256 KB |
00_04_random.txt | AC | 2 ms | 256 KB |
00_05_random.txt | AC | 2 ms | 256 KB |
00_06_random.txt | AC | 2 ms | 256 KB |
00_07_random.txt | AC | 1 ms | 256 KB |
00_08_random.txt | AC | 2 ms | 256 KB |
00_09_random.txt | AC | 2 ms | 256 KB |
00_10_random.txt | AC | 2 ms | 256 KB |
00_11_random.txt | AC | 1 ms | 256 KB |
00_12_random.txt | AC | 2 ms | 256 KB |
00_13_random.txt | AC | 1 ms | 256 KB |
00_14_random.txt | AC | 2 ms | 256 KB |
00_15_random.txt | AC | 1 ms | 256 KB |
00_16_random.txt | AC | 1 ms | 256 KB |
00_17_random.txt | AC | 1 ms | 256 KB |
00_18_random.txt | AC | 2 ms | 256 KB |
00_19_random.txt | AC | 2 ms | 256 KB |
00_20_random.txt | AC | 1 ms | 256 KB |
00_21_random.txt | AC | 2 ms | 256 KB |
00_22_random.txt | AC | 1 ms | 256 KB |
00_23_freedom.txt | AC | 2 ms | 256 KB |
00_24_freedom.txt | AC | 1 ms | 256 KB |
00_25_freedom.txt | AC | 2 ms | 256 KB |
00_26_full.txt | AC | 2 ms | 256 KB |
00_27_full.txt | AC | 2 ms | 256 KB |
00_28_full.txt | AC | 2 ms | 256 KB |
00_29_min.txt | AC | 1 ms | 256 KB |
00_30_min.txt | AC | 1 ms | 256 KB |
00_31_min.txt | AC | 1 ms | 256 KB |
00_32_max.txt | AC | 2 ms | 256 KB |
00_33_max.txt | AC | 3 ms | 256 KB |
00_34_max.txt | AC | 2 ms | 256 KB |
00_35_max.txt | AC | 3 ms | 256 KB |
00_36_max.txt | AC | 3 ms | 256 KB |
01_37_sample.txt | AC | 1 ms | 256 KB |
01_38_sample.txt | AC | 1 ms | 256 KB |
01_39_random.txt | AC | 136 ms | 512 KB |
01_40_random.txt | AC | 307 ms | 640 KB |
01_41_random.txt | AC | 91 ms | 640 KB |
01_42_random.txt | AC | 14 ms | 384 KB |
01_43_random.txt | AC | 1 ms | 256 KB |
01_44_random.txt | AC | 114 ms | 512 KB |
01_45_random.txt | AC | 13 ms | 384 KB |
01_46_random.txt | AC | 148 ms | 640 KB |
01_47_random.txt | AC | 1 ms | 256 KB |
01_48_random.txt | AC | 13 ms | 384 KB |
01_49_random.txt | AC | 150 ms | 640 KB |
01_50_random.txt | AC | 120 ms | 640 KB |
01_51_random.txt | AC | 3 ms | 256 KB |
01_52_random.txt | AC | 129 ms | 512 KB |
01_53_random.txt | AC | 77 ms | 512 KB |
01_54_random.txt | AC | 13 ms | 384 KB |
01_55_random.txt | AC | 101 ms | 512 KB |
01_56_random.txt | AC | 147 ms | 512 KB |
01_57_random.txt | AC | 194 ms | 640 KB |
01_58_random.txt | AC | 149 ms | 512 KB |
01_59_freedom.txt | AC | 20 ms | 384 KB |
01_60_freedom.txt | AC | 83 ms | 640 KB |
01_61_freedom.txt | AC | 86 ms | 640 KB |
01_62_full.txt | AC | 146 ms | 512 KB |
01_63_full.txt | AC | 139 ms | 512 KB |
01_64_full.txt | AC | 123 ms | 512 KB |
01_65_min.txt | AC | 1 ms | 256 KB |
01_66_min.txt | AC | 1 ms | 256 KB |
01_67_min.txt | AC | 1 ms | 256 KB |
01_68_max.txt | AC | 193 ms | 640 KB |
01_69_max.txt | AC | 208 ms | 640 KB |
01_70_max.txt | AC | 180 ms | 640 KB |
01_71_max.txt | AC | 154 ms | 640 KB |
01_72_max.txt | AC | 280 ms | 640 KB |
02_100_min.txt | AC | 1 ms | 256 KB |
02_101_min.txt | AC | 1 ms | 256 KB |
02_102_max.txt | TLE | 2106 ms | 41820 KB |
02_103_max.txt | TLE | 2106 ms | 41804 KB |
02_104_max.txt | TLE | 2106 ms | 42508 KB |
02_105_max.txt | TLE | 2105 ms | 41820 KB |
02_106_max.txt | TLE | 2106 ms | 41804 KB |
02_73_random.txt | TLE | 2105 ms | 36172 KB |
02_74_random.txt | TLE | 2106 ms | 41404 KB |
02_75_random.txt | TLE | 2105 ms | 23856 KB |
02_76_random.txt | TLE | 2104 ms | 36404 KB |
02_77_random.txt | TLE | 2104 ms | 16540 KB |
02_78_random.txt | TLE | 2105 ms | 32956 KB |
02_79_random.txt | TLE | 2104 ms | 9408 KB |
02_80_random.txt | TLE | 2106 ms | 41276 KB |
02_81_random.txt | TLE | 2105 ms | 38940 KB |
02_82_random.txt | TLE | 2105 ms | 31816 KB |
02_83_random.txt | TLE | 2105 ms | 18700 KB |
02_84_random.txt | TLE | 2105 ms | 20564 KB |
02_85_random.txt | TLE | 2110 ms | 39512 KB |
02_86_random.txt | TLE | 2105 ms | 33972 KB |
02_87_random.txt | TLE | 2104 ms | 12652 KB |
02_88_random.txt | TLE | 2106 ms | 39696 KB |
02_89_random.txt | TLE | 2105 ms | 42460 KB |
02_90_random.txt | TLE | 2104 ms | 11704 KB |
02_91_random.txt | TLE | 2104 ms | 6068 KB |
02_92_random.txt | TLE | 2105 ms | 19840 KB |
02_93_freedom.txt | TLE | 2105 ms | 33008 KB |
02_94_freedom.txt | TLE | 2104 ms | 19752 KB |
02_95_freedom.txt | TLE | 2105 ms | 23524 KB |
02_96_full.txt | TLE | 2104 ms | 4708 KB |
02_97_full.txt | TLE | 2105 ms | 37420 KB |
02_98_full.txt | TLE | 2105 ms | 38220 KB |
02_99_min.txt | AC | 1 ms | 256 KB |