fork(1) download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int main() {
  6. int *x, *y, n, pos, x1 = 0, y1 = 0;
  7. bool f = true;
  8. cin >> n;
  9. x = new int [n];
  10. y = new int [n];
  11. for (int i = 1; i <= n; i ++){
  12. cin >> pos;
  13. if (pos == 1){
  14. x1 -= 1;
  15. y1 += 1;
  16. }
  17. else if (pos == 2) y1 += 1;
  18. else if (pos == 3){
  19. x1 += 1;
  20. y1 += 1;
  21. }
  22. else if (pos == 4) x1 += 1;
  23. else if (pos == 5){
  24. x1 += 1;
  25. y1 -= 1;
  26. }
  27. else if (pos == 6) y1 -= 1;
  28. else if (pos == 7){
  29. x1 -= 1;
  30. y1 -= 1;
  31. }
  32. else if (pos == 8) x1 -= 1;
  33. x[i] = x1;
  34. y[i] = y1;
  35. }
  36. for (int i = 1; i < n && f; i++)
  37. for (int j = 0; j < i; j++)
  38. if ((x[i] == x[j]) && (y[i] == y[j])){
  39. cout << i;
  40. f = false;
  41. }
  42. if (f) cout << "Ok" << endl << abs(x[n]) + abs(y[n]);
  43. delete []x;
  44. delete []y;
  45. return 0;
  46. }
Success #stdin #stdout 0s 15232KB
stdin
5
1
2
4
7
4
stdout
4