QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#64088 | #4666. Delete And Win | zimindaada | WA | 0ms | 3528kb | C++14 | 2.0kb | 2022-11-24 08:33:53 | 2022-11-24 08:33:59 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
namespace ztd{
using namespace std;
typedef long long ll;
template<typename T> inline T read(T& t) {
t=0;short f=1;char ch=getchar();
while (ch<'0'||ch>'9') {if (ch=='-') f=-f;ch=getchar();}
while (ch>='0'&&ch<='9') t=t*10+ch-'0',ch=getchar();
t*=f; return t;
}
}
using namespace ztd;
const int maxn = 1e5+7;
char s[maxn], t[maxn];
int n, m, buc[26], nxt[maxn][26];
inline int getDis(int x, int c){
int mn = 1919810;
for(int i = 0; i < c; ++i){
// cerr << i << ' ';
mn = min(mn, nxt[x][i]);
}
return mn-x;
}
int ans = 1919810;
signed main(){
scanf("%s", s+1); m = strlen(s+1);
scanf("%s", t+1); n = strlen(t+1);
ans = n;
for(int i = 1; i <= min(n,m); ++i){
if(t[i] > s[i]) goto failed;
else if(t[i] < s[i]) goto tryhard;
}
if(n < m){
tryhard:puts("0");
return 0;
}else if(n == m){
puts("1");
return 0;
}else if(n > m) ans = n-m+1;
failed:;
// cerr << ans << '\n';
for(int i = 0; i < 26; ++i) buc[i] = 1919810;
for(int i = n; i >= 1; --i){
for(int j = 0; j < 26; ++j){
if((int)(t[i]-'a') == j) buc[j] = i;
nxt[i][j] = buc[j];
}
}
// for(int j = 0; j < 26; ++j){
// cerr << (nxt[1][j] == 1919810 ? -1 : nxt[1][j]) << ' ';
// } cerr << '\n';
// getDis(1,s[1]-'a'); return 0;
// cerr << "kora\n";
int nowans = 0, nowpos = 1;
for(int i = 1; i <= m; ++i){
// cerr << i << " : " << getDis(nowpos, s[i]-'a') << " ";
ans = min(ans, nowans + getDis(nowpos, s[i]-'a'));
if(nxt[nowpos][s[i]-'a'] != 1919810){
nowans += (nxt[nowpos][s[i]-'a']-nowpos);
nowpos = nxt[nowpos][s[i]-'a']+1;
}else{
nowans += (n-nowpos+1);
ans = min(ans, nowans);
nowpos = maxn+1;
}
// cerr << ans << ' ' << nowans << ' ' << nowpos << '\n';
if(nowpos == n+1){
if(m > nowpos) ans = min(ans, nowans);
else ;
}
if(nowpos > n || nowans >= ans) break;
}
if(ans > n) ans = n;
cout << ans << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3528kb
input:
pqsrpspqz pqrpqz
output:
0
result:
wrong answer 1st numbers differ - expected: '2', found: '0'