QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#660813 | #9427. Collect the Coins | panhongxuan | WA | 35ms | 6604kb | C++14 | 5.3kb | 2024-10-20 13:30:07 | 2024-10-20 13:30:08 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
namespace MyNamespace {
typedef long long ll;
namespace MyIO {
char buf[1000000], *p1, *p2;
#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++)
inline ll rd() {
char ch = getchar();
ll s = 0, w = 1;
while (!isdigit(ch)) {
if (ch == '-') w = -1;
ch = getchar();
}
while (isdigit(ch)) {
s = (s << 3) + (s << 1) + (ch ^ 48);
ch = getchar();
}
return (s * w);
}
void wr(ll x) {
if (x < 0) x = -x, putchar('-');
if (x > 9) wr(x / 10);
putchar(x % 10 + 48);
}
}
using namespace MyIO;
const ll INF = 1e18;
const ll fn = 1e6;
const ll N = fn + 10;
ll n, m;
struct nde {
ll t, x;
} a[N];
inline bool operator < (const nde &p, const nde &q) {
if (p.t != q.t) return p.t < q.t;
else return p.x < q.x;
}
inline bool operator == (const nde &p, const nde &q) {
return p.t == q.t && p.x == q.x;
}
inline ll cedv(ll x, ll y) {
// if (x == 0) return 0;
// else if (y == 0) return INF;
// else if ((x > 0 && y > 0) || (x < 0 && y < 0)) {
// x = abs(x), y = abs(y);
// return (x + y - 1) / y;
// }
// else return x / y;
return (x + y - 1) / y;
}
inline ll calc_slope(const nde &p, const nde &q) {
if (p.x == q.x) return 0;
else if (p.t == q.t) return INF;
else return cedv(abs(q.x - p.x), abs(q.t - p.t));
}
inline void ckmin(ll &x, ll y) {
x = min(x, y);
}
namespace Sub1 {
const ll fn = 1e3;
const ll N = fn + 10;
ll ans, dp[N][N];
void doit() {
// cerr << "Sub1\n";
for (ll i = 0; i <= n; ++i) {
for (ll j = 0; j <= n; ++j) {
dp[i][j] = INF;
}
}
dp[1][0] = 0;
for (ll i = 1; i <= n - 1; ++i) {
for (ll j = 0; j <= i; ++j) {
// let i go to i + 1
ckmin(dp[i + 1][j], max(dp[i][j], calc_slope(a[i], a[i + 1])));
// let j go to i + 1
ckmin(dp[i + 1][i], max(dp[i][j], (j > 0 ? calc_slope(a[j], a[i + 1]) : 0ll)));
}
}
ans = INF;
for (ll j = 0; j <= n; ++j) {
ans = min(ans, dp[n][j]);
// cerr << "A " << j << ' ' << dp[n][j] << endl;
}
wr(ans);
}
}
namespace Sub2 {
ll V, ans;
inline ll calc_f_b(const nde &p) {
return p.x - p.t * V;
}
inline ll calc_g_b(const nde &p) {
return p.x + p.t * V;
}
set<ll> F, G;
inline ll calc_greater(const set<ll> &A, ll x) {
auto it = A.upper_bound(x);
return distance(it, A.end());
}
inline ll calc_less(const set<ll> &A, ll x) {
auto it = A.lower_bound(x);
return distance(A.begin(), it);
}
bool check() {
bool can_transit_from_zero = 1;
F.clear(), G.clear();
for (ll i = 1; i <= n - 1; ++i) {
bool can_iplusone_i = 0;
// cerr << "L " << calc_less(F, calc_f_b(a[i + 1]))<< ' ' << calc_greater(G, calc_g_b(a[i + 1]))<< endl;
if (can_transit_from_zero || ll(F.size()) > calc_less(F, calc_f_b(a[i + 1])) + calc_greater(G, calc_g_b(a[i + 1]))) {
can_iplusone_i = 1;
}
else {
can_iplusone_i = 0;
}
if (i == 1 || calc_slope(a[i], a[i + 1]) <= V) {
// pass
}
else {
// cerr << "K " << i << endl;
can_transit_from_zero = 0;
F.clear(), G.clear();
}
if (can_iplusone_i) {
// cerr << "E " << i << endl;
F.insert(calc_f_b(a[i])), G.insert(calc_g_b(a[i]));
}
if (!(can_transit_from_zero || !F.empty())) {
// cerr << "D " << i << endl;
return 0;
}
// cerr << "J " << ll(F.size()) << endl;
// cerr << "I " << i << ' ' << can_transit_from_zero << endl;
// // if (!F.empty()) {
// cerr << "J " << ll(F.size());// << ' ' << *F.begin() << ' ' << *G.begin() << endl;
// cerr << "F "; for (ll i : F) cerr << i << ' '; cerr << endl;
// cerr << "G "; for (ll i : G) cerr << i << ' '; cerr << endl;
// }
}
return can_transit_from_zero || !F.empty();
}
inline bool check_simple() {
ll pre = 0;
for (ll i = 1; i <= n - 1; ++i) {
if (calc_slope(a[i], a[i + 1]) > V) {
if (pre == 0 || calc_slope(a[pre], a[i + 1]) <= V) {
pre = i;
}
else {
return 0;
}
}
}
return 1;
}
void doit() {
// cerr << "Sub2\n";
// V = 2;
// cerr << "A " << check() << endl;
ll bd = 0;
for (ll i = 1; i <= n - 1; ++i) {
bd = max(bd, calc_slope(a[i], a[i + 1]));
}
bd = min(bd, ll(2e9));
ll lef = 0, rig = bd; ans = bd;
while (lef <= rig) {
V = ((lef + rig) >> 1);
// cerr << "V " << V << endl;
if (check_simple() || check()) {
ans = V;
rig = V - 1;
}
else {
lef = V + 1;
}
}
wr(ans), putchar('\n');
}
}
void solve_tc() {
// cerr << "A\n";
n = rd();
for (ll i = 1; i <= n; ++i) {
a[i].t = rd(), a[i].x = rd();
}
sort(a + 1, a + n + 1);
n = unique(a + 1, a + n + 1) - (a + 1);
// cerr << "B\n";
// check -1
ll cnt = 1;
for (ll i = 2; i <= n; ++i) {
if (a[i].t != a[i - 1].t) {
cnt = 1;
}
else {
++cnt;
}
if (cnt >= 3) {
wr(-1), putchar('\n');
return;
}
}
Sub2::doit();
// if (n <= 1000) Sub1::doit();
// else Sub2::doit();
}
void NamespaceMain() {
// cerr << "D\n";
ll T = rd();
// cerr << "C\n";
while (T--) {
solve_tc();
}
}
}
int main() {
// freopen("D.in", "r", stdin);
// freopen("D.out", "w", stdout);
MyNamespace::NamespaceMain();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5728kb
input:
3 5 1 1 3 7 3 4 4 3 5 10 1 10 100 3 10 100 10 1000 10 10000
output:
2 0 -1
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 35ms
memory: 6604kb
input:
1135 2 6 5 8 8 8 2 9 2 10 4 4 5 3 6 2 6 8 8 2 8 7 1 9 1 6 4 6 6 1 6 2 9 10 10 1 10 7 5 1 6 2 5 6 7 8 6 10 3 8 1 10 5 4 5 7 6 1 6 6 8 4 9 1 9 4 8 1 1 1 3 2 9 3 3 5 9 6 10 9 7 10 7 3 5 8 6 6 10 6 7 2 9 4 7 5 10 6 3 6 7 8 9 10 1 6 1 4 2 8 5 9 7 10 9 1 10 5 9 2 7 4 5 5 9 6 10 7 4 9 4 9 9 10 3 10 7 1 3 1...
output:
0 1 0 3 1 3 1 0 3 2 2 0 2 0 0 0 1 1 1 0 0 0 1 4 2 0 2 1 1 0 1 2 2 2 5 3 0 0 0 1 1 1 0 2 0 0 0 1 0 2 1 0 1 1 4 4 1 1 0 0 0 3 0 1 4 3 1 0 0 2 2 2 4 2 0 0 0 1 0 2 1 0 0 0 1 3 0 0 0 2 0 3 0 1 2 1 1 0 0 0 5 1 1 0 6 1 0 0 2 2 0 0 3 1 4 3 6 0 8 0 0 3 0 2 2 4 1 1 0 0 0 7 2 2 1 0 0 3 1 2 0 1 2 3 3 0 3 3 3 5 ...
result:
wrong answer 2nd lines differ - expected: '3', found: '1'