Submission #275827

# Submission time Handle Problem Language Result Execution time Memory
275827 2020-08-20T07:54:51 Z 문홍윤(#5111) Radio (Balkan15_RADIO) C++17
0 / 100
34 ms 384 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=0; i<(1<<n); i++){
        LL temp=0;
        int cnt=0;
        memset(ch, 0, sizeof ch);
        for(int j=1; j<=n; j++){
            if(i&(1<<j-1))ch[j]=true, cnt++;
            else temp+=s[j];
        }
        if(cnt!=k)continue;
        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:59:23: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   59 |             if(i&(1<<j-1))ch[j]=true, cnt++;
      |                      ~^~
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:53:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   53 |     for(int i=1; i<=n; i++)scanf("%lld %lld %lld", &x[i], &p[i], &s[i]);
      |                            ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory 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 3 ms 384 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 3 ms 256 KB Output is correct
7 Incorrect 34 ms 384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 360 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 360 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 3 ms 384 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 3 ms 256 KB Output is correct
7 Incorrect 34 ms 384 KB Output isn't correct