結果

問題 No.937 Ultra Sword
ユーザー aa
提出日時 2019-11-29 23:39:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,969 bytes
コンパイル時間 1,857 ms
コンパイル使用メモリ 175,936 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-01 02:55:09
合計ジャッジ時間 4,039 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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