Submission #212053

# Submission time Handle Problem Language Result Execution time Memory
212053 2020-03-22T07:49:45 Z NONAME Nivelle (COCI20_nivelle) C++17
0 / 110
49 ms 11648 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-O3")
#define F first
#define S second
#define pb push_back
#define N +1000005
#define M ll(1e9 + 7)
#define sz(x) (int)x.size()
#define re return
#define oo ll(1e18)
#define el '\n'
using namespace std;
//using namespace __gnu_pbds;
//typedef tree <int, null_type, less_equal <int> , rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;
 
int ans, L, R, i, k, n, j, pf[N][28], fst[28];
string s;
 
int calc(int l, int r)
{
    int ans = 0;
    for (int i = 0; i < 26; i++) ans += min(1, pf[r][i] - pf[l - 1][i]);
    return ans;
}
 
int main()
{
//    srand(time(0));
    ios_base::sync_with_stdio(0);
    iostream::sync_with_stdio(0);
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
//    in("input.txt");
//    out("output.txt");
    cin >> n >> s;
    for (i = 1; i <= n; i++)
    {
        if (fst[s[i] - 'a'] == 0) fst[s[i] - 'a'] = i;
        for (j = 0; j < 26; j++) pf[i][j] = pf[i - 1][j];
        pf[i][s[i - 1] - 'a']++;
    }
 
    ans = calc(1, n);
    L = 1;
    R = n;
 
    for (k = 0; k < 27; k++)
    {
        int l = 1, kol = 1;
        for (i = k + 1; i <= n; i++)
        {
            while (l < i && calc(l, i) < kol)
                l++;
 
            kol = calc(l, i);
 
            if (kol * (R - L + 1) < ans * (i - l + 1))
            {
                ans = kol;
                L = l;
                R = i;
            }
        }
    }
    cout << L << " " << R;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 5 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 44 ms 11648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 49 ms 11648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 44 ms 11648 KB Output isn't correct
2 Halted 0 ms 0 KB -