Submission #5892326


Source Code Expand

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long int ll;
typedef pair<int,int> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// a^b mod M
long myPow(long a,long b,int M) {
    long ret = 1;
    long tmp = a;
    while(b>0) {
        if((b&1)==1) ret = (ret * tmp) % M;
        tmp = (tmp * tmp) % M;
        b = b>>1;
    }
    return ret;
}

 // nCk mod M
int nCk(int n,int k,int M) {
    long ret = 1;
    int mi = min(k, n-k);
    for(int i=1;i<=mi;i++) {
        ret = (ret * myPow(i,M-2,M)) % M;
    }
    for(int i=n-mi+1;i<=n;i++) {
        ret = (ret * i) % M;
    }
    return (int)ret;
};

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

int main() {
    ll N,M;
    cin >> N >> M;

    string s,t;
    cin >> s >> t;

    ll L = lcm(N,M);
    ll l = lcm(L/N,L/M);

    for(int i = 0;i < L;i += l){
        if(s[i / (L/N)] != t[i / (L/M)]) {
            pl(-1)
            return 0;
        }
    }

    pl(L)

    return 0;
}

Submission Info

Submission Time
Task A - Two Abbreviations
User azz
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2477 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 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 6 ms 512 KB
subtask01-06.txt 6 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 6 ms 512 KB
subtask01-14.txt 5 ms 384 KB
subtask01-15.txt 5 ms 512 KB