結果

問題 No.4 おもりと天秤
ユーザー 久我山菜々久我山菜々
提出日時 2018-09-29 16:28:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 746 bytes
コンパイル時間 907 ms
コンパイル使用メモリ 86,552 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 12:53:15
合計ジャッジ時間 1,981 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
5,376 KB
testcase_07 WA -
testcase_08 AC 2 ms
5,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 2 ms
5,376 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:8:11: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
    8 | int solve(auto b, auto e, int w, int c) {
      |           ^~~~
main.cpp:8:19: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
    8 | int solve(auto b, auto e, int w, int c) {
      |                   ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
#include<map>
#include<algorithm>

static int const INF{100000000};

int solve(auto b, auto e, int w, int c) {
  if(b == e || w == 0) return 0;

  if(w < c + *b) return solve(next(b), e, w, c);

  return solve(next(b), e, w - *b, c + *b) + *b;
}

int main(int, char**) {
  int n;
  std::cin >> n;
  std::vector<int> ws(n);
  int sum{};
  for(int i{}; i < n; ++i) {
    int t;
    std::cin >> t;
    ws[i] = t;
    sum += t;
  }

  if(sum % 2) {
    std::cout << "impossible" << std::endl;
    return 0;
  }

  sum /= 2;

  std::sort(begin(ws), end(ws), std::greater<int>());
  int v = solve(begin(ws), prev(end(ws)), sum, 0);

  std::cout << (sum == v ? "possible" : "impossible") << std::endl;

  return 0;
}
0