Submission #494807

#TimeUsernameProblemLanguageResultExecution timeMemory
494807duyanhloveavNivelle (COCI20_nivelle)C++17
110 / 110
74 ms708 KiB
/**
 *    author:  duyanhloveav
 *    created: 0*.0*.2021 18:25:28
 *    🥇 🐘 💯 🔥 🔥 🔥
**/
#include<bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a), _b=(b); i<_b; ++i)
#define fi first
#define se second
#define pb push_back
#define ll long long
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
const int N = 1 + 1e6;
const double INF = 1e9;

int n,d[26];
string s;

int32_t main() {
#define TASKNAME "coci1920_r4_nivelle"
    ios_base::sync_with_stdio (0);
    cin.tie (0);
    if ( fopen( TASKNAME".inp", "r" ) ) {
        freopen (TASKNAME".inp", "r", stdin);
        freopen (TASKNAME".out", "w", stdout);
    }
    cin >> n >> s;
    s = " " + s;
    int lo = 0, hi = 0;
    double res2 = 1e9;
    for (int i = n; i >= 1; i--) {
        d[s[i] - 'a'] = i;
        vector<int> a = {n + 1};
        for (int j = 0; j < 26; j++)
            if (d[j])
                a.push_back(d[j]);
        sort(all(a));
        for (int j = 0; j + 1 < sz(a); j++) {
            double res = (double)(j + 1) / (a[j + 1] - i);
            if (res2 > res) {
                res2 = res;
                lo = i;
                hi = a[j + 1] - 1;
            }
        }
    }
    cout << lo << " " << hi;
    return 0;
}

Compilation message (stderr)

nivelle.cpp: In function 'int32_t main()':
nivelle.cpp:40:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         for (int j = 0; j + 1 < sz(a); j++) {
      |                               ^
nivelle.cpp:26:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         freopen (TASKNAME".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
nivelle.cpp:27:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         freopen (TASKNAME".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...