結果

問題 No.921 ずんだアロー
ユーザー nakaken88nakaken88
提出日時 2019-11-08 22:11:31
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,317 bytes
コンパイル時間 1,619 ms
コンパイル使用メモリ 167,748 KB
実行使用メモリ 4,900 KB
最終ジャッジ日時 2023-10-13 03:54:41
合計ジャッジ時間 3,191 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 26 ms
4,632 KB
testcase_11 AC 28 ms
4,692 KB
testcase_12 AC 8 ms
4,352 KB
testcase_13 AC 21 ms
4,372 KB
testcase_14 WA -
testcase_15 AC 15 ms
4,352 KB
testcase_16 AC 3 ms
4,352 KB
testcase_17 AC 24 ms
4,348 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 29 ms
4,584 KB
testcase_24 AC 29 ms
4,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define rep0(i,n) rep(i,0,n)
#define rep1(i,n) rep(i,1,n+1)
#define repR(i,s,n) for(ll i = (n-1); i >= (s); i--)
#define repR0(i,n) repR(i,0,n)
#define repR1(i,n) repR(i,1,n+1)

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;
#define fcout cout << fixed << setprecision(18)

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int a[100];
int cells[100][100]; // r * c

int main() {
  ll N;
  cin >> N;

  vector<ll> A(N);
  rep0(i, N) cin >> A[i];

  vector<ll> B(N, 0);

  int i = 1, cnt = 0;
  int ans = 0;
  while(i < N) {
    if (A[i] == A[i - 1]) {
      B[i] = B[i - 1] = 1;
      if (cnt == 0) cnt++;
      cnt++;
    } else {
      ans += cnt;
      cnt = 0;
    }
    i++;
  }
  if (cnt > 0) {
    ans += cnt;
    B[N - 1] = B[N - 2] = 1;
  }

  if (ans == 0) {
    ans = (N + 1) / 2;
  } else {
    int b = 0;
    i = N - 1;
    while(i >= 0) {
      if (B[i] == 0) {
        b++;
      } else {
        ans += max(0, ((b - 1) / 2));
        b = 0;
      }
      i--;
    }
    ans += max(0, ((b - 0) / 2));
  }

  cout << ans << BR;
  return 0;
}
0