結果
| 問題 | 
                            No.1508 Avoid being hit
                             | 
                    
| コンテスト | |
| ユーザー | 
                             vwxyz
                         | 
                    
| 提出日時 | 2023-07-18 11:44:04 | 
| 言語 | C++17(clang)  (17.0.6 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                MLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,218 bytes | 
| コンパイル時間 | 3,404 ms | 
| コンパイル使用メモリ | 123,520 KB | 
| 実行使用メモリ | 814,724 KB | 
| 最終ジャッジ日時 | 2024-09-18 11:04:33 | 
| 合計ジャッジ時間 | 4,576 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | -- * 3 | 
| other | MLE * 1 -- * 42 | 
ソースコード
#include <iostream>
#include <vector>
#include <bitset>
using namespace std;
int main() {
    int N, Q;
    cin >> N >> Q;
    vector<int> A(Q);
    vector<int> B(Q);
    for (int q = 0; q < Q; ++q) {
        cin >> A[q];
        A[q] -= 1;
    }
    for (int q = 0; q < Q; ++q) {
        cin >> B[q];
        B[q] -= 1;
    }
    vector<bitset<100000>> dp(Q + 1);
    dp[0] = (1 << N) - 1;
    for (int q = 1; q <= Q; ++q) {
        dp[q] = dp[q - 1] >> 1 | dp[q - 1] | dp[q - 1] << 1;
        dp[q] &= ~(1 << N | 1 << A[q - 1] | 1 << B[q - 1]);
    }
    if (dp[Q].any()) {
        cout << "YES" << endl;
        int x;
        for (x = 0; x < N; ++x) {
            if (dp[Q][x]) {
                break;
            }
        }
        vector<int> ans_lst;
        ans_lst.push_back(x);
        for (int q = Q - 1; q >= 0; --q) {
            if (x - 1 >= 0 && dp[q][x - 1]) {
                x -= 1;
            } else if (x + 1 < N && dp[q][x + 1]) {
                x += 1;
            }
            ans_lst.push_back(x);
        }
        for (int i = ans_lst.size() - 1; i >= 0; --i) {
            cout << ans_lst[i] + 1 << endl;
        }
    } else {
        cout << "NO" << endl;
    }
    return 0;
}
            
            
            
        
            
vwxyz