1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ABC380Dの自分なりの回答

Posted at

前提

sの長さの範囲的に二重ループまではいけそう
kの範囲的にループは無理そう

小さな例で可視化

問題だけ読んでもわからないから、具体例で把握する。

S = "ab"
ステップ1: ab‖AB
ステップ2: ab‖AB‖AB‖ab
ステップ3: ab‖AB‖AB‖ab‖AB‖ab‖ab‖AB
ステップ4: ab‖AB‖AB‖ab‖AB‖ab‖ab‖AB‖AB‖ab‖ab‖AB‖ab‖AB‖AB‖ab

「倍倍」で増えているため、bitに着目する

実際に解くときは過去の経験上、法則を見つけるためにbitにとりあえず着目してみようという感じ。

ステップ3までを表で表す。Bは何ブロック目なのか表す。

B 2進表記 反転回数 1の個数
0 000 0 0
1 001 1 1
2 010 1 1
3 011 2 2
4 100 1 1
5 101 2 2
6 110 2 2
7 111 3 3
  1. 法則を見つける

ステップ2まで

B 2進表記 反転回数 1の個数
0 000 0 0
1 001 1 1
2 010 1 1
3 011 2 2

ステップ3まで

B 2進表記 反転回数 1の個数
0 000 0 0
1 001 1 1
2 010 1 1
3 011 2 2
4 100 1 1
5 101 2 2
6 110 2 2
7 111 3 3

$B$が0~3と4~7は、順に下位2bitが一緒。
最上位bitのみ反転している!

これより、以下のことが言えそう。

ステップ$i$まで
下位$1$~$i-1$bitをコピーする。
コピー元の下位$i$bitに0を、コピー先の下位$i$bitに1を追加する。0とは文字をかえない、1とは文字を変えるという意味。

回答

文字を変えるかどうかは、何ブロック目かをbitで表した時の1の数を数えていけば良い。

何ブロック目なのかは

cin >> k;
k--;
long long block = k / s.size()

で計算できる。

ブロック内のindexは

long long index = k % s.size()

で計算できる。

感想

「倍倍」で増えているということから、bitに着目するなんていう発想出てこなかった。
こんなの経験しないとわからないよ。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?