답안 #39681

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
39681 2018-01-17T06:22:04 Z 14kg JOIOJI (JOI14_joioji) C++11
100 / 100
33 ms 24340 KB
#include <stdio.h>
#include <map>
#define P 66667
#define N 200005
#define INF 999999999
#define Abs(x) (x>0?x:-(x))
#define max2(x,y) (x>y?x:y)

using namespace std;
int n;
char in[N];
map<int, int> M[N * 2];

int Find(int x, int y, int w) {
	if (x == 0 && y == 0) return 0;
	int res = M[x + n][y];
	if (!res) M[x + n][y] = w;
	return res ? res : INF;
}
int main() {
	int x = 0, y = 0, w, out = 0;

	scanf("%d %s", &n, in + 1);
	for (int i = 1; i <= n; i++) {
		if (in[i] == 'J') x++, y++;
		else if (in[i] == 'O') x--;
		else y--;
		w = Find(x, y, i), out = max2(out, i - w);
	} printf("%d", out);
}

Compilation message

joioji.cpp: In function 'int main()':
joioji.cpp:23:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %s", &n, in + 1);
                            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 20116 KB Output is correct
2 Correct 6 ms 20116 KB Output is correct
3 Correct 3 ms 20116 KB Output is correct
4 Correct 6 ms 20116 KB Output is correct
5 Correct 3 ms 20116 KB Output is correct
6 Correct 13 ms 20116 KB Output is correct
7 Correct 6 ms 20116 KB Output is correct
8 Correct 3 ms 20116 KB Output is correct
9 Correct 6 ms 20116 KB Output is correct
10 Correct 3 ms 20116 KB Output is correct
11 Correct 6 ms 20116 KB Output is correct
12 Correct 9 ms 20116 KB Output is correct
13 Correct 6 ms 20116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 20116 KB Output is correct
2 Correct 0 ms 20116 KB Output is correct
3 Correct 3 ms 20248 KB Output is correct
4 Correct 9 ms 20248 KB Output is correct
5 Correct 6 ms 20248 KB Output is correct
6 Correct 6 ms 20116 KB Output is correct
7 Correct 6 ms 20116 KB Output is correct
8 Correct 6 ms 20248 KB Output is correct
9 Correct 9 ms 20248 KB Output is correct
10 Correct 3 ms 20248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 20248 KB Output is correct
2 Correct 9 ms 20644 KB Output is correct
3 Correct 13 ms 20908 KB Output is correct
4 Correct 19 ms 21436 KB Output is correct
5 Correct 23 ms 22228 KB Output is correct
6 Correct 23 ms 22360 KB Output is correct
7 Correct 29 ms 22756 KB Output is correct
8 Correct 33 ms 22228 KB Output is correct
9 Correct 33 ms 22492 KB Output is correct
10 Correct 29 ms 22228 KB Output is correct
11 Correct 6 ms 23548 KB Output is correct
12 Correct 19 ms 21304 KB Output is correct
13 Correct 16 ms 20908 KB Output is correct
14 Correct 16 ms 24340 KB Output is correct
15 Correct 13 ms 20644 KB Output is correct