Submission #72054918


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
	return x*f;
}
void out(int x)
{
    if(x<0)putchar('-'),x=-x;
    if(x<10)putchar(x+'0');
    else out(x/10),putchar(x%10+'0');
}
int n,m;
char a[105],b[105];
int main(){
	n=read();
	m=read();
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int j=1;j<=m;j++) cin>>b[j];
	int ans=INT_MAX;
	for(int i=1;i<=n-m+1;i++){
		int da=0;
		for(int j=1;j<=m;j++){
			if(a[i+j-1]<b[j]) da+=((a[i+j-1]-'0')+10-(b[j]-'0'));
			if(a[i+j-1]>b[j]) da+=(a[i+j-1]-'0')-(b[j]-'0');
		}
		ans=min(ans,da);
	}
	cout<<ans;
	return 0;
}

Submission Info

Submission Time
Task B - Substring 2
User Fireflies
Language C++23 (GCC 15.2.0)
Score 200
Code Size 746 Byte
Status AC
Exec Time 1 ms
Memory 3676 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 200 / 200
Status
AC × 4
AC × 22
Set Name Test Cases
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
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3644 KiB
00_sample_01.txt AC 1 ms 3528 KiB
00_sample_02.txt AC 1 ms 3348 KiB
00_sample_03.txt AC 1 ms 3484 KiB
01_random_00.txt AC 1 ms 3356 KiB
01_random_01.txt AC 1 ms 3488 KiB
01_random_02.txt AC 1 ms 3676 KiB
01_random_03.txt AC 1 ms 3632 KiB
01_random_04.txt AC 1 ms 3632 KiB
01_random_05.txt AC 1 ms 3632 KiB
01_random_06.txt AC 1 ms 3632 KiB
01_random_07.txt AC 1 ms 3544 KiB
01_random_08.txt AC 1 ms 3348 KiB
01_random_09.txt AC 1 ms 3356 KiB
01_random_10.txt AC 1 ms 3544 KiB
01_random_11.txt AC 1 ms 3480 KiB
01_random_12.txt AC 1 ms 3528 KiB
01_random_13.txt AC 1 ms 3480 KiB
01_random_14.txt AC 1 ms 3632 KiB
01_random_15.txt AC 1 ms 3644 KiB
01_random_16.txt AC 1 ms 3632 KiB
01_random_17.txt AC 1 ms 3428 KiB