QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#258758#1989. Unique ActivitiesStypoxAC ✓794ms15740kbC++232.1kb2023-11-20 05:29:072023-11-20 05:29:07

Judging History

你现在查看的是最新测评结果

  • [2023-11-20 05:29:07]
  • 评测
  • 测评结果:AC
  • 用时:794ms
  • 内存:15740kb
  • [2023-11-20 05:29:07]
  • 提交

answer

#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

#define int int64_t
#define float long double

#ifdef DEBUG
template<class A,class B>ostream&operator<<(ostream&o,const pair<A,B>&p){cerr<<"("<<p.first<<", "<<p.second<<")";return o;}
template<class T,typename=typename enable_if<!is_same<T, string>::value,decltype(*begin(declval<T>()))>::type>ostream&operator<<(ostream&o,const T&v){cerr<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin()){cerr<<", ";}cerr<<*it;}cerr<<"]";return o;}
void deb(){cerr<<"\n";}template<class T,class...Ts>void deb(const T&t,const Ts&...args){cerr<<t;if(sizeof...(args)!=0){cerr<<"  ";}deb(args...);}
#else
#define deb(...)
#endif

#define P 31
#define MOD 1'000'000'009

int test(const string& s, int N) {
    int L = s.size();

    int curhash = 0;
    int Pn = 1;
    for (int i=0; i<N; i++){
        curhash *= P;
        curhash %= MOD;
        curhash += s[i];
        curhash %= MOD;

        Pn *= P;
        Pn %= MOD;
    }

    deb(curhash, (int)s[0]);
    unordered_map<int, int> m;
    m[curhash] = 0;
    for(int i=N; i<L; ++i){
        curhash *= P;
        curhash %= MOD;
        curhash += Pn * (MOD - s[i-N]);
        curhash += s[i];
        curhash %= MOD;

        if (m.contains(curhash)) {
            m[curhash] = -1;
        } else {
            m[curhash] = i-N+1;
        }
        deb(curhash);
    }

    int besti = L;
    for(auto& [h, i] : m) {
        if (i >= 0 && i < besti) {
            besti = i;
        }
    }

    deb(m);
    return (besti == L ? -1 : besti);
}

