Submission #5895564


Source Code Expand

Copy
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 100100;
string s, t;
int n, m;
int gcd(int a, int b)
{
	if(b == 0)
		return a;
	return gcd(b, a % b);
}
int main()
{
	std::ios::sync_with_stdio(false);
	cin >> n >> m;
	cin >> s >> t;
	int x = gcd(n, m);
	for(int i = 0; i < x; i ++)
		if(s[i * n / x] != t[i * m / x])
		{
			cout << "-1" << endl;
			return 0;
		}
	cout << 1ll * n * m / x << endl;
	return 0;
}

Submission Info

Submission Time
Task A - Two Abbreviations
User zhangyuxi
Language C++14 (GCC 5.4.1)
Score 300
Code Size 542 Byte
Status
Exec Time 2 ms
Memory 640 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample-01.txt, sample-02.txt, sample-03.txt
All 300 / 300 sample-01.txt, sample-02.txt, sample-03.txt, sample-01.txt, sample-02.txt, sample-03.txt, subtask01-01.txt, subtask01-02.txt, subtask01-03.txt, subtask01-04.txt, subtask01-05.txt, subtask01-06.txt, subtask01-07.txt, subtask01-08.txt, subtask01-09.txt, subtask01-10.txt, subtask01-11.txt, subtask01-12.txt, subtask01-13.txt, subtask01-14.txt, subtask01-15.txt
Case Name Status Exec Time Memory
sample-01.txt 1 ms 256 KB
sample-02.txt 1 ms 256 KB
sample-03.txt 1 ms 256 KB
subtask01-01.txt 1 ms 256 KB
subtask01-02.txt 1 ms 384 KB
subtask01-03.txt 1 ms 512 KB
subtask01-04.txt 1 ms 512 KB
subtask01-05.txt 2 ms 640 KB
subtask01-06.txt 1 ms 512 KB
subtask01-07.txt 1 ms 384 KB
subtask01-08.txt 1 ms 384 KB
subtask01-09.txt 1 ms 512 KB
subtask01-10.txt 2 ms 640 KB
subtask01-11.txt 2 ms 512 KB
subtask01-12.txt 1 ms 512 KB
subtask01-13.txt 1 ms 512 KB
subtask01-14.txt 1 ms 512 KB
subtask01-15.txt 1 ms 512 KB