結果

問題 No.937 Ultra Sword
ユーザー aa
提出日時 2019-11-29 23:36:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,905 bytes
コンパイル時間 2,067 ms
コンパイル使用メモリ 177,324 KB
実行使用メモリ 14,236 KB
最終ジャッジ日時 2024-05-01 02:54:36
合計ジャッジ時間 6,427 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,880 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 1 ms
6,812 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 195 ms
6,940 KB
testcase_06 TLE -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

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;
    cin >> n;
    akari<int> as(n), bs;
    for (int i = 0; i < n; i++)
    {
        cin >> 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 i = 0; i < n; i++)
    {
        for (int f = 1; f * f <= bs[i]; f++)
        {
            if (bs[i] % f == 0)
            {
                fs.insert(f);
                if (f * f != bs[i])
                {
                    fs.insert(bs[i] / f);
                }
            }
        }
    }
    i64 ans = 1e15;
    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