結果
問題 | No.1508 Avoid being hit |
ユーザー | SSRS |
提出日時 | 2021-05-15 00:00:50 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,458 bytes |
コンパイル時間 | 2,065 ms |
コンパイル使用メモリ | 179,548 KB |
実行使用メモリ | 14,848 KB |
最終ジャッジ日時 | 2024-10-02 06:40:02 |
合計ジャッジ時間 | 7,289 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 161 ms
13,012 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | RE | - |
testcase_07 | AC | 2 ms
6,816 KB |
testcase_08 | AC | 2 ms
6,820 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,820 KB |
testcase_13 | AC | 2 ms
6,820 KB |
testcase_14 | AC | 2 ms
6,816 KB |
testcase_15 | AC | 2 ms
6,820 KB |
testcase_16 | AC | 62 ms
13,344 KB |
testcase_17 | AC | 37 ms
9,216 KB |
testcase_18 | AC | 30 ms
7,424 KB |
testcase_19 | AC | 52 ms
12,032 KB |
testcase_20 | AC | 76 ms
14,848 KB |
testcase_21 | AC | 52 ms
11,008 KB |
testcase_22 | AC | 63 ms
12,912 KB |
testcase_23 | AC | 69 ms
13,552 KB |
testcase_24 | AC | 169 ms
12,660 KB |
testcase_25 | AC | 153 ms
11,792 KB |
testcase_26 | AC | 12 ms
5,248 KB |
testcase_27 | AC | 83 ms
7,552 KB |
testcase_28 | AC | 80 ms
7,680 KB |
testcase_29 | AC | 159 ms
11,956 KB |
testcase_30 | AC | 89 ms
7,936 KB |
testcase_31 | AC | 143 ms
10,880 KB |
testcase_32 | AC | 148 ms
11,608 KB |
testcase_33 | AC | 42 ms
5,632 KB |
testcase_34 | AC | 129 ms
7,552 KB |
testcase_35 | AC | 14 ms
5,248 KB |
testcase_36 | AC | 76 ms
5,760 KB |
testcase_37 | AC | 34 ms
5,248 KB |
testcase_38 | AC | 107 ms
6,656 KB |
testcase_39 | AC | 68 ms
5,504 KB |
testcase_40 | AC | 136 ms
7,788 KB |
testcase_41 | AC | 79 ms
5,760 KB |
testcase_42 | AC | 139 ms
7,828 KB |
testcase_43 | AC | 161 ms
8,552 KB |
testcase_44 | AC | 2 ms
5,248 KB |
testcase_45 | RE | - |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:102:17: warning: 'S' may be used uninitialized [-Wmaybe-uninitialized] 102 | 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]; i <= R[0]; i++){ if (i != A[0] && i != B[0]){ S = i; break; } } 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; } } }