QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#110367 | #5661. Multi-Ladders | ycccc319# | WA | 1ms | 3416kb | C++20 | 1.8kb | 2023-06-01 18:11:30 | 2023-06-01 18:11:34 |
Judging History
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,k,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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3356kb
input:
1 2 3 3
output:
162
result:
ok single line: '162'
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3416kb
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 276995160 407607609 52489881 53690844 98832450 846090933 543620055 992214290 693053429 883715672 80402569 0 0 344896140
result:
wrong answer 7th lines differ - expected: '349400141', found: '276995160'