結果

問題 No.3779 L or R
コンテスト
ユーザー GOTKAKO
提出日時 2026-10-30 21:30:18
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 8 ms / 2,000 ms
+ 117µs
コード長 1,425 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,593 ms
コンパイル使用メモリ 222,916 KB
実行使用メモリ 9,920 KB
最終ジャッジ日時 2026-10-30 21:30:23
合計ジャッジ時間 4,693 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N; cin >> N;
    string s; cin >> s;

    {
        string t = "";
        t += 'L';
        for(int i=1; i<N; i++){
            if(s.at(i) == s.at(i-1)) t += t.back()^'L'^'R';
            else t += t.back();
        } 
        int l = 0,r = 0;
        string S = "";
        for(auto c : t) r += c=='L';
        int pos = 0;
        for(auto c : t){
            if(c == 'R') l++;
            if((r+l)%2) S += s.at(pos)^'o'^'x';
            else S += s.at(pos);
            pos++;
            if(c == 'L') r--;
        }
        bool ok = true;
        for(auto c : S) if(c == 'x') ok = false;
        if(ok){cout << "Yes\n" << t << "\n"; return 0;}
    }
    {
        string t = "";
        t += 'R';
        for(int i=1; i<N; i++){
            if(s.at(i) == s.at(i-1)) t += t.back()^'L'^'R';
            else t += t.back();
        } 
        int l = 0,r = 0;
        string S = "";
        for(auto c : t) r += c=='L';
        int pos = 0;
        for(auto c : t){
            if(c == 'R') l++;
            if((r+l)%2) S += s.at(pos)^'o'^'x';
            else S += s.at(pos);
            pos++;
            if(c == 'L') r--;
        }
        bool ok = true;
        for(auto c : S) if(c == 'x') ok = false;
        if(ok){cout << "Yes\n" << t << "\n"; return 0;}
    }
    cout << "No\n";
}
0