Submission #199595

#TimeUsernameProblemLanguageResultExecution timeMemory
199595quocnguyen1012Nivelle (COCI20_nivelle)C++14
110 / 110
45 ms636 KiB
#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back

using namespace std;
typedef long long ll;

const int maxn = 1e5 + 5;

int N;
string str;
int cnt[26];

signed main(void)
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  if (fopen("A.INP", "r")){
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  }
  cin >> N >> str;
  str = " " + str;
  int L = 0, R = 0, mxap = 0;
  for (int type = 1; type <= 26; ++type){
    int r = 1, ap = 0;
    for (int i = 1; i <= N; ++i){
      while (r <= N){
        if (!cnt[str[r] - 'a']){
          if (ap + 1 > type) break;
          ++ap;
        }
        ++cnt[str[r] - 'a'];
        ++r;
      }
      if (mxap == 0 || (mxap * (r - i) > ap * (R - L + 1))){
        ///cerr << L << ' ' << R << ' ' << mxap << ' ' << i << ' '  << r - 1 << ' ' << ap << '\n';
        mxap = ap;
        L = i; R = r - 1;
      }
      --cnt[str[i] - 'a'];
      if (cnt[str[i] - 'a'] == 0) --ap;
    }
    for (int i = 0; i < 26; ++i) cnt[i] = 0;
  }
  cout << L << ' ' << R << '\n';
}

Compilation message (stderr)

nivelle.cpp: In function 'int main()':
nivelle.cpp:21:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("A.INP", "r", stdin);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
nivelle.cpp:22:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("A.OUT", "w", stdout);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...