Submission #25990697
Source Code Expand
Copy
#include <bits/stdc++.h>using namespace std;#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(0)#define FOR(i, a, b) for(int i = (a); i <= (b); i++)#define REP(n) FOR(O, 1, (n))#define pb push_back#define f first#define s secondtypedef long double ld;typedef long long ll;typedef pair<int, int> pii;typedef pair<int, pii> piii;typedef vector<int> vi;typedef vector<pii> vii;typedef vector<ll> vl;typedef vector<piii> viii;mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());const int MAXN = 600100, MAXK = 60;
#include <bits/stdc++.h> using namespace std; #define FAST_IO ios_base::sync_with_stdio(0); cin.tie(0) #define FOR(i, a, b) for(int i = (a); i <= (b); i++) #define REP(n) FOR(O, 1, (n)) #define pb push_back #define f first #define s second typedef long double ld; typedef long long ll; typedef pair<int, int> pii; typedef pair<int, pii> piii; typedef vector<int> vi; typedef vector<pii> vii; typedef vector<ll> vl; typedef vector<piii> viii; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int MAXN = 600100, MAXK = 60; //const ll MOD = 998244353; //const ll MOD = 1e9+7; const ll INF = 1e17; //const ld PI = asin(1) * 2.0; ll n; ll k; ll a[MAXN]; ll pref1[MAXN], pref2[MAXN]; ll cnt[MAXN]; int main() { FAST_IO; cin >> n >> k; FOR(i, 1, n) cin >> a[i]; FOR(i, 1, n) pref1[a[i]]++; FOR(i, 1, n) pref2[a[i]] += a[i]; FOR(i, 1, MAXN-1) pref1[i] += pref1[i-1]; FOR(i, 1, MAXN-1) pref2[i] += pref2[i-1]; // ll c = sqrt(MAXN); //ll c = 4; ll ans = 1; /*FOR(x, 2, c) { FOR(i, 1, n) { ll toAdd = a[i]%x; toAdd = (x - toAdd) % x; cnt[x] += toAdd; } //cout << " x = " << x << " cnt = " << cnt[x] << endl; }*/ FOR(x, 1, MAXN-1) { ll lst = 0, cr = x; while (cr < MAXN) { //cout << " x = " << x << " cr = " << cr << " lst = " << lst << endl; //cout << " pref1 " << pref1[cr] << " - " << pref1[lst] << endl; //cout << " pref2 " << pref2[cr] << " - " << pref2[lst] << endl; cnt[x] += (pref1[cr] - pref1[lst]) * cr; cnt[x] -= pref2[cr] - pref2[lst]; //cnt[x] += cn lst = cr; cr += x; } // if (x < 10) //cout << " x = " << x << " cnt = " << cnt[x] << endl; } FOR(i, 1, MAXN-1) if (cnt[i] <= k) ans = i; if (cnt[MAXN-1] <= k) { ll rem = k - cnt[MAXN-1]; ll times = rem / n; ans = ((ll)(MAXN-1)) + times; //cout << " times = " << times << endl; } cout << ans << "\n"; return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - Maximize GCD |
User | Aldas25 |
Language | C++ (GCC 9.2.1) |
Score | 600 |
Code Size | 2224 Byte |
Status | AC |
Exec Time | 84 ms |
Memory | 19908 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 600 / 600 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt |
All | 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt, 02_large_ans_01.txt, 02_large_ans_02.txt, 02_large_ans_03.txt, 02_large_ans_04.txt, 02_large_ans_05.txt, 02_large_ans_06.txt, 02_large_ans_07.txt, 02_large_ans_08.txt, 02_large_ans_09.txt, 02_large_ans_10.txt, 03_rand_01.txt, 03_rand_02.txt, 03_rand_03.txt, 03_rand_04.txt, 03_rand_05.txt, 03_rand_06.txt, 03_rand_07.txt, 03_rand_08.txt, 03_rand_09.txt, 03_rand_10.txt, 03_rand_11.txt, 03_rand_12.txt, 03_rand_13.txt, 03_rand_14.txt, 03_rand_15.txt, 03_rand_16.txt, 03_rand_17.txt, 03_rand_18.txt, 03_rand_19.txt, 03_rand_20.txt, 03_rand_21.txt, 03_rand_22.txt, 03_rand_23.txt, 03_rand_24.txt, 03_rand_25.txt, 03_rand_26.txt, 03_rand_27.txt, 03_rand_28.txt, 03_rand_29.txt, 03_rand_30.txt, 03_rand_31.txt, 03_rand_32.txt, 03_rand_33.txt, 03_rand_34.txt, 03_rand_35.txt, 03_rand_36.txt, 03_rand_37.txt, 03_rand_38.txt, 03_rand_39.txt, 03_rand_40.txt, 04_small_ans_01.txt, 04_small_ans_02.txt, 04_small_ans_03.txt, 04_small_ans_04.txt, 04_small_ans_05.txt, 04_small_ans_06.txt, 04_small_ans_07.txt, 04_small_ans_08.txt, 04_small_ans_09.txt, 04_small_ans_10.txt, 04_small_ans_11.txt, 04_small_ans_12.txt, 04_small_ans_13.txt, 04_small_ans_14.txt, 04_small_ans_15.txt, 04_small_ans_16.txt, 04_small_ans_17.txt, 04_small_ans_18.txt, 04_small_ans_19.txt, 04_small_ans_20.txt, 05_handmade_01.txt, 05_handmade_02.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01_sample_01.txt | AC | 63 ms | 17652 KB |
01_sample_02.txt | AC | 60 ms | 17676 KB |
01_sample_03.txt | AC | 59 ms | 17636 KB |
02_large_ans_01.txt | AC | 75 ms | 18660 KB |
02_large_ans_02.txt | AC | 73 ms | 18688 KB |
02_large_ans_03.txt | AC | 69 ms | 18524 KB |
02_large_ans_04.txt | AC | 72 ms | 18520 KB |
02_large_ans_05.txt | AC | 75 ms | 18980 KB |
02_large_ans_06.txt | AC | 72 ms | 19012 KB |
02_large_ans_07.txt | AC | 83 ms | 19700 KB |
02_large_ans_08.txt | AC | 83 ms | 19716 KB |
02_large_ans_09.txt | AC | 63 ms | 17924 KB |
02_large_ans_10.txt | AC | 66 ms | 17964 KB |
03_rand_01.txt | AC | 72 ms | 18492 KB |
03_rand_02.txt | AC | 69 ms | 18492 KB |
03_rand_03.txt | AC | 61 ms | 18020 KB |
03_rand_04.txt | AC | 66 ms | 18068 KB |
03_rand_05.txt | AC | 66 ms | 18160 KB |
03_rand_06.txt | AC | 66 ms | 18184 KB |
03_rand_07.txt | AC | 69 ms | 18268 KB |
03_rand_08.txt | AC | 67 ms | 18184 KB |
03_rand_09.txt | AC | 66 ms | 18328 KB |
03_rand_10.txt | AC | 69 ms | 18188 KB |
03_rand_11.txt | AC | 63 ms | 18068 KB |
03_rand_12.txt | AC | 68 ms | 17988 KB |
03_rand_13.txt | AC | 79 ms | 19344 KB |
03_rand_14.txt | AC | 81 ms | 19376 KB |
03_rand_15.txt | AC | 65 ms | 17932 KB |
03_rand_16.txt | AC | 62 ms | 17932 KB |
03_rand_17.txt | AC | 75 ms | 18792 KB |
03_rand_18.txt | AC | 72 ms | 18804 KB |
03_rand_19.txt | AC | 65 ms | 18208 KB |
03_rand_20.txt | AC | 66 ms | 18168 KB |
03_rand_21.txt | AC | 72 ms | 18768 KB |
03_rand_22.txt | AC | 73 ms | 18872 KB |
03_rand_23.txt | AC | 78 ms | 19776 KB |
03_rand_24.txt | AC | 80 ms | 19720 KB |
03_rand_25.txt | AC | 76 ms | 18948 KB |
03_rand_26.txt | AC | 72 ms | 18952 KB |
03_rand_27.txt | AC | 70 ms | 18488 KB |
03_rand_28.txt | AC | 69 ms | 18616 KB |
03_rand_29.txt | AC | 64 ms | 18156 KB |
03_rand_30.txt | AC | 64 ms | 18016 KB |
03_rand_31.txt | AC | 78 ms | 19480 KB |
03_rand_32.txt | AC | 78 ms | 19544 KB |
03_rand_33.txt | AC | 69 ms | 18552 KB |
03_rand_34.txt | AC | 69 ms | 18560 KB |
03_rand_35.txt | AC | 60 ms | 17968 KB |
03_rand_36.txt | AC | 64 ms | 17856 KB |
03_rand_37.txt | AC | 69 ms | 18360 KB |
03_rand_38.txt | AC | 65 ms | 18260 KB |
03_rand_39.txt | AC | 80 ms | 19632 KB |
03_rand_40.txt | AC | 80 ms | 19484 KB |
04_small_ans_01.txt | AC | 66 ms | 18440 KB |
04_small_ans_02.txt | AC | 69 ms | 18344 KB |
04_small_ans_03.txt | AC | 68 ms | 18412 KB |
04_small_ans_04.txt | AC | 66 ms | 18444 KB |
04_small_ans_05.txt | AC | 66 ms | 18348 KB |
04_small_ans_06.txt | AC | 70 ms | 18236 KB |
04_small_ans_07.txt | AC | 67 ms | 18288 KB |
04_small_ans_08.txt | AC | 70 ms | 18360 KB |
04_small_ans_09.txt | AC | 74 ms | 18984 KB |
04_small_ans_10.txt | AC | 72 ms | 19032 KB |
04_small_ans_11.txt | AC | 70 ms | 18676 KB |
04_small_ans_12.txt | AC | 70 ms | 18796 KB |
04_small_ans_13.txt | AC | 76 ms | 19296 KB |
04_small_ans_14.txt | AC | 73 ms | 19248 KB |
04_small_ans_15.txt | AC | 72 ms | 19100 KB |
04_small_ans_16.txt | AC | 77 ms | 19072 KB |
04_small_ans_17.txt | AC | 66 ms | 18024 KB |
04_small_ans_18.txt | AC | 64 ms | 18172 KB |
04_small_ans_19.txt | AC | 79 ms | 19468 KB |
04_small_ans_20.txt | AC | 79 ms | 19464 KB |
05_handmade_01.txt | AC | 62 ms | 17676 KB |
05_handmade_02.txt | AC | 84 ms | 19908 KB |