Submission #5184915
Source Code Expand
#include "iostream" #include "climits" #include "list" #include "queue" #include "stack" #include "set" #include "functional" #include "algorithm" #include "string" #include "map" #include "unordered_map" #include "unordered_set" #include "iomanip" #include "cmath" #include "random" #include "bitset" #include "cstdio" #include "numeric" #include "cassert" using namespace std; //const long long int MOD = 1000000007; const int MOD = 1000000007; //const int MOD = 998244353; long long int N, M, K, H, W, L, R; //int N, M, K, H, W, L, R; class UnionFind { vector<int>parent; vector<int>rank; public: UnionFind(int num) { num++; parent.resize(num); rank.resize(num); for (int i = 0; i < num; i++) { parent[i] = i; rank[i] = 0; } } int Find(int node) { if (parent[node] == node)return node; else return parent[node] = Find(parent[node]); } void Unite(int u, int v) { u = Find(u); v = Find(v); if (u == v)return; if (rank[u] < rank[v])parent[u] = v; else { parent[v] = u; if (rank[u] == rank[v])rank[u]++; } } bool Check_Same(int u, int v) { return Find(u) == Find(v); } }; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> H >> W; vector<string>s(H); for (auto& i : s)cin >> i; if (H == 1) { auto t = s[0]; reverse(t.begin(), t.end()); if (s[0] == t) { cout << 1 << endl; } else cout << 2 << endl; return 0; } if (W == 1) { auto t = s; reverse(t.begin(), t.end()); if (s == t)cout << 1 << endl; else cout << 2 << endl; return 0; } long long int ans = 1; if (H <= 3 || W <= 3) { for (int i = 0; i < H / 2; i++) { for (int j = 0; j < W / 2; j++) { vector<char>v; v.push_back(s[i][j]); v.push_back(s[H - i - 1][W - j - 1]); v.push_back(s[H - i - 1][j]); v.push_back(s[i][W - j - 1]); set<vector<char>>sv; sort(v.begin(), v.end()); do { sv.insert(v); } while (next_permutation(v.begin(), v.end())); ans *= sv.size(); ans %= MOD; } } if (H & 1) { //assert(0); bool flag = false; for (int j = 0; j < W / 2; j++) { if (s[H / 2][j] != s[H / 2][W - j - 1])flag = true; } if (flag)ans <<= 1; ans %= MOD; } if (W & 1) { bool flag = false; for (int j = 0; j < H / 2; j++) { if (s[j][W / 2] != s[H - j - 1][W / 2])flag = true; } if (flag)ans <<= 1; ans %= MOD; } cout << ans << endl; } else { long long int ans = 1; if (H & 1) { //assert(0); bool flag = false; for (int j = 0; j < W / 2; j++) { if (s[H / 2][j] != s[H / 2][W - j - 1])flag = true; } if (flag)ans <<= 1; ans %= MOD; } if (W & 1) { bool flag = false; for (int j = 0; j < H / 2; j++) { if (s[j][W / 2] != s[H - j - 1][W / 2])flag = true; } if (flag)ans <<= 1; ans %= MOD; } vector<vector<int>>box(H / 2, vector<int>(W / 2)); for (int i = 0; i < H / 2; i++) { for (int j = 0; j < W / 2; j++) { vector<char>v; v.push_back(s[i][j]); v.push_back(s[H - i - 1][W - j - 1]); v.push_back(s[H - i - 1][j]); v.push_back(s[i][W - j - 1]); set<vector<char>>sv; sort(v.begin(), v.end()); do { sv.insert(v); } while (next_permutation(v.begin(), v.end())); ans *= min(12, (int)sv.size()); ans %= MOD; if (sv.size() > 12)box[i][j] = 1; } } UnionFind uf(H / 2 + W / 2); for (int i = 0; i < H / 2; i++) { for (int j = 0; j < W / 2; j++) { if (box[i][j])uf.Unite(i, j + H / 2); } } int sz = 0; for (int i = 0; i < H / 2 + W / 2; i++){ if (uf.Find(i) == i)sz++; } for (int i = 0; i < H / 2 + W / 2 - sz; i++) { ans <<= 1; ans %= MOD; } cout << ans << endl; } return 0; }
Submission Info
Submission Time | |
---|---|
Task | I - Reverse Grid |
User | olphe |
Language | C++14 (GCC 5.4.1) |
Score | 1900 |
Code Size | 3843 Byte |
Status | AC |
Exec Time | 26 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 | 4 ms | 384 KB |
01-11.txt | AC | 8 ms | 384 KB |
01-12.txt | AC | 8 ms | 384 KB |
01-13.txt | AC | 4 ms | 384 KB |
01-14.txt | AC | 6 ms | 256 KB |
01-15.txt | AC | 7 ms | 256 KB |
01-16.txt | AC | 25 ms | 384 KB |
01-17.txt | AC | 24 ms | 384 KB |
01-18.txt | AC | 25 ms | 384 KB |
01-19.txt | AC | 13 ms | 384 KB |
01-20.txt | AC | 13 ms | 384 KB |
01-21.txt | AC | 14 ms | 384 KB |
01-22.txt | AC | 2 ms | 256 KB |
01-23.txt | AC | 10 ms | 256 KB |
01-24.txt | AC | 18 ms | 384 KB |
01-25.txt | AC | 18 ms | 384 KB |
01-26.txt | AC | 18 ms | 384 KB |
01-27.txt | AC | 2 ms | 256 KB |
01-28.txt | AC | 4 ms | 256 KB |
01-29.txt | AC | 1 ms | 256 KB |
01-30.txt | AC | 6 ms | 256 KB |
01-31.txt | AC | 25 ms | 384 KB |
01-32.txt | AC | 26 ms | 384 KB |
01-33.txt | AC | 24 ms | 384 KB |
01-34.txt | AC | 25 ms | 384 KB |
01-35.txt | AC | 25 ms | 384 KB |
sample-01.txt | AC | 1 ms | 256 KB |
sample-02.txt | AC | 1 ms | 256 KB |