Submission #1042291

#TimeUsernameProblemLanguageResultExecution timeMemory
1042291dpsaveslivesGondola (IOI14_gondola)C++17
60 / 100
25 ms5168 KiB
#include "gondola.h"
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;

int valid(int n, int inputSeq[]){
    int pos = -1; set<int> vals;
    for(int i = 0;i<n;++i){
        if(inputSeq[i] <= n && pos == -1){
            pos = i;
        }
        vals.insert(inputSeq[i]);
    }
    if(vals.size() != n){
        return 0;
    }
    if(pos == -1){
        return 1;
    }
    int cur = inputSeq[pos];
    for(int i = pos;i<n;++i){
        if(inputSeq[i] <= n){
            //cout << i << " " << cur << "\n";
            if(inputSeq[i] != cur){
                return 0;
            }
        }
        if(cur == n){
            cur = 0;
        }
        ++cur;
    }
    for(int i = 0;i<=pos-1;++i){
        if(inputSeq[i] <= n){
            if(inputSeq[i] != cur){
                return 0;
            }
        }
        if(cur == n){
            cur = 0;
        }
        ++cur;

    }
    return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[]){
    vector<pair<int,int>> arr;
    int pos = -1; bool any = false;
    for(int i = 0;i<n;++i){
        if(gondolaSeq[i] <= n){
            if(pos == -1){
                pos = i;
            }
        }
        else{
            any = true;
            arr.push_back({gondolaSeq[i],i});
        }
    }
    if(!any){
        return 0;
    }
    int rep = 0, cur;
    if(pos != -1){
        cur = gondolaSeq[pos];
    }
    else{
        cur = 1;
        pos = 0;
    }
    vector<int> reps(n,-1);
    for(int i = pos;i<n;++i){
        if(gondolaSeq[i] > n){
            reps[i] = cur;
        }
        if(cur == n){
            cur = 0;
        }
        ++cur;
    }
    for(int i = 0;i<=pos-1;++i){
        if(gondolaSeq[i] > n){
            reps[i] = cur;
        }
        if(cur == n){
            cur = 0;
        }
        ++cur;
    }
    sort(arr.begin(),arr.end());
    cur = n+1; int i = 0;
    while(i < arr.size()){
        replacementSeq[rep] = reps[arr[i].s];
        //cout << rep << " " << replacementSeq[rep] << "\n";
        ++rep;
        while(cur < arr[i].f){ //until arr[i] = cur
            replacementSeq[rep] = cur;
            //cout << rep << " " << replacementSeq[rep] << "\n";
            ++rep; ++cur;
        }
        ++cur; ++i;
    }
    return rep;
}
int countReplacement(int n,	int	inputSeq[]){
    return 1;
}

Compilation message (stderr)

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:15:20: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   15 |     if(vals.size() != n){
      |        ~~~~~~~~~~~~^~~~
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:94:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |     while(i < arr.size()){
      |           ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...