結果

問題 No.1650 Moving Coins
ユーザー yamakeyamake
提出日時 2021-08-20 22:20:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,749 bytes
コンパイル時間 2,314 ms
コンパイル使用メモリ 182,160 KB
実行使用メモリ 13,824 KB
最終ジャッジ日時 2024-04-22 05:03:10
合計ジャッジ時間 9,734 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:35:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   35 |     auto [sub,i]=que.top();que.pop();
      |          ^

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define debug(output) if(debugFlag)cout<<#output<<"= "<<output<<endl
using lint = long long;
typedef pair<int,int> P;
const bool debugFlag=true;
const lint linf=1e18+7;
const lint inf=1e9+7;
const int MOD=1000000007;
bool hoge(P a,P b){
  a.first=abs(a.first);
  b.first=abs(b.first);
  return a>b;
}
signed main(){
  int n;cin>>n;
  vector<int> a(n),b(n);
  rep(i,n)cin>>a[i];
  rep(i,n)cin>>b[i];
  vector<pair<int,char>> res;
  set<int> memo;
  rep(i,n)memo.insert(a[i]);
  priority_queue<P,vector<P>,function<bool(P,P)>> que(hoge);
  rep(i,n){
    if(a[i]!=b[i]){
      que.push({b[i]-a[i],i});
    }
  }
  memo.insert(inf);
  memo.insert(-inf);
  while(!que.empty()){
    auto [sub,i]=que.top();que.pop();
    if(sub<0){
      auto it=memo.lower_bound(b[i]);
      if(*it==a[i]){
        rep(x,-sub)res.push_back({i+1,'L'});
        a[i]=b[i];
        memo.erase(it);
        memo.insert(b[i]);
      }
      else{
        it=memo.find(a[i]);
        --it;
        rep(x,a[i]-(*it+1))res.push_back({i+1,'L'});
        a[i]=*it+1;
        sub=b[i]-a[i];
        if(sub==0)continue;
        que.push({sub,i});
      }
    }
    else{
      auto it=memo.upper_bound(a[i]);
      if(*it>b[i]){
        rep(x,sub)res.push_back({i+1,'R'});
        memo.erase(a[i]);
        memo.insert(b[i]);
      }
      else{
        rep(x,*it-1-a[i])res.push_back({i+1,'R'});
        memo.erase(a[i]);
        a[i]=*it-1;
        memo.insert(a[i]);
        if(sub==0)continue;
        que.push({b[i]-a[i],i});
      }
    }
  }
  cout<<res.size()<<"\n";
  for(auto& val:res){
    cout<<val.first<<" "<<val.second<<"\n";
  }
  return 0;
}
0