結果
| 問題 |
No.2643 Many Range Sums Problems
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-02-19 23:00:20 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,298 bytes |
| コンパイル時間 | 773 ms |
| コンパイル使用メモリ | 79,572 KB |
| 実行使用メモリ | 10,788 KB |
| 最終ジャッジ日時 | 2024-09-29 02:43:56 |
| 合計ジャッジ時間 | 32,903 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 TLE * 1 -- * 19 |
コンパイルメッセージ
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])
| ^
ソースコード
#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");
}