結果

問題 No.1650 Moving Coins
ユーザー 👑 CleyLCleyL
提出日時 2022-01-11 11:23:48
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 397 ms / 2,000 ms
コード長 1,036 bytes
コンパイル時間 739 ms
コンパイル使用メモリ 81,432 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2024-11-14 11:30:34
合計ジャッジ時間 11,809 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <stack>
using namespace std;
int main(){
    int n;cin>>n;
    vector<int> A(n),B(n);
    for(int i = 0; n > i; i++){
        cin>>A[i];
    }
    for(int i = 0; n > i; i++){
        cin>>B[i];
    }
    vector<pair<int,char>> C;
    stack<int> D;
    for(int i = 0; n > i; i++){
        if(A[i]>=B[i]){
            while(D.size()){
                int x = D.top();D.pop();
                while(A[x-1]!=B[x-1]){
                    C.push_back({x,'R'});
                    A[x-1]++;
                }
            }
            while(A[i]!=B[i]){
                C.push_back({i+1,'L'});
                A[i]--;
            }
        }else if(A[i] < B[i]){
            D.push(i+1);
        }
    }
    while(D.size()){
        int x = D.top();D.pop();
        while(A[x-1]!=B[x-1]){
            C.push_back({x,'R'});
            A[x-1]++;
        }
    }
    cout << C.size() << endl;
    for(int i = 0; C.size() > i; i++){
        cout << C[i].first << " " << C[i].second << endl;
    }
}
0