結果
問題 | No.2712 Play more! |
ユーザー | tomo0608 |
提出日時 | 2024-03-31 14:20:18 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 174 ms / 2,000 ms |
コード長 | 9,709 bytes |
コンパイル時間 | 3,425 ms |
コンパイル使用メモリ | 278,160 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-09-30 23:46:31 |
合計ジャッジ時間 | 5,578 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,248 KB |
testcase_03 | AC | 1 ms
5,248 KB |
testcase_04 | AC | 1 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 1 ms
5,248 KB |
testcase_07 | AC | 64 ms
5,248 KB |
testcase_08 | AC | 66 ms
5,248 KB |
testcase_09 | AC | 66 ms
5,248 KB |
testcase_10 | AC | 1 ms
5,248 KB |
testcase_11 | AC | 30 ms
5,248 KB |
testcase_12 | AC | 174 ms
5,248 KB |
testcase_13 | AC | 19 ms
5,248 KB |
testcase_14 | AC | 88 ms
5,248 KB |
testcase_15 | AC | 158 ms
5,248 KB |
testcase_16 | AC | 10 ms
5,248 KB |
testcase_17 | AC | 4 ms
5,248 KB |
testcase_18 | AC | 21 ms
5,248 KB |
testcase_19 | AC | 4 ms
5,248 KB |
testcase_20 | AC | 32 ms
5,248 KB |
testcase_21 | AC | 13 ms
5,248 KB |
testcase_22 | AC | 152 ms
5,248 KB |
testcase_23 | AC | 5 ms
5,248 KB |
testcase_24 | AC | 17 ms
5,248 KB |
testcase_25 | AC | 4 ms
5,248 KB |
testcase_26 | AC | 21 ms
5,248 KB |
testcase_27 | AC | 31 ms
5,248 KB |
testcase_28 | AC | 49 ms
5,248 KB |
testcase_29 | AC | 18 ms
5,248 KB |
testcase_30 | AC | 164 ms
5,248 KB |
testcase_31 | AC | 49 ms
5,248 KB |
testcase_32 | AC | 42 ms
5,248 KB |
testcase_33 | AC | 2 ms
5,248 KB |
testcase_34 | AC | 2 ms
5,248 KB |
testcase_35 | AC | 2 ms
5,248 KB |
ソースコード
#pragma region competitive_programming #ifdef __LOCAL #define _GLIBCXX_DEBUG #endif #pragma GCC optimize("Ofast") #include<bits/stdc++.h> //#include "modint_plus.hpp" //typedef atcoder::modint1000000007 mint; //typedef atcoder::modint998244353 mint; //#include<atcoder/convolution> //#include "Formal_Power_Series.hpp" //typedef tomo0608::Formal_Power_Series<mint> fps; namespace tomo0608 { typedef long long ll; typedef long double ld; template <class T> using V = std::vector<T>; template <class T> using VV = V<V<T>>; template <class T> using VVV = V<VV<T>>; typedef std::pair<int, int> pii; typedef std::pair<long long, long long> pll; template<class... T>void input(T&... a) { (std::cin >> ... >> a); }; #define INT(...) int __VA_ARGS__; IN(__VA_ARGS__) #define LL(...) long long __VA_ARGS__; IN(__VA_ARGS__) #define CHAR(...) char __VA_ARGS__; IN(__VA_ARGS__) #define STR(...) string __VA_ARGS__; IN(__VA_ARGS__) #define DBL(...) double __VA_ARGS__; IN(__VA_ARGS__) #define VEC(type, name, size) std::vector<type> name(size);IN(name) #define VECVEC(type, name, h, w) std::vector<std::vector<type>> name(h, std::vector<type>(w));IN(name) template<class T1, class T2> std::istream& operator>>(std::istream& is, std::pair<T1, T2>& p) { is >> p.first >> p.second; return is; } template<class T1, class T2> std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p) { os << '(' << p.first << ", " << p.second << ')'; return os; } template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& v) { for (auto& e : v) is >> e; return is; } template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) { for (auto& e : v) os << e << ' '; return os; } template<typename T> std::ostream& operator << (std::ostream& os, std::set<T>& set_var) { os << "{"; for (auto itr = set_var.begin(); itr != set_var.end(); itr++) { os << *itr;++itr;if (itr != set_var.end()) os << ", ";itr--; }os << "}";return os; } template <typename T, typename U> std::ostream& operator<<(std::ostream& os, std::map<T, U>& map_var) { os << "{";for (auto itr = map_var.begin(); itr != map_var.end(); itr++) { os << *itr;itr++;if (itr != map_var.end()) os << ", ";itr--; }os << "}";return os; } template<int i, class T> void print_tuple(std::ostream&, const T&) {} template<int i, class T, class H, class ...Args> void print_tuple(std::ostream& os, const T& t) { if (i){os << ", ";} os << std::get<i>(t); print_tuple<i + 1, T, Args...>(os, t); } template<class ...Args> std::ostream& operator<<(std::ostream& os, const std::tuple<Args...>& t) { os << "{"; print_tuple<0, std::tuple<Args...>, Args...>(os, t); return os << "}"; } void IN() {} template <class Head, class... Tail> void IN(Head& head, Tail &...tail) { std::cin >> head; IN(tail...); } void print() { std::cout << '\n'; } template<class T, class... Ts>void print(const T& a, const Ts&... b) { std::cout << a; (std::cout << ... << (std::cout << ' ', b)); std::cout << '\n'; } void drop() { std::cout << '\n';exit(0); } template<class T, class... Ts>void drop(const T& a, const Ts&... b) { std::cout << a; (std::cout << ... << (std::cout << ' ', b)); std::cout << '\n';exit(0); } #ifdef __LOCAL void debug_out() { std::cerr << std::endl; } template < class Head, class... Tail> void debug_out(Head H, Tail... T) { std::cerr << ' ' << H; debug_out(T...); } #define debug(...) std::cerr << 'L' << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define dump(x) std::cerr << 'L' << __LINE__ << " " << #x << " = " << (x) << std::endl #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif #define rep1(a) for(long long i = 0; i < (a); i++) #define rep2(i, a) for(long long i = 0; i < (a); i++) #define rep3(i, a, b) for(long long i = (a); i < (b); i++) #define rep4(i, a, b, c) for(long long i = (a); i < (b); i += (c)) #define drep1(a) for(long long i = (a)-1; i >= 0; i--) #define drep2(i, a) for(long long i = (a)-1; i >= 0; i--) #define drep3(i, a, b) for(long long i = (a)-1; i >= (b); i--) #define drep4(i, a, b, c) for(long long i = (a)-1; i >= (b); i -= (c)) #define overload4(a, b, c, d, e, ...) e #define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__) #define drep(...) overload4(__VA_ARGS__, drep4, drep3, drep2, drep1)(__VA_ARGS__) #define endl '\n' struct io_setup { io_setup() { std::cin.tie(0); std::ios_base::sync_with_stdio(false); std::cout << std::setprecision(20); } }io_setup; } // namespace tomo0608 namespace tomo0608 { #define ALL(x) x.begin(),x.end() template <class T = long long, class S> T SUM(const S& v) { return accumulate(ALL(v), T(0)); } #define MIN(v) *min_element(ALL(v)) #define MAX(v) *max_element(ALL(v)) #define SORT(v) sort(ALL(v)) #define REVERSE(v) reverse(ALL(v)) #define RSORT(v) sort(ALL(v)); reverse(ALL(v)) #define UNIQUE(x) SORT(x), x.erase(unique(ALL(x)), x.end()) #define lb(c, x) distance((c).begin(), lower_bound(ALL(c), (x))) #define ub(c, x) distance((c).begin(), upper_bound(ALL(c), (x))) template <typename T> void zip(std::vector<T>& x) { std::vector<T> y = x;UNIQUE(y);for (int i = 0; i < x.size(); ++i) { x[i] = lb(y, x[i]); } } template<class T> using priority_queue_rev = std::priority_queue<T, std::vector<T>, std::greater<T>>; template<class T, class U> inline bool chmax(T& a, const U& b) { if (a < b) { a = b; return 1; } return 0; } template<class T, class U> inline bool chmin(T& a, const U& b) { if (a > b) { a = b; return 1; } return 0; } template<class T> inline int count_between(std::vector<T>& a, T l, T r) { return lower_bound(ALL(a), r) - lower_bound(ALL(a), l); } // [l, r) template<typename T> int bittest(T n, int k) { return (n >> k) & 1; } int topbit(signed t) { return t == 0 ? -1 : 31 - __builtin_clz(t); } int topbit(long long t) { return t == 0 ? -1 : 63 - __builtin_clzll(t); } int lowbit(signed a) { return a == 0 ? 32 : __builtin_ctz(a); } int lowbit(long long a) { return a == 0 ? 64 : __builtin_ctzll(a); } #define perm(v) for(bool permrepflag = true; (permrepflag ? exchange(permrepflag, false) : next_permutation(ALL(v)));) template <typename T, typename S> T ceil(T x, S y) { assert(y); return (y < 0 ? ceil(-x, -y) : (x > 0 ? (x + y - 1) / y : x / y)); } template <typename T, typename S> T floor(T x, S y) { assert(y); return (y < 0 ? floor(-x, -y) : (x > 0 ? x / y : x / y - (x % y == 0 ? 0 : 1))); } template <typename T> std::vector<int> id_sort(const std::vector<T>& v, bool greater = false) { int n = v.size(); std::vector<int> ret(n); std::iota(ALL(ret), 0); std::sort(begin(ret), end(ret), [&](int i, int j) { return greater ? v[i] > v[j] : v[i] < v[j]; }); return ret; } struct Random_Number_Generator { std::mt19937_64 mt; Random_Number_Generator() : mt(std::chrono::steady_clock::now().time_since_epoch().count()) {} // 区間 [l,r) の整数で乱数発生 int64_t operator()(int64_t l, int64_t r) { std::uniform_int_distribution<int64_t> dist(l, r - 1); return dist(mt); } // 区間 [0,r) の整数で乱数発生 int64_t operator()(int64_t r) { return (*this)(0, r); } } rng; struct Timer { std::chrono::system_clock::time_point start_time; Timer() { reset(); } void reset() { start_time = std::chrono::system_clock::now(); } int get_time() { std::chrono::system_clock::time_point now_time = std::chrono::system_clock::now(); return std::chrono::duration_cast<std::chrono::milliseconds>(now_time - start_time).count(); } } timer; } //using namespace atcoder; using namespace std; using namespace tomo0608; int dx[8] = { 1, 0, -1, 0, 1, 1, -1, -1 }; int dy[8] = { 0, 1, 0, -1, 1, -1, -1, 1 }; // インタラクティブ問題のときは出力するたびにcout.flush();を忘れない!!!!! void solve(); int main() { int codeforces = 1; //cin >> codeforces; while (codeforces--) { solve(); } return 0; } #pragma endregion const ll inf = 1e18; void solve() { LL(n, m); V<tuple<ll,ll,ll>> edges; VEC(ll, a, n); VV<ll> g(2*n), rg(2*n); rep(i, n){ edges.emplace_back(i,i+n, -a[i]); g[i].push_back(i+n); rg[i+n].push_back(i); } rep(i, m){ LL(x, y, z); x--,y--; edges.emplace_back(x+n, y, z); g[x+n].push_back(y); rg[y].push_back(x+n); } V<ll> f1(2*n, 0); f1[0] = 1; queue<int> que; que.emplace(0); while(!que.empty()){ int now = que.front();que.pop(); for(int to: g[now]){ if(f1[to]) continue; f1[to] = 1; que.emplace(to); } } V<ll> f2(2*n, 0); f2[2*n-1] = 1; que.emplace(2*n-1); while(!que.empty()){ int now = que.front();que.pop(); for(int to: rg[now]){ if(f2[to]) continue; f2[to] = 1; que.emplace(to); } } V<ll> dist(2*n, inf); dist[0] = 0; rep(t, 2*n-1){ for(auto [f, t, c]: edges){ if(dist[f] == inf) continue; chmin(dist[t], dist[f] + c); } } for(auto [f, t, c]: edges){ if(dist[f] == inf) continue; if(f1[f] && f2[t] && dist[t] > dist[f]+c){ cout << "inf" << endl; return; } } print(-dist[2*n-1]); }