TLE求条
查看原帖
TLE求条
668800
_Kimi_楼主2024/12/21 16:39
#include<bits/stdc++.h>
#define int long long
#define sept fixed << setprecision(4)
#define debug(x) cerr << (#x) << endl
#define pb emplace_back
#define endl '\n' 
#define WA AC
using namespace std;
const int N = 1e4 + 10;
int T;
int n, tot, ans, cnt = 1;
char s[N];
int ch[N * 10][15];
int son[N * 10];
bool bo[N * 10];
void insert(char S[]){
	int len = strlen(S), u = 0;
	for(int i = 0; i < len; i++){
		int c = S[i] - '0';
		if(!ch[u][c]) ch[u][c] = ++tot, son[u]++;
		else if(!S[i + 1]) ans = 1;
		if(bo[ch[u][c]]) ans = 1;
		u = ch[u][c];
	}
	bo[u] = 1;
}
bool find(char S[]){
	int len = strlen(S), u = 1;
		for(int i = 0; i < len; i++){
		int c = S[i] - '0';
		u = ch[u][c];
	}
	if(bo[u] && son[u]) return 1;
	return 0;
}
void init(){
	tot = 1, ans = 0;
	memset(ch, 0, sizeof ch);
	memset(son, 0, sizeof son);
	memset(bo, 0, sizeof bo);
}
signed main(){
	srand(19491001);
	while(~scanf("%s", s)){
		if(s[0] == '9'){
			if(ans) printf("Set %d is not immediately decodable\n", cnt++);
			else printf("Set %d is immediately decodable\n", cnt++);
			init();
		}else insert(s);
	}
	return 0;
}

验证码cc66祭

2024/12/21 16:39
加载中...