1 solutions

  • 1
    @ 2026-4-1 9:47:58
    #include<bits/stdc++.h>
    using namespace std;
    string s[111110];
    int main()
    {
        int t;cin>>t;
        while(t--)
        {
            int n;cin>>n;
            for(int i=1;i<=n;i++)
            {
                cin>>s[i];
            }
            sort(s+1,s+n+1);
            bool st=true;
            for(int i=1;i<=n;i++)
            {
                for(int j=0;j+1<s[i].size();j++)
                {
                    if(s[i][j]>s[i][j+1]) 
                    {
                        st=false;
                    }
                }
            }
            for(int i=1;i+1<=n;i++)
            {
                if(s[i][s[i].size()-1]>s[i+1][0]) st=false;
            }
            if(st==true) cout<<1<<endl;
            else cout<<0<<endl;
        }
        return 0;
    }
    
    • 1

    Information

    ID
    2216
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    10
    Tags
    # Submissions
    1
    Accepted
    1
    Uploaded By