Submission #1386918


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll maxx = 1e3 + 20, mod = 1e9 + 7;

char t[maxx][maxx];
ll n, m, k, ted = 0, c1 = 0, e, c2 = 0, mat[2][2], tmp[2][2];
bool b1 = false, b2 = false;
vector<ll> v;

ll pw(ll a, ll b)
{
	if (!b) return 1ll;
	ll x = pw(a, b / 2);
	x = (x * x) % mod;
	if (b % 2) x = (x * a) % mod;
	return x;
}

void zrb(ll t1[][2], ll t2[][2])
{
	ll t3[2][2] = {{0, 0}, {0, 0}};
	for(ll i = 0; i < 2; i++)
		for(ll j = 0; j < 2; j++)
			for(ll o = 0; o < 2; o++)
				t3[i][j] = (((t3[i][j] + ((t1[i][o] * t2[o][j]) % mod)) % mod) + mod) % mod;
	for(ll i = 0; i < 2; i++)
		for(ll j = 0; j < 2; j++)
			mat[i][j] = t3[i][j];
}

void pw(ll x)
{
	if (x == 1) return;
	while (x >= 1) 
	{
		v.push_back(x);
		x /= 2;
	}
	reverse(v.begin(), v.end());
	x = 1;
	for(ll i = 1; i < v.size(); i++)
	{
		x *= 2ll;
		zrb(mat, mat);
		if (x != v[i]) x++, zrb(mat, tmp);
	}
	return;
}

int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> m >> k;
	for(ll i = 0; i < n; i++) for(ll j = 0; j < m; j++) cin >> t[i][j], ted += (t[i][j] == '#');
	if (!k) return cout << 1 << endl, 0;
	for(ll i = 0; i < n; i++) if (t[i][0] == '#' && t[i][m-1] == '#') b1 = true, c1++;
	for(ll i = 0; i < m; i++) if (t[0][i] == '#' && t[n-1][i] == '#') b2 = true, c2++;
	if (b1 && b2) return cout << 1 << endl, 0; 
	if (!b1 && !b2) return cout << pw(ted, k - 1) << endl, 0;
	if (b1)
	{
		while (true) cout << 0 / 0 << endl;
		for(ll i = 0; i < n; i++) for(ll j = 0; j < m - 1; j++) if (t[i][j] == '#' && t[i][j + 1] == '#') e++;
		mat[0][0] = ted; mat[0][1] = -e; mat[1][0] = 0; mat[1][1] = c1;
		tmp[0][0] = ted; tmp[0][1] = -e; tmp[1][0] = 0; tmp[1][1] = c1;
		pw(k - 1);
		return cout << (((mat[0][0] + mat[0][1]) % mod) + mod) % mod << endl, 0;
	}
	else
	{
		for(ll i = 0; i < n - 1; i++) for(ll j = 0; j < m; j++) if (t[i][j] == '#' && t[i + 1][j] == '#') e++;
		mat[0][0] = ted; mat[0][1] = -e; mat[1][0] = 0; mat[1][1] = c2;
		tmp[0][0] = ted; tmp[0][1] = -e; tmp[1][0] = 0; tmp[1][1] = c2;
		pw(k - 1);
		return cout << (((mat[0][0] + mat[0][1]) % mod) + mod) % mod << endl, 0;
	}
	return 0;
}

Submission Info

Submission Time
Task F - Fraction of Fractal
User Behnood
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2228 Byte
Status TLE
Exec Time 2107 ms
Memory 4096 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:66:26: warning: division by zero [-Wdiv-by-zero]
   while (true) cout << 0 / 0 << endl;
                          ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 1700
Status
AC × 1
TLE × 2
AC × 27
TLE × 20
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 12 ms 1280 KB
02.txt TLE 2103 ms 4096 KB
03.txt AC 13 ms 1280 KB
04.txt TLE 2103 ms 3968 KB
05.txt AC 13 ms 1280 KB
06.txt AC 12 ms 1280 KB
07.txt AC 12 ms 1280 KB
08.txt AC 12 ms 1280 KB
09.txt TLE 2103 ms 4096 KB
10.txt AC 14 ms 1280 KB
11.txt AC 12 ms 1280 KB
12.txt TLE 2103 ms 4096 KB
13.txt TLE 2103 ms 4096 KB
14.txt AC 12 ms 1280 KB
15.txt AC 12 ms 1280 KB
16.txt AC 12 ms 1280 KB
17.txt TLE 2103 ms 4096 KB
18.txt TLE 2103 ms 3968 KB
19.txt TLE 2103 ms 4096 KB
20.txt AC 13 ms 1280 KB
21.txt AC 13 ms 1280 KB
22.txt AC 12 ms 1280 KB
23.txt AC 14 ms 1280 KB
24.txt AC 12 ms 1280 KB
25.txt AC 12 ms 1280 KB
26.txt TLE 2103 ms 4096 KB
27.txt AC 13 ms 1280 KB
28.txt TLE 2103 ms 4096 KB
29.txt TLE 2103 ms 3072 KB
30.txt AC 1 ms 256 KB
31.txt AC 1 ms 256 KB
32.txt TLE 2103 ms 3072 KB
33.txt AC 1 ms 256 KB
34.txt TLE 2103 ms 3072 KB
35.txt AC 1 ms 256 KB
36.txt TLE 2103 ms 3072 KB
37.txt TLE 2103 ms 3072 KB
38.txt AC 1 ms 256 KB
39.txt TLE 2103 ms 3072 KB
40.txt AC 1 ms 256 KB
41.txt TLE 2103 ms 3072 KB
42.txt TLE 2103 ms 3072 KB
43.txt AC 1 ms 256 KB
44.txt AC 1 ms 256 KB
s1.txt TLE 2107 ms 3072 KB
s2.txt AC 1 ms 256 KB
s3.txt TLE 2103 ms 3072 KB