結果

問題 No.701 ひとりしりとり
ユーザー tsutajtsutaj
提出日時 2018-06-15 22:33:40
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 217 ms / 2,000 ms
コード長 1,967 bytes
コンパイル時間 1,059 ms
コンパイル使用メモリ 109,284 KB
実行使用メモリ 70,520 KB
最終ジャッジ日時 2023-09-13 04:51:14
合計ジャッジ時間 3,424 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
68,860 KB
testcase_01 AC 94 ms
69,516 KB
testcase_02 AC 93 ms
68,852 KB
testcase_03 AC 94 ms
68,312 KB
testcase_04 AC 94 ms
68,628 KB
testcase_05 AC 95 ms
69,340 KB
testcase_06 AC 94 ms
70,520 KB
testcase_07 AC 94 ms
67,660 KB
testcase_08 AC 94 ms
67,784 KB
testcase_09 AC 96 ms
68,444 KB
testcase_10 AC 108 ms
70,124 KB
testcase_11 AC 217 ms
67,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

vector<string> words[30];
vector<string> words_end[30];

int cnt = 0;
void generate() {
    queue<string> que;
    que.push("");

    while(cnt < 1000000) {
        string s = que.front(); que.pop();
        if(s.length() == 20) continue;

        for(int i=0; i<26; i++) {
            cnt++;
            string ns = s + (char)('a' + i);

            int fst_c = ns[0] - 'a';
            if(ns.back() == 'n') {
                words_end[fst_c].push_back(ns);
            }
            else {
                words[fst_c].push_back(ns);
            }

            que.push(ns);
        }
    }
}

signed main() {
    generate();
    int N; cin >> N;

    vector<int> ptr(26, 0);

    int chr = 0;
    for(int i=0; i<N-1; i++) {
        string ans = words[chr][ ptr[chr]++ ];
        chr = ans.back() - 'a';
        cout << ans << endl;
    }
    cout << words_end[chr][0] << endl;
    return 0;
}
0