結果

問題 No.921 ずんだアロー
ユーザー tomatoma
提出日時 2019-11-08 22:02:59
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,174 bytes
コンパイル時間 1,606 ms
コンパイル使用メモリ 171,180 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-13 03:51:37
合計ジャッジ時間 3,155 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 26 ms
4,352 KB
testcase_11 AC 28 ms
4,348 KB
testcase_12 AC 8 ms
4,348 KB
testcase_13 AC 20 ms
4,348 KB
testcase_14 AC 23 ms
4,348 KB
testcase_15 AC 14 ms
4,348 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 28 ms
4,348 KB
testcase_24 AC 30 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
#define int ll

signed main()
{
    int N;
    cin >> N;
    vector<int> A(N), B;
    vector<bool> same(N, false);
    rep(i, N)cin >> A[i];

    rep(i, N - 1) {
        if (A[i] == A[i + 1]) {
            same[i] = true;
            same[i + 1] = true;
        }
    }
    {
        int cnt = 0;
        rep(i, N) {
            if (same[i]) {
                if (cnt != 0)B.push_back(cnt);
                cnt = 0;
            }
            else {
                cnt++;
            }
        }
        if (cnt != 0)B.push_back(cnt);
    }


    int res = 0;
    rep(i, N)if (same[i])res++;
    if (!B.empty() && B.front() == N) {
        res += (B.front() + 1) / 2;
        B.pop_back();
    }
    if (!same.back() && !B.empty()) {
        res += B.back() / 2;
        B.pop_back();
    }
    if (!same.front() && !B.empty()) {
        reverse(B.begin(), B.end());
        res += B.back() / 2;
        B.pop_back();
    }
    for (int len : B) {
        res += (len - 1) / 2;
    }
    cout << res << endl;
    return 0;
}
0