結果

問題 No.258 回転寿司(2)
コンテスト
ユーザー firiexp
提出日時 2019-10-29 14:41:03
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,119 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 884 ms
コンパイル使用メモリ 99,900 KB
最終ジャッジ日時 2026-01-25 16:59:25
合計ジャッジ時間 1,277 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp:14:13: エラー: ‘uint32_t’ does not name a type
   14 | using u32 = uint32_t;
      |             ^~~~~~~~
main.cpp:11:1: 備考: ‘uint32_t’ is defined in header ‘<cstdint>’; this is probably fixable by adding ‘#include <cstdint>’
   10 | #include <cmath>
  +++ |+#include <cstdint>
   11 | 
main.cpp:17:39: エラー: ‘::numeric_limits’ has not been declared
   17 | template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;
      |                                       ^~~~~~~~~~~~~~
main.cpp:17:55: エラー: expected primary-expression before ‘>’ token
   17 | template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;
      |                                                       ^
main.cpp:17:61: エラー: ‘max()’ の呼び出しに適合する関数がありません
   17 | template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;
      |                                                        ~~~~~^~
main.cpp:17:61: 備考: there are 4 candidates
次のファイルから読み込み:  /usr/local/gcc-15/include/c++/15.2.0/string:53,
         次から読み込み:  /usr/local/gcc-15/include/c++/15.2.0/bits/locale_classes.h:42,
         次から読み込み:  /usr/local/gcc-15/include/c++/15.2.0/bits/ios_base.h:43,
         次から読み込み:  /usr/local/gcc-15/include/c++/15.2.0/ios:46,
         次から読み込み:  /usr/local/gcc-15/include/c++/15.2.0/bits/ostream.h:43,
         次から読み込み:  /usr/local/gcc-15/include/c++/15.2.0/ostream:42,
         次から読み込み:  /usr/local/gcc-15/include/c++/15.2.0/iostream:43,
         次から読み込み:  main.cpp:1:
/usr/local/gcc-15/include/c++/15.2.0/bits/stl_algobase.h:258:5: 備考: 候補 1: ‘template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)’
  258 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/local/gcc-15/include/c++/15.2.0/bits/stl_algobase.h

ソースコード

diff #
raw source code

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (auto &&i : v) scanf("%d", &i);
    vector<int> dp(n+1);
    vector<int> from(n+1);
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j < i-1; ++j) {
            if(dp[i] < dp[j]){
                dp[i] = dp[j];
                from[i] = j;
            }
        }
        dp[i] += v[i-1];
    }
    int cur = max_element(dp.begin(),dp.end()) - dp.begin();
    int ans = dp[cur];
    vector<int> ans2;
    while(cur){
        ans2.emplace_back(cur);
        cur = from[cur];
    }
    reverse(ans2.begin(),ans2.end());
    cout << ans << "\n";
    for (int i = 0; i < ans2.size(); ++i) {
        if(i) printf(" ");
        printf("%d", ans2[i]);
    }
    puts("");
    return 0;
}
0