# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
275802 | 2020-08-20T07:49:49 Z | 문홍윤(#5111) | Radio (Balkan15_RADIO) | C++17 | 104 ms | 368 KB |
#include <bits/stdc++.h> #define eb emplace_back #define mp make_pair #define F first #define S second #define all(x) x.begin(), x.end() #define svec(x) sort(x.begin(), x.end()) #define press(x) x.erase(unique(x.begin(), x.end()), x.end()) using namespace std; typedef long long LL; typedef pair<int, int> pii; typedef pair<LL, LL> pll; typedef pair<int, LL> pil; typedef pair<LL, int> pli; const LL llinf=2e18; const int inf=1e9; int n, k; LL x[110], p[110], s[110], ans[110], anss=llinf; vector<pli> use; vector<LL> vc; bool ch[110]; LL solve(){ LL ret=llinf; use.clear(); vc.clear(); memset(ans, 0, sizeof ans); for(int i=1; i<=n; i++){ if(!ch[i])continue; use.eb(x[i]-p[i], -1); use.eb(x[i]+p[i], 1); vc.eb(x[i]-p[i]); vc.eb(x[i]+p[i]); } if(vc.size()==0)return 0ll; svec(use); svec(vc); press(vc); LL num=0, sum=0; int pv=0; for(int i=0; i<vc.size(); i++){ for(; pv<use.size(); pv++){ if(use[pv].F>vc[i])break; if(use[pv].S==1)num++, sum+=use[pv].F; } ans[i]+=num*vc[i]-sum; } num=sum=0; pv=use.size()-1; for(int i=vc.size()-1; i>=0; i--){ for(; pv>=0; pv--){ if(use[pv].F<vc[i])break; if(use[pv].S==-1)num++, sum+=use[pv].F; } ans[i]+=sum-num*vc[i]; } for(int i=0; i<vc.size(); i++)ret=min(ret, ans[i]); return ret; } int main(){ scanf("%d %d", &n, &k); for(int i=1; i<=n; i++){ scanf("%lld %lld %lld", &x[i], &p[i], &s[i]); } for(int i=0; i<(1<<n); i++){ int pc=__builtin_popcount(i); if(pc!=k)continue; LL temp=0; memset(ch, 0, sizeof ch); for(int j=0; j<n; j++){ if(i&(1<<j))ch[j+1]=true; else temp+=s[j+1]; } anss=min(anss, solve()-temp); } printf("%lld", anss); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 256 KB | Output is correct |
2 | Correct | 0 ms | 256 KB | Output is correct |
3 | Correct | 0 ms | 256 KB | Output is correct |
4 | Correct | 2 ms | 256 KB | Output is correct |
5 | Correct | 3 ms | 256 KB | Output is correct |
6 | Correct | 1 ms | 256 KB | Output is correct |
7 | Incorrect | 2 ms | 256 KB | Output isn't correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 256 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 104 ms | 368 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 256 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 104 ms | 368 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 256 KB | Output is correct |
2 | Correct | 0 ms | 256 KB | Output is correct |
3 | Correct | 0 ms | 256 KB | Output is correct |
4 | Correct | 2 ms | 256 KB | Output is correct |
5 | Correct | 3 ms | 256 KB | Output is correct |
6 | Correct | 1 ms | 256 KB | Output is correct |
7 | Incorrect | 2 ms | 256 KB | Output isn't correct |