Submission #994392
Source Code Expand
#include<iostream> #include<iomanip> #include<map> #include<unordered_map> #include<set> #include<unordered_set> #include<vector> #include<array> #include<string> #include<stack> #include<queue> #include<algorithm> #include<cassert> #include<functional> #include<random> #include<complex> #include<bitset> #include<chrono> //#include<boost/multiprecision/cpp_int.hpp> #define int int64_t #define uint uint64_t #define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++) #define rep(i, a) REP(i, 0, a) #define EACH(i, a) for (auto i: a) #define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++) #define ALL(a) (a.begin()), (a.end()) #define HAS(a, x) (a.find(x) != a.end()) #define Min(x) *min_element(ALL(x)) #define Max(x) *max_element(ALL(x)) #define Unique(L) (L.erase(unique(ALL(L)), L.end())) #define veccat(v1, v2) std::copy((v2).begin(),(v2).end(),std::back_inserter(v1)/*v1の後ろにv2を入れる*/) #define intmax (std::numeric_limits<int64_t>::max() / 4) using namespace std; //typedef boost::multiprecision::cpp_int bigint; const double EPS = 1e-9; const double PI = acos(-1.0); class segtree_max_pointupdate { private: typedef int T; public: segtree_max_pointupdate(const int N) { SIZE = roundup_pow2(N); v.clear(); v.resize(SIZE * 2, -INF); } //v[index]=numberとする。 void update(const int index, const T number) { v[index + SIZE] = number; for (int i = (index + SIZE) / 2; i; i = i / 2)v[i] = max(v[i * 2], v[i * 2 + 1]); } //[index]の値を返す。 T getnum(const int index) { return v[index + SIZE]; } //[L,R)の最大値を返す。 T getmax(const int L, const int R) { return getmax_inner(L, R, 1, 0, SIZE); } private: T getmax_inner(const int queryL, const int queryR, const int index, const int segL, const int segR) { if (queryR <= segL || segR <= queryL)return -INF; if (queryL <= segL && segR <= queryR)return v[index]; return max(getmax_inner(queryL, queryR, index * 2, segL, (segL + segR) / 2), getmax_inner(queryL, queryR, index * 2 + 1, (segL + segR) / 2, segR)); } //x以上であるような2のべき乗数のうち最小のものを返す。 int roundup_pow2(int x) { x--; rep(i, 6)x |= x >> (1LL << i); return x + 1; } int SIZE; vector<T>v; const static T INF = 99999999; }; int N, A; segtree_max_pointupdate memo(1000001); int solve(const int speed, const int time, const int ub) { //現在time秒目で、1秒間にspeed枚焼けて、手持ちゼロであるときの //手持ちN枚にできる最短の時刻を求めて返す。 //ただし時刻ub以降については考えない。 if (ub <= time)return ub; int maxspeed = memo.getmax(0, time + 1); if (speed <= maxspeed)return ub; memo.update(time, speed); const int hold_ans = time + (N + speed - 1) / speed; if (hold_ans <= time + 2 + A)return hold_ans; int best_ans = hold_ans; int next_ub = min(ub, hold_ans); int next_time = time + 1; for (int i = speed * 2; i < N; i += speed) { next_time++; if (best_ans <= next_time + A)break; int ans = solve(i, next_time + A, next_ub); best_ans = min(best_ans, ans); next_ub = min(ub, best_ans); } return best_ans; } signed main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N >> A; assert(N <= 1000000 && A <= 1000000); int ans = solve(1, 0, intmax); cout << ans << endl; }
Submission Info
Submission Time | |
---|---|
Task | E - Cookies |
User | eukaryo |
Language | C++14 (GCC 5.4.1) |
Score | 500 |
Code Size | 3469 Byte |
Status | RE |
Exec Time | 140 ms |
Memory | 16768 KB |
Judge Result
Set Name | sample | dataset1 | dataset2 | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 500 / 500 | 0 / 500 | ||||||||||
Status |
|
|
|
Set Name | Test Cases |
---|---|
sample | sample-01.txt, sample-02.txt, sample-03.txt |
dataset1 | sample-01.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt |
dataset2 | sample-01.txt, sample-02.txt, sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 02-11.txt, 02-12.txt, 02-13.txt, 02-14.txt, 02-15.txt, 02-16.txt, 02-17.txt, 02-18.txt, 02-19.txt, 02-20.txt, 02-21.txt, 02-22.txt, 02-23.txt, 02-24.txt, 02-25.txt, 02-26.txt, 02-27.txt, 02-28.txt, 02-29.txt, 02-30.txt, 02-31.txt, 02-32.txt, 02-33.txt, 02-34.txt, 02-35.txt, 02-36.txt, 02-37.txt, 02-38.txt, 02-39.txt, 02-40.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01-01.txt | AC | 24 ms | 16640 KB |
01-02.txt | AC | 24 ms | 16640 KB |
01-03.txt | AC | 25 ms | 16640 KB |
01-04.txt | AC | 27 ms | 16640 KB |
01-05.txt | AC | 28 ms | 16640 KB |
01-06.txt | AC | 30 ms | 16640 KB |
01-07.txt | AC | 40 ms | 16640 KB |
01-08.txt | AC | 55 ms | 16640 KB |
01-09.txt | AC | 79 ms | 16640 KB |
01-10.txt | AC | 76 ms | 16640 KB |
01-11.txt | AC | 76 ms | 16640 KB |
01-12.txt | AC | 24 ms | 16640 KB |
01-13.txt | AC | 23 ms | 16640 KB |
01-14.txt | AC | 24 ms | 16640 KB |
01-15.txt | AC | 24 ms | 16640 KB |
01-16.txt | AC | 24 ms | 16640 KB |
01-17.txt | AC | 38 ms | 16640 KB |
01-18.txt | AC | 23 ms | 16640 KB |
01-19.txt | AC | 23 ms | 16640 KB |
01-20.txt | AC | 24 ms | 16640 KB |
01-21.txt | AC | 23 ms | 16640 KB |
01-22.txt | AC | 23 ms | 16640 KB |
01-23.txt | AC | 23 ms | 16640 KB |
01-24.txt | AC | 23 ms | 16640 KB |
01-25.txt | AC | 24 ms | 16640 KB |
01-26.txt | AC | 23 ms | 16640 KB |
02-01.txt | RE | 137 ms | 16640 KB |
02-02.txt | RE | 138 ms | 16640 KB |
02-03.txt | RE | 138 ms | 16640 KB |
02-04.txt | RE | 136 ms | 16640 KB |
02-05.txt | RE | 134 ms | 16640 KB |
02-06.txt | RE | 135 ms | 16768 KB |
02-07.txt | RE | 137 ms | 16640 KB |
02-08.txt | RE | 135 ms | 16640 KB |
02-09.txt | RE | 134 ms | 16640 KB |
02-10.txt | RE | 136 ms | 16640 KB |
02-11.txt | RE | 135 ms | 16640 KB |
02-12.txt | RE | 137 ms | 16640 KB |
02-13.txt | RE | 135 ms | 16640 KB |
02-14.txt | RE | 135 ms | 16640 KB |
02-15.txt | RE | 138 ms | 16640 KB |
02-16.txt | RE | 137 ms | 16640 KB |
02-17.txt | RE | 134 ms | 16640 KB |
02-18.txt | RE | 138 ms | 16640 KB |
02-19.txt | RE | 137 ms | 16640 KB |
02-20.txt | RE | 137 ms | 16640 KB |
02-21.txt | RE | 136 ms | 16640 KB |
02-22.txt | RE | 135 ms | 16640 KB |
02-23.txt | RE | 137 ms | 16640 KB |
02-24.txt | RE | 137 ms | 16640 KB |
02-25.txt | RE | 137 ms | 16640 KB |
02-26.txt | RE | 136 ms | 16640 KB |
02-27.txt | RE | 136 ms | 16640 KB |
02-28.txt | RE | 137 ms | 16640 KB |
02-29.txt | RE | 137 ms | 16640 KB |
02-30.txt | RE | 136 ms | 16640 KB |
02-31.txt | RE | 136 ms | 16640 KB |
02-32.txt | RE | 137 ms | 16640 KB |
02-33.txt | RE | 137 ms | 16640 KB |
02-34.txt | RE | 138 ms | 16640 KB |
02-35.txt | RE | 135 ms | 16640 KB |
02-36.txt | RE | 137 ms | 16640 KB |
02-37.txt | RE | 136 ms | 16640 KB |
02-38.txt | RE | 140 ms | 16640 KB |
02-39.txt | RE | 138 ms | 16640 KB |
02-40.txt | RE | 139 ms | 16640 KB |
sample-01.txt | AC | 24 ms | 16640 KB |
sample-02.txt | RE | 139 ms | 16640 KB |
sample-03.txt | AC | 28 ms | 16640 KB |