이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "overtaking.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mxN = 1007;
int n, len, x, m, y, t[mxN][mxN], e[mxN][mxN], gt[mxN][mxN];
vector<int> s, vec;
vector<deque<pair<int,int>>> prefmx;
vector<pair<int,int>> arr;
int cur_ind;
bool cmp(int a, int b) {
if (t[a][cur_ind] == t[b][cur_ind]) {
return arr[a].second < arr[b].second;
}
return t[a][cur_ind] < t[b][cur_ind];
}
void init(int32_t L, int32_t N, std::vector<long long> T, std::vector<int32_t> W, int32_t X, int32_t M, std::vector<int32_t> S)
{
n = N, len = L, m = M, x = X;
vector<int> inds;
for (int i = 0; i < n; ++i) {
arr.push_back({T[i], W[i]});
vec.push_back(T[i]);
inds.push_back(i);
}
sort(arr.begin(), arr.end());
sort(vec.begin(), vec.end());
for (int i = 0; i < n; ++i) {
t[i][0] = arr[i].first;
}
for (int i = 0; i < m; ++i) {
s.push_back(S[i]);
}
prefmx.push_back({{len, 0}});
for (int i = 1; i < n; ++i) { // y = arr[i].second * x + arr[i].first;
int del = 0, dist = len;
deque<pair<int,int>> cur = prefmx.back();
for (int j = 0; j < cur.size(); ++j) {
int prv = cur[j].second;
int cross;
if (arr[i].second != arr[prv].second) {
cross = (arr[prv].first - arr[i].first) /
(arr[i].second - arr[prv].second);
}
else {
cross = -1;
}
if (cross < 0 || cross >= cur[j].first) {
del++;
}
else {
/*
if (i == 3) {
cout << arr[i].first << ' ' << arr[i].second << "\n";
cout << arr[prv].first << ' ' << arr[prv].second << "\n";
cout << cur[j].first << ' ' << cur[j].second << "\n";
}
*/
dist = cross;
break;
}
}
while (del--) {
cur.pop_front();
}
cur.push_front({dist, i});
prefmx.push_back(cur);
}
for (int j = 1; j < m; ++j) {
for (int i = 0; i < n; ++i) {
e[i][j] = t[i][j - 1] + arr[i].second * (s[j] - s[j - 1]);
}
cur_ind = j - 1;
sort(inds.begin(), inds.end(), cmp);
int mx = 0;
for (auto i : inds) {
mx = max(mx, e[i][j]);
t[i][j] = mx;
}
}
for (int i = 0; i < n; ++i) {
gt[i][m - 1] = t[i][m - 1];
}
for (int j = m - 2; j >= 0; --j) {
cur_ind = j;
sort(inds.begin(), inds.end(), cmp);
int mx = 0;
for (auto i : inds) {
gt[i][j] = max(mx, t[i][j] + x * (len - s[j]));
mx = max(mx, gt[i][j + 1]);
}
}
}
long long arrival_time(long long Y)
{
y = Y;
int ind = upper_bound(vec.begin(), vec.end(), y) - vec.begin();
if (!ind) {
return y + x * len;
}
ind--;
int lb = 0, rb = len, res = -1;
while (lb <= rb) {
int mb = (lb + rb) / 2;
int l = 0, r = prefmx[ind].size() - 1, id = 0;
while (l <= r) {
int mid = (l + r) / 2;
if (prefmx[ind][mid].first >= mb) {
r = mid - 1;
id = prefmx[ind][mid].second;
}
else {
l = mid + 1;
}
}
int vala = y + mb * x, valb = arr[id].first + mb * arr[id].second;
if (valb >= vala) {
rb = mb - 1;
res = gt[id][lower_bound(s.begin(), s.end(), mb) - s.begin()];
}
else {
lb = mb + 1;
}
}
if (res == -1) {
return y + x * len;
}
return res;
}
컴파일 시 표준 에러 (stderr) 메시지
overtaking.cpp: In function 'void init(int32_t, int32_t, std::vector<long long int>, std::vector<int>, int32_t, int32_t, std::vector<int>)':
overtaking.cpp:47:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::deque<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for (int j = 0; j < cur.size(); ++j) {
| ~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |