結果
| 問題 |
No.45 回転寿司
|
| ユーザー |
vjudge1
|
| 提出日時 | 2025-04-17 17:11:56 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,450 bytes |
| コンパイル時間 | 2,864 ms |
| コンパイル使用メモリ | 183,932 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-04-17 17:12:00 |
| 合計ジャッジ時間 | 3,986 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
ソースコード
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// use when u need indexing in sets like (when you need lower upper bound while frequently updating set)
// idx.order_of_key(value) for nums<value idx.order_of_key(value+1) for nums<=value
#define int long long
#define ld long double
#define yesno(b) cout << ((b) ? "YES" : "NO") << "\n";
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define mod 1000000007
#define mod2 998244353
const int inf = 1e17 + 1;
#define forn(i, a, b) for (int i = a; i < b; i++)
#define forr(i, a, b) for (int i = a; i >= b; i--)
#define input(vec, n) for(int z = 0; z < (n); z++) cin >> vec[z];
int solv_(int idx,vi &dp,int n,vi &arr){
if(idx>=n) return 0LL;
else if(dp[idx]!=-1) return dp[idx];
return dp[idx]=max(arr[idx]+solv_(idx+2,dp,n,arr),solv_(idx+1,dp,n,arr));
}
void solve() {
int n;
cin>>n;
vi arr(n),dp(n,-1);
forn(i,0,n){
cin>>arr[i];
}
cout<<solv_(0,dp,n,arr);
}
int32_t main(){
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
int t=1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
vjudge1