QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#372975#3663. The Biggest TriangleSkillZz_RE 0ms0kbC++201.7kb2024-03-31 22:04:562024-03-31 22:05:27

Judging History

你现在查看的是最新测评结果

  • [2024-03-31 22:05:27]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-03-31 22:04:56]
  • 提交

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");
    
    
    
    
    
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

3
0 0 0 1
0 0 1 0
0 1 1 0

output:


result: