Submission #1153170


Source Code Expand

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1.0);

const int mod = (int) 1e9 + 7;

void add(int &x, int y) {
  if ((x += y) >= mod) {
    x -= mod;
  }
}

int mult(int x, int y) {
  return (long long) x * y % mod;
}

int power(int x, long long pw) {
  int res = 1;
  for (; pw; pw >>= 1) {
    if (pw & 1) {
      res = mult(res, x);
    }
    x = mult(x, x);
  }
  return res;
}

void precalc() {
}


const int maxn = (int) 1e3 + 10;
char q[maxn][maxn];

int n, m;
long long k;

int read() {
  if (scanf("%d%d%lld", &n, &m, &k) < 3) {
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    scanf("%s", q[i]);
  }
  return 1;
}

void myrot() {
  int k = max(n, m);
  for (int i = 0; i <= k; ++i) {
    for (int j = 0; j < i; ++j) {
      swap(q[i][j], q[j][i]);
    }
  }
  swap(n, m);
}

void solve() {
  int h = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      h += (q[i][j] == '#');
    }
  }
  int ss[2];
  for (int it = 0; it < 2; ++it) {
    int &s = ss[it];
    s = 0;
    for (int i = 0; i < n; ++i) {
      if (q[i][0] == '#' && q[i][m - 1] == '#') {
        ++s;
      }
    }
    myrot();
  }

  if (k <= 1) {
    printf("1\n");
    return;
  }
  --k;

  if (!ss[0] && !ss[1]) {
    printf("%d\n", power(h, k));
    return;
  }
  if (ss[0] && ss[1]) {
    printf("1\n");
    return;
  }
  int s = ss[0];
  if (ss[1]) {
    myrot();
    s = ss[1];
  }

  int b = -s;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (q[i][j] == '#') {
        while (q[i][j] == '#') {
          ++j;
        }
        ++b;
      }
    }
  }
  int c = mult(b, power(s - h + mod, mod - 2));
  if (c < 0) {
    c += mod;
  }
  //eprintf("h = %d, s = %d, b = %d, c = %d\n", h, s, b, c);

  int val = mult(c + 1, power(s, k));
  add(val, mod - mult(c, power(h, k)));
  printf("%d\n", val);
}

int main() {
  precalc();
#ifdef LOCAL
  freopen(TASK ".out", "w", stdout);
  assert(freopen(TASK ".in", "r", stdin));
#endif

  while (1) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}

Submission Info

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

Compile Error

./Main.cpp: In function ‘int read()’:
./Main.cpp:71:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s", q[i]);
                      ^

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