QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#109342 | #6367. Bad Word | do_while_true | WA | 0ms | 3604kb | C++14 | 1.0kb | 2023-05-28 16:51:44 | 2023-05-28 16:51:46 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
typedef long long ll;
template <typename T> T Min(T x, T y) { return x < y ? x : y; }
template <typename T> T Max(T x, T y) { return x > y ? x : y; }
const int N = 200010;
int n, nxt[N][3], p[31], vis[31];
char ch[N];
std::vector< std::string > vec;
ll ans;
void check(int x) {
int cur = 0;
for(int i = 0; ; ++i) {
cur = nxt[cur][p[i % x]];
if(cur > n) {
int ct = i / x;
ans = Max(ans, 1ll * ct * ct * x);
return ;
}
}
}
void dfs(int x) {
if(x)
check(x);
for(int i = 0; i < 3; ++i)
if(vis[i] < 2) {
++vis[i];
p[x] = i;
dfs(x+1);
--vis[i];
}
}
void solve() {
scanf("%d", &n);
scanf("%s", ch+1);
for(int j = 0; j < 3; ++j) nxt[n][j] = n+1;
for(int i = n-1; i >= 0; --i) {
for(int j = 0; j < 3; ++j)
if(j + 'a' == ch[i+1]) nxt[i][j] = i + 1;
else nxt[i][j] = nxt[i+1][j];
}
ans = 0;
dfs(0);
printf("%lld\n", ans);
}
int main() {
solve();return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3604kb
input:
7 abcdcba
output:
6
result:
wrong answer 1st numbers differ - expected: '2', found: '6'