結果

問題 No.1650 Moving Coins
ユーザー chocoruskchocorusk
提出日時 2021-07-17 18:10:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 936 bytes
コンパイル時間 931 ms
コンパイル使用メモリ 86,116 KB
実行使用メモリ 19,584 KB
最終ジャッジ日時 2024-04-22 03:24:48
合計ジャッジ時間 8,055 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
19,584 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 18 ms
5,376 KB
testcase_04 AC 13 ms
5,376 KB
testcase_05 AC 16 ms
5,376 KB
testcase_06 AC 18 ms
5,376 KB
testcase_07 AC 18 ms
5,376 KB
testcase_08 AC 108 ms
8,704 KB
testcase_09 AC 124 ms
8,704 KB
testcase_10 AC 109 ms
8,704 KB
testcase_11 AC 114 ms
8,960 KB
testcase_12 AC 77 ms
6,912 KB
testcase_13 AC 81 ms
6,912 KB
testcase_14 AC 105 ms
8,448 KB
testcase_15 AC 59 ms
6,400 KB
testcase_16 AC 125 ms
9,216 KB
testcase_17 AC 123 ms
9,216 KB
testcase_18 AC 134 ms
9,728 KB
testcase_19 TLE -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

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> st;
    for(int i=0; i<n; i++) if(a[i]!=b[i]) st.insert(i);
    for(int i=0; i<m; i++){
        for(auto j:st){
            if(a[j]<b[j] && (j==n-1 || a[j]+1!=a[j+1])){
                printf("%d R\n", j+1);
                a[j]++;
                if(a[j]==b[j]) st.erase(j);
                break;
            }
            if(a[j]>b[j] && (j==0 || a[j]-1!=a[j-1])){
                printf("%d L\n", j+1);
                a[j]--;
                if(a[j]==b[j]) st.erase(j);
                break;
            }
        }
    }
    return 0;
}
0