Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
43361 姜博睿 【J】T2 C++ 通过 100 1 MS 1224 KB 804 2026-10-29 12:59:31

Tests(10/10):


#include <bits/stdc++.h> using namespace std; const int N=1e6+9; int T,n,A,a[30],ans; bool v,s[N]; struct node{ int x,i,y; }; queue<node>b; int main(){ cin>>T; while(T--){ cin>>n>>A; while(!b.empty())b.pop(); for(int i=0;i<=A;i++)s[i]=0; v=0; for(int i=1;i<=n;i++)cin>>a[i]; sort(a+1,a+n+1); for(int i=1;i<=n;i++)b.push({A%a[i],i,1}),s[A%a[i]]=1; while(!b.empty()){ node x=b.front(); b.pop(); if(x.x==0){ v=1; cout<<x.y<<endl; break; } else for(int i=1;i<x.i;i++)if(s[x.x%a[i]]==0)b.push({x.x%a[i],i,x.y+1}),s[x.x%a[i]]=1; } if(v==0)cout<<-1<<endl; } return 0; }


测评信息: