QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#372975 | #3663. The Biggest Triangle | SkillZz_ | RE | 0ms | 0kb | C++20 | 1.7kb | 2024-03-31 22:04:56 | 2024-03-31 22:05:27 |
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
int n;
const int N = 1005;
bool dp[N][N], vis[N][N], vis2[N][N], dp2[N][N];
vector <vector <int>> v, v2;
bool can[N][N][4];
bool ans = true;
bool solve(int idx, int ctr)
{
if(ctr == n)
return (idx == n - 1);
bool &ret = dp[idx][ctr];
if(vis[idx][ctr])
return ret;
vis[idx][ctr] = true;
for(int j = 0; j < 4; j++)
{
auto solveRet = solve(v[idx][j] - 1, ctr + 1);
ret |= solveRet;
can[idx][ctr][j] |= solveRet;
}
return ret;
}
bool solve2(int idx, int ctr)
{
if(idx == n - 1)
return false;
if(ctr == n)
{
return (idx == n - 1);
}
bool &ret = dp2[idx][ctr];
if(vis2[idx][ctr])
return ret;
vis2[idx][ctr]= true;
for(int j = 0; j < 4; j++)
{
bool solveRet = false;
solveRet |= solve2(v2[idx][j] - 1, ctr + 1);
ret |= solveRet;
if(can[idx][ctr][j])
ans &= solveRet;
}
return ret;
}
int main()
{
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n;
v.resize(n, vector <int> (4)), v2.resize(n, vector <int> (4));
for(int i = 0; i < n; i++) // senior
{
for(int j = 0; j < 4; j++)
cin >> v[i][j];
}
for(int i = 0; i < n; i++) // senior
{
for(int j = 0; j < 4; j++)
cin >> v2[i][j];
}
if(!solve(0, 0))
{
cout << "Impossible\n";
return 0;
}
solve2(0, 0);
cout << (ans ? "Yes\n" : "No\n");
}
詳細信息
Test #1:
score: 0
Runtime Error
input:
3 0 0 0 1 0 0 1 0 0 1 1 0