제출 #910883

#제출 시각아이디문제언어결과실행 시간메모리
910883Isaac_Q1Race (IOI11_race)C++14
컴파일 에러
0 ms0 KiB
#include<bits/stdc++.h>
#include<vector>
using namespace std;
vector<int> temp;
int res = INT_MAX;
int h[100][2];
int check()
{
    int ht[100]={0};
    int cnt = 0;
    for(int i=0; i<temp.size(); i++)
    {
        ht[h[i][0]] ++;
        ht[h[i][1]] ++;
        cnt += 2;
        if(ht[h[i][0]] == 2) cnt -= 2;
        else if(ht[h[i][0]] > 2) return 0;
        if(ht[h[i][1]] == 2) cnt -= 2;
        else if(ht[h[i][1]] > 2) return 0;
    }
    if(cnt == 2) return 1;
    return 0;
}
void sub(int a[], int ind, int target, int n)
{
    if(ind >= n) return;
    if(target < 0) return;
    if(target == 0) 
    {
        if(check()){
        int k = temp.size();
        res = min(res, k);
        }
        return;
    } 
    for(int i = ind; i<n; i++) 
    {
        temp.push_back(i);
        target -= a[i];
        sub(a,i+1,target,n);
        target += a[i];
        temp.pop_back();
    }
    return;
}
int main()
{
    int n,k;
    cin >> n >> k;
    int l[n-1];
    for(int i=0; i<n-1; i++) cin >> h[i][0] >> h[i][1];
    for(int i=0; i<n-1; i++) 
    {
        cin >> l[i];
    }
    int u;
    int u1,u2;
    for(int i=0; i<n-2; i++)
    {
        for(int j=i+1; j<n-1; j++)
        {
            if(l[i] > l[j])
            {
                u = l[i];
                l[i] = l[j];
                l[j] = u;

                u1 = h[i][0];
                h[i][0] = h[j][0];
                h[j][0] = u1;

                u2 = h[i][1];
                h[i][1] = h[j][1];
                h[j][1] = u2;
            }
        }
    }
    sub(l,0,k,n-1);
    if(res == INT_MAX) cout << "-1";
    else cout << res;
    return 0;
}

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

race.cpp: In function 'int check()':
race.cpp:11:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for(int i=0; i<temp.size(); i++)
      |                  ~^~~~~~~~~~~~
/usr/bin/ld: /tmp/ccOU4J8s.o: in function `main':
race.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccNJ84Rq.o:grader.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccNJ84Rq.o: in function `main':
grader.cpp:(.text.startup+0x28): undefined reference to `best_path(int, int, int (*) [2], int*)'
collect2: error: ld returned 1 exit status