結果

問題 No.1544 [Cherry 2nd Tune C] Synchroscope
ユーザー root__786root__786
提出日時 2021-06-11 23:01:20
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,144 ms / 2,000 ms
コード長 1,255 bytes
コンパイル時間 2,958 ms
コンパイル使用メモリ 202,072 KB
実行使用メモリ 463,656 KB
最終ジャッジ日時 2023-08-21 13:51:40
合計ジャッジ時間 42,229 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1,049 ms
433,700 KB
testcase_04 AC 681 ms
263,432 KB
testcase_05 AC 993 ms
423,868 KB
testcase_06 AC 975 ms
418,800 KB
testcase_07 AC 517 ms
226,628 KB
testcase_08 AC 1,036 ms
428,376 KB
testcase_09 AC 1,041 ms
448,668 KB
testcase_10 AC 956 ms
432,640 KB
testcase_11 AC 576 ms
241,900 KB
testcase_12 AC 416 ms
205,788 KB
testcase_13 AC 628 ms
252,956 KB
testcase_14 AC 1,112 ms
458,636 KB
testcase_15 AC 1,013 ms
445,344 KB
testcase_16 AC 504 ms
225,048 KB
testcase_17 AC 228 ms
110,372 KB
testcase_18 AC 167 ms
85,648 KB
testcase_19 AC 132 ms
76,832 KB
testcase_20 AC 836 ms
407,832 KB
testcase_21 AC 508 ms
228,520 KB
testcase_22 AC 295 ms
124,416 KB
testcase_23 AC 1,087 ms
462,452 KB
testcase_24 AC 1,091 ms
462,848 KB
testcase_25 AC 1,090 ms
462,328 KB
testcase_26 AC 1,093 ms
462,408 KB
testcase_27 AC 1,082 ms
462,236 KB
testcase_28 AC 1,084 ms
463,100 KB
testcase_29 AC 1,090 ms
462,140 KB
testcase_30 AC 1,093 ms
462,264 KB
testcase_31 AC 1,090 ms
461,776 KB
testcase_32 AC 1,092 ms
463,656 KB
testcase_33 AC 1,120 ms
462,520 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 1,088 ms
463,352 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 1,129 ms
463,480 KB
testcase_39 AC 1,144 ms
462,496 KB
testcase_40 AC 1,135 ms
463,412 KB
testcase_41 AC 1,132 ms
461,344 KB
testcase_42 AC 1,118 ms
458,844 KB
testcase_43 AC 1,081 ms
453,380 KB
testcase_44 AC 1,083 ms
453,880 KB
testcase_45 AC 1,104 ms
458,832 KB
testcase_46 AC 1,100 ms
457,524 KB
testcase_47 AC 1,105 ms
458,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
    int n,m;
    cin>>n>>m;
    int c=0;
    vector<int> a,b;
    int k;
    for(int i=0;i<n;i++){
        cin>>k;
        a.push_back(k);
    }
    for(int i=0;i<m;i++){
        cin>>k;
        b.push_back(k);
    }
    int same=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++)
        {
            if(a[i]==b[j]){
                same=1;
                break;
            }
        }
        if(same==1)
        break;
    }
    if(same==0){
        cout<<-1<<endl;
        return 0;
    }
    else{
        int size=max({n*n,m*m,m*n});
        int i=0,c=0;
        vector<int> AA;
        while(i<n){
            if(c==size) break;
            AA.push_back(a[i]);
            i=(i+1)%n;
            c++;
        }
        vector<int> BB;
        int j=0;
        c=0;
        while(j<m){
            if(c==size) break;
            BB.push_back(b[j]);
            j=(j+1)%m;
            c++;
        }
        int s=0;
        for(int i=0;i<AA.size();i++){
            if(AA[i]==BB[i]){
                s=1;
                cout<<(i+1);
                break;
            }
        }
        if(s==0) cout<<-1<<endl;
    }
    return 0;
}
0