Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

Help in MTRICK

$
0
0

Hello @all,

As some people said that brute-force was possible for this problem, I decided to try and solve it that way and wrote the following code:

#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iostream>
#include <map>
#include <functional>
#include <numeric>
using namespace std;
typedef unsigned long long int u64;

u64 multiplyModulo(u64 a, u64 b, u64 c)
{
    u64 result = 0ULL;
    a %= c;
    b %= c;
    while(b) {
        if(b & 0x1) {
            result += a;
            result %= c;
        }
        b >>= 1;
        a <<= 1;
        a %= c;
    }
    return result;
}

int main()
{
    ios_base::sync_with_stdio(false);
    int t;
    cin >> t;
    while(t--)
    {
        int N;
        cin >> N;
        vector<u64> v(N);
        for(int i = 0; i < N; i++)
        {
            cin >> v[i];
        }
        u64 A,B,C;
        cin >> A >> B >> C;
        string s;
        cin >> s;


        for(int i = 0; i < N; i++)
        {
            if(s.substr(i,1)=="R") //rev all elems... todo
            {
                reverse(v.begin(),v.end());
            }
            if(s.substr(i,1)=="A")
            {
                for(int j = i; j < N; j++)
                {
                    v[j] += A;
                    if(v[j] >= C)
                        v[j] %= C;
                }
            }
            if(s.substr(i,1)=="M")
            {
                for(int j = i; j < N; j++)
                {
                    v[j] = multiplyModulo(v[j],B,C);
                }
            }
            //for(int z = i; z < N; z++)
            //v[z] = v[z]%C;
        cout << v[i]<< " ";
        }
        cout << endl;
    }
    return 0;
}

Can anyone point me in the right track?

I didn't really understood editorial's concepts very well...

Best,

Bruno


Viewing all articles
Browse latest Browse all 39796

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>