提出 #72014811


ソースコード 拡げる

#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <deque>
#include <iterator>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <utility>
#define open(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef char ch;
typedef string str;
ll n,m;
str s,t;
map<pair<ch,ch>,ll> mp;
void init()
{
	for(char a='0';a<='9';a++)
	{
		for(char b='0';b<='9';b++)
		{
			mp[make_pair(a,b)]=(b-a+10)%10;
		}
	}
}
ll cost(str a,str b)
{
	ll l=a.length();
	ll cst=0;
	for(int i=0;i<l;i++) cst+=mp[make_pair(a[i],b[i])];
	return cst;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m>>s>>t;
    ll ans=1e18;
    init();
	for(int i=0;i+m-1<n;i++)
	{
		str temp="";
		for(int j=i,cnt=1;cnt<=m;j++,cnt++) temp+=s[j];
		ans=min(ans,cost(t,temp));
	}
    cout<<ans;
}

提出情報

提出日時
問題 B - Substring 2
ユーザ zjd2013
言語 C++23 (GCC 15.2.0)
得点 200
コード長 1121 Byte
結果 AC
実行時間 2 ms
メモリ 3636 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 200 / 200
結果
AC × 4
AC × 22
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3492 KiB
00_sample_01.txt AC 1 ms 3600 KiB
00_sample_02.txt AC 1 ms 3432 KiB
00_sample_03.txt AC 1 ms 3404 KiB
01_random_00.txt AC 1 ms 3544 KiB
01_random_01.txt AC 1 ms 3544 KiB
01_random_02.txt AC 1 ms 3404 KiB
01_random_03.txt AC 1 ms 3404 KiB
01_random_04.txt AC 1 ms 3556 KiB
01_random_05.txt AC 2 ms 3404 KiB
01_random_06.txt AC 1 ms 3604 KiB
01_random_07.txt AC 1 ms 3492 KiB
01_random_08.txt AC 1 ms 3636 KiB
01_random_09.txt AC 1 ms 3404 KiB
01_random_10.txt AC 2 ms 3556 KiB
01_random_11.txt AC 1 ms 3556 KiB
01_random_12.txt AC 1 ms 3504 KiB
01_random_13.txt AC 1 ms 3504 KiB
01_random_14.txt AC 1 ms 3600 KiB
01_random_15.txt AC 1 ms 3504 KiB
01_random_16.txt AC 1 ms 3504 KiB
01_random_17.txt AC 1 ms 3492 KiB