QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#135390#5661. Multi-LaddersNicolas125841WA 1ms3476kbC++171.5kb2023-08-05 14:39:402023-08-05 14:39:44

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:39:44]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3476kb
  • [2023-08-05 14:39:40]
  • 提交

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;

        if(l < 2){
            cout << "0\n";
            continue;
        }

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

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

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

详细

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: 3476kb

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
67926327
493059521
999917063
874721371
528484719
110679368
415825769
918952047
414862606
837156664
996330811
0
0
933257754

result:

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