Submission #28245

# Submission time Handle Problem Language Result Execution time Memory
28245 2017-07-16T04:08:12 Z 三( ε:)(#1146, xdoju, veckal, unused) Play Onwards (FXCUP2_onward) C++14
1 / 1
39 ms 2304 KB
#include <bits/stdc++.h>
using namespace std;

string str[205];
vector<int> graph[205];
int vis[205];

bool comp(const string &s1, const string &s2, int k)
{
    unordered_set<string> st;
    for (int i = 0; i <= (int)s1.size() - k; i++)
    {
        st.insert(s1.substr(i, k));
    }

    for (int j = 0; j <= (int)s2.size() - k; j++)
    {
        if (st.count(s2.substr(j, k))) return true;
    }
    return false;
}

bool dfs(int t, int c)
{
    vis[t] = c;
    for (int nxt : graph[t])
    {
        if (vis[nxt] == 0)
        {
            if (dfs(nxt, c ^ 3) == false) return false;
        }
        else if (vis[nxt] == vis[t]) return false;
    }
    return true;
}

int main()
{
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n; i++)
    {
        cin >> str[i];
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            if (comp(str[i], str[j], k))
            {
                graph[i].push_back(j);
                graph[j].push_back(i);
            }
        }
    }

    int C = 1;

    for (int i = 0; i < n; i++)
    {
        if (vis[i]) continue;
        if (dfs(i, C) == false)
        {
            printf("No\n");
            return 0;
        }
        else C ^= 3;
    }

    printf("Yes\n");
    for (int i = 0; i < n; i++) printf("%d\n", vis[i]);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2040 KB Output is correct
2 Correct 0 ms 2040 KB Output is correct
3 Correct 0 ms 2040 KB Output is correct
4 Correct 0 ms 2040 KB Output is correct
5 Correct 6 ms 2304 KB Output is correct
6 Correct 23 ms 2304 KB Output is correct
7 Correct 33 ms 2040 KB Output is correct
8 Correct 36 ms 2040 KB Output is correct
9 Correct 36 ms 2040 KB Output is correct
10 Correct 39 ms 2040 KB Output is correct
11 Correct 3 ms 2040 KB Output is correct
12 Correct 29 ms 2040 KB Output is correct
13 Correct 26 ms 2040 KB Output is correct
14 Correct 16 ms 2040 KB Output is correct
15 Correct 0 ms 2040 KB Output is correct
16 Correct 0 ms 2040 KB Output is correct
17 Correct 0 ms 2040 KB Output is correct
18 Correct 0 ms 2040 KB Output is correct
19 Correct 29 ms 2040 KB Output is correct
20 Correct 29 ms 2040 KB Output is correct
21 Correct 26 ms 2040 KB Output is correct