結果

問題 No.1916 Making Palindrome on Gird
ユーザー KKT89KKT89
提出日時 2022-04-29 21:51:36
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 521 ms / 3,000 ms
コード長 2,190 bytes
コンパイル時間 1,787 ms
コンパイル使用メモリ 144,268 KB
実行使用メモリ 5,232 KB
最終ジャッジ日時 2023-09-11 12:52:20
合計ジャッジ時間 6,811 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 35 ms
4,380 KB
testcase_16 AC 21 ms
4,376 KB
testcase_17 AC 66 ms
4,376 KB
testcase_18 AC 204 ms
4,536 KB
testcase_19 AC 194 ms
4,380 KB
testcase_20 AC 197 ms
4,380 KB
testcase_21 AC 200 ms
4,380 KB
testcase_22 AC 198 ms
4,412 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 518 ms
5,128 KB
testcase_29 AC 516 ms
5,080 KB
testcase_30 AC 515 ms
5,128 KB
testcase_31 AC 514 ms
5,128 KB
testcase_32 AC 521 ms
5,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}


0