結果
問題 | No.1544 [Cherry 2nd Tune C] Synchroscope |
ユーザー |
![]() |
提出日時 | 2021-06-12 16:18:36 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 153 ms / 2,000 ms |
コード長 | 1,062 bytes |
コンパイル時間 | 755 ms |
コンパイル使用メモリ | 93,512 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-17 13:19:31 |
合計ジャッジ時間 | 3,666 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 48 |
ソースコード
/* -*- coding: utf-8 -*-** 1544.cc: No.1544 [Cherry 2nd Tune C] Synchroscope - yukicoder*/#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<iostream>#include<string>#include<vector>#include<map>#include<set>#include<stack>#include<list>#include<queue>#include<deque>#include<algorithm>#include<numeric>#include<utility>#include<complex>#include<functional>using namespace std;/* constant */const int MAX_N = 5000;const int MAX_M = 5000;/* typedef *//* global variables */int as[MAX_N], bs[MAX_M];/* subroutines */template <typename T>T gcd(T m, T n) { // m > 0, n > 0if (m < n) swap(m, n);while (n > 0) {T r = m % n;m = n;n = r;}return m;}/* main */int main() {int n, m;scanf("%d%d", &n, &m);for (int i = 0; i < n; i++) scanf("%d", as + i);for (int i = 0; i < m; i++) scanf("%d", bs + i);int l = n * m / gcd(n, m);for (int i = 0; i < l; i++)if (as[i % n] == bs[i % m]) { printf("%d\n", i + 1); return 0; }puts("-1");return 0;}