結果

問題 No.1950 片道きゃっちぼーる
ユーザー kwm_tkwm_t
提出日時 2022-05-20 23:01:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,934 bytes
コンパイル時間 6,127 ms
コンパイル使用メモリ 287,908 KB
実行使用メモリ 111,504 KB
最終ジャッジ日時 2023-10-20 13:54:47
合計ジャッジ時間 18,861 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 491 ms
69,416 KB
testcase_04 AC 497 ms
69,416 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 398 ms
37,776 KB
testcase_07 AC 572 ms
83,412 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 463 ms
54,672 KB
testcase_12 AC 462 ms
62,032 KB
testcase_13 AC 455 ms
51,756 KB
testcase_14 AC 366 ms
40,920 KB
testcase_15 WA -
testcase_16 AC 406 ms
37,776 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 461 ms
54,684 KB
testcase_21 AC 413 ms
42,352 KB
testcase_22 AC 407 ms
42,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
map<long long, int> Compless(const vector<long long> &v) {
	vector<long long>vv = v;
	sort(all(vv));
	vv.erase(unique(all(vv)), vv.end());
	map<long long, int>mp;
	rep(i, vv.size()) mp[vv[i]] = i;
	return mp;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n; cin >> n;
	vector<long long>x(n), a(n);
	rep(i, n)cin >> x[i];
	rep(i, n)cin >> a[i];
	set<long long>st;
	rep(i, n) {
		st.insert(x[i]);
		st.insert(x[i] + a[i]);
		if (x[i] >= a[i])st.insert(x[i] - a[i]);
	}
	vector<long long>v;
	for (auto e : st)v.push_back(e);
	sort(all(v));
	v.erase(unique(all(v)), v.end());
	auto mp = Compless(v);
	dsu uf(v.size());
	rep(i, n) {
		long long s = x[i];
		long long t = x[i] + a[i];
		long long u = x[i] - a[i];
		uf.merge(mp[s], mp[t]);
		if (u >= 0) {
			uf.merge(mp[s], mp[u]);
		}
	}
	map<int, long long>mp2;
	auto g = uf.groups();
	for (auto v : g) {
		long long mx = -1;
		rep(i, v.size()) {
			chmax(mx, v[i]);
		}
		mp2[uf.leader(v[0])] = mx;
	}
	rep(i, n) {
		long long dist = v[mp2[uf.leader(mp[x[i]])]];
		long long ans = dist - x[i];
		cout << ans << endl;
	}
	return 0;
}
0