# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
130045 | nikolapesic2802 | Tug of War (BOI15_tug) | C++14 | 5 ms | 3704 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define D(x) cerr << #x << " is " << (x) << "\n";
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
//9:20
const int N=6e4+1,M=6e5+1;
vector<int> degree(N),visited(N);
vector<set<pair<int,int> > > graf(N);
int dif,n,k,a,b,c;
void dfs(int tr)
{
if(graf[tr].size()==0)
return;
int sl=(*graf[tr].begin()).f;
int t=(*graf[tr].begin()).s;
graf[tr].erase(graf[tr].begin());
graf[sl].erase({tr,t});
if(tr<n)
dif+=t;
else
dif-=t;
dfs(sl);
}
bitset<2*M> moze;
int main()
{
freopen("in.txt","r",stdin);
scanf("%i %i",&n,&k);
for(int i=0;i<2*n;i++)
scanf("%i %i %i",&a,&b,&c),a--,b+=n-1,graf[a].insert({b,c}),graf[b].insert({a,c}),degree[a]++,degree[b]++;
queue<int> q;
for(int i=0;i<2*n;i++)
if(degree[i]==1)
q.push(i);
while(q.size())
{
int tr=q.front();
q.pop();
visited[tr]=1;
int sl=(*graf[tr].begin()).f;
int t=(*graf[tr].begin()).s;
graf[tr].erase(graf[tr].begin());
degree[tr]--;
degree[sl]--;
graf[sl].erase({tr,t});
if(degree[sl]==1)
q.push(sl);
if(tr<n)
dif+=t;
else
dif-=t;
}
vector<int> dp={abs(dif)};
dif=0;
for(int i=0;i<2*n;i++)
{
if(!visited[i])
{
if(degree[i]==0)
{
printf("NO\n");
return 0;
}
assert(degree[i]==2);
dfs(i);
dp.pb(abs(dif));
dif=0;
}
}
sort(dp.rbegin(),dp.rend());
while(dp.size()&&dp.back()==0)
dp.pop_back();
if(dp.empty())
{
printf("YES\n");
return 0;
}
moze[M]=1;
for(auto p:dp)
moze=(moze<<p)|(moze>>p);
bool ima=false;
for(int i=M;i<=M+k;i++)
if(moze[i])
ima=true;
if(ima)
printf("YES\n");
else
printf("NO\n");
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |