結果

問題 No.2643 Many Range Sums Problems
ユーザー kotatsugamekotatsugame
提出日時 2024-02-19 23:00:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,298 bytes
コンパイル時間 1,102 ms
コンパイル使用メモリ 78,368 KB
実行使用メモリ 10,772 KB
最終ジャッジ日時 2024-02-19 23:00:56
合計ジャッジ時間 34,230 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 5 ms
6,676 KB
testcase_04 AC 6 ms
6,676 KB
testcase_05 AC 5 ms
6,676 KB
testcase_06 AC 4 ms
6,676 KB
testcase_07 AC 4 ms
6,676 KB
testcase_08 AC 5,689 ms
6,676 KB
testcase_09 TLE -
testcase_10 AC 4 ms
6,676 KB
testcase_11 AC 3 ms
6,676 KB
testcase_12 AC 7,972 ms
6,676 KB
testcase_13 AC 1,435 ms
6,676 KB
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'bool check(std::vector<int>)':
main.cpp:34:46: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   34 |                 for(int u=0;u<=N;u++)for(auto[v,c]:G[u])
      |                                              ^

ソースコード

diff #

#include<iostream>
#include<vector>
#include<cassert>
using namespace std;
int N,K;
int R[5000];
long X[5000];
long dist[5001];
bool use[5000];
vector<pair<int,long> >G[5001];
bool check(vector<int>s)
{
	for(int i=0;i<=N;i++)
	{
		G[i].clear();
		dist[i]=1e18;
	}
	for(int i=0;i<N;i++)
	{
		use[i]=true;
		G[i].push_back(make_pair(i+1,K));
		G[i+1].push_back(make_pair(i,0));
	}
	for(int i:s)use[i]=false;
	for(int i=0;i<N;i++)if(use[i])
	{
		G[i].push_back(make_pair(R[i],X[i]));
		G[R[i]].push_back(make_pair(i,-X[i]));
	}
	dist[0]=0;
	for(int t=0;t<=N+2;t++)
	{
		bool ch=false;
		for(int u=0;u<=N;u++)for(auto[v,c]:G[u])
		{
			if(dist[v]>dist[u]+c)
			{
				dist[v]=dist[u]+c;
				ch=true;
			}
		}
		if(!ch)return true;
	}
	return false;
}
bool ans[5000];
void solve(vector<int>del)
{
	assert(!del.empty());
	if(del.size()==1)
	{
		ans[del[0]]=true;
		return;
	}
	vector<int>L,R;
	for(int i:del)
	{
		L.push_back(i);
		swap(L,R);
	}
	if(check(L))solve(L);
	if(check(R))solve(R);
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin>>N>>K;
	for(int i=0;i<N;i++)cin>>R[i]>>X[i];
	if(check(vector<int>()))
	{
		for(int i=0;i<N;i++)cout<<"Yes\n";
		return 0;
	}
	vector<int>del(N);
	for(int i=0;i<N;i++)del[i]=i;
	solve(del);
	for(int i=0;i<N;i++)cout<<(ans[i]?"Yes\n":"No\n");
}
0