QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#58218#2902. Shortest Missing SubsequencesBeevo#AC ✓709ms74980kbC++231.5kb2022-10-25 03:46:472022-10-25 03:46:48

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-25 03:46:48]
  • 评测
  • 测评结果:AC
  • 用时:709ms
  • 内存:74980kb
  • [2022-10-25 03:46:47]
  • 提交

answer

#include <bits/stdc++.h>

#define el '\n'
#define ll long long
#define ld long double

#define Beevo ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

const int N = 1e6 + 5, INF = 1e9;

int n, m;
string v;
int dp[N];
vector<int> indices[26];

int solve(int idx) {
    if (idx > n)
        return 0;

    int &ret = dp[idx];

    if (~ret)
        return ret;

    ret = INF;

    for (int i = 0; i < m; i++) {
        auto up = upper_bound(indices[v[i] - 'a'].begin(), indices[v[i] - 'a'].end(), idx);

        ret = min(ret, solve(*up) + 1);
    }

    return ret;
}

bool valid(int idx, int relIdx, string &s) {
    if (idx > n)
        return 0;

    if (relIdx >= s.size())
        return 1;

    auto up = upper_bound(indices[s[relIdx] - 'a'].begin(), indices[s[relIdx] - 'a'].end(), idx);

    return valid(*up, relIdx + 1, s);
}

void testCase() {
    string s;
    cin >> v >> s;

    n = s.size(), m = v.size();

    sort(v.begin(), v.end());

    for (int i = 0; i < n; i++)
        indices[s[i] - 'a'].push_back(i + 1);

    for (int i = 0; i < m; i++)
        indices[v[i] - 'a'].push_back(n + 1);

    memset(dp, -1, sizeof dp);

    int q;
    cin >> q;

    while (q--) {
        cin >> s;

        if (s.size() != solve(0) || valid(indices[s[0] - 'a'][0], 1, s))
            cout << 0 << el;
        else
            cout << 1 << el;
    }
}

