結果
問題 | No.1261 数字集め |
ユーザー | magsta |
提出日時 | 2020-10-14 22:46:09 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,937 bytes |
コンパイル時間 | 1,341 ms |
コンパイル使用メモリ | 92,160 KB |
実行使用メモリ | 145,920 KB |
最終ジャッジ日時 | 2024-07-21 04:47:09 |
合計ジャッジ時間 | 116,006 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2,394 ms
145,536 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | AC | 1,587 ms
134,400 KB |
testcase_45 | AC | 345 ms
70,012 KB |
testcase_46 | AC | 744 ms
96,220 KB |
testcase_47 | AC | 527 ms
82,816 KB |
testcase_48 | AC | 1,205 ms
120,832 KB |
testcase_49 | AC | 1,453 ms
133,376 KB |
testcase_50 | AC | 1,356 ms
124,928 KB |
testcase_51 | AC | 311 ms
71,936 KB |
testcase_52 | AC | 54 ms
52,224 KB |
testcase_53 | AC | 355 ms
72,448 KB |
testcase_54 | AC | 447 ms
75,536 KB |
testcase_55 | AC | 188 ms
62,464 KB |
testcase_56 | AC | 273 ms
65,920 KB |
testcase_57 | AC | 1,161 ms
117,364 KB |
testcase_58 | AC | 312 ms
70,240 KB |
testcase_59 | AC | 1,555 ms
136,008 KB |
testcase_60 | AC | 386 ms
74,604 KB |
testcase_61 | AC | 518 ms
84,096 KB |
testcase_62 | AC | 1,369 ms
127,404 KB |
testcase_63 | AC | 185 ms
63,952 KB |
testcase_64 | AC | 1,650 ms
142,572 KB |
testcase_65 | AC | 1,016 ms
111,360 KB |
testcase_66 | AC | 819 ms
101,408 KB |
testcase_67 | AC | 1,300 ms
127,564 KB |
testcase_68 | AC | 787 ms
98,816 KB |
testcase_69 | AC | 747 ms
97,656 KB |
testcase_70 | AC | 633 ms
88,340 KB |
testcase_71 | AC | 1,276 ms
123,776 KB |
testcase_72 | AC | 431 ms
77,600 KB |
testcase_73 | AC | 502 ms
81,996 KB |
testcase_74 | AC | 226 ms
65,744 KB |
testcase_75 | AC | 777 ms
95,212 KB |
testcase_76 | AC | 1,166 ms
117,588 KB |
testcase_77 | AC | 1,330 ms
128,384 KB |
testcase_78 | AC | 49 ms
51,072 KB |
testcase_79 | AC | 1,408 ms
131,148 KB |
testcase_80 | AC | 82 ms
52,480 KB |
testcase_81 | AC | 140 ms
59,264 KB |
testcase_82 | AC | 1,092 ms
114,008 KB |
testcase_83 | AC | 487 ms
79,432 KB |
testcase_84 | AC | 1,769 ms
145,880 KB |
testcase_85 | AC | 1,705 ms
145,792 KB |
testcase_86 | AC | 1,737 ms
145,920 KB |
testcase_87 | AC | 1,773 ms
145,792 KB |
testcase_88 | AC | 1,779 ms
145,920 KB |
testcase_89 | AC | 1,782 ms
145,792 KB |
testcase_90 | AC | 1,757 ms
145,792 KB |
testcase_91 | AC | 1,722 ms
145,916 KB |
testcase_92 | AC | 1,753 ms
145,792 KB |
testcase_93 | AC | 1,733 ms
145,920 KB |
ソースコード
#include <iostream> #include <vector> #include <algorithm> #include <utility> #include <map> #define MOD 1000000007 using namespace std; long long modpow(long long a, long long n) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % MOD; a = a * a % MOD; n >>= 1; } return res; } long long modinv(long long a) { return modpow(a, MOD - 2); } vector<long long> enum_divisors(long long N) { vector<long long> res; for (long long i = 1; i * i <= N; ++i) { if (N % i == 0) { res.push_back(i); // 重複しないならば i の相方である N/i も push if (N/i != i) res.push_back(N/i); } } // 小さい順に並び替える sort(res.begin(), res.end()); return res; } long long p_q_r(long long p, long long q, long long r, long long M){ if (r > p) swap(p, r); if (q > p) swap(p, q); if (r > q) swap(q, r); long long a, b, c, d, e; a = modpow(p, M - 2); b = modpow(q, M - 2); c = modpow(r, M - 2); d = (((a - c) * modinv(p - r) % MOD) + MOD) % MOD; e = (((b - c) * modinv(q - r) % MOD) + MOD) % MOD; d = d * p % MOD; e = e * q % MOD; return (((d - e) * modinv(p - q) % MOD) + MOD) % MOD; } int main() { long long N, M; cin >> N >> M; long long A[N]; for (int i = 1; i < N; i++) cin >> A[i]; map<long long, long long> Map; for (int i = 1; i < N; i++){ Map[A[i]]++; if (Map[A[i]] > 1) cout << "errar" << endl; if (A[i] < 2 || A[i] > 1000000) cout << "errbr" << endl; } const auto &res = enum_divisors(N); long long count = 0; long long ans = 0; for (int i = 0; i < res.size(); i++){ for (int j = 0; j < res.size(); j++){ if (res[i] == 1 || res[j] == 1) continue; if (N == (res[i] * res[j])) continue; if (N % (res[i] * res[j]) == 0){ long long p = A[res[i] - 1] - 1; long long q = A[res[i] * res[j] - 1] - 1; long long r = A[N - 1] - 1; ans = (ans + p_q_r(p, q, r, M)) % MOD; } } } cout << ans << endl; long long Q; cin >> Q; if (Q < 1 || Q > 10000) cout << "errer" << endl; vector<long long> num[N]; bool flag[N]; for (int i = 0; i < N; i++) flag[i] = false; map<long long, long long> Map_[1000001]; for (int i = 0; i < Q; i++){ long long X, Y; cin >> X >> Y; if (X >= Y || X < 1 || Y > N) cout << "errfr" << endl; if (Y % X == 0) cout << "errgr" << endl; Map_[X][Y]++; if (Map_[X][Y] > 1) cout << "errxr" << endl; if (Y == N){ const auto &res_ = enum_divisors(X); for (int i = 0; i < res_.size(); i++){ if (res_[i] == 1 || res_[i] == X) continue; long long p = A[res_[i] - 1] - 1; long long q = A[X - 1] - 1; long long r = A[Y - 1] - 1; ans = (ans + p_q_r(p, q, r, M)) % MOD; } for (int i = 0; i < num[X - 1].size(); i++){ long long p = A[num[X - 1][i] - 1] - 1; long long q = A[X - 1] - 1; long long r = A[Y - 1] - 1; ans = (ans + p_q_r(p, q, r, M)) % MOD; } flag[X - 1] = true; } if (Y != N){ if (N % Y == 0){ long long p = A[X - 1] - 1; long long q = A[Y - 1] - 1; long long r = A[N - 1] - 1; ans = (ans + p_q_r(p, q, r, M)) % MOD; } if (flag[Y - 1] == true){ long long p = A[X - 1] - 1; long long q = A[Y - 1] - 1; long long r = A[N - 1] - 1; ans = (ans + p_q_r(p, q, r, M)) % MOD; } num[Y - 1].push_back(X); } cout << ans << endl; } }