fork download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int x[2001][2001];
  6.  
  7. int main() {
  8. int n;
  9. cin >> n;
  10. int pos;
  11. bool f = true;
  12. int x1 = 1001, y1 = 1001;
  13. for(int i = 0; i< n && f; i++) {
  14. cin >> pos;
  15. if(x[x1][y1] == 1) {
  16. cout << i;
  17. f = false;
  18. }
  19. else x[x1][y1] = 1;
  20. switch (pos) {
  21. case 1: x1--; y1++; break;
  22. case 3: x1++;
  23. case 2: y1++; break;
  24. case 4: x1++; break;
  25. case 5: x1++;
  26. case 6: y1--; break;
  27. case 7: y1--;
  28. case 8: x1--;
  29. }
  30. }
  31. if (f) cout << "Ok" << endl << abs(x1-1001) + abs(y1-1001);
  32. return 0;
  33. }
Success #stdin #stdout 0s 30872KB
stdin
Standard input is empty
stdout
Ok
0