█████████ ████ ███░░░░░███ ░░███ ███ ░░░ ██████ ███████ ██████ ██████ ░███ ███░░███ ███░░███ ███░░███ ███░░███ ░███ ░███ ░███░███ ░███ ░███████ ░███ ░███ ░░███ ███░███ ░███░███ ░███ ░███░░░ ░███ ░███ ░░█████████ ░░██████ ░░████████░░██████ ░░██████ ░░░░░░░░░ ░░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░░

Envío 2197

Problema 0xc9 - Substring más corta con mínimo K caracteres diferentes

  • Autor: Javier
  • Fecha: 2020-11-29 16:54:23 UTC (Hace alrededor de 4 años)
Caso # Resultado Tiempo Memoria
#1
Error de compilación
                      main.cpp:13:20: error: use of undeclared identifier 'INT_MAX'
    int shortest = INT_MAX;
                   ^
1 error generated.

                    
#2
Error de compilación
                      main.cpp:13:20: error: use of undeclared identifier 'INT_MAX'
    int shortest = INT_MAX;
                   ^
1 error generated.

                    
#3
Error de compilación
                      main.cpp:13:20: error: use of undeclared identifier 'INT_MAX'
    int shortest = INT_MAX;
                   ^
1 error generated.

                    
#4
Error de compilación
                      main.cpp:13:20: error: use of undeclared identifier 'INT_MAX'
    int shortest = INT_MAX;
                   ^
1 error generated.

                    
#5
Error de compilación
                      main.cpp:13:20: error: use of undeclared identifier 'INT_MAX'
    int shortest = INT_MAX;
                   ^
1 error generated.

                    
#6
Error de compilación
                      main.cpp:13:20: error: use of undeclared identifier 'INT_MAX'
    int shortest = INT_MAX;
                   ^
1 error generated.

                    
#7
Error de compilación
                      main.cpp:13:20: error: use of undeclared identifier 'INT_MAX'
    int shortest = INT_MAX;
                   ^
1 error generated.

                    
#8
Error de compilación
                      main.cpp:13:20: error: use of undeclared identifier 'INT_MAX'
    int shortest = INT_MAX;
                   ^
1 error generated.

                    
#9
Error de compilación
                      main.cpp:13:20: error: use of undeclared identifier 'INT_MAX'
    int shortest = INT_MAX;
                   ^
1 error generated.

                    
#10
Error de compilación
                      main.cpp:13:20: error: use of undeclared identifier 'INT_MAX'
    int shortest = INT_MAX;
                   ^
1 error generated.

                    
#11
Error de compilación
                      main.cpp:13:20: error: use of undeclared identifier 'INT_MAX'
    int shortest = INT_MAX;
                   ^
1 error generated.

                    
#12
Error de compilación
                      main.cpp:13:20: error: use of undeclared identifier 'INT_MAX'
    int shortest = INT_MAX;
                   ^
1 error generated.

                    
#13
Error de compilación
                      main.cpp:13:20: error: use of undeclared identifier 'INT_MAX'
    int shortest = INT_MAX;
                   ^
1 error generated.

                    
#14
Error de compilación
                      main.cpp:13:20: error: use of undeclared identifier 'INT_MAX'
    int shortest = INT_MAX;
                   ^
1 error generated.

                    
#15
Error de compilación
                      main.cpp:13:20: error: use of undeclared identifier 'INT_MAX'
    int shortest = INT_MAX;
                   ^
1 error generated.

                    
#16
Error de compilación
                      main.cpp:13:20: error: use of undeclared identifier 'INT_MAX'
    int shortest = INT_MAX;
                   ^
1 error generated.

                    
#17
Error de compilación
                      main.cpp:13:20: error: use of undeclared identifier 'INT_MAX'
    int shortest = INT_MAX;
                   ^
1 error generated.

                    
#18
Error de compilación
                      main.cpp:13:20: error: use of undeclared identifier 'INT_MAX'
    int shortest = INT_MAX;
                   ^
1 error generated.

                    
#19
Error de compilación
                      main.cpp:13:20: error: use of undeclared identifier 'INT_MAX'
    int shortest = INT_MAX;
                   ^
1 error generated.

                    
#20
Error de compilación
                      main.cpp:13:20: error: use of undeclared identifier 'INT_MAX'
    int shortest = INT_MAX;
                   ^
1 error generated.

                    
#21
Error de compilación
                      main.cpp:13:20: error: use of undeclared identifier 'INT_MAX'
    int shortest = INT_MAX;
                   ^
1 error generated.

                    
#22
Error de compilación
                      main.cpp:13:20: error: use of undeclared identifier 'INT_MAX'
    int shortest = INT_MAX;
                   ^
1 error generated.

                    
#23
Error de compilación
                      main.cpp:13:20: error: use of undeclared identifier 'INT_MAX'
    int shortest = INT_MAX;
                   ^
1 error generated.

                    
#24
Error de compilación
                      main.cpp:13:20: error: use of undeclared identifier 'INT_MAX'
    int shortest = INT_MAX;
                   ^
1 error generated.

                    
#25
Error de compilación
                      main.cpp:13:20: error: use of undeclared identifier 'INT_MAX'
    int shortest = INT_MAX;
                   ^
1 error generated.

                    
#26
Error de compilación
                      main.cpp:13:20: error: use of undeclared identifier 'INT_MAX'
    int shortest = INT_MAX;
                   ^
1 error generated.

                    
#27
Error de compilación
                      main.cpp:13:20: error: use of undeclared identifier 'INT_MAX'
    int shortest = INT_MAX;
                   ^
1 error generated.

                    
#28
Error de compilación
                      main.cpp:13:20: error: use of undeclared identifier 'INT_MAX'
    int shortest = INT_MAX;
                   ^
1 error generated.

                    
#29
Error de compilación
                      main.cpp:13:20: error: use of undeclared identifier 'INT_MAX'
    int shortest = INT_MAX;
                   ^
1 error generated.

                    
#30
Error de compilación
                      main.cpp:13:20: error: use of undeclared identifier 'INT_MAX'
    int shortest = INT_MAX;
                   ^
1 error generated.

                    
#31
Error de compilación
                      main.cpp:13:20: error: use of undeclared identifier 'INT_MAX'
    int shortest = INT_MAX;
                   ^
1 error generated.

                    
#32
Error de compilación
                      main.cpp:13:20: error: use of undeclared identifier 'INT_MAX'
    int shortest = INT_MAX;
                   ^
1 error generated.

                    
Puntos totales: 0 / 100

Código

#include <iostream>
#include <map>
// #include <bits/stdc++.h>
using namespace std;

int main() {
    string word;
    int k;
    cin >> word >> k;
    
    map<char, int> map_count;
    int left = 0;
    int shortest = INT_MAX;
    for (int right = 0; right < word.size(); right++) {
        char letter = word[right];
        map_count[letter]++;
        while (map_count.size() >= k) {
            shortest = min(shortest, right - left + 1);
            char left_char = word[left];
            map_count[left_char]--;
            if (map_count[left_char] == 0) {
                map_count.erase(left_char);
            }
            left++;
        }
        

    }
    cout << shortest << endl;
}