結果

問題 No.1014 competitive fighting
ユーザー leaf_1415leaf_1415
提出日時 2020-03-25 04:11:43
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 464 ms / 2,000 ms
コード長 3,250 bytes
コンパイル時間 2,334 ms
コンパイル使用メモリ 93,600 KB
実行使用メモリ 149,612 KB
最終ジャッジ日時 2023-09-21 19:29:31
合計ジャッジ時間 18,885 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
52,504 KB
testcase_01 AC 123 ms
52,556 KB
testcase_02 AC 121 ms
52,384 KB
testcase_03 AC 124 ms
52,548 KB
testcase_04 AC 122 ms
52,464 KB
testcase_05 AC 431 ms
78,604 KB
testcase_06 AC 439 ms
78,600 KB
testcase_07 AC 440 ms
78,452 KB
testcase_08 AC 433 ms
78,608 KB
testcase_09 AC 442 ms
78,684 KB
testcase_10 AC 464 ms
149,612 KB
testcase_11 AC 328 ms
60,060 KB
testcase_12 AC 421 ms
78,640 KB
testcase_13 AC 258 ms
64,204 KB
testcase_14 AC 248 ms
63,192 KB
testcase_15 AC 271 ms
65,348 KB
testcase_16 AC 126 ms
52,596 KB
testcase_17 AC 174 ms
56,484 KB
testcase_18 AC 365 ms
73,572 KB
testcase_19 AC 416 ms
77,980 KB
testcase_20 AC 218 ms
60,620 KB
testcase_21 AC 353 ms
71,340 KB
testcase_22 AC 312 ms
67,732 KB
testcase_23 AC 199 ms
57,804 KB
testcase_24 AC 200 ms
58,272 KB
testcase_25 AC 145 ms
53,448 KB
testcase_26 AC 354 ms
71,364 KB
testcase_27 AC 177 ms
56,584 KB
testcase_28 AC 186 ms
57,084 KB
testcase_29 AC 126 ms
52,772 KB
testcase_30 AC 429 ms
77,548 KB
testcase_31 AC 372 ms
72,212 KB
testcase_32 AC 128 ms
52,676 KB
testcase_33 AC 137 ms
52,628 KB
testcase_34 AC 275 ms
57,548 KB
testcase_35 AC 321 ms
59,440 KB
testcase_36 AC 258 ms
57,176 KB
testcase_37 AC 129 ms
52,712 KB
testcase_38 AC 245 ms
56,888 KB
testcase_39 AC 185 ms
54,660 KB
testcase_40 AC 240 ms
56,760 KB
testcase_41 AC 208 ms
55,316 KB
testcase_42 AC 317 ms
59,288 KB
testcase_43 AC 136 ms
52,684 KB
testcase_44 AC 296 ms
58,444 KB
testcase_45 AC 222 ms
55,952 KB
testcase_46 AC 137 ms
53,220 KB
testcase_47 AC 179 ms
54,500 KB
testcase_48 AC 266 ms
57,472 KB
testcase_49 AC 131 ms
52,920 KB
testcase_50 AC 306 ms
58,884 KB
testcase_51 AC 230 ms
55,892 KB
testcase_52 AC 133 ms
52,720 KB
testcase_53 AC 435 ms
78,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define eps 1e-9

using namespace std;
typedef pair<llint, llint> P;

struct edge{
	llint to, cost;
	edge(){}
	edge(llint a, llint b){
		to = a, cost = b;
	}
};

llint n;
llint a[100005], b[100005], c[100005];
P p[100005];
vector<edge> G[1<<18], revG[1<<18];
llint N = 1<<17;

vector<int> topo;
bool used[1<<18];
int scc[1<<18];

map<llint, llint> mp;
llint dp[1<<18];
llint ans[100005];

void tpsort(int v)
{
	used[v] = true;
	for(int i = 0; i < G[v].size(); i++){
		if(!used[G[v][i].to]) tpsort(G[v][i].to);
	}
	topo.push_back(v);
}
void sccdfs(int v, int id)
{
	used[v] = true;
	scc[v] = id;
	for(int i = 0; i < revG[v].size(); i++){
		if(!used[revG[v][i].to]) sccdfs(revG[v][i].to, id);
	}
}

void add(int a, int b, int k, int l, int r, llint s, llint c)
{
	if(b < l || r < a) return ;
	if(a <= l && r <= b){
		G[s+N].push_back(edge(k, c));
		return;
	}
	add(a, b, k*2, l, (l+r)/2, s, c);
	add(a, b, k*2+1, (l+r)/2+1, r, s, c);
}
void add(int a, int b, llint s, llint c)
{
	if(a > b) return;
	//cout << a << " " << b << " " << s << " " << c << endl;
	return add(a, b, 1, 0, N-1, s, c);
}

void dfs(int v)
{
	used[v] = true;
	for(int i = 0; i < revG[v].size(); i++){
		if(!used[revG[v][i].to]) dfs(revG[v][i].to);
	}
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i] >> b[i] >> c[i];
	
	for(int i = 1; i <= n; i++) p[i] = P(a[i], i);
	sort(p+1, p+n+1);
	p[0] = P(-inf, 0);
	
	for(int i = 0; i < N; i++){
		G[i].push_back(edge(i*2, 0));
		G[i].push_back(edge(i*2+1, 0));
	}
	
	for(llint i = 1; i <= n; i++){
		llint id = p[i].second;
		llint pos = upper_bound(p, p+n+1, P(b[id]-c[id], inf)) - p;
		add(0, min(i-1, pos-1), i, b[id]);
		add(i+1, pos-1, i, b[id]);
	}
	
	for(int i = 0; i < 2*N; i++){
		for(int j = 0; j < G[i].size(); j++){
			revG[G[i][j].to].push_back(edge(i, G[i][j].cost));
		}
	}
	
	for(int i = 0; i < 2*N; i++) if(!used[i]) tpsort(i);
	reverse(topo.begin(), topo.end());
	
	int id = 0;
	for(int i = 0; i < 2*N; i++) used[i] = false;
	for(int i = 0; i < topo.size(); i++) if(!used[topo[i]]) sccdfs(topo[i], id++);
	
	for(int i = 0; i < 2*N; i++) mp[scc[i]]++, used[i] = false;;
	for(int i = 0; i < 2*N; i++){
		if(!used[i] && mp[scc[i]] >= 2) dfs(i);
	}
	
	for(int i = 0; i < 2*N; i++) dp[i] = -inf;
	dp[N] = 0;
	reverse(topo.begin(), topo.end());
	for(int i = 0; i < topo.size(); i++){
		llint v = topo[i];
		if(used[v]) continue;
		for(int j = 0; j < revG[v].size(); j++){
			llint u = revG[v][j].to;
			if(used[u]) continue;
			dp[u] = max(dp[u], dp[v] + revG[v][j].cost);
		}
	}
	
	for(int i = 1; i <= n; i++){
		llint id = p[i].second;
		if(used[N+i]) ans[id] = -1;
		else ans[id] = dp[N+i];
	}
	
	for(int i = 1; i <= n; i++){
		if(ans[i] == -1) cout << "BAN" << endl;
		else cout << ans[i] << endl;
	}
	
	return 0;
}
0