結果

問題 No.910 素数部分列
ユーザー noshi91noshi91
提出日時 2019-10-18 22:48:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,169 bytes
コンパイル時間 1,168 ms
コンパイル使用メモリ 76,080 KB
実行使用メモリ 9,752 KB
最終ジャッジ日時 2023-09-08 00:55:25
合計ジャッジ時間 2,895 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,376 KB
testcase_05 WA -
testcase_06 AC 1 ms
4,376 KB
testcase_07 WA -
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 1 ms
4,376 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 AC 12 ms
9,532 KB
testcase_49 AC 11 ms
9,476 KB
testcase_50 AC 12 ms
9,616 KB
testcase_51 AC 11 ms
9,528 KB
testcase_52 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

//#define NDEBUG
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <vector>

namespace n91 {

  using i8 = std::int_fast8_t;
  using i32 = std::int_fast32_t;
  using i64 = std::int_fast64_t;
  using u8 = std::uint_fast8_t;
  using u32 = std::uint_fast32_t;
  using u64 = std::uint_fast64_t;
  using isize = std::ptrdiff_t;
  using usize = std::size_t;

  struct rep {
    struct itr {
      usize i;
      constexpr itr(const usize i) noexcept : i(i) {}
      void operator++() noexcept { ++i; }
      constexpr usize operator*() const noexcept { return i; }
      constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
    };
    const itr f, l;
    constexpr rep(const usize f, const usize l) noexcept
      : f(std::min(f, l)), l(l) {}
    constexpr auto begin() const noexcept { return f; }
    constexpr auto end() const noexcept { return l; }
  };
  struct revrep {
    struct itr {
      usize i;
      constexpr itr(const usize i) noexcept : i(i) {}
      void operator++() noexcept { --i; }
      constexpr usize operator*() const noexcept { return i; }
      constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
    };
    const itr f, l;
    constexpr revrep(const usize f, const usize l) noexcept
      : f(l - 1), l(std::min(f, l) - 1) {}
    constexpr auto begin() const noexcept { return f; }
    constexpr auto end() const noexcept { return l; }
  };
  template <class T> auto md_vec(const usize n, const T& value) {
    return std::vector<T>(n, value);
  }
  template <class... Args> auto md_vec(const usize n, Args... args) {
    return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
  }
  template <class T> constexpr T difference(const T& a, const T& b) noexcept {
    return a < b ? b - a : a - b;
  }
  template <class T> void chmin(T& a, const T& b) noexcept {
    if (b < a)
      a = b;
  }
  template <class T> void chmax(T& a, const T& b) noexcept {
    if (a < b)
      a = b;
  }
  template <class T> T scan() {
    T ret;
    std::cin >> ret;
    return ret;
  }

} // namespace n91

#include <algorithm>
#include <iostream>
#include <limits>
#include <string>
#include <utility>

namespace n91 {

  void main_() {
    const usize n{ scan<usize>() };
    const std::string s{ scan<std::string>() };
    isize ans = 0;
    static constexpr isize Minf = std::numeric_limits<isize>::lowest();
    std::vector<isize> dp(n + 1, Minf), dp9 = dp, dp99 = dp, dp1 = dp;
    dp[0] = 0;
    for (const auto i : rep(0, n)) {
      chmax(dp[i + 1], dp[i]);
      chmax(dp9[i + 1], dp9[i]);
      chmax(dp99[i + 1], dp99[i]);
      chmax(dp1[i + 1], dp1[i]);
      const char e = s[i];
      if (e == '3' || e == '5' || e == '7') {
        ++ans;
        continue;
      }
      if (e == '1') {
        chmax(dp1[i + 1], dp[i]);
        chmax(dp[i + 1], dp99[i] + 1);
        chmax(dp[i + 1], dp1[i] + 1);
      }
      else {
        chmax(dp9[i + 1], dp[i]);
        chmax(dp99[i + 1], dp9[i]);
        chmax(dp[i + 1], dp1[i] + 1);
      }
    }
    std::cout << ans + dp[n] << std::endl;
  }

} // namespace n91

int main() {
  n91::main_();
  return 0;
}
0