Language: C++

#include <cstdio>
#include <set>
using namespace std;
typedef unsigned long long ull;
int n, m, p;
char code[1010][1010];
bool ma[1010][1010];
bool pattern[1010][1010];
??
ull ha[1010][1010], tmp[1010][1010];
ull mh[1010][1010];
void compute_hash(bool a[1010][1010], int n, int m) {
????????const ull B1 = 9983;
????????const ull B2 = 100000007;
????????ull t1 = 1;
????????for (int j = 0; j < p; j++) t1 *= B1;
??
????????for (int i = 0; i < n; i++) {
????????????????ull e = 0;
????????????????for (int j = 0; j < p; j++) e = e * B1 + a[i][j];
??
????????????????for (int j = 0; j + p <= m; j++) {
????????????????????????tmp[i][j] = e;
????????????????????????if (j + p < m) e = e * B1 - t1 * a[i][j] + a[i][j + p];
????????????????}
????????}
??
????????ull t2 = 1;
????????for (int i = 0; i < p; i++) t2 *= B2;
??
????????for (int j = 0; j + p <= m; j++) {
????????????????ull e = 0;
????????????????for (int i = 0; i < p; i++) e = e * B2 + tmp[i][j];
??
????????????????for (int i = 0; i + p <= n; i++) {
????????????????????????ha[i][j] = e;
????????????????????????if (i + p < n) e = e * B2 - t2 * tmp[i][j] + tmp[i + p][j];
????????????????}
????????}
??????????
}
??
int getbit(char ch) {
????????if (ch >= 'A' && ch <= 'Z')???????????????? return 0 + ch - 'A';
????????if (ch >= 'a' && ch <= 'z')???????????????? return 26 + ch - 'a';
????????if (ch >= '0' && ch <= '9')???????????????? return 52 + ch - '0';
????????if (ch == '+') return 62;
????????return 63;
}
??
void decode(bool mat[1010][1010], int h, int w) {
????????for (int i = 0; i < h; i++) {
????????????????for (int j = 0; j < (w + 5) / 6; j++) {
????????????????????????int bit = getbit(code[i][j]);
????????????????????????for (int k = 0; k < 6; k++) {
????????????????????????????????mat[i][j*6+k] = ((bit >> (5 - k)) & 1) == 1;
????????????????????????}
????????????????}
????????}
}
??
void init() {
????????for (int i = 0; i < n; i++) scanf("%s", code[i]);
????????decode(ma, n, m);
????????for (int i = 0; i < p; i++) scanf("%s", code[i]);
????????decode(pattern, p, p);
}
??
bool tm[1010][1010];
void rotate() {
????????for (int i = 0; i < p; i++) {
????????????????for (int j = 0; j < p; j++) {
????????????????????????tm[i][j] = pattern[j][p-1-i];
????????????????}
????????}
????????for (int i = 0; i < p; i++) for (int j = 0; j < p; j++)
????????????????????????????????????????????????????????????????????????pattern[i][j] = tm[i][j];
}
void mirror() {
????????for (int i = 0; i < p; i++) {
????????????????for (int j = 0; j < p; j++) {
????????????????????????tm[i][j] = pattern[i][p-1-j];
????????????????}
????????}
????????for (int i = 0; i < p; i++) for (int j = 0; j < p; j++)
????????????????????????????????????????????????????????????????????????pattern[i][j] = tm[i][j];
}
??
set<ull> seen;
??
void solve() {
????????seen.clear();
????????int ans = 0;
????????compute_hash(pattern, p, p);
????????ull hp = ha[0][0];
????????seen.insert(hp);
????????compute_hash(ma, n, m);
????????for (int i = 0; i + p <= n; i++) {
????????????????for (int j = 0; j + p<= m; j++) {
????????????????????????if (ha[i][j] == hp) ans++;
????????????????????????mh[i][j] = ha[i][j];
????????????????}
????????}
????????for (int k = 0; k < 7; k++) {
????????????????if (k == 3) mirror();
????????????????else rotate();
????????????????compute_hash(pattern, p, p);
????????????????hp = ha[0][0];
????????????????if (seen.find(hp) != seen.end()) continue;
????????????????seen.insert(hp);
????????????????for (int i = 0; i + p <= n; i++) {
????????????????????????for (int j = 0; j + p <= m; j++) {
????????????????????????????????if (mh[i][j] == hp) ans++;
????????????????????????}
????????????????}
????????}
????????printf("%d\n", ans);
}
??
int main() {
????????for (;;) {
????????????????scanf("%d%d%d", &m, &n, &p);
????????????????if (n == 0 && m == 0 && p == 0) break;
????????????????init();
????????????????solve();
????????}
????????return 0;
}

Compiler output:
a.cc:9:1: error: expected unqualified-id before '?' token
    9 | ??
      | ^
a.cc: In function 'void compute_hash(bool (*)[1010], int, int)':
a.cc:13:1: error: expected primary-expression before '?' token
   13 | ????????const ull B1 = 9983;
      | ^
a.cc:13:2: error: expected primary-expression before '?' token
   13 | ????????const ull B1 = 9983;
      |  ^
a.cc:13:3: error: expected primary-expression before '?' token
   13 | ????????const ull B1 = 9983;
      |   ^
a.cc:13:4: error: expected primary-expression before '?' token
   13 | ????????const ull B1 = 9983;
      |    ^
a.cc:13:5: error: expected primary-expression before '?' token
   13 | ????????const ull B1 = 9983;
      |     ^
a.cc:13:6: error: expected primary-expression before '?' token
   13 | ????????const ull B1 = 9983;
      |      ^
a.cc:13:7: error: expected primary-expression before '?' token
   13 | ????????const ull B1 = 9983;
      |       ^
a.cc:13:8: error: expected primary-expression before '?' token
   13 | ????????const ull B1 = 9983;
      |        ^
a.cc:13:9: error: expected primary-expression before 'const'
   13 | ????????const ull B1 = 9983;
      |         ^~~~~
a.cc:13:9: error: expected ':' before 'const'
   13 | ????????const ull B1 = 9983;
      |         ^~~~~
      |         :
a.cc:13:9: error: expected primary-expression before 'const'
   13 | ????????const ull B1 = 9983;
      |         ^~~~~
a.cc:13:9: error: expected ':' before 'const'
   13 | ????????const ull B1 = 9983;
      |         ^~~~~
      |         :
a.cc:13:9: error: expected primary-expression before 'const'
   13 | ????????const ull B1 = 9983;
      |         ^~~~~
a.cc:13:9: error: expected ':' before 'const'
   13 | ????????const ull B1 = 9983;
      |         ^~~~~
      |         :
a.cc:13:9: error: expected primary-expression before 'const'
   13 | ????????const ull B1 = 9983;
      |         ^~~~~
a.cc:13:9: error: expected ':' before 'const'
   13 | ????????const ull B1 = 9983;
      |         ^~~~~
      |         :
a.cc:13:9: error: expected primary-expression before 'const'
   13 | ????????const ull B1 = 9983;
      |         ^~~~~
a.cc:13:9: error: expected ':' before 'const'
   13 | ????????const ull B1 = 9983;
      |         ^~~~~
      |         :
a.cc:13:9: error: expected primary-expression before 'const'
   13 | ????????const ull B1 = 9983;
      |         ^~~~~
a.cc:13:9: error: expected ':' before 'const'
   13 | ????????const ull B1 = 9983;
      |         ^~~~~
      |         :
a.cc:13:9: error: expected primary-expression before 'const'
   13 | ????????const ull B1 = 9983;
      |         ^~~~~
a.cc:13:9: error: expected ':' before 'const'
   13 | ????????const ull B1 = 9983;
      |         ^~~~~
      |         :
a.cc:13:9: error: expected primary-expression before 'const'
   13 | ????????const ull B1 = 9983;
      |         ^~~~~
