QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#186048#5661. Multi-Laddersaesthetic#WA 1ms3616kbC++202.0kb2023-09-23 02:46:332023-09-23 02:46:33

Judging History

你现在查看的是最新测评结果

  • [2023-09-23 02:46:33]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3616kb
  • [2023-09-23 02:46:33]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
const int MOD = 1e9 + 7;
long long n, k, lam;

long long gbrute(int x)
{
    if(x == 1)
        return 0;
    if(x == 2)    
        return lam * (lam - 1) % MOD;
    return (gbrute(x - 1)* (lam - 2) % MOD + gbrute(x - 2) * (lam - 1) % MOD) % MOD;
}

struct mat
{
    long long elem[2][2];
    mat operator *(const mat &o) const
    {
        mat ret;
        for(int i = 0; i < 2; ++i)
            for(int j = 0; j < 2; ++j)
            {
                long long acc = 0;
                for(int k = 0; k < 2; ++k)
                    acc += elem[i][k] * o.elem[k][j] % MOD;
                ret.elem[i][j] = acc % MOD;
            }
        return ret;
    }

    static mat identity()
    {
        mat m;
        m.elem[0][0] = 1;
        m.elem[0][1] = 0;
        m.elem[1][0] = 0;
        m.elem[1][1] = 1;
        return m;
    }
};

mat powmat(mat &m, long long e)
{
    if(!e)
        return mat::identity();
    if(e & 1)
        return m * powmat(m, e - 1);
    mat aux = powmat(m, e >> 1);
    return aux * aux;
}

long long g(long long x)
{
    mat m;
    m.elem[0][0] = lam - 2;
    m.elem[0][1] = lam - 1;
    m.elem[1][0] = 1;
    m.elem[1][1] = 0;

    m = powmat(m, x - 1);

    return m.elem[1][0] * (lam - 1) % MOD * lam % MOD;
}

long long powm(long long b, long long e, long long m)
{
    if(!e)
        return 1;
    if(e & 1)
        return b * powm(b, e - 1, m) % m;
    long long aux = powm(b, e >> 1, m);
    return aux * aux % m;
}

void solve()
{
    cin >> n >> k >> lam;

    long long a = ((lam - 1) + (lam - 2) * (lam - 2) % MOD) % MOD;
    long long ans = g(n);
    long long aa = powm(a, k, MOD);
    aa = powm(aa, n - 1, MOD);
    cout << (ans * aa) % MOD << '\n';
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout); 
    #endif
    ios_base::sync_with_stdio(false), cin.tie(NULL);

    int t;
    for(cin >> t; t--;)
    {
        solve();
    }   
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3388kb

input:

1
2 3 3

output:

162

result:

ok single line: '162'

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3616kb

input:

20
2 3 3
1 3 3
10 3 0
10 3 2
1 21 2
1 22 0
2000 15000 2000
12000 30000 200000
1000000000 3 3
2 1000000000 3
2 3 100000000
1000000000 1000000000 10
1000000000 3 100000000
2 1000000000 100000000
1 1000000000 10
1 1000000000 100000000
1 1000 100000000
1000000000 1000000000 0
1000000000 1000000000 1
100...

output:

162
0
0
2
0
0
619159556
44174210
103570820
415637863
304930780
218103365
294935167
29649047
0
0
0
0
0
311752813

result:

wrong answer 2nd lines differ - expected: '6', found: '0'