답안 #1016077

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1016077 2024-07-07T11:23:32 Z vjudge1 Bajka (COCI20_bajka) C++17
50 / 70
65 ms 792 KB
#include <bits/stdc++.h>

using namespace std;

int main()
{
	int n,m;
	cin>>n>>m;
	string s,t;
	cin>>s>>t;
	int dp[n][m+1];
	for (int i=0;i<n;i++)
		for (int j=0;j<=m;j++)
			dp[i][j]=n*m*j;
	vector<int> ind[256];
	for (int i=0;i<n;i++)
		ind[s[i]].push_back(i);
	for (int j=1;j<=m;j++)
		for (int i=0;i<n;i++)
		{
			for (int k:ind[s[i]])
			{
				if (k && s[k-1]==t[m-j])
					dp[i][j]=min(dp[i][j],dp[k-1][j-1]+1+abs(i-k));
				if (k<n-1 && s[k+1]==t[m-j])
					dp[i][j]=min(dp[i][j],dp[k+1][j-1]+1+abs(i-k));
			}
		}
	int ans=dp[0][m];
	for (int i=1;i<n;i++)
		ans=min(ans,dp[i][m]);
	if (ans>=n*m)
		ans=0;
	cout<<ans-1<<endl;
	
	return 0;
}

Compilation message

bajka.cpp: In function 'int main()':
bajka.cpp:17:11: warning: array subscript has type 'char' [-Wchar-subscripts]
   17 |   ind[s[i]].push_back(i);
      |           ^
bajka.cpp:21:23: warning: array subscript has type 'char' [-Wchar-subscripts]
   21 |    for (int k:ind[s[i]])
      |                       ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 788 KB Output is correct
2 Correct 14 ms 604 KB Output is correct
3 Correct 5 ms 792 KB Output is correct
4 Correct 7 ms 604 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 13 ms 788 KB Output is correct
8 Correct 36 ms 604 KB Output is correct
9 Correct 65 ms 604 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 11 ms 604 KB Output is correct