結果

問題 No.327 アルファベット列
ユーザー LeonardoneLeonardone
提出日時 2015-12-20 02:16:18
言語 Ruby
(3.3.0)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 1,541 bytes
コンパイル時間 101 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2024-04-16 07:07:26
合計ジャッジ時間 6,224 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
12,160 KB
testcase_01 AC 94 ms
12,288 KB
testcase_02 AC 86 ms
12,288 KB
testcase_03 AC 88 ms
12,160 KB
testcase_04 AC 89 ms
12,160 KB
testcase_05 AC 92 ms
12,160 KB
testcase_06 AC 90 ms
12,160 KB
testcase_07 AC 88 ms
12,160 KB
testcase_08 AC 87 ms
12,288 KB
testcase_09 AC 89 ms
12,160 KB
testcase_10 AC 89 ms
12,288 KB
testcase_11 AC 89 ms
12,160 KB
testcase_12 AC 89 ms
12,288 KB
testcase_13 AC 89 ms
12,160 KB
testcase_14 AC 91 ms
12,160 KB
testcase_15 AC 90 ms
12,160 KB
testcase_16 AC 89 ms
12,160 KB
testcase_17 AC 89 ms
12,288 KB
testcase_18 AC 88 ms
12,160 KB
testcase_19 AC 89 ms
12,160 KB
testcase_20 AC 89 ms
12,288 KB
testcase_21 AC 88 ms
12,416 KB
testcase_22 AC 89 ms
12,032 KB
testcase_23 AC 87 ms
12,160 KB
testcase_24 AC 89 ms
12,032 KB
testcase_25 AC 89 ms
12,288 KB
testcase_26 AC 88 ms
12,288 KB
testcase_27 AC 87 ms
12,160 KB
testcase_28 AC 93 ms
12,160 KB
testcase_29 AC 88 ms
12,288 KB
testcase_30 AC 89 ms
12,160 KB
testcase_31 AC 87 ms
12,160 KB
testcase_32 AC 88 ms
12,288 KB
testcase_33 AC 89 ms
12,160 KB
testcase_34 AC 91 ms
12,160 KB
testcase_35 AC 92 ms
12,160 KB
testcase_36 AC 92 ms
12,032 KB
testcase_37 AC 90 ms
12,160 KB
testcase_38 AC 89 ms
12,288 KB
testcase_39 AC 88 ms
12,288 KB
testcase_40 AC 89 ms
12,288 KB
testcase_41 AC 89 ms
12,160 KB
testcase_42 AC 90 ms
12,160 KB
testcase_43 AC 89 ms
12,160 KB
testcase_44 AC 89 ms
12,032 KB
testcase_45 AC 88 ms
12,160 KB
testcase_46 AC 89 ms
12,160 KB
testcase_47 AC 94 ms
12,288 KB
testcase_48 AC 91 ms
12,160 KB
testcase_49 AC 89 ms
12,032 KB
testcase_50 AC 96 ms
12,160 KB
testcase_51 AC 92 ms
12,160 KB
testcase_52 AC 95 ms
12,160 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

#! ruby
# yukicoder My Practice
# author: Leonardone @ NEETSDKASU
############################################################
def gs() gets.chomp end
def gi() gets.to_i end
def gss() gs.split end
def gis() gss.map(&:to_i) end
def nmapf(n,f) n.times.map{ __send__ f } end
def ngs(n) nmapf n,:gs end
def ngi(n) nmapf n,:gi end
def ngss(n) nmapf n,:gss end
def ngis(n) nmapf n,:gis end
def arr2d(h,w,v=0) h.times.map{[v] * w} end
def for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end
def nsum(n) n * (n + 1) / 2 end
def vcount(d,r=Hash.new(0)) d.inject(r){|r,e| r[e]+=1;r} end
############################################################

=begin
前にAtCoderで似たようなのあった
その時の解説を思い出してみる

0000000000000000
000000000000000A
000000000000000B
..
000000000000000Z
00000000000000AA
00000000000000AB
..
00000000000000AZ
00000000000000BA
..
00000000000000ZZ
0000000000000AAA

1桁目のAは0が1=26**0個続いた後に26**1回ごとに1=26**0個出現
2桁目のAは0が26**0+26**1個続いたあとに26**2回ごとに26**1個出現
3桁目のAは0が26**0+26**1+26**2個続いた後に26**3回ごとに26**2個個出現

つまり、最初の000000を無視したとして考えて
n から 26**1+26**2 を引いて 26**3 で割った余りを 26**2で割った値が3桁目のアルファベットになる
=end

al = ('A'..'Z').to_a
n = gi 
s = -1
d1 = 1
d2 = 26
ans = ""
loop {
    s += d1
    break if s > n
    ans << al[((n - s) % d2) / d1]
    d1 = d2
    d2 *= 26
}
puts ans.reverse




0