結果
| 問題 |
No.1676 Coin Trade (Single)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-10-08 22:38:05 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 42 ms / 2,000 ms |
| コード長 | 2,361 bytes |
| コンパイル時間 | 3,018 ms |
| コンパイル使用メモリ | 283,704 KB |
| 実行使用メモリ | 9,088 KB |
| 最終ジャッジ日時 | 2025-10-08 22:38:12 |
| 合計ジャッジ時間 | 6,169 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 35 |
ソースコード
#include<bits/stdc++.h>
#if __has_include(<atcoder/all>)
#endif
using namespace std;
#define eb emplace_back
#define LL(...) ll __VA_ARGS__;lin(__VA_ARGS__)
#define FO(n) for(ll IJK=n;IJK-->0;)
#define fo(i,...) for(auto[i,i##stop,i##step]=for_range<ll>(0,__VA_ARGS__);i<i##stop;i+=i##step)
#define fe(a,e,...) for(auto&&__VA_OPT__([)e __VA_OPT__(,__VA_ARGS__]):a)
#define defpp template<ostream&o=cout>void pp(const auto&...a){[[maybe_unused]]const char*c="";((o<<c<<a,c=" "),...);o<<'\n';}void epp(const auto&...a){pp<cerr>(a...);}
#define entry defpp void main();void main2();}int main(){my::io();my::main();}namespace my{
namespace my{
void io(){cin.tie(nullptr)->sync_with_stdio(0);cout<<fixed<<setprecision(15);}
using ll=long long;
template<class T>constexpr auto for_range(T s,T b){T a=0;if(s)swap(a,b);return array{a-s,b,1-s*2};}
void lin(auto&...a){(cin>>...>>a);}
constexpr ll size10(auto x){x|=1;ll r=0;while(x>0)x/=10,++r;return r;}
template<class T>constexpr ll maxsize10(){return size10(numeric_limits<T>::max());}
bool amax(auto&a,const auto&b){return a<b?a=b,1:0;}
template<bool is_negative=false>struct infinity{
template<integral T>static constexpr T ones(size_t n){return n?ones<T>(n-1)*10+1:0;}
template<integral T>constexpr operator T()const{static constexpr T v=ones<T>(maxsize10<T>())*(1-is_negative*2);return v;}
constexpr auto operator-()const{return infinity<!is_negative>();}
};
constexpr infinity oo;
template<class...A>using pack_back_t=tuple_element_t<sizeof...(A)-1,tuple<A...>>;
}
namespace my{
template<class V>struct vec;
template<int D,class T>struct hvec_helper{using type=vec<typename hvec_helper<D-1,T>::type>;};
template<class T>struct hvec_helper<0,T>{using type=T;};
template<int D,class T>using hvec=hvec_helper<D,T>::type;
template<class V>struct vec:vector<V>{
using vector<V>::vector;
auto&emplace_back(auto&&...a){vector<V>::emplace_back(std::forward<decltype(a)>(a)...);return*this;}
};
template<class...A>requires(sizeof...(A)>=2)vec(const A&...a)->vec<hvec<sizeof...(A)-2,pack_back_t<A...>>>;
}
namespace my{entry
void main(){
LL(N,K);
vec<vec<ll>>g(N);
vec<ll>a(N);
fo(i,N){
lin(a[i]);
LL(M);
FO(M){
LL(p);--p;
g[p].eb(i);
}
}
vec dp(N,ll(-oo));
dp[0]=0;
fo(i,N-1){
amax(dp[i+1],dp[i]);
fe(g[i],j)amax(dp[j],dp[i]+a[j]-a[i]);
}
pp(dp[N-1]);
}}