ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#212161 | #3817. 写字 | Panjunnan | Compile Error | / | / | C++ | 1.3kb | 2024-10-13 11:43:12 | 2024-10-13 12:28:38 |
answer
#include <iostream>
#include <vector>
#include <unordered_map>
#include <climits>
using namespace std;
const int MAXN = 100005;
int dp[(int)1e4+5][26];
int n, m;
char S[MAXN], T[MAXN];
unordered_map<char, vector<int>> positions;
int main() {
cin >> n >> m;
cin >> S + 1;
cin >> T + 1;
for (int i = 1; i <= n; ++i) {
positions[S[i]].push_back(i);
}
for (int i = 0; i < m; ++i) {
dp[i+1][T[i+1] - 'a'] = INT_MAX;
}
for (int i = 1; i <= m; ++i) {
if (positions.find(T[i]) == positions.end()) {
cout << -1 << endl;
return 0;
}
for (int j = 0; j < 26; ++j) {
dp[i][j] = INT_MAX;
}
for (int j = 0; j < positions[T[i]].size(); ++j) {
int pos = positions[T[i]][j];
for (int k = 0; k < 26; ++k) {
if (i > 1) {
dp[i][k] = min(dp[i][k], dp[i-1][k] + 1 + abs(pos - positions[T[i-1]][0]));
}
dp[i][T[i] - 'a'] = min(dp[i][T[i] - 'a'], dp[i-1][j] + 1);
}
}
}
int minTime = INT_MAX;
for (int i = 0; i < 26; ++i) {
minTime = min(minTime, dp[m][i]);
}
cout << (minTime == INT_MAX ? -1 : minTime) << endl;
return 0;
}
Details
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:12:1: error: 'unordered_map' does not name a type unordered_ma...