QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#64113#4666. Delete And WinzimindaadaRE 0ms0kbC++141.9kb2022-11-24 09:08:182022-11-24 09:08:22

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-24 09:08:22]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2022-11-24 09:08:18]
  • 提交

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(){
    #ifndef lkytxdy
    freopen("string.in","r",stdin);
    freopen("string.out","w",stdout);
    #else
    #endif
    scanf("%s", t+1); n = strlen(t+1);
    scanf("%s", s+1); m = strlen(s+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];
		}
	} 
	
	int nowans = 0, nowpos = 1, finishi = 1919810;
	for(int i = 1; i <= m; ++i){
		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;
		}
		
		if(nowpos <= n) ans = min(ans, nowans+(n-nowpos+1));
		
		if(nowpos > n || nowans >= ans) {
			finishi = i;
			break;
		}
	}
	if(finishi < m) ans = min(ans, nowans);
	if(ans > n) ans = n;
	cout << ans << '\n';
    return 0;
}

详细

Test #1:

score: 0
Dangerous Syscalls

input:

pqsrpspqz
pqrpqz

output:


result: