QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#231922 | #6226. 取石子 | SorahISA | 100 ✓ | 50ms | 3704kb | C++20 | 7.9kb | 2023-10-29 18:07:44 | 2023-10-29 18:07:44 |
Judging History
answer
#ifndef SorahISA
#define SorahISA
#include SorahISA __FILE__ SorahISA
vector<int> fib;
int sz;
void solve() {
int K, N; cin >> K >> N;
/// count n such that K >= lowbit(n) in fibonacci-based representation ///
// int tmp = 0;
// for (int n = 1; n <= N-1; ++n) {
// for (int i = sz-1, num = n; i >= 0; --i) {
// if (num >= fib[i]) num -= fib[i];
// if (1 <= num and num <= K) { ++tmp; break; }
// }
// }
// debug(tmp);
int bitlen = 0;
while (fib[bitlen] <= K) ++bitlen;
int ans = 0;
for (int i = sz-1, num = N-1; i >= 0; --i) {
if (num >= fib[i]) {
ans += fib[i] - (i >= bitlen ? fib[i - bitlen] : 0);
num -= fib[i];
}
}
print(ans);
}
void init() {
fib = {1, 2};
for (int i = 2; fib.back() < LLONG_MAX / 4; ++i) {
fib.eb(fib[i-1] + fib[i-2]);
}
sz = SZ(fib); /// 89
}
int32_t main() {
fastIO();
init();
int t = 1; cin >> t;
for (int _ = 1; _ <= t; ++_) {
// cout << "Case #" << _ << ": ";
solve();
}
return 0;
}
#else
#ifdef local
#define _GLIBCXX_DEBUG 1
#endif
#pragma GCC optimize("Ofast", "unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
// #define double __float80
using pii = pair<int, int>;
template <typename T> using Prior = std::priority_queue<T>;
template <typename T> using prior = std::priority_queue<T, vector<T>, greater<T>>;
// #define X first
// #define Y second
#define eb emplace_back
#define ef emplace_front
#define ee emplace
#define pb pop_back
#define pf pop_front
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
#define SZ(x) ((int)(x).size())
template <size_t D, typename T> struct Vec : vector<Vec<D-1, T>> {
static_assert(D >= 1, "Vector dimension must be greater than zero!");
template <typename... Args> Vec(int n = 0, Args... args) : vector<Vec<D-1, T>>(n, Vec<D-1, T>(args...)) {}
};
template <typename T> struct Vec<1, T> : vector<T> {
Vec(int n = 0, const T& val = T()) : vector<T>(n, val) {}
};
template <class F>
inline constexpr decltype(auto) lambda_fix(F&& f) {
return [f = std::forward<F>(f)](auto&&... args) {
return f(f, std::forward<decltype(args)>(args)...);
};
}
#ifdef local
#define fastIO() void()
#define debug(...) \
_color.emplace_back("\u001b[31m"), \
fprintf(stderr, "%sAt [%s], line %d: (%s) = ", _color.back().c_str(), __FUNCTION__, __LINE__, #__VA_ARGS__), \
_do(__VA_ARGS__), _color.pop_back(), \
fprintf(stderr, "%s", _color.back().c_str())
#define print(...) \
fprintf(stdout, "%s", "\u001b[36m"), \
_P(__VA_ARGS__), \
fprintf(stdout, "%s", "\u001b[0m")
deque<string> _color{"\u001b[0m"};
template <typename T> concept is_string = is_same_v<T, string&> or is_same_v<T, const string&>;
template <typename T> concept is_iterable = requires (T _t) {begin(_t);};
template <typename T> inline void _print_err(T &&_t);
template <typename T> inline void _print_err(T &&_t) requires is_iterable<T> and (not is_string<T>);
template <size_t I, typename ...U> inline typename enable_if<I == sizeof...(U), void>::type _print_err(const tuple<U...> &);
template <size_t I, typename ...U> inline typename enable_if<I < sizeof...(U), void>::type _print_err(const tuple<U...> &_t);
template <size_t I, typename ...U> inline typename enable_if<I == sizeof...(U), void>::type _print_err(tuple<U...> &);
template <size_t I, typename ...U> inline typename enable_if<I < sizeof...(U), void>::type _print_err(tuple<U...> &_t);
template <typename T, typename U> ostream& operator << (ostream &os, const pair<T, U> &_tu);
inline void _do() {cerr << "\n";};
template <typename T> inline void _do(T &&_t) {_print_err(_t), cerr << "\n";}
template <typename T, typename ...U> inline void _do(T &&_t, U &&..._u) {_print_err(_t), cerr << ", ", _do(_u...);}
#else
#define fastIO() ios_base::sync_with_stdio(0), cin.tie(0)
#define debug(...) void()
#define print(...) _P(__VA_ARGS__)
#endif
inline void _P() {cout << "\n";};
template <typename T> inline void _P(T &&_t) {cout << _t << "\n";}
template <typename T, typename ...U> inline void _P(T &&_t, U &&..._u) {cout << _t << " ", _P(_u...);}
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int getRand(int L, int R) {
if (L > R) swap(L, R);
return (int)(rng() % ((uint64_t)R - L + 1) + L);
}
template <typename T, typename U> bool chmin(T &lhs, U rhs) {return lhs > rhs ? lhs = rhs, 1 : 0;}
template <typename T, typename U> bool chmax(T &lhs, U rhs) {return lhs < rhs ? lhs = rhs, 1 : 0;}
/// below are Fast I/O and _print_err templates ///
/*
/// Fast I/O by FHVirus ///
/// https://fhvirus.github.io/blog/2020/fhvirus-io/ ///
#include <unistd.h>
const int S = 65536;
int OP = 0;
char OB[S];
inline char RC() {
static char buf[S], *p = buf, *q = buf;
return p == q and (q = (p = buf) + read(0, buf, S)) == buf ? -1 : *p++;
}
inline int RI() {
static char c;
int a;
while (((c = RC()) < '0' or c > '9') and c != '-' and c != -1);
if (c == '-') {
a = 0;
while ((c = RC()) >= '0' and c <= '9') a *= 10, a -= c ^ '0';
}
else {
a = c ^ '0';
while ((c = RC()) >= '0' and c <= '9') a *= 10, a += c ^ '0';
}
return a;
}
inline void WI(int n, char c = '\n') {
static char buf[20], p;
if (n == 0) OB[OP++] = '0';
p = 0;
if (n < 0) {
OB[OP++] = '-';
while (n) buf[p++] = '0' - (n % 10), n /= 10;
}
else {
while (n) buf[p++] = '0' + (n % 10), n /= 10;
}
for (--p; p >= 0; --p) OB[OP++] = buf[p];
OB[OP++] = c;
if (OP > S-20) write(1, OB, OP), OP = 0;
}
/// Fast I/O by FHVirus ///
/// https://fhvirus.github.io/blog/2020/fhvirus-io/ ///
*/
#ifdef local
template <typename T> inline void _print_err(T &&_t) {cerr << _t;}
template <typename T> inline void _print_err(T &&_t) requires is_iterable<T> and (not is_string<T>) {
string _tmp_color = _color.back();
++_tmp_color[3], _color.emplace_back(_tmp_color);
cerr << _color.back() << "[";
for (bool _first = true; auto &_x : _t) {
if (!_first) cerr << ", ";
_print_err(_x), _first = false;
}
cerr << "]" << (_color.pop_back(), _color.back());
}
template <typename T, typename U> ostream& operator << (ostream &os, const pair<T, U> &_tu) {
string _tmp_color = _color.back();
++_tmp_color[3], _color.emplace_back(_tmp_color);
cerr << _color.back() << "(";
_print_err(_tu.first), cerr << ", ", _print_err(_tu.second);
cerr << ")" << (_color.pop_back(), _color.back());
return os;
}
template <size_t I = 0, typename ...U> inline typename enable_if<I == sizeof...(U), void>::type _print_err(const tuple<U...> &) {
cerr << ")" << (_color.pop_back(), _color.back());
}
template <size_t I = 0, typename ...U> inline typename enable_if<I < sizeof...(U), void>::type _print_err(const tuple<U...> &_t) {
if (!I) {
string _tmp_color = _color.back();
++_tmp_color[3], _color.emplace_back(_tmp_color);
cerr << _color.back();
}
cerr << (I ? ", " : "("), _print_err(get<I>(_t)), _print_err<I+1, U...>(_t);
}
template <size_t I = 0, typename ...U> inline typename enable_if<I == sizeof...(U), void>::type _print_err(tuple<U...> &) {
cerr << ")" << (_color.pop_back(), _color.back());
}
template <size_t I = 0, typename ...U> inline typename enable_if<I < sizeof...(U), void>::type _print_err(tuple<U...> &_t) {
if (!I) {
string _tmp_color = _color.back();
++_tmp_color[3], _color.emplace_back(_tmp_color);
cerr << _color.back();
}
cerr << (I ? ", " : "("), _print_err(get<I>(_t)), _print_err<I+1, U...>(_t);
}
#endif
#endif
詳細信息
Test #1:
score: 10
Accepted
time: 1ms
memory: 3684kb
input:
499 336 455 5 9 420 424 35 57 9 424 55 71 38 414 64 346 42 480 18 212 37 249 82 488 6 190 75 165 51 272 13 37 29 143 44 195 71 175 149 180 42 245 62 376 193 285 47 207 128 145 5 209 281 329 9 437 258 296 2 31 70 240 268 356 21 93 147 180 79 115 63 106 112 443 219 305 332 476 47 450 134 290 51 89 243...
output:
453 7 423 55 386 70 405 341 469 200 243 481 162 162 266 34 138 191 172 179 239 371 283 202 143 178 328 397 295 19 236 355 89 179 113 104 439 303 474 440 287 87 387 248 10 342 220 237 179 55 180 21 240 424 303 135 30 35 225 456 307 339 130 119 412 410 144 317 436 94 295 151 127 413 271 376 399 98 195...
result:
ok 499 lines
Test #2:
score: 10
Accepted
time: 12ms
memory: 3552kb
input:
49875 14399 29607 6224 29914 1106 26641 17 26569 6365 25718 27 4637 1618 2714 33573 40913 35563 36097 8973 28132 5673 25161 17636 34907 6000 10087 4467 7440 8334 49937 259 20572 6268 28505 6401 15802 12571 13234 23041 27538 2493 47406 5802 10423 11962 30757 3300 3837 8350 20422 225 16103 23645 34285...
output:
29604 29908 26621 25088 25713 4477 2712 40912 36096 28129 25156 34904 10085 7438 49931 20508 28500 15799 13233 27537 47384 10421 30754 3836 20419 16022 34283 14143 11943 3085 26304 4187 45877 6744 2564 6583 41136 24161 24495 3581 20250 1596 1768 42297 36849 39560 1567 19248 5957 29387 18796 41587 42...
result:
ok 49875 lines
Test #3:
score: 10
Accepted
time: 23ms
memory: 3680kb
input:
94256 53191 66970 85363 96281 23759 25693 28568 43227 27 31316 10224 32226 9111 25249 16987 19389 15006 30353 9523 59244 42546 55606 6039 6830 5609 54488 2509 12330 29480 70960 14785 65267 60831 91903 281 18175 31994 76610 3582 9689 7665 34764 12673 18964 16448 22115 5748 30321 33618 49834 18843 244...
output:
66969 96280 25692 43225 30237 32222 25246 19387 30350 59237 55604 6828 54478 12324 70958 65262 91901 18118 76607 9686 34760 18962 22113 30315 49832 24425 70059 40152 56259 57054 14261 45339 15707 14217 55632 98631 52711 24035 98749 39748 89561 80981 18906 48683 22461 41206 97044 74800 91011 49044 98...
result:
ok 94256 lines
Test #4:
score: 10
Accepted
time: 0ms
memory: 3704kb
input:
3 34279 810634 918771 1021048 25 42120
output:
810613 1021047 40669
result:
ok 3 lines
Test #5:
score: 10
Accepted
time: 0ms
memory: 3540kb
input:
3 690379 1982172 417599 1708659 1717080 2863950
output:
1982169 1708655 2863948
result:
ok 3 lines
Test #6:
score: 10
Accepted
time: 1ms
memory: 3560kb
input:
944 1 343954967570505156 1 84731075985818925 1 138311144113583007 1 104547054550584433 1 693241347397247084 1 472332079344024358 1 156793474620214247 1 850344749061699637 1 803512580085688163 1 310836022836048564 1 495053169351075063 1 82844446500137324 1 178945557527795821 1 216483389996708327 1 59...
output:
131379107012565125 32364391123232826 52830156028503762 39933421414633890 264794632298974933 180414800332505167 59889778090727832 324802791986569006 306914495204610982 118728795795532068 189093484453752948 31643762783880187 68351120839818397 82689296978943594 226609373538521525 31210098343021365 1747...
result:
ok 944 lines
Test #7:
score: 10
Accepted
time: 39ms
memory: 3704kb
input:
91665 1 367380666905152293 1 182005789689897190 1 623096247285159354 1 671594325644512277 1 742160204799780654 1 794275980040994924 1 74354650304567324 1 911166360819358930 1 764757676441890048 1 752269248988307295 1 955093740058796962 1 747803753737785010 1 404138290206507311 1 181396406609700806 1...
output:
140326927948164534 69520025512275542 238001588200421479 256526205744638559 283479973135933361 303386427928026962 28400949194731997 348034580427444623 292111439243407250 287341284422175938 364813346260203446 285635617013077651 154367090703617032 69287261887809626 23433513534972568 245586033973105615 ...
result:
ok 91665 lines
Test #8:
score: 10
Accepted
time: 1ms
memory: 3700kb
input:
911 78374152724567593 983112666946547816 753553157811176669 788891899819251115 33856693441045857 281513707367405940 458492126183900287 469318687938414816 20297113357777935 33378284552002778 10115955709864055 787679629225677540 17150232293760847 102828488233093971 112680441700253174 12938526751175947...
output:
983112666946547804 788891899819251114 281513707367405931 469318687938414815 33378284552002776 787679629225677476 102828488233093965 129385267511759476 393578058742371563 710310834833243826 96936676611661623 735136776039311809 198814605441753839 180714195277663471 595056197625354637 81570251109792082...
result:
ok 911 lines
Test #9:
score: 10
Accepted
time: 50ms
memory: 3588kb
input:
98295 873150664261731328 951581568702046682 56 727890463110977051 859978062141145093 947945138127019948 330253590080540990 768615565614466064 13256179404231692 95760438247048090 638707615934448347 792288571729874417 54711657924896980 847301161318887407 856185831773980409 893587664123567425 312798854...
output:
951581568702046681 718314614598993502 947945138127019947 768615565614466061 95760438247048082 792288571729874415 847301161318887390 893587664123567424 537497297873269823 9294212206362214 658682178594527622 905480424268227148 325786925372156416 562180168829403836 53899373768465925 713229827374765299 ...
result:
ok 98295 lines
Test #10:
score: 10
Accepted
time: 47ms
memory: 3584kb
input:
91640 405786310369032226 553800146036810186 84 288402474700211717 19845023439645913 392170479523345754 597697212044203925 702078911619194971 11204130783741609 13290697100124817 23 484543424049569697 559463321235963921 601484656718057819 227796568880241875 992739563025444500 156735875816653837 901104...
output:
553800146036810184 284608362058033389 392170479523345734 702078911619194969 13290697100124816 467854850303592542 601484656718057818 992739563025444495 901104214479350060 48697612993165859 734901520058359731 279043494845859133 114370108376756251 853502730432930234 262119937602158135 18879980688626615...
result:
ok 91640 lines