QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#135387#5661. Multi-LaddersNicolas125841WA 1ms3516kbC++171.4kb2023-08-05 14:33:272023-08-05 14:33:29

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-05 14:33:29]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3516kb
  • [2023-08-05 14:33:27]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const ll mod = 1000000007;

ll modpow(ll b, ll e) {
    ll ans = 1;
    for (; e; b = b * b % mod, e /= 2)
        if (e & 1) ans = ans * b % mod;
    return ans;
}

template<class T, int N> struct Matrix {
typedef Matrix M;
array<array<T, N>, N> d{};
M operator*(const M& m) const {
M a;
rep(i,0,N) rep(j,0,N)
rep(k,0,N) {a.d[i][j] += d[i][k]*m.d[k][j] % mod; a.d[i][j] %= mod;}
return a;
}
vector<T> operator*(const vector<T>& vec) const {
vector<T> ret(N);
rep(i,0,N) rep(j,0,N) {ret[i] += d[i][j] * vec[j] % mod; ret[i] %= mod;}
return ret;
}
M operator^(ll p) const {
assert(p >= 0);
M a, b(*this);
rep(i,0,N) a.d[i][i] = 1;
while (p) {
if (p&1) a = a*b;
b = b*b;
p >>= 1;
}
return a;
}
};

int main(){
    cin.tie(NULL)->sync_with_stdio(false);

    int t;
    cin >> t;

    while(t--){
        ll n, k, l;
        cin >> n >> k >> l;

        Matrix<ll, 3> A;
        A.d = {{{{0, k-1, k-2}}, {{1, 0, 0}}, {{0, k-1, k-2}}}};

        vector<ll> vec = {1,0,0};

        vec = (A^(k-1)) * vec;
        
        cout << (modpow((n - 1) * ((k - 1) + modpow(k - 2, 2)) % mod, k) * k % mod) * ((vec[1] * (k - 1) % mod + vec[2] * (k - 2) % mod) % mod) % mod  << "\n";
    }
}

详细

Test #1:

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

input:

1
2 3 3

output:

162

result:

ok single line: '162'

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3492kb

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
118098
118098
0
0
561141893
789759042
999917063
27363649
162
655796160
999917063
27363649
0
0
0
655796160
655796160
655796160

result:

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