QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#306951 | #5537. Storing Eggs | NYCU_CartesianTree | WA | 86ms | 39744kb | C++20 | 3.5kb | 2024-01-17 18:02:56 | 2024-01-17 18:02:57 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define pb push_back
const int mol=998244353;
char a[5][105];
int dp[105][105][105];
const double eps=1e-7;
int okbc[105][105][105],okac[105][105][105],okab[105][105][105];
void solve(){
int n,q;
cin>>n>>q;
int cc=0;
for(int i=1;i<=3;i++) for(int j=1;j<=n;j++) cin>>a[i][j];
for(int i=1;i<=3;i++) for(int j=1;j<=n;j++){
if(a[i][j]!='#') cc++;
}
if(cc<q){
cout<<"-1\n";
return;
}
int l=0,r=50000;
while(l<r){
int mid=l+r+1>>1;
for(int i=0;i<=n;i++) for(int j=0;j<=n;j++) for(int k=0;k<=n;k++) dp[i][j][k]=0,okab[i][j][k]=0,okac[i][j][k]=0,okbc[i][j][k]=0;
for(int i=n;i>=0;i--){
for(int j=n;j>=0;j--){
for(int k=n;k>=0;k--){
bool ok=1;
if(a[1][i]=='#') ok=0;
if(a[2][j]=='#') ok=0;
if((j-i)*(j-i)+1<mid&&i&&j) ok=0;
if((k-i)*(k-i)+4<mid&&i&&k) ok=0;
if(j&&(k-j)*(k-j)+1<mid&&k) ok=0;
if(a[3][k]=='#') ok=0;
if(!ok){
okab[i][j][k]=okab[i][j][k+1];
okac[i][j][k]=okac[i][j+1][k];
okbc[i][j][k]=okac[i+1][j][k];
}
else
okab[i][j][k]=k,okac[i][j][k]=j,okbc[i][j][k]=i;
}
}
}
int ans=0;
int t=sqrt(mid);
while(t*t>=mid) t--;
while(t*t<mid) t++;
for(int i=0;i<=n;i++){
if(a[1][i]=='#') continue;
for(int j=0;j<=n;j++){
if((j-i)*(j-i)+1<mid&&i&&j) continue;
if(a[2][j]=='#') continue;
for(int k=0;k<=n;k++){
if(k){
if((k-i)*(k-i)+4<mid&&i) continue;
if(j&&(k-j)*(k-j)+1<mid) continue;
}
if(a[3][k]=='#') continue;
int u=0;if(i) u++;if(j) u++;if(k) u++;
dp[i][j][k]=max({u,dp[i][j][k]});
if(i) dp[i][j][k]=max(dp[i][j][k],dp[i-1][j][k]);
if(j) dp[i][j][k]=max(dp[i][j][k],dp[i][j-1][k]);
if(k) dp[i][j][k]=max(dp[i][j][k],dp[i][j][k-1]);
if(i+t<=n&&okbc[i+t][j][k]) dp[okbc[i+t][j][k]][j][k]=max(dp[okbc[i+t][j][k]][j][k],dp[i][j][k]+1);
if(j+t<=n&&okac[i][j+t][k]) dp[i][okac[i][j+t][k]][k]=max(dp[i][okac[i][j+t][k]][k],dp[i][j][k]+1);
if(k+t<=n&&okab[i][j][k+t]) dp[i][j][okab[i][j][k+t]]=max(dp[i][j][okab[i][j][k+t]],dp[i][j][k]+1);
ans=max(ans,dp[i][j][k]);
// if(dp[i][j][k]==1&&k==0&&mid==2) cout<<i<<" "<<j<<" "<<k<<" "<<mid*mid<<" "<<dp[i][j][k+mid*mid]<<"\n";
}
}
}
// cout<<mid<<" "<<dp[2][1][2]<<" "<<okac[2][3][2]<<"\n";
// cout<<ans<<" "<<mid<<"pp\n";
if(ans>=q) l=mid;
else r=mid-1;
}
// cout<<l<<"\n";
cout<<fixed<<setprecision(6)<<sqrt(l)<<"\n";
}
signed main(){
ios::sync_with_stdio(0);cin.tie(0);
// double t1=(double)clock()/CLOCKS_PER_SEC;
solve();
// double t2=(double)clock()/CLOCKS_PER_SEC;
// cout<<fixed<<setprecision(10)<<t2-t1<<"\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 12024kb
input:
5 2 #.... ..... ....#
output:
4.472136
result:
ok found '4.4721360', expected '4.4721360', error '0.0000000'
Test #2:
score: 0
Accepted
time: 1ms
memory: 9972kb
input:
5 6 ##.## ##### .....
output:
1.000000
result:
ok found '1.0000000', expected '1.0000000', error '0.0000000'
Test #3:
score: 0
Accepted
time: 1ms
memory: 9928kb
input:
3 4 ..# ... ...
output:
1.414214
result:
ok found '1.4142140', expected '1.4142140', error '0.0000000'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
2 6 .. .# ..
output:
-1
result:
ok found '-1.0000000', expected '-1.0000000', error '-0.0000000'
Test #5:
score: 0
Accepted
time: 1ms
memory: 9936kb
input:
1 2 . . .
output:
2.000000
result:
ok found '2.0000000', expected '2.0000000', error '0.0000000'
Test #6:
score: 0
Accepted
time: 67ms
memory: 39616kb
input:
100 2 .................................................................................................... .................................................................................................... ...............................................................................................
output:
99.020200
result:
ok found '99.0202000', expected '99.0202000', error '0.0000000'
Test #7:
score: -100
Wrong Answer
time: 86ms
memory: 39744kb
input:
100 3 .................................................................................................... .................................................................................................... ...............................................................................................
output:
50.000000
result:
wrong answer 1st numbers differ - expected: '49.0407990', found: '50.0000000', error = '0.0195592'