Great! it worked, it is given that there would be atmost 10^4 steps that's 
why i used (int). Thanks for making time to debug it. I appreciate it.


On Saturday, April 25, 2020 at 1:16:00 AM UTC+5:30, porker2008 wrote:
>
> You need to use long long to handle intermediate result, otherwise it will 
> overflow.
> Otherwise, your solution looks pretty good!
>
> *#include <iostream>*
> *#include <vector>*
> *#include <string>*
> *using namespace std;*
>
> *long long MOD = 1000000000LL;*
>
> *pair<pair<long long, long long>, int> xydis(string s) {*
> * long long x = 0;*
> * long long y = 0;*
> * int i = 0;*
> * for (i = 0; s[i] != ')' && i < s.size(); i++) {*
> * if (s[i] == 'N') {*
> * y--;*
> * }*
> * if (s[i] == 'S') {*
> * y++;*
> * }*
> * if (s[i] == 'E') {*
> * x++;*
> * }*
> * if (s[i] == 'W') {*
> * x--;*
> * }*
> * if (isdigit(s[i])) {*
> * int n = s[i] - '0';*
> * pair<pair<long long, long long>, int> future = xydis(s.substr(i + 2, 
> s.length() - i - 1));*
> * x += n * future.first.first;*
> * y += n * future.first.second;*
> * x = (x + MOD) % MOD;*
> * y = (y + MOD) % MOD;*
> * i += future.second + 2;*
> * }*
> * }*
> * x = (x + MOD) % MOD;*
> * y = (y + MOD) % MOD;*
> * return make_pair(make_pair(x, y), i);*
> *}*
> *int main() {*
> * int te;*
> * cin >> te;*
> * for (int i = 0; i < te; i++) {*
> * string s;*
> * cin >> s;*
> * cout << "Case #" << i + 1 << ": ";*
> * pair<int, int> result = xydis(s).first;*
> * long long x = result.first + 1;*
> * long long y = result.second + 1;*
> * cout << x << " " << y << endl;*
> * }*
> *}*
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/d3f6109b-ce70-4d5b-9de5-5e94660dbaf0%40googlegroups.com.

Reply via email to