signed main() {
    string s;
    cin >> s;
    for (auto& c : s) {
        c -= 'A'-1;
    }

    // deb("res", test(s, 11));
    // return 0;

    int a=1, b=s.size();
    while (b > a+1) {
        int m = (a+b-1)/2;
        deb("m", a, b, m);
        if (test(s, m) >= 0) {
            b = m+1;
        } else {
            a = m+1;
        }
    }

    int offset = test(s, a);
    deb(a, b, offset);
    for (int i=offset; i<offset+a; ++i) {
        cout << (char)(s[i]+'A'-1);
    }
    cout << endl;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3600kb

input:

ABCABC

output:

CA

result:

ok single line: 'CA'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3596kb

input:

DABCABCD

output:

DA

result:

ok single line: 'DA'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3600kb

input:

BABABBABAABBBAA

output:

AAB

result:

ok single line: 'AAB'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3732kb

input:

BBABBBBBBAABAABABAAB

output:

ABB

result:

ok single line: 'ABB'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

BBABBBBBBAABAABABAABBABBBABBBAAABABBABAAAAABAABBAB

output:

ABBBB

result:

ok single line: 'ABBBB'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3760kb

input:

DDACEDDCDCEBEBCBAECEEBCAACDEAC

output:

DA

result:

ok single line: 'DA'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3772kb

input:

GGAEIHGEHFJDICECBJEIJCEBBFHIBFGFJDIHHIEAIABGAJHFDFBDJDDCIHBBFIHBEIEBIFIDJIJEHBJGFJDECDCAJEHBBCCABIGI

output:

GG

result:

ok single line: 'GG'

Test #8:

score: 0
Accepted
time: 0ms
memory: 3780kb

input:

GGAEIHGEHFJDICECBJEIJCEBBFHIBFGFJDIHHIEAIABGAJHFDFBDJDDCIHBBFIHBEIEBIFIDJIJEHBJGFJDECDCAJEHBBCCABIGIEIDDJGJEHHFBFJBHJFDDAEBDFCFGABCDAJIJBABDJJBGBFBAJADCBHDAAIGJBEBDBEFGCAIHAJBGDEFHJCDACCFIEBJHCAHGJIEFGECIAHBFAIECDHFJEFJJCEGGBAJDFCDDHGJGAGJGACHBECHIHIJAAHFEHAGDIBCAGGFADAAIJBDBJDEECBHGBAEHBECIFBCEAAAD...

output:

EIH

result:

ok single line: 'EIH'

Test #9:

score: 0
Accepted
time: 9ms
memory: 3916kb

input:

GGAEIHGEHFJDICECBJEIJCEBBFHIBFGFJDIHHIEAIABGAJHFDFBDJDDCIHBBFIHBEIEBIFIDJIJEHBJGFJDECDCAJEHBBCCABIGIEIDDJGJEHHFBFJBHJFDDAEBDFCFGABCDAJIJBABDJJBGBFBAJADCBHDAAIGJBEBDBEFGCAIHAJBGDEFHJCDACCFIEBJHCAHGJIEFGECIAHBFAIECDHFJEFJJCEGGBAJDFCDDHGJGAGJGACHBECHIHIJAAHFEHAGDIBCAGGFADAAIJBDBJDEECBHGBAEHBECIFBCEAAAD...

output:

AEIH

result:

ok single line: 'AEIH'

Test #10:

score: 0
Accepted
time: 21ms
memory: 4020kb

input:

MYNBIQPMZJPLSGQEJEYDTZIRWZTEJDXCVKPRDLNKTUGRPOQIBZRACXMWZVUATPKHXKWCGSHHZEZROCCKQPDJRJWDRKRGZTRSJOCTZMKSHJFGFBTVIPCCVYEEBCWRVMWQIQZHGVSNSIOPVUWZLCKTDPSUKGHAXIDWHLZFKNBDZEWHBSURTVCADUGTSDMCLDBTAGFWDPGXZBVARNTDICHCUJLNFBQOBTDWMGILXPSFWVGYBZVFFKQIDTOVFAPVNSQJULMVIERWAOXCKXBRIEHYPLTJVLSUTEWJMXNUCATGWKFH...

output:

YNB

result:

ok single line: 'YNB'

Test #11:

score: 0
Accepted
time: 186ms
memory: 8596kb

input:

MYNBIQPMZJPLSGQEJEYDTZIRWZTEJDXCVKPRDLNKTUGRPOQIBZRACXMWZVUATPKHXKWCGSHHZEZROCCKQPDJRJWDRKRGZTRSJOCTZMKSHJFGFBTVIPCCVYEEBCWRVMWQIQZHGVSNSIOPVUWZLCKTDPSUKGHAXIDWHLZFKNBDZEWHBSURTVCADUGTSDMCLDBTAGFWDPGXZBVARNTDICHCUJLNFBQOBTDWMGILXPSFWVGYBZVFFKQIDTOVFAPVNSQJULMVIERWAOXCKXBRIEHYPLTJVLSUTEWJMXNUCATGWKFH...

output:

PMZ

result:

ok single line: 'PMZ'

Test #12:

score: 0
Accepted
time: 794ms
memory: 15620kb

input:

MYNBIQPMZJPLSGQEJEYDTZIRWZTEJDXCVKPRDLNKTUGRPOQIBZRACXMWZVUATPKHXKWCGSHHZEZROCCKQPDJRJWDRKRGZTRSJOCTZMKSHJFGFBTVIPCCVYEEBCWRVMWQIQZHGVSNSIOPVUWZLCKTDPSUKGHAXIDWHLZFKNBDZEWHBSURTVCADUGTSDMCLDBTAGFWDPGXZBVARNTDICHCUJLNFBQOBTDWMGILXPSFWVGYBZVFFKQIDTOVFAPVNSQJULMVIERWAOXCKXBRIEHYPLTJVLSUTEWJMXNUCATGWKFH...

output:

BIQP

result:

ok single line: 'BIQP'

Test #13:

score: 0
Accepted
time: 643ms
memory: 15740kb

input:

BBABBBBBBAABAABABAABBABBBABBBAAABABBABAAAAABAABBABBABABBABBABAAAABBAAAAAABBAABBBBBABABBAAABAABABBAAAAAAAAAABABAAAAAABAAABABAAABBBAABAABABBBAAAAABBABAABBBBBBAABABABAABBBBABBBAAABAAABBBABBAABABABBAABBBBABAAAABBBAAAAAAAABBAABBAABBABABAABAAAABBBABBBBAABBAAABBBBABAABAABBBABABAABAABBBBBAABBBBABABBABBAABAA...

output:

BBABABAAAAAAABA

result:

ok single line: 'BBABABAAAAAAABA'

Test #14:

score: 0
Accepted
time: 0ms
memory: 3808kb

input:

A

output:

A

result:

ok single line: 'A'

Test #15:

score: 0
Accepted
time: 48ms
memory: 3812kb

input:

MYNMYNMYNMYNMYNMYNMYNMYNMYNMYNMYNMYNMYNMYNMYNMYNMYNMYNMYNMYNMYNMYNMYNMYNMYNMYNMYNMYNMYNMYNMYNMYNMYNMYNMYNMYNMYNMYNMYNMYNMYNMYNMYNMYNMYNMYNMYNMYNMYNMYN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