CODE FESTIVAL 2016 Final

Submission #995439

Source codeソースコード

#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <functional>
#include <vector>
using namespace std;

constexpr int MOD = 1000000007;

int main() {
  int H, W; scanf("%d%d", &H, &W);
  static char S[200][201];
  for(int i = 0; i < H; ++i) {
    scanf(" %200s", S[i]);
  }
  static bool has_parity[100][100];
  int count = 1;
  int H2 = H/2;
  int W2 = W/2;
  for(int i = 0; i < H2; ++i) {
    for(int j = 0; j < W2; ++j) {
      char chs[4] = {S[i][j], S[i][W-1-j], S[H-1-i][j], S[H-1-i][W-1-j]};
      sort(chs, chs+4);
      int arbity;
      bool hp = false;
      if(chs[0] == chs[1] && chs[1] == chs[2] && chs[2] == chs[3]) {
        arbity = 1;
      } else if(chs[0] == chs[1] && chs[2] == chs[3]) {
        arbity = 6;
      } else if(chs[1] == chs[2] && chs[2] == chs[3]) {
        arbity = 4;
      } else if(chs[0] == chs[1] && chs[1] == chs[2]) {
        arbity = 4;
      } else if(chs[0] == chs[1] || chs[1] == chs[2] || chs[2] == chs[3]) {
        arbity = 12;
      } else {
        arbity = 12;
        hp = true;
      }
      count = (int64_t)count * arbity % MOD;
      has_parity[i][j] = hp;
    }
  }
  if(H % 2 == 1) {
    bool hp = false;
    for(int j = 0; j < W2; ++j) {
      if(S[H/2][j] != S[H/2][W-1-j]) hp = true;
    }
    if(hp) count = (int64_t)count * 2 % MOD;
  }
  if(W % 2 == 1) {
    bool hp = false;
    for(int i = 0; i < H2; ++i) {
      if(S[i][W/2] != S[H-1-i][W/2]) hp = true;
    }
    if(hp) count = (int64_t)count * 2 % MOD;
  }
  vector<char> vis(H2+W2);
  function<void(int)> dfs = [&](int v) {
    if(vis[v]) return;
    vis[v] = true;
    if(v < H2) {
      int i = v;
      for(int j = 0; j < W2; ++j) {
        if(has_parity[i][j]) {
          dfs(H2+j);
        }
      }
    } else {
      int j = v-H2;
      for(int i = 0; i < H2; ++i) {
        if(has_parity[i][j]) {
          dfs(i);
        }
      }
    }
  };
  int resolvable_parities = H2+W2;
  for(int i = 0; i < H2; ++i) {
    if(!vis[i]) {
      --resolvable_parities;
      dfs(i);
    }
  }
  for(int j = 0; j < W2; ++j) {
    if(!vis[H2+j]) {
      --resolvable_parities;
      dfs(H2+j);
    }
  }
  for(int i = 0; i < resolvable_parities; ++i) {
    count = (int64_t)count * 2 % MOD;
  }
  printf("%d\n", count);
  return 0;
}

Submission

Task問題 I - Reverse Grid
User nameユーザ名 qnighy
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 1900
Source lengthソースコード長 2365 Byte
File nameファイル名
Exec time実行時間 3 ms
Memory usageメモリ使用量 256 KB

Compiler messageコンパイルメッセージ

./Main.cpp: In function ‘int main()’:
./Main.cpp:11:34: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
int H, W; scanf("%d%d", &H, &W);
^
./Main.cpp:14:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf(" %200s", S[i]);
^

Test case

Set

Set name Score得点 / Max score Cases
sample - sample-01.txt,sample-02.txt
all 1900 / 1900 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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
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 2 ms 256 KB
01-09.txt AC 2 ms 256 KB
01-10.txt AC 3 ms 256 KB
01-11.txt AC 3 ms 256 KB
01-12.txt AC 3 ms 256 KB
01-13.txt AC 3 ms 256 KB
01-14.txt AC 2 ms 256 KB
01-15.txt AC 2 ms 256 KB
01-16.txt AC 3 ms 256 KB
01-17.txt AC 3 ms 256 KB
01-18.txt AC 3 ms 256 KB
01-19.txt AC 3 ms 256 KB
01-20.txt AC 3 ms 256 KB
01-21.txt AC 3 ms 256 KB
01-22.txt AC 2 ms 256 KB
01-23.txt AC 3 ms 256 KB
01-24.txt AC 3 ms 256 KB
01-25.txt AC 3 ms 256 KB
01-26.txt AC 3 ms 256 KB
01-27.txt AC 2 ms 256 KB
01-28.txt AC 2 ms 256 KB
01-29.txt AC 2 ms 256 KB
01-30.txt AC 2 ms 256 KB
01-31.txt AC 3 ms 256 KB
01-32.txt AC 3 ms 256 KB
01-33.txt AC 3 ms 256 KB
01-34.txt AC 3 ms 256 KB
01-35.txt AC 3 ms 256 KB
sample-01.txt AC 2 ms 256 KB
sample-02.txt AC 2 ms 256 KB