Submission #296176

# Submission time Handle Problem Language Result Execution time Memory
296176 2020-09-10T11:35:31 Z BThero Long Mansion (JOI17_long_mansion) C++17
10 / 100
267 ms 7172 KB
// chrono::system_clock::now().time_since_epoch().count()
#include<bits/stdc++.h>

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << " = " << x << endl;

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = (int)5e3 + 5;

vector<int> keys[MAXN];
pii seg[MAXN];
int betw[MAXN];
int n, q;
int own[MAXN];

void solve() {
  scanf("%d", &n);
  
  for (int i = 1; i < n; ++i) {
    scanf("%d", &betw[i]);
  }
  
  for (int i = 1; i <= n; ++i) {
    int sz;
    scanf("%d", &sz);
    keys[i].resize(sz);
    
    for (int j = 0; j < sz; ++j) {
      scanf("%d", &keys[i][j]);
    }
  }
  
  for (int i = 1; i <= n; ++i) {
    int L = i, R = i;
    fill(own + 1, own + n + 1, 0);
    
    for (int x : keys[i]) {
      own[x] = 1;
    }
    
    bool did = 1;
    
    while (did) {
      did = 0;
    
      if (L > 1 && own[betw[L - 1]]) {
        --L;
        
        for (int x : keys[L]) {
          own[x] = 1;
        }
        
        did = 1;
      }
      
      if (R < n && own[betw[R]]) {
        ++R;
        
        for (int x : keys[R]) {
          own[x] = 1;
        }
        
        did = 1;
      }
    }
    
    seg[i] = mp(L, R);
  }
  
  scanf("%d", &q);
  
  for (int i = 1; i <= q; ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    
    if (seg[a].fi <= b && b <= seg[a].se) {
      printf("YES\n");
    }
    else {
      printf("NO\n");
    }
  }
}

int main() {
  int tt = 1;
  
  while (tt--) {
    solve();
  }

  return 0;
}

Compilation message

long_mansion.cpp: In function 'void solve()':
long_mansion.cpp:26:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   26 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
long_mansion.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   29 |     scanf("%d", &betw[i]);
      |     ~~~~~^~~~~~~~~~~~~~~~
long_mansion.cpp:34:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   34 |     scanf("%d", &sz);
      |     ~~~~~^~~~~~~~~~~
long_mansion.cpp:38:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   38 |       scanf("%d", &keys[i][j]);
      |       ~~~~~^~~~~~~~~~~~~~~~~~~
long_mansion.cpp:79:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   79 |   scanf("%d", &q);
      |   ~~~~~^~~~~~~~~~
long_mansion.cpp:83:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   83 |     scanf("%d %d", &a, &b);
      |     ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 640 KB Output is correct
2 Correct 34 ms 692 KB Output is correct
3 Correct 86 ms 760 KB Output is correct
4 Correct 6 ms 640 KB Output is correct
5 Correct 33 ms 640 KB Output is correct
6 Correct 12 ms 640 KB Output is correct
7 Correct 11 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 640 KB Output is correct
2 Correct 34 ms 692 KB Output is correct
3 Correct 86 ms 760 KB Output is correct
4 Correct 6 ms 640 KB Output is correct
5 Correct 33 ms 640 KB Output is correct
6 Correct 12 ms 640 KB Output is correct
7 Correct 11 ms 640 KB Output is correct
8 Correct 173 ms 6472 KB Output is correct
9 Correct 168 ms 6428 KB Output is correct
10 Correct 205 ms 7000 KB Output is correct
11 Correct 267 ms 7172 KB Output is correct
12 Correct 192 ms 6008 KB Output is correct
13 Correct 176 ms 6648 KB Output is correct
14 Correct 174 ms 6668 KB Output is correct
15 Correct 184 ms 6672 KB Output is correct
16 Correct 196 ms 6500 KB Output is correct
17 Correct 171 ms 6732 KB Output is correct
18 Correct 163 ms 6648 KB Output is correct
19 Correct 165 ms 6696 KB Output is correct
20 Correct 172 ms 6648 KB Output is correct
21 Correct 186 ms 6392 KB Output is correct
22 Correct 194 ms 6656 KB Output is correct
23 Correct 172 ms 6456 KB Output is correct
24 Correct 169 ms 6420 KB Output is correct
25 Correct 170 ms 6384 KB Output is correct
26 Correct 172 ms 6392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 9 ms 896 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 640 KB Output is correct
2 Correct 34 ms 692 KB Output is correct
3 Correct 86 ms 760 KB Output is correct
4 Correct 6 ms 640 KB Output is correct
5 Correct 33 ms 640 KB Output is correct
6 Correct 12 ms 640 KB Output is correct
7 Correct 11 ms 640 KB Output is correct
8 Correct 173 ms 6472 KB Output is correct
9 Correct 168 ms 6428 KB Output is correct
10 Correct 205 ms 7000 KB Output is correct
11 Correct 267 ms 7172 KB Output is correct
12 Correct 192 ms 6008 KB Output is correct
13 Correct 176 ms 6648 KB Output is correct
14 Correct 174 ms 6668 KB Output is correct
15 Correct 184 ms 6672 KB Output is correct
16 Correct 196 ms 6500 KB Output is correct
17 Correct 171 ms 6732 KB Output is correct
18 Correct 163 ms 6648 KB Output is correct
19 Correct 165 ms 6696 KB Output is correct
20 Correct 172 ms 6648 KB Output is correct
21 Correct 186 ms 6392 KB Output is correct
22 Correct 194 ms 6656 KB Output is correct
23 Correct 172 ms 6456 KB Output is correct
24 Correct 169 ms 6420 KB Output is correct
25 Correct 170 ms 6384 KB Output is correct
26 Correct 172 ms 6392 KB Output is correct
27 Execution timed out 9 ms 896 KB Time limit exceeded (wall clock)
28 Halted 0 ms 0 KB -