QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#113843#5537. Storing EggsPetroTarnavskyi#TL 69ms28352kbC++172.3kb2023-06-19 17:53:492023-06-19 17:53:53

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 17:53:53]
  • Judged
  • Verdict: TL
  • Time: 69ms
  • Memory: 28352kb
  • [2023-06-19 17:53:49]
  • 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];
double dp[N][N][8][8];

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

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

double f(int mask1, int mask2, int dis)
{
	double 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, sqrt(d1 * d1 + dis * dis));
		}
	}
	
	return 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);
	
	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)
						{
							double cur = dp[col][cnt][mask][pmask];
							cur = min(cur, f(mask, m, now - col));
							assert((mask == 0 || m == 0) || f(mask, m, now - col) < inf);
							cur = min(cur, f(pmask, m, now - col + 1));
							assert((pmask == 0 || m == 0) || f(pmask, m, now - col + 1) < inf);
							cur = min(cur, res[m]);
							
							setmax(dp[now][cnt + __builtin_popcount(m)][m][col + 1 == now ? mask : 0], cur);
						}
					}
				}
			}
		}
	}
	
	double 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) << ans << '\n';
	}
	
	return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 5708kb

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

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

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

input:

2 6
..
.#
..

output:

-1

result:

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

Test #5:

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

input:

1 2
.
.
.

output:

2.0000000000

result:

ok found '2.0000000', expected '2.0000000', error '0.0000000'

Test #6:

score: 0
Accepted
time: 53ms
memory: 28352kb

input:

100 2
....................................................................................................
....................................................................................................
...............................................................................................

output:

99.0201999594

result:

ok found '99.0202000', expected '99.0202000', error '0.0000000'

Test #7:

score: 0
Accepted
time: 69ms
memory: 26224kb

input:

100 3
....................................................................................................
....................................................................................................
...............................................................................................

output:

49.0407993410

result:

ok found '49.0407993', expected '49.0407990', error '0.0000000'

Test #8:

score: -100
Time Limit Exceeded

input:

100 100
....................................................................................................
....................................................................................................
.............................................................................................

output:


result: