Submission #3393349


Source Code Expand

Copy
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;


// 最大公約数(Greatest Common Divisor)
uint64_t gcd(uint64_t m, uint64_t n)
{
	// ユークリッドの互除法
	for (;;)
	{
		if (0 == m) { return n; }
		n %= m;
		if (0 == n) { return m; }
		m %= n;
	}
}
// 最小公倍数(Least Common Multiple)を返す。
uint64_t lcm(uint64_t m, uint64_t n)
{
	if (0 == m) { return n; }
	if (0 == n) { return m; }
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

uint64_t N,M;
std::string s, t;

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N>>M;
	in >> s >> t;

	auto len = lcm(N, M);

	auto diff_n = (len / N);
	auto diff_m = (len / M);
	auto add = lcm(diff_n, diff_m);

	for (uint64_t i = 0; i < len; i+= add)
	{
		if (i % diff_n == 0 && i % diff_m == 0)
		{
			if (s[i / diff_n] != t[i / diff_m]) {
				out << -1 << endl;
				return 0;
			}
		}

	}
	out << len << endl;

	return 0;
}
#endif

Submission Info

Submission Time
Task A - Two Abbreviations
User eiya
Language C++14 (Clang 3.8.0)
Score 300
Code Size 1613 Byte
Status
Exec Time 9 ms
Memory 888 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 5 ms 888 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 4 ms 384 KB
subtask01-03.txt 7 ms 512 KB
subtask01-04.txt 7 ms 512 KB
subtask01-05.txt 9 ms 512 KB
subtask01-06.txt 8 ms 512 KB
subtask01-07.txt 3 ms 384 KB
subtask01-08.txt 6 ms 512 KB
subtask01-09.txt 6 ms 512 KB
subtask01-10.txt 9 ms 512 KB
subtask01-11.txt 8 ms 512 KB
subtask01-12.txt 7 ms 512 KB
subtask01-13.txt 7 ms 512 KB
subtask01-14.txt 7 ms 512 KB
subtask01-15.txt 7 ms 512 KB