結果

問題 No.1055 牛歩
ユーザー QCFiumQCFium
提出日時 2019-09-26 18:56:40
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 69 ms / 1,000 ms
コード長 1,980 bytes
コンパイル時間 1,770 ms
コンパイル使用メモリ 176,856 KB
実行使用メモリ 10,828 KB
最終ジャッジ日時 2023-10-22 08:00:54
合計ジャッジ時間 8,708 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
10,828 KB
testcase_01 AC 40 ms
10,324 KB
testcase_02 AC 25 ms
5,728 KB
testcase_03 AC 24 ms
5,728 KB
testcase_04 AC 25 ms
5,732 KB
testcase_05 AC 25 ms
5,732 KB
testcase_06 AC 27 ms
6,448 KB
testcase_07 AC 25 ms
6,448 KB
testcase_08 AC 27 ms
6,448 KB
testcase_09 AC 22 ms
5,964 KB
testcase_10 AC 22 ms
5,964 KB
testcase_11 AC 22 ms
5,964 KB
testcase_12 AC 21 ms
6,560 KB
testcase_13 AC 22 ms
6,560 KB
testcase_14 AC 22 ms
5,960 KB
testcase_15 AC 22 ms
5,960 KB
testcase_16 AC 19 ms
5,412 KB
testcase_17 AC 19 ms
5,412 KB
testcase_18 AC 19 ms
5,412 KB
testcase_19 AC 20 ms
5,412 KB
testcase_20 AC 24 ms
5,984 KB
testcase_21 AC 26 ms
5,984 KB
testcase_22 AC 26 ms
6,028 KB
testcase_23 AC 26 ms
6,032 KB
testcase_24 AC 26 ms
6,052 KB
testcase_25 AC 23 ms
6,232 KB
testcase_26 AC 23 ms
6,496 KB
testcase_27 AC 25 ms
6,232 KB
testcase_28 AC 24 ms
6,232 KB
testcase_29 AC 27 ms
5,968 KB
testcase_30 AC 26 ms
6,232 KB
testcase_31 AC 7 ms
4,348 KB
testcase_32 AC 7 ms
4,348 KB
testcase_33 AC 7 ms
4,348 KB
testcase_34 AC 6 ms
4,348 KB
testcase_35 AC 7 ms
4,348 KB
testcase_36 AC 7 ms
4,348 KB
testcase_37 AC 6 ms
4,348 KB
testcase_38 AC 7 ms
4,348 KB
testcase_39 AC 2 ms
4,348 KB
testcase_40 AC 2 ms
4,348 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 3 ms
4,348 KB
testcase_43 AC 2 ms
4,348 KB
testcase_44 AC 2 ms
4,348 KB
testcase_45 AC 2 ms
4,348 KB
testcase_46 AC 2 ms
4,348 KB
testcase_47 AC 2 ms
4,348 KB
testcase_48 AC 2 ms
4,348 KB
testcase_49 AC 2 ms
4,348 KB
testcase_50 AC 2 ms
4,348 KB
testcase_51 AC 2 ms
4,348 KB
testcase_52 AC 2 ms
4,348 KB
testcase_53 AC 2 ms
4,348 KB
testcase_54 AC 2 ms
4,348 KB
testcase_55 AC 2 ms
4,348 KB
testcase_56 AC 2 ms
4,348 KB
testcase_57 AC 2 ms
4,348 KB
testcase_58 AC 2 ms
4,348 KB
testcase_59 AC 2 ms
4,348 KB
testcase_60 AC 2 ms
4,348 KB
testcase_61 AC 2 ms
4,348 KB
testcase_62 AC 2 ms
4,348 KB
testcase_63 AC 2 ms
4,348 KB
testcase_64 AC 2 ms
4,348 KB
testcase_65 AC 2 ms
4,348 KB
testcase_66 AC 2 ms
4,348 KB
testcase_67 AC 2 ms
4,348 KB
testcase_68 AC 2 ms
4,348 KB
testcase_69 AC 1 ms
4,348 KB
testcase_70 AC 1 ms
4,348 KB
testcase_71 AC 2 ms
4,348 KB
testcase_72 AC 2 ms
4,348 KB
testcase_73 AC 2 ms
4,348 KB
testcase_74 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

bool solve(int n, int m, int *a, int q, int *b) {
	assert(std::is_sorted(a, a + m));
	std::vector<int> list[m];
	for (int i = 0; i < q; i++) list[b[i]].push_back(i);
	int pos[q];
	for (int i = 0; i < q; i++) pos[i] = -2;
	// 0-th koma
	{
		int cur = a[0];
		for (auto i : list[0]) {
			if (!cur) cur++;
			else cur--;
			pos[i] = cur;
		}
	}
	for (int i = 1; i < m; i++) {
		std::deque<std::pair<int, int> > clearance; // {pos, clearance}
		{ // init clearance with slide maximum
			int head = 0;
			int cur_pos = a[i];
			for (auto j : list[i - 1]) {
				while (head < (int) list[i].size() && list[i][head] < j) head++, cur_pos++;
				int cur_clearance = cur_pos - pos[j];
				if (cur_clearance <= 0) return false;
				while (clearance.size() && clearance.back().second >= cur_clearance) clearance.pop_back();
				clearance.push_back({j, cur_clearance});
			}
		}
		int head = 0;
		int cur_pos = a[i];
		int prev_pos = a[i - 1];
		int clearance_minus = 0;
		for (auto j : list[i - 1]) {
			while (head < (int) list[i].size() && list[i][head] < j) {
				if (prev_pos < cur_pos - 1 && (!clearance.size() || clearance.front().second - clearance_minus > 2)) { // -1
					cur_pos--;
					clearance_minus += 2;
				} else cur_pos++;
				pos[list[i][head]] = cur_pos;
				head++;
			}
			if (clearance.size() && clearance.front().first == j) clearance.pop_front(); 
			prev_pos = pos[j];
		}
		while (head < (int) list[i].size()) {
			if (prev_pos < cur_pos - 1) cur_pos--;
			else cur_pos++;
			pos[list[i][head]] = cur_pos;
			head++;
		}
	}
	assert(!std::count(pos, pos + q, -2));
	for (int i = 0; i < q; i++) if (pos[i] >= n) return false;
	return true;
}

int main() {
	int n = ri(), m = ri();
	int a[m];
	for (int i = 0; i < m; i++) a[i] = ri() - 1;
	int q = ri();
	int b[q];
	for (int i = 0; i < q; i++) b[i] = ri() - 1;
	std::cout << (solve(n, m, a, q, b) ? "YES" : "NO") << std::endl;
	
	return 0;
}
0