提出 #61516589


ソースコード 拡げる

/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#ifdef EMT
#include "Header/stdc++.h"
#else
#include <bits/stdc++.h>
#endif
using namespace std;

#ifdef EMT
#define debug(x) cerr << "\e[1;31m" << #x << " = " << (x) << "\e[0m\n"
#define print(x) emilia_mata_tenshi(#x, begin(x), end(x))
template<typename T, typename T2> ostream& operator<<(ostream &os, const pair<T, T2> &obj) {
    return os << '{' << obj.first << ',' << obj.second << '}';
}
template<class TupType, size_t... I> void lamy_kawaii(ostream& os, const TupType& _tup, index_sequence<I...>) {
    // source: https://stackoverflow.com/a/41171552
    os << '{';
    (..., (cerr << (I == 0? "" : ",") << get<I>(_tup)));
    os << '}';
}
template<class... T> ostream& operator<<(ostream &os, const tuple<T...>& _tup) {
    lamy_kawaii(os, _tup, make_index_sequence<sizeof...(T)>());
    return os;
}
template<typename T> void emilia_mata_tenshi(const char *s, T l, T r) {
    cerr << "\e[1;33m" << s << " = [";
    while (l != r) {
        cerr << *l;
        cerr << (++l == r ? ']' : ',');
    }
    cerr << "\e[0m\n";
}
#else
#define debug(x) 48763
#define print(x) 48763
#endif

template<typename T, typename T2> istream& operator>>(istream &is, pair<T, T2> &obj) {
    is >> obj.first >> obj.second;
    return is;
}
template<typename T> istream& operator>>(istream &is, vector<T> &obj) {
    for (auto &x : obj)
        is >> x;
    return is;
}

#define YN(x) ((x) ? "YES" : "NO")
#define Yn(x) ((x) ? "Yes" : "No")
#define yn(x) ((x) ? "yes" : "no")
#define emilia_my_wife ios::sync_with_stdio(0); cin.tie(NULL);
using ll = int64_t;
using ull = uint64_t;
using ld = long double;
using uint = uint32_t;
template<typename T>
using base_type = remove_cv_t<remove_reference_t<T>>;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
static int Lamy_is_cute = []() {
    emilia_my_wife
    return 48763;
}();
/*--------------------------------------------------------------------------------------*/

signed main() {
    int n, m;
    cin >> n >> m;
    vector<pair<ull, ull>> arr(m);
    for (int i = 0; i < m; i++)
        cin >> arr[i].first;
    for (int i = 0; i < m; i++) {
        cin >> arr[i].second;
        arr[i].second--;
    }
    arr.push_back({n + 1, 0});
    sort(arr.begin(), arr.end());

    ull ans = 0;
    ull prv = 0;
    stack<pair<ull, ull>> remaining;
    for (const auto &[x, a] : arr) {
        ull nd = x - prv - 1;
        if (nd > 0) {
            ans += (prv + 1 + x - 1) * nd / 2;
        }
        while (nd > 0) {
            if (remaining.empty()) {
                cout << "-1\n";
                return 0;
            }
            ull w = min(remaining.top().second, nd);
            nd -= w;
            remaining.top().second -= w;
            ans -= w * remaining.top().first;
            if (remaining.top().second == 0)
                remaining.pop();
        }
        remaining.push({x, a});
        prv = x;
    }
    while (!remaining.empty() && remaining.top().second == 0)
        remaining.pop();
    if (!remaining.empty())
        cout << "-1\n";
    else
        cout << ans << '\n';
}

提出情報

提出日時
問題 C - Sowing Stones
ユーザ JiKuai
言語 C++ 20 (gcc 12.2)
得点 300
コード長 3792 Byte
結果 AC
実行時間 38 ms
メモリ 9588 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 300 / 300
結果
AC × 2
AC × 43
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 02_hand_00.txt, 02_hand_01.txt, 02_hand_02.txt, 02_hand_03.txt, 02_hand_04.txt, 02_hand_05.txt, 02_hand_06.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3476 KiB
00_sample_01.txt AC 1 ms 3604 KiB
01_random_00.txt AC 23 ms 7292 KiB
01_random_01.txt AC 23 ms 7136 KiB
01_random_02.txt AC 32 ms 9216 KiB
01_random_03.txt AC 23 ms 7268 KiB
01_random_04.txt AC 20 ms 6876 KiB
01_random_05.txt AC 23 ms 7824 KiB
01_random_06.txt AC 29 ms 8524 KiB
01_random_07.txt AC 26 ms 8060 KiB
01_random_08.txt AC 30 ms 8792 KiB
01_random_09.txt AC 33 ms 9068 KiB
01_random_10.txt AC 16 ms 6052 KiB
01_random_11.txt AC 20 ms 6764 KiB
01_random_12.txt AC 13 ms 5500 KiB
01_random_13.txt AC 14 ms 5680 KiB
01_random_14.txt AC 15 ms 5624 KiB
01_random_15.txt AC 18 ms 6488 KiB
01_random_16.txt AC 38 ms 8848 KiB
01_random_17.txt AC 27 ms 7296 KiB
01_random_18.txt AC 10 ms 4500 KiB
01_random_19.txt AC 20 ms 6156 KiB
01_random_20.txt AC 37 ms 9440 KiB
01_random_21.txt AC 36 ms 9492 KiB
01_random_22.txt AC 36 ms 9480 KiB
01_random_23.txt AC 37 ms 9516 KiB
01_random_24.txt AC 37 ms 9432 KiB
01_random_25.txt AC 36 ms 9448 KiB
01_random_26.txt AC 36 ms 9588 KiB
01_random_27.txt AC 36 ms 9356 KiB
01_random_28.txt AC 1 ms 3420 KiB
01_random_29.txt AC 1 ms 3332 KiB
01_random_30.txt AC 1 ms 3608 KiB
01_random_31.txt AC 1 ms 3532 KiB
01_random_32.txt AC 1 ms 3480 KiB
01_random_33.txt AC 1 ms 3536 KiB
02_hand_00.txt AC 34 ms 8616 KiB
02_hand_01.txt AC 26 ms 6712 KiB
02_hand_02.txt AC 16 ms 6292 KiB
02_hand_03.txt AC 11 ms 5248 KiB
02_hand_04.txt AC 1 ms 3604 KiB
02_hand_05.txt AC 1 ms 3376 KiB
02_hand_06.txt AC 35 ms 9360 KiB