1 条题解

  • 0
    @ 2023-11-25 16:43:53
    #include <bits/stdc++.h>
    using namespace std;
    int n, m;
    string s[3005];
    int minPos, secPos; //最小、次小的 s 位置 
    string ss[3005];
    bool cmp(char a, char b)
    {
        return a > b;
    }
    int main()
    {
        freopen("dict.in", "r", stdin);
        freopen("dict.out", "w", stdout);
        ios::sync_with_stdio(false);
        cin.tie(0);
        // 输入
        cin >> n >> m;
        for (int i = 1; i <= n; i++)
            cin >> s[i];
        // 整理 s 变为最大值,ss 变为最小值(字典序)
        for (int i = 1; i <= n; i++)
        {
            ss[i] = s[i];
            sort(s[i].begin(), s[i].end(), cmp);
            sort(ss[i].begin(), ss[i].end());        
        }
        minPos = 0;
        secPos = 0;
        for (int i = 1; i <= n; i++)
        {
            if (minPos == 0 || s[i] < s[minPos])
            {
                secPos = minPos;
                minPos = i;
            }
            else if (secPos == 0 || s[i] < s[secPos])
            {
                secPos = i;
            }
        }
        //cout << s[minPos] << " " << s[secPos] << "\n";
        // 输出
        if (n == 1)
        {
            cout << "1";
            return 0;
        }
        for (int i = 1; i <= n; i++)
        {
            //cout << ss[i] << ":";
            if (i == minPos)
            {
                if(ss[i] < s[secPos])
                    cout << "1";
                else
                    cout << "0";
            }
            else
            {
                if(ss[i] < s[minPos])
                    cout << "1";
                else
                    cout << "0";
            }
            //cout<<"\n";
        }
        cout << '\n';
        return 0;
    }
    
    • 1

    信息

    ID
    1363
    时间
    1000ms
    内存
    512MiB
    难度
    10
    标签
    递交数
    8
    已通过
    2
    上传者