結果

問題 No.1917 LCMST
ユーザー Trí Tâm NguyễnTrí Tâm Nguyễn
提出日時 2024-03-12 23:40:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,916 bytes
コンパイル時間 1,950 ms
コンパイル使用メモリ 173,540 KB
実行使用メモリ 41,392 KB
最終ジャッジ日時 2024-03-12 23:41:04
合計ジャッジ時間 11,456 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,636 KB
testcase_01 AC 4 ms
7,636 KB
testcase_02 AC 4 ms
7,636 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 3 ms
7,636 KB
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 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 174 ms
41,392 KB
testcase_30 AC 196 ms
41,392 KB
testcase_31 AC 174 ms
41,392 KB
testcase_32 AC 173 ms
41,392 KB
testcase_33 AC 171 ms
41,392 KB
testcase_34 AC 94 ms
7,640 KB
testcase_35 AC 95 ms
7,640 KB
testcase_36 AC 99 ms
7,640 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'void solve()':
main.cpp:77:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   77 |     for (auto [w, u, v] : total)
      |               ^

ソースコード

diff #

//Make CSP great again
//Vengeance
#include <bits/stdc++.h>
#define TASK "TESTCODE"
using namespace std;
const int N = 1e6, M = 1e5;
int lab[N + 1];
int last[M + 1];

int FindSet(int u)
{
    return lab[u] < 0 ? u : lab[u] = FindSet(lab[u]);
}
bool unite(int u, int v)
{
    u = FindSet(u);
    v = FindSet(v);
    if (u == v)
    {
        return false;
    }
    if (lab[u] > lab[v])
    {
        swap(u, v);
    }
    lab[u] += lab[v];
    lab[v] = u;
    return true;
}
int rep[M + 1];
int n;
long long res = 0;
void read()
{
    cin >> n;
    for (int i = 1; i <= n; ++ i)
    {
        int a;
        cin >> a;
        lab[i] = -1;
        if (rep[a])
        {   
            res += a;
            unite(rep[a], i);
        }
        rep[a] = i;
    }
}
void solve()
{   
    vector<tuple<long long, int, int> > total;
    for (int i = 1; i <= M; ++ i)
    {   
        for (int j = i; j <= M; j += i)
        {
            if (rep[j])
            {
                last[i] = j;
                break;
            }
        }
    }
    for (int i = 1; i <= M; ++ i)
    {   
        if (!last[i])
        {
            continue;
        }
        for (int j = i; j <= M; j += i)
        {
            if (rep[j])
            {
                total.emplace_back(1LL * last[i] * j/__gcd(last[i], j), last[i], j);
            }
        }
    }
    for (auto [w, u, v] : total)
    {   
        res += 1LL * w * unite(rep[u], rep[v]);
    }
    assert(lab[FindSet(1)] == -n);
    cout << res;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    if (fopen(TASK".INP", "r"))
    {
        freopen(TASK".INP", "r", stdin);
        //freopen(TASK".OUT", "w", stdout);
    }
    int t = 1;
    bool typetest = false;
    if (typetest)
    {
        cin >> t;
    }
    for (int __ = 1; __ <= t; ++ __)
    {
        //cout << "Case " << __ << ": ";
        read();
        solve();
    }
}
0