CSES - Datatähti 2017 alku - Results
Submission details
Task:Kolikot
Sender:Alex
Submission time:2016-10-10 22:16:25 +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:30:14: error: expected ')' before ';' token
    if (y[x]=1;){
              ^
input/code.cpp:30:14: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
input/code.cpp:30:15: error: expected primary-expression before ')' token
    if (y[x]=1;){
               ^
input/code.cpp:30:15: error: expected ';' before ')' token
input/code.cpp:42:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(k<v.size()-1&&v.at(k+1).first==x){
                  ^

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){
               return 1;
               y[x-v.at(k).first*i]=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)){
          i++;
      }
            
      cout << i;

    
    return 0;
}