Submission #847560
Source Code Expand
#include <bits/stdc++.h> using namespace std; typedef long long LL; #define MOD 1000000007 LL powmod(LL a, LL n){ if(n == 0) return 1; if(n % 2) return (a*powmod(a,n-1)) % MOD; LL c = powmod(a,n/2); return (c*c) % MOD; } LL inv(LL a){ return powmod(a,MOD-2); } char stuff[1100][1100]; int main(){ LL h, w, k; scanf("%lld%lld%lld", &h, &w, &k); for(int i = 0; i < h; i++){ scanf("%s", stuff[i]); } if(k == 0){ cout << 1 << endl; return 0; } k--; int vq = 0; int hq = 0; for(int i = 0; i < h; i++){ if(stuff[i][0]=='#' && stuff[i][w-1]=='#'){ hq = 1; } } for(int i = 0; i < w; i++){ if(stuff[0][i]=='#' && stuff[h-1][i]=='#'){ vq = 1; } } if(vq && hq){ cout << 1 << endl; return 0; } LL c, a, e; c = a = e = 0; for(int i = 0; i < h; i++){ for(int j = 0; j < w; j++){ if(stuff[i][j]=='#'){ c++; } } } if(!vq && !hq){ cout << powmod(c,k) << endl; return 0; } if(vq){ for(int i = 0; i < 1050; i++){ for(int j = 0; j < i; j++){ swap(stuff[i][j],stuff[j][i]); } } swap(h,w); } for(int i = 0; i < h; i++){ for(int j = 0; j < w-1; j++){ if(stuff[i][j]=='#' && stuff[i][j+1]=='#'){ a++; } } if(stuff[i][0]=='#' && stuff[i][w-1]=='#'){ e++; } } LL ans1 = powmod(c,k); if(a == 0 || c == e){ cout << ans1 % MOD << endl; return 0; } LL ans2 = powmod(c,k)-powmod(e,k); ans2 %= MOD; ans2 *= inv(c-e); ans2 %= MOD; ans1 -= a*ans2; ans1 %= MOD; while(ans1 < 0) ans1 += MOD; cout << ans1 << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | F - Fraction of Fractal |
User | ksun48 |
Language | C++14 (GCC 5.4.1) |
Score | 1700 |
Code Size | 1610 Byte |
Status | AC |
Exec Time | 89 ms |
Memory | 1408 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:21:35: 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:23:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%s", stuff[i]); ^
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 | 12 ms | 1280 KB |
02.txt | AC | 13 ms | 1280 KB |
03.txt | AC | 15 ms | 1408 KB |
04.txt | AC | 13 ms | 1280 KB |
05.txt | AC | 15 ms | 1408 KB |
06.txt | AC | 11 ms | 1280 KB |
07.txt | AC | 11 ms | 1280 KB |
08.txt | AC | 10 ms | 1280 KB |
09.txt | AC | 13 ms | 1280 KB |
10.txt | AC | 18 ms | 1408 KB |
11.txt | AC | 11 ms | 1280 KB |
12.txt | AC | 14 ms | 1280 KB |
13.txt | AC | 13 ms | 1280 KB |
14.txt | AC | 11 ms | 1280 KB |
15.txt | AC | 11 ms | 1280 KB |
16.txt | AC | 11 ms | 1280 KB |
17.txt | AC | 13 ms | 1280 KB |
18.txt | AC | 13 ms | 1280 KB |
19.txt | AC | 13 ms | 1280 KB |
20.txt | AC | 15 ms | 1408 KB |
21.txt | AC | 15 ms | 1408 KB |
22.txt | AC | 12 ms | 1280 KB |
23.txt | AC | 15 ms | 1408 KB |
24.txt | AC | 14 ms | 1408 KB |
25.txt | AC | 15 ms | 1408 KB |
26.txt | AC | 13 ms | 1280 KB |
27.txt | AC | 14 ms | 1408 KB |
28.txt | AC | 13 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 | 89 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 |