QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#392175#3791. Interesting Calculatorucup-team1251100 ✓908ms38392kbC++171.7kb2024-04-17 10:49:032024-04-17 10:49:04

Judging History

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

  • [2024-04-17 10:49:04]
  • 评测
  • 测评结果:100
  • 用时:908ms
  • 内存:38392kb
  • [2024-04-17 10:49:03]
  • 提交

answer

#include<iostream>
#include<queue>
#include<utility>
#include<vector> 
using namespace std;
#define ll long long
#define PII pair<ll, int>
const int N = 1e5 + 10, M = N * 35;

int x, y;
int e[M], ne[M], h[N], idx, times[N], cnt = 1;
ll dist[N], w[M], ww;
bool vis[N];

void add(int a, int b, ll 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;
		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])
				times[j] = min(times[ver] + 1, times[j]);
			else if (dist[j] > dist[ver] + w[i])
			{
				dist[j] = dist[ver] + w[i];
				heap.push({dist[j], j}); 
				times[j] = times[ver] + 1;
			}
		}
	}
}
void solve()
{
	idx = 0;
	for (int i = 0; i <= y; i ++)	
	{
		h[i] = -1;
		vis[i] = 0;
		dist[i] = 1e15;
		times[i] = 2e5; 
	}
	cout << "Case " << cnt ++ << ": ";
	cin >> ww;
	for (int j = 1; j * 10 <= y; j ++)
		add(j, j * 10, ww);
	for (int i = 1; i < 10; i ++)
	{
		cin >> ww;
		for (int j = 0; j * 10 + i <= y; j ++)
			add(j, j * 10 + i, ww);
	}
	cin >> ww;
	for (int i = 1; i < 10; i ++)
	{
		cin >> ww;
		for (int j = 0; j + i <= y; j ++)
			add(j, j + i, ww);
	}
	cin >> ww;
	for (int j = 0; j < y; j ++)
		add(j, 0, ww);
	cin >> ww;
	for (int i = 2; i < 10; i ++)
	{
		cin >> ww;
		for (int j = 0; j * i <= y; j ++)
			add(j, j * i, ww);
	}
	dij();
	cout << dist[y] << ' ' << times[y] << '\n';
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	while (cin >> x >> y)
		solve();
	return 0;
 } 

详细

Test #1:

score: 100
Accepted
time: 908ms
memory: 38392kb

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:

Case 1: 9 4
Case 2: 12 3
Case 3: 500000 5
Case 4: 49999 49999
Case 5: 700000 7
Case 6: 68382 10
Case 7: 112558 11
Case 8: 130701 18
Case 9: 63820 10
Case 10: 225950 7
Case 11: 198287 11
Case 12: 123217 19
Case 13: 91914 10
Case 14: 137984 11
Case 15: 85481 22
Case 16: 180261 12
Case 17: 26654 9
Case...

result:

ok 30 lines