Submission #1244808

#TimeUsernameProblemLanguageResultExecution timeMemory
1244808CrabCNHNivelle (COCI20_nivelle)C++20
110 / 110
48 ms584 KiB
#include <bits/stdc++.h> #define int long long #define pii pair <int, int> #define fi first #define se second using namespace std; const int N = 1e5 + 5; const int inf = 1e18 + 7; int n, a[N]; map <int, int> mp; int last[27]; string s; void sub2 () { int bestL = -1, bestR = -1, bestCnt = 26; for (int i = 0; i < n; i ++) { mp.clear (); int cnt = 0; for (int j = i; j < n; j ++) { if (mp.find (s[j] - 'a') == mp.end ()) { mp[s[j] - 'a'] ++; cnt ++; } if (cnt *(bestR - bestL + 1) < bestCnt * (j - i + 1)) { bestL = i; bestR = j; bestCnt = cnt; //cout << bestL << " " << bestR << ' ' << bestCnt << '\n'; } } } cout << bestL + 1 << ' ' << bestR + 1; } void subfull () { int bestL = -1, bestR = -1, bestCnt = 26; vector <int> all (27, -1); memset (last, -1, sizeof (last)); for (int j = 0; j < n; j ++) { all.erase (find (all.begin (), all.end (), last[s[j] - 'a'])); last[s[j] - 'a'] = j; all.insert (all.begin (), j); for (int cnt = 1; cnt <= 26; cnt ++) { int i = all[cnt] + 1; if (cnt *(bestR - bestL + 1) < bestCnt * (j - i + 1)) { bestL = i; bestR = j; bestCnt = cnt; //cout << bestL << " " << bestR << ' ' << bestCnt << '\n'; } } } cout << bestL + 1 << ' ' << bestR + 1; } signed main () { ios_base :: sync_with_stdio (0); cin.tie (0); cout.tie (0); #define task "crab" if (fopen (task".inp", "r")) { freopen (task".inp", "r", stdin); freopen (task".out", "w", stdout); } cin >> n >> s; if (n <= 2000) { sub2 (); } else { subfull (); } }

Compilation message (stderr)

nivelle.cpp: In function 'int main()':
nivelle.cpp:66:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
nivelle.cpp:67:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |         freopen (task".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...