# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1022719 | 2024-07-14T03:51:13 Z | guagua0407 | Tug of War (BOI15_tug) | C++17 | 196 ms | 2600 KB |
//#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); } const int mxn=6e4+5; int l[mxn],r[mxn],S[mxn]; bool vis[mxn]; int main() {_ int n,k; cin>>n>>k; vector<vector<int>> ls(n),rs(n); int all=0; for(int i=0;i<2*n;i++){ cin>>l[i]>>r[i]>>S[i]; all+=S[i]; l[i]--; r[i]--; ls[l[i]].push_back(i); rs[r[i]].push_back(i); } int ans=0; for(int i=0;i<2*n;i++){ if(vis[i]) continue; { int cnt=0; for(auto v:ls[l[i]]){ if(!vis[v]) cnt++; } if(cnt==1){ int x=i; while(x!=-1){ vis[x]=true; ans+=S[x]; int cnt2=0; int nxt; for(auto v:rs[r[x]]){ if(!vis[v]){ cnt2++; nxt=v; } } if(cnt2!=1){ cout<<"NO"<<'\n'; return 0; } x=nxt; vis[x]=true; cnt2=0; for(auto v:ls[l[x]]){ if(!vis[v]){ cnt2++; nxt=v; } } if(cnt2==1){ x=nxt; } else{ x=-1; } } } } if(vis[i]) continue; { int cnt=0; for(auto v:rs[r[i]]){ if(!vis[v]) cnt++; } if(cnt==1){ int x=i; while(x!=-1){ vis[x]=true; int cnt2=0; int nxt; for(auto v:ls[l[x]]){ if(!vis[v]){ cnt2++; nxt=v; } } if(cnt2!=1){ cout<<"NO"<<'\n'; return 0; } x=nxt; vis[x]=true; ans+=S[x]; cnt2=0; for(auto v:rs[r[x]]){ if(!vis[v]){ cnt2++; nxt=v; } } if(cnt2==1){ x=nxt; } else{ x=-1; } } } } } vector<int> cand; for(int i=0;i<2*n;i++){ if(vis[i]) continue; int x=i; int a=0; int b=0; int state=0; while(x!=-1){ vis[x]=true; if(state==0){ state=1; a+=S[x]; bool tf=false; for(auto v:ls[l[x]]){ if(!vis[v]){ x=v; tf=true; break; } } if(!tf) x=-1; } else{ state=0; b+=S[x]; bool tf=false; for(auto v:rs[r[x]]){ if(!vis[v]){ x=v; tf=true; break; } } if(!tf) x=-1; } } ans+=a; cand.push_back(b-a); } bitset<mxn*20> b; b[ans]=1; for(auto v:cand){ if(v>=0) b|=(b<<v); else b|=(b>>(-v)); } int cur=all/2; while((all-cur)-cur<=k){ if(b[cur] or b[all-cur]){ cout<<"YES"<<'\n'; return 0; } cur--; } cout<<"NO"<<'\n'; return 0; } //maybe its multiset not set //yeeorz //laborz
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 860 KB | Output is correct |
2 | Correct | 2 ms | 1028 KB | Output is correct |
3 | Correct | 1 ms | 860 KB | Output is correct |
4 | Correct | 1 ms | 860 KB | Output is correct |
5 | Correct | 1 ms | 860 KB | Output is correct |
6 | Correct | 1 ms | 860 KB | Output is correct |
7 | Correct | 1 ms | 860 KB | Output is correct |
8 | Correct | 1 ms | 860 KB | Output is correct |
9 | Correct | 1 ms | 912 KB | Output is correct |
10 | Correct | 1 ms | 860 KB | Output is correct |
11 | Correct | 1 ms | 860 KB | Output is correct |
12 | Correct | 1 ms | 860 KB | Output is correct |
13 | Correct | 1 ms | 860 KB | Output is correct |
14 | Correct | 1 ms | 856 KB | Output is correct |
15 | Correct | 1 ms | 860 KB | Output is correct |
16 | Correct | 1 ms | 860 KB | Output is correct |
17 | Correct | 1 ms | 912 KB | Output is correct |
18 | Correct | 1 ms | 860 KB | Output is correct |
19 | Correct | 1 ms | 856 KB | Output is correct |
20 | Correct | 1 ms | 860 KB | Output is correct |
21 | Correct | 1 ms | 860 KB | Output is correct |
22 | Incorrect | 1 ms | 860 KB | Output isn't correct |
23 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 860 KB | Output is correct |
2 | Correct | 2 ms | 1028 KB | Output is correct |
3 | Correct | 1 ms | 860 KB | Output is correct |
4 | Correct | 1 ms | 860 KB | Output is correct |
5 | Correct | 1 ms | 860 KB | Output is correct |
6 | Correct | 1 ms | 860 KB | Output is correct |
7 | Correct | 1 ms | 860 KB | Output is correct |
8 | Correct | 1 ms | 860 KB | Output is correct |
9 | Correct | 1 ms | 912 KB | Output is correct |
10 | Correct | 1 ms | 860 KB | Output is correct |
11 | Correct | 1 ms | 860 KB | Output is correct |
12 | Correct | 1 ms | 860 KB | Output is correct |
13 | Correct | 1 ms | 860 KB | Output is correct |
14 | Correct | 1 ms | 856 KB | Output is correct |
15 | Correct | 1 ms | 860 KB | Output is correct |
16 | Correct | 1 ms | 860 KB | Output is correct |
17 | Correct | 1 ms | 912 KB | Output is correct |
18 | Correct | 1 ms | 860 KB | Output is correct |
19 | Correct | 1 ms | 856 KB | Output is correct |
20 | Correct | 1 ms | 860 KB | Output is correct |
21 | Correct | 1 ms | 860 KB | Output is correct |
22 | Incorrect | 1 ms | 860 KB | Output isn't correct |
23 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 152 ms | 2396 KB | Output is correct |
2 | Correct | 5 ms | 2396 KB | Output is correct |
3 | Correct | 158 ms | 2600 KB | Output is correct |
4 | Correct | 6 ms | 2392 KB | Output is correct |
5 | Correct | 180 ms | 2392 KB | Output is correct |
6 | Correct | 6 ms | 2392 KB | Output is correct |
7 | Correct | 172 ms | 2576 KB | Output is correct |
8 | Correct | 7 ms | 2396 KB | Output is correct |
9 | Correct | 146 ms | 2472 KB | Output is correct |
10 | Correct | 8 ms | 2392 KB | Output is correct |
11 | Correct | 196 ms | 2576 KB | Output is correct |
12 | Correct | 5 ms | 2396 KB | Output is correct |
13 | Correct | 151 ms | 2580 KB | Output is correct |
14 | Correct | 149 ms | 2396 KB | Output is correct |
15 | Correct | 6 ms | 2396 KB | Output is correct |
16 | Correct | 143 ms | 2576 KB | Output is correct |
17 | Correct | 6 ms | 2280 KB | Output is correct |
18 | Correct | 150 ms | 2580 KB | Output is correct |
19 | Correct | 5 ms | 2392 KB | Output is correct |
20 | Correct | 145 ms | 2572 KB | Output is correct |
21 | Correct | 5 ms | 2392 KB | Output is correct |
22 | Incorrect | 6 ms | 2396 KB | Output isn't correct |
23 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 860 KB | Output is correct |
2 | Correct | 2 ms | 1028 KB | Output is correct |
3 | Correct | 1 ms | 860 KB | Output is correct |
4 | Correct | 1 ms | 860 KB | Output is correct |
5 | Correct | 1 ms | 860 KB | Output is correct |
6 | Correct | 1 ms | 860 KB | Output is correct |
7 | Correct | 1 ms | 860 KB | Output is correct |
8 | Correct | 1 ms | 860 KB | Output is correct |
9 | Correct | 1 ms | 912 KB | Output is correct |
10 | Correct | 1 ms | 860 KB | Output is correct |
11 | Correct | 1 ms | 860 KB | Output is correct |
12 | Correct | 1 ms | 860 KB | Output is correct |
13 | Correct | 1 ms | 860 KB | Output is correct |
14 | Correct | 1 ms | 856 KB | Output is correct |
15 | Correct | 1 ms | 860 KB | Output is correct |
16 | Correct | 1 ms | 860 KB | Output is correct |
17 | Correct | 1 ms | 912 KB | Output is correct |
18 | Correct | 1 ms | 860 KB | Output is correct |
19 | Correct | 1 ms | 856 KB | Output is correct |
20 | Correct | 1 ms | 860 KB | Output is correct |
21 | Correct | 1 ms | 860 KB | Output is correct |
22 | Incorrect | 1 ms | 860 KB | Output isn't correct |
23 | Halted | 0 ms | 0 KB | - |