/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 5ms 536.0 KiB
#4 Accepted 4ms 616.0 KiB
#5 Accepted 102ms 1.789 MiB
#6 Accepted 84ms 1.77 MiB
#7 Accepted 951ms 12.961 MiB
#8 Accepted 950ms 12.957 MiB
#9 Time Exceeded ≥2105ms ≥112.203 MiB
#10 Accepted 34ms 1.77 MiB
#11 Accepted 47ms 1.688 MiB
#12 Time Exceeded ≥2107ms ≥124.516 MiB

Code

// Created on: 2025-02-26 12:29
// Author: Safwan_Ibrahim

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

#define ll long long
#define endl '\n'

map<char, int>Need;

void prec() {
    string T = "IEEELUSBCHAPTER";
    for (auto x : T) {
        Need[x]++;
    }
}
bool check(map<char, int>&Mp) {
    for (auto [x, y] : Need) {
        if (Mp[x] < y) {
            return false;
        }
    }
    return true;
}



void Try() {
    string S; cin >> S;
    map<char, int> Ps[S.size() + 4];

    map<char, int>Mp;
    int mn = 1e9;
    for (int i = 0; i < S.size(); i++) {
        Mp[S[i]]++;
        Ps[i] = {Mp.begin(), Mp.end()};
    }


    int l = -1;
    map<char, int>Mp2;
    for (int r = 0; r < S.size(); r++) {
        Mp2[S[r]]++;
        while(l < r) {

            map<char, int>Tmp;
            for (auto [x, y] : Mp2) {
                if (l != -1) {
                    Tmp[x] = Mp2[x] - Ps[l][x];
                }
                else {
                    Tmp[x] = Mp2[x];
                }
            }
            if (check(Tmp)) {
                mn = min(mn, (r + 1) - (l + 1));
                l++;
            }
            else {
                break;
            }
        }
    }

    if (mn == 1e9) {
        cout << -1 << endl;
    }
    else {
        cout << mn << endl;
    }
    
}

int32_t main() {
    ios_base::sync_with_stdio(0);cin.tie(0);

    int t = 1; cin >> t;
    prec();
    for (int i = 1; i <= t; i++) {
        Try();
    }
    return 0;
} 

Information

Submit By
Type
Submission
Problem
P1174 IEEE LU SB CHAPTER
Contest
Intra LU IEEE Beginner Programming Contest
Language
C++17 (G++ 13.2.0)
Submit At
2025-02-26 07:06:36
Judged At
2025-02-26 07:06:36
Judged By
Score
60
Total Time
≥2107ms
Peak Memory
≥124.516 MiB