Submission #5434368


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) int((a).size())
#define LOWB(x) (x & (-x))
#define UNIQUE(a) sort(ALL(a)), (a).erase(unique(ALL(a)), (a).end())
#define INF 1e9
#define INF_LL 4e18
#define rep(i,a,b) for(__typeof(b) i=a; i<(b); ++i)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
/*-----------------------------------*/
vector<string> s;
int n;

int main() {
  cin >> n;
  s.resize(n);
  for (int i=0; i<n; i++) cin >> s[i];

  int cntAB = 0, headB = 0, tailA = 0, both = 0;
  for (int i=0; i<n; i++) {
    if (s[i][0] == 'B') headB++;
    if (s[i].back() == 'A') tailA++;
    if (s[i][0] == 'B' && s[i].back() == 'A') both ++;
    for (int j=0; j+1<(int)s[i].size(); j++) {
      if (s[i][j] == 'A' && s[i][j+1] == 'B') cntAB++;
    }
  }
  headB -= both;
  tailA -= both;
  int ans = cntAB;
  ans += min(headB, tailA);
  int diff = abs(headB - tailA);
  if (both < diff) ans += both;
  else {
    ans += diff;
    both -= diff;
    if (diff)
      ans += both;
    else
      ans += max(0, both-1);
  }
  cout << ans << endl;
}

Submission Info

Submission Time
Task C - AB Substrings
User eggeek
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1247 Byte
Status WA
Exec Time 7 ms
Memory 768 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 3
AC × 44
WA × 4
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All rand_01.txt, rand_02.txt, rand_03.txt, rand_04.txt, rand_05.txt, rand_06.txt, rand_07.txt, rand_08.txt, rand_09.txt, rand_10.txt, rand_11.txt, rand_12.txt, rand_13.txt, rand_14.txt, rand_15.txt, rand_16.txt, rand_17.txt, rand_18.txt, rand_19.txt, rand_20.txt, rand_21.txt, rand_22.txt, rand_23.txt, rand_24.txt, rand_25.txt, rand_26.txt, rand_27.txt, rand_28.txt, rand_29.txt, rand_30.txt, rand_31.txt, rand_32.txt, rand_33.txt, rand_34.txt, rand_35.txt, rand_36.txt, rand_37.txt, rand_38.txt, rand_39.txt, rand_40.txt, rand_41.txt, rand_42.txt, rand_43.txt, rand_44.txt, rand_45.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
rand_01.txt AC 7 ms 768 KiB
rand_02.txt AC 7 ms 768 KiB
rand_03.txt AC 7 ms 768 KiB
rand_04.txt AC 7 ms 768 KiB
rand_05.txt AC 7 ms 768 KiB
rand_06.txt AC 7 ms 768 KiB
rand_07.txt AC 7 ms 768 KiB
rand_08.txt AC 7 ms 768 KiB
rand_09.txt AC 4 ms 640 KiB
rand_10.txt AC 5 ms 640 KiB
rand_11.txt AC 2 ms 384 KiB
rand_12.txt AC 4 ms 512 KiB
rand_13.txt WA 5 ms 640 KiB
rand_14.txt WA 5 ms 640 KiB
rand_15.txt AC 4 ms 512 KiB
rand_16.txt AC 4 ms 512 KiB
rand_17.txt AC 2 ms 384 KiB
rand_18.txt AC 3 ms 512 KiB
rand_19.txt AC 2 ms 384 KiB
rand_20.txt AC 3 ms 384 KiB
rand_21.txt AC 7 ms 768 KiB
rand_22.txt AC 7 ms 768 KiB
rand_23.txt AC 7 ms 768 KiB
rand_24.txt AC 7 ms 768 KiB
rand_25.txt WA 7 ms 768 KiB
rand_26.txt WA 7 ms 768 KiB
rand_27.txt AC 4 ms 512 KiB
rand_28.txt AC 4 ms 640 KiB
rand_29.txt AC 4 ms 512 KiB
rand_30.txt AC 4 ms 512 KiB
rand_31.txt AC 3 ms 384 KiB
rand_32.txt AC 5 ms 640 KiB
rand_33.txt AC 5 ms 640 KiB
rand_34.txt AC 4 ms 512 KiB
rand_35.txt AC 4 ms 512 KiB
rand_36.txt AC 4 ms 512 KiB
rand_37.txt AC 3 ms 384 KiB
rand_38.txt AC 5 ms 640 KiB
rand_39.txt AC 4 ms 512 KiB
rand_40.txt AC 5 ms 640 KiB
rand_41.txt AC 5 ms 640 KiB
rand_42.txt AC 3 ms 512 KiB
rand_43.txt AC 5 ms 640 KiB
rand_44.txt AC 4 ms 512 KiB
rand_45.txt AC 4 ms 512 KiB
sample_01.txt AC 1 ms 256 KiB
sample_02.txt AC 1 ms 256 KiB
sample_03.txt AC 1 ms 256 KiB