QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#505717 | #4682. Pipe Stream | Max_s_xaM | WA | 6ms | 3648kb | C++14 | 4.4kb | 2024-08-05 09:44:38 | 2024-08-05 09:44:38 |
Judging History
answer
#include <iostream>
typedef long long ll;
typedef double lf;
// #define DEBUG 1
struct IO
{
#define MAXSIZE (1 << 20)
#define isdigit(x) (x >= '0' && x <= '9')
char buf[MAXSIZE], *p1, *p2;
char pbuf[MAXSIZE], *pp;
#if DEBUG
#else
IO() : p1(buf), p2(buf), pp(pbuf) {}
~IO() {fwrite(pbuf, 1, pp - pbuf, stdout);}
#endif
#define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2) ? ' ' : *p1++)
#define blank(x) (x == ' ' || x == '\n' || x == '\r' || x == '\t')
template <typename T>
void Read(T &x)
{
#if DEBUG
std::cin >> x;
#else
bool sign = 0; char ch = gc(); x = 0;
for (; !isdigit(ch); ch = gc())
if (ch == '-') sign = 1;
for (; isdigit(ch); ch = gc()) x = x * 10 + (ch ^ 48);
if (sign) x = -x;
#endif
}
void Read(char *s)
{
#if DEBUG
std::cin >> s;
#else
char ch = gc();
for (; blank(ch); ch = gc());
for (; !blank(ch); ch = gc()) *s++ = ch;
*s = 0;
#endif
}
void Read(char &c) {for (c = gc(); blank(c); c = gc());}
void Push(const char &c)
{
#if DEBUG
putchar(c);
#else
if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf;
*pp++ = c;
#endif
}
template <typename T>
void Write(T x)
{
if (x < 0) x = -x, Push('-');
static T sta[35];
int top = 0;
do sta[top++] = x % 10, x /= 10; while (x);
while (top) Push(sta[--top] ^ 48);
}
template <typename T>
void Write(T x, char lst) {Write(x), Push(lst);}
} IO;
#define Read(x) IO.Read(x)
#define Write(x, y) IO.Write(x, y)
#define Put(x) IO.Push(x)
using namespace std;
const int MAXN = 1e3 + 10;
int t;
lf cm, bnd[MAXN];
ll bg[MAXN], pw[MAXN];
inline bool Calc(int n, lf v1, lf v2)
{
// cout << "Calc " << n << ' ' << v1 << ' ' << v2 << "\n";
for (int i = 1; i <= n; i++) bnd[i] = cm / i, bg[i] = pw[i] = 0;
while (n && bnd[n] < v1) n--;
for (int i = n; i >= 1 && n - i <= 32; i--) bg[i] = (1ll << n - i), pw[i] = bg[i] << 1;
// for (int i = 1; i <= n; i++) cout << bg[i] << ' ' << pw[i] << ' ' << bnd[i] << '\n';
ll ad = 0, cur;
while (n)
{
ll mn = 1e18; int p = 0;
for (int i = n; i >= 1 && n - i <= 32; i--)
{
if ((bg[i] + ad) * t + v1 > bnd[i]) cur = 0;
else cur = (ll)(((bnd[i] - v1) / t - bg[i] - ad) / pw[i]) + 1;
if (mn > bg[i] + ad + cur * pw[i]) mn = bg[i] + ad + cur * pw[i], p = i;
}
if (n <= 32 && mn >= (1ll << n) + ad) return ((1ll << n) + ad) * t + v1 >= v2;
if ((mn - 1) * t + v1 >= v2 - t) return 1;
ll cnt = 0;
if (bnd[p] > (mn - 1) * t + v1)
{
v1 = bnd[p] - mn * t;
if (bnd[p] >= v2 - t) return 1;
}
else cnt--;
// cout << mn << ' ' << p << " " << v1 << "\n";
if (p == 1) break;
for (int i = p; i <= n; i++)
cnt += (mn - bg[i] - ad) / pw[i] + 1;
mn -= ad, ad += cnt;
for (int i = p - 1; i >= 1 && p - 1 - i <= 32; i--)
{
if (!bg[i]) { bg[i] = (1ll << p - 1 - i); continue; }
ll c = mn + (pw[i + 1] >> 1);
if (__builtin_ctzll(c) == n - i) bg[i] = c >> n - p + 1, mn = c;
else bg[i] = (mn -= (pw[i + 1] >> 1)) >> n - p + 1;
}
n = p - 1;
for (int i = n; i >= 1 && n - i <= 32; i--)
pw[i] = 1ll << n - i + 1;
}
return 0;
}
inline void Solve(int v1, int v2)
{
if (v2 - v1 <= t) return cout << "0\n", void();
int l = 1, r = 200, mid;
while (l <= r)
{
mid = l + r >> 1;
if (Calc(mid, v1, v2)) r = mid - 1;
else l = mid + 1;
}
if (l == 201) cout << "impossible\n";
else cout << r + 1 << '\n';
// cout << Calc(4, v1, v2) << "\n";
}
int main()
{
// freopen("G.in", "r", stdin);
// freopen("G.out", "w", stdout);
#if DEBUG
#else
ios::sync_with_stdio(0), cin.tie(0);
#endif
int T;
Read(T);
while (T--)
{
int lb, rb, l, s;
Read(l), Read(lb), Read(rb), Read(t), Read(s);
cm = l / s;
Solve(lb, rb);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3588kb
input:
3 1000 1 30 1 1 60 2 10 2 5 59 2 10 2 5
output:
5 3 impossible
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 6ms
memory: 3648kb
input:
100 1 1 2 1 1 1 1 3 1 1 2 1 3 1 1 3 1 4 1 1 4 1 4 1 1 100000 1 1000000 1 1 100000 1 9 1 1 100000 1 9454 1 1 100000 1 9455 1 1 500832 1 40181 1 1 500832 1 40182 1 1 524288 1 41871 1 1 524288 1 41872 1 1 930168 1 70677 1 1 930168 1 70678 1 1 930169 1 70677 1 1 930169 1 70678 1 1 930170 1 70677 1 1 930...
output:
0 impossible 1 impossible 2 impossible 3 impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible 3 3 5 impossible 0 0 impossible impossible impossible 25 2 2 19 16 14 1 ...
result:
wrong answer 8th lines differ - expected: '24', found: 'impossible'