forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathG.cpp
More file actions
71 lines (64 loc) · 1.52 KB
/
G.cpp
File metadata and controls
71 lines (64 loc) · 1.52 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
71
#include <bits/stdc++.h>
using namespace std;
int isGood(vector <string> s)
{
set <string> blocks;
for (int i = 0; i < s.size(); i++)
{
string block = s[i].substr(0, 1);
for (int j = 1; j < s[i].size(); j++)
if (s[i][j] != s[i][j - 1])
block += s[i][j];
if (block.size() > 2) return 0;
if (block.size() == 1) continue;
blocks.insert(block);
}
return blocks.size() < 2;
}
int main()
{
ios::sync_with_stdio(0);
freopen("puzzle.in", "r", stdin);
freopen("puzzle.out", "w", stdout);
int it = 0, n;
string a[55];
while (cin >> n, n)
{
for (int i = 0; i < n; i++)
cin >> a[i];
if (it) cout << endl;
int ans = 0;
vector <string> s;
for (int i = 0; i < n; i++)
s.push_back(a[i]);
ans |= isGood(s);
s.clear();
for (int j = 0; j < n; j++)
{
string row = "";
for (int i = j; i < n; i++)
{
if (j < i) row += a[i][j * 2 + 1];
row += a[i][j * 2];
}
s.push_back(row);
}
ans |= isGood(s);
s.clear();
for (int i = 0; i < n; i++)
reverse(a[i].begin(), a[i].end());
for (int j = 0; j < n; j++)
{
string row = "";
for (int i = j; i < n; i++)
{
if (j < i) row += a[i][j * 2 + 1];
row += a[i][j * 2];
}
s.push_back(row);
}
ans |= isGood(s);
cout << "Puzzle " << ++it << endl;
cout << "Parts can" << (ans ? "" : "not") << " be separated" << endl;
}
}