Submission #731945

# Submission time Handle Problem Language Result Execution time Memory
731945 2023-04-28T07:23:21 Z NemanjaSo2005 Passport (JOI23_passport) C++14
48 / 100
2000 ms 722824 KB
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int N,L[200005],R[200005],dist[200005],d1[200005],d2[200005];
bool ubacen[2505];
struct slog{
   int gde,kol;
}pp,tren;
bool cmp(slog a,slog b){
   return a.kol<b.kol;
}
vector<slog> V;
queue<slog> Q,C;
void BFS(){
   for(int i=1;i<=N;i++)
      dist[i]=-1;
   if(Q.size()==0){
      Q.push(C.front());
      C.pop();
   }
   while(C.size()){
      if(C.front().kol!=Q.front().kol)
         break;
      Q.push(C.front());
      C.pop();
   }
   while(Q.size()){
      tren=Q.front();
      Q.pop();
      if(dist[tren.gde]!=-1)
         continue;
      dist[tren.gde]=tren.kol;
      for(int i=1;i<=N;i++){
         if(tren.gde<L[i])
            continue;
         if(tren.gde>R[i])
            continue;
         pp.gde=i;
         pp.kol=tren.kol+1;
         while(C.size()){
            if(C.front().kol>pp.kol)
               break;
            Q.push(C.front());
            C.pop();
         }
         Q.push(pp);
      }
   }
   while(C.size())
      C.pop();
   return;
}
int main(){
   cin>>N;
   for(int i=1;i<=N;i++)
      cin>>L[i]>>R[i];
   for(int i=1;i<=N;i++){
      if(L[i]!=1)
         continue;
      pp.gde=i;
      pp.kol=0;
      Q.push(pp);
   }
   BFS();
   for(int i=1;i<=N;i++)
      d1[i]=dist[i];
   for(int i=1;i<=N;i++){
      if(R[i]!=N)
         continue;
      pp.gde=i;
      pp.kol=0;
      Q.push(pp);
   }
   BFS();
   for(int i=1;i<=N;i++)
      d2[i]=dist[i];
  /* for(int i=1;i<=N;i++)
      cout<<d1[i]<<" ";
   cout<<endl;
   for(int i=1;i<=N;i++)
      cout<<d2[i]<<" ";
   cout<<endl;*/
   for(int i=1;i<=N;i++){
      if(d1[i]==-1 or d2[i]==-1)
         continue;
      pp.gde=i;
      pp.kol=d1[i]+d2[i];
      V.push_back(pp);
   }
   if(V.size()){
      sort(V.begin(),V.end(),cmp);
      for(int i=0;i<V.size();i++)
         C.push(V[i]);
      BFS();
   }
   else
      for(int i=1;i<=N;i++)
         dist[i]=-1;
   int Q,x;
   cin>>Q;
   while(Q--){
      cin>>x;
      if(d1[x]==-1 or d2[x]==-1)
         cout<<"-1\n";
      else
         cout<<dist[x]+1<<"\n";
   }
   return 0;
}

Compilation message

passport.cpp: In function 'int main()':
passport.cpp:92:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<slog>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |       for(int i=0;i<V.size();i++)
      |                   ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Execution timed out 2080 ms 722824 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 3 ms 468 KB Output is correct
14 Correct 3 ms 468 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 3 ms 468 KB Output is correct
14 Correct 3 ms 468 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 70 ms 7436 KB Output is correct
17 Correct 17 ms 468 KB Output is correct
18 Correct 139 ms 5696 KB Output is correct
19 Correct 127 ms 6156 KB Output is correct
20 Correct 16 ms 468 KB Output is correct
21 Correct 28 ms 372 KB Output is correct
22 Correct 54 ms 13624 KB Output is correct
23 Correct 110 ms 10392 KB Output is correct
24 Correct 74 ms 13604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 3 ms 468 KB Output is correct
14 Correct 3 ms 468 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 70 ms 7436 KB Output is correct
17 Correct 17 ms 468 KB Output is correct
18 Correct 139 ms 5696 KB Output is correct
19 Correct 127 ms 6156 KB Output is correct
20 Correct 16 ms 468 KB Output is correct
21 Correct 28 ms 372 KB Output is correct
22 Correct 54 ms 13624 KB Output is correct
23 Correct 110 ms 10392 KB Output is correct
24 Correct 74 ms 13604 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 80 ms 9428 KB Output is correct
28 Correct 24 ms 500 KB Output is correct
29 Correct 22 ms 372 KB Output is correct
30 Correct 29 ms 376 KB Output is correct
31 Correct 62 ms 7712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Execution timed out 2080 ms 722824 KB Time limit exceeded
5 Halted 0 ms 0 KB -