fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main() {
  6. int m, n, s, k;
  7. cin >> m >> n >> s >> k;
  8. string str;
  9. cin >> str;
  10. int star_number = 0;
  11. bool end_of_stars = 0;
  12. bool sec_seq = 0;
  13. bool imp = 0;
  14. bool un = 0;
  15. bool amb = 0;
  16. for (int i = 0; i < str.length() && !sec_seq; i++){
  17. if (str[i] == '*') {
  18. if (end_of_stars == 1) sec_seq = 1;
  19. else star_number++;
  20. }
  21. else {
  22. if ( (star_number != 0) and (end_of_stars == 0) ) end_of_stars = 1;
  23. }
  24. }
  25. if (sec_seq == 1) imp = 1;
  26. else {
  27. if (star_number == 0) {
  28. if (s > k-1 && s > m-k) imp = 1;
  29. else {
  30. if (n>s) amb = 1;
  31. else {
  32. if ( ( (s > m - k) and (k - 1 == s) ) or ( (s > k - 1) and (m - k == s) ) ) un = 1;
  33. else amb = 1;
  34. }
  35. }
  36. }
  37. else {
  38. if (star_number != s) imp = 1;
  39. else {
  40. if (m == s || s == 1 || k == 1 || k == m) un = 1;
  41. else amb = 1;
  42. }
  43. }
  44. }
  45. if (un == 1) cout << "Unique";
  46. if (amb == 1) cout << "Ambiguous";
  47. if (imp == 1) cout << "Impossible";
  48. return 0;
  49. }
Success #stdin #stdout 0s 4512KB
stdin
3 4 2 3
..**
stdout
Ambiguous