結果

問題 No.1834 1D Gravity
ユーザー SSRSSSRS
提出日時 2022-02-04 22:35:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 985 bytes
コンパイル時間 2,374 ms
コンパイル使用メモリ 207,844 KB
実行使用メモリ 790,928 KB
最終ジャッジ日時 2023-09-02 05:09:19
合計ジャッジ時間 36,045 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int B = 1000;
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;
  }
  for (int i = 0; i < B - 1; i++){
    vector<int> mx(N, 0);
    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;
        break;
      }
    }
  }
}
0