signed main() {
    Beevo

    int T = 1;
//    cin >> T;

    while (T--)
        testCase();

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 6ms
memory: 7536kb

input:

abcd
abcccabac
3
cbb
cbba
cba

output:

0
0
0

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 5ms
memory: 7444kb

input:

z
zzzzzzz
10
z
zz
zzz
zzzz
zzzzz
zzzzzz
zzzzzzz
zzzzzzzz
zzzzzzzzz
zzzzzzzzzz

output:

0
0
0
0
0
0
0
1
0
0

result:

ok 10 lines

Test #3:

score: 0
Accepted
time: 630ms
memory: 16576kb

input:

abcdefghijklmnopqrstuvwxyz
oaxsgfhkwuecvdrltjzpqibnymtaympfvuzogrqkwhbdcsjleixnojmletqrbkdzfhawpsxcvyniughnqibtzjpewovluyrdfmakxscgcyhmqbieontgwufalzjsprvkdxzfqsrijldncaphwxyutbgevmokltvqhkprunydecwmgxoijzbfsacafhozxyljvnrmbdupeqiswgtkbhwxptqayglfovirnjuemkdczsmyadiqnwtxjbhlsvokpucgefrzvicbdnkrjmxgf...

output:

0
0
1
1
0
1
1
1
1
1
1
1
1
1
1
0
0
0
0
0
0
0
0
0
0
0

result:

ok 26 lines

Test #4:

score: 0
Accepted
time: 120ms
memory: 74980kb

input:

d
dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd...

output:

1

result:

ok single line: '1'

Test #5:

score: 0
Accepted
time: 707ms
memory: 16568kb

input:

abcdefghijklmnopqrstuvwxyz
wktxlbgnmkyuvhmjpxxfndhdtcqugxnsvpxdictbxwrimocjliqqxfomlwngbvyoyacswksvurqaqmvwigtiswbfyofgvdvolcciwnymchohsdoivyofupophlcpukipgheeveaqrgmbcrtdwdybwcxsyvorkvsnhnvgwfxrpvykphlmrqsyujciqdmpqiwegathdsfjueilvbcudwsfbvpqxyoprbadqepvpdkcjvdapafesdmftubyraolqcvgbfbqhjlebnmbpcskf...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
1
0
0
0
0
0
1
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
1
0
0
1
0
0
0
0
0
0
0
0
0
1
0
0
1
...

result:

ok 10000 lines

Test #6:

score: 0
Accepted
time: 709ms
memory: 16644kb

input:

abcdefghijklmnopqrstuvwxyz
wktxlbgnmkyuvhmjpxxfndhdtcqugxnsvpxdictbxwrimocjliqqxfomlwngbvyoyacswksvurqaqmvwigtiswbfyofgvdvolcciwnymchohsdoivyofupophlcpukipgheeveaqrgmbcrtdwdybwcxsyvorkvsnhnvgwfxrpvykphlmrqsyujciqdmpqiwegathdsfjueilvbcudwsfbvpqxyoprbadqepvpdkcjvdapafesdmftubyraolqcvgbfbqhjlebnmbpcskf...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
1
0
0
1
0
0
0
0
0
0
0
0
0
1
0
0
1
...

result:

ok 10000 lines

Test #7:

score: 0
Accepted
time: 588ms
memory: 19092kb

input:

abcdefghijklmnopqrstuvwxyz
ngmgaeihgmnehfjdicecmbjmeilmjceblbnkfhibfgfjkdihhnieamiablnglnmkkajhnnfdlflnbdjddmcmihbbfihbeielbifnidmjijehbjmgfjdecdncajkehbbkmccanblnikgnlieimdndkjngjehhkklmfbfjbhjkfnddalebldfmcfgnabmcnldanjkijkbabkdjnjbgbfnbajadclbhdlmakaigjbnebdbkefgcaihajblgdeflhnjclkdmamkcncfiebjhk...

output:

1
0
1
1
1
0
1
0
0
1
0
1
0
1
0
0
0
0
1
1
1
0
0
0
1
1
0
0
1
1
0
0
0
1
0
0
0
1
1
0
0
0
0
0
1
0
1
1
1
0
0
1
0
0
0
0
1
0
1
1
1
1
0
0
0
1
0
0
0
1
1
0
1
0
1
0
0
1
1
1
1
1
0
0
1
0
0
1
0
1
0
0
1
1
0
1
0
1
1
0
1
0
1
1
0
0
1
0
1
0
1
1
0
0
0
1
1
0
0
1
1
0
1
0
0
0
1
0
1
1
0
1
0
0
0
0
1
1
1
1
0
0
0
1
0
0
1
0
1
0
...

result:

ok 1000000 lines

Test #8:

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

input:

abcd
aabcdacbacdabcabdcccbddadbcdbacbdad
8
dddaadda
dddaaddb
dddaaddc
dddaaddd
dddaadaa
dddaadab
dddaadac
dddaadad

output:

0
0
0
0
0
0
0
0

result:

ok 8 lines

Test #9:

score: 0
Accepted
time: 2ms
memory: 7460kb

input:

f
f
2
f
ff

output:

0
1

result:

ok 2 lines

Test #10:

score: 0
Accepted
time: 1ms
memory: 7524kb

input:

xy
x
6
x
y
xx
xy
yx
yy

output:

0
1
0
0
0
0

result:

ok 6 lines

Test #11:

score: 0
Accepted
time: 636ms
memory: 13596kb

input:

abcdefghijklmnopqrstuvwxyz
irxwwhliqvpptnwkhqgyxopsvwguplvwksziymgggtrgzynukovgrkwpzqrknkukvpzmzgoxzrztijtvymivmyvuqzoqxzujmlsyqxzqosxgqlvwootjnryuwuvnhptqiwjqxonqvgpgmuxsssotjjqkgwkrzyrkoqnzxsnpzltrsvgowxxyzvqwiqwrkozhqynrrkzqoqxnongrrtwsmpsgwktjrsjyhwrwxxzlgxzuhhygpgvvllliwtjnmhjjlrzjtltumpumqpigm...

output:

0
0
1
0
0
0
1
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
1
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
1
0
0
1
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
1
0
0
...

result:

ok 200000 lines

Test #12:

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

input:

abcdefghijklmnopqrstu
orslbpmouunpnnfcgtbplsqimmroonbfbgoehmkohbdekngpkkudgpeknramojnffimsborgoheggfshaqrhteepcmchqdtsu
1
au

output:

0

result:

ok single line: '0'

Test #13:

score: 0
Accepted
time: 3ms
memory: 7464kb

input:

ab
aab
1
bb

output:

1

result:

ok single line: '1'

Test #14:

score: 0
Accepted
time: 2ms
memory: 7520kb

input:

ab
ba
1
bb

output:

1

result:

ok single line: '1'

Test #15:

score: 0
Accepted
time: 3ms
memory: 7464kb

input:

abc
baaaaac
1
cc

output:

1

result:

ok single line: '1'

Test #16:

score: 0
Accepted
time: 1ms
memory: 7468kb

input:

abc
abcccabac
3
cbb
cbba
cba

output:

1
0
0

result:

ok 3 lines