QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#716834 | #9599. Dragon Bloodline | Ynoiynoi# | WA | 1ms | 5692kb | C++20 | 2.2kb | 2024-11-06 16:08:35 | 2024-11-06 16:08:36 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MAXN 100005
int n,m,ss;
int a[MAXN];
int b[114],d[MAXN];
int c[60];
bool fl[MAXN];
int r[MAXN][60];
int nn;
int ct[3];
void qk() {
memset(b,0,sizeof(b));
for(int i = 0; i <= n+3; i ++) {
a[i] = 0;
d[i] = 0;
memset(r[i],0,sizeof(r[i]));
}
}
bool pd(int m) {
for(int j = 0; j <= 54; j ++)
c[j] = 0;
for(int i = 1; i <= n; i ++) {
fl[i] = 1;
d[i] = m*a[i];
for(int j = 0; j <= 54; j ++)
if(d[i]&(1ll<<j)) c[j] ++;
}
for(int j = 0; j <= 54; j ++) {
ct[0] = 0; ct[1] = 0;
for(int i = 1; i <= n; i ++) {
if(d[i]&(1ll<<j)) ct[1] ++;
else ct[0] ++;
}
int s0 = ct[0];
for(int i = n; i >= 1; i --) {
int x;
if(j == 0) x = i;
else x = r[i][j-1];
if(d[x]&(1ll<<j)) {
r[s0+ct[1]][j] = x;
ct[1] --;
} else {
r[ct[0]][j] = x;
ct[0] --;
}
}
/*if(j <= 4) {
// cout<<ct[0]<<" "<
cout<<j<<"\n";
for(int i = 1; i <= n; i ++)
cout<<r[i][j]<<" ";
cout<<"\n";
}*/
}
for(int j = 54; j >= 1; j --) {
// cout<<j<<":"<<b[j]<<" "<<c[j]<<"\n";
if(b[j] > c[j]) {
int x = b[j]-c[j];
c[j] = 0;
for(int i = n; i >= 1; i --) {
int y = r[i][j-1];
// cout<<y<<"\n";
if(fl[y] && x) {
fl[y] = 0;
x --;
for(int k = 0; k < j; k ++)
if(d[y]&(1ll<<k)) c[k] --;
// cout<<j<<":"<<y<<"?\n";
}
}
} else {
c[j] -= b[j];
c[j-1] += c[j]*2;
c[j] = 0;
}
}
return b[0] >= c[0];
}
signed main() {
int T;
cin >> T;
while(T --) {
cin >> n >> m;
qk();
int sa = 0;
for(int i = 1; i <= n; i ++) {
cin >> a[i];
sa += a[i];
}
ss = 0;
for(int i = 1; i <= m; i ++) {
cin >> b[i-1];
ss += (1ll<<(i-1))*b[i-1];
}
//cout<<pd(5);
//return 0;
int l = 1,r = ss/sa;
while(l+3 < r) {
int mid = (l+r)>>1;
if(pd(mid)) l = mid;
else r = mid;
}
for(int i = r; i >= l; i --)
if(pd(i)) {
cout<<i<<"\n";
break;
}
}
return 0;
}
/*
6
4 3
1 2 3 4
4 4 4
3 2
1 1 1
1 7
3 4
6 6 2
1 1 5 5
3 5
3 1 1
1 1 1 1 1
4 5
1 9 9 8
2 2 2 3 1
5 4
1 3 1 7 1
4 1 5 2
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5684kb
input:
6 4 3 1 2 3 4 4 4 4 3 2 1 1 1 1 7 3 4 6 6 2 1 1 5 5 3 5 3 1 1 1 1 1 1 1 4 5 1 9 9 8 2 2 2 3 1 5 4 1 3 1 7 1 4 1 5 2
output:
2 4 4 5 2 3
result:
ok 6 lines
Test #2:
score: 0
Accepted
time: 1ms
memory: 5624kb
input:
1 1 20 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
output:
1048575000000000
result:
ok single line: '1048575000000000'
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 5692kb
input:
2 3 2 1 1 1 1 7 4 2 1 1 1 1 1 2
output:
4
result:
wrong answer 2nd lines differ - expected: '0', found: ''