結果

問題 No.1650 Moving Coins
ユーザー kappybarkappybar
提出日時 2021-09-23 11:58:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 391 ms / 2,000 ms
コード長 1,427 bytes
コンパイル時間 2,125 ms
コンパイル使用メモリ 175,332 KB
実行使用メモリ 7,432 KB
最終ジャッジ日時 2023-09-18 19:51:19
合計ジャッジ時間 13,927 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 261 ms
5,228 KB
testcase_04 AC 199 ms
5,396 KB
testcase_05 AC 244 ms
5,168 KB
testcase_06 AC 264 ms
5,228 KB
testcase_07 AC 270 ms
5,036 KB
testcase_08 AC 315 ms
6,212 KB
testcase_09 AC 331 ms
5,872 KB
testcase_10 AC 331 ms
6,088 KB
testcase_11 AC 337 ms
6,084 KB
testcase_12 AC 305 ms
5,664 KB
testcase_13 AC 306 ms
5,752 KB
testcase_14 AC 336 ms
5,920 KB
testcase_15 AC 295 ms
5,532 KB
testcase_16 AC 336 ms
6,296 KB
testcase_17 AC 328 ms
6,476 KB
testcase_18 AC 362 ms
6,508 KB
testcase_19 AC 380 ms
6,836 KB
testcase_20 AC 386 ms
6,796 KB
testcase_21 AC 387 ms
6,604 KB
testcase_22 AC 391 ms
7,432 KB
testcase_23 AC 379 ms
7,432 KB
testcase_24 AC 269 ms
5,228 KB
testcase_25 AC 268 ms
5,232 KB
testcase_26 AC 115 ms
5,424 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:51:14: 警告: 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