trie报WA求调
查看原帖
trie报WA求调
772284
Justskr楼主2024/8/14 20:00
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
int tree[200][20];
int num[1006];
ll cnt;

inline void add(string n){
	ll p = 0;
	for(ll i = 0;i < n.size();i++){
		ll u = (ll)n[i]-'0';
		if(tree[p][u] == 0){
			tree[p][u] = ++cnt;
		}
		p = tree[p][u];
		num[p]++;
	}
}

inline ll query(string s){
	ll p = 0;
	for(ll i = 0;i < s.size();i++){
		ll u = (ll)s[i]-'0';
		if(tree[p][u] == 0){
			return 0;
		}
		p = tree[p][u];
	}
	return num[p];
}
string s[29009];
int main(){
	//ios::sync_with_stdio(false);
	//cin.tie(0),cout.tie(0);
	ll cntt = 0,cnttt = 0;
	while(cin >> s[++cntt]){
		if(s[cntt] == "9"){
			cnttt++;
			bool o = 0;
			for(ll i  = 1;i <= cntt;i++){
				if(query(s[i]) > 1){
					//cout << s[i] << " " << query(s[i]) <<  endl;
					cout << "Set " << cnttt << " is not immediately decodable";
					o = 1;
					break;
				}
				if(!o) cout << "Set " << cnttt << " is immediately decodable";
				cout << endl;
				break;
			}
			
			for(ll i = 0;i <= 20;i++){
				num[i] = 0;
				for(ll j = 0;j <= 20;j++){
					tree[i][j] = 0;
				}
			}
			cntt = 0;
			cnt = 0;
			continue;
		};
		add(s[cntt]);
	}



	return 0;
}

2024/8/14 20:00
加载中...