a.cc:13:9: error: expected ':' before 'const'
   13 | ????????const ull B1 = 9983;
      |         ^~~~~
      |         :
a.cc:13:9: error: expected primary-expression before 'const'
   13 | ????????const ull B1 = 9983;
      |         ^~~~~
a.cc:14:1: error: expected primary-expression before '?' token
   14 | ????????const ull B2 = 100000007;
      | ^
a.cc:14:2: error: expected primary-expression before '?' token
   14 | ????????const ull B2 = 100000007;
      |  ^
a.cc:14:3: error: expected primary-expression before '?' token
   14 | ????????const ull B2 = 100000007;
      |   ^
a.cc:14:4: error: expected primary-expression before '?' token
   14 | ????????const ull B2 = 100000007;
      |    ^
a.cc:14:5: error: expected primary-expression before '?' token
   14 | ????????const ull B2 = 100000007;
      |     ^
a.cc:14:6: error: expected primary-expression before '?' token
   14 | ????????const ull B2 = 100000007;
      |      ^
a.cc:14:7: error: expected primary-expression before '?' token
   14 | ????????const ull B2 = 100000007;
      |       ^
a.cc:14:8: error: expected primary-expression before '?' token
   14 | ????????const ull B2 = 100000007;
      |        ^
a.cc:14:9: error: expected primary-expression before 'const'
   14 | ????????const ull B2 = 100000007;
      |         ^~~~~
a.cc:14:9: error: expected ':' before 'const'
   14 | ????????const ull B2 = 100000007;
      |         ^~~~~
      |         :
a.cc:14:9: error: expected primary-expression before 'const'
   14 | ????????const ull B2 = 100000007;
      |         ^~~~~
a.cc:14:9: error: expected ':' before 'const'
   14 | ????????const ull B2 = 100000007;
      |         ^~~~~
      |         :
a.cc:14:9: error: expected primary-expression before 'const'
   14 | ????????const ull B2 = 100000007;
      |         ^~~~~
a.cc:14:9: error: expected ':' before 'const'
   14 | ????????const ull B2 = 100000007;
      |         ^~~~~
      |         :
a.cc:14:9: error: expected primary-expression before 'const'
   14 | ????????const ull B2 = 100000007;
      |         ^~~~~
a.cc:14:9: error: expected ':' before 'const'
   14 | ????????const ull B2 = 100000007;
      |         ^~~~~
      |         :
a.cc:14:9: error: expected primary-expression before 'const'
   14 | ????????const ull B2 = 100000007;
      |         ^~~~~
a.cc:14:9: error: expected ':' before 'const'
   14 | ????????const ull B2 = 100000007;
      |         ^~~~~
      |         :
a.cc:14:9: error: expected primary-expression before 'const'
   14 | ????????const ull B2 = 100000007;
      |         ^~~~~
a.cc:14:9: error: expected ':' before 'const'
   14 | ????????const ull B2 = 100000007;
      |         ^~~~~
      |         :
a.cc:14:9: error: expected primary-expression before 'const'
   14 | ????????const ull B2 = 100000007;
      |         ^~~~~
a.cc:14:9: error: expected ':' before 'const'
   14 | ????????const ull B2 = 100000007;
      |         ^~~~~
      |         :
a.cc:14:9: error: expected primary-expression before 'const'
   14 | ????????const ull B2 = 100000007;
      |         ^~~~~
a.cc:14:9: error: expected ':' before 'const'
   14 | ????????const ull B2 = 100000007;
      |         ^~~~~
      |         :
a.cc:14:9: error: expected primary-expression before 'const'
   14 | ????????const ull B2 = 100000007;
      |         ^~~~~
a.cc:15:1: error: expected primary-expression before '?' token
   15 | ????????ull t1 = 1;
      | ^
a.cc:15:2: error: expected primary-expression before '?' token
   15 | ????????ull t1 = 1;
      |  ^
a.cc:15:3: error: expected primary-expression before '?' token
   15 | ????????ull t1 = 1;
      |   ^
a.cc:15:4: error: expected primary-expression before '?' token
   15 | ????????ull t1 = 1;
      |    ^
