답안 #946389

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
946389 2024-03-14T15:34:59 Z efedmrlr Monochrome Points (JOI20_monochrome) C++17
35 / 100
2000 ms 7908 KB
// #pragma GCC optimize("O3,Ofast,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>

using namespace std;


#define int long long int
#define MP make_pair
#define pb push_back
#define REP(i,n) for(int i = 0; (i) < (n); (i)++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()


void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}


const double EPS = 0.00001;
const int INF = 1e9+500;
const int N = 3e5+5;
const int ALPH = 26;
const int LGN = 25;
constexpr int MOD = 1e9+7;
int n,m,q;
vector<int> pw;
vector<int> b,w;
int getSum(int l, int r) {
    if(l <= r) {
        return pw[r] - ((l > 0) ? pw[l - 1] : 0);
    }
    return pw[r] + (pw[2*n-1] - ((l > 0) ? pw[l - 1] : 0));
}
int dif(int l, int r) {
    if(l <= r) return r - l + 1;
    else return 2*n + r - l + 1;
}
int calc_k(int k) {
    int ret = 0;
    for(int i = 0; i<n; i++) {
        int j = (i + k) % n;
        int wu = getSum(w[i], b[j]) - 1;
        int wd = n - 1 - wu, bu = dif(w[i], b[j]) - 2 - wu;
        int bd = n - 1 - bu;

        // cout << " wi:" << w[i] << " bj:" << b[j] << " wu:" << wu << " wd:" << wd << " bu:" << bu << " bd:" << bd <<  "\n";
        ret += min(wu, bd) + min(wd, bu);
    }
    // cout << ret << "\n";
    return ret / 2;
}
inline void solve() {
    cin >> n;
    string s;
    cin >> s;
    pw.assign(2*n + 3, 0);
    pw[0] = s[0] == 'W';
    for(int i = 0; i<2*n; i++) {
        if(s[i] == 'B') b.pb(i);
        else w.pb(i);
    }
    for(int i = 1; i<2*n; i++) {
        pw[i] = pw[i - 1] + (s[i] == 'W');
    }
    int ans = 0;
    for(int k = 0; k < n; k++) {
        ans = max(ans, calc_k(k));
    }
    cout << ans << "\n";
}
 
signed main() {

    fastio();
    int test = 1;
    //cin>>test;
    while(test--) {
        solve();
    }
    
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 0 ms 600 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 0 ms 600 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 504 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 0 ms 600 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 504 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 856 KB Output is correct
34 Correct 19 ms 344 KB Output is correct
35 Correct 20 ms 540 KB Output is correct
36 Correct 18 ms 348 KB Output is correct
37 Correct 17 ms 348 KB Output is correct
38 Correct 16 ms 348 KB Output is correct
39 Correct 18 ms 344 KB Output is correct
40 Correct 17 ms 604 KB Output is correct
41 Correct 15 ms 348 KB Output is correct
42 Correct 19 ms 600 KB Output is correct
43 Correct 19 ms 792 KB Output is correct
44 Correct 17 ms 544 KB Output is correct
45 Correct 18 ms 540 KB Output is correct
46 Correct 18 ms 348 KB Output is correct
47 Correct 19 ms 348 KB Output is correct
48 Correct 19 ms 348 KB Output is correct
49 Correct 16 ms 600 KB Output is correct
50 Correct 19 ms 348 KB Output is correct
51 Correct 18 ms 348 KB Output is correct
52 Correct 19 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 0 ms 600 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 504 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 856 KB Output is correct
34 Correct 19 ms 344 KB Output is correct
35 Correct 20 ms 540 KB Output is correct
36 Correct 18 ms 348 KB Output is correct
37 Correct 17 ms 348 KB Output is correct
38 Correct 16 ms 348 KB Output is correct
39 Correct 18 ms 344 KB Output is correct
40 Correct 17 ms 604 KB Output is correct
41 Correct 15 ms 348 KB Output is correct
42 Correct 19 ms 600 KB Output is correct
43 Correct 19 ms 792 KB Output is correct
44 Correct 17 ms 544 KB Output is correct
45 Correct 18 ms 540 KB Output is correct
46 Correct 18 ms 348 KB Output is correct
47 Correct 19 ms 348 KB Output is correct
48 Correct 19 ms 348 KB Output is correct
49 Correct 16 ms 600 KB Output is correct
50 Correct 19 ms 348 KB Output is correct
51 Correct 18 ms 348 KB Output is correct
52 Correct 19 ms 348 KB Output is correct
53 Execution timed out 2037 ms 7908 KB Time limit exceeded
54 Halted 0 ms 0 KB -