CSES - Datatähti 2017 alku - Results
Submission details
Task:Järjestys
Sender:Alex
Submission time:2016-10-16 23:21:04 +0300
Language:C++
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.05 s1details
#20.06 s2details
#3--3details

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:71:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < vip.size(); i+=2) {
                                  ^
input/code.cpp:80:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 1; i < vip.size(); i+=2) {
                                  ^
input/code.cpp:96:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int j = 0; j < v.size(); j++) {
                                ^
input/code.cpp:102:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         }else...

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< pair<long , long> > vip;
    vector< long > q;
    long a;
        cin >> a;
    v.push_back(make_pair(a,0));
    vip.push_back(make_pair(a,0));
    int s=1;
    for (int i = 1; i < n; i++) {
        long a;
        cin >> a;
        
            if(v.at(s-1).first==a){
                v.pop_back();
                vip.push_back(make_pair(a,-1));
                vip.at(i-1).second=-1;
                s=s-1;
                
            }else{
                
        v.push_back(make_pair(a,0));
        vip.push_back(make_pair(a,0));
        s++;
            }
        
        
        
    }
    
     long b =0;
    long r1 ;
    for (int i = 0; i < vip.size(); i+=2) {
        if(vip.at(i).first>b){
            r1=i;
            b=vip.at(i).first;
        }

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

    }

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

  
    
    
    long c =1;
    while(c<4){
        vector< pair<long , long> > v2=v;
    for (int j = 0; j < v.size(); j++) {
        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){
            v.at(h).second=c;
        }
        v2.at(h).first=0;
      
    }
    c++;
    
    }
    
    
    int z=0;
    for (int i = 0; i < vip.size(); i++) {
        if(vip.at(i).second==0){
            
            vip.at(i).second=v.at(z).second;
            z++;
        }else{
            
            
            
            if(vip.at(i-1).second==1){
                vip.at(i).second=2;
            }else{
                 vip.at(i).second=1;;
            }
        }

    }


    
    
    
    
    long a1=0;
     long a2=0;
     long a3=0;
     
     for (int i = 0; i < vip.size(); i++) {
         if(vip.at(i).second==1&&vip.at(i).first>a1){
             a1=vip.at(i).first;
         }
            if(vip.at(i).second==2&&vip.at(i).first>a2){
             a2=vip.at(i).first;
         }
         if(vip.at(i).second==3&&vip.at(i).first>a3){
             a3=vip.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 < vip.size(); i++) {
             cout << vip.at(i).second << " ";
         }
     }else{
         cout << f1 << " ";
         cout << 2 << endl;
         
         int x =1;
         for (int i = 0; i < vip.size(); i++) {
             cout << x << " ";
             if(x==1){
                 x=2;
             }else{
                 x=1;
             }
         }
     }
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

Test details

Test 1

Group: 1

Verdict:

input
10
9 3 4 7 6 5 10 2 8 1

correct output
32
10 10 9 10 9 8 7 9 4 2 1 4 5 2...

user output
17 2
1 2 1 2 1 2 1 2 1 2 

Test 2

Group: 2

Verdict:

input
1000
650 716 982 41 133 1000 876 92...

correct output
3984
207 207 206 207 128 127 126 12...

user output
1999 2
1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 ...

Test 3

Group: 3

Verdict:

input
100000
94703 47808 62366 31885 7091 8...

correct output
399956
98676 98676 98675 98676 62994 ...

user output
(empty)