답안 #167013

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
167013 2019-12-05T08:44:25 Z errorgorn JOIOJI (JOI14_joioji) C++14
100 / 100
50 ms 11292 KB
#include <cstdio>
#include <unordered_map>
#include <utility>
#include <string>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <chrono>
using namespace std;
typedef pair<int,int> ii;
int n;
char c;
string s;
struct custom_hash {
    typedef long long ll;
    typedef unsigned long long ull;
    const ull FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    static ull splitmix64(ull x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(ll x) const {
        return splitmix64(x + FIXED_RANDOM);
    }
    size_t operator()(const pair<int,int> &i)const{
        return splitmix64((((ll)i.first)^(((ll)i.second)<<32))+FIXED_RANDOM);
    }
};
unordered_map<ii,int,custom_hash> suffix;
int arr[3];
int pre[3];
int main(){
    suffix.reserve(4096);
    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

joioji.cpp: In function 'int main()':
joioji.cpp:52:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int x=0;x<s.size();x++){
                  ~^~~~~~~~~
joioji.cpp:61:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int x=0;x<s.size();x++){
                  ~^~~~~~~~~
joioji.cpp:40:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 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 376 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 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 296 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 3 ms 476 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 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 4 ms 632 KB Output is correct
2 Correct 8 ms 1644 KB Output is correct
3 Correct 11 ms 1840 KB Output is correct
4 Correct 21 ms 3004 KB Output is correct
5 Correct 35 ms 5668 KB Output is correct
6 Correct 42 ms 5796 KB Output is correct
7 Correct 44 ms 5796 KB Output is correct
8 Correct 42 ms 5796 KB Output is correct
9 Correct 44 ms 5796 KB Output is correct
10 Correct 41 ms 5796 KB Output is correct
11 Correct 40 ms 6432 KB Output is correct
12 Correct 30 ms 3168 KB Output is correct
13 Correct 30 ms 2016 KB Output is correct
14 Correct 50 ms 11292 KB Output is correct
15 Correct 31 ms 1988 KB Output is correct