結果

問題 No.2100 [Cherry Alpha C] Two-way Steps
ユーザー sapphire__15sapphire__15
提出日時 2022-08-09 13:49:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,731 bytes
コンパイル時間 1,069 ms
コンパイル使用メモリ 94,204 KB
実行使用メモリ 6,276 KB
最終ジャッジ日時 2023-09-08 19:52:48
合計ジャッジ時間 7,857 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 RE -
testcase_45 WA -
testcase_46 WA -
testcase_47 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cassert>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#include <utility>
using namespace std;

int n;
int a[1100];
string s, t;

bool bfs() {
    vector<vector<pair<char, char>>> prv(n+1, vector<pair<char, char>>(n+1));
    vector<vector<bool>> used(n+1, vector<bool>(n+1));
    queue<pair<int, int>> q;
    q.push({0, n});
    used[0][n] = true;
    const pair<char, char> START = {'0', 'n'};
    prv[0][n] = START;
    while(!q.empty()) {
        auto [l, r] = q.front();
        if(l == r) break;
        q.pop();
        for(auto &dl : {1, -1}) for(auto &dr : {-1, 1}) {
            int nl = l + dl,
                nr = r + dr;
            if(0 <= nl && nr <= n && nl <= nr && !used[nl][nr] && a[nl] == a[nr]) {
                used[nl][nr] = true;
                prv[nl][nr] = { dl == 1 ? 'R' : 'L',
                                dr == 1 ? 'R' : 'L'};
                q.push({nl, nr});
            }
        }
    }
    for(int i = 0; i <= n; i++) {
        if(used[i][i]) {
            int l = i, r = i;
            while(prv[l][r] != START) {
                s += prv[l][r].first;
                t += prv[l][r].second;
                if(s.back() == 'L') l++;
                else l--;
                if(t.back() == 'L') r++;
                else r--;
            }
            return true;
        }
    }
    return false;
}

int main() {
    cin >> n;
    for(int i = 0; i <= n; i++) cin >> a[i];
    if(bfs()) {
        cout << "Yes" << endl;
        reverse(s.begin(), s.end());
        reverse(t.begin(), t.end());
        cout << s.size() << endl;
        cout << s << endl;
        cout << t << endl;
    } else {
        cout << "No" << endl;
    }
}
0