結果

問題 No.45 回転寿司
ユーザー vintersn0w
提出日時 2018-05-08 18:19:11
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,515 bytes
コンパイル時間 878 ms
コンパイル使用メモリ 72,752 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-27 18:52:32
合計ジャッジ時間 2,047 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <cmath>

using namespace std;
typedef uint uint32_t;

int N;
int v[1005] = {0};
int s[1005][2]= {0};
// int s[1005] = {-1};

int search(int idx, int able) {
    if (idx == N) return 0;
    if (s[idx][able] > 0) return s[idx][able];

    // cout << 'h' << endl;
    if (s[idx][0] == 0) {
        s[idx][0] = search(idx+1, 1);
        if (able == 0) {
            return s[idx][0];
        }
    }

    s[idx][1] = search(idx+1, 0) + v[idx];
    // cout << idx << '\t' << s[idx][0] << '\t' << s[idx][1] << endl;
    int res = max(s[idx][0], s[idx][1]);
    return res;
}


int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> v[i];
    }

    cout << search(0, 1) << endl;

    // for (int i = 0; i < N; i++) {
    //     cout << s[i][0] << '\t';
    // }
    // cout << endl;
    // for (int i = 0; i < N; i++) {
    //     cout << s[i][1] << '\t';
    // }
    // cout << endl;

    // int p=0;
    // bool able=true;
    // for (int i = 0; i < N; i++) {
    //     if (v[i] + v[i+2] < v[i+1]) {
    //         able=true;
    //         continue;
    //     }
    //     if (v[i] + v[i+2] > v[i+1] + v[i+3] && able) {
    //         able = false;
    //         p += v[i];
    //         continue;
    //     }
    //     if (v[i] > v[i+1] && able) {
    //         able = false;
    //         p += v[i];
    //         continue;
    //     }
    //     able = true;
    // }
    // cout << p << endl;
}
0