QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#726344 | #2372. Level Up | LaVuna47 | TL | 2ms | 7640kb | C++20 | 1.9kb | 2024-11-08 23:09:51 | 2024-11-08 23:09:51 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define x first
#define y second
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
typedef long long ll;
typedef double db;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<db, db> pdd;
const ll INF = 1e15;
struct Type
{
ll ex1, t1, ex2, t2;
};
vector<Type> a;
int n;
ll dp[505][505][2];
ll f(int p, ll S1, ll S2, int lvl)
{
if(lvl == 1 && S2 == 0)
{
return 0;
}
if(p == n)
return INF;
ll res = INF;
res = min(res, a[p].t2 + f(p+1, S1, max(0ll,S2 - a[p].ex2), lvl));
res = min(res, f(p+1, S1, S2, lvl));
if(lvl == 0)
{
if(S1 - a[p].ex1 <= 0)
{
res = min(res, a[p].t1 + f(p+1, 0, max(0ll, S2 - abs(S1 - a[p].ex1)), 1));
}
else
{
res = min(res, a[p].t1 + f(p+1, max(0ll, S1 - a[p].ex1), S2, lvl));
}
}
return res;
}
int solve()
{
ll S1, S2;
if (!(cin >> n >> S1 >> S2))
return 1;
a = vector<Type>(n);
for(auto&[ex1, t1, ex2, t2]: a)
cin >> ex1 >> t1 >> ex2 >> t2;
sort(all(a), [](const Type& t1, const Type& t2) -> bool {
return t1.ex1 < t2.ex2;
});
for(auto& item: dp)
for(auto& i: item)
for(auto& j: i)
j = -1;
ll res = f(0, S1, S2, 0);
//ll res = dp[S1][S2][0];
if(res == INF)
cout << "-1" << '\n';
else
cout << res << '\n';
return 0;
}
int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int TET = 1e9;
//cin >> TET;
for (int i = 1; i <= TET; i++)
{
if (solve())
{
break;
}
#ifdef ONPC
cerr << "____________________________\n";
#endif
}
#ifdef ONPC
cerr << "\nfinished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec\n";
#endif
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 7624kb
input:
2 100 100 100 100 10 10 101 11 100 10
output:
110
result:
ok single line: '110'
Test #2:
score: 0
Accepted
time: 0ms
memory: 7640kb
input:
4 20 20 40 1000 20 20 6 6 5 5 10 10 1 1 10 10 1 1
output:
40
result:
ok single line: '40'
Test #3:
score: 0
Accepted
time: 2ms
memory: 7568kb
input:
2 20 5 10 10 5 5 10 10 5 5
output:
-1
result:
ok single line: '-1'
Test #4:
score: 0
Accepted
time: 2ms
memory: 7564kb
input:
5 10 10 7 6 4 2 4 4 2 2 2 4 1 1 4 4 2 2 9 9 6 7
output:
18
result:
ok single line: '18'
Test #5:
score: -100
Time Limit Exceeded
input:
50 500 500 31 8085460 27 5738750 35 6396250 28 3088390 104 11849007 54 8299872 16 3941084 11 1308473 2 12078306 1 8983355 3 8771257 2 6535023 6 2314939 4 398722 23 3498723 20 1276781 28 33264266 22 23291943 56 1421421 39 250597 23 365902 18 126347 18 15795320 14 11247902 23 3967562 20 1366149 2 7872...