結果

問題 No.1755 Almost Palindrome
ユーザー milanis48663220milanis48663220
提出日時 2023-08-05 01:53:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 166 ms / 2,000 ms
コード長 2,615 bytes
コンパイル時間 1,754 ms
コンパイル使用メモリ 123,552 KB
実行使用メモリ 6,940 KB
最終ジャッジ日時 2024-04-22 23:58:06
合計ジャッジ時間 2,644 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 166 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>
#include <atcoder/modint>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}


using mint = atcoder::modint998244353;

ostream& operator<<(ostream& os, const mint& m){
    os << m.val();
    return os;
}

bool is_p(string s){
    string t = s;
    reverse(t.begin(), t.end());
    return s == t;
}

bool ok(string s){
    if(is_p(s)) return false;
    int n = s.size();
    for(int i = 0; i < n; i++){
        string t;
        for(int j = 0; j < n; j++){
            if(i == j) continue;
            t += s[j];
        }
        if(is_p(t)) return true;
    }
    return false;
}

mint naive(int n){
    string s;
    mint ans = 0;
    function<void(int)> dfs = [&](int i){
        if(i == n){
            if(ok(s)){
                ans++;
            }
            return;
        }
        for(int x = 0; x < 26; x++){
            s += 'a'+x;
            dfs(i+1);
            s.pop_back();
        }
    };
    dfs(0);
    return ans;
}

mint solve(int n){
    if(n == 1){
        return mint(0);
    }
    if(n == 2){
        return mint(26)*25;
    }
    mint ans = mint(26)*25*mint(26).pow(n/2-1);
    mint x = 2*((n-1)/2);
    if(n%2 == 0) x++;
    ans *= x;
    if(n%2 == 0){
        int m = (n-4)/2;
        ans -= 26*25*(mint(26).pow(m+1)-1)/25;
    }
    return ans;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int t; cin >> t;
    while(t--) {
        int n; cin >> n;
        cout << solve(n) << endl;   
    }
}
0