結果

問題 No.327 アルファベット列
ユーザー kichirb3
提出日時 2018-04-06 08:27:58
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 895 bytes
コンパイル時間 657 ms
コンパイル使用メモリ 78,996 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-26 10:44:44
合計ジャッジ時間 1,922 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #

// No.327 アルファベット列
// https://yukicoder.me/problems/no/327
//
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
using namespace std;

string solve(long long int N);


int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    long long N;
    cin >> N;
    string ans = solve(N);
    cout << ans << endl;
}

string solve(long long int N) {
    vector<long long> acc;
    acc.push_back(0);
    for (int i = 1; i < 10; ++i)
        acc.push_back(acc[i-1] + pow(26, i));

    int keta = upper_bound(acc.begin(), acc.end(), N) - acc.begin();
    long long offset = N - acc[keta-1];

    string ans = "";
    for (int i = 0; i < keta; ++i) {
        int t = offset % 26;
        ans += 'A' + t;
        offset /= 26;
    }
    reverse(ans.begin(), ans.end());
    return ans;
}
0