QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#113847#5537. Storing EggsPetroTarnavskyi#WA 1ms5864kbC++172.3kb2023-06-19 18:10:112023-06-19 18:10:13

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-19 18:10:13]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 5864kb
  • [2023-06-19 18:10:11]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

const int N = 474;
const int inf = 4747474;
string v[3];
int dp[N][N][8][8];

int res[8] = {inf, inf, inf, 1, inf, 2, 1, 1};
int r[8][8];

void setmax(int& a, int b)
{
	a = max(a, b);
}
void setmin(int& a, int b)
{
	a = min(a, b);
}

void f(int mask1, int mask2)
{
	int ans = inf;
	FOR (i, 0, 3)
	{
		if (((mask1 >> i) & 1) == 0)
			continue;
		FOR (j, 0, 3)
		{
			if (((mask2 >> j) & 1) == 0)
				continue;
				
			int d1 = abs(i - j);
			setmin(ans, d1 * d1);
		}
	}
	r[mask1][mask2] = ans;
}


bool ok(int m, int i)
{
	FOR (j, 0, 3)
	{
		if (((m >> j) & 1) && v[j][i] == '#')
			return false;
	}
	return true;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	FOR (i, 0, 8)
	{
		FOR (j, 0, 8)
		{
			f(i, j);
		}
	}
	
	int n, k;
	cin >> n >> k;
	FOR (i, 0, 3)
	{
		string s;
		cin >> s;
		v[i] = "#" + s;
	}
	FOR (i, 0, n + 1)
	{
		FOR(cnt, 0, k + 1)
		{
			FOR (m1, 0, 8)
			{
				FOR (m2, 0, 8)
					dp[i][cnt][m1][m2] = 0;
			}
		}
	}
	dp[0][0][0][0] = inf;
	FOR (now, 1, n + 1)
	{
		FOR (cnt, 0, k + 1)
		{
			FOR (col, 0, now)
			{
				FOR (m, 0, 8)
				{
					if (!ok(m, now))
						continue;
					FOR (mask, 0, 8)
					{
						if(mask == 0 && col != 0)
							continue;
						FOR (pmask, 0, 8)
						{
							int d = now - col;
							if (d > 2 && pmask > 0) break;
							int cur = dp[col][cnt][mask][pmask];
							cur = min(cur, r[mask][m] + d * d);
							cur = min(cur, r[pmask][m] + (d + 1) * (d + 1));
							cur = min(cur, res[m]);
							setmax(dp[now][cnt + __builtin_popcount(m)][m][col + 1 == now ? mask : 0], cur);
						}
					}
				}
			}
		}
	}
	
	int ans = 0;
	FOR (i, 0, 8)
	{
		FOR (j, 0, 8)
		{
			ans = max(ans, dp[n][k][i][j]);
		}
	}
	if (ans < 0.1) {
		cout << "-1\n";
	}
	else {
		cout << fixed << setprecision(10) << sqrt(ans) << '\n';
	}
	
	return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3804kb

input:

5 2
#....
.....
....#

output:

4.4721359550

result:

ok found '4.4721360', expected '4.4721360', error '0.0000000'

Test #2:

score: 0
Accepted
time: 1ms
memory: 5864kb

input:

5 6
##.##
#####
.....

output:

1.0000000000

result:

ok found '1.0000000', expected '1.0000000', error '0.0000000'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3648kb

input:

3 4
..#
...
...

output:

1.4142135624

result:

ok found '1.4142136', expected '1.4142140', error '0.0000003'

Test #4:

score: 0
Accepted
time: 1ms
memory: 3536kb

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: 3784kb

input:

1 2
.
.
.

output:

1.4142135624

result:

wrong answer 1st numbers differ - expected: '2.0000000', found: '1.4142136', error = '0.2928932'