Skip to content

Instantly share code, notes, and snippets.

@mi6112ogit
Created September 15, 2017 06:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mi6112ogit/a17b044b1a0e70d86410c6f68290a3bb to your computer and use it in GitHub Desktop.
Save mi6112ogit/a17b044b1a0e70d86410c6f68290a3bb to your computer and use it in GitHub Desktop.
#include <iostream>
#include <algorithm>
#include <utility>
#include <map>
#include <queue>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
using namespace std;
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF (1 << 30)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<int, P> Pi;
const int MOD = 1e9 + 7;
const int dy[]={0, 0, 1, -1};
const int dx[]={1, -1, 0, 0};
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }
string s[5][5];
int res = 0;
map<string, bool> mp;
void dfs(int y, int x, int cnt, string now) {
if(cnt == 6) {
if(!mp[now]) {
++res;
mp[now] = true;
}
return;
}
now += s[y][x];
rep(i, 4) {
int nx = x + dx[i], ny = y + dy[i];
if(nx < 0 || nx >= 5 || ny < 0 || ny >= 5) continue;
dfs(ny, nx, cnt + 1, now);
}
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
rep(i, 5) rep(j, 5) cin >> s[i][j];
rep(i, 5) rep(j, 5) {
string now = "";
dfs(i, j, 0, now);
}
printf("%d\n", res);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment