Submission #8886042


Source Code Expand

//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;


int main(){
  string S; cin >> S;

  vector <int> cnt;
  int now = 1;
  for (int i = 1; i < S.length(); i++){
    if (S[i] == S[i - 1]){
      now++;
    }else{
      cnt.push_back(now);
      now = 1;
    }
  }
  cnt.push_back(now);

  if (cnt.size() % 2 != 0){
    int now = 0;
    for (int i = 0; i < cnt.size() / 2 + 1; i++){
      now += cnt[i];
    }
    int ans = now;
    for (int i = cnt.size() / 2 + 1; i < cnt.size(); i++){
      now += cnt[i] - cnt[i - cnt.size() / 2 - 1];
      ans = min(ans, now);
    }
    cout << ans << endl;
  }else{
    int now = 0;
    for (int i = 0; i < cnt.size() / 2; i++){
      now += cnt[i];
    }
    int ans1 = now;

    for (int i = cnt.size() / 2; i < cnt.size() - 1; i++){
      now += cnt[i] - cnt[i - cnt.size() / 2];
      ans1 = min(now, ans1);
    }

    now = 0;
    for (int i = 0; i < cnt.size() / 2; i++){
      now += cnt[cnt.size() - 1 - i];
    }
    int ans2 = now;
    for (int i = cnt.size() / 2; i < cnt.size() - 1; i++){
      now += cnt[cnt.size() - 1 - i] - cnt[cnt.size() - 1 - (i - cnt.size() / 2)];
      ans2 = min(now, ans2);
    }
    
    cout << max(ans1, ans2) << endl;
  }
  
  return 0;
}

Submission Info

Submission Time
Task D - Wide Flip
User yutas
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1565 Byte
Status WA
Exec Time 5 ms
Memory 768 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 3
AC × 14
WA × 16
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt WA 5 ms 768 KB
02.txt WA 5 ms 768 KB
03.txt WA 5 ms 768 KB
04.txt WA 5 ms 768 KB
05.txt WA 5 ms 768 KB
06.txt WA 5 ms 640 KB
07.txt WA 5 ms 512 KB
08.txt WA 5 ms 512 KB
09.txt WA 5 ms 768 KB
10.txt WA 5 ms 768 KB
11.txt WA 5 ms 768 KB
12.txt WA 5 ms 512 KB
13.txt WA 5 ms 640 KB
14.txt WA 5 ms 768 KB
15.txt WA 5 ms 768 KB
16.txt WA 5 ms 768 KB
17.txt AC 5 ms 512 KB
18.txt AC 5 ms 512 KB
19.txt AC 5 ms 512 KB
20.txt AC 5 ms 512 KB
21.txt AC 1 ms 256 KB
22.txt AC 1 ms 256 KB
23.txt AC 1 ms 256 KB
24.txt AC 1 ms 256 KB
25.txt AC 1 ms 256 KB
26.txt AC 1 ms 256 KB
27.txt AC 1 ms 256 KB
s1.txt AC 1 ms 256 KB
s2.txt AC 1 ms 256 KB
s3.txt AC 1 ms 256 KB