結果

問題 No.1544 [Cherry 2nd Tune C] Synchroscope
ユーザー root__786root__786
提出日時 2021-06-11 23:01:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,170 ms / 2,000 ms
コード長 1,255 bytes
コンパイル時間 2,668 ms
コンパイル使用メモリ 203,708 KB
実行使用メモリ 461,152 KB
最終ジャッジ日時 2024-05-08 19:14:46
合計ジャッジ時間 42,786 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 990 ms
432,916 KB
testcase_04 AC 693 ms
261,704 KB
testcase_05 AC 935 ms
422,392 KB
testcase_06 AC 913 ms
417,680 KB
testcase_07 AC 534 ms
226,300 KB
testcase_08 AC 959 ms
426,752 KB
testcase_09 AC 1,047 ms
448,120 KB
testcase_10 AC 969 ms
430,616 KB
testcase_11 AC 594 ms
239,324 KB
testcase_12 AC 431 ms
204,900 KB
testcase_13 AC 644 ms
250,868 KB
testcase_14 AC 1,087 ms
457,448 KB
testcase_15 AC 1,031 ms
443,428 KB
testcase_16 AC 519 ms
223,916 KB
testcase_17 AC 243 ms
109,080 KB
testcase_18 AC 179 ms
83,300 KB
testcase_19 AC 141 ms
75,492 KB
testcase_20 AC 861 ms
406,268 KB
testcase_21 AC 534 ms
225,792 KB
testcase_22 AC 310 ms
123,536 KB
testcase_23 AC 1,110 ms
461,148 KB
testcase_24 AC 1,111 ms
461,140 KB
testcase_25 AC 1,111 ms
461,012 KB
testcase_26 AC 1,111 ms
461,144 KB
testcase_27 AC 1,112 ms
461,148 KB
testcase_28 AC 1,110 ms
461,148 KB
testcase_29 AC 1,112 ms
461,144 KB
testcase_30 AC 1,112 ms
461,144 KB
testcase_31 AC 1,105 ms
461,144 KB
testcase_32 AC 1,111 ms
461,144 KB
testcase_33 AC 1,142 ms
461,152 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 1,113 ms
461,096 KB
testcase_37 AC 3 ms
5,376 KB
testcase_38 AC 1,168 ms
461,060 KB
testcase_39 AC 1,169 ms
460,904 KB
testcase_40 AC 1,170 ms
461,060 KB
testcase_41 AC 1,168 ms
460,908 KB
testcase_42 AC 1,157 ms
460,536 KB
testcase_43 AC 1,103 ms
453,488 KB
testcase_44 AC 1,109 ms
452,816 KB
testcase_45 AC 1,136 ms
457,984 KB
testcase_46 AC 1,118 ms
456,052 KB
testcase_47 AC 1,126 ms
456,396 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