fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int solve(vector<int> &A) {
  7. std::sort(A.begin(), A.end());
  8. int size1 = A.size();
  9. bool flag = true;
  10. for(int i =0; i <size1; i++) {
  11. if(A[i]!=0) {flag = false; break; }
  12. }
  13. if(flag) return 1;
  14. for(int i =1; i <size1; i++) {
  15. if(A[i] == A[i-1]) continue;
  16. if(A[i-1] == size1 - i) return 1;
  17. }
  18. return -1;
  19. }
  20.  
  21. int main() {
  22. // your code goes here
  23. //vector<int> A = {1, 2, 7, 0, 9, 3, 6, 0, 6 };
  24. vector<int> A = { -4, 7, 5, 3, 5, -4, 2, -1, -9, -8, -3, 0, 9, -7, -4, -10, -4, 2, 6, 1, -2, -3, -1, -8, 0, -8, -7, -3, 5, -1, -8, -8, 8, -1, -3, 3, 6, 1, -8, -1, 3, -9, 9, -6, 7, 8, -6, 5, 0, 3, -4, 1, -10, 6, 3, -8, 0, 6, -9, -5, -5, -6, -3, 6, -5, -4, -1, 3, 7, -6, 5, -8, -5, 4, -3, 4, -6, -7, 0, -3, -2, 6, 8, -2, -6, -7, 1, 4, 9, 2, -10, 6, -2, 9, 2, -4, -4, 4, 9, 5, 0, 4, 8, -3, -9, 7, -8, 7, 2, 2, 6, -9, -10, -4, -9, -5, -1, -6, 9, -10, -1, 1, 7, 7, 1, -9, 5, -1, -3, -3, 6, 7, 3, -4, -5, -4, -7, 9, -6, -2, 1, 2, -1, -7, 9, 0, -2, -2, 5, -10, -1, 6, -7, 8, -5, -4, 1, -9, 5, 9, -2, -6, -2, -9, 0, 3, -10, 4, -6, -6, 4, -3, 6, -7, 1, -3, -5, 9, 6, 2, 1, 7, -2, 5 } ;
  25. cout << solve(A);
  26. return 0;
  27. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
-1