結果
問題 | No.1508 Avoid being hit |
ユーザー | SSRS |
提出日時 | 2021-05-15 00:02:52 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 179 ms / 3,000 ms |
コード長 | 2,666 bytes |
コンパイル時間 | 2,159 ms |
コンパイル使用メモリ | 181,116 KB |
実行使用メモリ | 14,696 KB |
最終ジャッジ日時 | 2024-10-02 07:13:28 |
合計ジャッジ時間 | 7,733 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 164 ms
13,336 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 | AC | 2 ms
5,248 KB |
testcase_07 | AC | 2 ms
5,248 KB |
testcase_08 | AC | 2 ms
5,248 KB |
testcase_09 | AC | 2 ms
5,248 KB |
testcase_10 | AC | 2 ms
5,248 KB |
testcase_11 | AC | 2 ms
5,248 KB |
testcase_12 | AC | 2 ms
5,248 KB |
testcase_13 | AC | 2 ms
5,248 KB |
testcase_14 | AC | 2 ms
5,248 KB |
testcase_15 | AC | 2 ms
5,248 KB |
testcase_16 | AC | 65 ms
13,348 KB |
testcase_17 | AC | 38 ms
9,344 KB |
testcase_18 | AC | 30 ms
7,424 KB |
testcase_19 | AC | 54 ms
12,032 KB |
testcase_20 | AC | 80 ms
14,696 KB |
testcase_21 | AC | 54 ms
11,124 KB |
testcase_22 | AC | 64 ms
13,056 KB |
testcase_23 | AC | 73 ms
13,568 KB |
testcase_24 | AC | 179 ms
13,004 KB |
testcase_25 | AC | 161 ms
12,288 KB |
testcase_26 | AC | 13 ms
5,248 KB |
testcase_27 | AC | 84 ms
7,808 KB |
testcase_28 | AC | 84 ms
7,808 KB |
testcase_29 | AC | 164 ms
12,404 KB |
testcase_30 | AC | 91 ms
8,320 KB |
testcase_31 | AC | 144 ms
11,156 KB |
testcase_32 | AC | 155 ms
11,980 KB |
testcase_33 | AC | 44 ms
5,632 KB |
testcase_34 | AC | 136 ms
7,936 KB |
testcase_35 | AC | 15 ms
5,248 KB |
testcase_36 | AC | 76 ms
5,888 KB |
testcase_37 | AC | 35 ms
5,248 KB |
testcase_38 | AC | 109 ms
6,912 KB |
testcase_39 | AC | 71 ms
5,632 KB |
testcase_40 | AC | 141 ms
8,192 KB |
testcase_41 | AC | 82 ms
6,144 KB |
testcase_42 | AC | 142 ms
8,160 KB |
testcase_43 | AC | 168 ms
8,936 KB |
testcase_44 | AC | 2 ms
5,248 KB |
testcase_45 | AC | 2 ms
5,248 KB |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:102:12: warning: 'S' may be used uninitialized [-Wmaybe-uninitialized] 102 | ans[0] = S; main.cpp:94:9: note: 'S' was declared here 94 | 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]--; } } 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; } } bool ok = true; vector<int> ans(Q + 1); ans[0] = S; 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; } } if (K == -1){ ok = false; break; } S = K; ans[i + 1] = K; } if (!ok){ cout << "NO" << endl; } else { cout << "YES" << endl; for (int i = 0; i <= Q; i++){ cout << ans[i] + 1 << endl; } } } }