Submission #5894202


Source Code Expand

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

int gccal(int a,int b){
  if(b==0){
    return a;
  }
  gccal(b,a%b);
}

int main(){
  int n,m;
  cin >> n>>m;
  string s;
  string t;
  cin >> s>>t;
  int gcd=gccal(max(n,m),min(n,m));
  long lcm=n/gcd*m;
  for(int i=1;i<2;i++){
    long l=i*lcm;
    bool ans=true;
    string u(i*lcm,'0');
    for(int j=0;j<n;j++){
      u.at(-1+j*l/n+1)=s.at(j);
    }
    for(int j=0;j<m;j++){
      if(u.at(-1+j*l/m+1)!=t.at(j)&&u.at(-1+j*l/m+1)!='0'){
        ans=false;
        break;
      }
    }
    if(ans){
      cout << l;
      return 0;
    }
  }
  cout << -1;
           
      
}

Submission Info

Submission Time
Task A - Two Abbreviations
User mototakashi
Language C++14 (GCC 5.4.1)
Score 0
Code Size 666 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 4 ms 1792 KB
subtask01-03.txt
subtask01-04.txt 15 ms 23552 KB
subtask01-05.txt 8 ms 768 KB
subtask01-06.txt
subtask01-07.txt 3 ms 896 KB
subtask01-08.txt 6 ms 768 KB
subtask01-09.txt
subtask01-10.txt
subtask01-11.txt 16 ms 19072 KB
subtask01-12.txt 8 ms 1920 KB
subtask01-13.txt
subtask01-14.txt 10 ms 4864 KB
subtask01-15.txt 7 ms 896 KB