Submission #993528
Source Code Expand
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <string> #include <cstring> #include <vector> using namespace std; typedef long long ll; const ll MOD = (ll)1e9 + 7; ll mult(ll x, ll y) { return (x * y) % MOD; } const int N = 500; int n, m; char s[N][N]; vector<int> g[N]; bool used[N]; ll f[5]; ll getCount(string p) { sort(p.begin(), p.end()); ll res = f[(int)p.size()]; int l = 0; while(l < (int)p.size()) { int r = l; while(r < (int)p.size() && p[l] == p[r]) r++; res /= f[r - l]; l = r; } return res; } void dfs(int v) { used[v] = 1; for (int u : g[v]) if (!used[u]) dfs(u); return; } int main() { // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); f[0] = 1; for (int i = 1; i < 5; i++) f[i] = f[i - 1] * i; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) scanf(" %s ", s[i]); ll ans = 1; for (int x = 0; x < n / 2; x++) for (int y = 0; y < m / 2; y++) { string p = ""; p += s[x][y]; p += s[n - 1 - x][y]; p += s[x][m - 1 - y]; p += s[n - 1 - x][m - 1 - y]; ll z = getCount(p); if (z == 24) { z = 12; g[x].push_back(n + y); g[n + y].push_back(x); } ans = mult(ans, z); } if (n & 1) { bool ok = false; for (int y = 0; !ok && y < m / 2; y++) if (s[n / 2][y] != s[n / 2][m - 1 - y]) { ok = true; ans = mult(ans, 2); } } if (m & 1) { bool ok = false; for (int x = 0; !ok && x < n / 2; x++) if (s[x][m / 2] != s[n - 1 - x][m / 2]) { ok = true; ans = mult(ans, 2); } } int res = n + m; for (int i = 0; i < n + m; i++) if (!used[i]) { res--; dfs(i); } for (int i = 0; i < res; i++) ans = mult(ans, 2); printf("%lld\n", ans); return 0; }
Submission Info
Submission Time | |
---|---|
Task | I - Reverse Grid |
User | Um_nik |
Language | C++14 (GCC 5.4.1) |
Score | 1900 |
Code Size | 1866 Byte |
Status | AC |
Exec Time | 6 ms |
Memory | 512 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:57:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d%d", &n, &m); ^ ./Main.cpp:59:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf(" %s ", s[i]); ^
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 | 384 KB |
01-09.txt | AC | 3 ms | 384 KB |
01-10.txt | AC | 5 ms | 384 KB |
01-11.txt | AC | 5 ms | 384 KB |
01-12.txt | AC | 5 ms | 384 KB |
01-13.txt | AC | 5 ms | 384 KB |
01-14.txt | AC | 3 ms | 256 KB |
01-15.txt | AC | 4 ms | 384 KB |
01-16.txt | AC | 6 ms | 512 KB |
01-17.txt | AC | 6 ms | 512 KB |
01-18.txt | AC | 6 ms | 512 KB |
01-19.txt | AC | 6 ms | 384 KB |
01-20.txt | AC | 6 ms | 384 KB |
01-21.txt | AC | 6 ms | 384 KB |
01-22.txt | AC | 3 ms | 256 KB |
01-23.txt | AC | 4 ms | 384 KB |
01-24.txt | AC | 6 ms | 384 KB |
01-25.txt | AC | 6 ms | 384 KB |
01-26.txt | AC | 6 ms | 384 KB |
01-27.txt | AC | 3 ms | 256 KB |
01-28.txt | AC | 3 ms | 256 KB |
01-29.txt | AC | 3 ms | 384 KB |
01-30.txt | AC | 3 ms | 384 KB |
01-31.txt | AC | 6 ms | 512 KB |
01-32.txt | AC | 6 ms | 512 KB |
01-33.txt | AC | 6 ms | 512 KB |
01-34.txt | AC | 6 ms | 512 KB |
01-35.txt | AC | 6 ms | 512 KB |
sample-01.txt | AC | 3 ms | 256 KB |
sample-02.txt | AC | 3 ms | 256 KB |