QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#383259 | #5537. Storing Eggs | FOY# | WA | 1ms | 3916kb | C++20 | 5.1kb | 2024-04-09 07:56:59 | 2024-04-09 07:56:59 |
Judging History
answer
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;
using ld = long double;
int n, m;
int main() {
// m is number we have to place (K in question)
cin >> n >> m;
int cnt = 0;
vector<vector<bool>> usable(n, vector<bool>(3));
for (int i = 0; i < 3; i++) {
for (int j = 0; j < n; j++) {
char c; cin >> c;
usable[j][i] = (c == '.');
cnt += (usable[j][i]);
}
}
if (cnt < m) {
cout << -1 << endl;
return 0;
}
// sq distance
int lv = 1;
int rv = 1e9;
// check 2
// go by column
// int of total count or something, dp[i][0] is ith column is X.X, dp[i][1] is .X.
// third dimension, whether actually placed or not
// 0 is not possible to place
vector<vector<vector<int>>> dp2(n+1, vector<vector<int>>(2, vector<int>(2, 0)));
for (int i = 1; i <= n; i++) {
bool one = (usable[i-1][0] && usable[i-1][2]);
bool two = (usable[i-1][1]);
int bruh = 0;
for (int j =0; j < 2; j++) {
for (int k = 0; k < 2; k++) {
bruh = max(bruh, dp2[i-1][j][k]);
}
}
dp2[i][0][0] = bruh;
dp2[i][1][0] = bruh;
bruh = max(dp2[i-1][0][0], dp2[i-1][1][0]);
if (one) {
dp2[i][0][1] = bruh + 2;
dp2[i][0][1] = max(dp2[i][0][1], dp2[i-1][1][1] + 2);
}
if (two) {
dp2[i][1][1] = bruh + 1;
dp2[i][1][1] = max(dp2[i][1][1], dp2[i-1][0][1] + 1);
}
}
bool poop = false;
for (int i = 1; i <= n && !poop; i++) {
for (int j= 0; j < 2 && !poop; j++) {
for (int k = 0; k < 2 && !poop; k++) {
if (dp2[i][j][k] >= m) {
poop = true;
}
}
}
}
// cout << "DP 2: " << endl;
// for (int i = 1; i <= n; i++) {
// int blah = 0;
// for (int j = 0; j < 2; j++) {
// for (int k = 0; k < 2; k++) {
// blah = max(blah, dp2[i][j][k]);
// }
// }
// cout << blah << ' ';
// }
// cout << endl;
// if (poop) cout << "POOP!" << endl;
// return 0;
if (poop) lv = 2;
// run it back for lv = 5, essentially identically dp
// no not the same
// because you can't actually alternate top bottom to get 5
// you need to skip shit
// so you need blank columns
// and you need a blank column after two adjacent non-blank columns
// etc. etc.
// so dp[i] will have one extra dimension for the type
// which will just be a 2-bit number
// 00 is empty, 01 is top, 10 is bottom
// and then just check against the last two columns to place
// bruh
cnt = 0;
for (int i = 0; i < n-1; i+=3) {
if (usable[i][0] && usable[i+1][2]) {
cnt++;
}
else if (usable[i][2] && usable[i+1][2]) {
cnt++;
}
}
if (n % 3 == 1) {
cnt += (usable[n-1][0] || usable[n-1][2]);
}
bool poop2 = false;
if (cnt >= m) poop2 = true;
if (poop2) {
lv = 5;
}
while (rv - lv > 1) {
int mid = (lv + rv)/2;
// if (mid > 20) rv = mid;
// cout << "MID: " << mid << endl;
vector<vector<vector<bool>>> dp(m, vector<vector<bool>>(n, vector<bool>(3, false)));
for (int j = 0; j < n; j++) {
for (int k = 0; k < 3; k++) {
if (!usable[j][k]) continue;
dp[0][j][k] = true;
}
}
for (int i = 1; i < m; i++) {
for (int j = 0; j < n; j++) {
for (int k = 0; k < 3; k++) {
if (!usable[j][k]) continue;
for (int p = 0; p < j; p++) {
for (int q = 0; q < 3; q++) {
if (dp[i-1][p][q]) {
if (((j-p)*(j-p) + (k-q)*(k-q)) >= mid) {
dp[i][j][k] = true;
}
}
}
}
}
}
}
// cout << "DP: " << endl;
// for (int i = 0; i < m; i++) {
// for (int j = 0; j < n; j++) {
// for (int k = 0; k < 3; k++) {
// cout << dp[i][j][k] << ' ';
// }
// cout << endl;
// }
// cout << endl;
// }
bool worked = false;
for (int j = 0; j < n; j++) {
for (int k = 0; k < 3; k++) {
worked = worked || dp[m-1][j][k];
}
}
if (worked) {
lv = mid;
}
else {
rv = mid;
}
}
// if (poop) cout << "POOP!" << endl;
// if (poop2) cout << "POOP 2!" << endl;
// cout << "LV: " << lv << endl;
cout << fixed << setprecision(10);
cout << sqrt((ld)(lv)) << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3880kb
input:
5 2 #.... ..... ....#
output:
4.4721359550
result:
ok found '4.4721360', expected '4.4721360', error '0.0000000'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3772kb
input:
5 6 ##.## ##### .....
output:
1.0000000000
result:
ok found '1.0000000', expected '1.0000000', error '0.0000000'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
3 4 ..# ... ...
output:
1.4142135624
result:
ok found '1.4142136', expected '1.4142140', error '0.0000003'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3772kb
input:
2 6 .. .# ..
output:
-1
result:
ok found '-1.0000000', expected '-1.0000000', error '-0.0000000'
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3916kb
input:
1 2 . . .
output:
1.4142135624
result:
wrong answer 1st numbers differ - expected: '2.0000000', found: '1.4142136', error = '0.2928932'