# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
120145 | 2019-06-23T14:51:04 Z | errorgorn | JOIOJI (JOI14_joioji) | C++14 | 1000 ms | 62180 KB |
#include <cstdio> #include <unordered_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; struct custom_hash{ size_t operator()(const pair<int,int> &i)const{ return (i.first<<8)^i.second; } }; unordered_map<ii,int,custom_hash> suffix; int arr[3]; int pre[3]; int main(){ suffix.reserve(1024); suffix.max_load_factor(0.25); 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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1076 ms | 62000 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1087 ms | 62180 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1065 ms | 62136 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |