# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1021848 | guagua0407 | Tug of War (BOI15_tug) | C++17 | 26 ms | 860 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
int main() {_
int n,k;
cin>>n>>k;
vector<int> l(2*n),r(2*n),S(2*n);
int all=0;
for(int i=0;i<2*n;i++){
cin>>l[i]>>r[i]>>S[i];
l[i]--;
r[i]--;
all+=S[i];
}
for(int i=0;i<(1<<(2*n));i++){
if(__builtin_popcount(i)!=n) continue;
vector<int> L(n),R(n);
bool tf=true;
int sum=0;
for(int j=0;j<2*n;j++){
if(i&(1<<j)){
if(L[l[j]]) tf=false;
L[l[j]]=1;
sum+=S[j];
}
else{
if(R[r[j]]) tf=false;
R[r[j]]=1;
}
}
if(!tf) continue;
if(abs(sum-(all-sum))<=k){
cout<<"YES"<<'\n';
return 0;
}
}
cout<<"NO"<<'\n';
return 0;
}
//maybe its multiset not set
//yeeorz
//laborz
Compilation message (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... |