QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#85811#5661. Multi-Laddersu2x1WA 2ms3396kbC++141.2kb2023-03-08 16:02:542023-03-08 16:02:56

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 16:02:56]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3396kb
  • [2023-03-08 16:02:54]
  • 提交

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 { 1, 2, {} }; 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)%mod, 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: 3364kb

input:

1
2 3 3

output:

162

result:

ok single line: '162'

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 3396kb

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
410795592
654710102
514320698
415637863
176686901
271604347
615888704
816317724
506617192
603674547
595896761
0
0
902842271

result:

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