Imtiaz.axi's blog

By Imtiaz.axi, history, 5 months ago, In English

In last div 3 round in C-LR i had a problem for deviding a big nunmber with a small one. I am new to programming. Note: i tried unsigned long long x; but still same

#include<bits/stdc++.h>
#define ll long long
#define str string
#define fori(i,a,N) for (int i=a;i<N;i++)
using namespace std;
vector<int> prefix(vector<int> arr) {
    int n = arr.size();
    vector<int> ps(n);
    ps[0] = arr[0];
    for (int i = 1; i < n; i++) {
        ps[i] = ps[i &mdash; 1] + arr[i];
    }
    return ps;
}

int main()
{
    int t;
    cin>>t;
    while(t--){
        int N,M;
        cin>>N>>M;
        vector<int>A(N);
        string S;
        ll x=1;
        for(int i=0;i<N;i++){
            cin>>A[i];
            x*=A[i];
    }
        cin>>S;
        cout<<x%M<<" ";
        int l=0,r=N-1;
        fori(i,0,N-1){
        if(S[i]=='L'){
            x/=A[l];
            l++;
            cout<<x%M<<" ";
        }
        else if(S[i]=='R'){
            x/=A[r];
            r--;
            cout<<x%M<<" ";
        }
        }
        cout<<endl;
    }
   
}

Here when the value of x becomes more than 10^20, dividing it with numbers like 34,57 or any small type number doesnt give correct output.for that x%M is also comes wrong.what should i do? And also is the code logic correct? I know it will always bottle neck if inputs are big numbers. But for small numbers what do i have to modify?  

Full text and comments »

  • Vote: I like it
  • +5
  • Vote: I do not like it

By Imtiaz.axi, history, 5 months ago, In English

I saw people hack in contest. But I dont understand how to do that. Is there an editorial available for that?

Full text and comments »

  • Vote: I like it
  • +4
  • Vote: I do not like it