結果
問題 | No.1508 Avoid being hit |
ユーザー | SSRS |
提出日時 | 2021-05-15 00:01:27 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,470 bytes |
コンパイル時間 | 1,782 ms |
コンパイル使用メモリ | 181,364 KB |
実行使用メモリ | 14,836 KB |
最終ジャッジ日時 | 2024-10-02 06:40:59 |
合計ジャッジ時間 | 7,337 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 165 ms
13,032 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | AC | 2 ms
6,816 KB |
testcase_03 | AC | 2 ms
6,820 KB |
testcase_04 | AC | 2 ms
6,820 KB |
testcase_05 | AC | 2 ms
6,820 KB |
testcase_06 | RE | - |
testcase_07 | AC | 2 ms
6,820 KB |
testcase_08 | AC | 2 ms
6,816 KB |
testcase_09 | AC | 2 ms
6,816 KB |
testcase_10 | AC | 2 ms
6,816 KB |
testcase_11 | AC | 2 ms
6,816 KB |
testcase_12 | AC | 2 ms
6,816 KB |
testcase_13 | AC | 2 ms
6,820 KB |
testcase_14 | AC | 2 ms
6,820 KB |
testcase_15 | AC | 2 ms
6,820 KB |
testcase_16 | AC | 67 ms
13,312 KB |
testcase_17 | AC | 35 ms
9,212 KB |
testcase_18 | AC | 29 ms
7,552 KB |
testcase_19 | AC | 52 ms
12,288 KB |
testcase_20 | AC | 78 ms
14,836 KB |
testcase_21 | AC | 52 ms
11,008 KB |
testcase_22 | AC | 64 ms
12,928 KB |
testcase_23 | AC | 70 ms
13,600 KB |
testcase_24 | AC | 168 ms
12,588 KB |
testcase_25 | AC | 156 ms
11,888 KB |
testcase_26 | AC | 13 ms
6,816 KB |
testcase_27 | AC | 82 ms
7,552 KB |
testcase_28 | AC | 84 ms
7,552 KB |
testcase_29 | AC | 159 ms
11,940 KB |
testcase_30 | AC | 88 ms
7,936 KB |
testcase_31 | AC | 140 ms
10,892 KB |
testcase_32 | AC | 153 ms
11,488 KB |
testcase_33 | AC | 44 ms
6,820 KB |
testcase_34 | AC | 127 ms
7,536 KB |
testcase_35 | AC | 14 ms
6,816 KB |
testcase_36 | AC | 76 ms
6,816 KB |
testcase_37 | AC | 35 ms
6,820 KB |
testcase_38 | AC | 106 ms
6,820 KB |
testcase_39 | AC | 71 ms
6,820 KB |
testcase_40 | AC | 138 ms
7,808 KB |
testcase_41 | AC | 79 ms
6,816 KB |
testcase_42 | AC | 140 ms
7,848 KB |
testcase_43 | AC | 164 ms
8,608 KB |
testcase_44 | AC | 2 ms
6,820 KB |
testcase_45 | RE | - |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:101:17: warning: 'S' may be used uninitialized [-Wmaybe-uninitialized] 101 | cout << S + 1 << endl; | ^ main.cpp:95:9: note: 'S' was declared here 95 | int S; | ^
ソースコード
#include <bits/stdc++.h> using namespace std; int main(){ int N, Q; cin >> N >> Q; vector<int> A(Q); for (int i = 0; i < Q; i++){ cin >> A[i]; A[i]--; } vector<int> B(Q); for (int i = 0; i < Q; i++){ cin >> B[i]; B[i]--; } for (int i = 0; i < Q; i++){ if (A[i] > B[i]){ swap(A[i], B[i]); } } vector<vector<int>> E(Q * 2 + 2); for (int i = 0; i < Q; i++){ if (A[i] == 0){ E[Q * 2].push_back(i * 2); } if (B[i] == 0){ E[Q * 2].push_back(i * 2 + 1); } if (A[i] == N - 1){ E[i * 2].push_back(Q * 2 + 1); } if (B[i] == N - 1){ E[i * 2 + 1].push_back(Q * 2 + 1); } if (abs(A[i] - B[i]) == 1){ E[i * 2].push_back(i * 2 + 1); E[i * 2 + 1].push_back(i * 2); } if (i > 0){ if (A[i] == A[i - 1]){ E[i * 2 - 2].push_back(i * 2); E[i * 2].push_back(i * 2 - 2); } if (A[i] == B[i - 1]){ E[i * 2 - 1].push_back(i * 2); E[i * 2].push_back(i * 2 - 1); } if (B[i] == A[i - 1]){ E[i * 2 - 2].push_back(i * 2 + 1); E[i * 2 + 1].push_back(i * 2 - 2); } if (B[i] == B[i - 1]){ E[i * 2 - 1].push_back(i * 2 + 1); E[i * 2 + 1].push_back(i * 2 - 1); } } } vector<bool> used(Q * 2 + 2, false); used[Q * 2] = true; queue<int> q; q.push(Q * 2); while (!q.empty()){ int v = q.front(); q.pop(); for (int w : E[v]){ if (!used[w]){ used[w] = true; q.push(w); } } } if (used[Q * 2 + 1]){ cout << "NO" << endl; } else { vector<int> L(Q, 0), R(Q, N - 1); for (int i = Q - 1; i >= 0; i--){ if (i < Q - 1){ L[i] = max(L[i + 1] - 1, 0); R[i] = min(R[i + 1] + 1, N - 1); } if (A[i] == L[i]){ L[i]++; } if (B[i] == L[i]){ L[i]++; } if (B[i] == R[i]){ R[i]--; } if (A[i] == R[i]){ R[i]--; } } cout << "YES" << endl; int S; for (int i = L[0] - 1; i <= R[0] + 1; i++){ if (0 <= i && i < N && i != A[0] && i != B[0]){ S = i; } } cout << S + 1 << endl; for (int i = 0; i < Q; i++){ int K = -1; for (int j = S - 1; j <= S + 1; j++){ if (L[i] <= j && j <= R[i] && j != A[i] && j != B[i]){ K = j; break; } } assert(K != -1); S = K; cout << K + 1 << endl; } } }