Submission #3392873

Source Code Expand

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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair


ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }

ll solve(ll N,ll M,string& s,string& t){
    ll g = gcd(N, M);
    ll L = N / g * M;
    ll u = L / N, v = L / M;

    map<ll, char> e;
    rep(i,N){
        e[u*i] = s[i];
    }
    rep(i,M){
        ll at = v*i;
        if (found(e,at) && e[at] != t[i]) return -1;
    }

    return L;
}

int main() {
    int n,m; cin >> n >> m;
    string s,t; cin >> s >> t;
    cout << solve(n,m,s,t) << endl;
    return 0;
}

Submission Info

Submission Time
Task A - Two Abbreviations
User naoya_t
Language C++14 (GCC 5.4.1)
Score 300
Code Size 1717 Byte
Status
Exec Time 42 ms
Memory 6144 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 512 KB
subtask01-03.txt 24 ms 3072 KB
subtask01-04.txt 19 ms 2304 KB
subtask01-05.txt 36 ms 6144 KB
subtask01-06.txt 17 ms 3200 KB
subtask01-07.txt 7 ms 1664 KB
subtask01-08.txt 14 ms 2432 KB
subtask01-09.txt 21 ms 4096 KB
subtask01-10.txt 39 ms 5120 KB
subtask01-11.txt 42 ms 5632 KB
subtask01-12.txt 36 ms 5248 KB
subtask01-13.txt 29 ms 4992 KB
subtask01-14.txt 32 ms 4992 KB
subtask01-15.txt 24 ms 4096 KB