Submission #28551

# Submission time Handle Problem Language Result Execution time Memory
28551 2017-07-16T07:15:30 Z 이제 내가 두목이다~(#1175, exqt, kshy9598) Play Onwards (FXCUP2_onward) C++11
0 / 1
19 ms 2296 KB
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;

vector<int> adj[202];
int dic[202];
string str[202];
bool flag = true;

void dfs(int x, int c)
{
    if(dic[x] != c && dic[x] != 0)
    {
        flag = false;
        return;
    }
    if(dic[x] == c) return;
    if(!flag) return;

    dic[x] = c;
    for(int nxt : adj[x])
    {
        dfs(nxt, c == 1 ? 2 : 1);
    }
}

int asdf(string s, string t, int k)
{
    if(s.size() < k || t.size() < k) return 0;
    for(int i=0; i<(int)s.size()-k+1; i++)
    {
        string a = s.substr(i, k);
        if(t.find(a) != string::npos) return 1;
    }
    return 0;
}

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(asdf(str[i], str[j], k) || asdf(str[j], str[i], k))
            {
                adj[j].push_back(i);
                adj[i].push_back(j);
            }
        }
    }

    for(int i=0; i<n; i++)
    {
        if(dic[i] == 0) dfs(i, 1);
    }

    if(flag)
    {
        cout << "Yes\n";
        for(int i=0; i<n; i++) cout << dic[i] << '\n';
    }
    else cout << "No\n";

	return 0;
}

Compilation message

onward.cpp: In function 'int asdf(std::__cxx11::string, std::__cxx11::string, int)':
onward.cpp:34:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(s.size() < k || t.size() < k) return 0;
                 ^
onward.cpp:34:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(s.size() < k || t.size() < k) return 0;
                                 ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2032 KB Output is correct
2 Correct 0 ms 2032 KB Output is correct
3 Correct 0 ms 2032 KB Output is correct
4 Correct 0 ms 2032 KB Output is correct
5 Correct 3 ms 2296 KB Output is correct
6 Correct 0 ms 2296 KB Output is correct
7 Correct 19 ms 2032 KB Output is correct
8 Correct 19 ms 2032 KB Output is correct
9 Correct 16 ms 2032 KB Output is correct
10 Correct 16 ms 2032 KB Output is correct
11 Incorrect 6 ms 2032 KB Output isn't correct
12 Halted 0 ms 0 KB -