結果

問題 No.1950 片道きゃっちぼーる
ユーザー 沙耶花沙耶花
提出日時 2022-05-20 22:00:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 703 ms / 3,000 ms
コード長 1,333 bytes
コンパイル時間 4,586 ms
コンパイル使用メモリ 272,852 KB
実行使用メモリ 89,924 KB
最終ジャッジ日時 2023-10-20 12:40:06
合計ジャッジ時間 17,816 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 AC 2 ms
4,368 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 568 ms
89,924 KB
testcase_04 AC 542 ms
58,772 KB
testcase_05 AC 2 ms
4,368 KB
testcase_06 AC 478 ms
62,612 KB
testcase_07 AC 596 ms
77,568 KB
testcase_08 AC 703 ms
77,312 KB
testcase_09 AC 560 ms
63,448 KB
testcase_10 AC 573 ms
58,772 KB
testcase_11 AC 567 ms
58,772 KB
testcase_12 AC 559 ms
58,772 KB
testcase_13 AC 511 ms
45,452 KB
testcase_14 AC 478 ms
32,584 KB
testcase_15 AC 678 ms
64,392 KB
testcase_16 AC 489 ms
46,772 KB
testcase_17 AC 2 ms
4,368 KB
testcase_18 AC 581 ms
68,140 KB
testcase_19 AC 686 ms
64,656 KB
testcase_20 AC 565 ms
58,772 KB
testcase_21 AC 498 ms
34,696 KB
testcase_22 AC 498 ms
34,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001


int main() {
    
	int n;
	cin>>n;
	vector<long long> a(n),x(n);
	rep(i,n)cin>>x[i];
	rep(i,n)cin>>a[i];
	
	vector<long long> t = x;
	rep(i,n){
		t.push_back(x[i]+a[i]);
		t.push_back(x[i]-a[i]);
	}
	
	sort(t.begin(),t.end());
	t.erase(unique(t.begin(),t.end()),t.end());
	
	scc_graph S(t.size());
	
	vector<vector<int>> E(t.size());
	rep(i,n){
		int d0 = distance(t.begin(),lower_bound(t.begin(),t.end(),x[i]));
		int d1 = distance(t.begin(),lower_bound(t.begin(),t.end(),x[i]+a[i]));
		E[d0].push_back(d1);
		S.add_edge(d0,d1);
		d1 = distance(t.begin(),lower_bound(t.begin(),t.end(),x[i]-a[i]));
		E[d0].push_back(d1);
		S.add_edge(d0,d1);
	}
	
	auto s = S.scc();
	
	vector<int> pos(t.size());
	rep(i,s.size()){
		rep(j,s[i].size())pos[s[i][j]] = i;
	}
	
	vector<long long> dp(t.size(),-Inf);
	for(int i=s.size()-1;i>=0;i--){
		long long m = -Inf;
		rep(j,s[i].size()){
			m = max(m,t[s[i][j]]);
			rep(k,E[s[i][j]].size())m = max(m,dp[E[s[i][j]][k]]);
		}
		rep(j,s[i].size()){
			dp[s[i][j]] = m;
		}
	}
	rep(i,n){
		int d0 = distance(t.begin(),lower_bound(t.begin(),t.end(),x[i]));
		cout<<dp[d0] - x[i]<<endl;
	}
	
    return 0;
}
0