/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 1ms 556.0 KiB
#3 Accepted 3ms 540.0 KiB
#4 Accepted 3ms 540.0 KiB
#5 Accepted 92ms 1.891 MiB
#6 Accepted 90ms 1.781 MiB
#7 Accepted 1033ms 13.195 MiB
#8 Accepted 1022ms 12.961 MiB
#9 Time Exceeded ≥2104ms ≥112.254 MiB
#10 Accepted 36ms 2.023 MiB
#11 Accepted 45ms 1.605 MiB
#12 Time Exceeded ≥2007ms ≥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'

const int N = 1e5 + 8;
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]]++;
        if (check(Mp)) {
            mn = min(mn, i + 1);
        }
        Ps[i] = {Mp.begin(), Mp.end()};
    }

    int l = 0;
    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) {
                Tmp[x] = Mp2[x] - Ps[l][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 06:59:35
Judged At
2025-02-26 06:59:35
Judged By
Score
60
Total Time
≥2104ms
Peak Memory
≥124.516 MiB