Created
October 17, 2019 11:10
-
-
Save Nimishkhurana/f03a6c6860d225c7a50905260bbe644d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<string.h> | |
using namespace std; | |
int main(){ | |
int t; | |
cin>>t; | |
// cin.ignore(); | |
while(t--){ | |
string s; | |
cin>>s; | |
int n = s.length(); | |
int arr[n]; | |
for(int i=0;i<n;i++) arr[i]=-1; | |
bool flag=false; | |
for(int i=0;i<n;i++){ | |
if(s[i]=='.') | |
continue; | |
int range = s[i]-'0'; | |
for(int j=max(0,i-range);j<=min(n-1,i+range);j++){ | |
if(arr[j]!=-1){ | |
flag=true; | |
cout<<"unsafe"<<endl; | |
break; | |
} | |
else{ | |
arr[j]=i; | |
} | |
} | |
if(flag) break; | |
} | |
if(!flag) cout<<"safe"<<endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment