UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#212039#3817. 写字xiangjy300ms1260kbC++2.0kb2024-10-13 10:34:262024-10-13 12:16:00

answer

#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
using namespace std;
/*
\\\\ \\ \\ \\ \\ \\ \\ \\ || || || || || || // // // // // // // ////
\\\\ \\ \\ \\ \\ \\ \\        _ooOoo_          // // // // // // ////
\\\\ \\ \\ \\ \\ \\          o8888888o            // // // // // ////
\\\\ \\ \\ \\ \\             88" . "88               // // // // ////
\\\\ \\ \\ \\                (| -_- |)                  // // // ////
\\\\ \\ \\                   O\  =  /O                     // // ////
\\\\ \\                   ____/`---'\____                     // ////
\\\\                    .'  \\|     |//  `.                      ////
//==                   /  \\|||  :  |||//  \                     ==\\
//==                  /  _||||| -:- |||||-  \                    ==\\
//==                  |   | \\\  -  /// |   |                    ==\\
//==                  | \_|  ''\---/''  |   |                    ==\\
//==                  \  .-\__  `-`  ___/-. /                    ==\\
//==                ___`. .'  /--.--\  `. . ___                  ==\\
//==             ."" '<  `.___\_<|>_/___.'  >' "".               ==\\
//==            | | :  `- \`.;`\ _ /`;.`/ - ` : | |              \\\\
////            \  \ `-.   \_ __\ /__ _/   .-` /  /              \\\\
////      ========`-.____`-.___\_____/___.-`____.-'========      \\\\
////                           `=---='                           \\\\
//// //   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  \\ \\\\
//// // //      佛祖保佑      永无BUG      永不修改        \\ \\ \\\\
//// // // // // // || || || || || || || || || || \\ \\ \\ \\ \\ \\\\
*/
int main(){
	int n,m,x,ans=0;
	scanf("%d%d",&n,&m);
	string a,b;
	cin>>a>>b;
	for(int i=0; i<m; i++) {
		bool flag=0;
		for(int j=0; j<n; j++) {
			if(b[i]==a[j]) {
				flag=1;
				if(i==0) x=j;
				else {
					ans+=abs(x-j);
					x=j;
				}
			}
		}
		if(!flag) {
			printf("-1");
			return 0;
		}
	}
	printf("%d",ans);
	return 0;
}

详细

小提示:点击横条可展开更详细的信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 20
Accepted
time: 0ms
memory: 1248kb

input:

1 1
v
v

output:

0

result:

ok 1 number(s): "0"

Test #2:

score: -20
Wrong Answer
time: 0ms
memory: 1256kb

input:

5 5
bacbb
cabcb

output:

14

result:

wrong answer 1st numbers differ - expected: '7', found: '14'

Subtask #2:

score: 30
Accepted

Test #3:

score: 30
Accepted
time: 0ms
memory: 1256kb

input:

26 300
ywzhvjnpdfqtukimsrbxageloc
brsmsrbxbxbxbxagagagegelococololegaxagaxaxbxbrbxbrsrsmikimikikimim...

output:

299

result:

ok 1 number(s): "299"

Test #4:

score: 0
Accepted
time: 0ms
memory: 1256kb

input:

26 300
wempkfsunqgytdzibajorvxhlc
gqnununqnusfsununununqnununususunusususfkpmewewewewewempkfkpkpmpmp...

output:

299

result:

ok 1 number(s): "299"

Test #5:

score: 0
Accepted
time: 0ms
memory: 1256kb

input:

26 300
gieywcraxnvblsuojfpthdkmzq
nvbvbvblsusuojfjojouoususlslbvnxnxnxarcraxnvnvnxnxnvnxnxnvblslsusu...

output:

299

result:

ok 1 number(s): "299"

Subtask #3:

score: 0
Wrong Answer

Test #6:

score: 0
Wrong Answer
time: 0ms
memory: 1260kb

input:

300 300
hgbfdbgcghedefchdabhgdddahcdedebceffegfbceehceeheggffhhddbecbfdhceeedcaeeebdaddfgccggfdcachg...

output:

171573

result:

wrong answer 1st numbers differ - expected: '3643', found: '171573'