結果

問題 No.2673 A present from B
ユーザー 👑 chro_96chro_96
提出日時 2024-03-15 22:55:11
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,426 bytes
コンパイル時間 321 ms
コンパイル使用メモリ 32,000 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-15 22:55:13
合計ジャッジ時間 1,373 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 1 ms
6,548 KB
testcase_04 AC 3 ms
6,548 KB
testcase_05 AC 2 ms
6,548 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 1 ms
6,548 KB
testcase_10 AC 2 ms
6,548 KB
testcase_11 AC 1 ms
6,548 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,548 KB
testcase_23 AC 2 ms
6,548 KB
testcase_24 AC 1 ms
6,548 KB
testcase_25 AC 2 ms
6,548 KB
testcase_26 AC 1 ms
6,548 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 p[500] = {};
  
  res = scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    p[i] = i;
    for (int j = 0; j < i; j++) {
      d[j][i] = i-j;
      d[i][j] = i-j;
    }
  }
  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) {
      for (int j = 0; j < n; j++) {
        if (d[j][p[a-2]] > d[j][p[a-1]]+1) {
          d[j][p[a-2]] = d[j][p[a-1]]+1;
        }
      }
      for (int j = 0; j < n; j++) {
        if (d[j][p[a-1]] > d[j][p[a-2]]+1) {
          d[j][p[a-1]] = d[j][p[a-2]]+1;
        }
      }
    }
    if (a < n-1) {
      for (int j = 0; j < n; j++) {
        if (d[j][p[a+1]] > d[j][p[a]]+1) {
          d[j][p[a+1]] = d[j][p[a]]+1;
        }
      }
      for (int j = 0; j < n; j++) {
        if (d[j][p[a]] > d[j][p[a+1]]+1) {
          d[j][p[a]] = d[j][p[a+1]]+1;
        }
      }
    }
  }
  
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (d[i][p[0]] > d[i][p[j]]+j) {
        d[i][p[0]] = d[i][p[j]]+j;
      }
    }
  }
  
  for (int i = 0; i < n-1; i++) {
    ans[i] = d[i+1][p[0]];
  }
  
  printf("%d", ans[0]);
  for (int i = 1; i < n-1; i++) {
    printf(" %d", ans[i]);
  }
  printf("\n");
  
  return 0;
}
0