답안 #885105

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
885105 2023-12-09T02:34:56 Z harao Difference (POI11_roz) C++17
100 / 100
136 ms 12456 KB
#include<bits/stdc++.h>
using namespace std;

const int N = 1e6 + 7;

int n, pre[N], ans;
string s;

vector<int> g[26];

void solve (int m) {
	for(int i = 1;i <= n; i++) {
		pre[i] = pre[i - 1] + ((s[i] - 'a') == m);
	}
	for(int k = 0;k < 26; k++) {
		if(k == m) continue;
		int mn = 0;
		for(int i = 1;i < g[k].size(); i++) {
			ans = max(ans, pre[g[k][i]] - i - mn);
			mn = min(mn, pre[g[k][i-1]] - i);
		}
	}
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

//    freopen(".inp", "r", stdin);
//    freopen(".out", "w", stdout);

	cin >> n;
	cin >> s;
	s = " " + s;
	for(int i = 1;i <= n; i++)
    {
		g[s[i] - 'a'].push_back(i);
	}
	for(int i = 0;i < 26; i++) g[i].push_back(n);
	for(int i = 0;i < 26; i++) solve(i);

	cout << ans;
}

Compilation message

roz.cpp: In function 'void solve(int)':
roz.cpp:18:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |   for(int i = 1;i < g[k].size(); i++) {
      |                 ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 3160 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 3 ms 676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 136 ms 12456 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 103 ms 9460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 134 ms 12212 KB Output is correct
2 Correct 104 ms 10464 KB Output is correct
3 Correct 97 ms 9888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 133 ms 12220 KB Output is correct
2 Correct 113 ms 10392 KB Output is correct
3 Correct 110 ms 10788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 132 ms 12372 KB Output is correct
2 Correct 111 ms 11804 KB Output is correct
3 Correct 111 ms 11044 KB Output is correct