답안 #296290

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
296290 2020-09-10T13:14:32 Z Mlxa Monochrome Points (JOI20_monochrome) C++14
25 / 100
2000 ms 428 KB
#ifdef LC
#include "pch.h"
#else
#include <bits/stdc++.h>
#endif
using namespace std;
using ll = long long;
#define int ll
#define all(x) x.begin(), x.end()
#define x first
#define y second

const int INPUT_BUF = 1 << 12;
const int OUTPUT_BUF = 1 << 16;
char input[INPUT_BUF];
char output[OUTPUT_BUF];
int input_ptr = 0;
int input_len = 0;
int output_ptr = 0;

inline
bool check_eof() {
    if (input_ptr == input_len) {
        input_ptr = 0;
        input_len = fread(input, 1, INPUT_BUF, stdin);
    }
    return input_ptr == input_len;
}
inline
char get_char() {
    assert(!check_eof());
    return input[input_ptr++];
}
inline
char read_char() {
    char c = get_char();
    while (c <= ' ') {
        c = get_char();
    }
    return c;
}
inline
int read_int() {
    int sgn = +1;
    char c = read_char();
    if (c == '-') {
        sgn = -1;
        c = get_char();
    }
    int x = 0;
    while ('0' <= c && c <= '9') {
        x = 10 * x + c - '0';
        c = get_char();
    }
    return x * sgn;

}
inline
__attribute__((destructor))
void flush_output() {
    fwrite(output, 1, output_ptr, stdout);
    output_ptr = 0;
}
inline
void write(char c) {
    if (output_ptr == OUTPUT_BUF) {
        flush_output();
    }
    output[output_ptr++] = c;
}
inline
void write(signed x) {
    static const int LEN = 20;
    static char tmp[LEN];
    int n = 0;
    if (x < 0) {
        write('-');
        x *= -1;
    }
    while (!n || x) {
        tmp[n++] = (char)(x % 10 + '0');
        x /= 10;
    }
    while (n--) {
        write(tmp[n]);
    }
}
inline
void write(long long x) {
    static const int LEN = 20;
    static char tmp[LEN];
    int n = 0;
    if (x < 0) {
        write('-');
        x *= -1;
    }
    while (!n || x) {
        tmp[n++] = (char)(x % 10 + '0');
        x /= 10;
    }
    while (n--) {
        write(tmp[n]);
    }
}
inline
void write(string s) {
    for (char c : s) {
        write(c);
    }
}
inline
void write(const char *s) {
    for (const char *ptr = s; *ptr; ++ptr) {
        write(*ptr);
    }
}

const int N = 1e6;
int n;
char s[N];
vector<int> g[2];
int fen[N];
void clear() {
    fill_n(fen, N, 0);
}
void add(int i) {
    for (; i < N; i |= i + 1) {
        ++fen[i];
    }
}
int go[N];
int func(int k) {
    int s = 0;
    for (int i = 0; i < (int)g[0].size(); ++i) {
        int j = (i + k) % (int)g[1].size();
        go[g[0][i]] = g[1][j];
        go[g[1][j]] = g[0][i];
    }
    auto solve = [&](int l, int r) {
        if (l > r) {
            swap(l, r);
        }
        assert(go[l] == r);
        assert(go[r] == l);
        assert(l <= r); 
        for (int i = l + 1; i <= r - 1; ++i) {
            s += go[i] < l || go[i] > r;
        }
    };
    for (int i = 0; i < (int)g[0].size(); ++i) {
        int j = (i + k) % (int)g[1].size();
        solve(g[0][i], g[1][j]);
    }
    return s / 2;
}

int32_t main() {
#ifdef LC
    assert(freopen("input.txt", "r", stdin));
    //assert(freopen("output.txt", "w", stdout));
#endif
    ios::sync_with_stdio(0); cin.tie(0);
    
    n = read_int();
    n *= 2;
    for (int i = 0; i < n; ++i) {
        if ((s[i] = read_char()) == 'W') {
            g[0].push_back(i);
        } else {
            g[1].push_back(i);
        }
    }
    int ans = 0;
    for (int i = 0; i < 2 * n; ++i) {
        ans = max(ans, func(i));
    }
    write(ans);
    write('\n');
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 416 KB Output is correct
14 Correct 101 ms 420 KB Output is correct
15 Correct 103 ms 428 KB Output is correct
16 Correct 89 ms 424 KB Output is correct
17 Correct 110 ms 384 KB Output is correct
18 Correct 68 ms 428 KB Output is correct
19 Correct 74 ms 384 KB Output is correct
20 Correct 79 ms 384 KB Output is correct
21 Correct 64 ms 424 KB Output is correct
22 Correct 64 ms 384 KB Output is correct
23 Correct 32 ms 384 KB Output is correct
24 Correct 80 ms 384 KB Output is correct
25 Correct 57 ms 420 KB Output is correct
26 Correct 118 ms 384 KB Output is correct
27 Correct 123 ms 384 KB Output is correct
28 Correct 172 ms 420 KB Output is correct
29 Correct 92 ms 424 KB Output is correct
30 Correct 73 ms 424 KB Output is correct
31 Correct 151 ms 384 KB Output is correct
32 Correct 145 ms 428 KB Output is correct
33 Correct 119 ms 420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 416 KB Output is correct
14 Correct 101 ms 420 KB Output is correct
15 Correct 103 ms 428 KB Output is correct
16 Correct 89 ms 424 KB Output is correct
17 Correct 110 ms 384 KB Output is correct
18 Correct 68 ms 428 KB Output is correct
19 Correct 74 ms 384 KB Output is correct
20 Correct 79 ms 384 KB Output is correct
21 Correct 64 ms 424 KB Output is correct
22 Correct 64 ms 384 KB Output is correct
23 Correct 32 ms 384 KB Output is correct
24 Correct 80 ms 384 KB Output is correct
25 Correct 57 ms 420 KB Output is correct
26 Correct 118 ms 384 KB Output is correct
27 Correct 123 ms 384 KB Output is correct
28 Correct 172 ms 420 KB Output is correct
29 Correct 92 ms 424 KB Output is correct
30 Correct 73 ms 424 KB Output is correct
31 Correct 151 ms 384 KB Output is correct
32 Correct 145 ms 428 KB Output is correct
33 Correct 119 ms 420 KB Output is correct
34 Execution timed out 2062 ms 384 KB Time limit exceeded
35 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 416 KB Output is correct
14 Correct 101 ms 420 KB Output is correct
15 Correct 103 ms 428 KB Output is correct
16 Correct 89 ms 424 KB Output is correct
17 Correct 110 ms 384 KB Output is correct
18 Correct 68 ms 428 KB Output is correct
19 Correct 74 ms 384 KB Output is correct
20 Correct 79 ms 384 KB Output is correct
21 Correct 64 ms 424 KB Output is correct
22 Correct 64 ms 384 KB Output is correct
23 Correct 32 ms 384 KB Output is correct
24 Correct 80 ms 384 KB Output is correct
25 Correct 57 ms 420 KB Output is correct
26 Correct 118 ms 384 KB Output is correct
27 Correct 123 ms 384 KB Output is correct
28 Correct 172 ms 420 KB Output is correct
29 Correct 92 ms 424 KB Output is correct
30 Correct 73 ms 424 KB Output is correct
31 Correct 151 ms 384 KB Output is correct
32 Correct 145 ms 428 KB Output is correct
33 Correct 119 ms 420 KB Output is correct
34 Execution timed out 2062 ms 384 KB Time limit exceeded
35 Halted 0 ms 0 KB -