QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#85862#5661. Multi-Laddersu2x1AC ✓2ms3436kbC++141.2kb2023-03-08 18:45:362023-03-08 18:45: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-03-08 18:45:38]
  • 评测
  • 测评结果:AC
  • 用时:2ms
  • 内存:3436kb
  • [2023-03-08 18:45:36]
  • 提交

answer

#include <iostream>
#include <cstring>

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

const int mod = 1e9+7;

long long n, k, r;

struct Mat { int x, y; long long val[3][3]; };

Mat operator*(const Mat &a, const Mat &b) {
  Mat ret { a.x, b.y, {} }; 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 = { 2, 2, { {1, 0}, {0, 1}} },
      a = { 2, 2, { {r-2, 1}, {r-1, 0}} };
  long long kk = k-1;
  while(kk) {
    if (kk&1) { retm = retm*a; }
    kk/=2; a=a*a;
  }
  return (r*(r-1)%mod) * retm.val[0][1] % mod;
}

long long calL() {
  long long ret = 1, a = ((r-2)*(r-2)%mod+(r-1)%mod) % mod;
  long long 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;
    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: 3436kb

input:

1
2 3 3

output:

162

result:

ok single line: '162'

Test #2:

score: 0
Accepted
time: 2ms
memory: 3408kb

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
349400141
243010659
52489881
53690844
176686901
218103365
558243892
991895211
693053429
883715672
80402569
0
0
311752813

result:

ok 20 lines