이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
//#define int long long
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
const double eps = 1e-9;
ll dpL[1005], dpR[1005];
int32_t main() {
int n, m;
cin >> n >> m;
vector<array<int, 4> > v(n+2);
set<int> s; s.insert(1); s.insert(m);
for(int i=1; i<=n; i++) {
cin >> v[i][0] >> v[i][1] >> v[i][2] >> v[i][3];
s.insert(v[i][0]);
s.insert(v[i][1]);
s.insert(v[i][2]);
}
vector<int> comp(all(s));
for(int i=1; i<=n; i++) {
v[i][0] = lower_bound(all(comp), v[i][0]) - comp.begin();
v[i][1] = lower_bound(all(comp), v[i][1]) - comp.begin();
v[i][2] = lower_bound(all(comp), v[i][2]) - comp.begin();
}
ll ans = 1e18;
for(int i=1; i<=n; i++) dpL[i] = dpR[i] = 1e18;
auto check = [&](int i, int j) {
return v[i][0] <= v[j][2] && v[j][2] <= v[i][1];
};
for(int i=1; i<=n; i++) {
if(v[i][0] == 0) dpL[i] = v[i][3];
if(v[i][1] == comp.size()-1) dpR[i] = v[i][3];
for(int j=1; j<i; j++)
if(dpL[j] != 1e18 && check(i, j)) dpL[i] = min(dpL[i], dpL[j] + v[i][3]);
for(int j=1; j<i; j++)
if(dpR[j] != 1e18 && check(i, j)) dpR[i] = min(dpR[i], dpR[j] + v[i][3]);
ans = min(ans, dpL[i] + dpR[i] - v[i][3]);
}
cout << (ans == 1e18 ? -1 : ans) << '\n';
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
pinball.cpp: In function 'int32_t main()':
pinball.cpp:55:20: warning: comparison of integer expressions of different signedness: 'std::array<int, 4>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | if(v[i][1] == comp.size()-1) dpR[i] = v[i][3];
# | 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... |