UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#212146#3817. 写字yangtianming001Compile Error//C++111.5kb2024-10-13 11:35:142024-10-13 12:27:10

answer

#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <climits>

using namespace std;

int find_min_time(string S, string T) {
	int n = S.length(), m = T.length();
	
	unordered_map<char, vector<int>> char_pos;
	for (int i = 0; i < n; i++) {
		char_pos[S[i]].push_back(i);
	}
	
	for (char c : T) {
		if (char_pos.find(c) == char_pos.end()) {
			return -1; 
		}
	}
	
	vector<vector<int>> dp(n, vector<int>(m, INT_MAX));
	
	queue<tuple<int, int, int>> q;
	
	for (int start_pos : char_pos[T[0]]) {
		q.push({start_pos, 0, 1});
		dp[start_pos][0] = 1;
	}
	
	while (!q.empty()) {
		auto [s_pos, t_pos, time] = q.front();
		q.pop();
		
		if (t_pos == m - 1) {
			return time;
		}
		
		char next_char = T[t_pos + 1];
		
		if (s_pos - 1 >= 0 && dp[s_pos - 1][t_pos] > time + 1) {
			dp[s_pos - 1][t_pos] = time + 1;
			q.push({s_pos - 1, t_pos, time + 1});
		}
		if (s_pos + 1 < n && dp[s_pos + 1][t_pos] > time + 1) {
			dp[s_pos + 1][t_pos] = time + 1;
			q.push({s_pos + 1, t_pos, time + 1});
		}
		
		for (int jump_pos : char_pos[next_char]) {
			if (jump_pos != s_pos && dp[jump_pos][t_pos + 1] > time + abs(jump_pos - s_pos)) {
				dp[jump_pos][t_pos + 1] = time + abs(jump_pos - s_pos);
				q.push({jump_pos, t_pos + 1, dp[jump_pos][t_pos + 1]});
			}
		}
	}
	
	return -1;
}

int main() {
	int n, m;
	string S, T;
	cin >> n >> m;
	cin >> S;
	cin >> T;
	cout << find_min_time(S, T) << endl;
	
	return 0;
}

Details

answer.code: In function 'int find_min_time(std::string, std::string)':
answer.code:28:27: error: converting to 'std::queue<std::tuple<int, int, int> >::value_type {aka std::tuple<int, int, int>}' from initializer list would use explicit constructor 'constexpr std::tuple< <template-parameter-1-1> >::tuple(_UElements&& ...) [with _UElements = {int&, int, int}; <template-parameter-2-2> = void; _Elements = {int, int, int}]'
   q.push({start_pos, 0, 1});\x0d
                           ^
answer.code:33:...