Submission #500252

#TimeUsernameProblemLanguageResultExecution timeMemory
500252MounirNivelle (COCI20_nivelle)C++14
110 / 110
70 ms928 KiB
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define pb push_back
#define pii pair<int, int>
#define chmin(x, v) x = min(x, v)
#define chmax(x, v) x = max(x, v)
#define x first
#define y second
//#define int long long
using namespace std;

signed main(){
      int nVals; cin >> nVals;
      string line; cin >> line;

      queue<int> occs[26];
      for (int i = 0; i < nVals; ++i)
            occs[line[i] - 'a'].push(i);
      
      int l, r;
      double res = 2;
      for (int deb = 0; deb < nVals; ++deb){
            if (deb != 0)
                  occs[line[deb - 1] - 'a'].pop();
            
            vector<int> dates;
            for (int c = 0; c < 26; ++c){
                  if (!occs[c].empty())
                        dates.pb(occs[c].front());
            }
            sort(all(dates));
            for (int i = 0; i < sz(dates); ++i){
                  int maxi = nVals - 1;
                  if (i + 1 != sz(dates))
                        maxi = dates[i + 1] - 1;
                  
                  double resCur = (i + 1)/double(maxi - deb + 1);
                  if (resCur < res){
                        res = resCur;
                        l = deb;
                        r = maxi;
                  }
            }
      }
      cout << l + 1 << " " << r + 1 << endl;
      return 0;   
}

Compilation message (stderr)

nivelle.cpp: In function 'int main()':
nivelle.cpp:46:35: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
   46 |       cout << l + 1 << " " << r + 1 << endl;
      |                                   ^
nivelle.cpp:46:24: warning: 'l' may be used uninitialized in this function [-Wmaybe-uninitialized]
   46 |       cout << l + 1 << " " << r + 1 << endl;
      |                        ^~~
#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...