結果

問題 No.429 CupShuffle
ユーザー rsk0315rsk0315
提出日時 2019-02-19 01:23:37
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 1,053 bytes
コンパイル時間 404 ms
コンパイル使用メモリ 44,032 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 11:01:18
合計ジャッジ時間 1,441 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 5 ms
5,376 KB
testcase_11 AC 33 ms
5,376 KB
testcase_12 AC 32 ms
5,376 KB
testcase_13 AC 35 ms
5,376 KB
testcase_14 AC 34 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:49:16: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘size_t’ {aka ‘long unsigned int’} [-Wformat=]
   49 |       printf("%d%c", i, sep);
      |               ~^     ~
      |                |     |
      |                int   size_t {aka long unsigned int}
      |               %ld
main.cpp:14:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   14 |   scanf("%zu %zu %zu", &N, &K, &X);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:21:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   21 |     scanf("%zu %zu", &A, &B);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
main.cpp:25:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   25 |   scanf(" ? ?");
      |   ~~~~~^~~~~~~~
main.cpp:30:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   30 |     scanf("%zu %zu", &ai, &bi);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
main.cpp:39:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   39 |     scanf("%d", &C[i]);
      |     ~~~~~^~~~~~~~~~~~~

ソースコード

diff #

#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>

void inspect(const std::vector<int>& a) {
  return;
  for (size_t i = 0; i < a.size(); ++i)
    fprintf(stderr, "%d%c", a[i], i+1<a.size()? ' ':'\n');
}

int main() {
  size_t N, K, X;
  scanf("%zu %zu %zu", &N, &K, &X);

  std::vector<int> a(N+1);
  std::iota(a.begin(), a.end(), 0);

  for (size_t i = 1; i < X; ++i) {
    size_t A, B;
    scanf("%zu %zu", &A, &B);
    std::swap(a[A], a[B]);
    inspect(a);
  }
  scanf(" ? ?");

  std::vector<int> A, B;
  for (size_t i = X; i < K; ++i) {
    size_t ai, bi;
    scanf("%zu %zu", &ai, &bi);
    A.push_back(ai);
    B.push_back(bi);
  }
  std::reverse(A.begin(), A.end());
  std::reverse(B.begin(), B.end());

  std::vector<int> C(N+1);
  for (size_t i = 1; i <= N; ++i)
    scanf("%d", &C[i]);

  for (size_t i = 0; i < A.size(); ++i) {
    std::swap(C[A[i]], C[B[i]]);
    inspect(C);
  }

  char sep = ' ';
  for (size_t i = 1; i <= N; ++i)
    if (a[i] != C[i]) {
      printf("%d%c", i, sep);
      sep = '\n';
    }
}
0