fork download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int main() {
  6. int *x, n, pos, x1 = 0, y1 = 0;
  7. bool f = true;
  8. cin >> n;
  9. int X[] = {-1, 0, 1, 1, 1, 0, -1, -1};
  10. int Y[] = {1, 1, 1, 0, -1, -1, -1, 0};
  11. x = new int [2*n+2];
  12. for (int i = 2; i < (2 * n + 2); i += 2){
  13. cin >> pos;
  14. x1 += X[pos-1];
  15. y1 += Y[pos-1];
  16. x[i] = x1;
  17. x[i+1] = y1;
  18. }
  19. for (int i = 0; i < (2 * n + 2) && f; i += 2)
  20. for (int j = 0; j < i; j += 2)
  21. if ((x[i] == x[j]) && (x[i+1] == x[j+1])){
  22. cout << i / 2;
  23. f = false;
  24. }
  25. if (f) cout << "Ok" << endl << abs(x[2*n+1]) + abs(x[2*n]);
  26. delete []x;
  27. return 0;
  28. }
Success #stdin #stdout 0s 15232KB
stdin
5
1
2
4
7
4
stdout
4