結果

問題 No.1650 Moving Coins
ユーザー milanis48663220milanis48663220
提出日時 2021-08-20 21:55:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 335 ms / 2,000 ms
コード長 1,675 bytes
コンパイル時間 1,637 ms
コンパイル使用メモリ 123,492 KB
実行使用メモリ 6,916 KB
最終ジャッジ日時 2024-04-22 04:26:02
合計ジャッジ時間 12,576 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 281 ms
5,376 KB
testcase_04 AC 194 ms
5,376 KB
testcase_05 AC 246 ms
5,376 KB
testcase_06 AC 268 ms
5,376 KB
testcase_07 AC 274 ms
5,376 KB
testcase_08 AC 301 ms
5,376 KB
testcase_09 AC 307 ms
5,376 KB
testcase_10 AC 315 ms
5,376 KB
testcase_11 AC 312 ms
5,376 KB
testcase_12 AC 313 ms
5,376 KB
testcase_13 AC 301 ms
5,376 KB
testcase_14 AC 314 ms
5,376 KB
testcase_15 AC 310 ms
5,376 KB
testcase_16 AC 321 ms
5,376 KB
testcase_17 AC 299 ms
5,424 KB
testcase_18 AC 334 ms
5,564 KB
testcase_19 AC 331 ms
6,916 KB
testcase_20 AC 330 ms
6,916 KB
testcase_21 AC 334 ms
6,916 KB
testcase_22 AC 335 ms
6,916 KB
testcase_23 AC 331 ms
6,916 KB
testcase_24 AC 256 ms
5,376 KB
testcase_25 AC 262 ms
5,376 KB
testcase_26 AC 45 ms
5,376 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