답안 #1085901

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1085901 2024-09-09T02:59:48 Z Bananabread Passport (JOI23_passport) C++17
54 / 100
832 ms 455668 KB
#include<bits/stdc++.h>
#define ll long long
#define ntr "\n"
#define mod (ll)(1e9+7)
#define taskname "temp"
#define frep freopen(taskname".inp","r",stdin); freopen(taskname".out","w",stdout);
using namespace std;
vector<array<int,3>> adj[2501][2501];
ll dist[2501][2501];
ll vis[2501][2501];
ll n,q;
ll l[200001];
ll r[200001];
void sub1(){
    for(int i=1;i<=n;i++){
        cin>>l[i]>>r[i];
    }
    ll mx=r[1];
    ll ans=1;
    cin>>q>>q;
    priority_queue<ll> q;
    for(int i=1;i<=n;i++){
        if(i>mx){
            cout<<-1;
            return;
        }
        q.push(r[i]);
        if(i==mx){
            ans++;
            mx=q.top();
        }
    }
    cout<<ans-1;
}
int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //frep;
    cin>>n;
   
    if(n>2500){
		sub1();
		return 0;
    }
    for(int i=1;i<=n;i++){
        cin>>l[i]>>r[i];
    }
    for(int i=1;i<=n;i++){
        ll mx=0,mn=1e18;
        adj[l[i]][r[i]].push_back({i,i,1});
        for(int j=i;j<=n;j++){
            mx=max(mx,r[j]);
            mn=min(mn,l[j]);
            if(i!=j){
                adj[i][mx].push_back({i,j,1});
                adj[mn][j].push_back({i,j,1});
                adj[i+1][j].push_back({i,j,0});
                adj[i][j-1].push_back({i,j,0});
            }
        }
    }
    memset(dist,0x3f,sizeof(dist));
    dist[1][n]=0;
    deque<array<ll,2>> dq;
    dq.push_front({1,n});
    while(!dq.empty()){
        ll u=dq.front()[0],v=dq.front()[1];
        dq.pop_front();
        if(vis[u][v]) continue;
        vis[u][v]=1;
        for(auto i:adj[u][v]){
            ll x=i[0],y=i[1],w=i[2];
            if(dist[x][y]>dist[u][v]+w){
                dist[x][y]=dist[u][v]+w;
                if(w==0){
                    dq.push_front({x,y});
                }
                else{
                    dq.push_back({x,y});
                }
            }
        }
    }
    cin>>q;
    for(int i=1;i<=q;i++){
        ll x;
        cin>>x;
        cout<<(dist[x][x] >= 1e18 ? -1 : dist[x][x])<<ntr;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 196176 KB Output is correct
2 Correct 85 ms 196108 KB Output is correct
3 Correct 86 ms 196176 KB Output is correct
4 Correct 90 ms 154832 KB Output is correct
5 Correct 94 ms 155024 KB Output is correct
6 Correct 92 ms 155088 KB Output is correct
7 Correct 83 ms 154060 KB Output is correct
8 Correct 81 ms 152532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 85 ms 196224 KB Output is correct
2 Correct 85 ms 196224 KB Output is correct
3 Correct 88 ms 196176 KB Output is correct
4 Correct 85 ms 196176 KB Output is correct
5 Correct 83 ms 196140 KB Output is correct
6 Correct 80 ms 196176 KB Output is correct
7 Correct 96 ms 196176 KB Output is correct
8 Correct 92 ms 196180 KB Output is correct
9 Correct 85 ms 196152 KB Output is correct
10 Correct 84 ms 196180 KB Output is correct
11 Correct 92 ms 200876 KB Output is correct
12 Correct 93 ms 200964 KB Output is correct
13 Correct 92 ms 201296 KB Output is correct
14 Correct 91 ms 201048 KB Output is correct
15 Correct 90 ms 200788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 85 ms 196224 KB Output is correct
2 Correct 85 ms 196224 KB Output is correct
3 Correct 88 ms 196176 KB Output is correct
4 Correct 85 ms 196176 KB Output is correct
5 Correct 83 ms 196140 KB Output is correct
6 Correct 80 ms 196176 KB Output is correct
7 Correct 96 ms 196176 KB Output is correct
8 Correct 92 ms 196180 KB Output is correct
9 Correct 85 ms 196152 KB Output is correct
10 Correct 84 ms 196180 KB Output is correct
11 Correct 92 ms 200876 KB Output is correct
12 Correct 93 ms 200964 KB Output is correct
13 Correct 92 ms 201296 KB Output is correct
14 Correct 91 ms 201048 KB Output is correct
15 Correct 90 ms 200788 KB Output is correct
16 Correct 598 ms 427092 KB Output is correct
17 Correct 803 ms 448728 KB Output is correct
18 Correct 625 ms 438892 KB Output is correct
19 Correct 715 ms 433492 KB Output is correct
20 Correct 583 ms 425556 KB Output is correct
21 Correct 567 ms 451408 KB Output is correct
22 Correct 497 ms 436228 KB Output is correct
23 Correct 682 ms 455668 KB Output is correct
24 Correct 574 ms 449796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 85 ms 196224 KB Output is correct
2 Correct 85 ms 196224 KB Output is correct
3 Correct 88 ms 196176 KB Output is correct
4 Correct 85 ms 196176 KB Output is correct
5 Correct 83 ms 196140 KB Output is correct
6 Correct 80 ms 196176 KB Output is correct
7 Correct 96 ms 196176 KB Output is correct
8 Correct 92 ms 196180 KB Output is correct
9 Correct 85 ms 196152 KB Output is correct
10 Correct 84 ms 196180 KB Output is correct
11 Correct 92 ms 200876 KB Output is correct
12 Correct 93 ms 200964 KB Output is correct
13 Correct 92 ms 201296 KB Output is correct
14 Correct 91 ms 201048 KB Output is correct
15 Correct 90 ms 200788 KB Output is correct
16 Correct 598 ms 427092 KB Output is correct
17 Correct 803 ms 448728 KB Output is correct
18 Correct 625 ms 438892 KB Output is correct
19 Correct 715 ms 433492 KB Output is correct
20 Correct 583 ms 425556 KB Output is correct
21 Correct 567 ms 451408 KB Output is correct
22 Correct 497 ms 436228 KB Output is correct
23 Correct 682 ms 455668 KB Output is correct
24 Correct 574 ms 449796 KB Output is correct
25 Correct 90 ms 196176 KB Output is correct
26 Correct 87 ms 196144 KB Output is correct
27 Correct 558 ms 447448 KB Output is correct
28 Correct 832 ms 452028 KB Output is correct
29 Correct 633 ms 425556 KB Output is correct
30 Correct 592 ms 451440 KB Output is correct
31 Correct 573 ms 454736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 196176 KB Output is correct
2 Correct 85 ms 196108 KB Output is correct
3 Correct 86 ms 196176 KB Output is correct
4 Correct 90 ms 154832 KB Output is correct
5 Correct 94 ms 155024 KB Output is correct
6 Correct 92 ms 155088 KB Output is correct
7 Correct 83 ms 154060 KB Output is correct
8 Correct 81 ms 152532 KB Output is correct
9 Correct 85 ms 196224 KB Output is correct
10 Correct 85 ms 196224 KB Output is correct
11 Correct 88 ms 196176 KB Output is correct
12 Correct 85 ms 196176 KB Output is correct
13 Correct 83 ms 196140 KB Output is correct
14 Correct 80 ms 196176 KB Output is correct
15 Correct 96 ms 196176 KB Output is correct
16 Correct 92 ms 196180 KB Output is correct
17 Correct 85 ms 196152 KB Output is correct
18 Correct 84 ms 196180 KB Output is correct
19 Correct 92 ms 200876 KB Output is correct
20 Correct 93 ms 200964 KB Output is correct
21 Correct 92 ms 201296 KB Output is correct
22 Correct 91 ms 201048 KB Output is correct
23 Correct 90 ms 200788 KB Output is correct
24 Correct 598 ms 427092 KB Output is correct
25 Correct 803 ms 448728 KB Output is correct
26 Correct 625 ms 438892 KB Output is correct
27 Correct 715 ms 433492 KB Output is correct
28 Correct 583 ms 425556 KB Output is correct
29 Correct 567 ms 451408 KB Output is correct
30 Correct 497 ms 436228 KB Output is correct
31 Correct 682 ms 455668 KB Output is correct
32 Correct 574 ms 449796 KB Output is correct
33 Correct 90 ms 196176 KB Output is correct
34 Correct 87 ms 196144 KB Output is correct
35 Correct 558 ms 447448 KB Output is correct
36 Correct 832 ms 452028 KB Output is correct
37 Correct 633 ms 425556 KB Output is correct
38 Correct 592 ms 451440 KB Output is correct
39 Correct 573 ms 454736 KB Output is correct
40 Incorrect 94 ms 155088 KB Output isn't correct
41 Halted 0 ms 0 KB -