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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
| #include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int w, h;
int sy, sx, gy, gx;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
bool can(int y,int x) {
if(0 <= y && y < h && 0 <= x && x < w) return true;
return false;
}
vector<string> s;
char c;
bool used[55][55], visited[55][55];
bool check() {
REP(i, sy, gy+1){
REP(j, sx, gx+1) {
if(s[i][j] == c || used[i][j]) continue;
return false;
}
}
return true;
}
void f() {
REP(i, sy, gy+1) {
REP(j, sx, gx+1) {
used[i][j] = true;
}
}
}
int main() {
int n;
cin >> n;
rep(q, n) {
cin >> h >> w;
s.resize(h);
rep(i, h) cin >> s[i];
memset(used, 0, sizeof(used));
set<char> S;
bool flag = true, update = true;
while(update) {
update = false;
rep(i, h) {
rep(j, w) {
if(s[i][j] == '.') continue;
if(used[i][j]) continue;
sy = i;
sx = j;
gy = i;
gx = j;
c = s[i][j];
memset(visited, 0, sizeof(visited));
rep(k, h) {
rep(l, w) {
if(s[k][l] == c) {
sy = min(sy, k);
sx = min(sx, l);
gy = max(gy, k);
gx = max(gx, l);
}
}
}
if(S.find(c) == S.end() && check()) {
f();
S.insert(c);
update = true;
}
}
}
}
rep(i, h) {
rep(j, w) {
if(used[i][j]) continue;
if(s[i][j] == '.') continue;
flag = false;
}
}
if(flag) cout << "SAFE" << endl;
else cout << "SUSPICIOUS" << endl;
}
return 0;
}
|