結果

問題 No.921 ずんだアロー
ユーザー kappybarkappybar
提出日時 2020-03-29 13:51:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,141 bytes
コンパイル時間 1,565 ms
コンパイル使用メモリ 168,764 KB
実行使用メモリ 4,728 KB
最終ジャッジ日時 2023-08-30 18:43:29
合計ジャッジ時間 3,127 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF = 1e9;
const int MOD = 1000000007;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int ans = 0;
    vector<P> k = {P(a[0],0)};
    rep(i,n){
        if(k.back().first == a[i]){
            k.back().second ++;
        }else{
            k.emplace_back(P(a[i],1));
        }
    }

    bool ok = true;
    rep(i,k.size()){
        if(k[i].second > 1) ans += k[i].second - 1;
        else{
            if(ok){
                if(0 < i && i < n-1){
                    if(k[i-1].second > 1 && k[i+1].second > 1){
                        ans += 2;
                        ok = false;
                    }
                    else{
                        ans ++;
                        ok = false;
                    }
                }
                else{
                    ans ++;
                    ok = false;
                }
            }else{
                ok = true;
            }
        }
    }

    cout << ans << endl;

    return 0;
}
0