結果
問題 | No.937 Ultra Sword |
ユーザー | omochana2 |
提出日時 | 2019-12-04 23:49:20 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 125 ms / 3,000 ms |
コード長 | 3,031 bytes |
コンパイル時間 | 1,298 ms |
コンパイル使用メモリ | 147,340 KB |
実行使用メモリ | 8,600 KB |
最終ジャッジ日時 | 2023-08-21 06:36:45 |
合計ジャッジ時間 | 7,076 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
5,676 KB |
testcase_01 | AC | 6 ms
5,624 KB |
testcase_02 | AC | 3 ms
5,768 KB |
testcase_03 | AC | 3 ms
5,760 KB |
testcase_04 | AC | 2 ms
5,676 KB |
testcase_05 | AC | 125 ms
7,640 KB |
testcase_06 | AC | 81 ms
8,408 KB |
testcase_07 | AC | 91 ms
8,508 KB |
testcase_08 | AC | 43 ms
8,420 KB |
testcase_09 | AC | 34 ms
8,420 KB |
testcase_10 | AC | 99 ms
8,416 KB |
testcase_11 | AC | 14 ms
5,756 KB |
testcase_12 | AC | 46 ms
7,696 KB |
testcase_13 | AC | 45 ms
7,712 KB |
testcase_14 | AC | 52 ms
7,828 KB |
testcase_15 | AC | 40 ms
7,820 KB |
testcase_16 | AC | 6 ms
5,660 KB |
testcase_17 | AC | 9 ms
5,604 KB |
testcase_18 | AC | 43 ms
7,692 KB |
testcase_19 | AC | 27 ms
7,704 KB |
testcase_20 | AC | 24 ms
7,820 KB |
testcase_21 | AC | 102 ms
8,516 KB |
testcase_22 | AC | 3 ms
5,584 KB |
testcase_23 | AC | 6 ms
5,688 KB |
testcase_24 | AC | 122 ms
7,676 KB |
testcase_25 | AC | 87 ms
8,236 KB |
testcase_26 | AC | 80 ms
8,400 KB |
testcase_27 | AC | 74 ms
8,436 KB |
testcase_28 | AC | 82 ms
8,356 KB |
testcase_29 | AC | 4 ms
6,180 KB |
testcase_30 | AC | 66 ms
8,600 KB |
testcase_31 | AC | 105 ms
8,400 KB |
testcase_32 | AC | 58 ms
8,416 KB |
testcase_33 | AC | 100 ms
8,432 KB |
testcase_34 | AC | 17 ms
6,492 KB |
testcase_35 | AC | 8 ms
6,416 KB |
testcase_36 | AC | 82 ms
8,540 KB |
testcase_37 | AC | 9 ms
6,368 KB |
testcase_38 | AC | 67 ms
8,404 KB |
testcase_39 | AC | 6 ms
6,292 KB |
testcase_40 | AC | 79 ms
8,316 KB |
testcase_41 | AC | 29 ms
8,484 KB |
testcase_42 | AC | 61 ms
8,428 KB |
testcase_43 | AC | 57 ms
8,540 KB |
testcase_44 | AC | 21 ms
6,308 KB |
testcase_45 | AC | 38 ms
8,404 KB |
testcase_46 | AC | 38 ms
8,508 KB |
ソースコード
#include <bits/stdc++.h> #define ADD(a, b) a = (a + ll(b)) % mod #define MUL(a, b) a = (a * ll(b)) % mod #define MAX(a, b) a = max(a, b) #define MIN(a, b) a = min(a, b) #define rep(i, a, b) for(int i = int(a); i < int(b); i++) #define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--) #define all(a) (a).begin(), (a).end() #define sz(v) (int)(v).size() #define pb push_back #define sec second #define fst first #define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef pair<int, pi> ppi; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vl> mat; typedef complex<double> comp; void Debug() {cerr << '\n'; } template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){ cerr<<arg<<" ";Debug(rest...);} template<class T>ostream& operator<<(ostream& out,const vector<T>& v) { out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;} template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){ out<<"("<<v.first<<", "<<v.second<<")";return out;} const int MAX_N = 500010; const int MAX_V = 100010; const double eps = 1e-6; const ll mod = 1000000007; const int inf = (1 << 30) - 1; const ll linf = 1LL << 60; const double PI = 3.14159265358979323846; mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng) /////////////////////////////////////////////////////////////////////////////////////////////////// int N; ll A[MAX_N]; ll S[MAX_N]; int top_bit(int a) { int tmp = 0; while(a) { a /= 2; tmp++; } return tmp; } ll gcd(int a, int b) { // debug(a, b); if(b == 0) return a; else { if(a < b) return gcd(b, a); else { int c = top_bit(a); int d = top_bit(b); return gcd(a ^ (b << (c - d)), b); } } } void solve() { cin >> N; int g = 0; rep(i, 0, N) { cin >> A[i]; int n = A[i]; g = gcd(g, n); for(int j = 1; j * j <= n; j++) { if(n % j == 0) { if(j * j == n) S[j] += n; else { S[j] += n; S[n / j] += n; } } } } ll sum = accumulate(A, A + N, 0ll); ll res = linf; rep(i, 0, N) { MIN(res, (sum - S[A[i]]) + S[A[i]] / A[i]); } int c = top_bit(g); for(int bit = 1; bit < (1 << (18 - c)); bit++) { int tmp = g; int d = 0; rep(i, 0, 18 - c) { if(bit & (1 << i)) d ^= tmp; tmp *= 2; } if(d <= 100000) { MIN(res, (sum - S[d]) + S[d] / d); } } cout << res << "\n"; } uint32_t rd() { uint32_t res; #ifdef __MINGW32__ asm volatile("rdrand %0" :"=a"(res) ::"cc"); #else res = std::random_device()(); #endif return res; } int main() { #ifndef LOCAL ios::sync_with_stdio(false); cin.tie(0); #endif cout << fixed; cout.precision(20); cerr << fixed; cerr.precision(6); rng.seed(rd()); #ifdef LOCAL //freopen("in.txt", "wt", stdout); //for tester if(!freopen("in.txt", "rt", stdin)) return 1; #endif solve(); cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; return 0; }