답안 #625348

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
625348 2022-08-10T05:48:08 Z EthanKim8683 악어의 지하 도시 (IOI11_crocodile) C++17
0 / 100
8 ms 9320 KB
#include<vector>
#include<algorithm>
#include<queue>

using namespace std;

using I=int;
using B=bool;
using Lli=long long int;

// dijkstra's from all exits
// only push nodes once reachable from two exits

const I N=100000;
const I M=1000000;
const I K=999999;
const I MAX=1e9;

vector<pair<I,I>>adjs[N];
B exis[N];
I viss[N];
Lli diss[N][2];
priority_queue<pair<Lli,I>,vector<pair<Lli,I>>,greater<pair<Lli,I>>>que;

void add(Lli dis,I a){
  viss[a]++;
  if(dis<diss[a][0]){
    diss[a][1]=diss[a][0];
    diss[a][0]=dis;
    if(viss[a]>=2)que.push({diss[a][1],a});
  }else if(dis<diss[a][1]){
    diss[a][1]=dis;
    if(viss[a]>=2)que.push({diss[a][1],a});
  }
}

I travel_plan(I n,I m,I r[][2],I l[],I k,I p[]){
  fill(&diss[0][0],&diss[0][0]+sizeof(diss)/sizeof(I),MAX);
  for(I i=0;i<m;i++){
    I a=r[i][0],b=r[i][1],d=l[i];
    adjs[a].push_back({b,d});
    adjs[b].push_back({a,d});
  }
  for(I i=0;i<k;i++)que.push({diss[p[i]][0]=diss[p[i]][1]=0,p[i]});
  while(!que.empty()){
    auto[dis,a]=que.top();
    que.pop();
    for(auto[b,d]:adjs[a])add(dis+d,b);
  }
  return diss[0][1];
}

#ifdef ETHANKIM8683
#include<iostream>
#include<cstdio>

I main(){
  cin.tie(0)->sync_with_stdio(0);
  I n,m;
  cin>>n>>m;
  static I r[M][2];
  for(I i=0;i<m;i++)cin>>r[i][0]>>r[i][1];
  static I l[M];
  for(I i=0;i<m;i++)cin>>l[i];
  I k;
  cin>>k;
  static I p[K];
  for(I i=0;i<k;i++)cin>>p[i];
  printf("%i\n",travel_plan(n,m,r,l,k,p));
  return 0;
}
#endif

Compilation message

crocodile.cpp: In function 'I travel_plan(I, I, I (*)[2], I*, I, I*)':
crocodile.cpp:38:7: warning: array subscript 400000 is outside array bounds of 'Lli [100000][2]' {aka 'long long int [100000][2]'} [-Warray-bounds]
   38 |   fill(&diss[0][0],&diss[0][0]+sizeof(diss)/sizeof(I),MAX);
      |   ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
crocodile.cpp:22:5: note: while referencing 'diss'
   22 | Lli diss[N][2];
      |     ^~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 9320 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 9320 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 9320 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -