結果

問題 No.1650 Moving Coins
ユーザー CleyLCleyL
提出日時 2022-01-11 11:23:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 403 ms / 2,000 ms
コード長 1,036 bytes
コンパイル時間 944 ms
コンパイル使用メモリ 79,796 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2024-04-26 20:33:51
合計ジャッジ時間 13,102 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 248 ms
5,580 KB
testcase_04 AC 188 ms
5,448 KB
testcase_05 AC 233 ms
5,456 KB
testcase_06 AC 263 ms
5,576 KB
testcase_07 AC 262 ms
5,456 KB
testcase_08 AC 319 ms
6,412 KB
testcase_09 AC 331 ms
6,372 KB
testcase_10 AC 327 ms
6,492 KB
testcase_11 AC 345 ms
6,460 KB
testcase_12 AC 307 ms
6,060 KB
testcase_13 AC 303 ms
5,952 KB
testcase_14 AC 327 ms
6,216 KB
testcase_15 AC 295 ms
5,832 KB
testcase_16 AC 341 ms
6,536 KB
testcase_17 AC 328 ms
6,560 KB
testcase_18 AC 379 ms
6,820 KB
testcase_19 AC 381 ms
7,848 KB
testcase_20 AC 403 ms
7,020 KB
testcase_21 AC 391 ms
7,560 KB
testcase_22 AC 402 ms
7,148 KB
testcase_23 AC 391 ms
7,044 KB
testcase_24 AC 266 ms
5,708 KB
testcase_25 AC 263 ms
5,456 KB
testcase_26 AC 125 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

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