結果

問題 No.2100 [Cherry Alpha C] Two-way Steps
ユーザー sapphire__15sapphire__15
提出日時 2022-08-09 13:24:59
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 948 bytes
コンパイル時間 851 ms
コンパイル使用メモリ 72,348 KB
最終ジャッジ日時 2025-01-30 19:40:53
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other WA * 11 RE * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

bool dfs(const int l, const int r) {
    if(l == r) return true;
    used[l][r] = true;
    for(auto &dl : {1, -1}) for(auto &dr : {-1, 1}) {
        int nl = l + dl,
            nr = r + dr;
        if(0 <= nl && nr <= n && a[nl] == a[nr] && !used[nl][nr]) {
            if(dfs(nl, nr)) {
                s += dl == 1 ? "R" : "L"; 
                t += dr == 1 ? "R" : "L"; 
                return true;
            }
        }
    }
    return false;
}

int main() {
    cin >> n;
    for(int i = 0; i <= n; i++) cin >> a[i];
    if(dfs(0, n)) {
        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