結果

問題 No.937 Ultra Sword
ユーザー NyaanNyaanNyaanNyaan
提出日時 2019-11-29 23:06:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 6,222 bytes
コンパイル時間 1,846 ms
コンパイル使用メモリ 180,820 KB
実行使用メモリ 5,492 KB
最終ジャッジ日時 2023-08-13 09:10:35
合計ジャッジ時間 9,402 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
4,564 KB
testcase_01 WA -
testcase_02 AC 5 ms
4,580 KB
testcase_03 AC 6 ms
4,604 KB
testcase_04 AC 4 ms
4,560 KB
testcase_05 AC 385 ms
5,428 KB
testcase_06 AC 217 ms
5,172 KB
testcase_07 AC 241 ms
5,084 KB
testcase_08 AC 108 ms
4,888 KB
testcase_09 AC 82 ms
5,016 KB
testcase_10 AC 263 ms
5,492 KB
testcase_11 AC 25 ms
4,624 KB
testcase_12 AC 98 ms
5,436 KB
testcase_13 AC 95 ms
5,100 KB
testcase_14 AC 109 ms
5,428 KB
testcase_15 AC 83 ms
5,108 KB
testcase_16 AC 7 ms
4,820 KB
testcase_17 AC 14 ms
4,644 KB
testcase_18 AC 90 ms
5,160 KB
testcase_19 AC 55 ms
5,068 KB
testcase_20 AC 49 ms
4,836 KB
testcase_21 AC 278 ms
5,432 KB
testcase_22 AC 6 ms
4,560 KB
testcase_23 AC 7 ms
4,644 KB
testcase_24 AC 376 ms
5,428 KB
testcase_25 AC 241 ms
5,368 KB
testcase_26 AC 201 ms
5,168 KB
testcase_27 AC 197 ms
5,084 KB
testcase_28 AC 218 ms
5,084 KB
testcase_29 AC 9 ms
4,700 KB
testcase_30 AC 166 ms
5,180 KB
testcase_31 AC 270 ms
5,436 KB
testcase_32 AC 161 ms
5,164 KB
testcase_33 AC 268 ms
5,444 KB
testcase_34 AC 42 ms
4,644 KB
testcase_35 AC 20 ms
4,644 KB
testcase_36 AC 222 ms
5,164 KB
testcase_37 AC 23 ms
4,636 KB
testcase_38 AC 178 ms
5,108 KB
testcase_39 AC 13 ms
4,556 KB
testcase_40 AC 213 ms
5,164 KB
testcase_41 AC 80 ms
4,968 KB
testcase_42 AC 165 ms
5,088 KB
testcase_43 AC 148 ms
4,948 KB
testcase_44 AC 52 ms
4,560 KB
testcase_45 AC 96 ms
4,820 KB
testcase_46 AC 100 ms
4,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(int i = (N) - 1; i >= 0; i--)
#define rep1(i,N) for(int i = 1; i <= (N) ; i++)
#define repr1(i,N) for(int i = (N) ; i > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; using vl = vector<ll>;
using vi = vector<int>; using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif
using P = pair<int,int>; using vp = vector<P>;
constexpr int MOD = /** 1000000007; //*/ 998244353;
//////////


// 素数判定 O( sqrt(N) log log N )
// 0からNに対して素数->1、それ以外->0の配列を返す関数
vector<int> Primes(int N){
  vector<int> A(N + 1 , 1);
  A[0] = A[1] = 0;
  for(int i = 2; i * i <= N ; i++) 
    if(A[i]==1) for(int j = i << 1 ; j <= N; j += i) A[j] = 0;
  return A;
}

// 因数 O( sqrt(N) log log N )
// 0からNに対して素数->1、それ以外->最小の素数である因数、の配列を返す
vector<int> Factors(int N){
  vector<int> A(N + 1 , 1);
  A[0] = A[1] = 0;
  for(int i = 2; i * i <= N ; i++) 
    if(A[i]==1) for(int j = i << 1 ; j <= N; j += i) A[j] = i;
  return A;
}

