結果

問題 No.2573 moving up
ユーザー binapbinap
提出日時 2024-01-19 21:06:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,319 ms / 2,000 ms
コード長 1,963 bytes
コンパイル時間 4,784 ms
コンパイル使用メモリ 278,948 KB
実行使用メモリ 51,096 KB
最終ジャッジ日時 2024-01-19 21:06:57
合計ジャッジ時間 17,722 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,676 KB
testcase_01 AC 815 ms
51,096 KB
testcase_02 AC 1,319 ms
51,096 KB
testcase_03 AC 1,073 ms
51,096 KB
testcase_04 AC 1,037 ms
51,096 KB
testcase_05 AC 1,122 ms
51,096 KB
testcase_06 AC 957 ms
51,096 KB
testcase_07 AC 897 ms
50,164 KB
testcase_08 AC 187 ms
26,800 KB
testcase_09 AC 8 ms
6,676 KB
testcase_10 AC 635 ms
43,412 KB
testcase_11 AC 168 ms
23,760 KB
testcase_12 AC 360 ms
31,260 KB
testcase_13 AC 665 ms
42,492 KB
testcase_14 AC 40 ms
11,416 KB
testcase_15 AC 69 ms
26,536 KB
testcase_16 AC 4 ms
6,676 KB
testcase_17 AC 23 ms
6,676 KB
testcase_18 AC 565 ms
42,616 KB
testcase_19 AC 558 ms
40,808 KB
testcase_20 AC 49 ms
11,136 KB
testcase_21 AC 72 ms
14,976 KB
testcase_22 AC 31 ms
7,372 KB
testcase_23 AC 141 ms
22,484 KB
testcase_24 AC 269 ms
31,992 KB
testcase_25 AC 379 ms
33,504 KB
testcase_26 AC 69 ms
13,820 KB
testcase_27 AC 54 ms
28,388 KB
testcase_28 AC 48 ms
28,388 KB
testcase_29 AC 58 ms
28,388 KB
testcase_30 AC 53 ms
28,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long>> vvl;
typedef long double ld;
typedef pair<int, int> P;

ostream& operator<<(ostream& os, const modint& a) {os << a.val(); return os;}
template <int m> ostream& operator<<(ostream& os, const static_modint<m>& a) {os << a.val(); return os;}
template<typename T> istream& operator>>(istream& is, vector<T>& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;}
template<typename U, typename T> ostream& operator<<(ostream& os, const pair<U, T>& p){os << p.first << ' ' << p.second; return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); return os;}
template <typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : ""); return os;}

int main(){
	int h, w;
	cin >> h >> w;
	int n = h * (h + w);
	mcf_graph<int, int> graph(n + 2);
	int sv = n;
	int tv = n + 1;
	rep(y, h) rep(x, h + w){
		int from = y * (h + w) + x;
		if(y < h - 1){
			int to = (y + 1) * (h + w) + x;
			graph.add_edge(from, to, 100, 1);
			graph.add_edge(to, from, 100, 1);
		}
		if(x < h + w - 1){
			int to = y * (h + w) + (x + 1);
			graph.add_edge(from, to, 100, 1);
			graph.add_edge(to, from, 100, 1);
		}
		if(y < h - 1 and x < h + w - 1){
			int to = (y + 1) * (h + w) + (x + 1);
			graph.add_edge(from, to, 100, 1);
			graph.add_edge(to, from, 100, 1);
		}
	}
	rep(i, w){
		int y, x;
		cin >> y >> x;
		x--; y--;
		graph.add_edge(sv, y * (h + w) + x, 1, 0);
	}
	rep(x, w){
		graph.add_edge(x, tv, 1, 0);
	}
	auto [cap, cost] = graph.flow(sv, tv);
//	cout << cap << ' ' << cost << "\n";
	cout << cost << "\n";
	return 0;
}
0