-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA_Game_of_Robots.cpp
More file actions
49 lines (47 loc) · 902 Bytes
/
A_Game_of_Robots.cpp
File metadata and controls
49 lines (47 loc) · 902 Bytes
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
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool solve(string s)
{
int lasti = -1;
for (int i = 0; i < s.size(); i++)
{
if (s[i] == '.')
{
continue;
}
if (lasti == -1)
lasti = i;
else
{
int ci = i, cr = s[i] - 48;
int li = lasti, lr = s[lasti] - 48;
int leftm = ci - cr;
int rightm = li + lr;
if (leftm <= rightm)
{
return false;
}
lasti = i;
}
}
return true;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t;
cin >> t;
while (t--)
{
string s;
cin >> s;
if (solve(s))
cout << "safe" << endl;
else
cout << "unsafe" << endl;
}
return 0;
}