QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#91227 | #4376. Dragon slayer | Tobo# | WA | 359ms | 3460kb | C++20 | 2.3kb | 2023-03-27 20:01:31 | 2023-03-27 20:01:33 |
Judging History
answer
#include <bits/stdc++.h>
#define N 1000005
#define mod 1000000007
using i64 = long long;
using namespace std;
int n, m, k, s1, t1, s2, t2, vis[31][31];
vector<array<int, 4>> block;
int dir[4][2] = {{0, -2}, {0, 2}, {2, 0}, {2, -2}};
bool dfs(int curx, int cury, int sta)
{
if (tie(curx, cury) == tie(s2, t2))
return true;
vis[curx][cury] = 1;
for (int j = 0; j < 4; j++)
{
int cx = curx + dir[j][0];
int cy = cury + dir[j][1];
if (cx < 0 || cy < 0)
continue;
if (cx > n || cy > m)
continue;
if (vis[cx][cy])
continue;
bool is = 1;
for (int i = 0; i < k && is; i++)
{
if (sta >> i & 1)
{
if (block[i][0] == block[i][2])
{
if ((block[i][0] - curx) * (block[i][0] - cx) == -1)
if (min(block[i][1], block[i][3]) <= cy && max(block[i][1], block[i][3]) >= cy)
is = 0;
}
else
{
if ((block[i][1] - cury) * (block[i][1] - cy) == -1)
if (min(block[i][0], block[i][2]) <= cx && max(block[i][0], block[i][2]) >= cx)
is = 0;
}
}
}
if (is && dfs(cx, cy, sta))
return true;
}
return false;
}
int popcount(int x)
{
int res = 0;
while (x)
{
res += x & 1;
x >>= 1;
}
return res;
}
void solve()
{
cin >> n >> m >> k;
n *= 2, m *= 2;
cin >> s1 >> t1 >> s2 >> t2;
s1 = 2 * s1 + 1;
t1 = 2 * t1 + 1;
s2 = 2 * s2 + 1;
t2 = 2 * t2 + 1;
block.clear();
array<int, 4> f;
for (int i = 1; i <= k; i++)
{
cin >> f[0] >> f[1] >> f[2] >> f[3];
for (int &j : f)
j *= 2;
block.push_back(f);
}
int ans = k;
for (int s = 0; s < (1 << k); s++)
{
memset(vis, 0, sizeof(vis));
if (dfs(s1, t1, s))
ans = min(ans, popcount((1 << k) - 1 - s));
}
cout << ans << '\n';
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
cin >> t;
while (t--)
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 359ms
memory: 3460kb
input:
10 4 4 4 0 2 3 3 0 2 4 2 1 3 1 0 2 4 2 1 3 1 3 4 3 2 2 0 0 2 1 0 1 3 1 1 0 1 2 3 2 2 0 0 2 1 2 1 2 2 1 0 1 1 15 15 15 3 12 4 1 8 0 8 15 1 11 15 11 1 1 1 15 3 1 3 15 0 10 14 10 14 1 14 14 8 1 8 15 1 5 14 5 0 15 14 15 0 4 14 4 0 2 15 2 11 0 11 15 4 1 4 15 1 11 15 11 1 12 14 12 15 15 15 8 5 14 0 0 12 1...
output:
1 2 0 7 3 9 1 4 15 0
result:
wrong answer 4th lines differ - expected: '5', found: '7'