結果

問題 No.3726 Flawless Flow
コンテスト
ユーザー tnakao0123
提出日時 2026-09-21 12:57:37
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,164 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 159 ms
コンパイル使用メモリ 54,560 KB
実行使用メモリ 10,036 KB
最終ジャッジ日時 2026-09-21 12:57:43
合計ジャッジ時間 3,512 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 48 WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/* -*- coding: utf-8 -*-
 *
 * 3726.cc:  No.3726 Flawless Flow - yukicoder
 */

#include<cstdio>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_N = 500;

/* typedef */

/* global variables */

int as[MAX_N], bs[MAX_N];
int bps[MAX_N], cps[MAX_N + 1][MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", as + i), as[i]--;
  for (int i = 0; i < n; i++) scanf("%d", bs + i), bs[i]--;

  for (int i = 0; i < n; i++) bps[bs[i]] = i;
  for (int i = 0; i < n; i++) cps[0][i] = bps[as[i]];
  //for (int i = 0; i < n; i++) printf(" %d", cps[0][i]); putchar('\n');
  
  for (int i = 0; i < n; i++) {
    copy(cps[i], cps[i] + n, cps[i + 1]);
    for (int j = 0; j < n;) {
      if (j + 1 < n && cps[i + 1][j] > cps[i + 1][j + 1]) {
	swap(cps[i + 1][j], cps[i + 1][j + 1]);
	j += 2;
      }
      else
	j++;
    }
  }

  for (int j = 0; j + 1 < n; j++)
    if (cps[n][j] > cps[n][j + 1]) {
      puts("-1");
      return 0;
    }

  for (int i = 0; i <= n; i++)
    for (int j = 0; j < n; j++)
      printf("%d%c", bs[cps[i][j]] + 1, (j + 1 < n) ? ' ' : '\n');
  
  return 0;
}

0