编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#3428 #1010. 击毙你~~~ Compile Error 0 0 ms 0 K C++ 17 (Clang) / 1.5 K s230034010 2023-11-25 15:09:29
显示原始代码
#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:8:14: error: no matching function for call to 'find'
        it = std::find(it, word.end(), c);
             ^~~~~~~~~
/usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/streambuf_iterator.h:422:5: note: candidate template ignored: could not match 'istreambuf_iterator' against '__normal_iterator'
    find(istreambuf_iterator<_CharT> __first,
    ^
1 error generated.