Cod sursa(job #2464958)

Utilizator CyborgSquirrelJardan Andrei CyborgSquirrel Data 29 septembrie 2019 11:06:50
Problema Secv Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.08 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
 
using namespace std;
 
ifstream fin("secv.in");
ofstream fout("secv.out");
 
int n;
vector<int> fatman, tsarbomba;
 
void projectmanhattan(){
    tsarbomba = fatman;
    sort(tsarbomba.begin(), tsarbomba.end());
    for(int i = n-1; i >= 0; i--){
        if(tsarbomba[i] == tsarbomba[i-1]){
            tsarbomba.erase(tsarbomba.begin()+i);
        }
    }
}
 
int s = -1;
void updates(int a){
    if(s == -1){
        s = a;
    }else{
        s = min(s, a);
    }
    
}

void idk(int p){
    int tsi = 0, tsn = tsarbomba.size();
    int en;
    for(int i = p; i < n; i++){
        if(tsi != tsn && fatman[i] == tsarbomba[tsi]){
            tsi++;
            en = i;
        }
    }
 
    if(tsi == tsn){
        updates(en-p+1);
    }
}
 
int main(){
    fin >> n;
    for(int i = 0; i < n; i++){
        int a;fin >> a;
        fatman.push_back(a);
    }
    projectmanhattan();
 
    for(int i = 0; i < n; i++){
        idk(i);
    }
    fout << s;
    return 0;
}