Submission #848283


Source Code Expand

Copy
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

ll M = 1000000007;

ll modpow(ll x,ll k){
	if(k == 0)return 1;
	ll ret = modpow(x,k/(ll)2);
	ret *= ret;
	ret %= M;
	if(k%2 == 1){
		ret *= x;
		ret %= M;
	}
	return ret;
}

int main(){
	ll h,w,k;
	char s[1002][1002];
	scanf("%lld%lld%lld",&h,&w,&k);
	rep(i,h){
		scanf("\n");
		rep(j,w)scanf("%c",&s[i][j]);
	}
	
	
	ll a = 0;
	rep(i,h)rep(j,w)if(s[i][j] == '#')a ++;
	
	if(k == 0){
		cout << 1 << endl;
		return 0;
	}
	
	if(h == 1){
		if(s[0][0] == '#' && s[0][w-1] == '#'){
			cout << 1 << endl;
			return 0;
		}
		else cout << modpow(a,k-1) << endl;
		return 0;
	}
	if(w == 1){
		if(s[0][0] == '#' && s[h-1][0] == '#'){
			cout << 1 << endl;
			return 0;
		}
		else cout << modpow(a,k-1) << endl;
		return 0;
	}
	
	ll cnt[2] = {};
	rep(j,w){
		if(s[0][j] == '#' && s[h-1][j] == '#')cnt[0] ++;
	}
	rep(i,h){
		if(s[i][0] == '#' && s[i][w-1] == '#')cnt[1] ++;
	}
	
	if(cnt[0] > 0 && cnt[1] > 0){
		puts("1");
		return 0;
	}
	ll b = max(cnt[0],cnt[1]);
	
	if(b ==0){
		cout << modpow(a,k-1) << endl;
	}
	else {
		ll c = 0;
		if(cnt[0] > 0){
			rep(i,h-1)rep(j,w){
				if(s[i][j] == '#' && s[i+1][j] == '#')c ++;
			}
		}
		else {
			rep(i,h)rep(j,w-1){
				if(s[i][j] == '#' && s[i][j+1] == '#')c ++;
			}
		}
		k --;
		ll ret = modpow(a,k) - modpow(b,k) + M;
		ret %= M;
		ret *= modpow(a-b,M-2);
		ret %= M;
		ret *= c;
		ret %= M;
		ret = M-ret;
		ret += modpow(a,k);
		ret %= M;
		cout << ret << endl;
	}
}

Submission Info

Submission Time
Task F - Fraction of Fractal
User yokozuna57
Language C++14 (GCC 5.4.1)
Score 1700
Code Size 2509 Byte
Status AC
Exec Time 73 ms
Memory 1280 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:54:32: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld%lld",&h,&w,&k);
                                ^
./Main.cpp:56:14: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("\n");
              ^
./Main.cpp:57:31: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   rep(j,w)scanf("%c",&s[i][j]);
                               ^

Judge Result

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