Skip to content

Instantly share code, notes, and snippets.

@fpdjsns
Created January 5, 2019 12:36
Show Gist options
  • Save fpdjsns/92ce5fc97f0fb363b588979ba8628c97 to your computer and use it in GitHub Desktop.
Save fpdjsns/92ce5fc97f0fb363b588979ba8628c97 to your computer and use it in GitHub Desktop.
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
int n = 4;
set<string> setNum;
int dx[4] = { -1,1,0,0 };
int dy[4] = { 0,0,-1,1 };
vector<vector<int>> arr;
void getSum(int x, int y, int cnt, string s) {
s += arr[x][y]+'0';
cnt++;
if (cnt == 7) {
setNum.insert(s);
return;
}
for (int i = 0; i < 4; i++) {
int nx = x + dx[i];
int ny = y + dy[i];
if (nx < 0 || n <= nx || ny < 0 || n <= ny) continue;
getSum(nx, ny, cnt, s);
}
}
int main() {
int t;
cin >> t;
for (int c = 1; c <= t; c++) {
setNum = set<string>();
arr = vector<vector<int>>(4, vector<int>(4));
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
cin >> arr[i][j];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
getSum(i, j, 0, "");
printf("#%d %d\n", c, setNum.size());
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment