Submission #546397

#TimeUsernameProblemLanguageResultExecution timeMemory
546397Nguyennams1Nivelle (COCI20_nivelle)C++14
0 / 110
2 ms340 KiB
#include<bits/stdc++.h> #define ll long long #define lu unsigned long long #define f first #define st second #define pb push_back // #define v vector using namespace std; void solve(){ int n,l=0,r=0,rs=0; cin>>n; string s; cin>>s; map<char,ll>mp,mu; set<pair<ll,char>>sp; for(int i=0;i<s.size();i++) mp[s[i]]--; // sort(mp.begin(),mp.end()); double mas=1e9,sum=1,mis=1e9,maz=-1e9,id1=0,id2=0,id3=0; int cnt=0; char g=s[0]; for(int i=1;i<=s.size();i++) { if(s[i]==g && i!= s.size()) cnt++; else{ g=s[i]; if(cnt>maz) {maz=cnt;id1=i-1;id3=id2;} id2=i; cnt=0; } } // cout<<maz<<endl; int id=0; for(auto x: mp){ sp.insert({x.st,x.f}); } for(auto x: sp){ int id = s.find(x.st),sl_m=1; mu[s[id]]++; int i=0; for( i=id+1;i<s.size();i++){ if(mu[s[i]]==0) sl_m++; if(double(double(sl_m)/double(i-id+1))<=mis){ mis=double(double(sl_m)/double(i-id+1));rs=i;} // cout<<mis<<endl; mu[s[i]]++; } mu.clear(); if(mis<mas) { mas=mis; l=id;r=rs; } mis=1e9; } // cout<<maz<<endl; // cout<<1.0/double(maz+1)<<endl; if(1.0/double(maz+1)>=mas)cout<<l+1<<" "<<r+1<<endl; else cout<<id3+1<<" "<<id1+1<<endl; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // int t; cin>>t; // while(t--) solve(); return 0; }

Compilation message (stderr)

nivelle.cpp: In function 'void solve()':
nivelle.cpp:15:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |    for(int i=0;i<s.size();i++) mp[s[i]]--;
      |                ~^~~~~~~~~
nivelle.cpp:20:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |    for(int i=1;i<=s.size();i++) {
      |                ~^~~~~~~~~~
nivelle.cpp:21:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |        if(s[i]==g && i!= s.size()) cnt++;
      |                      ~^~~~~~~~~~~
nivelle.cpp:38:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |        for( i=id+1;i<s.size();i++){
      |                    ~^~~~~~~~~
nivelle.cpp:17:19: warning: unused variable 'sum' [-Wunused-variable]
   17 |    double mas=1e9,sum=1,mis=1e9,maz=-1e9,id1=0,id2=0,id3=0;
      |                   ^~~
nivelle.cpp:30:7: warning: unused variable 'id' [-Wunused-variable]
   30 |   int id=0;
      |       ^~
nivelle.cpp: In function 'int main()':
nivelle.cpp:60:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |     freopen("input.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
nivelle.cpp:61:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |     freopen("output.txt", "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...