QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#726498#2372. Level UpLaVuna47WA 50ms11680kbC++202.6kb2024-11-09 01:45:472024-11-09 01:45:49

Judging History

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

  • [2024-11-09 01:45:49]
  • 评测
  • 测评结果:WA
  • 用时:50ms
  • 内存:11680kb
  • [2024-11-09 01:45:47]
  • 提交

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[2][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)
				for(auto& y: j)
					y = INF;
	FOR(s1, 0, S1+1)
	{
		dp[0][s1][0][1] = 0;
		dp[1][s1][0][1] = 0;
	}
	
	RFOR(p,n,0)
	{
		
		FOR(s1, 0, S1+1)
		{
			FOR(s2, 0, S2+1)
			{
				FOR(lvl, 0, 2)
				{
					ll res = INF;
					res = min(res, a[p].t2 + dp[(p+1)&1][s1][max(0ll,s2 - a[p].ex2)][lvl]);
					res = min(res, dp[(p+1)&1][s1][s2][lvl]);
					if(lvl == 0)
					{
						if(s1 - a[p].ex1 <= 0)
						{
							res = min(res, a[p].t1 + dp[(p+1)&1][0][max(0ll, s2 - abs(s1 - a[p].ex1))][1]);
						}
						else
						{
							res = min(res, a[p].t1 + dp[(p+1)&1][max(0ll, s1 - a[p].ex1)][s2][lvl]);
						}
					}
					dp[p&1][s1][s2][lvl] = res;
				}
			}
		}
	}



	ll res = min(dp[0][S1][S2][0], dp[1][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
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 11608kb

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: 2ms
memory: 11588kb

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: 0ms
memory: 11680kb

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: 11592kb

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
Wrong Answer
time: 50ms
memory: 11612kb

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...

output:

-1

result:

wrong answer 1st lines differ - expected: '503438008', found: '-1'