Submission #844578

#TimeUsernameProblemLanguageResultExecution timeMemory
844578vjudge1Nivelle (COCI20_nivelle)C++17
0 / 110
182 ms852 KiB
#include <bits/stdc++.h> #define int long long using namespace std; int32_t main(){ int n;cin>>n; string str;cin>>str; vector<int> ilk(26,-1); vector<int> son(26,-1); for (int i = 0; i < n; i++){ if (ilk[str[i]-'a']==-1) ilk[str[i]-'a']=i; son[str[i]-'a']=i; } vector<int> ls; vector<int> rs; for (int i = 0; i < 26; i++){ if (son[i]==-1) continue; ls.push_back(son[i]+1); ls.push_back(ilk[i]); rs.push_back(ilk[i]-1); rs.push_back(son[i]); } vector<bool> vis(26,true); int frac1 = 1; int frac2 = 1; sort(ls.begin(), ls.end()); sort(rs.begin(), rs.end()); int ansl=0, ansr=0; for (int ll = 0; ll < ls.size(); ll++){ for (int rr = 0; rr < rs.size(); rr++){ int l = ls[ll]; int r = rs[rr]; if (l>r) continue; fill(vis.begin(), vis.end(), 0); int crr = 0; for (int i = l; i <= r; i++){ if (!vis[str[i]-'a']) crr++; vis[str[i]-'a']=true; } if (crr*frac2<(r-l+1)*frac1){ frac1=crr; frac2=(r-l+1); ansl=l; ansr=r; } } } cout<<ansl+1<<" "<<ansr+1<<endl; }

Compilation message (stderr)

nivelle.cpp: In function 'int32_t main()':
nivelle.cpp:28:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |  for (int ll = 0; ll < ls.size(); ll++){
      |                   ~~~^~~~~~~~~~~
nivelle.cpp:29:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |   for (int rr = 0; rr < rs.size(); rr++){
      |                    ~~~^~~~~~~~~~~
#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...