結果

問題 No.1544 [Cherry 2nd Tune C] Synchroscope
ユーザー AnumishAnumish
提出日時 2021-06-11 21:46:04
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 292 ms / 2,000 ms
コード長 2,162 bytes
コンパイル時間 858 ms
コンパイル使用メモリ 98,664 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-21 12:02:59
合計ジャッジ時間 12,009 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 246 ms
4,380 KB
testcase_04 AC 226 ms
4,380 KB
testcase_05 AC 117 ms
4,380 KB
testcase_06 AC 156 ms
4,380 KB
testcase_07 AC 189 ms
4,376 KB
testcase_08 AC 245 ms
4,376 KB
testcase_09 AC 12 ms
4,376 KB
testcase_10 AC 142 ms
4,376 KB
testcase_11 AC 200 ms
4,380 KB
testcase_12 AC 108 ms
4,380 KB
testcase_13 AC 203 ms
4,376 KB
testcase_14 AC 277 ms
4,380 KB
testcase_15 AC 224 ms
4,376 KB
testcase_16 AC 92 ms
4,380 KB
testcase_17 AC 79 ms
4,376 KB
testcase_18 AC 105 ms
4,376 KB
testcase_19 AC 92 ms
4,380 KB
testcase_20 AC 204 ms
4,376 KB
testcase_21 AC 47 ms
4,380 KB
testcase_22 AC 140 ms
4,380 KB
testcase_23 AC 291 ms
4,376 KB
testcase_24 AC 292 ms
4,380 KB
testcase_25 AC 291 ms
4,380 KB
testcase_26 AC 291 ms
4,376 KB
testcase_27 AC 292 ms
4,376 KB
testcase_28 AC 291 ms
4,376 KB
testcase_29 AC 291 ms
4,380 KB
testcase_30 AC 292 ms
4,380 KB
testcase_31 AC 291 ms
4,376 KB
testcase_32 AC 291 ms
4,376 KB
testcase_33 AC 292 ms
4,376 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 260 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 290 ms
4,376 KB
testcase_39 AC 290 ms
4,376 KB
testcase_40 AC 289 ms
4,376 KB
testcase_41 AC 291 ms
4,380 KB
testcase_42 AC 288 ms
4,380 KB
testcase_43 AC 282 ms
4,380 KB
testcase_44 AC 285 ms
4,380 KB
testcase_45 AC 288 ms
4,380 KB
testcase_46 AC 287 ms
4,376 KB
testcase_47 AC 284 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include <algorithm>
#include <array>
#include <cassert>
//#include <chrono>
#include <cmath>
//#include <cstring>
//#include <functional>
//#include <iomanip>
#include <iostream>
#include <map>
//#include <numeric>
//#include <queue>
//#include <random>
#include <set>
#include <vector>
using namespace std;
#define FAST  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp> 
//using namespace __gnu_pbds; 
#define int long long 
#define ll int
#define all(a) a.begin(),a.end()    
#define rev(a) a.rbegin(),a.rend()    
//typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; //less_equal for multiset
#define ar array
#define pb push_back
#define fi(a,b) for(int i=a;i<(b);i++)
#define fj(a,b) for(int j=a;j<(b);j++)
#define fk(a,b) for(int k=a;k<(b);k++)
const double pi=acosl(-1);



void solve()
{
    int n,m;
    cin>>n>>m;
    vector<int> a(n);
    fi(0,n)
    {
        cin>>a[i];
    }
    vector<int> b(m);
    fi(0,m)
    {
        cin>>b[i];
    }
    int ans=1e18;
    fi(0,n)
    {
        vector<int> vis(m);
        fj(0,m)
        {
            if(a[i]==b[j]) vis[j]=1;
        }
        for(int moves=0;moves<=5001;moves++)
        {
            if(vis[(moves*n+i)%m])
            {
                ans=min(ans,moves*n+i+1);
            }
        }
    }
    if(ans==1e18) ans=-1;
    cout<<ans<<'\n';

    
    
}

signed main()
{
    FAST;
    int tt=1;
    //cin>>tt;    
    while(tt--)
    {
        solve();
    }    
}










//int dx[] = {+1,-1,+0,+0,-1,-1,+1,+1}; // Eight Directions
//int dy[] = {+0,+0,+1,-1,+1,-1,-1,+1}; // Eight Directions
//int dx[]= {-2,-2,-1,1,-1,1,2,2}; // Knight moves
//int dy[]= {1,-1,-2,-2,2,2,-1,1}; // Knight moves
// For (a^b)%mod, where b is large, replace b by b%(mod-1)..{because we solve this by introducing log ..do same for general cases}
// a+b = (a|b)+(a&b)
// a+b = 2*(a&b)+(a^b)
0