Submission #1871933


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 ;
using namespace std ;
int H, W ; ll k ;
char a[N][N] ;
void upd(int &x, int y) { x = (x + y) % mo ; }
void mul(int A[2][2], int B[2][2], int (&C)[2][2]) {
	rep(i, 0, 1) rep(j, 0, 1) C[i][j] = 0 ;
	rep(i, 0, 1) rep(j, 0, 1) rep(k, 0, 1) upd(C[i][j], (ll) A[i][k] * B[k][j] % mo) ;
}
int ksm(int a, ll b) {
	int ans = 1, w = a % mo ;
	for ( ; b ; b /= 2) {
		if (b & 1LL) ans = (ll) ans * w % mo ;
		w = (ll) w * w % mo ;
	}
	return ans ;
}
int main() {
	scanf("%d%d%lld", &H, &W, &k) ;
	if (k < 2LL) { puts("1") ; return 0 ; } k -= 2 ;
	int tx = 0, ty = 0, w[2][2] = {0}, ans[2][2] = {0}, tmp[2][2], x, y ;
	rep(i, 1, H) scanf("%s", a[i] + 1) ;
	rep(i, 1, H) if (a[i][1] == '#' && a[i][W] == '#') ++ tx ;
	rep(i, 1, W) if (a[1][i] == '#' && a[H][i] == '#') ++ ty ;
	rep(i, 1, H) rep(j, 1, W) if (a[i][j] == '#') ++ w[0][0] ;
	if (tx && ty) { puts("1") ; return 0 ; } 
	if (!tx && !ty) { printf("%d\n", ksm(w[0][0], k - 1)) ; return 0 ; }
	if (tx) {
		rep(i, 1, H) rep(j, 1, W - 1) if (a[i][j] == '#' && a[i][j + 1] == '#') ++ w[0][1] ;
		w[1][1] = tx ;
	} else {
		rep(i, 1, H - 1) rep(j, 1, W) if (a[i][j] == '#' && a[i + 1][j] == '#') ++ w[0][1] ;
		w[1][1] = ty ;
	}
	rep(i, 0, 1) rep(j, 0, 1) ans[i][j] = (i == j) ;
	x = w[0][0], y = w[0][1] ;
	for ( ; k ; k /= 2) {
		if (k & 1LL) {
			mul(ans, w, tmp) ;
			rep(i, 0, 1) rep(j, 0, 1) ans[i][j] = tmp[i][j] ;
		}
		mul(w, w, tmp) ;
		rep(i, 0, 1) rep(j, 0, 1) w[i][j] = tmp[i][j] ;
	}
	int X = (ll) x * ans[0][0] % mo + (ll) y * ans[1][0] % mo ; X %= mo ;
	int Y = (ll) x * ans[0][1] % mo + (ll) y * ans[1][1] % mo ; Y %= mo ;
	printf("%d\n", ((X - Y) % mo + 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 1899 Byte
Status WA
Exec Time 7 ms
Memory 2176 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:26: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:29: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
AC × 3
AC × 43
WA × 4
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 5 ms 2176 KB
02.txt AC 6 ms 2176 KB
03.txt AC 6 ms 2176 KB
04.txt AC 6 ms 2176 KB
05.txt AC 6 ms 2176 KB
06.txt WA 5 ms 2176 KB
07.txt WA 5 ms 2176 KB
08.txt AC 5 ms 2176 KB
09.txt AC 6 ms 2176 KB
10.txt AC 6 ms 2176 KB
11.txt AC 5 ms 2176 KB
12.txt AC 6 ms 2176 KB
13.txt AC 6 ms 2176 KB
14.txt AC 5 ms 2176 KB
15.txt AC 5 ms 2176 KB
16.txt WA 5 ms 2176 KB
17.txt AC 7 ms 2176 KB
18.txt AC 6 ms 2176 KB
19.txt AC 6 ms 2176 KB
20.txt AC 6 ms 2176 KB
21.txt AC 6 ms 2176 KB
22.txt WA 5 ms 2176 KB
23.txt AC 6 ms 2176 KB
24.txt AC 6 ms 2176 KB
25.txt AC 6 ms 2176 KB
26.txt AC 5 ms 2176 KB
27.txt AC 6 ms 2176 KB
28.txt AC 6 ms 2176 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