QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#391900#3791. Interesting Calculatorucup-team12510 0ms0kbC++171.7kb2024-04-16 21:38:352024-04-16 21:38:36

Judging History

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

  • [2024-04-16 21:38:36]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-04-16 21:38:35]
  • 提交

answer

#include<iostream>
#include<queue>
#include<utility>
#include<vector> 
using namespace std;
#define PII pair<int, int>
#define int long long
const int N = 1e5 + 10;
int x, y, ww;
int e[N], ne[N], h[N], w[N], dist[N], idx, times[N], cnt = 1;
bool vis[N];
void add(int a, int b, int ww)
{
	e[idx] = b, ne[idx] = h[a], w[idx] = ww, h[a] = idx ++;
}
void dij()
{
	priority_queue<PII, vector<PII>, greater<PII>> heap;
	heap.push({0, x});
	dist[x] = 0;
	times[x] = 0;
	while (heap.size())
	{
		auto t = heap.top();
		heap.pop();
		int ver = t.second;
//		cout << ver << "?sdfsd";
		if (vis[ver])	continue;
		vis[ver] = 1;
		for (int i = h[ver]; i != -1; i = ne[i])
		{
			int j = e[i];
			if (dist[j] > dist[ver] + w[i])
			{
				dist[j] = dist[ver] + w[i];
				heap.push({dist[j], j}); 
//				cout << "sdf ";
				times[j] = times[ver] + 1;
			}
			else if (dist[j] == dist[ver] + w[i])
				times[j] = min(times[ver] + 1, times[j]);
		}
	}
}
void solve()
{
	idx = 0;
	for (int i = 0; i <= y; i ++)	
	{
		h[i] = -1;
		vis[i] = 0;
		dist[i] = times[i] = 0x3f3f3f3f;
	}
	cout << "Case " << cnt ++ << ": ";
	for (int i = 0; i < 10; i ++)
	{
		cin >> ww;
		for (int j = 0; j <= y; j ++)
		{
			if (!i && !j)	continue;
			if (j * 10 + i <= y)
				add(j, j * 10 + i, ww);
		}
	}
	for (int i = 0; i < 10; i ++)
	{
		cin >> ww;
		if (i == 0)	continue;
		for (int j = 0; j <= y; j ++)
			if (j + i <= y)
				add(j, j + i, ww);
	}
	for (int i = 0; i < 10; i ++)
	{
		cin >> ww;
		if (i == 1)	continue;
		for (int j = 0; j <= y; j ++)
			if (j * i <= y)
				add(j, j * i, ww);
	}
	
	dij();
	cout << dist[y] << ' ' << times[y] << '\n';
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	while (cin >> x >> y)
		solve();
	return 0;
 } 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

12 256
100 100 100 1 100 100 100 100 100 100
6 5 4 3 2 1 2 3 4 5
100 100 10 100 100 100 100 100 100 100
12 256
100 100 100 1 100 100 100 100 100 100
100 100 100 100 100 1 100 100 100 100
100 100 10 100 100 100 100 100 100 100
1 100000
100000 100000 100000 100000 100000 100000 100000 100000 100000 10...

output:


result: