Submission #5305681
Source Code Expand
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
struct uf {
private:
vector<int> par, ran;
public:
void init(int n) {
par.resize(n, 0);
ran.resize(n, 0);
rep(i, n) {
par[i] = i;
}
}
int find(int x) {
if (par[x] == x)return x;
else return par[x] = find(par[x]);
}
void unite(int x, int y) {
x = find(x), y = find(y);
if (x == y)return;
if (ran[x] < ran[y]) {
par[x] = y;
}
else {
par[y] = x;
if (ran[x] == ran[y])ran[x]++;
}
}
bool same(int x, int y) {
return find(x) == find(y);
}
};
struct perm {
private:
int sz;
vector<ll> p, invp;
public:
perm(int n) {
sz = n + 1;
p.resize(sz), invp.resize(sz);
p[0] = 1;
rep1(i, sz - 1) {
p[i] = p[i - 1] * i%mod;
}
invp[sz - 1] = 1;
ll cop = mod - 2, x = p[sz - 1];
while (cop) {
if (cop % 2)invp[sz - 1] = invp[sz - 1] * x%mod;
cop >>= 1; x = x * x % mod;
}
per(i, sz - 1) {
invp[i] = invp[i + 1] * (i + 1) % mod;
}
}
ll comb(ll x, ll y) {
if (x < y || y < 0)return 0;
ll ret = p[x];
(ret *= invp[y]) %= mod;
(ret *= invp[x - y]) %= mod;
return ret;
}
ll combP(ll x, ll y) {
if (x < y || y < 0)return 0;
return p[x] * invp[x - y] % mod;
}
};
int h, w;
ll mod_inverse(ll x, ll n = mod - 2) {
ll ret = 1;
while (n) {
if (n % 2)ret = ret * x%mod;
x = x * x%mod; n >>= 1;
}
return ret;
}
int b[100][100];
int cnt;
bool used[200];
queue<P> cur;
void calc() {
h /= 2; w /= 2;
uf u; u.init(h + w+1);
rep(i, h) {
rep(j, w) {
if (b[i][j]) {
u.unite(i, h + j);
cnt++;
}
}
}
int g = h + w;
rep(i, h + w) {
if (u.same(g, i))continue;
cnt++; u.unite(g, i);
}
cnt -= h + w;
}
void solve() {
cin >> h >> w;
vector<char> v;
rep(i, h) {
rep(j, w) {
char t; cin >> t; v.push_back(t);
}
}
perm p(200);
int alf[26] = {};
rep(i, v.size()) {
alf[v[i] - 'a']++;
}
ll sum = 1;
rep(i, h / 2) {
rep(j, w / 2) {
vector<char> e;
e.push_back(v[i*w + j]);
e.push_back(v[i*w + w - 1 - j]);
e.push_back(v[(h - 1 - i)*w + j]);
e.push_back(v[(h - 1 - i)*w + w - 1 - j]);
sort(e.begin(), e.end());
ll z = 4;
int tmp = 0;
rep(k, 4) {
tmp++;
int le = k;
while (k + 1 < 4 && e[k + 1] == e[k])k++;
sum = sum * p.comb(z, k - le + 1) % mod;
z -= k - le + 1;
}
if (tmp == 4) {
b[i][j] = 1;
}
}
}
if (h % 2) {
int ch = h / 2; ch *= w;
bool f = false;
rep(j, w / 2) {
if (v[ch + j] != v[ch + w - 1 - j])f = true;
}
if (f)sum = sum * 2 % mod;
}
if (w % 2) {
int cw = w / 2;
bool f = false;
rep(i, h / 2) {
if (v[i*w + cw] != v[(h - 1 - i)*w + cw])f = true;
}
if (f)sum = sum * 2 % mod;
}
calc();
rep(i, cnt) {
sum = sum * (mod + 1) / 2 % mod;
}
cout << sum << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
solve();
//stop
return 0;
}
Submission Info
Submission Time |
|
Task |
I - Reverse Grid |
User |
heno239 |
Language |
C++14 (GCC 5.4.1) |
Score |
1900 |
Code Size |
3927 Byte |
Status |
AC |
Exec Time |
4 ms |
Memory |
384 KB |
Judge Result
Set Name |
sample |
all |
Score / Max Score |
0 / 0 |
1900 / 1900 |
Status |
|
|
Set Name |
Test Cases |
sample |
sample-01.txt, sample-02.txt |
all |
sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt, 01-31.txt, 01-32.txt, 01-33.txt, 01-34.txt, 01-35.txt, sample-01.txt, sample-02.txt |
Case Name |
Status |
Exec Time |
Memory |
01-01.txt |
AC |
1 ms |
256 KB |
01-02.txt |
AC |
1 ms |
256 KB |
01-03.txt |
AC |
1 ms |
256 KB |
01-04.txt |
AC |
1 ms |
256 KB |
01-05.txt |
AC |
1 ms |
256 KB |
01-06.txt |
AC |
1 ms |
256 KB |
01-07.txt |
AC |
1 ms |
256 KB |
01-08.txt |
AC |
1 ms |
256 KB |
01-09.txt |
AC |
1 ms |
256 KB |
01-10.txt |
AC |
3 ms |
384 KB |
01-11.txt |
AC |
3 ms |
384 KB |
01-12.txt |
AC |
3 ms |
384 KB |
01-13.txt |
AC |
3 ms |
384 KB |
01-14.txt |
AC |
2 ms |
256 KB |
01-15.txt |
AC |
2 ms |
384 KB |
01-16.txt |
AC |
4 ms |
384 KB |
01-17.txt |
AC |
3 ms |
384 KB |
01-18.txt |
AC |
4 ms |
384 KB |
01-19.txt |
AC |
3 ms |
384 KB |
01-20.txt |
AC |
3 ms |
384 KB |
01-21.txt |
AC |
3 ms |
384 KB |
01-22.txt |
AC |
1 ms |
256 KB |
01-23.txt |
AC |
2 ms |
384 KB |
01-24.txt |
AC |
3 ms |
384 KB |
01-25.txt |
AC |
3 ms |
384 KB |
01-26.txt |
AC |
4 ms |
384 KB |
01-27.txt |
AC |
1 ms |
256 KB |
01-28.txt |
AC |
2 ms |
256 KB |
01-29.txt |
AC |
1 ms |
256 KB |
01-30.txt |
AC |
2 ms |
256 KB |
01-31.txt |
AC |
3 ms |
384 KB |
01-32.txt |
AC |
3 ms |
384 KB |
01-33.txt |
AC |
3 ms |
384 KB |
01-34.txt |
AC |
3 ms |
384 KB |
01-35.txt |
AC |
3 ms |
384 KB |
sample-01.txt |
AC |
1 ms |
256 KB |
sample-02.txt |
AC |
1 ms |
256 KB |