# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
30106 | 2017-07-22T06:19:35 Z | tlwpdus | Difference (POI11_roz) | C++11 | 316 ms | 6900 KB |
#include <bits/stdc++.h> using namespace std; int A[1000010]; int D[26]; int n, res; char str[1000100]; int main() { int i, j, a; scanf("%d",&n); scanf("%s",str); if (n==1) { printf("0\n"); return 0; } for (i=0;i<n;i++) str[i]-='a'; for (a=0;a<26;a++) { for (i=0;i<26;i++) D[i] = 0; A[n-1] = 0; for (i=n-2;i>=0;i--) { if (str[i+1]==a) for (j=0;j<26;j++) D[j] = max(D[j]+1,1); else D[str[i+1]] = max(D[str[i+1]]-1,-1); A[i] = D[str[i]]; if (str[i]!=a) res = max(res,D[str[i]]-1); } for (i=0;i<26;i++) D[i] = 0; if (str[0]!=a) res = max(res,A[0]-1); for (i=1;i<n;i++) { if (str[i-1]==a) for (j=0;j<26;j++) D[j] = max(D[j]+1,1); else D[str[i-1]] = max(D[str[i-1]]-1,-1); if (str[i]!=a) res = max({res,A[i]+D[str[i]]-1,D[str[i]]-1}); } } printf("%d\n",res); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 6900 KB | Output is correct |
2 | Correct | 0 ms | 6900 KB | Output is correct |
3 | Correct | 0 ms | 6900 KB | Output is correct |
4 | Correct | 0 ms | 6900 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 6900 KB | Output is correct |
2 | Correct | 0 ms | 6900 KB | Output is correct |
3 | Correct | 0 ms | 6900 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 6900 KB | Output is correct |
2 | Correct | 0 ms | 6900 KB | Output is correct |
3 | Correct | 0 ms | 6900 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 6900 KB | Output is correct |
2 | Correct | 0 ms | 6900 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 6900 KB | Output is correct |
2 | Correct | 0 ms | 6900 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 6900 KB | Output is correct |
2 | Correct | 0 ms | 6900 KB | Output is correct |
3 | Correct | 3 ms | 6900 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 316 ms | 6900 KB | Output is correct |
2 | Correct | 0 ms | 6900 KB | Output is correct |
3 | Correct | 239 ms | 6900 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 299 ms | 6900 KB | Output is correct |
2 | Correct | 216 ms | 6900 KB | Output is correct |
3 | Correct | 233 ms | 6900 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 273 ms | 6900 KB | Output is correct |
2 | Correct | 279 ms | 6900 KB | Output is correct |
3 | Correct | 276 ms | 6900 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 249 ms | 6900 KB | Output is correct |
2 | Correct | 273 ms | 6900 KB | Output is correct |
3 | Correct | 259 ms | 6900 KB | Output is correct |