답안 #30105

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
30105 2017-07-22T06:19:03 Z 시제연(#1249) Difference (POI11_roz) C++11
100 / 100
269 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

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);
                 ^
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 6900 KB Output is correct
2 Correct 0 ms 6900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6900 KB Output is correct
2 Correct 0 ms 6900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 6900 KB Output is correct
2 Correct 0 ms 6900 KB Output is correct
3 Correct 3 ms 6900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 266 ms 6900 KB Output is correct
2 Correct 0 ms 6900 KB Output is correct
3 Correct 233 ms 6900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 253 ms 6900 KB Output is correct
2 Correct 229 ms 6900 KB Output is correct
3 Correct 239 ms 6900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 256 ms 6900 KB Output is correct
2 Correct 256 ms 6900 KB Output is correct
3 Correct 266 ms 6900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 266 ms 6900 KB Output is correct
2 Correct 269 ms 6900 KB Output is correct
3 Correct 266 ms 6900 KB Output is correct