結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー CELICACELICA
提出日時 2020-06-30 20:49:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,143 bytes
コンパイル時間 747 ms
コンパイル使用メモリ 76,380 KB
実行使用メモリ 9,252 KB
最終ジャッジ日時 2023-10-11 10:07:08
合計ジャッジ時間 7,031 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,756 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 AC 1 ms
4,368 KB
testcase_03 AC 1 ms
4,372 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,372 KB
testcase_06 AC 2 ms
4,372 KB
testcase_07 AC 1 ms
4,372 KB
testcase_08 WA -
testcase_09 AC 2 ms
4,380 KB
testcase_10 WA -
testcase_11 AC 2 ms
4,368 KB
testcase_12 WA -
testcase_13 AC 3 ms
4,372 KB
testcase_14 AC 4 ms
4,368 KB
testcase_15 WA -
testcase_16 AC 3 ms
4,372 KB
testcase_17 WA -
testcase_18 AC 4 ms
4,372 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 4 ms
4,372 KB
testcase_23 AC 54 ms
7,612 KB
testcase_24 AC 53 ms
8,204 KB
testcase_25 AC 53 ms
8,060 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 TLE -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    int n;
    scanf("%d", &n);

    vector<pair<long, int>> va;

    for (int i = 0; i < n; ++i)
    {
        long a;
        scanf("%ld", &a);
        va.push_back(make_pair(a, i));
    }

    sort(va.begin(), va.end());

    long tmin{ 300000001 };
    for (int i = 0; i < n - 1; ++i)
    {
        if (va[i].second > n - 2)
            continue;
        for (int j = i + 1; j < n; ++j)
        {
            if (va[i].second > va[j].second)
                continue;
            if (va[i].first + va[j].first > tmin)
                break;
            for (int k = 0; k < j; ++k)
            {
                if (k == i)
                    continue;
                if (va[j].second > va[k].second)
                        continue;
                if (va[i].first + va[j].first + va[k].first > tmin)
                    break;
                tmin = min(va[i].first + va[j].first + va[k].first, tmin);
            }
        }
    }

    if (tmin == 300000001)
        printf("-1\n");
    else
        printf("%ld\n", tmin);

    return 0;
}
0