# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
120211 | 2019-06-24T00:57:07 Z | errorgorn | JOIOJI (JOI14_joioji) | C++14 | 48 ms | 6288 KB |
#include <cstdio> #include <map> #include <utility> #include <string> #include <iostream> #include <cstring> #include <algorithm> using namespace std; typedef pair<int,int> ii; int n; char c; string s; map<ii,int> suffix; int arr[3]; int pre[3]; int main(){ //freopen("input.txt","r",stdin); scanf("%d",&n); getchar(); c=getchar(); while (c!='\n'){ s+=c; if (c=='J') arr[0]++; else if (c=='O') arr[1]++; else arr[2]++; c=getchar(); } suffix[ii(0,0)]=0; for (int x=0;x<3;x++) pre[x]=arr[x]; for (int x=0;x<s.size();x++){ if (s[x]=='J') pre[0]--; else if (s[x]=='O') pre[1]--; else pre[2]--; suffix[ii(pre[0]-pre[1],pre[0]-pre[2])]=x+1; } memset(pre,0,sizeof(pre)); int ans=0; int a=arr[0]-arr[1],b=arr[0]-arr[2]; for (int x=0;x<s.size();x++){ ans=max(ans,suffix[ii(a-(pre[0]-pre[1]),b-(pre[0]-pre[2]))]-x); if (s[x]=='J') pre[0]++; else if (s[x]=='O') pre[1]++; else pre[2]++; } printf("%d\n",ans); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Correct | 2 ms | 256 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Correct | 2 ms | 256 KB | Output is correct |
7 | Correct | 2 ms | 256 KB | Output is correct |
8 | Correct | 2 ms | 384 KB | Output is correct |
9 | Correct | 2 ms | 384 KB | Output is correct |
10 | Correct | 2 ms | 256 KB | Output is correct |
11 | Correct | 2 ms | 384 KB | Output is correct |
12 | Correct | 2 ms | 384 KB | Output is correct |
13 | Correct | 2 ms | 256 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 356 KB | Output is correct |
2 | Correct | 3 ms | 384 KB | Output is correct |
3 | Correct | 3 ms | 384 KB | Output is correct |
4 | Correct | 3 ms | 384 KB | Output is correct |
5 | Correct | 3 ms | 384 KB | Output is correct |
6 | Correct | 3 ms | 428 KB | Output is correct |
7 | Correct | 3 ms | 384 KB | Output is correct |
8 | Correct | 3 ms | 384 KB | Output is correct |
9 | Correct | 2 ms | 384 KB | Output is correct |
10 | Correct | 3 ms | 512 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 512 KB | Output is correct |
2 | Correct | 8 ms | 1024 KB | Output is correct |
3 | Correct | 13 ms | 1408 KB | Output is correct |
4 | Correct | 24 ms | 2308 KB | Output is correct |
5 | Correct | 36 ms | 3472 KB | Output is correct |
6 | Correct | 45 ms | 3600 KB | Output is correct |
7 | Correct | 44 ms | 4104 KB | Output is correct |
8 | Correct | 43 ms | 3592 KB | Output is correct |
9 | Correct | 48 ms | 3852 KB | Output is correct |
10 | Correct | 43 ms | 3720 KB | Output is correct |
11 | Correct | 36 ms | 5384 KB | Output is correct |
12 | Correct | 30 ms | 2320 KB | Output is correct |
13 | Correct | 23 ms | 1680 KB | Output is correct |
14 | Correct | 41 ms | 6288 KB | Output is correct |
15 | Correct | 24 ms | 1296 KB | Output is correct |