답안 #1038755

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1038755 2024-07-30T07:15:49 Z phong Monochrome Points (JOI20_monochrome) C++17
35 / 100
2000 ms 31812 KB
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

#define ll long long
const int nmax = 4e5 + 5, N = 1e5;
const ll oo = 1e9;
const int lg = 19, M = 2, mod = 1e6;
#define pii pair<ll, ll>
#define fi first
#define se second
#define debug(a, n) for(int i = 1; i <= n; ++i) cout << a[i] << ' '; cout << "\n";
#define endl "\n"
#define task "code"
using namespace std;

int n;
string s;
vector<int> one, two;
vector<pii> tmp;
struct holder{
    vector<int> tmp;
    int f[nmax];

    void update(int x, int val){
        for(; x <= 2 *n; x += x&-x) f[x] += val, tmp.push_back(x);
    }
    int get(int x){
        int res = 0;
        for(; x ; x -= x&-x) res += f[x];
        return res;
    }
    void clear(){
        for(auto p : tmp) f[p] = 0;
        tmp.clear();
    }
}F, G;
ll get(int x){
    tmp.clear();
    for(int i = 0; i < n; ++i){
        int u = one[i];
        int v = two[(i + x + n * 10) % n];
        if(u > v) swap(u, v);
        tmp.push_back({u, v});
//        cout << u << ' ' << v << endl;
    }
    sort(tmp.begin(), tmp.end());
//    for(auto [u, v] : tmp) cout << u << ' ' << v << endl;
    ll ans = 0;
    for(int i = tmp.size() - 1; i >= 0; --i){
        ans += G.get(tmp[i].se) - F.get(tmp[i].se);
        F.update(tmp[i].se, 1);
        G.update(tmp[i].fi, 1);
    }
    F.clear();G.clear();
    return ans;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
//    freopen(task".inp", "r", stdin);
//    freopen(task".out", "w", stdout);
    cin >> n;
    cin >> s;
    for(int i = 0; i < s.size(); ++i){
        if(s[i] == 'W') one.push_back(i + 1);
        else two.push_back(i + 1);
    }
//    cout << get(0);
//    for(int i = 0; i < n; ++i) cout << get(i) << ' ';
    int l = 0, r = n - 2, kq = -1;
    while(l <= r){
        int mid = r + l >> 1;
        if(get(mid) <= get(mid + 1)){
            kq = mid;
            l = mid + 1;
        }
        else r = mid - 1;
    }
    ll ans = 0;
    ans = max({get(kq), get(kq + 1), get(0), get(n - 1)});
    cout << ans;

}
/*
5
5 2 1 5 3
3
1 4
2 5
1 5

4
2 1 5 3
1
1 4


*/

Compilation message

monochrome.cpp:59:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   59 | main(){
      | ^~~~
monochrome.cpp: In function 'int main()':
monochrome.cpp:66:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |     for(int i = 0; i < s.size(); ++i){
      |                    ~~^~~~~~~~~~
monochrome.cpp:74:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   74 |         int mid = r + l >> 1;
      |                   ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 348 KB Output is correct
5 Correct 0 ms 344 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 348 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 344 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 348 KB Output is correct
5 Correct 0 ms 344 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 348 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 348 KB Output is correct
15 Correct 1 ms 480 KB Output is correct
16 Correct 1 ms 348 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 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 344 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 380 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 348 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 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 348 KB Output is correct
5 Correct 0 ms 344 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 348 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 348 KB Output is correct
15 Correct 1 ms 480 KB Output is correct
16 Correct 1 ms 348 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 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 344 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 380 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 348 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 348 KB Output is correct
34 Correct 5 ms 604 KB Output is correct
35 Correct 5 ms 780 KB Output is correct
36 Correct 5 ms 604 KB Output is correct
37 Correct 4 ms 604 KB Output is correct
38 Correct 3 ms 604 KB Output is correct
39 Correct 4 ms 604 KB Output is correct
40 Correct 4 ms 740 KB Output is correct
41 Correct 4 ms 600 KB Output is correct
42 Correct 4 ms 600 KB Output is correct
43 Correct 4 ms 604 KB Output is correct
44 Correct 4 ms 772 KB Output is correct
45 Correct 4 ms 772 KB Output is correct
46 Correct 4 ms 604 KB Output is correct
47 Correct 3 ms 604 KB Output is correct
48 Correct 4 ms 604 KB Output is correct
49 Correct 4 ms 604 KB Output is correct
50 Correct 4 ms 604 KB Output is correct
51 Correct 3 ms 604 KB Output is correct
52 Correct 6 ms 996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 348 KB Output is correct
5 Correct 0 ms 344 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 348 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 348 KB Output is correct
15 Correct 1 ms 480 KB Output is correct
16 Correct 1 ms 348 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 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 344 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 380 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 348 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 348 KB Output is correct
34 Correct 5 ms 604 KB Output is correct
35 Correct 5 ms 780 KB Output is correct
36 Correct 5 ms 604 KB Output is correct
37 Correct 4 ms 604 KB Output is correct
38 Correct 3 ms 604 KB Output is correct
39 Correct 4 ms 604 KB Output is correct
40 Correct 4 ms 740 KB Output is correct
41 Correct 4 ms 600 KB Output is correct
42 Correct 4 ms 600 KB Output is correct
43 Correct 4 ms 604 KB Output is correct
44 Correct 4 ms 772 KB Output is correct
45 Correct 4 ms 772 KB Output is correct
46 Correct 4 ms 604 KB Output is correct
47 Correct 3 ms 604 KB Output is correct
48 Correct 4 ms 604 KB Output is correct
49 Correct 4 ms 604 KB Output is correct
50 Correct 4 ms 604 KB Output is correct
51 Correct 3 ms 604 KB Output is correct
52 Correct 6 ms 996 KB Output is correct
53 Correct 1051 ms 31812 KB Output is correct
54 Correct 1072 ms 24872 KB Output is correct
55 Correct 961 ms 23636 KB Output is correct
56 Correct 949 ms 23836 KB Output is correct
57 Correct 782 ms 23176 KB Output is correct
58 Correct 712 ms 24024 KB Output is correct
59 Correct 773 ms 30264 KB Output is correct
60 Correct 774 ms 23648 KB Output is correct
61 Correct 865 ms 30800 KB Output is correct
62 Execution timed out 2011 ms 22872 KB Time limit exceeded
63 Halted 0 ms 0 KB -