답안 #61487

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
61487 2018-07-26T05:25:35 Z sean617 JOIOJI (JOI14_joioji) C++
100 / 100
90 ms 14592 KB
#include <iostream>
#include <cstdio>
#include <set>
#include <map>
#define PI pair<int, int>
using namespace std;

int n, l, r, md, ans, mx, s[3][200005];
set<PI> v;
map<PI, int> b1;
string a;
int main()
{
	int i, z, t1, t2;
	cin >> n;
	cin >> a;
	a = ' ' + a;
	for (i = 1; i <= n;i++) {
		s[0][i] = s[0][i - 1];
		s[1][i] = s[1][i - 1];
		s[2][i] = s[2][i - 1];
		if (a[i] == 'J') s[0][i]++;
		else if (a[i] == 'O') s[1][i]++;
		else s[2][i]++;
	}
	v.insert(PI(n, n));
	b1[PI(n, n)] = 0;
	for (i = 1; i <= n; i++) {
		t1 = s[0][i] - s[1][i] + n;
		t2 = s[1][i] - s[2][i] + n;
		if (v.count(PI(t1, t2)) == 0) {
			v.insert(PI(t1, t2));
			b1[PI(t1, t2)] = i;
		} else {
			mx = max(mx, i - b1[PI(t1, t2)]);
		}
	}
	cout << mx;
//	l = 0;
//	r = n / 3 + 1;
//	while (l < r) {
//		md = (l + r) / 2;
//		z = md * 3 - 1;
//		for (i = 1; i + z <= n; i++) {
//			if (s[0][i + z] - s[0][i - 1] == s[1][i + z] - s[1][i - 1] && s[2][i + z] - s[2][i - 1] == md) break;
//		}
//		if (i + z <= n) {ans = md; l = md + 1;}
//		else r = md;
//	}
//	cout << ans * 3;
    return 0;
}

Compilation message

joioji.cpp: In function 'int main()':
joioji.cpp:14:9: warning: unused variable 'z' [-Wunused-variable]
  int i, z, t1, t2;
         ^
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 3 ms 356 KB Output is correct
3 Correct 3 ms 392 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 4 ms 504 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 3 ms 644 KB Output is correct
11 Correct 3 ms 668 KB Output is correct
12 Correct 3 ms 668 KB Output is correct
13 Correct 4 ms 668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 668 KB Output is correct
2 Correct 3 ms 668 KB Output is correct
3 Correct 4 ms 892 KB Output is correct
4 Correct 5 ms 908 KB Output is correct
5 Correct 4 ms 960 KB Output is correct
6 Correct 4 ms 960 KB Output is correct
7 Correct 4 ms 960 KB Output is correct
8 Correct 5 ms 960 KB Output is correct
9 Correct 4 ms 1024 KB Output is correct
10 Correct 4 ms 1024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1164 KB Output is correct
2 Correct 13 ms 2184 KB Output is correct
3 Correct 24 ms 3224 KB Output is correct
4 Correct 37 ms 5360 KB Output is correct
5 Correct 68 ms 8012 KB Output is correct
6 Correct 87 ms 8880 KB Output is correct
7 Correct 90 ms 10004 KB Output is correct
8 Correct 82 ms 10004 KB Output is correct
9 Correct 79 ms 10012 KB Output is correct
10 Correct 76 ms 10012 KB Output is correct
11 Correct 89 ms 12556 KB Output is correct
12 Correct 69 ms 12556 KB Output is correct
13 Correct 45 ms 12556 KB Output is correct
14 Correct 82 ms 14592 KB Output is correct
15 Correct 37 ms 14592 KB Output is correct