Skip to content

Instantly share code, notes, and snippets.

@Nimishkhurana
Created October 17, 2019 11:10
Show Gist options
  • Save Nimishkhurana/f03a6c6860d225c7a50905260bbe644d to your computer and use it in GitHub Desktop.
Save Nimishkhurana/f03a6c6860d225c7a50905260bbe644d to your computer and use it in GitHub Desktop.
#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