結果

問題 No.937 Ultra Sword
ユーザー chocoruskchocorusk
提出日時 2019-11-29 22:26:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 3,000 ms
コード長 1,379 bytes
コンパイル時間 1,012 ms
コンパイル使用メモリ 111,728 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 02:33:18
合計ジャッジ時間 3,134 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,812 KB
testcase_01 AC 7 ms
6,944 KB
testcase_02 AC 4 ms
6,940 KB
testcase_03 AC 4 ms
6,944 KB
testcase_04 AC 3 ms
6,944 KB
testcase_05 AC 31 ms
6,944 KB
testcase_06 AC 41 ms
6,940 KB
testcase_07 AC 45 ms
6,940 KB
testcase_08 AC 23 ms
6,944 KB
testcase_09 AC 19 ms
6,944 KB
testcase_10 AC 49 ms
6,940 KB
testcase_11 AC 13 ms
6,944 KB
testcase_12 AC 41 ms
6,940 KB
testcase_13 AC 39 ms
6,940 KB
testcase_14 AC 44 ms
6,944 KB
testcase_15 AC 35 ms
6,944 KB
testcase_16 AC 8 ms
6,940 KB
testcase_17 AC 9 ms
6,940 KB
testcase_18 AC 37 ms
6,940 KB
testcase_19 AC 24 ms
6,940 KB
testcase_20 AC 22 ms
6,944 KB
testcase_21 AC 49 ms
6,944 KB
testcase_22 AC 4 ms
6,944 KB
testcase_23 AC 8 ms
6,940 KB
testcase_24 AC 38 ms
6,944 KB
testcase_25 AC 31 ms
6,944 KB
testcase_26 AC 29 ms
6,944 KB
testcase_27 AC 26 ms
6,944 KB
testcase_28 AC 31 ms
6,944 KB
testcase_29 AC 3 ms
6,944 KB
testcase_30 AC 23 ms
6,944 KB
testcase_31 AC 34 ms
6,940 KB
testcase_32 AC 20 ms
6,944 KB
testcase_33 AC 35 ms
6,940 KB
testcase_34 AC 8 ms
6,940 KB
testcase_35 AC 4 ms
6,940 KB
testcase_36 AC 29 ms
6,940 KB
testcase_37 AC 5 ms
6,940 KB
testcase_38 AC 23 ms
6,944 KB
testcase_39 AC 4 ms
6,940 KB
testcase_40 AC 27 ms
6,940 KB
testcase_41 AC 12 ms
6,940 KB
testcase_42 AC 21 ms
6,944 KB
testcase_43 AC 19 ms
6,940 KB
testcase_44 AC 9 ms
6,944 KB
testcase_45 AC 15 ms
6,940 KB
testcase_46 AC 17 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int gcd(int, int)':
main.cpp:44:19: warning: 'ib' may be used uninitialized [-Wmaybe-uninitialized]
   44 |         b^=(a<<(ib-ia));
      |                ~~~^~~~
main.cpp:31:17: note: 'ib' was declared here
   31 |         int ia, ib;
      |                 ^~
main.cpp:44:19: warning: 'ia' may be used uninitialized [-Wmaybe-uninitialized]
   44 |         b^=(a<<(ib-ia));
      |                ~~~^~~~
main.cpp:31:13: note: 'ia' was declared here
   31 |         int ia, ib;
      |             ^~

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int gcd(int a, int b){
	if(a>b) swap(a, b);
	if(a==0) return b;
	int ia, ib;
	for(int i=16; i>=0; i--){
		if(a&(1<<i)){
			ia=i;
			break;
		}
	}
	for(int i=16; i>=0; i--){
		if(b&(1<<i)){
			ib=i;
			break;
		}
	}
	b^=(a<<(ib-ia));
	return gcd(a, b);
}
int main()
{
	int n;
	cin>>n;
	int c[100010]={};
	int a[100010];
	for(int i=0; i<n; i++){
		cin>>a[i];
		c[a[i]]++;
	}
	int g=a[0];
	for(int i=1; i<n; i++){
		g=gcd(g, a[i]);
	}
	int ig=0;
	for(int i=16; i>=0; i--){
		if(g&(1<<i)){
			ig=i;
			break;
		}
	}
	ll ans=0;
	for(int i=0; i<n; i++) ans+=a[i];
	ll sum0=ans;
	for(int d=1; d<=100000; d++){
		int x=d;
		for(int i=16; i>=ig; i--){
			if(x&(1<<i)){
				x^=(g<<(i-ig));
			}
		}
		if(x) continue;
		ll sum=sum0;
		for(int i=d; i<=100000; i+=d){
			sum-=(ll)c[i]*(i-i/d);
		}
		ans=min(ans, sum);
	}
	cout<<ans<<endl;
	return 0;
}
0