fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int n;
  5. int a[100005];
  6. int slxh[100005]; /// slxh[t] = x có ý nghĩa là giá trị t được xuất hiện x lần
  7. int dd = 1;
  8.  
  9. int main()
  10. {
  11. cin >> n;
  12. for(int i = 1;i <= n;i++)
  13. {
  14. cin >> a[i];
  15. }
  16.  
  17. for(int i = 1;i <= n;i++)
  18. {
  19. slxh[i] = 0;
  20. }
  21.  
  22. for(int i = 1;i <= n;i++)
  23. {
  24. int t = a[i];
  25. if(t < 1 || t > n)
  26. {
  27. cout <<"NO";
  28. return 0;
  29. }
  30. slxh[t]++;
  31. }
  32.  
  33. for(int i = 1;i <= n;i++)
  34. {
  35. if(slxh[i] != 1)
  36. {
  37. dd = 0;
  38. break;
  39. }
  40. }
  41.  
  42. if(dd == 0)
  43. {
  44. cout <<"NO";
  45. }
  46. else cout <<"YES";
  47. }
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
YES