結果

問題 No.921 ずんだアロー
ユーザー mikianaaamikianaaa
提出日時 2020-09-09 12:28:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,311 bytes
コンパイル時間 1,505 ms
コンパイル使用メモリ 168,372 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-08-21 07:49:19
合計ジャッジ時間 3,639 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 4 ms
4,380 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 6 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 11 ms
4,380 KB
testcase_24 AC 10 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)n - 1; i > -1; i--)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) { cin >> A[i]; }
    int ans = 0;

    vector<int> points, spe;
    rep(i, N) {
        int cnt = 0;
        int cur = i;
        while (A[cur] == A[i] && cur < N) {
            cnt++;
            cur++;
        }

        points.push_back(cnt);
        if (cnt > 1) {
            spe.push_back(points.size() - 1);
            ans += cnt;
        }
        i = cur - 1;
    }

    if (spe.size() == 0)
        ans = (N / 2) + (N % 2);
    else {
        rep(i, spe.size()) {
            int diff;
            if (i == 0) {
                diff = max(0, spe[i] - 1);
            } else if (i == spe.size() - 1) {
                diff = max(0, (int)points.size() - spe[i] - 1);
            } else {
                diff = max(0, spe[i + 1] - spe[i] - 3);
            }

            ans += (diff / 2) + (diff % 2);
        }
    }

    cout << ans << endl;
    return 0;
}
0