Submission #1125644

#TimeUsernameProblemLanguageResultExecution timeMemory
1125644underwaterkillerwhaleNivelle (COCI20_nivelle)C++20
110 / 110
25 ms656 KiB
//#include"holiday.h"
#include <bits/stdc++.h>
#define ll long long
#define rep(i,m,n) for(int i=(m); i<=(n); i++)
#define REB(i,m,n) for(int i=(m); i>=(n); i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair
#define fs first
#define se second
#define bit(msk, i) ((msk >> i) & 1)
#define iter(id, v) for(auto id : v)
#define pb push_back
#define SZ(v) (ll)v.size()
#define ALL(v) v.begin(),v.end()

using namespace std;

mt19937_64 rd(chrono :: steady_clock :: now ().time_since_epoch().count());
ll Rand (ll l, ll r) { return uniform_int_distribution<ll> (l, r) (rd); }

const int N = 1e5 + 7;
const int Mod = 1e9 + 9999;///lon
const ll INF = 1e18 + 7;
const ll BASE = 137;
const int szBL = 450;

int n;
int lst[250];

void solution () {
    cin >> n;
    string s;
    cin >> s;
    s = '.' + s;

    set<int> Idx;
    Idx.insert(0);

    auto comp = [&] (pii &A, pii B) -> bool {
        if (1LL * A.fs * B.se < 1LL * B.fs * A.se) return 0;
        A = B;
        return 1;
    };

    pii opt = {1, 1}, res = {1, 1};
    rep (i, 1, n) {
        if (lst[s[i]] != 0) {
            Idx.erase(lst[s[i]]);
        }
        Idx.insert(i);
        lst[s[i]] = i;
        int Len = 0;
        for (auto j = Idx.rbegin(); j != Idx.rend(); ++j) {
            int curP = *j;
//            cout << curP + 1<<" "<<i<<"\n";
            if (Len != 0 && comp(opt, MP(Len, i - curP))) {
                res = {curP + 1, i};
            }
            ++Len;
        }
    }
    cout << res.fs <<" "<<res.se<<"\n";
}

#define file(name) freopen(name".inp","r",stdin); \
freopen(name".out","w",stdout);
int main () {
//    file("c");
    ios_base :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int num_Test = 1;
//    cin >> num_Test;
    while (num_Test--)
        solution();
}
/*
no bug challenge +30

20 50 22
15 26 1
18 20 1
3 41 0
7 16 0
1 38 0
4 3 1
16 23 1
14 48 1
20 19 0
17 10 1
12 31 0
16 21 0
13 23 1
15 16 1
1 40 1
13 46 0
9 29 1
7 48 1
19 17 1
16 34 0
8 8 1
4 10 1

*/
#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...