Submission #1679772
Source Code Expand
#include <stdio.h> #include <iostream> #include <algorithm> #include <memory.h> #include <vector> using namespace std; typedef long long LL; const int maxn = 2005; const int mod = 1e9+7; char g[maxn][maxn];int h,w; int cur[2],tr[2][2],bla,hor,sam1,sam2;LL K; LL fpm(LL p,LL k) { LL res=1ll; while (k) { if (k&1) (res*=p)%=mod; (p*=p)%=mod;k>>=1; } return res; } void mulcur() { int a=cur[0],b=cur[1]; cur[0]=((LL)a*tr[0][0]+(LL)b*tr[1][0])%mod; cur[1]=((LL)a*tr[0][1]+(LL)b*tr[1][1])%mod; } void multr() { int a00=tr[0][0],a01=tr[0][1]; int a10=tr[1][0],a11=tr[1][1]; tr[0][0]=((LL)a00*a00+(LL)a01*a10)%mod; tr[0][1]=((LL)a00*a01+(LL)a01*a11)%mod; tr[1][0]=((LL)a10*a00+(LL)a11*a10)%mod; tr[1][1]=((LL)a10*a01+(LL)a11*a11)%mod; } int main() { #ifdef Amberframe freopen("agc003f.in","r",stdin); freopen("agc003f.out","w",stdout); #endif scanf("%d %d %lld",&h,&w,&K); for (int i=1;i<=h;i++) scanf("%s",g[i]+1); for (int i=1;i<=h;i++) for (int j=1;j<=w;j++) bla+=(g[i][j]=='#'); for (int i=1;i<=h;i++) sam1+=(g[i][1]=='#'&&g[i][w]=='#'); for (int i=1;i<=w;i++) sam2+=(g[1][i]=='#'&&g[h][i]=='#'); if (!sam1&&!sam2) printf("%lld",fpm(bla,K-1)); else if (sam1&&sam2) printf("1"); else { if (sam1) { for (int i=1;i<=h;i++) for (int j=1;j<=w;j++) hor+=(g[i][j]=='#'&&g[i][j+1]=='#'); } else { for (int i=1;i<=h;i++) for (int j=1;j<=w;j++) hor+=(g[i][j]=='#'&&g[i+1][j]=='#'); } cur[0]=1;cur[1]=0; tr[0][0]=bla;tr[0][1]=hor;tr[1][1]=(sam1+sam2)%mod; for (K--;K;K>>=1,multr()) if (K&1) mulcur(); int ans=(cur[0]-cur[1])%mod; printf("%d",ans<0?ans+mod:ans); } return 0; }
Submission Info
Submission Time | |
---|---|
Task | F - Fraction of Fractal |
User | Amberframe |
Language | C++14 (GCC 5.4.1) |
Score | 1700 |
Code Size | 1701 Byte |
Status | AC |
Exec Time | 7 ms |
Memory | 2176 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:41:30: 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:42:43: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] for (int i=1;i<=h;i++) scanf("%s",g[i]+1); ^
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1700 / 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 | 6 ms | 2176 KB |
02.txt | AC | 7 ms | 2176 KB |
03.txt | AC | 7 ms | 2176 KB |
04.txt | AC | 7 ms | 2176 KB |
05.txt | AC | 7 ms | 2176 KB |
06.txt | AC | 6 ms | 2176 KB |
07.txt | AC | 6 ms | 2176 KB |
08.txt | AC | 6 ms | 2176 KB |
09.txt | AC | 7 ms | 2176 KB |
10.txt | AC | 7 ms | 2176 KB |
11.txt | AC | 6 ms | 2176 KB |
12.txt | AC | 6 ms | 2176 KB |
13.txt | AC | 7 ms | 2176 KB |
14.txt | AC | 6 ms | 2176 KB |
15.txt | AC | 6 ms | 2176 KB |
16.txt | AC | 6 ms | 2176 KB |
17.txt | AC | 7 ms | 2176 KB |
18.txt | AC | 7 ms | 2176 KB |
19.txt | AC | 7 ms | 2176 KB |
20.txt | AC | 7 ms | 2176 KB |
21.txt | AC | 7 ms | 2176 KB |
22.txt | AC | 6 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 | 6 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 |