Can anyone help why this code was showing runtime error 
Difference between en1 and en2, changed 21 character(s)
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;↵


    }↵












}

~~~~~↵

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English 15-03-2024 2024-06-06 11:21:53 21
en1 English 15-03-2024 2024-06-06 11:20:35 1521 Initial revision (published)