結果

問題 No.937 Ultra Sword
ユーザー polylogKpolylogK
提出日時 2019-11-29 22:35:21
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,929 bytes
コンパイル時間 1,686 ms
コンパイル使用メモリ 169,328 KB
実行使用メモリ 6,352 KB
最終ジャッジ日時 2023-08-13 09:02:06
合計ジャッジ時間 4,949 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
5,968 KB
testcase_01 WA -
testcase_02 AC 23 ms
6,256 KB
testcase_03 AC 23 ms
5,960 KB
testcase_04 AC 23 ms
5,976 KB
testcase_05 AC 34 ms
6,172 KB
testcase_06 AC 32 ms
6,240 KB
testcase_07 AC 33 ms
6,336 KB
testcase_08 AC 27 ms
5,976 KB
testcase_09 AC 27 ms
5,908 KB
testcase_10 AC 34 ms
6,336 KB
testcase_11 AC 25 ms
6,052 KB
testcase_12 AC 32 ms
6,332 KB
testcase_13 AC 32 ms
6,224 KB
testcase_14 AC 34 ms
6,340 KB
testcase_15 AC 31 ms
6,172 KB
testcase_16 AC 23 ms
6,064 KB
testcase_17 AC 24 ms
5,912 KB
testcase_18 AC 32 ms
6,228 KB
testcase_19 AC 28 ms
6,024 KB
testcase_20 AC 27 ms
5,908 KB
testcase_21 AC 34 ms
6,348 KB
testcase_22 AC 24 ms
6,068 KB
testcase_23 AC 23 ms
5,916 KB
testcase_24 AC 34 ms
6,260 KB
testcase_25 AC 33 ms
6,348 KB
testcase_26 AC 31 ms
6,176 KB
testcase_27 AC 31 ms
6,284 KB
testcase_28 AC 32 ms
6,240 KB
testcase_29 AC 23 ms
6,024 KB
testcase_30 AC 30 ms
6,336 KB
testcase_31 AC 34 ms
6,252 KB
testcase_32 AC 30 ms
6,236 KB
testcase_33 AC 35 ms
6,352 KB
testcase_34 AC 25 ms
5,992 KB
testcase_35 AC 24 ms
6,248 KB
testcase_36 AC 33 ms
6,180 KB
testcase_37 AC 24 ms
5,908 KB
testcase_38 AC 30 ms
6,224 KB
testcase_39 AC 23 ms
6,020 KB
testcase_40 AC 32 ms
6,172 KB
testcase_41 AC 26 ms
6,056 KB
testcase_42 AC 30 ms
6,176 KB
testcase_43 AC 29 ms
6,224 KB
testcase_44 AC 25 ms
6,076 KB
testcase_45 AC 27 ms
6,084 KB
testcase_46 AC 27 ms
6,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

using namespace std;
template <typename T>
void fwt(vector<T>& f) {
    int n = f.size();
    for (int i = 1; i < n; i <<= 1) {
        for (int j = 0; j < n; j++) {
            if ((j & i) == 0) {
                T x = f[j], y = f[j | i];
                f[j] = x + y, f[j | i] = x - y;
            }
        }
    }
}
template <typename T>
void ifwt(vector<T>& f) {
    int n = f.size();
    for (int i = 1; i < n; i <<= 1) {
        for (int j = 0; j < n; j++) {
            if ((j & i) == 0) {
                T x = f[j], y = f[j | i];
                f[j] = (x + y) / 2, f[j | i] = (x - y) / 2;
            }
        }
    }
}

int main() {
	int n; scanf("%d", &n); std::vector<int> a(n);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);

	// pre
	std::vector<i64> vec(1e5 + 1, 0);
	for(int i = 0; i < n; i++) vec[a[i]]++;

	// solve
	std::vector<i64> p(1 << 17, 1LL << 60);
	{ // p[k] := k にうるとらそーどを使った時の和
		i64 sum = 0;
		for(i64 i = 1; i < vec.size(); i++) sum += vec[i] * i;
		for(i64 i = 1; i < vec.size(); i++) {
			p[i] = sum;
			for(i64 j = i; j < vec.size(); j += i) p[i] -= vec[j] * (j - j / i);
		}
	}

	std::vector<i64> dp(1 << 17, 0); dp[0] = 1;
	for(int i = 0; i < n; i++) {
		int tmp = a[i];
		while(tmp < dp.size()) {
			dp[tmp] = 1;
			tmp <<= 1;
		}
	}
	fwt(dp);
	for(int i = 0; i < dp.size(); i++) dp[i] = dp[i] * dp[i];
	ifwt(dp);
	
	i64 ans = 1LL << 60;
	for(int i = 1; i < dp.size(); i++) {
		if(dp[i]) {
			ans = std::min(ans, p[i]);
		}
	}
	printf("%lld\n", ans);
	return 0;
}
0