Submission #1871857
Source Code Expand
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a; i <= b; ++ i)
const int N = 2005, mo = 1e9 + 7, flg[4][2] = {{1, 0}, {0, 1}, {- 1, 0}, {0, - 1}} ;
using namespace std ;
int H, W ;
char a[N][N] ; bool vis[N][N] ;
struct poi { int x, y ; } opt[N * N] ;
void upd(int &x, int y) { x = (x + y) % mo ; }
void mul(int A[4][4], int B[4][4], int (&C)[4][4]) {
rep(i, 0, 3) rep(j, 0, 3) C[i][j] = 0 ;
rep(i, 0, 3) rep(j, 0, 3) rep(k, 0, 3) upd(C[i][j], (ll) A[i][k] * B[k][j] % mo) ;
}
void bfs(int x, int y, int n, int m) {
int he = 0, ta = 1 ;
opt[1].x = x, opt[1].y = y, vis[x][y] = false ;
for ( ; he != ta ; ) {
++ he ; int x = opt[he].x, y = opt[he].y ;
rep(i, 0, 3) {
int xx = x + flg[i][0], yy = y + flg[i][1] ;
if (xx < 1 || xx > n || yy < 1 || yy > m || !vis[xx][yy] || a[xx][yy] != '#') continue ;
vis[xx][yy] = false, ++ ta, opt[ta].x = xx, opt[ta].y = yy ;
}
}
}
int count(int n, int m) {
int res = 0 ;
rep(i, 1, n) rep(j, 1, m) vis[i][j] = true ;
rep(i, 1, n) rep(j, 1, m) if (vis[i][j] && a[i][j] == '#') ++ res, bfs(i, j, n, m) ;
return res ;
}
void calc(int &sum, int &x, int &y, int &z) {
sum = 0, x = 0, y = 0, z = 0 ;
rep(i, 1, H) rep(j, 1, W) if (a[i][j] == '#') {
if (a[i - 1][j] == '#') {
if (a[i][j - 1] == '#') ++ z ; else ++ y ;
} else {
if (a[i][j - 1] == '#') ++ x ; else ++ sum ;
}
}
}
int main() {
int ans[4][4], w[4][4], tmp[4][4] ; ll k ;
scanf("%d%d%lld", &H, &W, &k) ;
rep(i, 1, 2 * H) rep(j, 1, 2 * W) a[i][j] = '.' ;
if (!k) { puts("1") ; return 0 ; } -- k ;
rep(i, 1, H) scanf("%s", a[i] + 1) ;
rep(i, 0, 3) rep(j, 0, 3) w[i][j] = ans[i][j] = 0 ;
rep(i, 0, 3) ans[i][i] = 1 ;
int sum, x, y, z ;
calc(sum, x, y, z), w[0][0] = sum, w[1][0] = x, w[2][0] = y, w[3][0] = z ;
rep(i, 1, H) a[i][0] = a[i][W] ;
calc(sum, x, y, z), w[0][1] = sum, w[1][1] = x, w[2][1] = y, w[3][1] = z ;
rep(i, 1, H) a[i][0] = '.' ;
rep(i, 1, W) a[0][i] = a[H][i] ;
calc(sum, x, y, z), w[0][2] = sum, w[1][2] = x, w[2][2] = y, w[3][2] = z ;
rep(i, 1, H) a[i][0] = a[i][W] ;
calc(sum, x, y, z), w[0][3] = sum, w[1][3] = x, w[2][3] = y, w[3][3] = z ;
for ( ; k ; k /= 2LL) {
if (k & 1LL) {
mul(ans, w, tmp) ;
rep(i, 0, 3) rep(j, 0, 3) ans[i][j] = tmp[i][j] ;
}
mul(w, w, tmp) ;
rep(i, 0, 3) rep(j, 0, 3) w[i][j] = tmp[i][j] ;
}
int res = 0, u = count(H * 2, W * 2), las = u ;
upd(res, (ll) u * ans[0][0] % mo) ;
rep(i, 1, H) rep(j, 1, W) a[i][j + W] = a[i][j] ;
u = count(H * 2, W * 2) ;
upd(res, (ll) (u - las) * ans[1][0] % mo) ;
rep(i, 1, H) rep(j, 1, W) a[i][j + W] = '.', a[i + H][j] = a[i][j] ;
u = count(H * 2, W * 2) ;
upd(res, (ll) (u - las) * ans[2][0] % mo) ;
rep(i, 1, H) rep(j, 1, W) a[i][j + W] = a[i][j] ;
las = count(H * 2, W * 2) ;
rep(i, 1, H) rep(j, 1, W) a[i + H][j + W] = a[i][j] ;
u = count(H * 2, W * 2) ;
upd(res, (ll) (u - las) * ans[3][0] % mo) ;
printf("%d\n", (res + mo) % mo) ;
return 0 ;
}
Submission Info
Submission Time |
|
Task |
F - Fraction of Fractal |
User |
mjy0724 |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
3100 Byte |
Status |
WA |
Exec Time |
206 ms |
Memory |
39552 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:48:32: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%lld", &H, &W, &k) ;
^
./Main.cpp:51:37: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
rep(i, 1, H) scanf("%s", a[i] + 1) ;
^
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 |
206 ms |
39552 KB |
02.txt |
AC |
183 ms |
25216 KB |
03.txt |
AC |
189 ms |
25216 KB |
04.txt |
AC |
188 ms |
25216 KB |
05.txt |
AC |
188 ms |
25088 KB |
06.txt |
AC |
178 ms |
17024 KB |
07.txt |
AC |
181 ms |
17024 KB |
08.txt |
WA |
41 ms |
8832 KB |
09.txt |
AC |
185 ms |
25216 KB |
10.txt |
AC |
185 ms |
25216 KB |
11.txt |
WA |
41 ms |
8832 KB |
12.txt |
AC |
41 ms |
8832 KB |
13.txt |
AC |
124 ms |
17024 KB |
14.txt |
AC |
40 ms |
8832 KB |
15.txt |
AC |
41 ms |
8832 KB |
16.txt |
AC |
40 ms |
8832 KB |
17.txt |
AC |
176 ms |
21120 KB |
18.txt |
AC |
188 ms |
25216 KB |
19.txt |
AC |
192 ms |
25216 KB |
20.txt |
AC |
186 ms |
25216 KB |
21.txt |
AC |
184 ms |
25216 KB |
22.txt |
AC |
41 ms |
8832 KB |
23.txt |
AC |
41 ms |
8832 KB |
24.txt |
AC |
41 ms |
8832 KB |
25.txt |
AC |
41 ms |
8832 KB |
26.txt |
AC |
41 ms |
8832 KB |
27.txt |
AC |
41 ms |
8832 KB |
28.txt |
AC |
40 ms |
8832 KB |
29.txt |
AC |
2 ms |
4352 KB |
30.txt |
AC |
2 ms |
4352 KB |
31.txt |
AC |
2 ms |
4352 KB |
32.txt |
AC |
2 ms |
4352 KB |
33.txt |
AC |
2 ms |
4352 KB |
34.txt |
AC |
2 ms |
4352 KB |
35.txt |
WA |
2 ms |
4352 KB |
36.txt |
AC |
2 ms |
4352 KB |
37.txt |
AC |
2 ms |
4352 KB |
38.txt |
WA |
2 ms |
4352 KB |
39.txt |
AC |
2 ms |
4352 KB |
40.txt |
WA |
2 ms |
4352 KB |
41.txt |
AC |
2 ms |
4352 KB |
42.txt |
AC |
2 ms |
4352 KB |
43.txt |
AC |
2 ms |
4352 KB |
44.txt |
AC |
2 ms |
4352 KB |
s1.txt |
AC |
2 ms |
4352 KB |
s2.txt |
AC |
2 ms |
4352 KB |
s3.txt |
AC |
2 ms |
4352 KB |