Submission #1148741


Source Code Expand

#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<utility>
#include<functional>
#include<iomanip>
#include<sstream>
#include<ctime>
#include<cassert>
using namespace std;
#define y0 y0z
#define y1 y1z
#define yn ynz
#define j0 j0z
#define j1 j1z
#define jn jnz
#define tm tmz
#define buli(x) (__builtin_popcountll(x))
#define bur0(x) (__builtin_ctzll(x))
#define bul2(x) (63-__builtin_clzll(x))
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define fil(a,b) memset((a),(b),sizeof(a))
#define cl(a) fil(a,0)
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)
#define rep(i,a,b) for (int i=(a),_ed=(b);i<_ed;i++)
#define per(i,a,b) for (int i=(b)-1,_ed=(a);i>=_ed;i--)
#define forg(i,gu) for (int i=gu;~i;i=e[i].next)
#define pw(x) ((ll(1))<<(x))
#define upmo(a,b) (((a)=((a)+(b))%mo)<0?(a)+=mo:(a))
#define mmo(a,b) (((a)=1ll*(a)*(b)%mo)<0?(a)+=mo:(a))
void getre(){int x=0;printf("%d\n",1/x);}
void gettle(){int res=1;while(1)res<<=1;printf("%d\n",res);}
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
template<typename T,typename S>inline bool upmin(T&a,const S&b){return a>b?a=b,1:0;}
template<typename T,typename S>inline bool upmax(T&a,const S&b){return a<b?a=b,1:0;}
template<typename N,typename PN>inline N flo(N a,PN b){return a>=0?a/b:-((-a-1)/b)-1;}
template<typename N,typename PN>inline N cei(N a,PN b){return a>0?(a-1)/b+1:-(-a/b);}
template<typename N>N gcd(N a,N b){return b?gcd(b,a%b):a;}
template<typename N>inline int sgn(N a){return a>0?1:(a<0?-1:0);}
#if ( ( _WIN32 || __WIN32__ ) && __cplusplus < 201103L)
#define lld "%I64d"
#else
#define lld "%lld"
#endif
inline void gn(long long&x){
	int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
	while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;
}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
inline void gn(double&x){double t;scanf("%lf",&t);x=t;}
inline void gn(long double&x){double t;scanf("%lf",&t);x=t;}
inline void gs(char *s){scanf("%s",s);}
inline void gc(char &c){while((c=getchar())>126 || c<33);}
inline void pc(char c){putchar(c);}
#ifdef JCVB
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif
typedef long long ll;
typedef double db;
inline ll sqr(ll a){return a*a;}
inline db sqrf(db a){return a*a;}
const int inf=0x3f3f3f3f;
//const ll inf=0x3f3f3f3f3f3f3f3fll;
const db pi=3.14159265358979323846264338327950288L;
const db eps=1e-6;
const int mo=1e9+7;
int qp(int a,ll b){int n=1;do{if(b&1)n=1ll*n*a%mo;a=1ll*a*a%mo;}while(b>>=1);return n;}


// mo < 2^30 = 1073741824
// first call mm_init(sz);
// indices from 0 to mm_n - 1
// call a.plus(),b.plus() before a*b

const int MM_N =3;

int mm_n;
struct mat{
	int a[MM_N][MM_N];
	void plus(){
		rep(i,0,mm_n)rep(j,0,mm_n)a[i][j]=(a[i][j]%mo+mo)%mo;
	}
}one,ba;
mat operator*(const mat&a,const mat&b){
	static ll ans[MM_N][MM_N];
	cl(ans);
	ll infa=8e18;
	rep(k,0,mm_n)rep(i,0,mm_n)rep(j,0,mm_n){
		if((ans[i][j]+=1ll*a.a[i][k]*b.a[k][j])>=infa)ans[i][j]%=mo;
	}
	mat c;
	rep(i,0,mm_n)rep(j,0,mm_n)c.a[i][j]=ans[i][j]%mo;
	return c;
}
mat qp(mat a,ll b){a.plus();mat n=one;do{if(b&1)n=n*a;a=a*a;}while(b>>=1);return n;}
void mm_init(int sz){
	mm_n=sz;
	rep(i,0,mm_n)one.a[i][i]=1;
}

char s[1111][1111];
char t[1111][1111];
int n,m;
ll k;
int main()
{
#ifdef JCVB
	//freopen("1.in","r",stdin);
	//freopen("1.out","w",stdout);
	int _time_jc=clock();
#endif
	mm_init(3);
	gn(n);gn(m);gn(k);
	rep(i,1,n+1)gs(s[i]+1);
	int heng=0,shu=0;
	rep(i,1,n+1)if(s[i][1]=='#' && s[i][m]=='#')heng=1;
	rep(j,1,m+1)if(s[1][j]=='#' && s[n][j]=='#')shu=1;
	int basebian=0,baseheng=0,basege=0;
	rep(i,1,n+1)rep(j,1,m+1)if(s[i][j]=='#')basege++;
	if(shu && heng){
		printf("1\n");
		return 0;
	}else if(!shu && !heng){
		printf("%d\n",qp(basege,k-1));
		return 0;
	}
	if(shu){
		rep(i,1,n+1)rep(j,1,m+1)t[j][i]=s[i][j];
		rep(i,1,m+1)rep(j,1,n+1)s[i][j]=t[i][j];
		swap(n,m);
	}
	rep(i,1,n+1)if(s[i][1]=='#' && s[i][m]=='#')basebian++;
	rep(i,1,n+1)rep(j,1,m)if(s[i][j]=='#' && s[i][j+1]=='#')baseheng++;

	ba.a[0][1]=-1;
	ba.a[0][2]=1;
	ba.a[1][1]=basebian;
	ba.a[1][2]=baseheng;
	ba.a[2][2]=basege;

	ba=qp(ba,k);
	int ret=(ba.a[0][0]+ba.a[0][2])%mo;
	printf("%d\n",ret);

#ifdef JCVB
	debug("time: %d\n",int(clock()-_time_jc));
#endif
	return 0;
}


Submission Info

Submission Time
Task F - Fraction of Fractal
User jcvb
Language C++14 (GCC 5.4.1)
Score 1700
Code Size 4769 Byte
Status AC
Exec Time 9 ms
Memory 2432 KB

Compile Error

./Main.cpp: In function ‘void gs(char*)’:
./Main.cpp:68:38: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
 inline void gs(char *s){scanf("%s",s);}
                                      ^

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 5 ms 1280 KB
02.txt AC 6 ms 1280 KB
03.txt AC 9 ms 2432 KB
04.txt AC 6 ms 1280 KB
05.txt AC 9 ms 2432 KB
06.txt AC 5 ms 1280 KB
07.txt AC 5 ms 1280 KB
08.txt AC 5 ms 1280 KB
09.txt AC 6 ms 1280 KB
10.txt AC 9 ms 2432 KB
11.txt AC 5 ms 1280 KB
12.txt AC 5 ms 1280 KB
13.txt AC 6 ms 1280 KB
14.txt AC 5 ms 1280 KB
15.txt AC 5 ms 1280 KB
16.txt AC 5 ms 1280 KB
17.txt AC 6 ms 1280 KB
18.txt AC 6 ms 1280 KB
19.txt AC 6 ms 1280 KB
20.txt AC 9 ms 2432 KB
21.txt AC 9 ms 2432 KB
22.txt AC 5 ms 1280 KB
23.txt AC 9 ms 2432 KB
24.txt AC 9 ms 2432 KB
25.txt AC 9 ms 2432 KB
26.txt AC 5 ms 1280 KB
27.txt AC 8 ms 2432 KB
28.txt AC 5 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