Submission #854299

# Submission time Handle Problem Language Result Execution time Memory
854299 2023-09-26T16:57:11 Z mychecksedad From Hacks to Snitches (BOI21_watchmen) C++17
0 / 100
2843 ms 25840 KB
/* Author : Mychecksdead  */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
const int N = 3e5+100, M = 1e5+10, K = 10;



int n, m, k, mx[N];
array<int, 2> T[N]; 
vector<int> g[N];
priority_queue<int> best[N];
void solve(){
  cin >> n >> m;
  for(int i = 0; i < m; i++){
    int u, v; cin >> u >> v;
    g[u].pb(v);
    g[v].pb(u);
  }
  for(int i = 1; i <= n; ++i) T[i] = {-1, 0}, mx[i] = 1;
  cin >> k;
  for(int i = 1; i <= k; ++i){
    int x; cin >> x;
    for(int j = 0; j < x; ++j){
      int nod; cin >> nod;
      T[nod] = {j, x};
      mx[nod] = x;
    }
  }
  priority_queue<array<int, 2>> q;
  q.push({0, 1});
  best[1].push(0);
  while(!q.empty()){
    int v = q.top()[1], D = -q.top()[0];
    q.pop();
    if(D > best[v].top()) continue;
    for(int u: g[v]){
      for(int j = 1; j <= max(mx[u], mx[v])+1; ++j){
        int DD = D + j;
        if(T[v][0] > -1 && (DD-1) % T[v][1] == T[v][0]) break;
        if(T[v][0] > -1 && T[u][0] > -1 && DD % T[v][1] == T[v][0] && (DD-1) % T[u][1] == T[u][0]){
          continue;
        }
        if(T[u][0] > -1 && DD % T[u][1] == T[u][0]){
          continue;
        }
        if(best[u].size() < mx[u]){
          best[u].push(DD);
          q.push({-DD, u});
        }else if(best[u].top() > DD){
          best[u].pop();
          best[u].push(DD);
          q.push({-DD, u});
        } 
      }
    }
  }
  if(best[n].empty()) cout << "impossible";
  else{
    while(best[n].size() > 1) best[n].pop();
    cout << best[n].top();
  }
}


int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int tt = 1, aa;
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  while(tt--){
    solve();
  }
  cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
  return 0;
} 

Compilation message

watchmen.cpp: In function 'void solve()':
watchmen.cpp:52:27: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   52 |         if(best[u].size() < mx[u]){
      |            ~~~~~~~~~~~~~~~^~~~~~~
watchmen.cpp: In function 'int main()':
watchmen.cpp:73:15: warning: unused variable 'aa' [-Wunused-variable]
   73 |   int tt = 1, aa;
      |               ^~
# Verdict Execution time Memory Grader output
1 Correct 2843 ms 19160 KB Output is correct
2 Incorrect 81 ms 25840 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2838 ms 19160 KB Output is correct
2 Incorrect 79 ms 25836 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2838 ms 19160 KB Output is correct
2 Incorrect 79 ms 25836 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2838 ms 19160 KB Output is correct
2 Incorrect 79 ms 25836 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2843 ms 19160 KB Output is correct
2 Incorrect 81 ms 25840 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2843 ms 19160 KB Output is correct
2 Incorrect 81 ms 25840 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2843 ms 19160 KB Output is correct
2 Incorrect 81 ms 25840 KB Output isn't correct
3 Halted 0 ms 0 KB -