結果

問題 No.505 カードの数式2
コンテスト
ユーザー Ut.k
提出日時 2017-04-21 23:39:54
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
RE  
実行時間 -
コード長 968 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 788 ms
コンパイル使用メモリ 83,212 KB
実行使用メモリ 7,976 KB
最終ジャッジ日時 2026-04-03 03:33:36
合計ジャッジ時間 4,385 ms
ジャッジサーバーID
(参考情報)
judge5_1 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14 WA * 4 RE * 11
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int opmax(int, int)':
main.cpp:15:8: warning: ignoring return value of 'const _Tp& std::max(const _Tp&, const _Tp&) [with _Tp = int]', declared with attribute 'nodiscard' [-Wunused-result]
   15 |     max(max(a + b, a - b), a * b);
      |     ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/string:53,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/locale_classes.h:42,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/ios_base.h:43,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/ios:46,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/ostream.h:43,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/ostream:42,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/iostream:43,
                 from main.cpp:1:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_algobase.h:258:5: note: declared here
  258 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
main.cpp: In function 'int opmin(int, int)':
main.cpp:22:8: warning: ignoring return value of 'const _Tp& std::min(const _Tp&, const _Tp&) [with _Tp = int]', declared with attribute 'nodiscard' [-Wunused-result]
   22 |     min(min(a + b, a - b), a * b);
      |     ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_algobase.h:234:5: note: declared here
  234 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
using namespace std;

int max4(int a, int b, int c, int d) {
  return max(max(a, b), max(c, d));
}

int min4(int a, int b, int c, int d) {
  return min(min(a, b), min(c, d));
}

int opmax(int a, int b) {
  if (b == 0) {
    max(max(a + b, a - b), a * b);
  }
  return max4(a + b, a - b, a * b, a / b);
}

int opmin(int a, int b) {
  if (b == 0) {
    min(min(a + b, a - b), a * b);
  }
  return min4(a + b, a - b, a * b, a / b);
}

int main() {
  int N;
  cin >> N;

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

  vector<vector<int> > DP(N);
  for (int i = 0; i < N; i++) {
    DP[i].resize(2);
    DP[i][0] = DP[i][1] = 0;
  }

  DP[0][0] = DP[0][1] = a[0];
  for (int i = 1; i < N; i++) {
    DP[i][0] = max(opmax(DP[i - 1][0], a[i]),
		   opmax(DP[i - 1][1], a[i]));
    DP[i][1] = min(opmin(DP[i - 1][0], a[i]),
		   opmin(DP[i - 1][1], a[i]));
  }

  cout << DP[N - 1][0] << endl;

  return 0;
}
0