hrithikjos56's blog

By hrithikjos56, history, 4 years ago, In English

Problem link

https://codeforces.me/contest/1351/problem/C

submission link https://codeforces.me/contest/1351/submission/109952345

include <bits/stdc++.h>

using namespace std;

define ios ios::sync_with_stdio(false); cin.tie(NULL);

define ll long long

define MOD 1000000007

int main() { ios;

ll t;

cin>>t;

while(t--) 
 {

string s;  

  cin>>s;

ll x = 0,y=0,n = s.size();

map<pair<ll,ll>,bool>mp;

ll ans = 0;

for(ll i=0;i<n;i++)

{

   mp[{x,y}] = 1;

    if(s[i] == 'N') y+= 1;

    else if(s[i] == 'S') y -= 1;

    else if(s[i] == 'E') x += 1;

    else if(s[i] == 'W') x -= 1;


    if(mp[{x,y}] == 1)   

      ans += 1;

    else 

       ans += 5;  

}

   cout<<ans<<endl;

 }

return 0;

}

  • Vote: I like it
  • -15
  • Vote: I do not like it

| Write comment?
»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

You should reset the map 'mp' to all 0,or there are probably some '1's at first.

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

You need to mark a particular segment ((x1,y1)->(x2,y2)) as visited not just the coordinate.