답안 #1117770

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1117770 2024-11-24T08:15:13 Z ntdaccode Passport (JOI23_passport) C++17
100 / 100
738 ms 87580 KB
#include<bits/stdc++.h>
#define fori(i,a,b) for(int i=a;i<=b;i++)
#define ll long long
#define ii pair<int,int>
#define fi first
#define se second
#define pb push_back
using namespace std;
const int mod=1e9+7;
const int M=2e5+10;
const int N=1e3+10;
int n,q;
//
int pos[M];
vector<ii> ke[4*M];
void build(int s,int l,int r)
{
  if(l==r)
  {
    pos[l]=s;
    return ;
  }
  int mid=(l+r)/2;
  build(s*2,l,mid);
  build(s*2+1,mid+1,r);
  ke[s*2].pb({s,0});
  ke[s*2+1].pb({s,0});
}
void upd(int s,int l,int r,int u,int v,int p)
{
  if(l>v||r<u) return ;
  if(u<=l&&r<=v)
  {
    ke[s].pb({p,1});
    return ;
  }
  int mid=(l+r)/2;
  upd(s*2,l,mid,u,v,p);
  upd(s*2+1,mid+1,r,u,v,p);
}
int d[4*M],f[4*M];
priority_queue<ii,vector<ii>,greater<ii> > h;
void dij()
{
  while(!h.empty())
  {
    ii u=h.top();h.pop();
    if(d[u.se]>u.fi) continue;
    for(ii v : ke[u.se])
    {
      if(d[v.fi]>u.fi+v.se)
      {
        d[v.fi]=u.fi+v.se;
        h.push({d[v.fi],v.fi});
      }
    }
  }
}
int32_t main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  #define task "1"
  if(fopen(task".inp","r"))
  {
    freopen(task".inp","r",stdin);
    freopen(task".out","w",stdout);
  }
  cin >> n;
  build(1,1,n);
  fori(i,1,n)
  {
    int l,r;
    cin >> l >> r;
    upd(1,1,n,l,r,pos[i]);
  }
  fori(i,1,4*n) d[i]=1e9;
  d[pos[1]]=0;
  h.push({0,pos[1]});
  dij();
  fori(i,1,4*n) f[i]=d[i];
  fori(i,1,4*n) d[i]=1e9;
  d[pos[n]]=0;
  h.push({0,pos[n]});
  dij();
  fori(i,1,4*n) f[i]+=d[i];
  fori(i,2,n-1) f[pos[i]]--;
  fori(i,1,4*n)
  {
    h.push({f[i],i});
    d[i]=f[i];
  }
  dij();
  cin >> q;
  while(q--)
  {
    int p;
    cin >> p;
    if(d[pos[p]]<1e8)cout << d[pos[p]]<< "\n";
    else cout << -1 << "\n";
  }
}

Compilation message

