QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#617213#9427. Collect the Coinszzpcd#WA 102ms13964kbC++202.8kb2024-10-06 14:27:332024-10-06 14:27:37

Judging History

你现在查看的是最新测评结果

  • [2024-11-06 15:56:27]
  • hack成功,自动添加数据
  • (/hack/1139)
  • [2024-10-06 14:27:37]
  • 评测
  • 测评结果:WA
  • 用时:102ms
  • 内存:13964kb
  • [2024-10-06 14:27:33]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int MN = 1e6 + 5;
using s64 = long long;
const s64 inf = numeric_limits<s64>::max();
int n, t[MN], c[MN];
int m, numc[MN];
s64 T1[MN], T2[MN];
void modi(s64* T, int x, s64 v) {
    for(; x <= m; x += (x & -x))
        T[x] = min(T[x], v);
}
void modiq(s64* T, int x) {
    for(; x <= m; x += (x & -x))
        T[x] = inf;
}
s64 query(s64* T, int x) {
    s64 ret = inf;
    for(; x; x -= (x & -x))
        ret = min(ret, T[x]);
    return ret;
}
bool check(int v) {
    fill(T1, T1 + m + 1, numeric_limits<s64>::max());
    fill(T2, T2 + m + 1, numeric_limits<s64>::max());
    vector<int> tmp;
    int i = 2;
    for(i = 2; i <= n; i++) {
        if((s64)(t[i] - t[i - 1]) * v < abs(c[i] - c[i - 1])) {
            for(int j = 1; j < i; j++) {
                tmp.push_back(j);
                modi(T1, numc[j], (s64)t[j] * v - c[j]);
                modi(T2, m - numc[j] + 1, (s64)t[j] * v + c[j]);
                // cerr << j << ' ' << numc[j] << ' ' << (s64)t[j] * v - c[j] << '\n';
            }
            i++;
            break;
        }
    }
    // cerr << v << " : " << i << '\n';
    for( ; i <= n; i++) {
        bool flag = 0;
        // cerr << (s64)t[i] * v - c[i] << ' ' << query(T1, numc[i]) << " T1\n";
        // cerr << (s64)t[i] * v + c[i] << ' ' << query(T2, m - numc[i] + 1) << " T2\n";
        if((s64)t[i] * v - c[i] >= query(T1, numc[i]) || (s64)t[i] * v + c[i] >= query(T2, m - numc[i] + 1)) {
            flag = 1;
        }
        if((s64)(t[i] - t[i - 1]) * v < abs(c[i] - c[i - 1])) {
            for(int x : tmp) {
                modiq(T1, numc[x]);
                modiq(T2, m - numc[x] + 1);
            }
            tmp.clear();
        }
        // cerr << flag << " flag\n";
        if(flag) {
            tmp.push_back(i - 1);
            modi(T1, numc[i - 1], (s64)t[i - 1] * v - c[i - 1]);
            modi(T2, m - numc[i - 1] + 1, (s64)t[i - 1] * v + c[i - 1]);
        }
        if(tmp.empty()) break;
    }
    return i > n;
}
void solve() {
    cin >> n;
    vector<int> num;
    for(int i = 1; i <= n; i++) cin >> t[i] >> c[i], num.push_back(c[i]);
    sort(num.begin(), num.end());
    num.erase(unique(num.begin(), num.end()), num.end());
    m = num.size();
    for(int i = 1; i <= n; i++) numc[i] = lower_bound(num.begin(), num.end(), c[i]) - num.begin() + 1;
    int L = 0, R = 1e9 + 1, ans = -1;
    while(L <= R) {
        int mid = (L + R >> 1);
        if(check(mid)) {
            ans = mid;
            R = mid - 1;
        } else L = mid + 1;
    }
    cout << ans << '\n';
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int T = 1;
    cin >> T;
    while(T--) {
        solve();
    }
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 11808kb

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: 102ms
memory: 13964kb

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
3
0
3
1
2
6
0
3
2
2
0
2
5
0
1
5
1
2
0
0
0
1
4
2
0
2
1
3
0
3
2
3
2
5
3
1
1
0
1
1
1
0
2
0
1
0
1
0
2
1
0
2
3
3
2
1
1
1
0
1
3
0
1
4
4
3
0
0
2
2
6
4
2
1
0
0
1
0
2
1
2
0
1
1
2
0
0
1
2
0
2
0
2
2
2
1
0
0
0
5
1
2
0
6
1
1
1
1
2
2
0
3
1
4
3
6
0
5
1
1
3
0
2
2
2
1
1
0
0
0
7
2
2
1
0
0
3
1
2
1
1
2
5
3
0
2
3
3
5
...

result:

wrong answer 6th lines differ - expected: '3', found: '2'