結果

問題 No.1371 交換門松列・松
ユーザー SSRSSSRS
提出日時 2021-01-29 23:01:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,305 bytes
コンパイル時間 2,460 ms
コンパイル使用メモリ 186,180 KB
実行使用メモリ 5,316 KB
最終ジャッジ日時 2023-09-09 16:45:47
合計ジャッジ時間 10,068 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
bool is_kadomatsu(int a, int b, int c){
  return (b < a && b < c || b > a && b > c) && a != c;
}
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
    A[i]--;
  }
  if (A[1] < A[0]){
    for (int i = 0; i < N; i++){
      A[i] = N - 1 - A[i];
    }
  }
  long long ans = 0;
  for (int i = 0; i < N; i++){
    for (int j = i + 1; j < min(i + 5, N); j++){
      swap(A[i], A[j]);
      bool ok = true;
      for (int k = i - 2; k <= j; k++){
        if (0 <= k && k < N - 2){
          if (!is_kadomatsu(A[k], A[k + 1], A[k + 2])){
            ok = false;
          }
        }
      }
      if (ok){
        ans++;
      }
      swap(A[i], A[j]);
    }
  }
  vector<int> L(N, -1), R(N, N);
  for (int i = 0; i < N - 2; i++){
    if (i % 2 == 0){
      R[i] = min(R[i], A[i + 1]);
      R[i + 2] = min(R[i + 2], A[i + 1]);
    } else {
      L[i] = max(L[i], A[i + 1]);
      L[i + 2] = max(L[i + 2], A[i + 1]);
    }
  }
  for (int i = 0; i < N; i++){
    for (int j = i + 5; j < N; j++){
      if (L[i] < A[j] && A[j] < R[i] && L[j] < A[i] && A[i] < R[j]){
        ans++;
      }
    }
  }
  cout << ans << endl;
}
0