QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#747819 | #4583. Concerto de Pandemic | shinonome_ena# | WA | 1274ms | 53988kb | C++23 | 1.9kb | 2024-11-14 18:22:24 | 2024-11-14 18:22:25 |
Judging History
answer
//#define LOCAL
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 1557557
#define MAXS 20
#define ln '\n'
#ifdef LOCAL
#define DEBUG(a) cout<<a
#else
#define DEBUG(a) 1557
#endif
int C[MAX];
int T[MAX];
ll TS[MAX];
int D[MAX];
int N, M, K, P;
int L[MAX];
int R[MAX];
int smx[MAX];
ll sp[MAX][MAXS];
int dis(int l, int r) {
if(l<=r) return r-l;
else return r+N-l;
}
bool chk(ll m) {
DEBUG(m<<ln);
int i, j;
for(i=1;i<=K;i++) {
int loc = D[i]+N;
int ind1, ind2;
ind1 = lower_bound(TS+1, TS+N*3+1, TS[loc-1]-m)-TS+1;
ind2 = upper_bound(TS+1, TS+N*3+1, TS[loc]+m)-TS-1;
L[i] = (ind1-1)%N+1;
R[i] = (ind2-1)%N+1;
if(dis(L[i], D[i])+dis(D[i], R[i])>=N-1){
L[i] = 1;
R[i] = N;
}
}
for(i=1;i<=N*2+1;i++) smx[i] = N*3;
for(i=1;i<=K;i++) {
int l, r;
l = L[i];
r = R[i];
if(l>r) r+=N;
smx[L[i]-1] = min(smx[L[i]-1], r);
smx[L[i]-1+N] = min(smx[L[i]-1+N], r+N);
DEBUG(L[i]<<' '<<R[i]<<ln);
}
for(i=N*2;i>=0;i--) smx[i] = min(smx[i], smx[i+1]);
for(i=1;i<=N;i++) sp[i][0] = smx[i]-i;
for(i=1;i<=N;i++) DEBUG(sp[i][0]<<' ');
DEBUG(ln);
for(j=1;j<MAXS;j++) {
for(i=1;i<=N;i++) {
int n = (i+sp[i][j-1]-1)%N;
n++;
sp[i][j] = sp[i][j-1]+sp[n][j-1];
}
}
for(i=1;i<=N;i++) {
int v=i;
ll sum=0;
for(j=0;j<MAXS;j++) {
if(P>>j&1){
sum+=sp[v][j];
int n = (v+sp[v][j]-1)%N;
n++;
v = n;
}
}
if(sum>=N) return true;
}
return false;
}
signed main(){
ios::sync_with_stdio(false), cin.tie(0);
cin>>N>>M>>K>>P;
int i;
ll l, r;
l = -1;
r = N;
for(i=1;i<=M;i++) cin>>C[i]>>T[i], r+=T[i];
for(i=1;i<=K;i++) cin>>D[i];
for(i=1;i<=M;i++) TS[C[i]]=TS[C[i]+N]=TS[C[i]+N*2] = T[i];
for(i=1;i<=N*3;i++) TS[i] += TS[i-1];
for(i=1;i<=N*3;i++) TS[i]+=i;
while(r-l>1) {
ll m = l+r>>1;
if(chk(m)) r = m;
else l = m;
}
cout<<r;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 18036kb
input:
10 4 3 2 1 2 4 4 6 2 7 5 2 5 8
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 0ms
memory: 17912kb
input:
8 1 3 5 1 5 4 2 7
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 3ms
memory: 17916kb
input:
5 2 2 1 1 14 2 14 3 5
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 0ms
memory: 17992kb
input:
2 1 1 1 1 200000 2
output:
0
result:
ok single line: '0'
Test #5:
score: -100
Wrong Answer
time: 1274ms
memory: 53988kb
input:
190976 113222 55610 23475 51263 120558 10007 171596 46671 108981 117183 169457 18187 84735 149298 124718 79376 129184 28117 76880 109791 87521 114840 59510 38014 178362 41701 11344 27561 192741 173835 54534 71368 76692 122745 95537 152595 158352 43901 162441 98927 105784 22484 96000 19443 113614 370...
output:
167341
result:
wrong answer 1st lines differ - expected: '170531', found: '167341'