結果

問題 No.1650 Moving Coins
ユーザー kappybar
提出日時 2021-09-23 11:58:48
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 355 ms / 2,000 ms
コード長 1,427 bytes
コンパイル時間 1,469 ms
コンパイル使用メモリ 176,456 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2024-07-05 09:25:42
合計ジャッジ時間 11,667 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:51:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   51 |     for(auto [i,c]:ans) cout << i+1 << " " << c << endl;
      |              ^

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define chmin(x,y) x = min((x),(y))
#define chmax(x,y) x = max((x),(y))
#define popcount(x) __builtin_popcountll(x)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
const int INF = 1e9;
const long long LINF = 1e17;
const int MOD = 1000000007;
//const int MOD = 998244353;
const double PI = 3.14159265358979323846;

int main(){
    int n;
    cin >> n;
    vector<int> a(n),b(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];

    queue<int> q;
    auto ok = [&](int i) -> bool {
        if (!(0 <= i && i < n)) return false;
        if (a[i] == b[i]) {
            return true;
        } else if (a[i] < b[i]) {
            if (i == n-1 || b[i] < a[i+1]) return true;
        } else if (b[i] < a[i]) {
            if (i == 0 || a[i-1] < b[i]) return true;
        }
        return false;
    };

    rep(i,n){
        if (ok(i)) q.push(i);
    }

    vector<pair<int,char>> ans;
    while(!q.empty()){
        int i = q.front();
        q.pop();
        while(a[i] < b[i]) {ans.emplace_back(i,'R'); ++a[i];}
        while(a[i] > b[i]) {ans.emplace_back(i,'L'); --a[i];}
        if (ok(i-1) && a[i-1] != b[i-1]) q.push(i-1);
        if (ok(i+1) && a[i+1] != b[i+1]) q.push(i+1);
    }

    cout << ans.size() << endl;
    for(auto [i,c]:ans) cout << i+1 << " " << c << endl;


    return 0;
}
0