結果

問題 No.284 門松と魔法(2)
ユーザー potetisenseipotetisensei
提出日時 2015-11-17 02:26:06
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,281 bytes
コンパイル時間 421 ms
コンパイル使用メモリ 52,240 KB
実行使用メモリ 7,688 KB
最終ジャッジ日時 2023-10-11 17:06:17
合計ジャッジ時間 3,512 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 1 ms
4,352 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 AC 1 ms
4,352 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 WA -
testcase_15 AC 1 ms
4,352 KB
testcase_16 AC 2 ms
4,352 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 1 ms
4,352 KB
testcase_20 AC 1 ms
4,352 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 1 ms
4,352 KB
testcase_27 AC 1 ms
4,352 KB
testcase_28 AC 1 ms
4,348 KB
testcase_29 AC 32 ms
7,284 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 32 ms
7,200 KB
testcase_33 AC 12 ms
4,348 KB
testcase_34 AC 13 ms
4,352 KB
testcase_35 AC 1 ms
4,348 KB
testcase_36 AC 1 ms
4,348 KB
testcase_37 AC 35 ms
7,688 KB
testcase_38 WA -
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <vector>
#include <set>
using namespace std;

#define PLUS 1
#define MINUS 0

typedef pair<int, int> Interval;
typedef pair<int, Interval> Pair;

int l, r;
int n;
int sub;
bool dir;
vector<int> as;
set<Pair> intervals;

int main() {
    scanf("%d", &n);
    for (int i=0; i<n; i++) {
        int a;
        scanf("%d", &a);
        if (i == 0 || as.back() != a) as.push_back(a);
        else sub++;
    }

    n -= sub;
    sub = 0;
    if (n <= 2) {
        puts("0");
        return 0;
    }

    l = 0;
    r = 1;
    dir = as[0] < as[1];
    for (int i=1; i<n-1; i++) {
        if (dir == as[i] < as[i+1]) r++;
        else {
            intervals.insert(Pair(r-l+1, Interval(l, r)));
            l = r;
            r = l+1;
            dir ^= 1;
        }
    }
    intervals.insert(Pair(r-l+1, Interval(l, r)));

    while (!intervals.empty()) {
        int num = intervals.rbegin()->first;
        int l = intervals.rbegin()->second.first;
        int r = intervals.rbegin()->second.second;
        if (num <= 2) break;
        intervals.erase(Pair(num, Interval(l, r)));
        sub += num-2;
        intervals.insert(Pair(2, Interval(l, r)));
    }

    if (n - sub <= 2) {
        puts("0");
    } else {
        printf("%d\n", n-sub);
    }
}
0