Submission #995045
Source Code Expand
#include <algorithm> #include <cstdio> #include <functional> #include <iostream> #include <cfloat> #include <climits> #include <cstdlib> #include <cstring> #include <cmath> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <time.h> #include <vector> #include <random> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> i_i; typedef pair<ll, int> ll_i; typedef pair<double, int> d_i; typedef pair<ll, ll> ll_ll; typedef pair<double, double> d_d; struct edge { int u, v; ll w; }; #define rep(i, N) for (int i = 0; i < N; i++) #define pb push_back ll MOD = 1000000007; ll _MOD = 1000000009; double EPS = 1e-10; struct union_find { vector<int> v; union_find(int n) : v(n, -1) {} int find(int x) { return v[x] < 0 ? x : v[x] = find(v[x]); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (-v[x] < -v[y]) swap(x, y); v[x] += v[y]; v[y] = x; } bool root(int x) { return v[x] < 0; } bool same(int x, int y) { return find(x) == find(y); } int size(int x) { return -v[find(x)]; } }; int main() { int H, W; cin >> H >> W; vector<string> a(H); rep(y, H) cin >> a[y]; ll ans = 1; for (int y = 0; y < H; y++) for (int x = 0; x < W; x++) { int _y = H - 1 - y, _x = W - 1 - x; if (y > _y || x > _x) continue; if (y < _y && x < _x) { map<char, int> mp; mp[a[y][x]]++; mp[a[y][_x]]++; mp[a[_y][x]]++; mp[a[_y][_x]]++; if (mp.size() == 2) { int ma = 0; for (auto z: mp) ma = max(ma, z.second); if (ma == 2) ans = ans * 6 % MOD; else ans = ans * 4 % MOD; } if (mp.size() == 3) ans = ans * 12 % MOD; if (mp.size() == 4) { ans = ans * 12 % MOD; a[y][x] = '*'; } } if (y == _y && x < _x) if (a[y][x] != a[y][_x]) a[y][x] = '*'; if (y < _y && x == _x) if (a[y][x] != a[_y][x]) a[y][x] = '*'; } union_find uf((H / 2) * (W / 2)); for (int y = 0; y < H; y++) { int _y = H - 1 - y; if (y < _y) { for (int x = 0; x < W / 2; x++) for (int _x = x + 1; _x < W / 2; _x++) if (a[y][x] == '*' && a[y][_x] == '*') uf.unite(y * (W / 2) + x, y * (W / 2) + _x); } } for (int x = 0; x < W; x++) { int _x = W - 1 - x; if (x < _x) { for (int y = 0; y < H / 2; y++) for (int _y = y + 1; _y < H / 2; _y++) if (a[y][x] == '*' && a[_y][x] == '*') uf.unite(y * (W / 2) + x, _y * (W / 2) + x); } } vector<set<int> > Y((H / 2) * (W / 2)), X((H / 2) * (W / 2)); for (int y = 0; y < H; y++) for (int x = 0; x < W; x++) { int _y = H - 1 - y, _x = W - 1 - x; if (y < _y && x < _x) { if (a[y][x] == '*') { int k = uf.find(y * (W / 2) + x); Y[k].insert(y); X[k].insert(x); } } } for (int k = 0; k < (H / 2) * (W / 2); k++) if (!Y[k].empty()) { int t = Y[k].size() + X[k].size(); t--; while (t--) ans = ans * 2 % MOD; } for (int y = 0; y < H; y++) { int _y = H - 1 - y; if (y == _y) { bool ok = false; for (int x = 0; x < W; x++) if (a[y][x] == '*') ok = true; if (ok) ans = ans * 2 % MOD; } } for (int x = 0; x < W; x++) { int _x = W - 1 - x; if (x == _x) { bool ok = false; for (int y = 0; y < H; y++) if (a[y][x] == '*') ok = true; if (ok) ans = ans * 2 % MOD; } } cout << ans << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | I - Reverse Grid |
User | sugim48 |
Language | C++14 (GCC 5.4.1) |
Score | 1900 |
Code Size | 3499 Byte |
Status | AC |
Exec Time | 14 ms |
Memory | 1408 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 |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01-01.txt | AC | 3 ms | 256 KB |
01-02.txt | AC | 3 ms | 256 KB |
01-03.txt | AC | 3 ms | 256 KB |
01-04.txt | AC | 3 ms | 256 KB |
01-05.txt | AC | 3 ms | 256 KB |
01-06.txt | AC | 3 ms | 256 KB |
01-07.txt | AC | 3 ms | 256 KB |
01-08.txt | AC | 3 ms | 256 KB |
01-09.txt | AC | 3 ms | 256 KB |
01-10.txt | AC | 7 ms | 1280 KB |
01-11.txt | AC | 8 ms | 1280 KB |
01-12.txt | AC | 8 ms | 1280 KB |
01-13.txt | AC | 7 ms | 1280 KB |
01-14.txt | AC | 4 ms | 512 KB |
01-15.txt | AC | 5 ms | 512 KB |
01-16.txt | AC | 13 ms | 1280 KB |
01-17.txt | AC | 13 ms | 1280 KB |
01-18.txt | AC | 13 ms | 1280 KB |
01-19.txt | AC | 9 ms | 1280 KB |
01-20.txt | AC | 9 ms | 1280 KB |
01-21.txt | AC | 9 ms | 1280 KB |
01-22.txt | AC | 3 ms | 256 KB |
01-23.txt | AC | 7 ms | 768 KB |
01-24.txt | AC | 11 ms | 1280 KB |
01-25.txt | AC | 11 ms | 1280 KB |
01-26.txt | AC | 11 ms | 1280 KB |
01-27.txt | AC | 3 ms | 256 KB |
01-28.txt | AC | 4 ms | 384 KB |
01-29.txt | AC | 3 ms | 256 KB |
01-30.txt | AC | 4 ms | 384 KB |
01-31.txt | AC | 13 ms | 1280 KB |
01-32.txt | AC | 13 ms | 1280 KB |
01-33.txt | AC | 13 ms | 1280 KB |
01-34.txt | AC | 14 ms | 1408 KB |
01-35.txt | AC | 14 ms | 1280 KB |
sample-01.txt | AC | 3 ms | 256 KB |
sample-02.txt | AC | 3 ms | 256 KB |