結果

問題 No.1014 competitive fighting
ユーザー kotatsugamekotatsugame
提出日時 2020-03-25 02:37:01
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 341 ms / 2,000 ms
コード長 1,331 bytes
コンパイル時間 851 ms
コンパイル使用メモリ 80,916 KB
実行使用メモリ 31,044 KB
最終ジャッジ日時 2023-09-21 19:26:17
合計ジャッジ時間 13,184 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
9,648 KB
testcase_01 AC 5 ms
9,584 KB
testcase_02 AC 4 ms
9,856 KB
testcase_03 AC 5 ms
9,628 KB
testcase_04 AC 5 ms
9,532 KB
testcase_05 AC 339 ms
21,100 KB
testcase_06 AC 336 ms
21,144 KB
testcase_07 AC 340 ms
21,444 KB
testcase_08 AC 339 ms
21,152 KB
testcase_09 AC 341 ms
21,260 KB
testcase_10 AC 308 ms
31,044 KB
testcase_11 AC 276 ms
17,264 KB
testcase_12 AC 338 ms
21,440 KB
testcase_13 AC 160 ms
15,064 KB
testcase_14 AC 145 ms
14,600 KB
testcase_15 AC 175 ms
15,688 KB
testcase_16 AC 11 ms
9,824 KB
testcase_17 AC 64 ms
11,908 KB
testcase_18 AC 280 ms
19,692 KB
testcase_19 AC 333 ms
20,956 KB
testcase_20 AC 118 ms
14,220 KB
testcase_21 AC 254 ms
19,168 KB
testcase_22 AC 204 ms
15,992 KB
testcase_23 AC 81 ms
12,304 KB
testcase_24 AC 84 ms
12,240 KB
testcase_25 AC 22 ms
10,320 KB
testcase_26 AC 248 ms
19,172 KB
testcase_27 AC 64 ms
11,776 KB
testcase_28 AC 71 ms
12,056 KB
testcase_29 AC 7 ms
9,644 KB
testcase_30 AC 325 ms
20,992 KB
testcase_31 AC 258 ms
19,400 KB
testcase_32 AC 7 ms
9,612 KB
testcase_33 AC 23 ms
10,312 KB
testcase_34 AC 212 ms
16,184 KB
testcase_35 AC 280 ms
17,176 KB
testcase_36 AC 198 ms
15,948 KB
testcase_37 AC 11 ms
10,072 KB
testcase_38 AC 174 ms
13,636 KB
testcase_39 AC 89 ms
11,668 KB
testcase_40 AC 170 ms
13,532 KB
testcase_41 AC 122 ms
13,132 KB
testcase_42 AC 271 ms
16,976 KB
testcase_43 AC 19 ms
10,312 KB
testcase_44 AC 245 ms
16,920 KB
testcase_45 AC 145 ms
13,380 KB
testcase_46 AC 29 ms
10,696 KB
testcase_47 AC 82 ms
11,760 KB
testcase_48 AC 206 ms
16,196 KB
testcase_49 AC 13 ms
9,788 KB
testcase_50 AC 259 ms
16,776 KB
testcase_51 AC 149 ms
13,344 KB
testcase_52 AC 14 ms
9,864 KB
testcase_53 AC 336 ms
21,100 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:40:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   40 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int N;
int A[1<<17],B[1<<17],C[1<<17];
int invi[1<<17],invinvi[1<<17];
vector<int>G[2<<17];
int n;
long memo[2<<17];
bool vis[2<<17];
void add_edge(int a,int b,int fm,int k,int l,int r)
{
	if(b<=l||r<=a)return;
	else if(a<=l&&r<=b)
	{
		G[fm].push_back(k);
	}
	else
	{
		add_edge(a,b,fm,k*2+1,l,(l+r)/2);
		add_edge(a,b,fm,k*2+2,(l+r)/2,r);
	}
}
long dfs(int u)
{
	if(vis[u])return memo[u];
	memo[u]=-1;
	vis[u]=true;
	long t=0;
	for(int v:G[u])
	{
		long k=dfs(v);
		if(k==-1)return-1;
		t=max(t,k);
	}
	if(u>=n-1)t+=B[invinvi[u-(n-1)]];
	return memo[u]=t;
}
main()
{
	cin>>N;
	n=1;
	while(n<N)n<<=1;
	for(int i=0;i<n-1;i++)
	{
		G[i].push_back(i*2+1);
		G[i].push_back(i*2+2);
	}
	vector<pair<int,int> >ai(N);
	for(int i=0;i<N;i++)
	{
		cin>>A[i]>>B[i]>>C[i];
		ai[i]=make_pair(A[i],i);
	}
	sort(ai.begin(),ai.end());
	for(int i=0;i<N;i++)invi[invinvi[i]=ai[i].second]=i;
	for(int i=0;i<N;i++)
	{
		int R=upper_bound(ai.begin(),ai.end(),make_pair(B[i]-C[i],N))-ai.begin();
		if(invi[i]<R)
		{
			add_edge(0,invi[i],n-1+invi[i],0,0,n);
			add_edge(invi[i]+1,R,n-1+invi[i],0,0,n);
		}
		else
		{
			add_edge(0,R,n-1+invi[i],0,0,n);
		}
	}
	for(int i=0;i<N;i++)
	{
		long ans=dfs(n-1+invi[i]);
		if(ans==-1)cout<<"BAN"<<endl;
		else cout<<ans<<endl;
	}
}
0