제출 #1127509

#제출 시각아이디문제언어결과실행 시간메모리
1127509AgageldiTug of War (BOI15_tug)C++20
18 / 100
405 ms836 KiB
/* ID: agageld1 LANG: C++17 TASK: */ #include <bits/stdc++.h> using namespace std; #define ll long long #define N 400005 #define ff first #define ss second #define pb push_back #define sz(s) (int)s.size() #define rep(c, a, b) for(c = a; c <= b; c++) //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); ll n, t, l[N], r[N], b[N], p, sum, s[N], k; map <int,int> v, m; void solve(int x) { if(x == 2*n + 1) { sum = 0; v.clear(); m.clear(); ll g1 = 0, g2 = 0; for(int i = 1; i <= 2*n; i++){ if(b[i]) { if(m[l[i]]) return; m[l[i]] = 1; sum -= s[i]; g2++; } else { if(v[r[i]]) return; v[r[i]] = 1; sum += s[i]; g1++; } } if(abs(sum) > k || g1 != g2) return; cout << "YES\n"; exit(0); return; } for(int i = 0; i <= 1; i++) { b[x] = i; solve(x + 1); } } int main () { ios::sync_with_stdio(0);cin.tie(0); cin >> n >> k; bool tr = 0; for(int i= 1; i <= n * 2;i++) { cin >> l[i] >> r[i] >> s[i]; } if(n > 10) { if(!k)cout << "YES\n"; else cout << "NO\n"; return 0; } solve(1); cout << "NO\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...