Submission #3399331


Source Code Expand

Copy
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>

using namespace std;
#define MAX 100000

long long int lcm(int number1, int number2);
int ggd(int number1, int number2);

int main(){
    int N, M;
    string S, T;

    cin >> N >> M >> S >> T;

    long long int L = lcm(S.size(), T.size());

    int LperN = L / N;
    int LperM = L / M;

    long long int temp = lcm(LperN, LperM);
    int cnt = 0;
    while (L >= cnt * temp){
        int Si = cnt * temp / LperN;
        int Ti = cnt * temp / LperM;
        if ((Si >= S.size()) || (Ti >= T.size())){
            break;
        }
        if (S[Si] != T[Ti]){
            cout << -1 << "\n";
            return 0;
        }
        cnt++;
    }
    cout << L << "\n";
    return 0;
}

int ggd(int number1, int number2){
    int m = number1;
    int n = number2;

    if (number2 > number1){
        m = number2;
        n = number1;
    }

    while (m % n != 0)
    {
        int temp = n;
        n = m % n;
        m = temp;
    }
    return n;
}

long long int lcm(int number1, int number2){
    return number1 * number2 / ggd(number1, number2);
}

Submission Info

Submission Time
Task A - Two Abbreviations
User Kuroka
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1374 Byte
Status

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample-01.txt, sample-02.txt, sample-03.txt
All 0 / 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 3 ms 384 KB
subtask01-03.txt 5 ms 512 KB
subtask01-04.txt 5 ms 512 KB
subtask01-05.txt
subtask01-06.txt 6 ms 512 KB
subtask01-07.txt 3 ms 384 KB
subtask01-08.txt 4 ms 384 KB
subtask01-09.txt 5 ms 384 KB
subtask01-10.txt 6 ms 512 KB
subtask01-11.txt 6 ms 512 KB
subtask01-12.txt
subtask01-13.txt 6 ms 512 KB
subtask01-14.txt 6 ms 384 KB
subtask01-15.txt