Submission #1499202
Source Code Expand
#include <bits/stdc++.h>
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
typedef std::vector<long> LI;
typedef std::queue<long> QI;
#define rep(i,n) for(long i = 0; i < (long)n; ++i)
const double pi = M_PI;
const long mod = 1000000007;
template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(long& x) { if( scanf("%ld", &x) < 0 ) exit(0); }
template<> void scan1(std::string& x) { if( not ( std::cin >> x ) ) exit(0); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
scan1(x); scan(xs...);
}
struct Solver {
Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
long n, m;
LI xs, ys;
long memo[2048][2048];
long f(long i, long k) {
if( i < 0 or k < 0 ) return (1LL << 53);
if( memo[i][k] >= 0 ) return memo[i][k];
// dumpll(i, k);
if( k <= 0 ) return 0;
if( i == 0 ) {
if( k == 0 ) return 0;
else if( k == 1 ) return 1;
else return (1LL << 53);
}
if( i < 0 ) return (1LL << 53);
if( i < k ) return (1LL << 53);
// not select
long res = f(i-1, k);
// select
long t = f(i-1, k-1);
// t / ys[i-1] < t + ? / ys[i]
// ys[i] * t / ys[i-1] < (t + ?)
// t * ys[i] / ys[i-1] - t < ?
// t * ys[i] / ys[i-1] - t * ys[i-1] / ys[i-1] < ?
// t * (ys[i] - ys[i-1]) / ys[i-1] < ?
// t * (ys[i] - ys[i-1]) / ys[i-1] + 1
dumpll(i, k);
// long s = (t * (ys[i] - ys[i-1]) + (ys[i-1] - 1)) / ys[i-1];
long s = t * (ys[i] - ys[i-1]) / ys[i-1] + 1;
if( s <= xs[i] ) {
dumpl(s);
res = std::min(res, t + s);
}
return memo[i][k] = res;
}
void solve() {
scan(n, m);
xs.resize(n); for(long &x : xs) scan(x);
for(long i = 0; i < 2048; ++i) {
for(long k = 0; k < 2048; ++k) {
memo[i][k] = -1;
}
}
long t = 0;
ys.resize(n);
for(long i = 0; i < n; ++i) t += xs[i], ys[i] = t;
if( ys[n-1] == m ) {
puts("1");
return;
}
long res = 0;
for(long i = n; i >= 0; --i) {
dumpll(i, f(n-1, i));
if( f(n-1, i) <= m ) {
printf("%ld\n", i);
break;
}
}
}
};
int main() {
loop std::unique_ptr<Solver>(new Solver())->solve();
}
Submission Info
Submission Time |
|
Task |
B - 高橋君ゲーム |
User |
spica314 |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
3173 Byte |
Status |
WA |
Exec Time |
67 ms |
Memory |
33152 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 100 |
Status |
|
|
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 |
10 ms |
33152 KB |
02.txt |
AC |
50 ms |
33152 KB |
03.txt |
AC |
65 ms |
33152 KB |
04.txt |
AC |
10 ms |
33152 KB |
05.txt |
AC |
65 ms |
33152 KB |
06.txt |
AC |
10 ms |
33152 KB |
07.txt |
AC |
10 ms |
33152 KB |
08.txt |
AC |
10 ms |
33152 KB |
09.txt |
AC |
10 ms |
33152 KB |
10.txt |
AC |
64 ms |
33152 KB |
11.txt |
AC |
50 ms |
33152 KB |
12.txt |
AC |
10 ms |
33152 KB |
13.txt |
AC |
52 ms |
33152 KB |
14.txt |
AC |
10 ms |
33152 KB |
15.txt |
AC |
41 ms |
33152 KB |
16.txt |
AC |
10 ms |
33152 KB |
17.txt |
AC |
10 ms |
33152 KB |
18.txt |
AC |
18 ms |
33152 KB |
19.txt |
WA |
10 ms |
33152 KB |
20.txt |
AC |
63 ms |
33152 KB |
21.txt |
AC |
10 ms |
33024 KB |
22.txt |
AC |
10 ms |
33024 KB |
23.txt |
AC |
10 ms |
33152 KB |
24.txt |
AC |
10 ms |
33152 KB |
25.txt |
AC |
10 ms |
33024 KB |
26.txt |
AC |
10 ms |
33024 KB |
27.txt |
AC |
10 ms |
33024 KB |
28.txt |
AC |
10 ms |
33024 KB |
29.txt |
AC |
60 ms |
33152 KB |
30.txt |
AC |
10 ms |
33152 KB |
31.txt |
AC |
19 ms |
33152 KB |
32.txt |
AC |
10 ms |
33152 KB |
33.txt |
AC |
16 ms |
33152 KB |
34.txt |
AC |
64 ms |
33152 KB |
35.txt |
AC |
10 ms |
33152 KB |
36.txt |
AC |
41 ms |
33152 KB |
37.txt |
AC |
10 ms |
33152 KB |
38.txt |
AC |
61 ms |
33152 KB |
39.txt |
AC |
10 ms |
33152 KB |
40.txt |
AC |
67 ms |
33152 KB |
41.txt |
AC |
33 ms |
33152 KB |
42.txt |
AC |
10 ms |
33152 KB |
43.txt |
AC |
58 ms |
33152 KB |
44.txt |
AC |
10 ms |
33152 KB |
45.txt |
AC |
10 ms |
33152 KB |
46.txt |
AC |
10 ms |
33152 KB |
47.txt |
AC |
64 ms |
33152 KB |
48.txt |
AC |
66 ms |
33152 KB |
49.txt |
AC |
66 ms |
33152 KB |
50.txt |
AC |
66 ms |
33152 KB |
51.txt |
AC |
10 ms |
33024 KB |
52.txt |
AC |
10 ms |
33024 KB |
53.txt |
AC |
10 ms |
33024 KB |
54.txt |
AC |
10 ms |
33024 KB |
55.txt |
AC |
10 ms |
33024 KB |
56.txt |
WA |
10 ms |
33024 KB |
57.txt |
AC |
10 ms |
33024 KB |
58.txt |
AC |
10 ms |
33024 KB |
59.txt |
AC |
10 ms |
33024 KB |
60.txt |
AC |
10 ms |
33024 KB |
61.txt |
AC |
10 ms |
33024 KB |
62.txt |
AC |
10 ms |
33024 KB |
63.txt |
AC |
10 ms |
33024 KB |
64.txt |
AC |
10 ms |
33024 KB |
s1.txt |
AC |
10 ms |
33024 KB |
s2.txt |
AC |
10 ms |
33024 KB |
s3.txt |
AC |
10 ms |
33024 KB |
s4.txt |
AC |
10 ms |
33024 KB |