Gym 101086 M ACPC Headquarters : AASTMT (Stairway to Heaven)

来源:互联网 发布:大数据 a股 编辑:程序博客网 时间:2024/05/21 22:29

M ACPC Headquarters : AASTMT (Stairway to Heaven)

As most of you know, the Arab Academy for Science and Technology and Maritime Transport in Alexandria, Egypt, hosts the ACPC Headquarters in the Regional Informatics Center (RIC), and it has been supporting our region with all kinds of resources it can provide, whether it was hosting nationals, regionals, or providing support for national contests around the Arab Region by sending its employees and students to participate in preparing contest systems, coaching, problem setting, and whatever these nationals ask for. However, ACPC’s volunteers’ schedules can get very busy, therefore, some conflicts might occur between the nationals they are assigned to help with. As to resolve these conflicts, Noura suggested that the SCPC2015 students can come up with a program that detects the conflicts in the contests’ schedule, and that is, detect for each volunteer whether they have been assigned to multiple contests running at the same time.

Given the requirements for each contest (contest name, start date, end date, number of required volunteers, volunteers’ names), print a list of volunteers’ names that have conflicts in their schedules, sorted in alphabetical order.

Input

The first line of input contains an integer T (1 ≤ T ≤ 330), the number of test cases.Each test case will contain only one string S of length 7. Each letter of the string represents the difficulty level of a problem (from A to E), 'A' is the easiest and 'E' is the hardest.

Output

For each test case print "YES" if she can prepare a contest using the current problems, otherwise print "NO".

Example

Input

3
EBEABDA
CEDEACA
BDAAEAA

Output

YES
NO
YES

Note

Warning: large Input/Output data, be careful with certain languages.

Solution

Every person every day only one job, else is illegal;
Pay attention to the details. There’re 3 TLE results before this 293ms-AC solotion, just because of ignoring somebody already passed.

Code

#include <bits/stdc++.h>using namespace std;typedef long long ll;set<string> ss;map<string,int> d;int T,sum,n,m,s,e,v,tot;string name;bool sheet[10001][366];int main() {//    freopen("03.in","r",stdin);//    freopen("03.out","w",stdout);    ios_base::sync_with_stdio(false);    cin.tie(0);    cin>>T;    while (T--) {        d.clear();        ss.clear();        memset(sheet,0,sizeof(sheet));        tot=0;        cin>>n;        while (n--) {            cin>>name;            cin>>s>>e>>v;            while (v--) {                cin>>name;                if (!d[name]) d[name]=++tot;                int p=d[name];                if (sheet[p][0]) continue;                for (int i=s; i<=e; ++i)                    if (sheet[p][i]) {                        sheet[p][0]=true;                        ss.insert(name);                        break;                    } else sheet[p][i]=true;            }        }        cout<<ss.size()<<endl;        set<string>::iterator p;        for (p=ss.begin(); p!=ss.end(); p++) cout<<(*p)<<endl;    }    return 0;}