QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#809255 | #9870. Items | ucup-team1004 | TL | 4ms | 8148kb | C++20 | 2.0kb | 2024-12-11 13:33:13 | 2024-12-11 13:33:14 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=1e6+5,M=N*20+5,K=1000+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const ll INF=1e18+7;mt19937 rnd(28382);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
#ifdef LOCAL
#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
#else
#define gdb(...) void()
#endif
}using namespace Debug;
int n,A[N],k,B[N],vis[N];
ll m,d[N];
void Solve(){
scanf("%d%lld",&n,&m);
for(int i=1;i<=n;i++) scanf("%d",&A[i]);
sort(A+1,A+n+1);
k=unique(A+1,A+n+1)-A-1;
if(m<1ll*n*A[1]){
puts("NO");return;
}
m-=1ll*n*A[1];for(int i=2;i<=k;i++) A[i]-=A[1];
if(k==1){
puts(!m?"YES":"NO");
return;
}
fill(d,d+A[k],-INF);
fill(vis,vis+A[k],0);
d[0]=1ll*n*A[k];
for(int i=1;i<=A[k];i++){
int v=-1;
for(int j=0;j<A[k];j++) if(!vis[j]&&(v==-1||d[v]<d[j])) v=j;
vis[v]=1;
gdb(v,d[v]);
for(int j=2;j<k;j++){
int u=(v+A[j])%A[k];
d[u]=max(d[u],d[v]+A[j]-A[k]);
}
}
if(d[m%A[k]]<m){puts("NO");return;}
fill(d,d+A[k],INF);
fill(vis,vis+A[k],0);
d[0]=0;
for(int i=1;i<=A[k];i++){
int v=-1;
for(int j=0;j<A[k];j++) if(!vis[j]&&(v==-1||d[v]>d[j])) v=j;
vis[v]=1;
for(int j=2;j<k;j++){
int u=(v+A[j])%A[k];
d[u]=min(d[u],d[v]+A[j]);
}
}
if(d[m%A[k]]>m){puts("NO");return;}
puts("YES");
}
int main(){
int t=1;
scanf("%d",&t);
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7932kb
input:
4 5 25 0 0 0 0 5 5 11 4 4 4 5 5 5 0 1 2 3 4 5 5 25 0 1 2 3 4
output:
YES NO NO NO
result:
ok 4 token(s): yes count is 1, no count is 3
Test #2:
score: 0
Accepted
time: 0ms
memory: 8056kb
input:
1314 1 0 0 1 0 1 1 1 0 1 1 1 2 0 0 0 2 0 0 1 2 0 0 2 2 0 1 0 2 0 1 1 2 0 1 2 2 0 2 0 2 0 2 1 2 0 2 2 2 1 0 0 2 1 0 1 2 1 0 2 2 1 1 0 2 1 1 1 2 1 1 2 2 1 2 0 2 1 2 1 2 1 2 2 2 2 0 0 2 2 0 1 2 2 0 2 2 2 1 0 2 2 1 1 2 2 1 2 2 2 2 0 2 2 2 1 2 2 2 2 2 3 0 0 2 3 0 1 2 3 0 2 2 3 1 0 2 3 1 1 2 3 1 2 2 3 2 0...
output:
YES NO NO YES YES YES YES YES NO NO YES NO NO NO YES NO YES NO NO NO NO NO NO YES YES YES YES YES YES YES NO NO NO NO NO NO YES NO YES NO NO NO YES NO NO YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES NO NO NO YES NO NO NO YES NO NO NO YES YES YES...
result:
ok 1314 token(s): yes count is 732, no count is 582
Test #3:
score: 0
Accepted
time: 4ms
memory: 8148kb
input:
10000 4 1 0 0 0 0 4 1 0 0 0 1 4 1 0 0 0 2 4 1 0 0 0 3 4 1 0 0 0 4 4 1 0 0 1 0 4 1 0 0 1 1 4 1 0 0 1 2 4 1 0 0 1 3 4 1 0 0 1 4 4 1 0 0 2 0 4 1 0 0 2 1 4 1 0 0 2 2 4 1 0 0 2 3 4 1 0 0 2 4 4 1 0 0 3 0 4 1 0 0 3 1 4 1 0 0 3 2 4 1 0 0 3 3 4 1 0 0 3 4 4 1 0 0 4 0 4 1 0 0 4 1 4 1 0 0 4 2 4 1 0 0 4 3 4 1 0 ...
output:
NO YES NO NO NO YES YES YES YES YES NO YES NO NO NO NO YES NO NO NO NO YES NO NO NO YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES NO YES NO NO NO YES YES YES YES YES NO YES NO NO NO NO YES NO NO NO NO YES NO NO NO NO YES NO NO NO YES YES YES YES ...
result:
ok 10000 token(s): yes count is 6168, no count is 3832
Test #4:
score: 0
Accepted
time: 0ms
memory: 8108kb
input:
1612 5 0 0 0 0 0 0 5 0 1 1 1 1 1 5 0 0 1 1 1 1 5 0 2 2 2 2 2 5 0 0 2 2 2 2 5 0 1 2 2 2 2 5 0 0 1 2 2 2 5 0 3 3 3 3 3 5 0 0 3 3 3 3 5 0 1 3 3 3 3 5 0 0 1 3 3 3 5 0 2 3 3 3 3 5 0 0 2 3 3 3 5 0 1 2 3 3 3 5 0 0 1 2 3 3 5 0 4 4 4 4 4 5 0 0 4 4 4 4 5 0 1 4 4 4 4 5 0 0 1 4 4 4 5 0 2 4 4 4 4 5 0 0 2 4 4 4 5...
output:
YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO NO NO YES NO NO NO YES NO NO NO YES NO NO NO YES NO NO NO YES NO NO NO YES NO NO NO...
result:
ok 1612 token(s): yes count is 864, no count is 748
Test #5:
score: 0
Accepted
time: 3ms
memory: 8068kb
input:
4662 6 0 0 0 0 0 0 0 6 0 1 1 1 1 1 1 6 0 0 1 1 1 1 1 6 0 2 2 2 2 2 2 6 0 0 2 2 2 2 2 6 0 1 2 2 2 2 2 6 0 0 1 2 2 2 2 6 0 3 3 3 3 3 3 6 0 0 3 3 3 3 3 6 0 1 3 3 3 3 3 6 0 0 1 3 3 3 3 6 0 2 3 3 3 3 3 6 0 0 2 3 3 3 3 6 0 1 2 3 3 3 3 6 0 0 1 2 3 3 3 6 0 4 4 4 4 4 4 6 0 0 4 4 4 4 4 6 0 1 4 4 4 4 4 6 0 0 1...
output:
YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO...
result:
ok 4662 token(s): yes count is 2730, no count is 1932
Test #6:
score: -100
Time Limit Exceeded
input:
1 100000 9999999999 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 9...