Submission #30106

#TimeUsernameProblemLanguageResultExecution timeMemory
30106tlwpdusDifference (POI11_roz)C++11
100 / 100
316 ms6900 KiB
#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 (stderr)

roz.cpp: In function 'int main()':
roz.cpp:25:19: warning: array subscript has type 'char' [-Wchar-subscripts]
    else D[str[i+1]] = max(D[str[i+1]]-1,-1);
                   ^
roz.cpp:25:37: warning: array subscript has type 'char' [-Wchar-subscripts]
    else D[str[i+1]] = max(D[str[i+1]]-1,-1);
                                     ^
roz.cpp:26:19: warning: array subscript has type 'char' [-Wchar-subscripts]
    A[i] = D[str[i]];
                   ^
roz.cpp:27:41: warning: array subscript has type 'char' [-Wchar-subscripts]
    if (str[i]!=a) res = max(res,D[str[i]]-1);
                                         ^
roz.cpp:33:19: warning: array subscript has type 'char' [-Wchar-subscripts]
    else D[str[i-1]] = max(D[str[i-1]]-1,-1);
                   ^
roz.cpp:33:37: warning: array subscript has type 'char' [-Wchar-subscripts]
    else D[str[i-1]] = max(D[str[i-1]]-1,-1);
                                     ^
roz.cpp:34:47: warning: array subscript has type 'char' [-Wchar-subscripts]
    if (str[i]!=a) res = max({res,A[i]+D[str[i]]-1,D[str[i]]-1});
                                               ^
roz.cpp:34:59: warning: array subscript has type 'char' [-Wchar-subscripts]
    if (str[i]!=a) res = max({res,A[i]+D[str[i]]-1,D[str[i]]-1});
                                                           ^
roz.cpp:13:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
                ^
roz.cpp:14:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s",str);
                 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...