Submission #1285178

#TimeUsernameProblemLanguageResultExecution timeMemory
1285178hrantsargsyanNivelle (COCI20_nivelle)C++20
110 / 110
51 ms20624 KiB
// Task Nivelle.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

const int N = 2e5;

int a[N], nextLetter[N][50];


int main()
{
    int n, minl = -1, minr = -1;
    long double ans=1.000000;
    cin >> n;    
    string s;
    cin >> s;
    for (int i = 0;i < s.size();++i)
    {
        a[i] = s[i] - 'a' + 1;        
    }
    for (int i = 0;i< n;++i)
    {
        for (int j = 0;j < 50;++j)
        {
            nextLetter[i][j] = n;
        }
    }
    nextLetter[n - 1][a[n - 1]] = n-1;
    for (int i = n - 2;i >= 0;--i)
    {
        for (int j = 1;j <= 30;++j)
        {
            if (a[i] == j)
            {
                nextLetter[i][j] = i;
            }
            else
            {
                nextLetter[i][j] = nextLetter[i + 1][j];
            }
        }
    }
    for (int i = 0;i < n;++i)
    {
        sort(nextLetter[i], nextLetter[i] + 30);
    }
    //for (int i = 0;i < n;++i)
    //{
    //    for (int j = 1;j<=26;++j)
    //    {
    //        cout << i << " " << j <<" "<<nextLetter[i][j] << endl;
    //    }
    //}
    for (int i = 0;i < n;++i)
    {
        for (int j = 1;j < 30;++j)
        {
            int dist = nextLetter[i][j] - i;
            long double currans = j*1.0 / dist;
            if (currans < ans)
            {
                ans = currans;
                minl = i;
                minr = nextLetter[i][j]-1;
            }
            if (nextLetter[i][j] == n)
            {
                break;
            }
        }
    }
    cout << minl+1 << " " << minr+1 << endl;
    //cout << ans << endl;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
#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...