Submission #888713

# Submission time Handle Problem Language Result Execution time Memory
888713 2023-12-18T06:07:06 Z vjudge1 Passport (JOI23_passport) C++17
0 / 100
1 ms 348 KB
#include <bits/stdc++.h>
#define int long long
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define pb push_back
using namespace std;

signed main(){
    ios_base::sync_with_stdio();
    cin.tie(0);
    int n;
    cin>>n;
    vector <int> l(n),r(n);
    for(int i=0;i<n;i++)cin>>l[i]>>r[i];
    vector <int> a,b,c;
    for(int i=0;i<n;i++){
        for(int j=l[i];j<=r[i];j++){
            a.pb(i+1);
            b.pb(j);
            c.pb(1);
        }
    }
    
    int q;cin>>q;
    set <pair <int,int> > st;
    vector <int> ans;
    while(q--){
        int x;cin>>x;
        vector <int> d(n+1,1e9),p(n+1);
        d[x]=0;
        for(int i=0;i<n;i++){
            for(int j=0;j<a.size();j++){
                if(d[a[j]]!=1e9 && d[b[j]]>d[a[j]]+c[j]){
                    d[b[j]]=d[a[j]]+c[j];
                    p[b[j]]=a[j];
                }
            }
        }
        int mx=0;
        set <int> s;
        for(int i=1;i<=n;i++){
            mx=max(mx,d[i]);
            if(d[i]==1e9)break;
            int curv=i;
            while(curv!=x){
                curv=p[curv];
                s.insert(curv);
                
            }
        }
        if(mx==1e18)cout<<-1<<"\n";
        else cout<<s.size()<<"\n";
    }
    
}

Compilation message

passport.cpp: In function 'int main()':
passport.cpp:33:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |             for(int j=0;j<a.size();j++){
      |                         ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 0 ms 344 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 0 ms 344 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 0 ms 344 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -