제출 #1141069

#제출 시각아이디문제언어결과실행 시간메모리
1141069the_coding_poohMonochrome Points (JOI20_monochrome)C++20
35 / 100
1905 ms3288 KiB
#include <bits/stdc++.h> #define uwu return 0; using namespace std; #define fs first #define sc second const int SIZE = 2e5 + 5; const double TL = 1.9; string S; int pos[2][SIZE], seg[SIZE]; int BITree[SIZE]; void modify(int pos, int val){ for (; pos < SIZE; pos += (pos & - pos)){ BITree[pos] += val; } return; } int query(int pos){ int ret = 0; for (; pos; pos -= (pos & - pos)){ ret += BITree[pos]; } return ret; } #define is_W(i) (S[(i + x) % (2 * N)] == 'W') long long eval(int x, int N){ for (int i = 0; i < 2 * N; i++){ BITree[i] = 0; } int ptr[2] = {0, 0}; for (int i = N; i < S.size(); i++){ pos[is_W(i)][ptr[is_W(i)]++] = i; } ptr[0] = 0, ptr[1] = 0; long long ans = 0; for (int i = 0; i < N; i++){ ans += query(pos[1 - is_W(i)][ptr[1 - is_W(i)]]); modify(pos[1 - is_W(i)][ptr[1 - is_W(i)]++], 1); } return ans; } mt19937 rng(time(0)); int main(){ cin.tie(0), ios::sync_with_stdio(0); int N; cin >> N >> S; long long ans = 0; auto ck = clock(); for (; double(clock() - ck) / CLOCKS_PER_SEC < TL;){ ans = max(ans, eval(rng() % (2 * N), N)); } cout << ans << '\n'; uwu }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...