답안 #30082

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
30082 2017-07-22T05:07:30 Z khsoo01 Difference (POI11_roz) C++11
100 / 100
206 ms 14332 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 1000005;

int n, sum[N], ans;
char ipt[N];

vector<int> s[26];

void solve (int I) {
	for(int i=1;i<=n;i++) {
		sum[i] = sum[i-1] + (ipt[i] == I);
	}
	for(int k=0;k<26;k++) {
		if(k == I) continue;
		int mn = 0;
		for(int i=1;i<s[k].size();i++) {
			ans = max(ans, sum[s[k][i]] - i - mn);
			mn = min(mn, sum[s[k][i-1]] - i);
		}
	}
}

int main()
{
	scanf("%d%s",&n,ipt+1);
	for(int i=1;i<=n;i++) {
		ipt[i] -= 'a';
		s[ipt[i]].push_back(i);
	}
	for(int i=0;i<26;i++) s[i].push_back(n);
	for(int i=0;i<26;i++) solve(i);
	printf("%d\n",ans);
}

Compilation message

roz.cpp: In function 'void solve(int)':
roz.cpp:17:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=1;i<s[k].size();i++) {
                ^
roz.cpp: In function 'int main()':
roz.cpp:29:11: warning: array subscript has type 'char' [-Wchar-subscripts]
   s[ipt[i]].push_back(i);
           ^
roz.cpp:26:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%s",&n,ipt+1);
                        ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 6904 KB Output is correct
2 Correct 0 ms 6904 KB Output is correct
3 Correct 0 ms 6904 KB Output is correct
4 Correct 0 ms 6904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 6904 KB Output is correct
2 Correct 0 ms 6904 KB Output is correct
3 Correct 0 ms 6904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 6904 KB Output is correct
2 Correct 0 ms 6904 KB Output is correct
3 Correct 0 ms 6904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 6904 KB Output is correct
2 Correct 0 ms 6904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 7036 KB Output is correct
2 Correct 0 ms 6904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 7312 KB Output is correct
2 Correct 0 ms 6904 KB Output is correct
3 Correct 0 ms 7036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 199 ms 14332 KB Output is correct
2 Correct 0 ms 6904 KB Output is correct
3 Correct 143 ms 11480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 206 ms 13980 KB Output is correct
2 Correct 136 ms 13456 KB Output is correct
3 Correct 119 ms 13684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 183 ms 14328 KB Output is correct
2 Correct 133 ms 14164 KB Output is correct
3 Correct 133 ms 12136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 199 ms 13928 KB Output is correct
2 Correct 136 ms 12112 KB Output is correct
3 Correct 133 ms 14200 KB Output is correct