結果

問題 No.701 ひとりしりとり
ユーザー @abcde@abcde
提出日時 2019-05-27 00:44:49
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 1,123 bytes
コンパイル時間 1,541 ms
コンパイル使用メモリ 167,148 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 18:06:50
合計ジャッジ時間 2,458 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 6 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    
    // 1. 入力情報取得.
    int N;
    scanf("%d", &N);
    
    // 2. ひとりしりとりする.
    // 1 * 26 * 26 * 26 * 26 * 1 = 456976
    const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";
    for(int i = 0; i < N; i++){
        
        // 2-1. しりとりを作成.
        int d1 = i / 17576;
        int d2 = (i - d1 * 17576) / 676;
        int d3 = (i - d1 * 17576 - d2 * 676) / 26;
        int d4 = i - d1 * 17576 - d2 * 676 - d3 * 26;
        
        // cout << "d1=" << d1 << " d2=" << d2 << " d3=" << d3 << " d4=" << d4 << endl;
        char ans[8] = "######";
        ans[0] = ans[5] = ALPHABET[0];
        ans[1] = ALPHABET[d1];
        ans[2] = ALPHABET[d2];
        ans[3] = ALPHABET[d3];
        ans[4] = ALPHABET[d4];
        
        // 2-2. 終了確認(末尾を 'n' に 変更).
        if(i == N - 1) ans[5] = ALPHABET[13];
        
        // 2-3. 出力.
        // 最大で スタート: aaaaaa ~ ゴール: afrydn までを出力.
        printf("%s\n", ans);
    }
    
    // 3. 後処理.
    return 0;
    
}
0