結果
問題 | No.2712 Play more! |
ユーザー | blue_jam |
提出日時 | 2024-03-31 15:13:24 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,036 bytes |
コンパイル時間 | 4,808 ms |
コンパイル使用メモリ | 271,068 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-09-30 20:26:19 |
合計ジャッジ時間 | 6,329 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,820 KB |
testcase_02 | AC | 2 ms
6,816 KB |
testcase_03 | AC | 2 ms
6,816 KB |
testcase_04 | WA | - |
testcase_05 | AC | 2 ms
6,820 KB |
testcase_06 | AC | 2 ms
6,816 KB |
testcase_07 | AC | 36 ms
6,820 KB |
testcase_08 | AC | 36 ms
6,820 KB |
testcase_09 | AC | 36 ms
6,816 KB |
testcase_10 | WA | - |
testcase_11 | AC | 19 ms
6,820 KB |
testcase_12 | AC | 67 ms
6,820 KB |
testcase_13 | AC | 20 ms
6,820 KB |
testcase_14 | AC | 48 ms
6,820 KB |
testcase_15 | AC | 104 ms
6,820 KB |
testcase_16 | AC | 11 ms
6,816 KB |
testcase_17 | AC | 5 ms
6,820 KB |
testcase_18 | AC | 9 ms
6,820 KB |
testcase_19 | AC | 5 ms
6,816 KB |
testcase_20 | AC | 31 ms
6,820 KB |
testcase_21 | AC | 15 ms
6,816 KB |
testcase_22 | AC | 46 ms
6,816 KB |
testcase_23 | AC | 8 ms
6,816 KB |
testcase_24 | AC | 10 ms
6,816 KB |
testcase_25 | AC | 6 ms
6,820 KB |
testcase_26 | AC | 9 ms
6,816 KB |
testcase_27 | AC | 27 ms
6,816 KB |
testcase_28 | AC | 29 ms
6,820 KB |
testcase_29 | AC | 14 ms
6,820 KB |
testcase_30 | AC | 83 ms
6,816 KB |
testcase_31 | AC | 32 ms
6,816 KB |
testcase_32 | AC | 29 ms
6,820 KB |
testcase_33 | AC | 2 ms
6,816 KB |
testcase_34 | AC | 2 ms
6,816 KB |
testcase_35 | AC | 2 ms
6,820 KB |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using namespace atcoder; using ll = long long; using mint = modint998244353; ll solveF(ll H, ll W, ll K) { vector<vector<mint>> dp(W + 1, vector<mint>(1 << H, 0)); dp[0][(1 << H) - 1] = 1LL; for (ll j = 0; j < W; j++) { for (ll s = 0; s < (1 << H); s++) { for (ll t = 0; t < (1 << H); t++) { ll u = s & t; ll cnt = __builtin_popcount(u); if (cnt >= K) { dp[j + 1][t] += dp[j][s]; } } } } mint ans = 0; for (ll s = 0; s < (1 << H); s++) { ans += dp[W][s]; } return ans.val(); } ll solveFNaive(ll H, ll W, ll K) { return 0; } typedef ll Weight; struct Edge{ int from, to; Weight weight; int rev; // 無向グラフの対の辺 Edge(int from, int to, Weight weight) : from(from), to(to), weight(weight) { } Edge(int from, int to, Weight weight, int rev) : from(from), to(to), weight(weight), rev(rev){ } }; bool operator < (const Edge &a, const Edge &b){ if(a.weight != b.weight) return a.weight > b.weight; if(a.from != b.from) return a.from > b.from; return a.to > b.to; } typedef vector<Edge> Edges; typedef vector<Edges> Graph; typedef vector<Weight> Array; typedef vector<Array> Matrix; void addFlowEdge(Graph &g, int a, int b, Weight c){ g[a].push_back(Edge(a, b, c, g[b].size())); g[b].push_back(Edge(b, a, 0, g[a].size() - 1)); } void addUndirectedEdge(Graph &g, int a, int b, Weight c){ g[a].push_back(Edge(a, b, c, g[b].size())); g[b].push_back(Edge(b, a, c, g[a].size() - 1)); } const Weight INF = 1e17; bool bellmanFord(const Graph &g, int s, vector<Weight> &dist, vector<int> &prev){ int n = g.size(); bool nagativeRoop = false; dist.assign(n, INF); dist[s] = 0; prev.assign(n, -1); for(int k = 0; k < n; ++k){ for(int v = 0; v < n; ++v){ for(Edges::const_iterator i=g[v].begin(); i != g[v].end(); ++i){ if(dist[i -> from] != INF && dist[i -> to] > dist[i -> from] + i -> weight){ dist[i -> to] = dist[i -> from] + i-> weight; prev[i -> to] = i -> from; if(k == n - 1){ dist[i -> to] = -INF; nagativeRoop = true; } } } } } return nagativeRoop; } int main() { ll N, M; cin >> N >> M; vector<ll> A(N); for (ll i = 0; i < N; i++) { cin >> A[i]; } Graph g(N); for (ll i = 0; i < M; i++) { ll a, b, c; cin >> a >> b >> c; a--; b--; g[a].push_back(Edge(a, b, c - A[b])); } vector<Weight> dist; vector<int> prev; bool negativeRoop = bellmanFord(g, 0, dist, prev); if (negativeRoop) { cout << "inf" << endl; } else { cout << A[0] - dist[N - 1] << endl; } return 0; }