結果
問題 | No.1650 Moving Coins |
ユーザー |
![]() |
提出日時 | 2021-08-20 22:10:49 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 556 ms / 2,000 ms |
コード長 | 1,818 bytes |
コンパイル時間 | 1,849 ms |
コンパイル使用メモリ | 176,464 KB |
実行使用メモリ | 28,160 KB |
最終ジャッジ日時 | 2024-10-14 03:56:28 |
合計ジャッジ時間 | 14,932 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
ソースコード
#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; }