CSES - Datatähti 2017 alku - Results
Submission details
Task:Kolikot
Sender:Alex
Submission time:2016-10-13 21:43:07 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int etsi(long int, std::vector<std::pair<long int, long int> >, long int, int*)':
input/code.cpp:43:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(k<v.size()-1&&v.at(k+1).first==x){
                  ^
input/code.cpp: In function 'int main(int, char**)':
input/code.cpp:147:29: error: no match for 'operator==' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long int, long int> > >::value_type {aka std::pair<long int, long int>}' and 'int')
                 if(v.at(k+1)==i){
                             ^
input/code.cpp:147:29: note: candidates are:
In file included from /usr/include/c++/4.8/bits/stl_algo.h:66:0,
                 from /usr/include/c++/4.8/algorithm:62,
                 from input/code.cpp:20:
/usr/include/c++/4.8/functional:2543:5: note: template<class _Res, class ... _Args> bool std::operator==(std::nullptr_t, const std::function<_Res(_ArgTypes ...)>&)
     operator==(nu...

Code

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/* 
 * File:   main.cpp
 * Author: alex
 *
 * Created on October 6, 2016, 9:19 PM
 */

#include <cstdlib>

using namespace std;

#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
/*
 * 
 */

int etsi (long x,vector< pair<long,long> > v, long o , int y[]){ 
   long n=v.size();
   long k=0;
   
  /* if (y[x]==1){
       
       return 1;
   }*/
   
    for (long b = n/2; b >= 1; b /= 2) {
        while(k+b<n&&v.at(k+b).first<x){
            k+=b;
        }
    }
   
   
   
   if(k<v.size()-1&&v.at(k+1).first==x){
       k++;
   }
   while(o!=-1&&v.at(k)>=v.at(o)){
       k--;
       if(k<0){
       return 0;
        }
   }
   if(k<0){
       return 0;
   }
   
   if(v.at(k).first>x){
       return 0;
   }
   
      if(x-v.at(k).first*v.at(k).second<v.at(k).first) {
          return 1; 
      } 
   
   for (int i = v.at(k).second; i > 0; i--) {   
           int pa= etsi(x-v.at(k).first*i,v,k,y);
           if(pa==1){
               y[x-v.at(k).first*i]=1;
               return 1;
               
           }else{
               
           }
    }

   
   return 0;
}














int main(int argc, char** argv) {
    
    long n;
    cin >> n;
    long l[n];
   int y[1000000];
    long a;
    long j=0;
    vector< pair<long,long> > v;
    
    for (int i = 0; i < n; i++) {
        
        cin >> a;
        l[i]=a;

    }
    
    sort(l, l+n);
    a=l[0];
    long r=1;
    long f;
for (int i = 1; i < n; i++) {        
        f=l[i];
        if(f==a){
            r++;
            a=f;
        }else{
            pair <int,int> p=make_pair(a,r);
            v.push_back(p);
            j++;
            a=f;
            r=1;
        }

    }
    pair <int,int> p=make_pair(a,r);
            v.push_back(p);
            
        
            

   
            
      int i=1;
      while(etsi(i,v,-1,y)){    
          
                long n=v.size();
                long k=0;
   

                         for (long b = n/2; b >= 1; b /= 2) {
                         while(k+b<n&&v.at(k+b).first<i){
                             k+=b;
                     }
                    }
                if(v.at(k+1)==i){
                    i=i*2-2;
                }
          
                    i++;
      }
            
      cout << i;

    
    return 0;
}