Submission #3859795
Source Code Expand
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()
#define all(x) beg(x), en(x)
#define resz resize
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;
const ld PI = 4*atan((ld)1);
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
namespace io {
// TYPE ID (StackOverflow)
template<class T> struct like_array : is_array<T>{};
template<class T, size_t N> struct like_array<array<T,N>> : true_type{};
template<class T> struct like_array<vector<T>> : true_type{};
template<class T> bool is_like_array(const T& a) { return like_array<T>::value; }
// I/O
void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
ios_base::sync_with_stdio(0); cin.tie(0);
if (sz(s)) { setIn(s+".in"), setOut(s+".out"); }
}
// INPUT
template<class T> void re(T& x) { cin >> x; }
template<class Arg, class... Args> void re(Arg& first, Args&... rest);
void re(double& x) { string t; re(t); x = stod(t); }
void re(ld& x) { string t; re(t); x = stold(t); }
template<class T> void re(complex<T>& x);
template<class T1, class T2> void re(pair<T1,T2>& p);
template<class T> void re(vector<T>& a);
template<class T, size_t SZ> void re(array<T,SZ>& a);
template<class Arg, class... Args> void re(Arg& first, Args&... rest) { re(first); re(rest...); }
template<class T> void re(complex<T>& x) { T a,b; re(a,b); x = cd(a,b); }
template<class T1, class T2> void re(pair<T1,T2>& p) { re(p.f,p.s); }
template<class T> void re(vector<T>& a) { F0R(i,sz(a)) re(a[i]); }
template<class T, size_t SZ> void re(array<T,SZ>& a) { F0R(i,SZ) re(a[i]); }
// OUTPUT
template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) {
os << '{' << a.f << ", " << a.s << '}'; return os;
}
template<class T> ostream& printArray(ostream& os, const T& a, int SZ) {
os << '{';
F0R(i,SZ) {
if (i) {
os << ", ";
if (is_like_array(a[i])) cout << "\n";
}
os << a[i];
}
os << '}';
return os;
}
template<class T, size_t SZ> ostream& operator<<(ostream& os, const array<T,SZ>& a) {
return printArray(os,a,SZ);
}
template<class T> ostream& operator<<(ostream& os, const vector<T>& a) {
return printArray(os,a,sz(a));
}
template<class T> ostream& operator<<(ostream& os, const set<T>& a) {
os << vector<T>(all(a)); return os;
}
template<class T1, class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {
os << vector<pair<T1,T2>>(all(a)); return os;
}
template<class T> void pr(const T& x) { cout << x << '\n'; }
template<class Arg, class... Args> void pr(const Arg& first, const Args&... rest) {
cout << first << ' '; pr(rest...);
}
}
using namespace io;
namespace modOp {
int ad(int a, int b, int mod = MOD) { return (a+b)%mod; }
int sub(int a, int b, int mod = MOD) { return (a-b+mod)%mod; }
int mul(int a, int b, int mod = MOD) { return (ll)a*b%mod; }
int AD(int& a, int b, int mod = MOD) { return a = ad(a,b,mod); }
int SUB(int& a, int b, int mod = MOD) { return a = sub(a,b,mod); }
int MUL(int& a, int b, int mod = MOD) { return a = mul(a,b,mod); }
int po (int b, int p, int mod = MOD) { return !p?1:mul(po(mul(b,b,mod),p/2,mod),p&1?b:1,mod); }
int inv (int b, int mod = MOD) { return po(b,mod-2,mod); }
int invGeneral(int a, int b) { // 0 < a < b, gcd(a,b) = 1
if (a == 0) return b == 1 ? 0 : -1;
int x = invGeneral(b%a,a);
return x == -1 ? -1 : ((1-(ll)b*x)/a+b)%b;
}
}
using namespace modOp;
int H,W;
vector<string> s;
int fac[5];
vi adj[400];
bool vis[400];
int sz = 0;
void dfs(int x) {
if (vis[x]) return;
sz ++; vis[x] = 1;
for (int y: adj[x]) dfs(y);
}
bool eq(string t) {
string T = t; reverse(all(T));
return T == t;
}
int solve() {
int ans = 1; // po(2,H/2+W/2-1)*po(12,(H/2)*(W/2));
F0R(i,400) vis[i] = 0, adj[i].clear();
for (int i = 0; i < H-1-i; ++i)
for (int j = 0; j < W-1-j; ++j) {
vpi pos;
pos.pb({i,j});
pos.pb({H-1-i,j});
pos.pb({i,W-1-j});
pos.pb({H-1-i,W-1-j});
map<char,int> oc;
trav(x,pos) oc[s[x.f][x.s]] ++;
int t = fac[sz(pos)];
trav(x,oc) t /= fac[x.s];
if (t == 24) {
MUL(ans,12);
adj[i].pb(j+200), adj[j+200].pb(i);
} else MUL(ans,t);
}
F0R(i,H) if (!vis[i]) {
sz = 0; dfs(i);
MUL(ans,po(2,sz-1));
}
if (H&1) {
if (!eq(s[H/2])) MUL(ans,2);
}
if (W&1) {
string t; F0R(i,H) t += s[i][W/2];
if (!eq(t)) MUL(ans,2);
}
return ans;
}
vector<string> revrow(vector<string> a, int b) {
reverse(all(a[b]));
return a;
}
vector<string> revcol(vector<string> a, int b) {
for (int i = 0; i < H-1-i; ++i) swap(a[i][b],a[H-1-i][b]);
return a;
}
int brute() {
set<vector<string>> S;
queue<vector<string>> q; q.push(s); S.insert(s);
while (sz(q)) {
auto a = q.front(); q.pop();
F0R(i,H) {
auto A = revrow(a,i);
if (!S.count(A)) {
S.insert(A);
q.push(A);
}
}
F0R(j,W) {
auto A = revcol(a,j);
if (!S.count(A)) {
S.insert(A);
q.push(A);
}
}
}
return sz(S);
}
int main() {
// you should actually read the stuff at the bottom
setIO();
while (cin >> H >> W) {
s.resz(H);
F0R(i,H) re(s[i]);
fac[0] = 1; FOR(i,1,5) fac[i] = i*fac[i-1];
pr(solve());
// pr(H,W,s,solve(),brute());
}
// you should actually read the stuff at the bottom
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?), set tle
* do smth instead of nothing and stay organized
*/
Submission Info
Submission Time |
|
Task |
I - Reverse Grid |
User |
Benq |
Language |
C++14 (GCC 5.4.1) |
Score |
1900 |
Code Size |
7601 Byte |
Status |
AC |
Exec Time |
5 ms |
Memory |
384 KB |
Compile Error
./Main.cpp: In function ‘void io::setIn(std::string)’:
./Main.cpp:67:56: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
void setIn(string s) { freopen(s.c_str(),"r",stdin); }
^
./Main.cpp: In function ‘void io::setOut(std::string)’:
./Main.cpp:68:58: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
^
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 |
4 ms |
256 KB |
01-12.txt |
AC |
4 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 |
5 ms |
384 KB |
01-17.txt |
AC |
5 ms |
384 KB |
01-18.txt |
AC |
5 ms |
384 KB |
01-19.txt |
AC |
4 ms |
384 KB |
01-20.txt |
AC |
4 ms |
384 KB |
01-21.txt |
AC |
4 ms |
384 KB |
01-22.txt |
AC |
1 ms |
256 KB |
01-23.txt |
AC |
3 ms |
384 KB |
01-24.txt |
AC |
5 ms |
384 KB |
01-25.txt |
AC |
5 ms |
384 KB |
01-26.txt |
AC |
5 ms |
384 KB |
01-27.txt |
AC |
2 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 |
5 ms |
384 KB |
01-32.txt |
AC |
5 ms |
384 KB |
01-33.txt |
AC |
5 ms |
384 KB |
01-34.txt |
AC |
5 ms |
384 KB |
01-35.txt |
AC |
5 ms |
384 KB |
sample-01.txt |
AC |
1 ms |
256 KB |
sample-02.txt |
AC |
1 ms |
256 KB |