passport.cpp: In function 'int32_t main()':
passport.cpp:67:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |     freopen(task".inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
passport.cpp:68:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |     freopen(task".out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 23120 KB Output is correct
2 Correct 4 ms 23120 KB Output is correct
3 Correct 5 ms 23120 KB Output is correct
4 Correct 696 ms 79904 KB Output is correct
5 Correct 325 ms 59832 KB Output is correct
6 Correct 170 ms 54716 KB Output is correct
7 Correct 212 ms 52532 KB Output is correct
8 Correct 188 ms 59300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 23120 KB Output is correct
2 Correct 4 ms 23120 KB Output is correct
3 Correct 4 ms 23120 KB Output is correct
4 Correct 5 ms 23120 KB Output is correct
5 Correct 4 ms 23120 KB Output is correct
6 Correct 4 ms 23132 KB Output is correct
7 Correct 4 ms 23288 KB Output is correct
8 Correct 5 ms 23120 KB Output is correct
9 Correct 4 ms 23120 KB Output is correct
10 Correct 4 ms 23288 KB Output is correct
11 Correct 5 ms 23132 KB Output is correct
12 Correct 4 ms 23120 KB Output is correct
13 Correct 5 ms 23376 KB Output is correct
14 Correct 5 ms 23368 KB Output is correct
15 Correct 5 ms 23248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 23120 KB Output is correct
2 Correct 4 ms 23120 KB Output is correct
3 Correct 4 ms 23120 KB Output is correct
4 Correct 5 ms 23120 KB Output is correct
5 Correct 4 ms 23120 KB Output is correct
6 Correct 4 ms 23132 KB Output is correct
7 Correct 4 ms 23288 KB Output is correct
8 Correct 5 ms 23120 KB Output is correct
9 Correct 4 ms 23120 KB Output is correct
10 Correct 4 ms 23288 KB Output is correct
11 Correct 5 ms 23132 KB Output is correct
12 Correct 4 ms 23120 KB Output is correct
13 Correct 5 ms 23376 KB Output is correct
14 Correct 5 ms 23368 KB Output is correct
15 Correct 5 ms 23248 KB Output is correct
16 Correct 8 ms 23764 KB Output is correct
17 Correct 9 ms 23748 KB Output is correct
18 Correct 11 ms 23888 KB Output is correct
19 Correct 9 ms 24056 KB Output is correct
20 Correct 6 ms 23632 KB Output is correct
21 Correct 7 ms 23740 KB Output is correct
22 Correct 6 ms 23632 KB Output is correct
23 Correct 8 ms 23632 KB Output is correct
24 Correct 8 ms 23888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 23120 KB Output is correct
2 Correct 4 ms 23120 KB Output is correct
3 Correct 4 ms 23120 KB Output is correct
4 Correct 5 ms 23120 KB Output is correct
5 Correct 4 ms 23120 KB Output is correct
6 Correct 4 ms 23132 KB Output is correct
7 Correct 4 ms 23288 KB Output is correct
8 Correct 5 ms 23120 KB Output is correct
9 Correct 4 ms 23120 KB Output is correct
10 Correct 4 ms 23288 KB Output is correct
11 Correct 5 ms 23132 KB Output is correct
12 Correct 4 ms 23120 KB Output is correct
13 Correct 5 ms 23376 KB Output is correct
14 Correct 5 ms 23368 KB Output is correct
15 Correct 5 ms 23248 KB Output is correct
16 Correct 8 ms 23764 KB Output is correct
17 Correct 9 ms 23748 KB Output is correct
18 Correct 11 ms 23888 KB Output is correct
19 Correct 9 ms 24056 KB Output is correct
20 Correct 6 ms 23632 KB Output is correct
21 Correct 7 ms 23740 KB Output is correct
22 Correct 6 ms 23632 KB Output is correct
23 Correct 8 ms 23632 KB Output is correct
24 Correct 8 ms 23888 KB Output is correct
25 Correct 8 ms 23288 KB Output is correct
26 Correct 4 ms 23120 KB Output is correct
27 Correct 8 ms 23888 KB Output is correct
28 Correct 7 ms 23632 KB Output is correct
29 Correct 7 ms 23632 KB Output is correct
30 Correct 7 ms 23632 KB Output is correct
31 Correct 7 ms 23632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 23120 KB Output is correct
2 Correct 4 ms 23120 KB Output is correct
3 Correct 5 ms 23120 KB Output is correct
4 Correct 696 ms 79904 KB Output is correct
5 Correct 325 ms 59832 KB Output is correct
6 Correct 170 ms 54716 KB Output is correct
7 Correct 212 ms 52532 KB Output is correct
8 Correct 188 ms 59300 KB Output is correct
9 Correct 4 ms 23120 KB Output is correct
10 Correct 4 ms 23120 KB Output is correct
11 Correct 4 ms 23120 KB Output is correct
12 Correct 5 ms 23120 KB Output is correct
13 Correct 4 ms 23120 KB Output is correct
14 Correct 4 ms 23132 KB Output is correct
15 Correct 4 ms 23288 KB Output is correct
16 Correct 5 ms 23120 KB Output is correct
17 Correct 4 ms 23120 KB Output is correct
18 Correct 4 ms 23288 KB Output is correct
19 Correct 5 ms 23132 KB Output is correct
20 Correct 4 ms 23120 KB Output is correct
21 Correct 5 ms 23376 KB Output is correct
22 Correct 5 ms 23368 KB Output is correct
23 Correct 5 ms 23248 KB Output is correct
24 Correct 8 ms 23764 KB Output is correct
25 Correct 9 ms 23748 KB Output is correct
26 Correct 11 ms 23888 KB Output is correct
27 Correct 9 ms 24056 KB Output is correct
28 Correct 6 ms 23632 KB Output is correct
29 Correct 7 ms 23740 KB Output is correct
30 Correct 6 ms 23632 KB Output is correct
31 Correct 8 ms 23632 KB Output is correct
32 Correct 8 ms 23888 KB Output is correct
33 Correct 8 ms 23288 KB Output is correct
34 Correct 4 ms 23120 KB Output is correct
35 Correct 8 ms 23888 KB Output is correct
36 Correct 7 ms 23632 KB Output is correct
37 Correct 7 ms 23632 KB Output is correct
38 Correct 7 ms 23632 KB Output is correct
39 Correct 7 ms 23632 KB Output is correct
40 Correct 738 ms 80284 KB Output is correct
41 Correct 358 ms 60528 KB Output is correct
42 Correct 455 ms 87580 KB Output is correct
43 Correct 459 ms 87316 KB Output is correct
44 Correct 198 ms 55212 KB Output is correct
45 Correct 280 ms 62512 KB Output is correct
46 Correct 122 ms 40632 KB Output is correct
47 Correct 371 ms 63128 KB Output is correct
48 Correct 310 ms 70620 KB Output is correct