8000 Merge pull request #447 from haneulkimdev/patch-2 · Getbra1n/basic-algo-lecture@83b8c3f · GitHub
[go: up one dir, main page]

Skip to content

Commit 83b8c3f

Browse files
Merge pull request encrypted-def#447 from haneulkimdev/patch-2
Update 20166.cpp
2 parents 0b47956 + 6cd43b0 commit 83b8c3f

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

0x15/solutions/20166.cpp

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,35 @@
1-
// Authored by : BaaaaaaaaaaarkingDog
1+
// Authored by : haneulkimdev
22
// Co-authored by : -
3-
// http://boj.kr/****************
3+
// http://boj.kr/fe5bca51572d4d88a54a6062e493b993
44
#include <bits/stdc++.h>
55
using namespace std;
66

7-
int main(void){
7+
string board[10];
8+
int n, m, k;
9+
int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
10+
int dy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
11+
unordered_map<string, int> cnt;
12+
13+
void dfs(int i, int j, string s) {
14+
cnt[s]++;
15+
if (s.size() == 5) return;
16+
for (int dir = 0; dir < 8; dir++) {
17+
int nx = (i + dx[dir] + n) % n;
18+
int ny = (j + dy[dir] + m) % m;
19+
dfs(nx, ny, s + board[nx][ny]);
20+
}
21+
}
22+
23+
int main(void) {
824
ios::sync_with_stdio(0);
925
cin.tie(0);
10-
11-
}
26+
cin >> n >> m >> k;
27+
for (int i = 0; i < n; i++) cin >> board[i];
28+
for (int i = 0; i < n; i++)
29+
for (int j = 0; j < m; j++) dfs(i, j, string(1, board[i][j]));
30+
while (k--) {
31+
string s;
32+
cin >> s;
33+
cout << cnt[s] << '\n';
34+
}
35+
}

0 commit comments

Comments
 (0)
0