Submission #516569

# Submission time Handle Problem Language Result Execution time Memory
516569 2022-01-21T13:37:15 Z leinad2 Monochrome Points (JOI20_monochrome) C++17
4 / 100
16 ms 204 KB
#include<bits/stdc++.h>
using namespace std;
int n, i, j, k, a, b;
long long ans=0;
char S[400010];
vector<int>A, B;
int seg[1600010];
void init(){for(int i=0;i<8*n;i++)seg[i]=0;}
void update(int id, int s, int e, int x, int v)
{
    if(e<x||x<s)return;
    if(s==e)
    {
        seg[id]+=v;
        return;
    }
    int m=s+e>>1;
    update(id*2, s, m, x, v);update(id*2+1, m+1, e, x, v);
    seg[id]=seg[id*2]+seg[id*2+1];
}
int get(int id, int s, int e, int l, int r)
{
    if(e<l||r<s)return 0;
    if(l<=s&&e<=r)return seg[id];
    int m=s+e>>1;
    return get(id*2, s, m, l, r)+get(id*2+1, m+1, e, l, r);
}
long long f(int i)
{
    init();
    vector<pair<int, int> >V;
    for(int j=i;j<n;j++)V.push_back({A[j-i], B[j]});
    for(int j=0;j<i;j++)V.push_back({A[j+n-i], B[j]});
    for(auto &p:V)if(p.first>p.second)swap(p.first, p.second);
    sort(V.begin(), V.end());
    long long res=0;
    for(auto p:V)
    {
        int a=p.second;
        update(1, 1, 2*n, a, 1);
        res+=get(1, 1, 2*n, p.first, a-1);
    }
    ans=max(ans, res);
    return res;
}
main()
{
    scanf("%d", &n);
    scanf("%s", &S);
    for(i=0;i<2*n;i++)
    {
        if(S[i]=='B')A.push_back(i+1);
        else B.push_back(i+1);
    }
    if(n<200)for(i=0;i<n;i++)f(i);
    else
    {
        int a=100, b=n-100;
        while(a+3<=b)
        {
            int m1=(a+a+b)/3, m2=(a+b+b)/3;
            if(f(m1)>f(m2))a=m1;
            else b=m2;
        }
        for(i=a;i<=b;i++)f(i);
        for(i=0;i<100;i++)f(i);
        for(i=n-100;i<n;i++)f(i);
    }
    cout<<ans;
}

Compilation message

monochrome.cpp: In function 'void update(int, int, int, int, int)':
monochrome.cpp:17:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   17 |     int m=s+e>>1;
      |           ~^~
monochrome.cpp: In function 'int get(int, int, int, int, int)':
monochrome.cpp:25:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   25 |     int m=s+e>>1;
      |           ~^~
monochrome.cpp: At global scope:
monochrome.cpp:46:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   46 | main()
      | ^~~~
monochrome.cpp: In function 'int main()':
monochrome.cpp:49:13: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'char (*)[400010]' [-Wformat=]
   49 |     scanf("%s", &S);
      |            ~^   ~~
      |             |   |
      |             |   char (*)[400010]
      |             char*
monochrome.cpp:48:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
monochrome.cpp:49:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |     scanf("%s", &S);
      |     ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Incorrect 16 ms 204 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Incorrect 16 ms 204 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Incorrect 16 ms 204 KB Output isn't correct
15 Halted 0 ms 0 KB -