結果

問題 No.1650 Moving Coins
ユーザー chocoruskchocorusk
提出日時 2021-07-17 18:06:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 471 ms / 2,000 ms
コード長 1,182 bytes
コンパイル時間 1,134 ms
コンパイル使用メモリ 88,288 KB
実行使用メモリ 14,592 KB
最終ジャッジ日時 2024-04-22 03:25:02
合計ジャッジ時間 11,915 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 253 ms
5,376 KB
testcase_04 AC 195 ms
5,376 KB
testcase_05 AC 219 ms
5,376 KB
testcase_06 AC 250 ms
5,376 KB
testcase_07 AC 267 ms
5,376 KB
testcase_08 AC 342 ms
6,528 KB
testcase_09 AC 341 ms
5,376 KB
testcase_10 AC 352 ms
6,528 KB
testcase_11 AC 344 ms
6,016 KB
testcase_12 AC 306 ms
5,376 KB
testcase_13 AC 308 ms
5,376 KB
testcase_14 AC 370 ms
5,632 KB
testcase_15 AC 305 ms
5,376 KB
testcase_16 AC 356 ms
6,784 KB
testcase_17 AC 334 ms
6,912 KB
testcase_18 AC 375 ms
6,784 KB
testcase_19 AC 356 ms
5,376 KB
testcase_20 AC 373 ms
5,376 KB
testcase_21 AC 378 ms
5,376 KB
testcase_22 AC 471 ms
14,592 KB
testcase_23 AC 433 ms
14,464 KB
testcase_24 AC 284 ms
5,376 KB
testcase_25 AC 261 ms
5,376 KB
testcase_26 AC 119 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
using ll=long long;
const int MAXA=1000000;
const int MAXN=200000;
const int MAXM=200000;
int a[MAXN+1], b[MAXN+1];
int main()
{
	int n;
	cin>>n;
	for(int i=0; i<n; i++) cin>>a[i];
	for(int i=0; i<n; i++) cin>>b[i];
	int m=0;
	for(int i=0; i<n; i++) m+=abs(a[i]-b[i]);
	cout<<m<<endl;
    set<int> stl, str;
    for(int i=0; i<n; i++){
        if(a[i]>b[i] && (i==0 || a[i]-a[i-1]>1)) stl.insert(i);
        else if(a[i]<b[i] && (i==n-1 || a[i+1]-a[i]>1)) str.insert(i);
    }
    for(int i=0; i<m; i++){
        if(stl.empty()){
            int k=*str.begin();
            str.erase(k);
            cout<<k+1<<" R"<<endl;
            a[k]++;
            if(a[k]<b[k] && (k==n-1 || a[k+1]-a[k]>1)) str.insert(k);
            if(k-1>=0 && a[k-1]<b[k-1] && a[k]-a[k-1]>1) str.insert(k-1);
        }else{
            int k=*stl.begin();
            stl.erase(k);
            cout<<k+1<<" L"<<endl;
            a[k]--;
            if(a[k]>b[k] && (k==0 || a[k]-a[k-1]>1)) stl.insert(k);
            if(k+1<n && a[k+1]>b[k+1] && a[k+1]-a[k]>1) stl.insert(k+1);
        }
    }
    return 0;
}
0