結果

問題 No.1508 Avoid being hit
ユーザー uzzyuzzy
提出日時 2021-05-14 23:59:06
言語 C++14
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 20 ms / 3,000 ms
コード長 1,709 bytes
コンパイル時間 1,756 ms
使用メモリ 4,592 KB
最終ジャッジ日時 2022-11-26 01:07:37
合計ジャッジ時間 5,043 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 17 ms
4,312 KB
testcase_01 AC 2 ms
3,376 KB
testcase_02 AC 1 ms
3,492 KB
testcase_03 AC 2 ms
3,376 KB
testcase_04 AC 2 ms
3,456 KB
testcase_05 AC 1 ms
3,544 KB
testcase_06 AC 2 ms
3,496 KB
testcase_07 AC 2 ms
3,372 KB
testcase_08 AC 1 ms
3,520 KB
testcase_09 AC 1 ms
3,396 KB
testcase_10 AC 2 ms
3,480 KB
testcase_11 AC 2 ms
3,468 KB
testcase_12 AC 1 ms
3,496 KB
testcase_13 AC 1 ms
3,380 KB
testcase_14 AC 1 ms
3,384 KB
testcase_15 AC 1 ms
3,492 KB
testcase_16 AC 12 ms
4,524 KB
testcase_17 AC 8 ms
4,064 KB
testcase_18 AC 6 ms
3,824 KB
testcase_19 AC 11 ms
4,240 KB
testcase_20 AC 14 ms
4,536 KB
testcase_21 AC 10 ms
4,136 KB
testcase_22 AC 13 ms
4,440 KB
testcase_23 AC 14 ms
4,548 KB
testcase_24 AC 18 ms
4,548 KB
testcase_25 AC 16 ms
4,592 KB
testcase_26 AC 2 ms
3,556 KB
testcase_27 AC 10 ms
4,048 KB
testcase_28 AC 10 ms
3,932 KB
testcase_29 AC 17 ms
4,472 KB
testcase_30 AC 10 ms
4,064 KB
testcase_31 AC 16 ms
4,436 KB
testcase_32 AC 17 ms
4,480 KB
testcase_33 AC 6 ms
3,844 KB
testcase_34 AC 16 ms
4,208 KB
testcase_35 AC 3 ms
3,584 KB
testcase_36 AC 10 ms
3,852 KB
testcase_37 AC 5 ms
3,716 KB
testcase_38 AC 13 ms
4,160 KB
testcase_39 AC 9 ms
3,804 KB
testcase_40 AC 17 ms
4,256 KB
testcase_41 AC 11 ms
3,888 KB
testcase_42 AC 18 ms
4,396 KB
testcase_43 AC 20 ms
4,420 KB
testcase_44 AC 1 ms
3,548 KB
testcase_45 AC 1 ms
3,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("O2")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

int L[100100], R[100100];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);


	int N, Q;
	cin >> N >> Q;
	int A[100100], B[100100];
	rep(i, Q) cin >> A[i];
	rep(i, Q) A[i]--;
	rep(i, Q) cin >> B[i];
	rep(i, Q) B[i]--;
	rep(i, Q) if (A[i] > B[i]) swap(A[i], B[i]);

	int yabai = 0;
	rep(i, Q) {
		if (L[i] == 0) {
			if (A[i] == 0) {
				L[i + 1] = 1;
				if (B[i] == 1) L[i + 1] = 2;
			}
			else L[i + 1] = 0;
		}
		else {
			if (A[i] == L[i] - 1 || B[i] == L[i] - 1) {
				L[i + 1] = L[i];
				if (B[i] == L[i] || A[i] == L[i]) L[i + 1] = L[i] + 1;
			}
			else L[i + 1] = L[i] - 1;
		}
		if (L[i + 1] >= N) yabai = 1;
	}

	for (int i = Q - 1; i >= 0; i--) {
		if (A[i] == L[i + 2] - 1 || B[i] == L[i + 2] - 1) {
			chmax(L[i + 1], L[i + 2]);
			if (B[i] == L[i + 2] || A[i] == L[i + 2]) chmax(L[i + 1], L[i + 2] + 1);
		}
		else chmax(L[i + 1], L[i + 2] - 1);
		if (L[i + 1] >= N) yabai = 1;
	}
	chmax(L[0], L[1] - 1);

	if (yabai) co("NO");
	else {
		rep(i, Q) {
			if (L[i + 1] == A[i] || L[i + 1] == B[i]) yabai = 1;
		}
		if (yabai) co("NO");
		else {
			co("YES");
			rep(i, Q + 1) co(L[i] + 1);
		}
	}


	Would you please return 0;
}
0