Submission #62815327
Source Code Expand
Copy
#include <iostream>#include <vector>#include <algorithm>#include <set>using namespace std;int main(){ios::sync_with_stdio(false);cin.tie(nullptr);int n, k;cin >> n >> k;vector<int> a(n);int mx = 0;for (int i = 0; i < n; i++){cin >> a[i];mx = max(mx, a[i]);}// 各数字の出現回数vector<int> c(mx + 1, 0);
#include <iostream> #include <vector> #include <algorithm> #include <set> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n, k; cin >> n >> k; vector<int> a(n); int mx = 0; for (int i = 0; i < n; i++){ cin >> a[i]; mx = max(mx, a[i]); } // 各数字の出現回数 vector<int> c(mx + 1, 0); for (int i = 0; i < n; i++){ c[a[i]]++; } // cc[d] = 入力中の d の倍数の個数 vector<int> cc(mx + 1, 0); for (int d = 1; d <= mx; d++){ for (int j = d; j <= mx; j += d){ cc[d] += c[j]; } } // mxまでの最小素因数を求める(ふるい) vector<int> sieve(mx + 1); for (int i = 0; i <= mx; i++){ sieve[i] = i; } for (int p = 2; p * p <= mx; p++){ if (sieve[p] == p) { for (int q = p * p; q <= mx; q += p){ if (sieve[q] == q) { sieve[q] = p; } } } } // 各数字について、条件を満たす最大の約数を出力 for (int i = 0; i < n; i++){ int x = a[i]; vector<int> factors; // x の素因数分解(重複あり) while (x > 1) { factors.push_back(sieve[x]); x /= sieve[x]; } // factors から全ての約数(重複を除く)を生成 set<int> divs; int m = factors.size(); for (int mask = 0; mask < (1 << m); mask++){ int prod = 1; for (int j = 0; j < m; j++){ if (mask & (1 << j)) prod *= factors[j]; } divs.insert(prod); } // 降順にソート vector<int> dvec(divs.begin(), divs.end()); sort(dvec.begin(), dvec.end(), greater<int>()); int ans = 1; for (int d : dvec){ if (cc[d] >= k){ ans = d; break; } } cout << ans << "\n"; } return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - GCD of Subset |
User | okapin |
Language | C++ 17 (gcc 12.2) |
Score | 0 |
Code Size | 2205 Byte |
Status | TLE |
Exec Time | 2213 ms |
Memory | 20872 KB |
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 475 | ||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 02_a_distinct_00.txt, 02_a_distinct_01.txt, 02_a_distinct_02.txt, 02_a_distinct_03.txt, 02_a_distinct_04.txt, 03_a_max_00.txt, 03_a_max_01.txt, 03_a_max_02.txt, 03_a_max_03.txt, 03_a_max_04.txt, 03_a_max_05.txt, 03_a_max_06.txt, 04_hcn_00.txt, 04_hcn_01.txt, 04_hcn_02.txt, 04_hcn_03.txt, 04_hcn_04.txt, 04_hcn_05.txt, 04_hcn_06.txt, 04_hcn_07.txt, 04_hcn_08.txt, 05_corner_00.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00_sample_00.txt | AC | 1 ms | 3536 KB |
00_sample_01.txt | AC | 1 ms | 3416 KB |
00_sample_02.txt | AC | 24 ms | 13928 KB |
01_random_00.txt | TLE | 2208 ms | 17624 KB |
01_random_01.txt | TLE | 2209 ms | 19652 KB |
01_random_02.txt | TLE | 2208 ms | 19460 KB |
01_random_03.txt | TLE | 2208 ms | 19676 KB |
01_random_04.txt | TLE | 2211 ms | 18772 KB |
01_random_05.txt | TLE | 2209 ms | 19692 KB |
01_random_06.txt | TLE | 2209 ms | 17688 KB |
01_random_07.txt | TLE | 2209 ms | 19728 KB |
01_random_08.txt | TLE | 2212 ms | 19200 KB |
01_random_09.txt | TLE | 2209 ms | 19808 KB |
02_a_distinct_00.txt | TLE | 2213 ms | 20648 KB |
02_a_distinct_01.txt | TLE | 2213 ms | 20872 KB |
02_a_distinct_02.txt | TLE | 2212 ms | 20388 KB |
02_a_distinct_03.txt | TLE | 2208 ms | 19804 KB |
02_a_distinct_04.txt | TLE | 2211 ms | 19892 KB |
03_a_max_00.txt | TLE | 2212 ms | 19756 KB |
03_a_max_01.txt | TLE | 2208 ms | 19664 KB |
03_a_max_02.txt | TLE | 2211 ms | 19764 KB |
03_a_max_03.txt | TLE | 2211 ms | 19780 KB |
03_a_max_04.txt | TLE | 2209 ms | 19632 KB |
03_a_max_05.txt | TLE | 2208 ms | 19728 KB |
03_a_max_06.txt | TLE | 2208 ms | 19644 KB |
04_hcn_00.txt | TLE | 2208 ms | 16364 KB |
04_hcn_01.txt | TLE | 2208 ms | 16356 KB |
04_hcn_02.txt | TLE | 2208 ms | 16384 KB |
04_hcn_03.txt | TLE | 2208 ms | 19628 KB |
04_hcn_04.txt | TLE | 2208 ms | 19680 KB |
04_hcn_05.txt | TLE | 2209 ms | 19684 KB |
04_hcn_06.txt | TLE | 2208 ms | 19664 KB |
04_hcn_07.txt | TLE | 2208 ms | 19684 KB |
04_hcn_08.txt | TLE | 2208 ms | 19648 KB |
05_corner_00.txt | AC | 10 ms | 7792 KB |