fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int a[200006], n, arr1[200006], arr2[200006];
  6.  
  7. int main(){
  8. ios_base :: sync_with_stdio(false);
  9. cin.tie(0);
  10.  
  11. int sum = 0;
  12. cin >> n;
  13. for(int j = 0; j < n+1; j++){
  14. cin >> a[j];
  15. sum += a[j];
  16. }
  17. sum -= a[n];
  18. if(sum == n || (n == 1 && a[1] == 2)){
  19. cout << "perfect\n";
  20. return 0;
  21. }
  22.  
  23. arr1[1] = arr2[1] = 0;
  24. int k = 2, flag = 0, par = 1, adj = 0;
  25. for(int j = 1; j < n+1; j++){
  26. int temp = k;
  27. for(int i = 0; i < a[j]; i++)
  28. arr1[k] = arr2[k] = par, k++;
  29. par = temp;
  30.  
  31. if(flag == 1){
  32. flag = 2;
  33. arr2[temp] = adj;
  34. }
  35. if(a[j] > 1) flag++, adj = temp + 1;
  36. }
  37.  
  38. cout << "ambiguous\n";
  39. for(int j = 1; j < k; j++)
  40. cout << arr1[j] << " ";
  41. cout << endl;
  42. for(int j = 1; j < k; j++)
  43. cout << arr2[j] << " ";
  44. cout << endl;
  45. return 0;
  46. }
  47.  
Success #stdin #stdout 0s 4344KB
stdin
1
1
stdout
perfect