結果

問題 No.1650 Moving Coins
ユーザー nawawannawawan
提出日時 2021-08-20 21:50:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 305 ms / 2,000 ms
コード長 1,132 bytes
コンパイル時間 2,357 ms
コンパイル使用メモリ 204,532 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2024-04-22 04:19:00
合計ジャッジ時間 12,520 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 256 ms
5,376 KB
testcase_04 AC 191 ms
5,376 KB
testcase_05 AC 233 ms
5,376 KB
testcase_06 AC 262 ms
5,376 KB
testcase_07 AC 255 ms
5,376 KB
testcase_08 AC 278 ms
5,504 KB
testcase_09 AC 275 ms
5,632 KB
testcase_10 AC 281 ms
5,888 KB
testcase_11 AC 288 ms
5,888 KB
testcase_12 AC 269 ms
5,376 KB
testcase_13 AC 272 ms
5,376 KB
testcase_14 AC 284 ms
5,504 KB
testcase_15 AC 264 ms
5,376 KB
testcase_16 AC 288 ms
5,760 KB
testcase_17 AC 268 ms
5,760 KB
testcase_18 AC 294 ms
6,144 KB
testcase_19 AC 305 ms
6,400 KB
testcase_20 AC 301 ms
6,400 KB
testcase_21 AC 298 ms
6,400 KB
testcase_22 AC 301 ms
6,400 KB
testcase_23 AC 303 ms
6,400 KB
testcase_24 AC 263 ms
5,376 KB
testcase_25 AC 268 ms
5,376 KB
testcase_26 AC 42 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    for(int i = 0; i < N; i++) cin >> B[i];
    int ind = 0;
    queue<pair<int, char>> ans;
    stack<int> s;
    for(int i = 0; i < N; i++){
        if(A[i] > B[i]){
            while(A[i] > B[i]){
                ans.push({i + 1, 'L'});
                A[i]--;
            }
        }
        else{
            if(i != N - 1 && A[i + 1] <= B[i]){
                s.push(i);
            }
            else{
                while(A[i] < B[i]){
                    ans.push({i + 1, 'R'});
                    A[i]++;
                }
            }
        }
    }
    while(!s.empty()){
        int now = s.top();
        s.pop();
        while(A[now] < B[now]){
            ans.push({now + 1, 'R'});
            A[now]++;
        }
    }
    cout << ans.size() << endl;
    while(!ans.empty()){
        pair<int, char> t = ans.front();
        cout << t.first << ' ' << (char)t.second << endl;
        ans.pop();
    }
}
0