結果

問題 No.327 アルファベット列
ユーザー @abcde@abcde
提出日時 2019-05-12 03:35:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,904 bytes
コンパイル時間 1,609 ms
コンパイル使用メモリ 172,888 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-14 18:26:05
合計ジャッジ時間 3,887 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 1 ms
4,380 KB
testcase_45 AC 2 ms
4,384 KB
testcase_46 AC 2 ms
4,380 KB
testcase_47 AC 1 ms
4,380 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 2 ms
4,376 KB
testcase_50 AC 1 ms
4,376 KB
testcase_51 AC 2 ms
4,380 KB
testcase_52 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using LL = long long;

int main() {
    
    // 1. 入力情報取得.
    LL N;
    cin >> N;
    
    // 2. アルファベット文字列長 と インデックス を 調査.
    // A - Z: 26個
    // AA - ZZ: 676個
    // AAA - ZZZ: 17576個
    // AAAA - ZZZZ: 456976個
    // AAAAA - ZZZZZ: 11881376個
    // AAAAAA - ZZZZZZ: 308915776個
    // AAAAAAA - ZZZZZZZ: 8031810176個
    // AAAAAAAA - ZZZZZZZZ: 208827064576個
    // AAAAAAAAA - ZZZZZZZZZ: 5429503678976個
    LL index[10] = {0, 26, 702, 18278, 475254, 12356630, 321272406, 8353082582, 217180147158, 5646683826134};
    LL l = -1;
    for(int i = 0; i < 10; i++){
        if(N < index[i]){
            l = i;
            break;
        }
    }
    // cout << "N=" << N << " l=" << l << endl;
    
    // 3. N に対するアルファベットは?
    // ex. N = 100 の 場合, l = 2 なので, AA - ZZ に含まれている.
    LL tN = N;
    tN -= index[l - 1];
    map<LL, int> m; // 26で割った回数, 余り を 保存.
    LL counter = 0;
    do{
        LL q = tN / 26;
        int r = tN % 26;
        m[counter] = r;
        tN = q;
        counter++;
    }while(tN > 0);
    // for(auto &p : m) cout << "q=" << p.first << " r=" << p.second << endl;
    
    // 4. 配列index から 土台作成.
    string ans = "";
    for(int i = 0; i < l; i++) ans += 'A';
    
    // 5. N に対するアルファベットを構築.
    // ex. 
    // N = 25   -> Z
    // N = 26   -> AA
    // N = 27   -> AB
    // N = 100  -> CW
    // N = 365  -> NB
    // N = 676  -> ZA
    // N = 701  -> ZZ
    // N = 730  -> ABC
    // N = 860  -> AGC
    // N = 1000 -> ALM
    // N= 1000000000000 -> DTMCHRXUO なのか???
    for(auto &p : m){
        char c = p.second;
        ans[l - 1 - p.first] += c;
    }
    
    // 6. 後処理.
    cout << ans << endl;
    return 0;
    
}
0