답안 #1033500

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1033500 2024-07-25T00:14:03 Z ArthuroWich 악어의 지하 도시 (IOI11_crocodile) C++11
컴파일 오류
0 ms 0 KB
#include "crocodile.h"
#include <set>
#include <vector>
#include <cstring>
#include <cstdio>
#include <algorithm>
 
using namespace std;
 
#define MAX_N 100000
 
#define trav(it, cont) for(typeof(cont.begin()) it = cont.begin(); it != cont.end(); it++)
 
typedef pair<int, int> pii;
vector<vector<pii> > adj;
int visited[MAX_N];
int best[MAX_N];
int secondBest[MAX_N];
 
int travel_plan(int N, int M,int R[][2],int L[], int K, int P[]){
  //in case called again - not sure how the IOI judge would do
  adj.clear();
  adj.resize(N);
  memset(visited, 0, sizeof(visited));
  memset(best, -1, sizeof(best));
  memset(secondBest, -1, sizeof(secondBest));
  for(int i = 0; i<M; i++){
    int t = R[i][0];
    int f = R[i][1];
    adj[t].push_back(pii(f, L[i]));
    adj[f].push_back(pii(t, L[i]));
  }
  set<pii> pq;
  for(int i = 0; i<K; i++){
    pq.insert(pii(0, P[i]));
  }
  
  while(!pq.empty()){
    pii v = *(pq.begin());
    pq.erase(pq.begin());
    trav(u, adj[v.second]) {
      pii uu = *u;
      visited[uu.first]++;
      int distance = uu.second + v.first;
      if(visited[uu.first] == 1){
    best[uu.first] = distance;
      } else if(visited[uu.first] == 2){
    int lowest = min(best[uu.first], distance);
    int highest = max(best[uu.first], distance);
    best[uu.first] = lowest;
    secondBest[uu.first] = highest;
    pq.insert(pii(highest, uu.first));
      } else {
    if(distance > secondBest[uu.first]) continue;
    pq.erase(pii(secondBest[uu.first], uu.first));
    int bestX, secondBestX;
    if(distance < best[uu.first]){
      bestX = distance;
      secondBestX = best[uu.first];
    } else {
      bestX = best[uu.first];
      secondBestX = distance;
    }
    best[uu.first] = bestX;
    secondBest[uu.first] = secondBestX;
    pq.insert(pii(secondBestX, uu.first));
      }
    }
  }
  return secondBest[0];
}

Compilation message

crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:12:28: error: 'typeof' was not declared in this scope
   12 | #define trav(it, cont) for(typeof(cont.begin()) it = cont.begin(); it != cont.end(); it++)
      |                            ^~~~~~
crocodile.cpp:41:5: note: in expansion of macro 'trav'
   41 |     trav(u, adj[v.second]) {
      |     ^~~~
crocodile.cpp:41:10: error: 'u' was not declared in this scope
   41 |     trav(u, adj[v.second]) {
      |          ^
crocodile.cpp:12:68: note: in definition of macro 'trav'
   12 | #define trav(it, cont) for(typeof(cont.begin()) it = cont.begin(); it != cont.end(); it++)
      |                                                                    ^~