For technical reasons, judging has been temporarily stopped. No estimates yet. We are sorry for the issue. ×

15-03-2024's blog

By 15-03-2024, history, 3 weeks ago, In English

when submitted under c++14/c++17 it was giving runtime error but accepted by c++20


#include <bits/stdc++.h> #define int long long #define mod 1000000007 using namespace std; int fast_pow (int b , int p) { if(p==0) return 1; return p%2 ? (b*(fast_pow((b*b)%mod,p/2)%mod))%mod : fast_pow((b*b)%mod,p/2)%mod ; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); freopen("error.txt","w",stderr); #endif int t; cin>>t; while(t--){ int n,m; cin>>n>>m; vector<int> v(n); for(int &a:v) cin>>a; string s; cin>>s; int i=0,j=n-1; for(auto val:s){ if(i>=j) break; if(val=='L') i++; else j--; } int p=v[i]; vector<int> ans; p%=m; ans.push_back(p); for(int k=s.size()-2;k>=0;k--){ if(s[k]=='L'){ i--; p*=v[i]; p%=m; } else{ j++; p*=v[j]; p%=m; } ans.push_back(p); } std::reverse(ans.begin(), ans.end()); for(auto val:ans) cout<<val<<" "; cout<<endl; } }
  • Vote: I like it
  • -7
  • Vote: I do not like it

»
3 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by 15-03-2024 (previous revision, new revision, compare).

»
3 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

The problem is at s.size()-2, because s.size()is unsigned, it causes overflow, you should cast (int)s.size()

»
3 weeks ago, # |
  Vote: I like it -10 Vote: I do not like it

It is showing runtime error due to #define int long long.

I do not see why people use this shit :/