fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. ios_base::sync_with_stdio(false);
  6. cin.tie(NULL);
  7. int t;
  8. cin>>t;
  9. while(t--){
  10. string s;
  11. cin>>s;
  12. int n=s.length();
  13. int ar[n],cou;
  14. for(int i=0;i<n;i++){
  15. if(s[i]=='.') ar[i]=0;
  16. else{
  17. ar[i]=s[i]+'0';
  18. ar[i]-=96;
  19. ++cou;
  20. }
  21. }
  22. if(cou==0 || cou==1){
  23. cout<<"safe"<<endl;
  24. continue;
  25. }
  26. int f=0,*br=ar;
  27. for(int i=0;i<n;i++){
  28. int j=ar[i];
  29. br[i]=0;
  30. if(j==0){
  31. continue;
  32. }
  33. for(int k=i-j;k<=i+j;k++){
  34. if(k<0){
  35. continue;
  36. }
  37. if(br[k]!=0){
  38. f=1;
  39. break;
  40. }
  41. }
  42. br[i]=j;
  43. if(f==1){
  44. break;
  45. }
  46. }
  47. cout<<"unsafe"<<endl;
  48. }
  49. return 0;
  50. }
Success #stdin #stdout 0s 4420KB
stdin
5
....
.2.....
.2...2..
.1.1.1.
...3..2..
stdout
safe
safe
unsafe
unsafe
unsafe