# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
955727 | vjudge1 | Pinball (JOI14_pinball) | C++17 | 1088 ms | 3600 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll m, n, i, j, k, a, b, w = 0, ma, r = (1LL << 50);
cin >> m >> n;
vector<vector<ll> > v, vv(m);
vector<ll> lp, nlp, nrp, rp;
vector<ll> d(m), s(3 * m);
for (i = 0; i < m; i++)
{
cin >> j;
v.push_back({j - 1, i, -1});
cin >> j;
v.push_back({j - 1, i, 1});
cin >> j;
v.push_back({j - 1, i, 0});
cin >> d[i];
}
sort(v.begin(), v.end());
if (v[0][0] || v[3 * m - 1][0] != n - 1)
{
cout << -1;
return 0;
}
for (i = 0; i < 3 * m; i++)
{
if (!i)
s[i] = 0;
else if (v[i][0] > v[i - 1][0])
s[i] = s[i - 1] + 1;
else
s[i] = s[i - 1];
w = max(w, s[i]);
}
for (i = 0; i < 3 * m; i++)
v[i] = {v[i][1], s[i], v[i][2]};
sort(v.begin(), v.end());
for (i = 0; i < m; i++)
vv[i] = {v[3 * i][1], v[3 * i + 1][1], v[3 * i + 2][1]};
nlp.resize(w + 1);
nrp.resize(w + 1);
for (i = 0; i <= w; i++)
nlp[i] = nrp[i] = r;
nlp[0] = nrp[w] = 0;
lp = nlp;
rp = nrp;
ma = r;
for (i = 0; i < m; i++)
{
for (j = vv[i][0]; j <= vv[i][2]; j++)
{
if (j < vv[i][1])
{
nlp[vv[i][1]] = min(nlp[vv[i][1]], lp[j] + d[i]);
}
if (j > vv[i][1])
{
nrp[vv[i][1]] = min(nrp[vv[i][1]], rp[j] + d[i]);
}
}
for (j = 1; j <= w; j++)
rp[j] = min(rp[j], rp[j - 1]);
for (j = w - 1; j >= 0; j--)
lp[j] = min(lp[j], lp[j + 1]);
ma = min(ma, lp[vv[i][0]] + rp[vv[i][2]] + d[i]);
lp = nlp;
rp = nrp;
}
for (j = 1; j <= w; j++)
rp[j] = min(rp[j], rp[j - 1]);
for (j = w - 1; j >= 0; j--)
lp[j] = min(lp[j], lp[j + 1]);
for (j = 0; j <= w; j++)
ma = min(ma, lp[j] + rp[j]);
if (ma < r)
cout << ma;
else
cout << -1;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |