結果

問題 No.1834 1D Gravity
ユーザー SSRSSSRS
提出日時 2022-02-04 22:40:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,394 bytes
コンパイル時間 2,470 ms
コンパイル使用メモリ 209,604 KB
実行使用メモリ 85,272 KB
最終ジャッジ日時 2023-09-02 05:12:41
合計ジャッジ時間 25,430 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int B = 100;
int main(){
  int N;
  cin >> N;
  vector<int> m(N);
  for (int i = 0; i < N; i++){
    cin >> m[i];
    m[i]--;
  }
  vector<vector<int>> p(B, vector<int>(N));
  for (int i = 0; i < N; i++){
    p[0][m[i]] = i;
  }
  bool ok = false;
  for (int i = 0; i < B - 1; i++){
    vector<int> mx(N, -1);
    for (int j = 0; j < N; j++){
      mx[p[i][j]] = max(mx[p[i][j]], j);
    }
    for (int j = 0; j < N; j++){
      if (p[i][j] == 0){
        p[i + 1][j] = 1;
      } else if (p[i][j] == N - 1){
        p[i + 1][j] = N - 2;
      } else if (mx[p[i][j] - 1] > mx[p[i][j] + 1]){
        p[i + 1][j] = p[i][j] - 1;
      } else {
        p[i + 1][j] = p[i][j] + 1;
      }
    }
    if (i >= 2){
      if (p[i] == p[i - 2]){
        int t = i - 2;
        set<int> st;
        for (int j = 0; j < N; j++){
          st.insert(p[i][j] + p[i + 1][j]);
        }
        cout << t << ' ' << st.size() << endl;
        ok = true;
        break;
      }
    }
  }
  if (!ok){
    vector<int> M(N, -1);
    for (int i = 0; i < N; i++){
      M[p[B - 1][i]] = max(M[p[B - 1][i]], i);
    }
    for (int i = 0; i <= N - 5; i++){
      if (M[i] >= 0 && M[i + 1] >= 0 && M[i + 2] >= 0 && M[i + 3] >= 0 && M[i + 4] >= 0){
        assert(!(M[i + 2] < M[i] && M[i] < M[i + 1] && M[i + 4] < M[i + 2] && M[i + 2] < M[i + 3]));
      }
    }
  }
}
0