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