-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path298B - Sail.cpp
More file actions
64 lines (63 loc) · 1.25 KB
/
298B - Sail.cpp
File metadata and controls
64 lines (63 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
ll x1,x2,y1,y2,x_req,y_req,t,t_req=0,i=0,east=0,west=0,north=0,south=0;
string directions;
bool possible =true;
cin>>t>>x1>>y1>>x2>>y2;
cin.ignore();
cin>>directions;
x_req=x2-x1;
y_req=y2-y1;
if(x_req<0){
west=abs(x_req)*1;
}
else if(x_req>0){
east=abs(x_req)*1;
}
if(y_req<0){
south=abs(y_req)*1;
}
else if(y_req>0){
north=abs(y_req)*1;
}
while(true){
if(directions[i]=='E'){
if(east!=0){
east-=1;
}
}
else if(directions[i]=='W'){
if(west!=0){
west-=1;
}
}
else if(directions[i]=='N'){
if(north!=0){
north-=1;
}
}
else if(directions[i]=='S'){
if(south!=0){
south-=1;
}
}
i+=1;
t_req+=1;
if(t_req>t){
possible=false;
break;
}
if(east==0 && west==0 && north==0 && south==0){
break;
}
}
if(possible){
cout<<t_req<<"\n";
}
else {
cout<<"-1\n";
}
return 0;
}