結果

問題 No.2076 Concon Substrings (ConVersion)
ユーザー chineristACchineristAC
提出日時 2022-09-16 22:34:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,438 ms / 5,000 ms
コード長 2,250 bytes
コンパイル時間 1,819 ms
コンパイル使用メモリ 139,280 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 17:01:19
合計ジャッジ時間 11,037 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 1,424 ms
4,376 KB
testcase_08 AC 1,020 ms
4,376 KB
testcase_09 AC 1,438 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 518 ms
4,376 KB
testcase_16 AC 448 ms
4,380 KB
testcase_17 AC 216 ms
4,380 KB
testcase_18 AC 1,113 ms
4,380 KB
testcase_19 AC 200 ms
4,380 KB
testcase_20 AC 737 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 140 ms
4,376 KB
testcase_23 AC 62 ms
4,376 KB
testcase_24 AC 79 ms
4,380 KB
testcase_25 AC 94 ms
4,380 KB
testcase_26 AC 53 ms
4,380 KB
testcase_27 AC 58 ms
4,376 KB
testcase_28 AC 97 ms
4,380 KB
testcase_29 AC 135 ms
4,376 KB
testcase_30 AC 139 ms
4,376 KB
testcase_31 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <random>
#include <stdio.h>
#include <fstream>
#include <functional>
#include <cassert>


using namespace std;


#define rep(i,n) for (int i=0;i<n;i+=1)
#define append push_back
#define all(x) (x).begin(), (x).end()

template<class T>
using vec = vector<T>;
template<class T>
using vvec = vec<vec<T>>;
template<class T>
using vvvec = vec<vvec<T>>;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;


template<class T>
bool chmin(T &a, T b){
  if (a>b){
    a = b;
    return true;
  }
  return false;
}

template<class T>
bool chmax(T &a, T b){
  if (a<b){
    a = b;
    return true;
  }
  return false;
}

template<class T>
T sum(vec<T> x){
  T res=0;
  for (auto e:x){
    res += e;
  }
  return res;
}

template<class T>
void printv(vec<T> x){
  for (auto e:x){
    cout<<e<<" ";
  }
  cout<<"\n";
}

template<class T>
ostream& operator<<(ostream& os, const vec<T>& A){
  os << "[";
  rep(i,A.size()){
    os << A[i];
    if (i!=A.size()-1){
      os << ", ";
    }
  }
  os << "]" ;
  return os;
}

int main() {

  int N,X,Y;
  cin>>N>>X>>Y;
  string S;
  cin>>S;

  vec<int> A;
  int i = 0;
  while (i < N-2){
    if (S[i]=='c' && S[i+1]=='o' && S[i+2]=='n'){
      int a = 1;
      int j = i+3;
      while (j < N-2){
       if (S[j]=='c' && S[j+1]=='o' && S[j+2]=='n') {
        a++;
        j += 3;
       }
       else{
        break;
       }
      }
      A.push_back(a);
      i = j;
    }
    else{
      i++;
    }
  }



  int M = 17000;
  vec<int> dp(2*M+10,-1);
  dp[0+M] = 0;
  for (auto a:A){
    vec<int> ndp(2*M+10,-1);
    for (int s=-M;s<=M;s++){
      if (dp[s+M]==-1){
        continue;
      }
      for (int k=0;k<=a/X;k++){
        int x = k;
        int y = (a-k*X)/Y;
        chmax(ndp[s+x-y+M],dp[s+M]+x+y);
      }
    }
    swap(dp,ndp);
  }

  int res = 0;
  for (int s=-M;s<=0;s++){
    if (dp[s+M]!=-1){
      chmax(res,dp[s+M]+s);
    }
  }
  if (dp[M+1]!=-1){
    chmax(res,dp[M+1]);
  }

  cout << res << endl;




       

}
0