QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#437401#2902. Shortest Missing SubsequencesJustJie#AC ✓436ms52464kbC++202.1kb2024-06-09 09:54:012024-06-09 09:54:03

Judging History

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

  • [2024-06-09 09:54:03]
  • 评测
  • 测评结果:AC
  • 用时:436ms
  • 内存:52464kb
  • [2024-06-09 09:54:01]
  • 提交

answer

/***************************************************************************************************
 * author : Jie Chen (4th Year CS)
 * school : Rochester Institute of Technology
 * created: 06.08.2024 21:38:12
****************************************************************************************************/
#include "bits/stdc++.h"

using namespace std;

using i64 = long long;

constexpr int A = 26;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    const auto ord = [&](char c) {
        return c - 'a';
    };

    string can_use;
    cin >> can_use;
    int good_mask = 0;
    for (auto c : can_use) {
        good_mask |= (1 << ord(c));
    }

    string s;
    cin >> s;
    int n = s.size();

    vector<set<int>> pos(A);
    bool good = true;
    for (int i = 0; auto c : s) {
        pos[ord(c)].insert(i);
        if (!(good_mask & (1 << ord(c)))) {
            good = false;
            break;
        }
        i++;
    }

    int sz = 0;
    int i = -1;
    while (i < n) {
        int lst = -1;
        for (int a = 0; a < A; a++) {
            if (good_mask & (1 << a)) {
                auto it = pos[a].upper_bound(i);
                if (it == pos[a].end()) {
                    lst = n;
                    break;
                }
                lst = max(lst, *it);
            }
        }
        sz++;
        i = lst;
    }

    int q;
    cin >> q;

    while (q--) {
        string t;
        cin >> t;

        if (!good || t.size() != sz) {
            cout << "0\n";
        } else {
            bool res = false;
            int i = -1;
            for (auto c : t) {
                if (!(good_mask & (1 << ord(c)))) {
                    res = false;
                    break;
                }
                const auto& v = pos[ord(c)];
                auto it = v.upper_bound(i);
                if (it == v.end()) {
                    res = true;
                    break;
                }
                i = *it;
            }
            cout << (res ? "1" : "0") << "\n";
        }
    }
}

// ~ Just Jie

詳細信息

Test #1:

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

input:

abcd
abcccabac
3
cbb
cbba
cba

output:

0
0
0

result:

ok 3 lines

Test #2:

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

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: 331ms
memory: 51216kb

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: 436ms
memory: 52464kb

input:

d
dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd...

output:

1

result:

ok single line: '1'

Test #5:

score: 0
Accepted
time: 199ms
memory: 51128kb

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: 218ms
memory: 51160kb

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: 260ms
memory: 50900kb

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: 3820kb

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: 0ms
memory: 3612kb

input:

f
f
2
f
ff

output:

0
1

result:

ok 2 lines

Test #10:

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

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: 228ms
memory: 50972kb

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: 3532kb

input:

abcdefghijklmnopqrstu
orslbpmouunpnnfcgtbplsqimmroonbfbgoehmkohbdekngpkkudgpeknramojnffimsborgoheggfshaqrhteepcmchqdtsu
1
au

output:

0

result:

ok single line: '0'

Test #13:

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

input:

ab
aab
1
bb

output:

1

result:

ok single line: '1'

Test #14:

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

input:

ab
ba
1
bb

output:

1

result:

ok single line: '1'

Test #15:

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

input:

abc
baaaaac
1
cc

output:

1

result:

ok single line: '1'

Test #16:

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

input:

abc
abcccabac
3
cbb
cbba
cba

output:

1
0
0

result:

ok 3 lines