Submission #2554782


Source Code Expand

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <functional>
#include <queue>
#include <tuple>
#include <map>

using namespace std;

using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vb = vector<char>;
using vvb = vector<vb>;
using vd = vector<double>;
using vvd = vector<vd>;

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) {
    for (auto &e:t) fill_v(e, v);
}

#define REP(i, a, b) for (int i = a; i < (int)(b); i++)
#define RREP(i, a, b) for (int i = (int)(b) - 1; i >= a; i--)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define mp(a, b) make_pair(a,b)

#define fi first
#define sn second
#define decpii(p) p.fi--,p.sn--;


#ifdef LOCAL
#define dump(c) cerr << "> " << #c << " = " << (c) << endl;
#define dumpn(c) cerr << "> " << #c << " = " << (c) << ", ";
#else
#define dump(c) ;
#define dumpn(c) ;
#endif


template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &a) {
    os << '[';
    rep(i, (int) a.size())os << (i ? " " : "") << a[i];
    return os << ']';
}


const int INF = 1 << 29;
const ll LINF = 1ll << 60;
const int MOD = 1000000007;

int dxf[] = {1, 0, -1, 0};
int dyf[] = {0, -1, 0, 1};

template<class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

inline vi uni(vi &vec) {
    sort(vec.begin(), vec.end());
    vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

struct ____ {
    ____() {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
    };
} ________;


auto solve() {
    int N, K;
    cin >> N >> K;
    vi a(N);
    rep(i, N) cin >> a[i];
    vll total(N + 1, 0);
    REP(i, 1, N + 1)total[i] = total[i - 1] + a[i - 1];

    if (K ==  accumulate(all(a), 0ll)) return 1;

    vvll dp(N + 1, vll(N + 1, LINF));
    dp[0][0] = 0;
    rep(i, N) {
        dump(i);
        rep(j, N + 1) {
            if (dp[i][j] == LINF) continue;
            chmin(dp[i + 1][j], dp[i][j]);
            double prev = 0.0;
            if (total[i] != 0)
                prev = (double) dp[i][j] / total[i];

            ll need = prev * total[i + 1];
            if ((double) need / total[i + 1] <= prev)
                need++;

            dumpn(j);
            dumpn(prev);
            dumpn(dp[i][j]);
            dumpn(total[i]);
            dumpn(need);
            dumpn(total[i + 1]);

            if (need <= K && need <= total[i + 1]) {
                chmin(dp[i + 1][j + 1], need);
                dump("OK")
            } else {
                dump("NG")
            }
        }
        dump(dp[i]);
    }

    rrep(i, N + 1) if (dp[N][i] != LINF) return i;
    return 0;
}


int main() {
//    cout << (solve() ? "yes" : "no") << endl;
    cout << solve() << endl;
//    solve();
    return 0;
}

Submission Info

Submission Time
Task B - 高橋君ゲーム
User palpal
Language C++14 (GCC 5.4.1)
Score 100
Code Size 4042 Byte
Status AC
Exec Time 37 ms
Memory 31744 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 4
AC × 68
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt, s4.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, 47.txt, 48.txt, 49.txt, 50.txt, 51.txt, 52.txt, 53.txt, 54.txt, 55.txt, 56.txt, 57.txt, 58.txt, 59.txt, 60.txt, 61.txt, 62.txt, 63.txt, 64.txt, s1.txt, s2.txt, s3.txt, s4.txt
Case Name Status Exec Time Memory
01.txt AC 36 ms 31616 KB
02.txt AC 32 ms 31616 KB
03.txt AC 21 ms 31616 KB
04.txt AC 37 ms 31488 KB
05.txt AC 22 ms 31488 KB
06.txt AC 36 ms 31488 KB
07.txt AC 37 ms 31616 KB
08.txt AC 37 ms 31616 KB
09.txt AC 36 ms 31616 KB
10.txt AC 22 ms 31616 KB
11.txt AC 32 ms 31488 KB
12.txt AC 36 ms 31488 KB
13.txt AC 29 ms 31488 KB
14.txt AC 37 ms 31616 KB
15.txt AC 32 ms 31616 KB
16.txt AC 37 ms 31616 KB
17.txt AC 37 ms 31616 KB
18.txt AC 36 ms 31488 KB
19.txt AC 37 ms 31488 KB
20.txt AC 25 ms 31488 KB
21.txt AC 1 ms 256 KB
22.txt AC 1 ms 256 KB
23.txt AC 36 ms 31616 KB
24.txt AC 37 ms 31616 KB
25.txt AC 1 ms 256 KB
26.txt AC 1 ms 256 KB
27.txt AC 1 ms 256 KB
28.txt AC 1 ms 256 KB
29.txt AC 27 ms 31616 KB
30.txt AC 37 ms 31616 KB
31.txt AC 35 ms 31616 KB
32.txt AC 36 ms 31488 KB
33.txt AC 35 ms 31488 KB
34.txt AC 23 ms 31488 KB
35.txt AC 37 ms 31616 KB
36.txt AC 35 ms 31744 KB
37.txt AC 37 ms 31616 KB
38.txt AC 26 ms 31616 KB
39.txt AC 36 ms 31488 KB
40.txt AC 22 ms 31488 KB
41.txt AC 35 ms 31488 KB
42.txt AC 36 ms 31616 KB
43.txt AC 29 ms 31616 KB
44.txt AC 36 ms 31616 KB
45.txt AC 36 ms 31616 KB
46.txt AC 36 ms 31488 KB
47.txt AC 20 ms 31488 KB
48.txt AC 20 ms 31488 KB
49.txt AC 20 ms 31616 KB
50.txt AC 20 ms 31616 KB
51.txt AC 1 ms 256 KB
52.txt AC 1 ms 256 KB
53.txt AC 1 ms 256 KB
54.txt AC 1 ms 256 KB
55.txt AC 1 ms 256 KB
56.txt AC 1 ms 256 KB
57.txt AC 1 ms 256 KB
58.txt AC 1 ms 256 KB
59.txt AC 1 ms 256 KB
60.txt AC 1 ms 256 KB
61.txt AC 1 ms 256 KB
62.txt AC 1 ms 256 KB
63.txt AC 1 ms 256 KB
64.txt AC 1 ms 256 KB
s1.txt AC 1 ms 256 KB
s2.txt AC 1 ms 256 KB
s3.txt AC 1 ms 256 KB
s4.txt AC 1 ms 256 KB