結果

問題 No.3623 2-Letter Shiritori 2
コンテスト
ユーザー GOTKAKO
提出日時 2026-08-14 23:43:56
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1 ms / 2,000 ms
+ 336µs
コード長 1,970 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,204 ms
コンパイル使用メモリ 223,496 KB
実行使用メモリ 9,364 KB
最終ジャッジ日時 2026-08-14 23:43:59
合計ジャッジ時間 2,145 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

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

    auto move = [&](char c,int add) -> char {
        int v = c-'A';
        v += add,v %= 26;
        return v+'A';
    };

    vector<vector<string>> S1(26),S2(26),S3(26),S4(26);
    for(int d=0; d<26; d++){
        if(d == 0){
            for(char c='A'; c<='Z'; c++){
                string s = "";
                s += c;
                S1.at(c-'A').push_back(s);
            }
        }
        else for(char c='A'; c<'A'+gcd(26,d); c++){
            string s = "";
            char now = c;
            s += now;
            now = move(now,d);
            while(now != c) s += now,now = move(now,d);
            if(gcd(26,d) == 13) S2.at(c-'A').push_back(s);
            if(gcd(26,d) == 2) S3.at(c-'A').push_back(s);
            if(gcd(26,d) == 1) S4.at(c-'A').push_back(s);
        }
    }
    auto dfs = [&](auto dfs,int pos) -> void {
        for(auto s : S1.at(pos)){
            int n = s.size();
            for(int i=0; i<n; i++) cout << s.at(i) << s.at((i+1)%n) << "\n";
        }
        for(auto s : S2.at(pos)){
            int n = s.size();
            for(int i=0; i<n; i++){
                cout << s.at(i) << s.at((i+1)%n) << "\n";
                if(i+1 != n) dfs(dfs,s.at(i+1)-'A');
            }    
        }
        for(auto s : S3.at(pos)){
            int n = s.size();
            for(int i=0; i<n; i++){
                cout << s.at(i) << s.at((i+1)%n) << "\n";
                if(i+1 != n) dfs(dfs,s.at(i+1)-'A');
            }    
        }
        for(auto s : S4.at(pos)){
            int n = s.size();
            for(int i=0; i<n; i++){
                cout << s.at(i) << s.at((i+1)%n) << "\n";
                if(i+1 != n) dfs(dfs,s.at(i+1)-'A');
            }    
        }
        S1.at(pos).clear();
        S2.at(pos).clear();
        S3.at(pos).clear();
        S4.at(pos).clear();
    };
    dfs(dfs,0);
}
0