QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#135377#5661. Multi-LaddersNicolas125841WA 1ms3524kbC++171.4kb2023-08-05 14:11:372023-08-05 14:11:38

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:11:38]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3524kb
  • [2023-08-05 14:11:37]
  • 提交

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];
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];
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";
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1
2 3 3

output:

162

result:

ok single line: '162'

Test #2:

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

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
-848737962
-453362749
999917063
-442513754
162
-486978315
999917063
-442513754
0
0
0
-486978315
-486978315
-486978315

result:

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