QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#699482 | #8831. Chemistry Class | BreakPlus | WA | 53ms | 16668kb | C++14 | 1.8kb | 2024-11-02 09:18:54 | 2024-11-02 09:18:55 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> Pr;
#define fi first
#define se second
#define mkp make_pair
#define pb emplace_back
// #define mid ((l+r)>>1)
#define popcnt __builtin_popcountll
const ll mod = 998244353;
inline ll read(){
ll x=0, f=1; char ch=getchar();
while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
while(ch>='0' && ch<='9') x=x*10+ch-'0', ch=getchar();
return x*f;
}
inline ll lg2(ll x){ return 63^__builtin_clzll(x); }
inline ll qpow(ll a,ll b){
ll ans=1, base=a;
while(b){
if(b&1) ans=ans*base%mod;
base=base*base%mod; b>>=1;
}
return ans;
}
void init(){ }
ll n,A,B,a[400005],dp[400005],qz[400005];
struct Queue{
ll que[400005], hd, tp;
void init(){ hd = 1, tp = 0; }
void insert(ll x){
while(hd<=tp && dp[que[tp]]-qz[que[tp]]<=dp[x]-qz[x]) tp--;
que[++tp]=x;
}
void pop(ll x){
while(hd<=tp && que[hd]<x) hd++;
}
ll get(){
if(hd>tp) return -1;
else return que[hd];
}
}q[2];
ll pt;
void procedure(){
pt=0;
n=read(), A=read(), B=read(); q[0].init(); q[1].init();
for(ll i=1;i<=2*n;i++) a[i]=read();
sort(a+1, a+2*n+1);
for(ll i=0;i<=2*n+1;i++) qz[i]=0;
for(ll i=3;i<=2*n+1;i++){
qz[i]=qz[i-2];
if(a[i-1]-a[i-2]<=B) qz[i]++;
}
memset(dp, 0xc0, sizeof(dp));
dp[0] = 0; q[0].insert(0);
for(ll i=1;i<=2*n;i++){
while(a[i]-a[pt+1]>A) pt++; q[i&1].pop(pt);
ll p=q[i&1].get();
if(~p) dp[i] = dp[p] + qz[i] - qz[p];
if(i>1 && a[i]-a[i-1]<=B) dp[i] = max(dp[i], dp[i-2] + 1);
q[i&1].insert(i);
}
if(dp[2*n]<0) puts("-1");
else printf("%lld\n", dp[2*n]);
}
int main(){
#ifdef LOCAL
assert(freopen("input.txt","r",stdin));
assert(freopen("output.txt","w",stdout));
#endif
ll T=read();
init();
while(T--) procedure();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 14112kb
input:
4 1 2 1 42 69 2 3 1 1 2 3 4 2 5 1 6 1 3 4 5 19 1 1 7 8 9 10 11 12 13 14 20
output:
-1 2 1 4
result:
ok 4 number(s): "-1 2 1 4"
Test #2:
score: 0
Accepted
time: 46ms
memory: 16164kb
input:
1 199996 67013419502794 1 403716252634677166 895717933735068492 410002430455111886 844431179242134559 322988383133810700 133475121268220299 481706326769800263 606871141911985391 195911124687409946 959578180866483093 930547702157856949 877914383714875160 994158366044742636 890855755285236186 69498488...
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 45ms
memory: 15748kb
input:
1 199998 38987266278826 1 974183459404323858 517476981059568123 730207399881008603 532509909948600146 89227878552241675 16653300445469756 791674368913652595 92177901403222015 980536748304824579 581564387828767376 471919726893404451 759601909683722004 632340812998214017 818440789777778368 18845836031...
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 40ms
memory: 16668kb
input:
1 199996 54170919220045 1 968843690955781467 596307347951820347 406785475849275444 383666938223357986 725160735782817082 132577412512120631 891899794864087098 779434145671998619 932681297277907326 208765550447928461 385078857912267975 669360937040314510 917331948890514855 505938744714587815 47145437...
output:
0
result:
ok 1 number(s): "0"
Test #5:
score: -100
Wrong Answer
time: 53ms
memory: 15844kb
input:
1 199998 35667463938291 8255384928693 770468016026697053 519790816750772730 110085058423772871 85144239858008037 782003096084947976 938498644167289660 693768718229582367 242186248813489674 155335549252315364 428982852761422230 890445026369869037 86401573937739054 9122788624365829 63351367715811463 1...
output:
199728
result:
wrong answer 1st numbers differ - expected: '193326', found: '199728'