Submission #3401769

Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;

int64_t gcd(int64_t a, int64_t b){
    return b==0 ? a : gcd(b, a%b);
}
int64_t lcm(int64_t a, int64_t b){
    return a*b / gcd(a, b);
}

int main(){
    int64_t i, j, k;
    int64_t N, M;
    string S, T;
    cin >> N >> M >> S >> T;
    int64_t L = lcm(N, M);
    int64_t l = lcm(L/N, L/M);
    for(i=0; i<L; i+=l){
        if(S[i / (L/N)] != T[i / (L/M)]){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << L << endl;
    return 0;
}

Submission Info

Submission Time
Task A - Two Abbreviations
User betrue12
Language C++14 (GCC 5.4.1)
Score 300
Code Size 540 Byte
Status
Exec Time 6 ms
Memory 512 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 3 ms 384 KB
subtask01-03.txt 5 ms 512 KB
subtask01-04.txt 5 ms 512 KB
subtask01-05.txt 6 ms 512 KB
subtask01-06.txt 5 ms 512 KB
subtask01-07.txt 2 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 5 ms 512 KB
subtask01-13.txt 5 ms 512 KB
subtask01-14.txt 5 ms 384 KB
subtask01-15.txt 5 ms 512 KB