Submission #2560220
Source Code Expand
#include <limits>
using ll = long long;
constexpr int INF = std::numeric_limits<int>::max() / 2;
constexpr ll LNF = std::numeric_limits<ll>::max() / 2;
#include <bits/stdc++.h>
using namespace std;
vector<pair<ll, int>> dijkstra(vector<vector<pair<int, ll>>> const &graph,
int start) {
vector<pair<ll, int>> result(graph.size(), make_pair(LNF, 0));
priority_queue<pair<ll, int>, vector<pair<ll, int>>,
greater<pair<ll, int>>>
que;
result[start] = make_pair(0, 0);
que.push(make_pair(0, start));
ll cost;
int from;
while (!que.empty()) {
tie(cost, from) = que.top();
que.pop();
if (cost > result[from].first) continue;
for (auto to : graph[from]) {
if (result[to.first].first > result[from].first + to.second) {
result[to.first].first = result[from].first + to.second;
result[to.first].second = result[from].second + 1;
que.push(make_pair(result[to.first].first, to.first));
}
}
}
return result;
}
int main() {
int N;
ll x;
cin >> N >> x;
vector<vector<pair<int, ll>>> graph(N + 1);
for (int i = 0; i < N; i++) {
ll cost;
cin >> cost;
graph[0].push_back(make_pair(i + 1, cost));
graph[(i + (N - 1)) % N + 1].push_back(make_pair(i + 1, x));
}
auto result = dijkstra(graph, 0);
auto max_steps = accumulate(
result.begin(), result.end(), 0,
[](auto const &s, auto const &a) { return max(s, a.second); });
max_steps--;
cerr << max_steps << endl;
auto sum_summon =
accumulate(result.begin() + 1, result.end(), 0ll,
[&](auto const &s, auto const &a) {
return s + a.first - ((a.second - 1) * x);
});
cout << sum_summon + x * max_steps << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
B - Colorful Slimes |
User |
statiolake |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
1994 Byte |
Status |
WA |
Exec Time |
3 ms |
Memory |
512 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 400 |
Status |
|
|
Set Name |
Test Cases |
Sample |
0_00.txt, 0_01.txt, 0_02.txt |
All |
0_00.txt, 0_01.txt, 0_02.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt |
Case Name |
Status |
Exec Time |
Memory |
0_00.txt |
AC |
1 ms |
256 KB |
0_01.txt |
AC |
1 ms |
256 KB |
0_02.txt |
AC |
1 ms |
256 KB |
1_00.txt |
AC |
2 ms |
512 KB |
1_01.txt |
AC |
2 ms |
512 KB |
1_02.txt |
AC |
2 ms |
512 KB |
1_03.txt |
AC |
2 ms |
512 KB |
1_04.txt |
WA |
2 ms |
512 KB |
1_05.txt |
AC |
2 ms |
512 KB |
1_06.txt |
WA |
2 ms |
512 KB |
1_07.txt |
AC |
2 ms |
512 KB |
1_08.txt |
WA |
2 ms |
512 KB |
1_09.txt |
AC |
2 ms |
512 KB |
1_10.txt |
WA |
2 ms |
512 KB |
1_11.txt |
WA |
2 ms |
512 KB |
1_12.txt |
WA |
2 ms |
512 KB |
1_13.txt |
WA |
2 ms |
512 KB |
1_14.txt |
WA |
3 ms |
512 KB |
1_15.txt |
WA |
2 ms |
512 KB |
1_16.txt |
WA |
2 ms |
512 KB |
1_17.txt |
WA |
3 ms |
512 KB |