Submission #801109

# Submission time Handle Problem Language Result Execution time Memory
801109 2023-08-02T04:36:46 Z vjudge1 Long Mansion (JOI17_long_mansion) C++14
10 / 100
421 ms 42052 KB
#include<bits/stdc++.h>
using namespace std ;
const int N = 5e5, NS = 5e3 ;
bool us[NS + 1][NS + 1] ;
int n, q, sm, c[N + 1] ;
vector<int> ks[N + 1] ;
map<int, int> ch, null ;
void bfs(int city)
{
    ch = null ;
    bool abu = 1 ;
    int l = city, r = city ;
    for(int i : ks[city])
        ch[i] = 1 ;
    us[city][city] = 1 ;
    while(abu)
    {
        abu ^= 1 ;
        if(l > 1 && ch[c[l - 1]])
        {
            l-- ;
            for(int i : ks[l])
                ch[i] = 1 ;
//            cout<<city<<' '<<l << '\n' ;
            us[city][l] = 1 ;
            abu |= 1 ;
        }
        if(r < n && ch[c[r]])
        {
            abu |= 1 ;
            r++ ;
            for(int i : ks[r])
                ch[i] = 1 ;
//            cout<<city<<' '<<r << '\n' ;
            us[city][r] = 1 ;
        }
    }
}
signed main()
{
    ios_base::sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
    cin >> n ;
    for(int i = 1 ; i < n ; i++)
        cin >> c[i] ;
    for(int i = 1 ; i <= n ; i++)
    {
        int b ;
        cin >> b ;
        sm += b ;
        for(int j = 1 ; j <= b ; j++)
        {
            int a ;
            cin >> a ;
            ks[i].push_back(a) ;
        }
    }
    if(n <= 5000 && sm <= 5000)
    {
        for(int i = 1 ; i <= n ; i++)
            bfs(i) ;
        cin >> q ;
        for(int i = 1 ; i <= q ; i++)
        {
            int x, y ;
            cin >> x >> y ;
            if(us[x][y])
                cout << "YES\n" ;
            else
                cout << "NO\n" ;
        }
        return 0 ;
    }
    return 0 ;
}
# Verdict Execution time Memory Grader output
1 Correct 16 ms 20180 KB Output is correct
2 Correct 102 ms 25416 KB Output is correct
3 Correct 242 ms 35500 KB Output is correct
4 Correct 23 ms 20308 KB Output is correct
5 Correct 328 ms 21948 KB Output is correct
6 Correct 126 ms 20840 KB Output is correct
7 Correct 81 ms 20656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 20180 KB Output is correct
2 Correct 102 ms 25416 KB Output is correct
3 Correct 242 ms 35500 KB Output is correct
4 Correct 23 ms 20308 KB Output is correct
5 Correct 328 ms 21948 KB Output is correct
6 Correct 126 ms 20840 KB Output is correct
7 Correct 81 ms 20656 KB Output is correct
8 Correct 109 ms 26164 KB Output is correct
9 Correct 88 ms 26060 KB Output is correct
10 Correct 188 ms 31564 KB Output is correct
11 Correct 327 ms 42052 KB Output is correct
12 Correct 127 ms 22044 KB Output is correct
13 Correct 86 ms 26220 KB Output is correct
14 Correct 102 ms 26332 KB Output is correct
15 Correct 248 ms 27084 KB Output is correct
16 Correct 402 ms 27796 KB Output is correct
17 Correct 102 ms 26288 KB Output is correct
18 Correct 106 ms 26404 KB Output is correct
19 Correct 137 ms 26656 KB Output is correct
20 Correct 399 ms 27568 KB Output is correct
21 Correct 421 ms 27788 KB Output is correct
22 Correct 364 ms 27452 KB Output is correct
23 Correct 200 ms 26448 KB Output is correct
24 Correct 181 ms 26432 KB Output is correct
25 Correct 164 ms 26424 KB Output is correct
26 Correct 104 ms 26208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 51 ms 18108 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 20180 KB Output is correct
2 Correct 102 ms 25416 KB Output is correct
3 Correct 242 ms 35500 KB Output is correct
4 Correct 23 ms 20308 KB Output is correct
5 Correct 328 ms 21948 KB Output is correct
6 Correct 126 ms 20840 KB Output is correct
7 Correct 81 ms 20656 KB Output is correct
8 Correct 109 ms 26164 KB Output is correct
9 Correct 88 ms 26060 KB Output is correct
10 Correct 188 ms 31564 KB Output is correct
11 Correct 327 ms 42052 KB Output is correct
12 Correct 127 ms 22044 KB Output is correct
13 Correct 86 ms 26220 KB Output is correct
14 Correct 102 ms 26332 KB Output is correct
15 Correct 248 ms 27084 KB Output is correct
16 Correct 402 ms 27796 KB Output is correct
17 Correct 102 ms 26288 KB Output is correct
18 Correct 106 ms 26404 KB Output is correct
19 Correct 137 ms 26656 KB Output is correct
20 Correct 399 ms 27568 KB Output is correct
21 Correct 421 ms 27788 KB Output is correct
22 Correct 364 ms 27452 KB Output is correct
23 Correct 200 ms 26448 KB Output is correct
24 Correct 181 ms 26432 KB Output is correct
25 Correct 164 ms 26424 KB Output is correct
26 Correct 104 ms 26208 KB Output is correct
27 Incorrect 51 ms 18108 KB Output isn't correct
28 Halted 0 ms 0 KB -