結果
問題 | No.1916 Making Palindrome on Gird |
ユーザー | cureskol |
提出日時 | 2022-04-29 22:31:13 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 406 ms / 3,000 ms |
コード長 | 3,476 bytes |
コンパイル時間 | 2,246 ms |
コンパイル使用メモリ | 191,184 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-29 04:06:24 |
合計ジャッジ時間 | 5,855 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,944 KB |
testcase_07 | AC | 1 ms
6,944 KB |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 1 ms
6,944 KB |
testcase_10 | AC | 2 ms
6,944 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 1 ms
6,944 KB |
testcase_13 | AC | 2 ms
6,944 KB |
testcase_14 | AC | 2 ms
6,944 KB |
testcase_15 | AC | 40 ms
6,940 KB |
testcase_16 | AC | 21 ms
6,944 KB |
testcase_17 | AC | 82 ms
6,944 KB |
testcase_18 | AC | 185 ms
6,940 KB |
testcase_19 | AC | 183 ms
6,940 KB |
testcase_20 | AC | 188 ms
6,944 KB |
testcase_21 | AC | 188 ms
6,944 KB |
testcase_22 | AC | 194 ms
6,944 KB |
testcase_23 | AC | 2 ms
6,940 KB |
testcase_24 | AC | 2 ms
6,940 KB |
testcase_25 | AC | 2 ms
6,940 KB |
testcase_26 | AC | 2 ms
6,944 KB |
testcase_27 | AC | 2 ms
6,940 KB |
testcase_28 | AC | 391 ms
6,944 KB |
testcase_29 | AC | 406 ms
6,940 KB |
testcase_30 | AC | 397 ms
6,940 KB |
testcase_31 | AC | 395 ms
6,944 KB |
testcase_32 | AC | 404 ms
6,940 KB |
コンパイルメッセージ
main.cpp:30:3: warning: inline variables are only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 30 | inline static constexpr T mod = MOD; | ^~~~~~ main.cpp: In function 'int main()': main.cpp:113:20: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 113 | for(const auto&[key,val]:mp){ | ^ main.cpp:114:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 114 | const auto&[y1,y2] = key; | ^ main.cpp:132:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 132 | for(const auto&[key,val]:mp) | ^
ソースコード
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0;i<(n);i++) #define ALL(v) v.begin(),v.end() #define debug(a) cerr<<#a<<":"<<a<<endl; #define debug2(a,b) cerr<<"("<<#a<<","<<#b<<"):("<<a<<","<<b<<")"<<endl; #define debug3(a,b,c) cerr<<"("<<#a<<","<<#b<<","<<#c<<"):("<<a<<","<<b<<","<<c<<")"<<endl; #define debug4(a,b,c,d) cerr<<"("<<#a<<","<<#b<<","<<#c<<","<<#d<<"):("<<a<<","<<b<<","<<c<<","<<d<<")"<<endl; template<typename T> istream& operator>>(istream&is,vector<T>&v){ for(T&p:v)is>>p; return is; } template<typename T> ostream& operator<<(ostream&os,const vector<T>&v){ if(&os==&cerr)os<<"["; for(int i=0;i<v.size();i++){ os<<v[i]; if(i+1<v.size())os<<(&os==&cerr?",":" "); } if(&os==&cerr)os<<"]"; return os; } template<typename T,T MOD=998244353> struct Mint{ inline static constexpr T mod = MOD; T v; Mint():v(0){} Mint(signed v):v(v){} Mint(long long t){v=t%MOD;if(v<0)v+=MOD;} Mint pow(long long k){ Mint res(1),tmp(v); while(k){ if(k&1)res*=tmp; tmp*=tmp; k>>=1; } return res; } static Mint add_identity(){return Mint(0);} static Mint mul_identity(){return Mint(1);} Mint inv(){return pow(MOD-2);} Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;} Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;} Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;} Mint& operator/=(Mint a){return (*this)*=a.inv();} Mint operator+(Mint a) const{return Mint(v)+=a;} Mint operator-(Mint a) const{return Mint(v)-=a;} Mint operator*(Mint a) const{return Mint(v)*=a;} Mint operator/(Mint a) const{return Mint(v)/=a;} Mint operator+() const{return *this;} Mint operator-() const{return v?Mint(MOD-v):Mint(v);} bool operator==(const Mint a)const{return v==a.v;} bool operator!=(const Mint a)const{return v!=a.v;} static Mint comb(long long n,int k){ Mint num(1),dom(1); for(int i=0;i<k;i++){ num*=Mint(n-i); dom*=Mint(i+1); } return num/dom; } friend ostream& operator<<(ostream&os,const Mint &m){os<<m.v;return os;} friend istream& operator>>(istream&is,Mint &m){is>>m.v;m.v%=MOD;if(m.v<0)m.v+=MOD;return is;} }; using mint=Mint<long long,1000000007>; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int h,w;cin>>h>>w; vector<string> s(h); cin>>s; map<pair<int,int>,mint> mp; int a=-1,b; if((h+w-1)&1){ REP(i,h)REP(j,w)if((i+1+j+1-1)*2-1 == h+w-1){ mp[{i,i}]=1; a=i+j,b=i+j; } } else{ REP(i,h)REP(j,w)if((i+1+j+1-1)*2 == h+w-1){ if(i+1<h and s[i+1][j]==s[i][j])mp[{i,i+1}]=1; if(j+1<w and s[i][j+1]==s[i][j])mp[{i,i}]=1; a=i+j,b=i+j+1; } } if(a<0){ cout<<0<<endl; return 0; } while(a){ map<pair<int,int>,mint> nxt; for(const auto&[key,val]:mp){ const auto&[y1,y2] = key; int x1=a-y1; int x2=b-y2; assert(x1>=0 and x2>=0); //debug4(y1,x1,y2,x2); //debug(val); if(x1 and x2+1<w and s[y1][x1-1]==s[y2][x2+1])nxt[{y1,y2}]+=val; if(x1 and y2+1<h and s[y1][x1-1]==s[y2+1][x2])nxt[{y1,y2+1}]+=val; if(y1 and x2+1<w and s[y1-1][x1]==s[y2][x2+1])nxt[{y1-1,y2}]+=val; if(y1 and y2+1<h and s[y1-1][x1]==s[y2+1][x2])nxt[{y1-1,y2+1}]+=val; } mp=nxt; a--;b++; } assert(a==0 and b==h-1+w-1); mint ans=0; for(const auto&[key,val]:mp) ans+=val; cout<<ans<<endl; }