結果

問題 No.1508 Avoid being hit
ユーザー uzzyuzzy
提出日時 2021-05-14 23:59:06
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 3,000 ms
コード長 1,709 bytes
コンパイル時間 2,629 ms
コンパイル使用メモリ 183,792 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-10 05:38:05
合計ジャッジ時間 5,434 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 14 ms
5,376 KB
testcase_17 AC 9 ms
5,376 KB
testcase_18 AC 8 ms
5,376 KB
testcase_19 AC 13 ms
5,376 KB
testcase_20 AC 18 ms
5,376 KB
testcase_21 AC 14 ms
5,376 KB
testcase_22 AC 16 ms
5,376 KB
testcase_23 AC 18 ms
5,376 KB
testcase_24 AC 21 ms
5,376 KB
testcase_25 AC 18 ms
5,376 KB
testcase_26 AC 3 ms
5,376 KB
testcase_27 AC 11 ms
5,376 KB
testcase_28 AC 10 ms
5,376 KB
testcase_29 AC 19 ms
5,376 KB
testcase_30 AC 10 ms
5,376 KB
testcase_31 AC 16 ms
5,376 KB
testcase_32 AC 18 ms
5,376 KB
testcase_33 AC 6 ms
5,376 KB
testcase_34 AC 20 ms
5,376 KB
testcase_35 AC 3 ms
5,376 KB
testcase_36 AC 12 ms
5,376 KB
testcase_37 AC 6 ms
5,376 KB
testcase_38 AC 16 ms
5,376 KB
testcase_39 AC 11 ms
5,376 KB
testcase_40 AC 20 ms
5,376 KB
testcase_41 AC 12 ms
5,376 KB
testcase_42 AC 21 ms
5,376 KB
testcase_43 AC 23 ms
5,376 KB
testcase_44 AC 1 ms
5,376 KB
testcase_45 AC 2 ms
5,376 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