結果

問題 No.937 Ultra Sword
ユーザー chocoruskchocorusk
提出日時 2019-11-29 22:23:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,379 bytes
コンパイル時間 966 ms
コンパイル使用メモリ 111,604 KB
実行使用メモリ 13,888 KB
最終ジャッジ日時 2024-05-01 02:32:17
合計ジャッジ時間 5,729 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
10,400 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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