結果

問題 No.1542 ぽんぽんぽん ぽんぽんぽんぽん ぽんぽんぽん
ユーザー niuezniuez
提出日時 2021-06-06 18:29:47
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 2,354 bytes
コンパイル時間 2,238 ms
コンパイル使用メモリ 205,716 KB
実行使用メモリ 5,576 KB
最終ジャッジ日時 2023-08-15 00:41:54
合計ジャッジ時間 4,470 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,428 KB
testcase_01 AC 3 ms
5,384 KB
testcase_02 AC 3 ms
5,576 KB
testcase_03 AC 3 ms
5,304 KB
testcase_04 AC 3 ms
5,348 KB
testcase_05 AC 5 ms
5,352 KB
testcase_06 AC 23 ms
5,388 KB
testcase_07 AC 3 ms
5,356 KB
testcase_08 AC 48 ms
5,544 KB
testcase_09 AC 13 ms
5,460 KB
testcase_10 AC 53 ms
5,308 KB
testcase_11 AC 52 ms
5,404 KB
testcase_12 AC 4 ms
5,396 KB
testcase_13 AC 8 ms
5,460 KB
testcase_14 AC 30 ms
5,356 KB
testcase_15 AC 4 ms
5,456 KB
testcase_16 AC 20 ms
5,404 KB
testcase_17 AC 3 ms
5,456 KB
testcase_18 AC 4 ms
5,336 KB
testcase_19 AC 4 ms
5,304 KB
testcase_20 AC 52 ms
5,400 KB
testcase_21 AC 3 ms
5,352 KB
testcase_22 AC 21 ms
5,340 KB
testcase_23 AC 58 ms
5,360 KB
testcase_24 AC 62 ms
5,348 KB
testcase_25 AC 59 ms
5,304 KB
testcase_26 AC 59 ms
5,460 KB
testcase_27 AC 58 ms
5,460 KB
testcase_28 AC 59 ms
5,328 KB
testcase_29 AC 60 ms
5,412 KB
testcase_30 AC 59 ms
5,464 KB
testcase_31 AC 60 ms
5,388 KB
testcase_32 AC 59 ms
5,532 KB
権限があれば一括ダウンロードができます

ソースコード

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 - 1] + 1);
        }
      }
    }
  }
  i64 ans = -1;
  for(int m = 1; m < N; m++) {
    if(dp[0][m] > 0 && dp[m][N] > 0) ans = std::max(ans, dp[0][m] + dp[m][N] - 2);
  }
  cout << ans << endl;
}
0