QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#358088#3173. Cakey McCakeFacePetroTarnavskyi#WA 1ms3920kbC++201.7kb2024-03-19 17:10:032024-03-19 17:10:04

Judging History

This is the latest submission verdict.

  • [2024-03-19 17:10:04]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3920kb
  • [2024-03-19 17:10:03]
  • Submitted

answer

#include <bits/stdc++.h>

using namespace std;

#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--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

const int N = 10'474;
const int INF = 1e9 + 47;
vector<pair<int, PII>> g[N];
bool used[N];
int cost[N];
int pres[N];
int deg[N];
map<string, int> m;

int add(string s)
{
	if (!m.count(s))
		m[s] = SZ(m);
	return m[s];
}

VI tps;

void dfs(int v)
{
	used[v] = true;
	for (auto [to, _] : g[v])
		if (!used[to])
			dfs(to);
	tps.PB(v);
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int b;
	int n;
	cin >> b >> n;
	FOR (i, 0, n)
	{
		string s, t;
		cin >> s >> t;
		int u = add(s);
		int v = add(t);
		cin >> s;
		int c, p;
		cin >> c >> p;
		g[v].PB({u, {c, p}});
		deg[u]++;
	}
	FOR (i, 0, SZ(m))
	{
		if (!used[i])
			dfs(i);
	}
	reverse(ALL(tps));
	FOR (i, 0, SZ(m))
	{
		cost[i] = INF;
		pres[i] = -INF;
	}
	for (auto v : tps)
	{
		if (deg[v] == 0)
		{
			cost[v] = 0;
			pres[v] = 0;
		}
		for (auto [to, par] : g[v])
		{
			auto [c, p] = par;
			if (cost[to] > cost[v] + c || (cost[to] == cost[v] + c && pres[to] < pres[v] + p))
			{
				cost[to] = cost[v] + c;
				pres[to] = pres[v] + p;
			}
		}
	}
	VI dp(N, 0);
	FOR (i, 0, SZ(m))
	{
		RFOR (j, N - cost[i], 0)
		{
			dp[j + cost[i]] = max(dp[j + cost[i]], dp[j] + pres[i]);
		}
	}
	int idx = max_element(dp.begin(), dp.begin() + b + 1) - dp.begin();
	cout << dp[idx] << '\n';
	cout << idx << '\n';
	
	
	
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3920kb

input:

5
5
0 10 12 20 30
1 5 17 27 50

output:

0
0

result:

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