結果

問題 No.937 Ultra Sword
ユーザー a
提出日時 2019-11-29 23:39:43
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,969 bytes
コンパイル時間 2,038 ms
コンパイル使用メモリ 177,572 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-21 03:02:24
合計ジャッジ時間 3,888 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 7 WA * 40
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'void solve()':
main.cpp:40:12: warning: 'g' may be used uninitialized [-Wmaybe-uninitialized]
   40 |     int n, g;
      |            ^

ソースコード

diff #

//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;
//------------------------------- Libraries --------------------------------//

//------------------------------- Dubug Functions ---------------------------//
inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}
//------------------------------- Solver ------------------------------------//

void solve()
{
    int n, g;
    cin >> n;
    akari<int> as(n), bs;
    for (int i = 0; i < n; i++)
    {
        cin >> as[i];
        if (i == 0)
        {
            g = as[i];
        }
        else
        {
            g = __gcd(g, as[i]);
        }
    }
    bs = as;
    for (int d = 0; d < 20; d++)
    {
        int p = -1;
        for (int i = 0; i < n; i++)
        {
            if (as[i] >> d & 1)
            {
                p = i;
                break;
            }
        }
        if (p == -1)
        {
            continue;
        }
        if (p)
        {
            swap(as[p], as[0]);
        }
        for (int i = 0; i < n; i++)
        {
            if (i == p || !(as[i] >> d & 1))
            {
                continue;
            }
            as[i] ^= as[p];
        }
    }
    int lsb = -1;
    for (int d = 0; d < 20; d++)
        for (int i = 0; i < n; i++)
        {
            //cout << bitset<20>(as[i]) << endl;
            if (as[i] >> d & 1)
            {
                lsb = d;
                i = n;
                d = 20;
            }
        }
    //print(lsb);
    int mask = (1 << lsb) - 1;
    set<int> fs;
    for (int f = 1; f * f <= g; f++)
    {
        if (g % f == 0)
        {
            fs.insert(f);
            if (f * f != g)
            {
                fs.insert(g / f);
            }
        }
    }
    i64 ans = accumulate(bs.begin(), bs.end(), i64(0));
    for (int f : fs)
    {
        if (mask & f)
        {
            continue;
        }
        i64 res = 0;
        for (int i = 0; i < n; i++)
        {
            if (bs[i] % f == 0)
            {
                res += bs[i] / f;
            }
            else
            {
                res += bs[i];
            }
        }
        ans = min(ans, res);
    }
    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}
0