結果

問題 No.2240 WAC
ユーザー shobonvipshobonvip
提出日時 2023-02-09 03:50:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,602 bytes
コンパイル時間 2,161 ms
コンパイル使用メモリ 212,340 KB
実行使用メモリ 100,924 KB
最終ジャッジ日時 2023-09-20 15:57:04
合計ジャッジ時間 6,023 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,752 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 TLE -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/maxflow>
using namespace std;
using namespace atcoder;

// importbisect
template <typename T>
int bisect_left(vector<T> &X, T v){
	return lower_bound(X.begin(), X.end(), v) - X.begin();
}

template <typename T>
int bisect_right(vector<T> &X, T v){
	return upper_bound(X.begin(), X.end(), v) - X.begin();
}
// -----

int main(){
	int n, m; cin >> n >> m;
	string s; cin >> s;
	int k = n + m;
	mf_graph<int> mf(4*k+2);

	vector<int> w(0);
	vector<int> a(0);
	vector<int> c(0);
	for (int i=0; i<2*k; i++){
		if (s[i] == 'W') w.push_back(i);
		if (s[i] == 'A') a.push_back(i);
		if (s[i] == 'C') c.push_back(i);
	}
	
	// スタートから各 W, C へ
	for (int i=0; i<k; i++){
		mf.add_edge(4*k, i, 1);
	}

	// 各 A からゴールへ
	for (int i=0; i<k; i++){
		mf.add_edge(3*k+i, 4*k+1, 1);
	}

	// ベルトコンベアー (前へ)
	for (int i=0; i<k-1; i++){
		mf.add_edge(k+i, k+i+1, 300000);
	}

	// ベルトコンベアー (うしろへ)
	for (int i=0; i<k-1; i++){
		mf.add_edge(2*k+i+1, 2*k+i, 300000);
	}

	// ベルトコンベアーから各 A へ
	for (int i=0; i<k; i++){
		mf.add_edge(k+i, 3*k+i, 1);
		mf.add_edge(2*k+i, 3*k+i, 1);
	}

	// 各 W からベルトコンベアへ
	for (int i=0; i<n; i++){
		int targ = bisect_right(a, w[i]);
		if (targ < k) mf.add_edge(i, k+targ, 1);
	}

	// 各 C からベルトコンベアへ
	for (int i=0; i<m; i++){
		int targ = bisect_left(a, c[i]);
		targ--;
		if (targ >= 0) mf.add_edge(i+n, 2*k+targ, 1);
	}

	if (mf.flow(4*k, 4*k+1) == k){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	
}
0