#include using namespace std; typedef unsigned int uint; typedef long long int ll; typedef unsigned long long int ull; #define debugv(v) printf("L%d %s => ",__LINE__,#v);for(auto e:v){cout< ",__LINE__,#m);for(int x=0;x<(w);x++){cout<<(m)[x]<<" ";}cout<>=1,k++)s=(s<<1)|(u&1);for(;0>=1)cout<<(s&1);}} #define TIME chrono::system_clock::now() #define MILLISEC(t) (chrono::duration_cast(t).count()) namespace{ std::chrono::system_clock::time_point t; void tic(){t=TIME;} void toc(){fprintf(stderr,"TIME : %lldms\n",MILLISEC(TIME-t));} } template ostream& operator <<(ostream &o,const pair p){o<<"("<> vertex_to; vector> vertex_from; vector arrow; Flow(int n,int m=5010):n(n),vertex_to(n),vertex_from(n){arrow.reserve(m);} void connect(int from, int to, int w_max){ vertex_to[from].push_back(arrow.size()); // toto vertex_from[to].push_back(arrow.size()); // fromfrom arrow.emplace_back(from,to,w_max); } size_t degree(int v){ return vertex_to[v].size() + vertex_from[v].size(); } size_t degree_in(int v){ return vertex_from[v].size(); } size_t degree_out(int v){ return vertex_to[v].size(); } }; // DAG int _dinic_path_dfs(Flow& flow, vector& flag, const vector& dist, int u, int i_sink, int mini){ // TODO: 経路再利用 if (i_sink == u) return mini; if (flag[u]) return -1; flag[u] = true; int sumw = 0; bool term=true; for (int e : flow.vertex_to[u]){ Flow::Arrow& a = flow.arrow[e]; if (a.w_max > 0 && dist[u]>dist[a.to]){ int w ; if (mini < 0) w = a.w_max; else w = min(a.w_max, mini); w = _dinic_path_dfs(flow, flag, dist, a.to, i_sink, w); if (w==-1) continue; a.w_max -= w; //printf("%d->%d (%d) : w=%d mini=%d \n",a.from,a.to,a.w_max+w,w,mini); sumw +=w; mini -=w; term = false; flag[u] = false; } } for (int e : flow.vertex_from[u]){ Flow::Arrow& a = flow.arrow[e]; if (a.cap>a.w_max && dist[u]>dist[a.from]){ int w ; if (mini < 0) w = a.cap-a.w_max; else w = min(a.cap-a.w_max, mini); w = _dinic_path_dfs(flow, flag, dist, a.from, i_sink, w); if (w==-1) continue; a.w_max += w; //printf("%d<-%d (%d) : w=%d mini=%d \n",a.from,a.to,a.w_max-w,w,mini); sumw +=w; mini -=w; term = false; flag[u] = false; } } return term ? -1 : sumw; } // flowは書き換えられる. void dinic_special(Flow &flow, int i_source, int i_sink){ assert(i_source != i_sink); vector dist(flow.n); queue q; vector flag(flow.n); // TODO: for (int distbegin=0; ; distbegin+=flow.n){ safebreak(); q.emplace(i_sink); // bfsはsinkからsourceへの距離を計算. dist[i_sink] = distbegin+1; while (!q.empty()){ int v = q.front(); q.pop(); for (int ie : flow.vertex_from[v]){ const Flow::Arrow& e = flow.arrow[ie]; if (0> height >> width; n = height*width; BipartiteMatching bm(n,n); for (y=0;y> cho[y]; } int white,black; white=black=0; for (y=0;y x && cho[y][x+1]!='.') bm.connect(x+y*width,x+1+y*width); if (height-1 > y && cho[y+1][x]!='.') bm.connect(x+y*width,x+(y+1)*width); } } int np=bm.solve_dinic_special(); white -= np; black -= np; cout << ( (np*100) + (min(white,black)*10) + abs(white-black) ) << endl; return 0; }