結果

問題 No.1650 Moving Coins
ユーザー HaaHaa
提出日時 2021-08-20 22:10:49
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 574 ms / 2,000 ms
コード長 1,818 bytes
コンパイル時間 1,835 ms
コンパイル使用メモリ 173,168 KB
実行使用メモリ 28,288 KB
最終ジャッジ日時 2024-04-22 04:49:28
合計ジャッジ時間 15,631 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 268 ms
6,940 KB
testcase_04 AC 198 ms
6,944 KB
testcase_05 AC 245 ms
6,940 KB
testcase_06 AC 272 ms
6,940 KB
testcase_07 AC 274 ms
6,944 KB
testcase_08 AC 436 ms
13,184 KB
testcase_09 AC 442 ms
12,288 KB
testcase_10 AC 453 ms
13,440 KB
testcase_11 AC 574 ms
13,440 KB
testcase_12 AC 377 ms
8,448 KB
testcase_13 AC 386 ms
8,576 KB
testcase_14 AC 500 ms
12,032 KB
testcase_15 AC 355 ms
7,296 KB
testcase_16 AC 480 ms
14,720 KB
testcase_17 AC 463 ms
15,104 KB
testcase_18 AC 530 ms
16,640 KB
testcase_19 AC 556 ms
28,160 KB
testcase_20 AC 555 ms
28,288 KB
testcase_21 AC 554 ms
28,288 KB
testcase_22 AC 562 ms
28,288 KB
testcase_23 AC 559 ms
28,032 KB
testcase_24 AC 267 ms
6,940 KB
testcase_25 AC 273 ms
6,940 KB
testcase_26 AC 187 ms
18,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
template<typename T> bool chmax(T &x, const T &y) {return (x<y)?(x=y,true):false;};
template<typename T> bool chmin(T &x, const T &y) {return (x>y)?(x=y,true):false;};
constexpr ll MOD=998244353;
constexpr ll INF=2e18;

int main() {
    int n; cin >> n;
    VI a(n), b(n);
    REP(i,n) cin >> a[i];
    REP(i,n) cin >> b[i];
    set<int> s;
    int ans=0;
    REP(i,n){
        int d=abs(a[i]-b[i]);
        ans+=d;
        s.insert(i);
    }
    cout << ans << endl;
    VI c(n,-1), f(n,0);
    while(ans){
        for(auto i:s){
            c[i]=-1;
            f[i]=0;
        }
        for(auto i:s){
            if(i<n-1&&a[i]<b[i]&&a[i+1]!=b[i+1]&&a[i]+1==a[i+1]){
                c[i+1]=i;
                f[i]=1;
            }
            else if(i>0&&a[i]>b[i]&&a[i-1]!=b[i-1]&&a[i]-1==a[i-1]){
                c[i-1]=i;
                f[i]=1;
            }       
        }
        set<int> es;
        for(auto i:s){
            if(!f[i]){
                int now=i;
                while(now!=-1){
                    if(a[now]==b[now]) break;
                    if(a[now]<b[now]){
                        a[now]++;
                        cout << now+1 << " R" << endl;
                    }
                    else{
                        a[now]--;
                        cout << now+1 << " L" << endl;
                    }
                    if(a[now]==b[now]){
                        es.insert(now);
                    }
                    ans--;
                    now=c[now];
                }
            }
        }
        for(auto i:es) s.erase(i);
    }
    return 0;
}
0