a.cc:15:5: error: expected primary-expression before '?' token
   15 | ????????ull t1 = 1;
      |     ^
a.cc:15:6: error: expected primary-expression before '?' token
   15 | ????????ull t1 = 1;
      |      ^
a.cc:15:7: error: expected primary-expression before '?' token
   15 | ????????ull t1 = 1;
      |       ^
a.cc:15:8: error: expected primary-expression before '?' token
   15 | ????????ull t1 = 1;
      |        ^
a.cc:15:13: error: expected primary-expression before 't1'
   15 | ????????ull t1 = 1;
      |             ^~
a.cc:15:12: error: expected ':' before 't1'
   15 | ????????ull t1 = 1;
      |            ^~~
      |            :
a.cc:15:13: error: 't1' was not declared in this scope
   15 | ????????ull t1 = 1;
      |             ^~
a.cc:15:19: error: expected ':' before ';' token
   15 | ????????ull t1 = 1;
      |                   ^
      |                   :
a.cc:15:19: error: expected primary-expression before ';' token
a.cc:15:19: error: expected ':' before ';' token
   15 | ????????ull t1 = 1;
      |                   ^
      |                   :
a.cc:15:19: error: expected primary-expression before ';' token
a.cc:15:19: error: expected ':' before ';' token
   15 | ????????ull t1 = 1;
      |                   ^
      |                   :
a.cc:15:19: error: expected primary-expression before ';' token
a.cc:15:19: error: expected ':' before ';' token
   15 | ????????ull t1 = 1;
      |                   ^
      |                   :
a.cc:15:19: error: expected primary-expression before ';' token
a.cc:15:19: error: expected ':' before ';' token
   15 | ????????ull t1 = 1;
      |                   ^
      |                   :
a.cc:15:19: error: expected primary-expression before ';' token
a.cc:15:19: error: expected ':' before ';' token
   15 | ????????ull t1 = 1;
      |                   ^
      |                   :
a.cc:15:19: error: expected primary-expression before ';' token
a.cc:15:19: error: expected ':' before ';' token
   15 | ????????ull t1 = 1;
      |                   ^
      |                   :
a.cc:15:19: error: expected primary-expression before ';' token
a.cc:16:1: error: expected primary-expression before '?' token
   16 | ????????for (int j = 0; j < p; j++) t1 *= B1;
      | ^
a.cc:16:2: error: expected primary-expression before '?' token
   16 | ????????for (int j = 0; j < p; j++) t1 *= B1;
      |  ^
a.cc:16:3: error: expected primary-expression before '?' token
   16 | ????????for (int j = 0; j < p; j++) t1 *= B1;
      |   ^
a.cc:16:4: error: expected primary-expression before '?' token
   16 | ????????for (int j = 0; j < p; j++) t1 *= B1;
      |    ^
a.cc:16:5: error: expected primary-expression before '?' token
   16 | ????????for (int j = 0; j < p; j++) t1 *= B1;
      |     ^
a.cc:16:6: error: expected primary-expression before '?' token
   16 | ????????for (int j = 0; j < p; j++) t1 *= B1;
      |      ^
a.cc:16:7: error: expected primary-expression before '?' token
   16 | ????????for (int j = 0; j < p; j++) t1 *= B1;
      |       ^
a.cc:16:8: error: expected primary-expression before '?' token
   16 | ????????for (int j = 0; j < p; j++) t1 *= B1;
      |        ^
a.cc:16:9: error: expected primary-expression before 'for'
   16 | ????????for (int j = 0; j < p; j++) t1 *= B1;
      |         ^~~
a.cc:16:9: error: expected ':' before 'for'
   16 | ????????for (int j = 0; j < p; j++) t1 *= B1;
      |         ^~~
      |         :
a.cc:16:9: error: expected primary-expression before 'for'
   16 | ????????for (int j = 0; j < p; j++) t1 *= B1;
      |         ^~~
a.cc:16:9: error: expected ':' befo