QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#131652 | #5501. Ctrl+C Ctrl+V | ClHg2 | AC ✓ | 1114ms | 256152kb | C++14 | 2.5kb | 2023-07-27 19:54:22 | 2023-07-27 19:54:28 |
Judging History
answer
#include <array>
#include <cstddef>
#include <cstdint>
#include <fstream>
#include <iostream>
#include <string>
namespace {
using std::cin;
using std::cout;
using std::int64_t;
using std::size_t;
namespace base {
template <typename T, size_t... sizes>
struct NestedArray {};
template <typename T, size_t size, size_t... sizes>
struct NestedArray<T, size, sizes...> {
using Type = std::array<typename NestedArray<T, sizes...>::Type, size>;
};
template <typename T>
struct NestedArray<T> {
using Type = T;
};
template <typename T, size_t... sizes>
using Array = typename NestedArray<T, sizes...>::Type;
void OptimizeIO() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
}
void OptimizeIO(const std::string &input_file, const std::string &output_file) {
static std::ifstream input_stream(input_file);
static std::ofstream output_stream(output_file);
cin.rdbuf(input_stream.rdbuf()), cout.rdbuf(output_stream.rdbuf());
cin.tie(nullptr), cout.tie(nullptr);
}
template <typename T>
inline void CheckMin(T &a, const T &b) {
if (b < a) a = b;
}
} // namespace base
using base::Array;
using base::CheckMin;
const int kMaxN = 1.0e6 + 5, kInf = 1.0e9 + 5;
int n;
Array<int, kMaxN, 4, 4, 4> f;
std::string s;
inline int F(char c) {
if (c == 'a') return 1;
if (c == 'n') return 2;
if (c == 'i') return 3;
return 0;
}
inline bool Check(int a, int b, int c, int d) {
return a == 1 && b == 2 && c == 3 && d == 1;
}
void Solve() {
cin >> s;
n = s.size(), s = ' ' + s;
for (int i = 0; i <= n; ++i) {
for (int a = 0; a < 4; ++a) {
for (int b = 0; b < 4; ++b) f[i][a][b].fill(kInf);
}
}
f[0][0][0][0] = 0;
for (int i = 1; i <= n; ++i) {
for (int a = 0; a < 4; ++a) {
for (int b = 0; b < 4; ++b) {
for (int c = 0; c < 4; ++c) {
int val = f[i - 1][a][b][c];
if (val == kInf) continue;
int d = F(s[i]);
if (!Check(a, b, c, d)) CheckMin(f[i][b][c][d], val);
for (int j = 0; j < 4; ++j) {
if (!Check(a, b, c, j)) CheckMin(f[i][b][c][j], val + 1);
}
}
}
}
}
int ans = kInf;
for (int a = 0; a < 4; ++a) {
for (int b = 0; b < 4; ++b) {
for (int c = 0; c < 4; ++c) CheckMin(ans, f[n][a][b][c]);
}
}
cout << ans << "\n";
}
int Main() {
base::OptimizeIO();
int t;
cin >> t;
while (t--) Solve();
return 0;
}
} // namespace
int main() { return Main(); }
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3504kb
input:
3 aniasieurodzilaapotemnicsieniedzialo nicciekawegouanianiagnieszkianialicji jeszczekrotszaautobiografiaani
output:
1 2 0
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 547ms
memory: 3648kb
input:
10000 aniaanianianianiaviananibnianianianianianiapianianianianianianiaanianianianiananianianianiananifw ananiacnganiaaywbwrkaniahaniaganiaglljaniaouaqrdyaniaypvsgjltrbcvjssrtnehqfzpfvaniahwaniauzncovwfmiqejteiuaniacblxyfikauptesitsitvananianiajndy anianianianianianiaanianianianianiaanianianianianiaa...
output:
13 11 53 16 10 13 35 2 39 7 19 14 47 7 78 34 59 60 21 13 22 18 18 9 77 3 19 14 44 64 18 26 14 4 27 38 9 65 13 27 51 23 3 13 26 69 5 20 32 23 22 13 29 2 23 2 18 21 68 50 21 9 5 6 21 22 77 1 60 54 8 19 51 13 6 18 70 18 22 19 20 4 74 17 26 8 19 78 11 28 72 8 45 21 23 21 15 54 65 14 2 9 10 5 33 78 0 30 ...
result:
ok 10000 lines
Test #3:
score: 0
Accepted
time: 1114ms
memory: 9340kb
input:
335 ananianianianianianianianianianianianianianianianianianianianianianianianianianiaanianianianianianianianianianianianianianianianianianianianianianianianianianianianianianianianianianianianianianiananianianianianianianianiananianianianianianianianianianianianianianianianianianianianianianianiania...
output:
3075 476 650 443 510 2446 624 560 2256 679 3138 361 512 300 484 1726 659 559 1887 381 3048 700 507 2769 2688 615 706 631 3009 367 516 535 3150 1759 418 489 1738 2676 497 666 655 2391 547 405 677 2189 492 465 413 2008 2477 2125 2586 1788 439 2765 2781 667 279 294 523 654 414 2126 2156 2175 1855 3135 ...
result:
ok 335 lines
Test #4:
score: 0
Accepted
time: 1049ms
memory: 256152kb
input:
5 aanninaiiiiiaaaaaiiniaaiaaanniiaaaiiiainainananinannnaiaiiainnianaainaaiaanannnnnniaiaiainanaaniaaaainaaanaanianiininiaiiaaaaaainaniinaininniiiinaaaannnananniianaananiainiiiniinninnnainaiiiaanaananinaininiiaaanaiiininnanannannnnaiaaaniiaaniaaanaaaiinianniaiiaiinaannaanniiaininaiianaiiiniinaaiiania...
output:
15253 17190 166607 49472 166658
result:
ok 5 lines