結果

問題 No.45 回転寿司
ユーザー suakiisuakii
提出日時 2018-06-07 13:21:27
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 314 ms / 5,000 ms
コード長 556 bytes
コンパイル時間 1,156 ms
コンパイル使用メモリ 143,776 KB
実行使用メモリ 66,596 KB
最終ジャッジ日時 2023-08-27 16:28:03
合計ジャッジ時間 5,217 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
15,348 KB
testcase_01 AC 111 ms
26,668 KB
testcase_02 AC 206 ms
44,968 KB
testcase_03 AC 246 ms
53,492 KB
testcase_04 AC 119 ms
28,712 KB
testcase_05 AC 5 ms
4,488 KB
testcase_06 AC 84 ms
21,672 KB
testcase_07 AC 201 ms
44,772 KB
testcase_08 AC 25 ms
9,052 KB
testcase_09 AC 237 ms
51,980 KB
testcase_10 AC 57 ms
16,064 KB
testcase_11 AC 18 ms
7,544 KB
testcase_12 AC 217 ms
48,140 KB
testcase_13 AC 5 ms
4,388 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 69 ms
18,420 KB
testcase_16 AC 32 ms
10,376 KB
testcase_17 AC 53 ms
15,180 KB
testcase_18 AC 33 ms
10,760 KB
testcase_19 AC 166 ms
38,244 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 4 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 71 ms
18,720 KB
testcase_27 AC 159 ms
36,696 KB
testcase_28 AC 80 ms
20,600 KB
testcase_29 AC 138 ms
32,372 KB
testcase_30 AC 144 ms
33,812 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 314 ms
66,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
int n, ans;
int a[1001];
int dp[1001][100000];

int f(int pos, int sum) {
    
    if (pos >= n)
        return sum;
    else if (dp[pos][sum])
        return dp[pos][sum];
    else
        return dp[pos][sum] = max(f(pos+1, sum), f(pos+2, sum+a[pos]));
        
    
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    
    cout << f(0, 0) << endl;
  
    return 0;
}


0