Submission #844334

#TimeUsernameProblemLanguageResultExecution timeMemory
844334vjudge1Nivelle (COCI20_nivelle)C++17
0 / 110
2 ms348 KiB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
//#define int long long

//#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    #define OPEN freopen(".in", "r", stdin); \
                 freopen(".out", "w", stdout);
#else
    #define OPEN void(23);
#endif

void solve()
{
    int n; cin >> n;
    string str; cin >> str; str = '$' + str;

    vector <array <int, 26>> pref(n +1);
    for(int i = 0; i < 26; i++) pref[0][i] = 0;
    for(int i = 1; i <= n; i++)
    {
        pref[i] = pref[i -1];
        pref[i][str[i] - 'a']++;
    }

    long double ans = 2;
    pair <int, int> inds;
    for(int l = 1; l <= n; l++)
    {
        for(int r = l; r <= n; r++)
        {
            array <int, 26> c;
            int tot = 0;
            for(int i = 0; i < 26; i++) 
                c[i] = pref[r][i] - pref[l -1][i], tot += (c[i] != 0);

            long double cost = tot;
            cost /= (r - l +1);
            //cerr << l << " " << r << " " << cost << "\n";
            if(cost < ans)
            {
                ans = cost;
                inds = {l, r};
            }
        }
    }

    cout << inds.first << " " << inds.second << "\n";

    return;
}

int32_t main()
{
    OPEN;

    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int t = 1; //cin >> t;
    while(t--)
    {
        solve();
    }
}

Compilation message (stderr)

nivelle.cpp: In function 'int32_t main()':
nivelle.cpp:9:25: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     #define OPEN freopen(".in", "r", stdin); \
      |                  ~~~~~~~^~~~~~~~~~~~~~~~~~~
nivelle.cpp:57:5: note: in expansion of macro 'OPEN'
   57 |     OPEN;
      |     ^~~~
nivelle.cpp:10:25: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |                  freopen(".out", "w", stdout);
      |                  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
nivelle.cpp:57:5: note: in expansion of macro 'OPEN'
   57 |     OPEN;
      |     ^~~~
#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...