Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- long long n,yPos,xPos,i,k,;
- set < pair < long long , long long > > s;
- int main()
- {
- s.insert({0,0});
- int res= 0;
- xPos=0;
- yPos=0;
- cin >> n;
- for(i=1;i<=n;i++){
- cin >> k;
- if(k==1){
- xPos--;
- yPos++;
- }
- if(k==2){
- yPos++;
- }
- if(k==3){
- xPos++;
- yPos++;
- }
- if(k==4){
- xPos++;
- }
- if(k==5){
- xPos++;
- yPos--;
- }
- if(k==6){
- yPos--;
- }
- if(k==7){
- xPos--;
- yPos--;
- }
- if(k==8){
- xPos--;
- }
- if(s.count{xPos,yPos}==1){
- res = i;
- break;
- }
- }
- if(res!=0)cout<<res<<endl;
- else{
- cout<<"Ok"<<endl;
- cout<<abs(xPos)+abs(yPos)<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement