結果
問題 | No.2131 Concon Substrings (COuNt Version) |
ユーザー |
|
提出日時 | 2024-09-15 12:19:38 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 3,820 bytes |
コンパイル時間 | 1,126 ms |
コンパイル使用メモリ | 115,556 KB |
最終ジャッジ日時 | 2025-02-24 08:42:29 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | MLE * 4 |
other | MLE * 16 |
ソースコード
#include<iostream> #include<string> #include<queue> #include<vector> #include<cassert> #include<random> #include<set> #include<map> #include<cassert> #include<unordered_map> #include<bitset> #include<numeric> #include<algorithm> using namespace std; typedef long long ll; const int inf=1<<30; const ll INF=1LL<<62; typedef pair<int,int> P; typedef pair<int,P> PP; const ll MOD=998244353; const int mod = 998244353; struct mint { long long x; // typedef long long long long; mint(long long x=0):x((x%mod+mod)%mod){} mint operator-() const { return mint(-x);} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;} mint operator+(const mint a) const { return mint(*this) += a;}//後ろのconstはメンバxを変更しないことを示す mint operator-(const mint a) const { return mint(*this) -= a;} mint operator*(const mint a) const { return mint(*this) *= a;} bool operator==(const mint a) const {return a.x==x;} mint pow(unsigned long long int t) const { assert(t>=0); if (!t) return 1; //aがtで割り切れない場合には t%=(mod-1)をして良い mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod-2);} mint& operator/=(const mint a) { return *this *= a.inv();} mint operator/(const mint a) const { return mint(*this) /= a;} }; std::istream& operator>>(std::istream& is, mint& a) { return is >> a.x;} std::ostream& operator<<(std::ostream& os, const mint& a) { return os << a.x;} struct combination { std::vector<mint> fact, ifact; combination(int n):fact(n+1),ifact(n+1) { assert(n < mod); fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; return fact[n]*ifact[k]*ifact[n-k]; } }; combination comb(305*305*305); /* S=conconconcon.... i文字目までみた.Sのj文字目まで一致 */ mint dp[3005][3005]; int main(){ int N; cin>>N; dp[0][0]=1; for(int i=0;i<N;i++){ for(int j=0;j<=N;j++){ dp[i+1][j]+=dp[i][j]*25; dp[i+1][j+1]+=dp[i][j];//con を構成する文字列 } } mint ans=0; for(int i=0;i<=N;i++){ ans+=dp[N][i]*(i/3); } cout<<ans<<endl; // mint ans=0; // mint twenty_six=26; // vector<mint> pow26(N+1); // pow26[0]=1; // for(int i=1;i<=N;i++){ // pow26[i]=pow26[i-1]*26; // } // for(int t=1;t<=N/3;t++){ // //conをt個 // int u=N-3*t; // mint c=1; // c*=comb(N,t*3);//N文字の中からconを入れる場所を考える // c*=pow26[u]; // ans+=c; // } // cout<<ans<<endl; // { // dp[0][0][0]=1; // for(int i=0;i<N;i++){ // for(int k=0;k<=1000;k++){ // for(int j=0;j<4;j++){ // //i文字目を採用しない // dp[i+1][j][k]+=dp[i][j][k]*26; // } // // for(char c='a';c<='z';c++){ // // int x=c-'a'; // //文字c // dp[i+1][1][k]+=dp[i][0][k]; // //文字o // dp[i+1][2][k]+=dp[i][1][k]; // //文字n // dp[i+1][0][k+1]+=dp[i][2][k]; // //} // } // } // mint ans=0; // for(int i=0;i<=N/3;i++){ // ans+=dp[N][0][i]*i; // } // cout<<ans<<endl; // } }