結果
| 問題 |
No.1650 Moving Coins
|
| コンテスト | |
| ユーザー |
chocorusk
|
| 提出日時 | 2021-07-17 18:06:57 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 459 ms / 2,000 ms |
| コード長 | 1,182 bytes |
| コンパイル時間 | 666 ms |
| コンパイル使用メモリ | 84,604 KB |
| 最終ジャッジ日時 | 2025-01-23 03:01:56 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 |
ソースコード
#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;
}
chocorusk