結果

問題 No.1650 Moving Coins
ユーザー milanis48663220milanis48663220
提出日時 2021-08-20 21:55:21
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 323 ms / 2,000 ms
コード長 1,675 bytes
コンパイル時間 1,357 ms
コンパイル使用メモリ 124,108 KB
実行使用メモリ 6,756 KB
最終ジャッジ日時 2023-08-04 06:20:54
合計ジャッジ時間 12,406 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 256 ms
4,376 KB
testcase_04 AC 191 ms
4,376 KB
testcase_05 AC 238 ms
4,380 KB
testcase_06 AC 272 ms
4,376 KB
testcase_07 AC 267 ms
4,380 KB
testcase_08 AC 295 ms
4,980 KB
testcase_09 AC 300 ms
4,808 KB
testcase_10 AC 301 ms
4,876 KB
testcase_11 AC 305 ms
4,896 KB
testcase_12 AC 295 ms
4,384 KB
testcase_13 AC 299 ms
4,380 KB
testcase_14 AC 310 ms
4,912 KB
testcase_15 AC 293 ms
4,380 KB
testcase_16 AC 309 ms
5,092 KB
testcase_17 AC 291 ms
5,044 KB
testcase_18 AC 305 ms
5,124 KB
testcase_19 AC 318 ms
6,704 KB
testcase_20 AC 316 ms
6,640 KB
testcase_21 AC 319 ms
6,708 KB
testcase_22 AC 323 ms
6,756 KB
testcase_23 AC 315 ms
6,744 KB
testcase_24 AC 251 ms
4,380 KB
testcase_25 AC 256 ms
4,380 KB
testcase_26 AC 38 ms
4,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

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; }

using namespace std;
typedef long long ll;
using P = pair<int, int>;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    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];

    priority_queue<P> que;
    int m = 0;
    for(int i = 0; i < n; i++) m += abs(a[i]-b[i]);
    auto push = [&](int i){
        if(a[i] < b[i]){
            que.push(P(abs(a[i]-b[i]), i));
        }
        if(a[i] > b[i]){
            que.push(P(abs(a[i]-b[i]), -i));
        }
    };
    for(int i = 0; i < n; i++) push(i);
    cout << m << endl;
    while(!que.empty()){
        auto [d, _i] = que.top(); que.pop();
        int i = abs(_i);
        if(d == 0) continue;
        if(a[i] < b[i]) {
            a[i]++;
            cout << i+1 << ' ' << 'R' << endl;
        }else{
            a[i]--;
            cout << i+1 << ' ' << 'L' << endl;
        }
        // for(int i = 0; i < n; i++) cout << a[i] << ' ';
        // cout << endl;
        push(i);
    }
}
0