1 条题解
-
0
思路
数字串保留前导0,任意两个输入项前缀冲突含重复号码则NO;旧短串/新短串两方向都检查,40组清空状态。
参考程序(C++11)
#include <bits/stdc++.h> using namespace std; int main(){ios::sync_with_stdio(false);cin.tie(nullptr);int t;cin>>t;while(t--){int n;cin>>n;vector<array<int,10>>tr(1);vector<char>end(1);tr.reserve(n*10+1);end.reserve(n*10+1);bool ok=true;while(n--){string s;cin>>s;int v=0;for(char c:s){if(end[v])ok=false;int x=c-'0';if(!tr[v][x]){tr[v][x]=tr.size();tr.push_back({});end.push_back(0);}v=tr[v][x];}if(end[v])ok=false;for(int u:tr[v])if(u)ok=false;end[v]=1;}cout<<(ok?"YES":"NO")<<'\n';}}
- 1