// オイラーのトーシェント関数 φ(N)=(Nと互いに素なN以下の自然数の個数)
vector<int> EulersTotientFunction(int N){
  vector<int> ret(N + 1 , 0);
  for(int i = 0; i <= N ; i++) ret[i] = i; 
  for(int i = 2 ; i <= N ; i++){
    if(ret[i] == i)
      for(int j = i; j <= N; j += i) ret[j] = ret[j] / i * (i - 1);
  }
  return ret;
}

// 約数列挙 O(sqrt(N))
// Nの約数を列挙した配列を返す
vector<long long> Divisor(long long N){
  vector<long long> v;
  for(long long i = 1; i * i <= N ; i++){
    if(N % i == 0){
      v.push_back(i);
      if(i * i != N) v.push_back(N / i);
    }
  }
  return v;
}

// 素因数分解
// 因数をkey、そのべきをvalueとするmapを返す
// ex) N=12 -> m={ (2,2) , (3,1) }
map<long long,int> PrimeFactors(long long N){
  map<long long,int> m;
  for(long long i=2; i * i <= N; i++)
    while(N % i == 0) m[i]++ , N /= i;
  if(N != 1) m[N]++;
  return m;
}

// 原始根 modでrが原始根かどうかを調べる
bool PrimitiveRoot(long long r , long long mod){
  r %= mod; if(r == 0) return false;
  auto modpow = [](long long a,long long b,long long m)->long long{
    a %= m; long long ret = 1;
    while(b){
      if(b & 1) ret = a * ret % m;
      a = a * a % m;
      b >>= 1;
    }
    return ret;
  };
  map<long long,int> m = PrimeFactors(mod - 1);
  each(x , m){
    if(modpow(r , (mod - 1) / x.fi , mod ) == 1) return false;
  }
  return true;
}

// 拡張ユークリッド ax+by=gcd(a,b)の解
// 返り値 最大公約数
long long extgcd(long long a,long long b, long long &x, long long &y){
  if(b == 0){
    x = 1; y = 0; return a;
  }
  long long d = extgcd(b , a%b , y , x);
  y -= a / b * x;
  return d;
}

// ブール代数ライブラリ
// Point. 乗法の単位元は-1 (UNIT & a = aを満たすUNITであるため)
struct BA{
  unsigned long long x;
  BA(): x(0){}
  BA(unsigned long long y):x(y){}
  
  BA operator += (const BA &p){
    x = x ^ p.x;
    return (*this);
  }
  BA operator *= (const BA &p){
    x = x & p.x;
    return (*this);
  }

  BA operator+(const BA &p)const {return BA(*this) += p;}
  BA operator*(const BA &p)const {return BA(*this) *= p;}
  bool operator==(const BA &p) const { return x == p.x; }
  bool operator!=(const BA &p) const { return x != p.x; }

  friend ostream &operator<<(ostream &os,const BA &p){
    return os << p.x;
  }
  friend istream &operator>>(istream &is, BA &a){
    unsigned int t;
    is >> t;
    a = BA(t);
    return (is);
  }
};


void solve(){
  ini(N);
  vl v(N); in(v);
  vl sum(131073 , 0);
  vi ok(131072 , 0);
  rep(i , N){
    auto d = Divisor(v[i]);
    each(x , d) sum[x] += v[i]; 
    int x = v[i];
    while(x <= 131071) { ok[x] = 1; x <<= 1;}
  }
  vi vec;
  rep1(i , 131071){
    if(ok[i] == 0) continue;
    int b = i;
    each(x , vec){
      int n = b ^ x;
      if(x > n) swap(x , n);
      if(b > x) swap(b , x);
      if(x > n) swap(x , n);
     }
    if(b != 0) vec.pb(b);
  }
  assert(vec.size() <= 17);
  trc(vec);
  ll ans = sum[1];
  for(int i = 1 ; i <= 131072 ; i++){
    int b = i;
    // hantei
    each(x , vec) b = min(b , x ^ b);
    if(b != 0) continue;
    amin(ans , sum[i] / i + (sum[1] - sum[i]));
  }
  out(ans);

}
0