結果

問題 No.1650 Moving Coins
ユーザー abc3abc3
提出日時 2021-08-20 23:25:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,798 bytes
コンパイル時間 2,095 ms
コンパイル使用メモリ 205,672 KB
実行使用メモリ 7,828 KB
最終ジャッジ日時 2024-04-22 07:58:07
合計ジャッジ時間 12,789 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 WA -
testcase_04 AC 174 ms
6,940 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 278 ms
6,940 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 293 ms
7,700 KB
testcase_20 AC 285 ms
7,700 KB
testcase_21 AC 297 ms
7,704 KB
testcase_22 AC 290 ms
7,696 KB
testcase_23 AC 290 ms
7,828 KB
testcase_24 AC 243 ms
6,944 KB
testcase_25 AC 239 ms
6,944 KB
testcase_26 AC 50 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

    #include <bits/stdc++.h>
    using namespace std;
    #include <math.h>
    #include <iomanip>
    #include <cstdint>
    #include <string>
    #include <sstream>
    template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
    template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
    #define rep(i,n) for (int i = 0; i < (n); ++i)
    typedef long long ll;
    using P=pair<ll,ll>;
    const int INF=1001001001;
    const int mod=1e9+7;

    void solve(){
        int n;
        cin>>n;
        vector<int>a(n+2),b(n+1);
        for(int i=1;i<=n;i++) cin>>a[i];
        for(int i=1;i<=n;i++) cin>>b[i];
        a[0]=-INF;a[n+1]=INF;

        queue<int> q;
        int mn=INF,j=-1;
        for(int i=1;i<=n;i++){
            int p=upper_bound(a.begin(),a.end(),b[i])-a.begin();
            p--;
            if(p<1){p++;}
            if(p-i==0){j=i;}
        }
        q.push(j);
        vector<pair<int,char>>ans;
        vector<int>seen(n+1);
        seen[j]=1;
        while(!q.empty()){
            int p=q.front();q.pop();
            seen[p]=1;
            while(abs(b[p]-a[p])){
                if(b[p]-a[p]>0){
                    ans.emplace_back(p,'R');
                    a[p]++;
                }
                else{
                    ans.emplace_back(p,'L');
                    a[p]--;
                }
            }
            if(p+1<=n&&!seen[p+1]){q.push(p+1);seen[p+1]=1;}
            if(p-1>=1&&!seen[p-1]){q.push(p-1);seen[p-1]=1;}
        }
        cout<<ans.size()<<endl;
        for(auto u:ans){
            cout<<u.first<<" "<<u.second<<endl;
        }
    }  

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

        solve();   

        return 0;
    }
0