QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#56551 | #2902. Shortest Missing Subsequences | abdelrahman001 | AC ✓ | 140ms | 111820kb | C++ | 1.8kb | 2022-10-20 02:06:32 | 2022-10-20 02:06:33 |
Judging History
answer
/// :3
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
#include "bits/stdc++.h"
#define pb push_back
#define F first
#define S second
#define f(i, a, b) for(int i = a; i < b; i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define mp(x,y) make_pair(x,y)
#define popCnt(x) (__builtin_popcountll(x))
//#define int ll
using ll = long long;
using ii = pair<int, int>;
using ull = unsigned long long;
const int N = 1e6+5, LG = 18, MOD = (119 << 23) + 1;
const long double PI = acos(-1);
const long double EPS = 1e-7;
const int dx[] = {1,1,0,-1,-1,-1,0,1};
const int dy[] = {0,1,1,1,0,-1,-1,-1};
const int bl = 1000;
string v, s;
int nxt[N][26], n;
int dp[N];
bool isSub(string t) {
for(int i = 0, j = 0; i < t.size(); i++) {
j = nxt[j][t[i]-'a'];
if(j == n + 1)return false;
}
return true;
}
void doWork() {
cin >> v >> s;
n = s.size();
fill(nxt[n], nxt[n] + 26, n+1);
for(int i = n - 1; i >= 0; --i) {
f(j,0,26)nxt[i][j]=nxt[i+1][j];
nxt[i][s[i]-'a'] = i + 1;
}
dp[n] = 1;
for(int i = n - 1; i >= 0; --i) {
dp[i] = INT_MAX;
for(char c : v) {
dp[i] = min(dp[i], dp[nxt[i][c-'a']] + 1);
}
}
int q; cin >> q;
while(q--) {
string t;
cin >> t;
if(!isSub(t) && t.size() == dp[0])
cout << "1\n";
else
cout << "0\n";
}
}
int32_t main() {
#ifdef ONLINE_JUDGE
ios_base::sync_with_stdio(0);
cin.tie(0);
#endif // ONLINE_JUDGE
int t = 1;
// cin >> t;
while (t--) {
doWork();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 5680kb
input:
abcd abcccabac 3 cbb cbba cba
output:
0 0 0
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 2ms
memory: 5664kb
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: 140ms
memory: 109608kb
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: 44ms
memory: 111820kb
input:
d dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd...
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 65ms
memory: 109688kb
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: 42ms
memory: 109680kb
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: 116ms
memory: 109772kb
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: 2ms
memory: 5776kb
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: 5600kb
input:
f f 2 f ff
output:
0 1
result:
ok 2 lines
Test #10:
score: 0
Accepted
time: 2ms
memory: 5684kb
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: 61ms
memory: 109680kb
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: 5664kb
input:
abcdefghijklmnopqrstu orslbpmouunpnnfcgtbplsqimmroonbfbgoehmkohbdekngpkkudgpeknramojnffimsborgoheggfshaqrhteepcmchqdtsu 1 au
output:
0
result:
ok single line: '0'
Test #13:
score: 0
Accepted
time: 1ms
memory: 5776kb
input:
ab aab 1 bb
output:
1
result:
ok single line: '1'
Test #14:
score: 0
Accepted
time: 0ms
memory: 5700kb
input:
ab ba 1 bb
output:
1
result:
ok single line: '1'
Test #15:
score: 0
Accepted
time: 2ms
memory: 5548kb
input:
abc baaaaac 1 cc
output:
1
result:
ok single line: '1'
Test #16:
score: 0
Accepted
time: 2ms
memory: 5776kb
input:
abc abcccabac 3 cbb cbba cba
output:
1 0 0
result:
ok 3 lines