Hi, I am unable to understand why I’m getting a WA for test-set 2. The idea I’ve implemented it to count how many times a symbol would contribute to the final answer. I think I’m making some mistake in doing modulo with 1e9 but not able to understand where. Can you help me figure this out?
Here’s my code:
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define lli long long int
#define ulli unsigned long long int
#define for0(i,n) for(long long int i=0;i<(long long int)n;i++)
#define for1(i,n) for(long long int i=1;i<(long long int)n;i++)
#pragma GCC target ("sse4.2")
#include <algorithm>
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
int cl=1;
const ulli bound = 1000000000;
while(t--){
string s;
cin>>s;
ulli curr=1, latest=1;
stack<lli> st;
st.push(1);
lli ea=0, we=0, no=0, so=0;
for0(i,s.size()){
if(s[i]>='0' && s[i]<='9'){
lli x = s[i]-'0';
st.push(x);
curr*=x;
} else if(s[i]!=')'){
switch(s[i]){
case 'E': ea=(ea+(curr%bound));
break;
case 'W': we=(we+(curr%bound));
break;
case 'N': no=(no+(curr%bound));
break;
case 'S': so=(so+(curr%bound));
break;
}
} else {
if(!st.empty()){
curr/=st.top();
st.pop();
}
}
}
lli ver = (so-no);
lli hor = (ea-we);
cout<<"Case #"<<cl<<": ";
if(bound+hor+1<0){
cout<<bound-(abs(hor)%bound)+1<<" ";
} else
(hor<0) ? cout<<bound+hor+1<<" " : cout<<(hor%bound)+1<<" ";
if(bound+ver+1<0){
cout<<bound-(abs(ver)%bound)+1<<" ";
} else
(ver<0) ? cout<<bound+ver+1<<"\n" : cout<<(ver%bound)+1<<"\n";
++cl;
}
return 0;
}