Submission #28238

# Submission time Handle Problem Language Result Execution time Memory
28238 2017-07-16T04:06:11 Z 三( ε:)(#1146, xdoju, veckal, unused) Play Onwards (FXCUP2_onward) C++14
0 / 1
43 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 <= s1.size() - k; i++)
    {
        st.insert(s1.substr(i, k));
    }

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

bool dfs(int t, int c = 1)
{
    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);
            }
        }
    }

    for (int i = 0; i < n; i++)
    {
        if (vis[i] == 0 && dfs(i) == false)
        {
            printf("No\n");
            return 0;
        }
    }

    printf("Yes\n");
    for (int i = 0; i < n; i++) printf("%d\n", vis[i]);
}

Compilation message

onward.cpp: In function 'bool comp(const string&, const string&, int)':
onward.cpp:11:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i <= s1.size() - k; i++)
                       ^
onward.cpp:16:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int j = 0; j <= s2.size() - k; j++)
                       ^
# 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 13 ms 2304 KB Output is correct
6 Correct 26 ms 2304 KB Output is correct
7 Correct 43 ms 2040 KB Output is correct
8 Correct 33 ms 2040 KB Output is correct
9 Correct 39 ms 2040 KB Output is correct
10 Correct 36 ms 2040 KB Output is correct
11 Incorrect 6 ms 2040 KB Output isn't correct
12 Halted 0 ms 0 KB -