답안 #275793

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
275793 2020-08-20T07:47:54 Z 문홍윤(#5111) Radio (Balkan15_RADIO) C++17
0 / 100
39 ms 256 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], anss=llinf;
vector<LL> l, r;
bool ch[110];

LL solve(){
    LL ret=llinf, suml=0, cntl=0, sumr=0, cntr=0;
    l.clear(); r.clear();
    for(int i=1; i<=n; i++){
        if(!ch[i])continue;
        l.eb(x[i]-p[i]);
        r.eb(x[i]+p[i]);
        suml+=x[i]-p[i];
        cntl++;
    }
    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];
            ret=min(ret, suml-cntl*l[i]+cntr*l[i]-sumr);
            i++;
        }
        else{
            cntr++;
            sumr+=r[j];
            ret=min(ret, suml-cntl*r[j]+cntr*r[j]-sumr);
            j++;
        }
    }
    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=1; i<(1<<n); i++){
        int bc=__builtin_popcount(i);
        if(bc!=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

radio.cpp: In function 'LL solve()':
radio.cpp:34:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for(int i=0, j=0; i<l.size()||j<r.size(); ){
      |                       ~^~~~~~~~~
radio.cpp:34:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for(int i=0, j=0; i<l.size()||j<r.size(); ){
      |                                   ~^~~~~~~~~
radio.cpp:35:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         if(j==r.size()||(i!=l.size()&&l[i]<=r[j])){
      |            ~^~~~~~~~~~
radio.cpp:35:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         if(j==r.size()||(i!=l.size()&&l[i]<=r[j])){
      |                          ~^~~~~~~~~~
radio.cpp: In function 'int main()':
radio.cpp:52:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   52 |     scanf("%d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~
radio.cpp:54:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   54 |         scanf("%lld %lld %lld", &x[i], &p[i], &s[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Incorrect 1 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 39 ms 256 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 39 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Incorrect 1 ms 256 KB Output isn't correct