fork download
  1. /******************************************************************************
  2.  
  3.   Online C++ Compiler.
  4.   Code, Compile, Run and Debug C++ program online.
  5. Write your code in this editor and press "Run" button to compile and execute it.
  6.  
  7. *******************************************************************************/
  8.  
  9. #include <bits/stdc++.h>
  10.  
  11. using namespace std;
  12.  
  13. #define ll long long
  14. string s;
  15. ll arr[55];
  16. int main()
  17. {
  18.  
  19. ll t;
  20. cin>>t;
  21. while(t--)
  22. {
  23. cin>>s;
  24. memset(arr,0,sizeof(arr));
  25. for(int i=0;i<s.length();i++)
  26. {
  27. if(s[i]>='0' && (s[i]<='9'))
  28. {
  29. for(int j=max(0,i-(s[i]-48));j<=(s.length()) && j<=i+s[i]-48;j++)
  30. {
  31. arr[j]++;
  32. }
  33. }
  34. }
  35. ll flag=0;
  36. for(int i=0;i<55;i++)
  37. {
  38. if(arr[i]>1)
  39. {
  40. flag=1;
  41. break;
  42. }
  43. }
  44. if(flag)
  45. {
  46. cout<<"unsafe\n";
  47. }
  48. else
  49. cout<<"safe\n";
  50. }
  51. return 0;
  52. }
  53.  
Success #stdin #stdout 0s 4356KB
stdin
4
....
.2.....
.2...2..
1.1.1.
stdout
safe
safe
unsafe
unsafe