Submission #212058

# Submission time Handle Problem Language Result Execution time Memory
212058 2020-03-22T07:56:41 Z NONAME Pod starim krovovima (COCI20_psk) C++17
0 / 50
6 ms 512 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, 1);
    L = 1;
    R = 1;
 
    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 Incorrect 5 ms 384 KB Output isn't correct
2 Incorrect 4 ms 384 KB Output isn't correct
3 Incorrect 5 ms 384 KB Output isn't correct
4 Incorrect 5 ms 384 KB Output isn't correct
5 Incorrect 5 ms 384 KB Output isn't correct
6 Incorrect 5 ms 384 KB Output isn't correct
7 Incorrect 5 ms 384 KB Output isn't correct
8 Incorrect 5 ms 512 KB Output isn't correct
9 Incorrect 5 ms 384 KB Output isn't correct
10 Incorrect 6 ms 512 KB Output isn't correct