結果

問題 No.1950 片道きゃっちぼーる
ユーザー 蜜蜂蜜蜂
提出日時 2022-05-06 02:03:38
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2,036 ms / 3,000 ms
コード長 1,514 bytes
コンパイル時間 4,260 ms
コンパイル使用メモリ 245,920 KB
実行使用メモリ 93,728 KB
最終ジャッジ日時 2023-09-18 12:31:19
合計ジャッジ時間 27,036 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 899 ms
68,752 KB
testcase_04 AC 900 ms
68,880 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 826 ms
37,516 KB
testcase_07 AC 1,115 ms
93,728 KB
testcase_08 AC 1,900 ms
93,580 KB
testcase_09 AC 999 ms
68,044 KB
testcase_10 AC 848 ms
63,492 KB
testcase_11 AC 828 ms
63,532 KB
testcase_12 AC 833 ms
63,392 KB
testcase_13 AC 932 ms
48,104 KB
testcase_14 AC 887 ms
40,640 KB
testcase_15 AC 2,036 ms
68,880 KB
testcase_16 AC 828 ms
37,544 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 987 ms
81,172 KB
testcase_19 AC 1,989 ms
68,756 KB
testcase_20 AC 778 ms
63,396 KB
testcase_21 AC 920 ms
43,936 KB
testcase_22 AC 894 ms
43,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//g++ 2.cpp -std=c++14 -O2 -I .
#include <bits/stdc++.h>
using namespace std;

#include <atcoder/all>
using namespace atcoder;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vst = vector<string>;
using vvst = vector<vst>;

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define pq_big(T) priority_queue<T,vector<T>,less<T>>
#define pq_small(T) priority_queue<T,vector<T>,greater<T>>
#define all(a) a.begin(),a.end()
#define rep(i,start,end) for(ll i=start;i<(ll)(end);i++)
#define per(i,start,end) for(ll i=start;i>=(ll)(end);i--)
#define uniq(a) sort(all(a));a.erase(unique(all(a)),a.end())

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin>>n;

  vi x(n),a(n);
  rep(i,0,n)cin>>x[i];
  rep(i,0,n)cin>>a[i];

  map<int,vi> g;
  vi st;
  rep(i,0,n){
    g[x[i]+a[i]].emplace_back(x[i]);
    g[x[i]-a[i]].emplace_back(x[i]);

    st.emplace_back(x[i]-a[i]);
    st.emplace_back(x[i]+a[i]);
  }

  uniq(st);
  reverse(all(st));

  map<int,int> opt;
  for(int v:st){
    opt[v]=v;
  }

  for(int v:st){
    queue<int> que;
    que.push(v);

    while(!que.empty()){
      int fr=que.front();
      que.pop();

      for(int nxt:g[fr]){
        if(opt[nxt]<opt[fr]){
          opt[nxt]=opt[fr];
          que.push(nxt);
        }
      }
    }
  }

  rep(i,0,n){
    cout<<opt[x[i]]-x[i]<<endl;
  }
}
0