UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#212172#3817. 写字PanjunnanCompile Error//C++1.6kb2024-10-13 11:48:042024-10-13 12:29:36

answer

#include <iostream>
#include <vector>
#include <unordered_map>
#include <climits>
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    string S, T;
    cin >> S >> T;

    // 构建S中每个字符的位置映射
    unordered_map<char, vector<int>> positions;
    for (int i = 0; i < n; ++i) {
        positions[S[i]].push_back(i);
    }

    // dp数组初始化
    vector<vector<int>> dp(m + 1, vector<int>(n + 1, INT_MAX));
    dp[0][0] = 0; // 初始化条件

    for (int i = 0; i <= m; ++i) {
        for (int j = 0; j <= n; ++j) {
            if (i > 0) {
                // 从S的某个位置j移动到S的另一个位置k,使得S[k] == T[i-1]
                if (!positions[T[i - 1]].empty()) {
                    for (int k : positions[T[i - 1]]) {
                        dp[i][k + 1] = min(dp[i][k + 1], dp[i - 1][j] + abs(k + 1 - j));
                    }
                }
                // 从S的某个位置j移动到S的另一个位置j+1,使得S[j+1] == T[i-1]
                if (j < n && S[j] == T[i - 1]) {
                    dp[i][j + 1] = min(dp[i][j + 1], dp[i - 1][j] + 1);
                }
            }
            // 从S的某个位置j移动到S的另一个位置j+1,使得S[j+1] != T[i]
            if (j < n) {
                dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + 1);
            }
        }
    }

    // 找到最小时间
    int minTime = INT_MAX;
    for (int j = 0; j <= n; ++j) {
        minTime = min(minTime, dp[m][j]);
    }

    cout << (minTime == INT_MAX ? -1 : minTime) << endl;
    return 0;
}

详细

In file included from /usr/include/c++/4.8/unordered_map:35:0,
                 from answer.code:3:
/usr/include/c++/4.8/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
 #error This file requires compiler and library support for the \
  ^
answer.code: In function 'int main()':
answer.code:14:5: error: 'unordered_...