답안 #156041

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
156041 2019-10-03T02:03:57 Z shuvi_dola JOIOJI (JOI14_joioji) C++14
100 / 100
64 ms 8044 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int cnti[N], cntj[N], cnto[N];
map <pair <int, int>, int> m;
string s;
int n;
int main()
{
	cin >> n;
	cin >> s;
	s = "1" + s;
	pair <int, int> v = {0, 0};
	m[v] = 0;
	for(int i = 1; i <= n; i++)
	{
		cnti[i] = cnti[i - 1] + (s[i] == 'I');
		cntj[i] = cntj[i - 1] + (s[i] == 'J');
		cnto[i] = cnto[i - 1] + (s[i] == 'O');
		pair <int, int> v = {cntj[i] - cnti[i], cntj[i] - cnto[i]};
		if(m.find(v) == m.end())
			m[v] = i;
	}

	int ans = 0;
	for(int i = n; i >= 1; i--)
	{
		pair <int, int> v = {cntj[i] - cnti[i], cntj[i] - cnto[i]};
		int j = m[v];
		ans = max(ans, i - j);
	}

	cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 252 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 248 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 3 ms 380 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 632 KB Output is correct
2 Correct 10 ms 1248 KB Output is correct
3 Correct 17 ms 2040 KB Output is correct
4 Correct 32 ms 3316 KB Output is correct
5 Correct 50 ms 5232 KB Output is correct
6 Correct 62 ms 5828 KB Output is correct
7 Correct 64 ms 6212 KB Output is correct
8 Correct 61 ms 5664 KB Output is correct
9 Correct 63 ms 6112 KB Output is correct
10 Correct 61 ms 5700 KB Output is correct
11 Correct 57 ms 7132 KB Output is correct
12 Correct 40 ms 4300 KB Output is correct
13 Correct 37 ms 3660 KB Output is correct
14 Correct 60 ms 8044 KB Output is correct
15 Correct 35 ms 3524 KB Output is correct