結果

問題 No.1834 1D Gravity
ユーザー 👑 NachiaNachia
提出日時 2022-02-04 21:56:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,416 bytes
コンパイル時間 820 ms
コンパイル使用メモリ 80,040 KB
実行使用メモリ 7,832 KB
最終ジャッジ日時 2023-09-02 04:49:05
合計ジャッジ時間 5,340 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;


using i64 = long long;
using u64 = unsigned long long;
using i32 = int;
using u32 = unsigned int;
#define rep(i,n) for(int i=0; i<(n); i++)



int main() {
    int N; cin >> N;
    vector<int> A(N); rep(i,N){ int a; cin >> a; A[i] = a-1; }

    vector<int> P(N); rep(i,N) P[A[i]] = i;
    vector<int> P1;
    rep(t,2){
        vector<int> maxG(N+2, -1);
        rep(i,N) maxG[P[i]+1] = max(maxG[i+1], i);
        rep(i,N){
            int p = P[i];
            if(maxG[p] > maxG[p+2]) P[i] = p-1; else P[i] = p+1;
        }
        if(t == 0) P1 = P;
    }

    vector<int> has(N+1,-1);
    rep(i,N) has[P[i]] = P[i];
    for(int i=1; i<=N; i++) if(has[i-1] != -1 && has[i] != -1) has[i] = has[i-1];
    vector<int> has1(N+3,-1);
    rep(i,N) has1[P1[i]] = P1[i];
    int t1 = 1;
    rep(i,N) if(has1[i] != -1 && has1[i+1] != -1 && has1[i+2] != -1) t1 = 0;

    int blockcnt = 0;
    rep(i,N) if(has[i] != -1 && has[i+1] == -1) blockcnt++;

    vector<int> has_freq(N);
    rep(i,N) if(has[i] != -1) has_freq[has[i]]++;
    int blockt = 0;
    rep(i,N) blockt = max(blockt, has_freq[i]);
    if(t1) blockt = 1;

    cout << blockt << " " << blockcnt << "\n";
    return 0;
}




struct ios_do_not_sync{
    ios_do_not_sync(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
    }
} ios_do_not_sync_instance;
0