QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#110366#5661. Multi-Laddersycccc319#WA 2ms3500kbC++201.8kb2023-06-01 18:08:242023-06-01 18:08:25

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-01 18:08:25]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3500kb
  • [2023-06-01 18:08:24]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
const ll mod =(int)1e9+7;
using namespace std;
ll inv(ll i)
{
    if (i == 1)
        return 1;
    return (mod - mod / i) * inv(mod % i) % mod;
}
inline ll qMul(ll a, ll b, ll mod)
{
    ll tmp = (a * b - (ll)((long double)a / mod * b + 1.0e-8) * mod);
    return tmp < 0 ? tmp + mod : tmp;
}
// 快速幂
ll qPow(ll base, ll power, ll mod)
{
    ll ans = 1;
    while (power)
    {
        if (power & 1)
        {
            ans = qMul(ans, base, mod);
        }
        base = qMul(base, base, mod);
        power >>= 1;
    }
    return ans % mod;
}
ll g(ll n,ll k,ll x)
{
    ll o=(x-2)*(x-2)%mod+2*(x-2)%mod;
    o=o%mod;
    ll gg= qPow(o,n-1,mod);
    ll ggg= qPow(gg,x,mod);
    return ggg%mod;
}
ll f(ll k,ll x)
{
    ll ans=x* qPow(x-1,k-1,mod)%mod;
    return ans;
}
ll ans_k(ll n,ll k,ll x)
{
    ll ans_3=x*(x-1)%mod*(x-2)%mod;
    if(k==3)
    {
        return ans_3;
    }
    ll a1=f(4,x);
    if(k==4)
    {
        return ((a1-ans_3)%mod+mod)%mod;
    }
    ll q=-(x-1);
    ll S=a1*(1- qPow(q,k-3,mod))%mod*inv(((1-q)%mod+mod)%mod)%mod;
    if(k&1)
    {
        S=((-S)%mod+mod)%mod;
        return ((S+ans_3)%mod+mod)%mod;
    }
    else
    {
        return ((S-ans_3)%mod+mod)%mod;
    }
}
int main()
{
    int l;
    cin>>l;
    while (l--)
    {
        ll n,k,x;
        cin>>n>>k>>x;
        if(x<=1)
        {
            cout<<0<<"\n";
            continue;
        }
        if(x==2)
        {
            if(k&1)
            {
                cout<<0<<"\n";
                continue;
            }
            else
            {
                cout<<2<<"\n";
                continue;
            }
        }
        ll ans=g(n,k,x)*ans_k(n,k,x)%mod;
        cout<<ans<<"\n";
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 3500kb

input:

1
2 3 3

output:

162

result:

ok single line: '162'

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 3412kb

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
6
0
0
0
0
347949796
53197066
52489881
796875060
285575040
574440768
540053077
484451630
693053429
883715672
80402569
0
0
118285344

result:

wrong answer 7th lines differ - expected: '349400141', found: '347949796'