QOJ.ac

QOJ

Límite de tiempo: 2 s Límite de memoria: 64 MB Puntuación total: 100

#23759. カードの並び替え

Estadísticas
問題
4
   カードの並び替え

問題

1 から 2n の数が書かれた 2n 枚のカードがあり, 上から 1, 2, 3, ... , 2n の順に積み重なっている.

このカードを, 次の方法を何回か用いて並べ替える.

整数 k でカット
上から k 枚のカードの山 A と 残りのカードの山 B に分けた後, 山 A の上に山 B をのせる.
cut

リフルシャッフル
上から n 枚の山 A と残りの山 B に分け, 上から A の1枚目, B の1枚目, A の2枚目, B の2枚目, …, A の n枚目, B の n枚目, となるようにして, 1 つの山にする.
shuffle

入力ファイルの指示に従い, カードを並び替えたあとのカードの番号を, 上から順番に出力するプログラムを作成せよ.

入力

  • 1 行目には n (1 ≦ n ≦ 100)が書かれている. すなわちカードの枚数は 2n 枚である.
  • 2 行目には操作の回数 m (1 ≦ m ≦ 1000)が書かれている.
  • 3 行目から m + 2 行目までの m 行には, 0 から 2n-1 までのいずれか 1 つの整数 k が書かれており, カードを並べ替える方法を順に指定している.
    • k = 0 の場合は, リフルシャッフルを行う.
    • 1 ≦ k ≦ 2n-1 の場合は, k でカットを行う.

出力

2n 行からなる出力ファイルを提出せよ. 1 行目には並べ替え終了後の一番上のカードの番号, 2 行目には並べ替え終了後の上から 2 番目のカードの番号というように, i 行目には上から i 番目のカードの番号を出力せよ.

入出力例

入力例1

入力例2

2
2
1
0




3
4
2
4
0
0

 

出力例1

出力例2

2
4
3
1




1
5
4
3
2
6

※各入出力例のデータは, 右クリック等によりファイルに保存して利用可能です.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.