結果
問題 | No.1261 数字集め |
ユーザー | SSRS |
提出日時 | 2020-10-16 23:22:45 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,085 bytes |
コンパイル時間 | 2,061 ms |
コンパイル使用メモリ | 177,236 KB |
実行使用メモリ | 115,968 KB |
最終ジャッジ日時 | 2024-07-21 04:39:01 |
合計ジャッジ時間 | 123,715 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2,748 ms
115,584 KB |
testcase_01 | AC | 488 ms
40,360 KB |
testcase_02 | AC | 1,228 ms
83,196 KB |
testcase_03 | AC | 1,228 ms
84,224 KB |
testcase_04 | AC | 752 ms
54,464 KB |
testcase_05 | AC | 1,671 ms
110,848 KB |
testcase_06 | AC | 837 ms
61,708 KB |
testcase_07 | AC | 1,245 ms
87,040 KB |
testcase_08 | AC | 693 ms
49,144 KB |
testcase_09 | AC | 861 ms
63,872 KB |
testcase_10 | AC | 18 ms
5,632 KB |
testcase_11 | AC | 1,688 ms
109,440 KB |
testcase_12 | AC | 1,560 ms
97,792 KB |
testcase_13 | AC | 1,367 ms
88,332 KB |
testcase_14 | AC | 78 ms
11,648 KB |
testcase_15 | AC | 590 ms
43,776 KB |
testcase_16 | AC | 1,367 ms
87,272 KB |
testcase_17 | AC | 1,049 ms
70,528 KB |
testcase_18 | AC | 660 ms
44,644 KB |
testcase_19 | AC | 1,285 ms
84,724 KB |
testcase_20 | AC | 104 ms
13,696 KB |
testcase_21 | AC | 1,869 ms
115,712 KB |
testcase_22 | AC | 1,814 ms
115,712 KB |
testcase_23 | AC | 1,786 ms
115,724 KB |
testcase_24 | AC | 1,841 ms
115,796 KB |
testcase_25 | AC | 1,876 ms
115,780 KB |
testcase_26 | AC | 1,808 ms
115,712 KB |
testcase_27 | AC | 1,797 ms
115,712 KB |
testcase_28 | AC | 1,835 ms
115,840 KB |
testcase_29 | AC | 1,850 ms
115,840 KB |
testcase_30 | AC | 1,866 ms
115,776 KB |
testcase_31 | AC | 1,859 ms
115,840 KB |
testcase_32 | AC | 1,860 ms
115,732 KB |
testcase_33 | AC | 1,797 ms
115,712 KB |
testcase_34 | AC | 1,723 ms
115,840 KB |
testcase_35 | AC | 1,768 ms
115,712 KB |
testcase_36 | AC | 1,786 ms
115,812 KB |
testcase_37 | AC | 1,831 ms
115,832 KB |
testcase_38 | AC | 1,853 ms
115,840 KB |
testcase_39 | AC | 1,799 ms
115,712 KB |
testcase_40 | AC | 1,785 ms
115,748 KB |
testcase_41 | AC | 1,800 ms
115,840 KB |
testcase_42 | AC | 1,691 ms
115,840 KB |
testcase_43 | AC | 1,736 ms
115,840 KB |
testcase_44 | AC | 1,569 ms
102,144 KB |
testcase_45 | AC | 280 ms
24,320 KB |
testcase_46 | AC | 755 ms
56,064 KB |
testcase_47 | AC | 567 ms
39,348 KB |
testcase_48 | AC | 1,246 ms
85,596 KB |
testcase_49 | AC | 1,460 ms
100,992 KB |
testcase_50 | AC | 1,370 ms
90,368 KB |
testcase_51 | AC | 341 ms
27,008 KB |
testcase_52 | AC | 35 ms
5,376 KB |
testcase_53 | AC | 381 ms
27,204 KB |
testcase_54 | AC | 459 ms
30,708 KB |
testcase_55 | AC | 167 ms
15,872 KB |
testcase_56 | AC | 236 ms
19,456 KB |
testcase_57 | AC | 1,243 ms
81,236 KB |
testcase_58 | AC | 316 ms
24,828 KB |
testcase_59 | AC | 1,601 ms
103,936 KB |
testcase_60 | AC | 390 ms
29,824 KB |
testcase_61 | AC | 525 ms
41,088 KB |
testcase_62 | AC | 1,469 ms
93,056 KB |
testcase_63 | AC | 156 ms
18,048 KB |
testcase_64 | AC | 1,717 ms
111,828 KB |
testcase_65 | AC | 1,090 ms
73,984 KB |
testcase_66 | AC | 892 ms
62,080 KB |
testcase_67 | AC | 1,406 ms
93,892 KB |
testcase_68 | AC | 838 ms
58,848 KB |
testcase_69 | AC | 796 ms
57,600 KB |
testcase_70 | AC | 649 ms
45,916 KB |
testcase_71 | AC | 1,365 ms
88,960 KB |
testcase_72 | AC | 432 ms
33,488 KB |
testcase_73 | AC | 568 ms
38,528 KB |
testcase_74 | AC | 202 ms
19,804 KB |
testcase_75 | AC | 841 ms
54,016 KB |
testcase_76 | AC | 1,179 ms
81,524 KB |
testcase_77 | AC | 1,434 ms
94,816 KB |
testcase_78 | AC | 33 ms
5,376 KB |
testcase_79 | AC | 1,417 ms
98,304 KB |
testcase_80 | WA | - |
testcase_81 | AC | 104 ms
12,416 KB |
testcase_82 | AC | 1,115 ms
76,928 KB |
testcase_83 | AC | 489 ms
35,312 KB |
testcase_84 | AC | 1,840 ms
115,840 KB |
testcase_85 | AC | 1,840 ms
115,916 KB |
testcase_86 | AC | 1,873 ms
115,940 KB |
testcase_87 | AC | 1,771 ms
115,812 KB |
testcase_88 | AC | 1,804 ms
115,840 KB |
testcase_89 | AC | 1,835 ms
115,840 KB |
testcase_90 | AC | 1,843 ms
115,792 KB |
testcase_91 | AC | 1,791 ms
115,880 KB |
testcase_92 | AC | 1,856 ms
115,796 KB |
testcase_93 | AC | 1,848 ms
115,968 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; array<array<long long, 3>, 3> matmul(array<array<long long, 3>, 3> &A, array<array<long long, 3>, 3> &B){ array<array<long long, 3>, 3> ans; for (int i = 0; i < 3; i++){ for (int j = 0; j < 3; j++){ ans[i][j] = 0; } } for (int i = 0; i < 3; i++){ for (int k = 0; k < 3; k++){ for (int j = 0; j < 3; j++){ ans[i][k] += A[i][j] * B[j][k]; } ans[i][k] %= MOD; } } return ans; } array<array<long long, 3>, 3> matexp(array<array<long long, 3>, 3> &A, long long b){ array<array<long long, 3>, 3> ans; for (int i = 0; i < 3; i++){ for (int j = 0; j < 3; j++){ ans[i][j] = i == j; } } while (b > 0){ if (b % 2 == 1){ ans = matmul(ans, A); } A = matmul(A, A); b /= 2; } return ans; } long long get(vector<int> &A, int M, int a, int b){ array<array<long long, 3>, 3> mat; mat[0][0] = A[a - 1] - 1; mat[0][1] = 1; mat[0][2] = 0; mat[1][0] = 0; mat[1][1] = A[b - 1] - 1; mat[1][2] = 1; mat[2][0] = 0; mat[2][1] = 0; mat[2][2] = A.back() - 1; mat = matexp(mat, M - 1); return mat[0][2]; } int main(){ int N, M; cin >> N >> M; vector<int> A(N, 0); for (int i = 1; i < N; i++){ cin >> A[i]; } long long ans = 0; vector<vector<int>> prev(N + 1); for (int a = 2; a < N; a++){ for (int b = a * 2; b < N; b += a){ prev[b].push_back(a); if (N % a == 0 && N % b == 0){ ans += get(A, M, a, b); if (ans >= MOD){ ans -= MOD; } } } } cout << ans << endl; int Q; cin >> Q; set<int> st; for (int i = 0; i < Q; i++){ int X, Y; cin >> X >> Y; if (Y == N){ for (int a : prev[X]){ ans += get(A, M, a, X); if (ans >= MOD){ ans -= MOD; } } st.insert(X); } else { if (st.count(Y)){ ans += get(A, M, X, Y); if (ans >= MOD){ ans -= MOD; } } } prev[Y].push_back(X); cout << ans << endl; } }