编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#3426 #1010. 击毙你~~~ Compile Error 0 0 ms 0 K C++ 17 / 1.5 K s230034010 2023-11-25 15:08:59
显示原始代码
#include <iostream>
#include <string>
#include <vector>

bool contains_subsequence(const std::string& word, const std::string& sub) {
    auto it = word.begin();
    for (char c : sub) {
        it = std::find(it, word.end(), c);
        if (it == word.end())
            return false;
        ++it;
    }
    return true;
}

int count_combinations_optimized(const std::vector<std::string>& words, const std::string& sub) {
    int count = 0;
    int n = words.size();
    std::vector<bool> contains_sub(n, false);

    for (int i = 0; i < n; ++i) {
        contains_sub[i] = contains_subsequence(words[i], sub);
    }

    for (int i = 0; i < n; ++i) {
        if (contains_sub[i]) {
            count += n;
        } else {
            for (int j = 0; j < n; ++j) {
                if (i != j) {
                    if (contains_sub[j] || contains_subsequence(words[i] + words[j], sub)) {
                        count += 1;
                    }
                }
            }
        }
    }

    for (int i = 0; i < n; ++i) {
        if (!contains_sub[i] && contains_subsequence(words[i] + words[i], sub)) {
            count += 1;
        }
    }

    return count;
}

int main() {
    int N;
    std::string T;
    std::cin >> N >> T;

    std::vector<std::string> words(N);
    for (int i = 0; i < N; ++i) {
        std::cin >> words[i];
    }

    int result = count_combinations_optimized(words, T);

    std::cout << result << std::endl;

    return 0;
}

编译信息

/sandbox/1/a.cpp: In function 'bool contains_subsequence(const string&, const string&)':
/sandbox/1/a.cpp:8:41: error: no matching function for call to 'find(__gnu_cxx::__normal_iterator<const char*, std::__cxx11::basic_string<char> >&, std::__cxx11::basic_string<char>::const_iterator, char&)'
    8 |         it = std::find(it, word.end(), c);
      |                                         ^
In file included from /usr/include/c++/10/bits/locale_facets.h:48,
                 from /usr/include/c++/10/bits/basic_ios.h:37,
                 from /usr/include/c++/10/ios:44,
                 from /usr/include/c++/10/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from /sandbox/1/a.cpp:1:
/usr/include/c++/10/bits/streambuf_iterator.h:422:5: note: candidate: 'template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT> >::__type std::find(std::istreambuf_iterator<_CharT>, std::istreambuf_iterator<_CharT>, const _CharT2&)'
  422 |     find(istreambuf_iterator<_CharT> __first,
      |     ^~~~
/usr/include/c++/10/bits/streambuf_iterator.h:422:5: note:   template argument deduction/substitution failed:
/sandbox/1/a.cpp:8:41: note:   '__gnu_cxx::__normal_iterator<const char*, std::__cxx11::basic_string<char> >' is not derived from 'std::istreambuf_iterator<_CharT>'
    8 |         it = std::find(it, word.end(), c);
      |                                         ^