Submission #275934

# Submission time Handle Problem Language Result Execution time Memory
275934 2020-08-20T08:27:33 Z 문홍윤(#5111) Circus (Balkan15_CIRCUS) C++17
Compilation error
0 ms 0 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];
        }
        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

circus.cpp: In function 'int main()':
circus.cpp:39:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         for(int i=0, j=0; i<l.size()||j<r.size(); ){
      |                           ~^~~~~~~~~
circus.cpp:39:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         for(int i=0, j=0; i<l.size()||j<r.size(); ){
      |                                       ~^~~~~~~~~
circus.cpp:40:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |             if(j==r.size()||(i!=l.size()&&l[i]<=r[j])){
      |                ~^~~~~~~~~~
circus.cpp:40:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |             if(j==r.size()||(i!=l.size()&&l[i]<=r[j])){
      |                              ~^~~~~~~~~~
circus.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);
      |     ~~~~~^~~~~~~~~~~~~~~~~
circus.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.cpp: In function 'int main()':
grader.cpp:14:12: warning: unused variable 'max_code' [-Wunused-variable]
   14 |  long long max_code;
      |            ^~~~~~~~
grader.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   16 |  scanf("%d%d", &N, &M);
      |  ~~~~~^~~~~~~~~~~~~~~~
grader.cpp:18:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   18 |   scanf("%d", &P[i]);
      |   ~~~~~^~~~~~~~~~~~~
grader.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   21 |  scanf("%d", &Q);
      |  ~~~~~^~~~~~~~~~
grader.cpp:23:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   23 |   scanf("%d", &d);
      |   ~~~~~^~~~~~~~~~
/tmp/ccBEN000.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccIZKL1b.o:circus.cpp:(.text.startup+0x0): first defined here
/tmp/ccBEN000.o: In function `main':
grader.cpp:(.text.startup+0x6c): undefined reference to `init(int, int, int*)'
grader.cpp:(.text.startup+0xa9): undefined reference to `minLength(int)'
collect2: error: ld returned 1 exit status