제출 #660472

#제출 시각아이디문제언어결과실행 시간메모리
660472thanh913Nivelle (COCI20_nivelle)C++14
0 / 110
305 ms9040 KiB
#include <bits/stdc++.h> using namespace std; //types #define ll long long #define ld long double #define pll pair<ll, ll> #define pii pair<int, int> #define fi first #define se second #define inf 0x3f3f3f3f #define pw2(x) (1LL << (x)) #define getBit(x, y) ((x) & (1LL << (y))) template<class X, class Y> bool cmax(X &a, const Y &b) { return a < b ? a = b, 1 : 0; } template<class X, class Y> bool cmin(X &a, const Y &b) { return a > b ? a = b, 1 : 0; } struct Answer { ll l, r, first, second; Answer(ll _l = 0, ll _r = 0, ll _first = 0, ll _second = 0) { l = _l; r = _r; first = _first; second = _second; } }; //lowercase 31, all 53 //(P/Q) % M = (P % M) * (Q^(M-2) % M) //------------------------------------------------------- const ld PI = 3.14159265359; const ll N = 1e5+5, L = 18, mod = 1e9+7; int n, a[N]; int lg[N], st[N][L+2]; int get(int l, int r) { int j = lg[r - l + 1]; return __builtin_popcount(st[l][j] | st[r - (1 << j) + 1][j]); } Answer ans(0, 0, inf, 1); Answer comp(Answer x, Answer y) { x.fi *= y.se; y.fi *= x.se; x.se = y.se = x.se * y.se; if (x.fi < y.fi) return x; return y; } int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) { char tmp; cin >> tmp; a[i] = 'z' - tmp; st[i][0] = (1 << a[i]); } for (int i = 2; i <= n; i++) lg[i] = lg[i/2] + 1; for (int j = 1; j <= L; j++) { for (int i = 1; i <= n - (1 << j) + 1; i++) { st[i][j] = st[i][j-1] | st[i + (1 << (j-1))][j-1]; } } for (int cnt = 1; cnt <= 26; cnt++) { for (int i = 1; i <= n; i++) { int l = i, r = n, kq = -1; while (l <= r) { int mid = (l+r) / 2; if (get(i, mid) <= cnt) { kq = mid; l = mid + 1; } else r = mid - 1; } if (kq != -1 && get(i, kq) == cnt) { ans = comp(ans, Answer(i, kq, cnt, kq-i+1)); } } } cout << ans.l << " " << ans.r; }
#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...