/* * Warmup Contest #2, September 4, 2010 Problem B * Solution by Nathaniel Barshay * Originally from http://ncpc.idi.ntnu.no/ncpc2007/ncpc2007problems.pdf (problem A) * ACM NCPC 2007 Problem A * * Put all strings into a set (treeset). Check if the prefix * of any string is in the set. * * Ignore the list of macros at the start of the code. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define IT(c) typeof((c).begin()) #define For(i, a, b) for(int (i) = int(a); i < int(b); ++i) #define rep(x, n) For(x,0,n) #define forit(c, i) for(IT(c) i = (c).begin(); i != (c).end(); ++i) #define bound(num, lower, upper) (max(min((num),((upper)-1)),(lower))) #define debug(x) cerr << #x << " = " << x << "\n" #define sz(a) int((a).size()) #define pb push_back #define all(c) (c).begin(),(c).end() #define mp make_pair #define setmin(a,b) a=min(a,b) #define setmax(a,b) a=max(a,b) typedef vector vi; typedef vector > vvi; typedef vector vs; typedef pair ii; /*==================================================================================================================*/ int main() { int np;cin>>np; rep(tp,np) { int n;cin>>n; set s; vector v; rep(i,n) { string ss;cin>>ss; v.pb(ss); s.insert(ss); } bool valid=true; rep(i,n) { string hit=v[i]; For(i,1,sz(hit)) { if(s.count(hit.substr(0,i))) valid=false; } } printf("%s\n", valid?"YES":"NO"); } }