結果

問題 No.1542 ぽんぽんぽん ぽんぽんぽんぽん ぽんぽんぽん
ユーザー niuezniuez
提出日時 2021-06-06 18:29:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,350 bytes
コンパイル時間 2,283 ms
コンパイル使用メモリ 208,264 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-02 12:57:20
合計ジャッジ時間 3,856 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,376 KB
testcase_01 AC 3 ms
5,504 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 3 ms
5,504 KB
testcase_04 AC 3 ms
5,504 KB
testcase_05 WA -
testcase_06 AC 17 ms
5,504 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 3 ms
5,632 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 3 ms
5,632 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 3 ms
5,504 KB
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 -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define STRINGIFY(n) #n
#define TOSTRING(n) STRINGIFY(n)
#define PREFIX "#" TOSTRING(__LINE__) "| "
#define debug(x) \
{ \
  std::cout << PREFIX << #x << " = " << x << std::endl; \
}
std::ostream& output_indent(std::ostream& os, int ind) {
  for(int i = 0; i < ind; i++) os << " ";
  return os;
}
template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p);
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v);
template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p) {
  return (os << "(" << p.first << ", " << p.second << ")");
}
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
  os << "[";
  for(int i = 0;i < v.size();i++) os << v[i] << ", ";
  return (os << "]");
}
template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
template<class Cond> struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; }
};
template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); }

int main() {
  i64 N;
  string SS;
  cin >> N >> SS;
  vector<int> S(N);
  rep(i,0,N) {
    if(SS[i] == 'p') S[i] = 0;
    if(SS[i] == 'o') S[i] = 1;
    if(SS[i] == 'n') S[i] = 2;
  }
  auto dp = ndvec(501, 501, i64(0));
  for(int l = 3; l <= N; l++) {
    for(int i = 0; i + l <= N; i++) {
      int j = i + l;
      for(int m = i + 1; m < j; m++) {
        dp[i][j] = std::max(dp[i][j], dp[i][m] + dp[m][j]);
      }
      for(int m = i + 1; m < j; m++) {
        if(S[i] == 0 && S[j - 1] == 2 && S[m] == 1) {
          dp[i][j] = std::max(dp[i][j], dp[i + 1][m] + dp[m + 1][j - 2] + 1);
        }
      }
    }
  }
  i64 ans = -1;
  for(int m = 1; m < N; m++) {
    if(dp[0][m] > 0 && dp[m][N]) ans = std::max(ans, dp[0][m] + dp[m][N] - 2);
  }
  cout << ans << endl;
}
0