QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#317218#7308. Permutation and noitatumrePckiseki#AC ✓57ms3684kbC++202.2kb2024-01-28 17:57:132024-01-28 17:57:13

Judging History

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

  • [2024-01-28 17:57:13]
  • 评测
  • 测评结果:AC
  • 用时:57ms
  • 内存:3684kb
  • [2024-01-28 17:57:13]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define all(x) begin(x), end(x)
#ifdef CKISEKI
#define safe cerr << __PRETTY_FUNCTION__ << " line " << __LINE__ << " safe\n"
#define debug(a...) debug_(#a, a)
#define orange(a...) orange_(#a, a)
#include <experimental/iterator>
void debug_(auto s, auto ...a) {
  cerr << "\e[1;32m(" << s << ") = (";
  int f = 0;
  (..., (cerr << (f++ ? ", " : "") << a));
  cerr << ")\e[0m\n";
}
void orange_(auto s, auto L, auto R) {
  cerr << "\e[1;33m[ " << s << " ] = [ ";
  using namespace experimental;
  copy(L, R, make_ostream_joiner(cerr, ", "));
  cerr << " ]\e[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) safe
#define orange(...) safe
#endif

using lld = int64_t;

constexpr int mod = 1'000'000'007;

int add(int a, int b) {
  assert(0 <= a and a < mod);
  assert(0 <= b and b < mod);
  return a + b >= mod ? a + b - mod : a + b;
}
int mul(lld a, lld b) {
  assert(0 <= a and a < mod);
  assert(0 <= b and b < mod);
  return static_cast<int>(a * b % mod);
}

using Mat = array<array<int, 4>, 4>;
Mat mul(const Mat &a, const Mat &b) {
  Mat c = {};
  for (int i = 0; i < 4; i++)
    for (int k = 0; k < 4; k++)
      for (int j = 0; j < 4; j++)
        c[i][j] = add(c[i][j], mul(a[i][k], b[k][j]));
  return c;
}
consteval Mat Idx() {
  Mat ret;
  for (int i = 0; i < 4; ++i)
    for (int j = 0; j < 4; ++j)
      ret[i][j] = i == j;
  return ret;
}

Mat ksm(Mat a, int k) {
  Mat r = Idx();
  while (k) {
    if (k & 1)
      r = mul(r, a);
    k >>= 1;
    a = mul(a, a);
  }
  return r;
}


int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int n;
  while (cin >> n) {
    if (n == 1) {
      cout << "1\n";
    } else if (n == 2) {
      cout << "2\n";
    } else if (n == 3) {
      cout << "6\n";
    } else if (n == 4) {
      cout << "16\n";
    } else if (n == 5) {
      cout << "36\n";
    } else if (n == 6) {
      cout << "80\n";
    } else {
      Mat a = {};
      a[0][0] = 2, a[0][2] = 1, a[0][3] = 1;
      a[1][0] = 1;
      a[2][1] = 1;
      a[3][3] = 1;

      auto b = ksm(a, n - 5);
      int ans = add(add(mul(b[0][0], 36), mul(b[0][1], 16)), add(mul(b[0][2], 6), mul(b[0][3], 2)));
      cout << ans << '\n';
    }
  }
  return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3592kb

input:

4
1000000000

output:

16
861159011

result:

ok 2 number(s): "16 861159011"

Test #2:

score: 0
Accepted
time: 57ms
memory: 3684kb

input:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
...

output:

1
2
6
16
36
80
178
394
870
1920
4236
9344
20610
45458
100262
221136
487732
1075728
2372594
5232922
11541574
25455744
56144412
123830400
273116546
602377506
328585407
930287362
462952218
254489838
439267033
341486279
937462398
314191817
969869915
877202216
68596237
107062384
91326979
251250197
609562...

result:

ok 20000 numbers

Extra Test:

score: 0
Extra Test Passed