-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaoj1204.cpp
More file actions
70 lines (68 loc) · 1.31 KB
/
aoj1204.cpp
File metadata and controls
70 lines (68 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <cstring>
#include <cctype>
#include <sstream>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <complex>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for(int i = a; i < (int)b; i++)
#define pb push_back
#define mp make_pair
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef long long ll;
const int INF = 1<<28;
const ll MOD = 1000000007;
vector<pi> x;
int n, ans;
void dfs(int pnt, int cnt, bool b[5][200]) {
if(pnt + n > ans) return;
if(cnt == 10) {
ans = min(ans, pnt + n-1);
return;
}
REP(i, x.size()) {
if(b[x[i].first][x[i].second + pnt]) {
dfs(pnt+1, cnt, b);
return;
}
}
REP(i, x.size())
b[x[i].first][x[i].second + pnt] = true;
dfs(pnt+1, cnt+1, b);
REP(i, x.size())
b[x[i].first][x[i].second + pnt] = false;
dfs(pnt+1, cnt, b);
return;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
while(cin >> n, n) {
ans = n * 10;
x.clear();
REP(i, 5) REP(j, n) {
char c; cin >> c;
if(c == 'X')
x.pb(mp(i, j));
}
bool b[5][200] = {};
dfs(0, 0, b);
cout << ans << endl;
}
return 0;
}