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/8cf9bd30-b93d-4d53-b103-c2bc346151aa%40googlegroups.com.

Reply via email to