結果
| 問題 |
No.161 制限ジャンケン
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-20 00:14:59 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 2,221 bytes |
| コンパイル時間 | 914 ms |
| コンパイル使用メモリ | 71,032 KB |
| 最終ジャッジ日時 | 2025-01-09 21:47:00 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp:49:17: error: ‘numeric_limits’ was not declared in this scope
49 | T inf = numeric_limits<T>::max() / 3;
| ^~~~~~~~~~~~~~
main.cpp:49:33: error: expected primary-expression before ‘>’ token
49 | T inf = numeric_limits<T>::max() / 3;
| ^
main.cpp:49:39: error: no matching function for call to ‘max()’
49 | T inf = numeric_limits<T>::max() / 3;
| ~~~~~^~
In file included from /usr/include/c++/13/string:51,
from /usr/include/c++/13/bits/locale_classes.h:40,
from /usr/include/c++/13/bits/ios_base.h:41,
from /usr/include/c++/13/ios:44,
from /usr/include/c++/13/ostream:40,
from /usr/include/c++/13/iostream:41,
from main.cpp:1:
/usr/include/c++/13/bits/stl_algobase.h:257:5: note: candidate: ‘template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)’
257 | max(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/13/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed:
main.cpp:49:39: note: candidate expects 2 arguments, 0 provided
49 | T inf = numeric_limits<T>::max() / 3;
| ~~~~~^~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)’
303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note: template argument deduction/substitution failed:
main.cpp:49:39: note: candidate expects 3 arguments, 0 provided
49 | T inf = numeric_limits<T>::max() / 3;
| ~~~~~^~
ソースコード
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
template <typename T>
class MinCostFlow
{
public:
MinCostFlow(int n) : n(n), capacity(n, vector<T>(n)), cost(n, vector<T>(n)), edge(n), prev(n) {}
void add_edge(int src, int dst, T cap, T cos)
{
capacity[src][dst] = cap;
capacity[dst][src] = 0;
cost[src][dst] = cos;
cost[dst][src] = -cos;
edge[src].push_back(dst);
edge[dst].push_back(src);
}
T min_cost_flow(int s, int t, T f)
{
T res = 0;
h.assign(n, 0);
while (f > 0)
{
if (!dijkstra(s, t))
return -1;
for (int i = 0; i < n; ++i)
h[i] += min_cost[i];
T d = f;
for (int v = t; v != s; v = prev[v])
d = min(d, capacity[prev[v]][v]);
f -= d;
res += d * h[t];
for (int v = t; v != s; v = prev[v])
{
capacity[prev[v]][v] -= d;
capacity[v][prev[v]] += d;
}
}
return res;
}
private:
int n;
T inf = numeric_limits<T>::max() / 3;
vector<vector<T>> capacity, cost;
vector<vector<int>> edge;
vector<T> min_cost, h;
vector<int> prev;
bool dijkstra(int s, int t)
{
min_cost.assign(n, inf);
min_cost[s] = 0;
priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> pq;
pq.emplace(0, s);
while (!pq.empty())
{
int c = pq.top().first;
int v = pq.top().second;
pq.pop();
if (min_cost[v] < c)
continue;
for (int nv : edge[v])
{
if (capacity[v][nv] > 0 && min_cost[nv] > min_cost[v] + cost[v][nv] + h[v] - h[nv])
{
min_cost[nv] = min_cost[v] + cost[v][nv] + h[v] - h[nv];
prev[nv] = v;
pq.emplace(min_cost[nv], nv);
}
}
}
return min_cost[t] != inf;
}
};
int g, c, p, n, a[4], b[4];
string s;
int main()
{
cin >> a[0] >> a[1] >> a[2] >> s;
n = (int)s.size();
for (int i = 0; i < n; ++i) {
if (s[i] == 'G') ++b[0];
if (s[i] == 'C') ++b[1];
if (s[i] == 'P') ++b[2];
}
MinCostFlow<int> mcf(8);
int INF = 333;
int s = 6;
int t = 7;
for (int i = 0; i < 3; ++i) {
mcf.add_edge(s, i, a[i], 0);
mcf.add_edge(i + 3, t, b[i], 0);
mcf.add_edge(i, i + 3, INF, -1);
mcf.add_edge(i, (i + 4) % 3 + 3, INF, -3);
mcf.add_edge(i, (i + 5) % 3 + 3, INF, 0);
}
cout << -mcf.min_cost_flow(s, t, n) << endl;
return 0;
}