結果
| 問題 |
No.2076 Concon Substrings (ConVersion)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-09-16 21:57:39 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 157 ms / 5,000 ms |
| コード長 | 2,363 bytes |
| コンパイル時間 | 1,029 ms |
| コンパイル使用メモリ | 111,584 KB |
| 実行使用メモリ | 6,272 KB |
| 最終ジャッジ日時 | 2025-06-20 00:38:10 |
| 合計ジャッジ時間 | 2,795 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:45:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
45 | scanf("%s", S);
| ~~~~~^~~~~~~~~
ソースコード
#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;
}