CSES - Datatähti 2017 alku - Results
Submission details
Task:Maalarit
Sender:Alex
Submission time:2016-10-16 00:58:00 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int fb(std::vector<std::pair<long int, long int> >)':
input/code.cpp:25:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < v.size(); i++) {
                                ^
input/code.cpp: In function 'int main(int, char**)':
input/code.cpp:52:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < v.size(); i+=2) {
                                ^
input/code.cpp:61:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 1; i < v.size(); i+=2) {
                                ^
input/code.cpp:77:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int j = 0; j < v.size(); j++) {
                                ^
input/code.cpp:84:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         }else if(h==v....

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 fb(vector< pair<long , long> > v){
    long b =0;
    long r ;
    
    for (int i = 0; i < v.size(); i++) {
        if(v.at(i).first>b){
            r=i;
            b=v.at(i).first;
        }

    }
    return r;
}


int main(int argc, char** argv) {
    long n;
    cin >> n;
    long u[n];
    vector< pair<long , long> > v;
    vector< long > q;
    
    for (int i = 0; i < n; i++) {
        long a;
        cin >> a;
        
        v.push_back(make_pair(a,0));
    }
    
     long b =0;
    long r1 ;
    for (int i = 0; i < v.size(); i+=2) {
        if(v.at(i).first>b){
            r1=i;
            b=v.at(i).first;
        }

    }
 b =0;
    long r2 ;
    for (int i = 1; i < v.size(); i+=2) {
        if(v.at(i).first>b){
            r2=i;
            b=v.at(i).first;
        }

    }

    long f1 = v.at(r1).first+v.at(r2).first;

  
    
    int y =0;
    long c =1;
    while(c<4){
        vector< pair<long , long> > v2=v;
    for (int j = 0; j < v.size(); j++) {
        y=0;
        long h = fb(v2);
        if(h==0){
            if(v.at(h+1).second!=c&&v.at(h).second==0){
            v.at(h).second=c;
        }
        }else if(h==v.size()-1){
            if(v.at(h-1).second!=c&&v.at(h).second==0){
            v.at(h).second=c;
        }
        }else
        if(v.at(h-1).second!=c&&v.at(h+1).second!=c&&v.at(h).second==0){
            int w=0;
            if(h>0&&h<v.size()-2){
                
                 if(v.at(h+1).first==v.at(h).first&&v.at(h-2).second=c&&v.at(h+3).second=c){
                     if(v.at(h+2).second>v.at(h-1).second){
                        v.at(h+1).second=c;
                y=1;
                w=1; 
                     }
                
                }else if(v.at(h+1).first==v.at(h).first){
                v.at(h+1).second=c;
                y=1;
                w=1;
                }else if(v.at(h+1).first==v.at(h).first){
                v.at(h+1).second=c;
                y=1;
                w=1;
                }
            
            
            }
            
            if(w!=1){
            v.at(h).second=c;
            }
            
        }
        if (y==0){
        v2.at(h).first=0;
        }else{
            v2.at(h+1).first=0;
        }
      
    }
    c++;
    
    }
    long a1=0;
     long a2=0;
     long a3=0;
     
     for (int i = 0; i < v.size(); i++) {
         if(v.at(i).second==1&&v.at(i).first>a1){
             a1=v.at(i).first;
         }
            if(v.at(i).second==2&&v.at(i).first>a2){
             a2=v.at(i).first;
         }
         if(v.at(i).second==3&&v.at(i).first>a3){
             a3=v.at(i).first;
         }
        }

     long f2 = a1 + a2 + a3;
     
     if(f2<f1){
         cout << f2 <<  " ";
         if(a3==0){
             cout << 2 << endl;
         }else{
             cout << 3 << endl;
         }
         for (int i = 0; i < v.size(); i++) {
             cout << v.at(i).second << " ";
         }
     }else{
         cout << f1 << " ";
         cout << 2 << endl;
         
         int x =1;
         for (int i = 0; i < v.size(); i++) {
             cout << x << " ";
             if(x==1){
                 x=2;
             }else{
                 x=1;
             }
         }
     }
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}