結果
問題 | No.1916 Making Palindrome on Gird |
ユーザー |
|
提出日時 | 2022-04-29 21:51:36 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 478 ms / 3,000 ms |
コード長 | 2,190 bytes |
コンパイル時間 | 1,661 ms |
コンパイル使用メモリ | 145,144 KB |
最終ジャッジ日時 | 2025-01-28 22:45:32 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#pragma GCC optimize("Ofast")#include <iostream>#include <vector>#include <algorithm>#include <map>#include <queue>#include <cstdio>#include <ctime>#include <assert.h>#include <chrono>#include <random>#include <numeric>#include <set>#include <deque>#include <stack>#include <sstream>#include <utility>#include <cstring>#include <unordered_map>#include <unordered_set>#include <tuple>#include <array>#include <bitset>using namespace std;typedef long long int ll;typedef unsigned long long ull;mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());ll myRand(ll B) {return (ull)rng() % B;}inline double time() {return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;}constexpr int mod = 1e9+7;void add(int &x,int y){x += y;if(x >= mod) x -= mod;}int dx[]={0,1};int dy[]={1,0};int main(){cin.tie(nullptr);ios::sync_with_stdio(false);int h,w; cin >> h >> w;vector<string> s(h);for(int i=0;i<h;i++){cin >> s[i];}using P = pair<int,int>;map<pair<P,P>,int> mp;if(s[0][0] == s[h-1][w-1]) mp[{{0,0},{h-1,w-1}}] = 1;int loop = (h+w)/2-1;int res = 0;for(int _=0;_<loop;_++){map<pair<P,P>,int> nmp;for(auto &p:mp){int _x1 = p.first.first.first, _y1 = p.first.first.second;int _x2 = p.first.second.first, _y2 = p.first.second.second;for(int i=0;i<2;i++){int nx1 = _x1 + dx[i];int ny1 = _y1 + dy[i];for(int j=0;j<2;j++){int nx2 = _x2 - dx[j];int ny2 = _y2 - dy[j];if(nx1 <= nx2 and ny1 <= ny2 and s[nx1][ny1] == s[nx2][ny2]){add(nmp[{{nx1,ny1},{nx2,ny2}}], p.second);}}}}swap(nmp,mp);}for(auto p:mp){auto v1 = p.first.first, v2 = p.first.second;if(abs(v1.first-v2.first)+abs(v1.second-v2.second) <= 1){add(res, p.second);}}cout << res << endl;}