QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#85809#5661. Multi-Laddersu2x1RE 2ms3312kbC++141.2kb2023-03-08 15:59:322023-03-08 15:59:43

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-08 15:59:43]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:3312kb
  • [2023-03-08 15:59:32]
  • 提交

answer

#include <iostream>
#include <cstring>

#define orep(i,l,r) for(auto i = (l); i < (r); ++i)
#define NL          std::cout << '\n';

const int maxN = 2e5+5;
const int mod = 1e9+7;
int arr[maxN];

long long n, k, r;

struct Mat { int x, y; long long val[3][3]; };
Mat tran, base;
Mat operator*(const Mat &a, const Mat &b) {
  Mat ret; memset(ret.val, 0, sizeof(ret.val));
  orep(i, 0, a.x) {
    orep(j, 0, b.y) {
      orep(z, 0, a.y) {
        ret.val[i][j] = ((a.val[i][z]*b.val[z][j]%mod) + ret.val[i][j]) % mod;
      }
    }
  }
  return ret;
}

long long calR() {
  Mat retm = base, a = tran;
  int kk = k-2;
  while(kk) {
    if (kk&1) { retm = retm*a; }
    kk/=2; a=a*a;
  }
  return retm.val[0][0];
}

long long calL() {
  long long ret = 1, a = ((r-2)*(r-2)%mod+(r-1)%mod) % mod;
  int kk = k*(n-1);
  while(kk) {
    if (kk&1) { ret = ret*a%mod; }
    kk/=2; a=a*a%mod;
  }
  return ret;
}

int main() {
  std::ios::sync_with_stdio(0); std::cin.tie(0);
  int t; std::cin >> t;
  while(t--) {
    std::cin >> n >> k >> r;
    tran = { 2, 2, {r-2, 1, r-1, 0} };
    base = { 1, 2, r*(r-1), r };
    std::cout << calR() * calL() % mod; NL;
  }


  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1
2 3 3

output:

162

result:

ok single line: '162'

Test #2:

score: -100
Runtime Error

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:


result: