Submission #442917

#TimeUsernameProblemLanguageResultExecution timeMemory
442917Dipto_DebdipNivelle (COCI20_nivelle)C++14
13 / 110
7 ms2692 KiB
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
bool cmp(pair<ll, ll> a, pair<ll, ll> b) {
  return a.second - a.first > b.second - b.first;
}
int main(int argc, char const *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n;
  string s;
  cin >> n;
  cin >> s;
  ll a = 0, b = 0;
  for (auto i : s) a |= (i == 'a'), b |= (i == 'b');
  ll hor = 0;
  ll cnt = 0;
  ll l = 0, r = 0;
  vector<pair<ll, ll>> v;
  char pre = '$';
  for (ll i = 0; i < n; i++) {
    if (pre == '$') cnt = 1, pre = s[i], l = 0;
    else if (s[i] != pre) {
      r = i - 1;
      v.push_back({l, r});
      l = i;
      pre = s[i];
    }
  }
  v.push_back({l, n - 1});
  sort(v.begin(), v.end(), cmp);
  if (a && b) {
    ll d1 = v[0].second - v[0].first + 1;
    ll d2 = n;
    ll l1 = 1;
    ll l2 = 2;
    if (l1 * d2 > l2 * d1) {
      cout << 1 << " " << n << endl;
    } else {
      cout << v[0].first + 1 << " " << v[0].second + 1;
    }
  } else {
    cout << v[0].first + 1 << " " << v[0].second + 1;
  }
  return 0;
}

Compilation message (stderr)

nivelle.cpp: In function 'int main(int, const char**)':
nivelle.cpp:16:6: warning: unused variable 'hor' [-Wunused-variable]
   16 |   ll hor = 0;
      |      ^~~
nivelle.cpp:17:6: warning: variable 'cnt' set but not used [-Wunused-but-set-variable]
   17 |   ll cnt = 0;
      |      ^~~
#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...