답안 #307800

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
307800 2020-09-29T10:24:27 Z Nayna Monochrome Points (JOI20_monochrome) C++14
0 / 100
1 ms 384 KB
#include <bits/stdc++.h>
 
using namespace std;
 
const int mxn = 1e5+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;
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];
   // cout << x << ' ' << y << '\n';
   // cout << '\n';
    sum+=min(x, y);
    return sum;
}
int main()
{
  //  input;
    //output;

    
    cin >> n;

    string s;
    cin >> s;
    
    vector<int>B, W;
    n = 2*n;
    for(int i = 0; i < n; i++)
    {
        if(s[i]=='B') pre[1][i+1] = 1;
        else pre[0][i+1] = 1;

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

    for(int i = 1; i <= n; i++) 
    {
        pre[0][i]+=pre[0][i-1];
        pre[1][i]+=pre[1][i-1];
    }
    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]) ans = max(ans, get(B[i], W[r]));
        }
    }
    cout << ans << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Incorrect 1 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Incorrect 1 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Incorrect 1 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Incorrect 1 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -