QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#391900 | #3791. Interesting Calculator | ucup-team1251 | 0 | 0ms | 0kb | C++17 | 1.7kb | 2024-04-16 21:38:35 | 2024-04-16 21:38:36 |
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;
}
详细
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...