結果

問題 No.929 よくあるボールを移動するやつ
ユーザー yk356yk356
提出日時 2019-11-22 23:02:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 836 bytes
コンパイル時間 1,921 ms
コンパイル使用メモリ 168,772 KB
実行使用メモリ 13,888 KB
最終ジャッジ日時 2024-04-19 12:22:12
合計ジャッジ時間 6,114 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
13,888 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<pair<int,int>> cnt;
    vector<int> flag;
    for(int i = 0; i < N; i++)
    {
        int b;
        scanf("%d", &b);
        if(b == 0) flag.push_back(i);
        else if(b >= 1) cnt.push_back(make_pair(i, b-1));
    }

    long long ans = 0;
    for(int i = 0; i < flag.size(); i++)
    {
        int idx = flag[i];
        int jdx = 0;
        int minv = 1e8;
        for(int j = 0; j < cnt.size(); j++)
        {
            int c1 = cnt[j].first;
            int c2 = cnt[j].second;
            if(abs(idx-j) < minv && c2 > 0)
            {
                jdx = j;
                minv = abs(idx-j);
            }
        }
        cnt[jdx].second -= 1;
        ans += (long long)minv;
    }

    cout << ans << endl;
    return 0;
}
0