Submission #1416779
Source Code Expand
#include <iostream> #include <string> #define MOD (1000 * 1000 * 1000 + 7) #define MAXN 1000 std::string m[MAXN]; char aux[MAXN][MAXN]; int a[2][2], r[2][2]; long long b[2][2]; inline void rot(int &nrlin, int &nrcol) { for (int i = 0; i < nrlin; i++) for (int j = 0; j < nrcol; j++) aux[j][i] = m[i][j]; int r = nrlin; nrlin = nrcol; nrcol = r; for (int i = 0; i < nrlin; i++) for (int j = 0; j < nrcol; j++) m[i][j] = aux[i][j]; } inline int sum(int nrlin, int nrcol) { int ans = 0; for (int i = 0; i < nrlin; i++) for (int j = 0; j < nrcol; j++) ans += (m[i][j] == '#'); return ans; } inline int per(int nrlin, int nrcol) { int ans = 0; for (int i = 0; i < nrlin; i++) for (int j = 1; j < nrcol; j++) ans += (m[i][j] == '#' && m[i][j - 1] == '#'); return ans; } inline int era(int nrlin, int nrcol) { int ans = 0; for (int i = 0; i < nrlin; i++) ans += (m[i][0] == '#' && m[i][nrcol - 1] == '#'); return ans; } inline int lgput(int a, long long n) { int r = 1; while (n) { if (n % 2) r = 1LL * r * a % MOD; n /= 2; a = 1LL * a * a % MOD; } return r; } inline void inmult(long long n) { r[0][0] = r[1][1] = 1; while (n) { if (n % 2) { for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) for (int k = 0; k < 2; k++) b[i][j] += 1LL * r[i][k] * a[k][j]; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { r[i][j] = b[i][j] % MOD; b[i][j] = 0; } } } for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) for (int k = 0; k < 2; k++) b[i][j] += 1LL * a[i][k] * a[k][j]; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { a[i][j] = b[i][j] % MOD; b[i][j] = 0; } } n /= 2; } } int main() { int nrlin, nrcol; long long k; std::cin >> nrlin >> nrcol >> k; for (int i = 0; i < nrlin; i++) std::cin >> m[i]; bool lin = 0; for (int i = 0; i < nrlin; i++) lin |= (m[i][0] == '#' && m[i][nrcol - 1] == '#'); bool col = 0; for (int j = 0; j < nrcol; j++) col |= (m[0][j] == '#' && m[nrlin - 1][j] == '#'); if (nrlin == 1 && (!lin)) col = 0; if (nrcol == 1 && (!col)) lin = 0; int ans = 1; if (k > 1) { if ((!lin) && (!col)) ans = lgput(sum(nrlin, nrcol), k - 1); else if ((!lin) || (!col)) { if (col) rot(nrlin, nrcol); a[0][0] = sum(nrlin, nrcol); a[1][0] = MOD - per(nrlin, nrcol); a[1][1] = era(nrlin, nrcol); inmult(k - 1); ans = r[0][0] + r[1][0]; if (ans >= MOD) ans -= MOD; } } std::cout << ans; }
Submission Info
Submission Time | |
---|---|
Task | F - Fraction of Fractal |
User | alexpetrescu |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 3232 Byte |
Status | WA |
Exec Time | 40 ms |
Memory | 2304 KB |
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 1700 | ||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | s1.txt, s2.txt, s3.txt |
All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, s1.txt, s2.txt, s3.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01.txt | AC | 33 ms | 1280 KB |
02.txt | AC | 36 ms | 1280 KB |
03.txt | AC | 39 ms | 2304 KB |
04.txt | AC | 36 ms | 1280 KB |
05.txt | WA | 39 ms | 2304 KB |
06.txt | AC | 34 ms | 1280 KB |
07.txt | AC | 34 ms | 1280 KB |
08.txt | AC | 33 ms | 1280 KB |
09.txt | AC | 36 ms | 1280 KB |
10.txt | AC | 39 ms | 2304 KB |
11.txt | AC | 33 ms | 1280 KB |
12.txt | AC | 35 ms | 1280 KB |
13.txt | AC | 36 ms | 1280 KB |
14.txt | AC | 34 ms | 1280 KB |
15.txt | AC | 35 ms | 1280 KB |
16.txt | AC | 34 ms | 1280 KB |
17.txt | AC | 36 ms | 1280 KB |
18.txt | AC | 36 ms | 1280 KB |
19.txt | AC | 36 ms | 1280 KB |
20.txt | WA | 39 ms | 2304 KB |
21.txt | AC | 40 ms | 2304 KB |
22.txt | AC | 34 ms | 1280 KB |
23.txt | AC | 39 ms | 2304 KB |
24.txt | AC | 39 ms | 2304 KB |
25.txt | AC | 39 ms | 2304 KB |
26.txt | AC | 35 ms | 1280 KB |
27.txt | AC | 39 ms | 2304 KB |
28.txt | AC | 35 ms | 1280 KB |
29.txt | AC | 1 ms | 256 KB |
30.txt | AC | 1 ms | 256 KB |
31.txt | AC | 1 ms | 256 KB |
32.txt | AC | 1 ms | 256 KB |
33.txt | AC | 1 ms | 256 KB |
34.txt | AC | 1 ms | 256 KB |
35.txt | AC | 1 ms | 256 KB |
36.txt | AC | 1 ms | 256 KB |
37.txt | AC | 1 ms | 256 KB |
38.txt | AC | 1 ms | 256 KB |
39.txt | AC | 1 ms | 256 KB |
40.txt | AC | 1 ms | 256 KB |
41.txt | AC | 1 ms | 256 KB |
42.txt | AC | 1 ms | 256 KB |
43.txt | AC | 1 ms | 256 KB |
44.txt | AC | 1 ms | 256 KB |
s1.txt | AC | 1 ms | 256 KB |
s2.txt | AC | 1 ms | 256 KB |
s3.txt | AC | 1 ms | 256 KB |