提出 #945459


ソースコード 拡げる

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <numeric>
#include <vector>
#include <queue>

#define ALL(v) (v).begin(),(v).end()
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{␣"; for(auto nth : list){ cout << nth << "␣"; } cout << "}" << endl;

using namespace std;

const int INF = INT_MAX / 3;

int main() {
    int K, T;
    cin >> K >> T;
    vector<int> cakes(T, 0);
    priority_queue<int> que;
    bool flag = false;
    map<int, int> cnt;
    for (int nth = 0; nth < T; ++nth) {
        cin >> cakes[nth];
        cnt[cakes[nth]] += 1;
        if (cnt[cakes[nth]] == T) flag = true;
        que.push(cakes[nth]);
    }

    //sort(ALL(cakes), greater<int>());

    while (que.size() != 1) {
        int c1 = que.top(); que.pop();
        int c2 = que.top(); que.pop();
        int diff = c1 - c2;
        que.push(diff);
    }
    cout << ((flag && T != 1)? 0 : que.top() - 1) << endl;
    return 0;
}

提出情報

提出日時
問題 B - K個のケーキ
ユーザ kengo92i
言語 C++14 (GCC 5.4.1)
得点 200
コード長 1083 Byte
結果 AC
実行時間 2 ms
メモリ 256 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 200 / 200
結果
AC × 3
AC × 10
セット名 テストケース
Sample 0_000.txt, 0_001.txt, 0_002.txt
All 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt
ケース名 結果 実行時間 メモリ
0_000.txt AC 2 ms 256 KiB
0_001.txt AC 2 ms 256 KiB
0_002.txt AC 2 ms 256 KiB
1_003.txt AC 2 ms 256 KiB
1_004.txt AC 2 ms 256 KiB
1_005.txt AC 2 ms 256 KiB
1_006.txt AC 2 ms 256 KiB
1_007.txt AC 2 ms 256 KiB
1_008.txt AC 2 ms 256 KiB
1_009.txt AC 2 ms 256 KiB