제출 #844375

#제출 시각아이디문제언어결과실행 시간메모리
844375vjudge1Nivelle (COCI20_nivelle)C++17
24 / 110
41 ms856 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define int int64_t #define ordered_set \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> #define F first #define S second #define I insert #define PB push_back #define POB pop_back #define sqr(a) ((a) * (a)) #define P pop #define max3(a, b, c) (max(a, max(b, c))) #define max4(a, b, c, d) (max(max(a, b), max(c, d))) #define min3(a, b, c) (min(a, min(b, c))) #define min4(a, b, c, d) (min(min(a, b), min(c, d))) #define MOD 1000000007 #define mod 998244353 int binpow(int a, int p, int m = MOD) { int ans = 1; while (p) { if (p & 1) ans = ((ans % m) * (a % m)) % m; a = sqr(a) % m; p >>= 1; } return ans; } void solve() { int n; string s; cin >> n >> s; if (n <= 2000) { double mini = INT_MAX; pair<int, int> ans = {0, 0}; for (int i = 0; i < n; i++) { set<char> sc; for (int j = i; j < n; j++) { sc.I(s[j]); if (mini > (double(sc.size()) / (j - i + 1))) { mini = double(sc.size()) / (j - i + 1); ans.F = i; ans.S = j; } } } cout << ans.F + 1 << ' ' << ans.S + 1; } else { int maxa = INT_MIN, maxb = INT_MIN; pair<int, int> maxal = {0, 0}, maxbl = {0, 0}; if (s[0] == 'a') maxa = 1; else maxb = 1; int cur = 1, curl = 0; for (int i = 1; i < n; i++) { if (s[i] == s[i - 1]) { cur++; if ((s[i] == 'a' && maxa < cur) || (s[i] == 'b' && maxb < cur)) { if (s[i] == 'a') maxal = {curl, i}; else maxbl = {curl, i}; } } else { cur = 1; curl = i; } } if (maxa == INT_MIN) maxa = 1; if (maxb == INT_MIN) maxb = 1; int mini = min3(double(1) / maxa, double(1) / maxb, double(2) / n); if (mini == double(1) / maxa) cout << maxal.F + 1 << ' ' << maxal.S + 1; else if (mini == double(1) / maxb) cout << maxbl.F + 1 << ' ' << maxbl.S + 1; else cout << 1 << ' ' << n; } } int32_t main() { int t = 1; // cin >> t; while (t--) { solve(); } }
#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...