結果

問題 No.2673 A present from B
ユーザー 👑 chro_96chro_96
提出日時 2024-03-15 22:02:34
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,202 bytes
コンパイル時間 214 ms
コンパイル使用メモリ 31,360 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-15 22:02:37
合計ジャッジ時間 2,332 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>

int main () {
  int n = 0;
  int m = 0;
  int a = 0;
  
  int res = 0;
  
  int ans[499] = {};
  
  int d[500][500] = {};
  int e[500][500] = {};
  int p[500] = {};
  
  res = scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    p[i] = i;
    e[i-1][i] = 1;
    e[i][i-1] = 1;
  }
  res = scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    int s = 0;
    res = scanf("%d", &a);
    s = p[a-1];
    p[a-1] = p[a];
    p[a] = s;
    if (a > 1) {
      e[p[a-2]][p[a-1]] = 1;
      e[p[a-1]][p[a-2]] = 1;
    }
    if (a < n-1) {
      e[p[a]][p[a+1]] = 1;
      e[p[a+1]][p[a]] = 1;
    }
  }
  
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (e[i][j] > 0) {
        d[i][j] = 1;
      } else {
        d[i][j] = n;
      }
    }
    d[i][i] = 0;
  }
  
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        if (d[j][i]+d[i][k] < d[j][k]) {
          d[j][k] = d[j][i]+d[i][k];
        }
      }
    }
  }
  
  for (int i = 0; i < n-1; i++) {
    ans[i] = d[p[0]][i+1];
  }
  
  printf("%d", ans[0]);
  for (int i = 1; i < n-1; i++) {
    printf(" %d", ans[i]);
  }
  printf("\n");
  
  return 0;
}
0