Submission #993690


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

const int md = 1000000007;

inline void add(int &a, int b) {
  a += b;
  if (a >= md) {
    a -= md;
  }
}

inline int mul(int a, int b) {
  return (long long) a * b % md;
}

const int N = 777;

int p[N];

int find_set(int x) {
  if (x != p[x]) {
    p[x] = find_set(p[x]);
  }
  return p[x];
}

void add_edge(int x, int y) {
  int xx = find_set(x);
  int yy = find_set(y);
  p[xx] = yy;
}

char s[N][N];
int sz[N];

int main() {
  int h, w;
  scanf("%d %d", &h, &w);
  for (int i = 0; i < h; i++) {
    scanf("%s", s[i]);
  }
  for (int i = 0; i < h / 2 + w / 2; i++) {
    p[i] = i;
  }
  int ans = 1;
  for (int i = 0; i < h - i - 1; i++) {
    for (int j = 0; j < w - j - 1; j++) {
      string z = "";
      z += s[i][j];
      z += s[h - i - 1][j];
      z += s[i][w - j - 1];
      z += s[h - i - 1][w - j - 1];
      sort(z.begin(), z.end());
      int cnt = 0;
      do {
        cnt++;
      } while (next_permutation(z.begin(), z.end()));
      if (cnt == 24) {
        ans = mul(ans, 12);
        add_edge(i, h / 2 + j);
      } else {
        ans = mul(ans, cnt);
      }
    }
  }
  if (h % 2 == 1) {
    string x = "";
    for (int j = 0; j < w; j++) {
      x += s[h / 2][j];
    }
    string y = x;
    reverse(y.begin(), y.end());
    if (x != y) {
      ans = mul(ans, 2);
    }
  }
  if (w % 2 == 1) {
    string x = "";
    for (int i = 0; i < h; i++) {
      x += s[i][w / 2];
    }
    string y = x;
    reverse(y.begin(), y.end());
    if (x != y) {
      ans = mul(ans, 2);
    }
  }
  for (int i = 0; i < h / 2 + w / 2; i++) {
    sz[i] = 0;
  }
  for (int i = 0; i < h / 2 + w / 2; i++) {
    sz[find_set(i)]++;
  }
  for (int i = 0; i < h / 2 + w / 2; i++) {
    if (sz[i] > 0) {
      for (int j = 0; j < sz[i] - 1; j++) {
        ans = mul(ans, 2);
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}

Submission Info

Submission Time
Task I - Reverse Grid
User tourist
Language C++14 (GCC 5.4.1)
Score 1900
Code Size 1987 Byte
Status AC
Exec Time 6 ms
Memory 512 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:40:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &h, &w);
                         ^
./Main.cpp:42:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s", s[i]);
                      ^

Judge Result

Set Name sample all
Score / Max Score 0 / 0 1900 / 1900
Status
AC × 2
AC × 37
Set Name Test Cases
sample sample-01.txt, sample-02.txt
all sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt, 01-31.txt, 01-32.txt, 01-33.txt, 01-34.txt, 01-35.txt
Case Name Status Exec Time Memory
01-01.txt AC 2 ms 256 KB
01-02.txt AC 2 ms 256 KB
01-03.txt AC 2 ms 256 KB
01-04.txt AC 2 ms 256 KB
01-05.txt AC 2 ms 256 KB
01-06.txt AC 2 ms 256 KB
01-07.txt AC 2 ms 256 KB
01-08.txt AC 3 ms 384 KB
01-09.txt AC 3 ms 384 KB
01-10.txt AC 4 ms 384 KB
01-11.txt AC 5 ms 384 KB
01-12.txt AC 5 ms 384 KB
01-13.txt AC 4 ms 384 KB
01-14.txt AC 3 ms 256 KB
01-15.txt AC 3 ms 384 KB
01-16.txt AC 6 ms 384 KB
01-17.txt AC 5 ms 512 KB
01-18.txt AC 6 ms 384 KB
01-19.txt AC 5 ms 384 KB
01-20.txt AC 5 ms 384 KB
01-21.txt AC 5 ms 384 KB
01-22.txt AC 2 ms 256 KB
01-23.txt AC 4 ms 384 KB
01-24.txt AC 5 ms 384 KB
01-25.txt AC 5 ms 384 KB
01-26.txt AC 5 ms 384 KB
01-27.txt AC 3 ms 256 KB
01-28.txt AC 3 ms 384 KB
01-29.txt AC 3 ms 384 KB
01-30.txt AC 3 ms 256 KB
01-31.txt AC 6 ms 384 KB
01-32.txt AC 6 ms 384 KB
01-33.txt AC 6 ms 384 KB
01-34.txt AC 6 ms 384 KB
01-35.txt AC 6 ms 384 KB
sample-01.txt AC 2 ms 256 KB
sample-02.txt AC 2 ms 256 KB