답안 #275856

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
275856 2020-08-20T08:03:11 Z 문홍윤(#5111) Radio (Balkan15_RADIO) C++17
0 / 100
1 ms 512 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[100010], p[100010], s[100010], anss=llinf;
vector<LL> l, r;

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 bt=0; bt<(1<<n); bt++){
        if(__builtin_popcount(bt)!=k)continue;
        LL suml=0, cntl=0, sumr=0, cntr=0, temp=0;
        l.clear(); r.clear();
        for(int i=1; i<=n; i++){
            if(bt&(1<<(i-1))){
                l.eb(x[i]-p[i]);
                r.eb(x[i]+p[i]);
                suml+=x[i]-p[i];
                cntl++;
            }
            else temp+=s[i];
        }
        assert(cntl==k);
        svec(l); svec(r);
        for(int i=0, j=0; i<l.size()||j<r.size(); ){
            if(j==r.size()||(i!=l.size()&&l[i]<=r[j])){
                cntl--;
                suml-=l[i];
                anss=min(anss, suml-cntl*l[i]+cntr*l[i]-sumr-temp);
                i++;
            }
            else{
                cntr++;
                sumr+=r[j];
                anss=min(anss, suml-cntl*r[j]+cntr*r[j]-sumr-temp);
                j++;
            }
        }
    }
    printf("%lld", anss);
}

Compilation message

radio.cpp: In function 'int main()':
radio.cpp:40:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         for(int i=0, j=0; i<l.size()||j<r.size(); ){
      |                           ~^~~~~~~~~
radio.cpp:40:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         for(int i=0, j=0; i<l.size()||j<r.size(); ){
      |                                       ~^~~~~~~~~
radio.cpp:41:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |             if(j==r.size()||(i!=l.size()&&l[i]<=r[j])){
      |                ~^~~~~~~~~~
radio.cpp:41:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |             if(j==r.size()||(i!=l.size()&&l[i]<=r[j])){
      |                              ~^~~~~~~~~~
radio.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   23 |     scanf("%d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~
radio.cpp:24:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   24 |     for(int i=1; i<=n; i++)scanf("%lld %lld %lld", &x[i], &p[i], &s[i]);
      |                            ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Incorrect 1 ms 384 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 512 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 512 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Incorrect 1 ms 384 KB Output isn't correct