답안 #307837

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
307837 2020-09-29T11:43:18 Z Nayna Monochrome Points (JOI20_monochrome) C++14
0 / 100
1 ms 384 KB
#include <bits/stdc++.h>
 
using namespace std;
 
const int mxn = 2e5+5;
 
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef pair<int,int>pii;
typedef pair<int,pii>piii;
 
#define  sf scanf
#define  pf printf
 
#define  input freopen("in.txt","r",stdin)
#define  output freopen("out.txt","w",stdout)
 
#define  inf 1e18
#define  ff first
#define  ss second
#define  MP make_pair
#define  pb push_back
#define  all(v) v.begin(), v.end()
#define  printcase(cases) printf("Case %d:", cases);
#define  Unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define  FAST  ios_base::sync_with_stdio(0);cout.tie(0)
#define  endl printf("\n")
#define  __lcm(a, b) ((a*b)/__gcd(a, b))
int pre[3][mxn];
int n;
string s;
/*
int get(int i, int r)
{
    int sum = 0;
   // cout << i << ' ' << r << '\n';
    int x = pre[0][i-1]+pre[0][n]-pre[0][r];
    int y = pre[1][r-1]-pre[1][i];
    sum+=min(x, y);
   // cout << x << ' ' << y << '\n';
    x = pre[1][i-1]+pre[1][n]-pre[1][r];
    y = pre[0][r-1]-pre[0][i];
   
    sum+=min(x, y);
    return sum;
}
*/
pii get(int i, int r)
{
    int b = 0, w = 0;
    for(int k = i; k <= r; k++)
    {
        if(s[k]=='B') b++;
        else w++; 
    }
    return {b, w};
}

int main()
{
  //  input;
  //  output;

    
    cin >> n;

    
    cin >> s;
    
    vector<int>B, W;
    n = 2*n;
    for(int i = 0; i < n; i++)
    {

        if(s[i]=='B') B.push_back(i);
        else W.push_back(i);
    }

    int ans = 0;
    int h = n/2;
    for(int i = 0; i < h; i++)
    {
        for(int r = 0; r < h; r++)
        {
            if(B[i]<W[r])
            {
                pii x = get(B[i]+1, W[r]-1);
                pii y = get(0, B[i]-1);
                pii p = get(W[r]+1, n-1);
                y.ff+=p.ff;
                y.ss+=p.ss;
                int sum = min(x.ff, y.ss)+min(x.ss, y.ff);
                ans = max(ans, sum);
            }
        }
    }
    cout << ans << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Incorrect 0 ms 256 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Incorrect 0 ms 256 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Incorrect 0 ms 256 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Incorrect 0 ms 256 KB Output isn't correct
5 Halted 0 ms 0 KB -