結果

問題 No.2076 Concon Substrings (ConVersion)
ユーザー 👑 hos.lyrichos.lyric
提出日時 2022-09-16 21:57:39
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 186 ms / 5,000 ms
コード長 2,363 bytes
コンパイル時間 1,172 ms
コンパイル使用メモリ 107,536 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-23 16:59:07
合計ジャッジ時間 3,273 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 176 ms
4,380 KB
testcase_08 AC 115 ms
4,380 KB
testcase_09 AC 186 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 139 ms
4,376 KB
testcase_16 AC 36 ms
4,376 KB
testcase_17 AC 21 ms
4,380 KB
testcase_18 AC 140 ms
4,380 KB
testcase_19 AC 7 ms
4,380 KB
testcase_20 AC 143 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 9 ms
4,376 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 7 ms
4,376 KB
testcase_28 AC 3 ms
4,384 KB
testcase_29 AC 6 ms
4,376 KB
testcase_30 AC 4 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }


int N, A, B;
char S[50'010];

int crt[20'010], nxt[20'010];

int main() {
  for (; ~scanf("%d%d%d", &N, &A, &B); ) {
    scanf("%s", S);
    
    vector<int> cs;
    for (int i = 0, j; i < N; i = j) {
      for (j = i; j < N && S[j] == "con"[(j - i) % 3]; ++j) {}
      if (i == j) {
        j = i + 1;
      } else if (j - i >= 3) {
        cs.push_back((j - i) / 3);
      }
    }
// cerr<<"cs = "<<cs<<endl;
    
    memset(crt, ~0, sizeof(crt));
    crt[0] = 0;
    int sz = 0;
    for (const int c : cs) {
      memset(nxt, ~0, (sz + 1) * sizeof(int));
      for (int dx = 0; A * dx <= c; ++dx) {
        const int dy = (c - A * dx) / B;
        for (int x = 0; x <= sz; ++x) if (~crt[x]) {
          chmax(nxt[x + dx], crt[x] + dy);
        }
      }
      sz += c / A;
      memcpy(crt, nxt, (sz + 1) * sizeof(int));
    }
// cerr<<"crt = ";pv(crt,crt+sz+1);
    
    int ans = 0;
    for (int x = 1; x <= sz; ++x) if (~crt[x]) {
      int score;
      if (x <= crt[x]) {
        score = 2 * x;
      } else {
        score = 2 * crt[x] + 1;
      }
      chmax(ans, score);
    }
    printf("%d\n", ans);
  }
  return 0;
}
0