제출 #1135479

#제출 시각아이디문제언어결과실행 시간메모리
1135479irmuun철로 (IOI14_rail)C++20
컴파일 에러
0 ms0 KiB
#include<bits/stdc++.h>
#include "rail.h"

using namespace std;

#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()

void findLocation(int N, int first, int location[], int stype[]){
    location[0]=first;
    stype[0]=1;
    if(N==1){
        return;
    }
    int dist[N][N];
    for(int i=0;i<N;i++){
        dist[i][i]=0;
        for(int j=i+1;j<N;j++){
            dist[i][j]=getDistance(i,j);
            dist[j][i]=dist[i][j];
        }
    }
    vector<int>g[N];
    vector<pair<int,int>>v;
    for(int i=0;i<N;i++){
        int mn=1e9,idx=-1;
        for(int j=0;j<N;j++){
            if(j==i) continue;
            if(dist[i][j]<mn){
                mn=dist[i][j];
                idx=j;
            }
        }
        g[i].pb(idx);
        g[idx].pb(i);
        v.pb({i,idx});
        //cout<<"PAIR "<<i<<' '<<idx<<endl;
    }
    int D=-1;
    for(auto p:v){
    	int x=p.ff,y=p.ss;
        if(x==0||y==0){
            if(x==0){
                D=y;
            }
            if(x==0) swap(x,y);
            location[x]=first+dist[x][y];
            stype[x]=2;
        }
    }
    vector<bool>used(N,false);
    queue<int>q;
    q.push(0);
    used[0]=true;
    while(!q.empty()){
        int x=q.front();
        q.pop();
        //cout<<"FOUND "<<x<<' '<<stype[x]<<endl;
        for(int y:g[x]){
            if(!used[y]){
                used[y]=true;
                if(stype[x]==1){
                    location[y]=location[x]+dist[x][y];
                    stype[y]=2;
                }
                else{
                    location[y]=location[x]-dist[x][y];
                    stype[y]=1;
                }
                q.push(y);
            }
        }
    }
    vector<array<int,3>>V;
    for(int i=0;i<v.size();i++){
    	if(used[v[i].ff]||used[v[i].ss]){
    		continue;
    	}
    	V.pb({dist[v[i].ff][v[i].ss],i,j});
    }
    sort(all(V));
    for(auto p:v){
    	int x=p[1],y=p[2];
    	if(used[x]){
    		stype[y]=3-stype[x];
    		if(stype[x]==1){
    			location[y]=location[x]+dist[x][y];
    		}
    		else{
				location[y]=location[x]-dist[x][y];
    		}
    		continue;
    	}
    	if(used[y]){
			stype[x]=3-stype[y];
    		if(stype[y]==1){
    			location[x]=location[y]+dist[x][y];
    		}
    		else{
				location[x]=location[y]-dist[x][y];
    		}
    		continue;
    	}
        if(dist[x][0]==dist[x][D]+dist[D][0]){//Left
            if(dist[x][D]>dist[y][D]){
                swap(x,y);//x then y
            }
            location[x]=location[D]-dist[D][x];
            location[y]=location[x]+dist[x][y];
            stype[x]=1;
            stype[y]=2;
        }
        else{//Right
            if(dist[x][0]>dist[y][0]){
                swap(x,y);//y then x
            }
            location[x]=location[0]+dist[0][x];
            location[y]=location[x]-dist[x][y];
            stype[x]=2;
            stype[y]=1;
        }
    }
}

컴파일 시 표준 에러 (stderr) 메시지

rail.cpp: In function 'void findLocation(int, int, int*, int*)':
rail.cpp:83:40: error: 'j' was not declared in this scope
   83 |         V.pb({dist[v[i].ff][v[i].ss],i,j});
      |                                        ^
rail.cpp:83:13: error: no matching function for call to 'std::vector<std::array<int, 3> >::push_back(<brace-enclosed initializer list>)'
   83 |         V.pb({dist[v[i].ff][v[i].ss],i,j});
      |         ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/vector:67,
                 from /usr/include/c++/11/functional:62,
                 from /usr/include/c++/11/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/11/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 from rail.cpp:1:
/usr/include/c++/11/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::array<int, 3>; _Alloc = std::allocator<std::array<int, 3> >; std::vector<_Tp, _Alloc>::value_type = std::array<int, 3>]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/11/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const std::array<int, 3>&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/11/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::array<int, 3>; _Alloc = std::allocator<std::array<int, 3> >; std::vector<_Tp, _Alloc>::value_type = std::array<int, 3>]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/11/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::array<int, 3> >::value_type&&' {aka 'std::array<int, 3>&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
rail.cpp:87:16: error: no match for 'operator[]' (operand types are 'std::pair<int, int>' and 'int')
   87 |         int x=p[1],y=p[2];
      |                ^
rail.cpp:89:23: error: 'y' was not declared in this scope
   89 |                 stype[y]=3-stype[x];
      |                       ^
rail.cpp:98:17: error: 'y' was not declared in this scope
   98 |         if(used[y]){
      |                 ^
rail.cpp:109:32: error: 'y' was not declared in this scope
  109 |             if(dist[x][D]>dist[y][D]){
      |                                ^
rail.cpp:113:22: error: 'y' was not declared in this scope
  113 |             location[y]=location[x]+dist[x][y];
      |                      ^
rail.cpp:118:32: error: 'y' was not declared in this scope
  118 |             if(dist[x][0]>dist[y][0]){
      |                                ^
rail.cpp:122:22: error: 'y' was not declared in this scope
  122 |             location[y]=location[x]-dist[x][y];
      |                      ^