제출 #807244

#제출 시각아이디문제언어결과실행 시간메모리
807244Andrey기지국 (IOI20_stations)C++14
100 / 100
838 ms1280 KiB
#include "stations.h"
#include<bits/stdc++.h>
using namespace std;

vector<int> yay(0);
vector<int> haha[10001];
vector<int> st(10001);

void dfs(int a, int t) {
    st[a] = 1;
    for(int i = 0; i < haha[a].size(); i++) {
        if(haha[a][i] != t) {
            dfs(haha[a][i],a);
            st[a]+=st[haha[a][i]];
        }
    }
}

void dude(int a, int t, int d, int l, int r) {
    if(d%2) {
        yay[a] = r;
        r--;
    }
    else {
        yay[a] = l;
        l++;
    }
    for(int i = 0; i < haha[a].size(); i++) {
        if(haha[a][i] != t) {
            dude(haha[a][i],a,d+1,l,l+st[haha[a][i]]-1);
            l+=st[haha[a][i]];
        }
    }
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
    for(int i = 0; i < n; i++) {
        haha[i].clear();
    }
    for(int i = 0; i < n-1; i++) {
        haha[u[i]].push_back(v[i]);
        haha[v[i]].push_back(u[i]);
    }
    yay.clear();
	for(int i = 0; i < n; i++) {
        yay.push_back(0);
	}
	vector<int> ans(0);
	dfs(0,-1);
	dude(0,-1,0,0,n-1);
	for(int i = 0; i < n; i++) {
        ans.push_back(yay[i]);
	}
    return ans;
}

int find_next_station(int s, int t, vector<int> c) {
    if(c.size() == 1) {
        return c[0];
    }
    if(s >= c[0]) {
        s%=1000;
        if(t > s) {
            return c[0];
        }
        if(t < c[1]) {
            return c[0];
        }
        for(int i = 1; i < c.size(); i++) {
            if(t >= c[i] && (i == c.size()-1 || t < c[i+1])) {
                return c[i];
            }
        }
    }
    else {
        if(s == 0) {
            for(int i = 0; i < c.size(); i++) {
                if(c[i] >= t) {
                    return c[i];
                }
            }
        }
        else {
            if(t < s) {
                return c[c.size()-1];
            }
            if(t > c[c.size()-2]) {
                return c[c.size()-1];
            }
            for(int i = 0; i < c.size()-1; i++) {
                if(c[i] >= t) {
                    return c[i];
                }
            }
        }
        return -1;
    }
}

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

stations.cpp: In function 'void dfs(int, int)':
stations.cpp:11:22: 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 < haha[a].size(); i++) {
      |                    ~~^~~~~~~~~~~~~~~~
stations.cpp: In function 'void dude(int, int, int, int, int)':
stations.cpp:28:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for(int i = 0; i < haha[a].size(); i++) {
      |                    ~~^~~~~~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:69:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |         for(int i = 1; i < c.size(); i++) {
      |                        ~~^~~~~~~~~~
stations.cpp:70:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |             if(t >= c[i] && (i == c.size()-1 || t < c[i+1])) {
      |                              ~~^~~~~~~~~~~~~
stations.cpp:77:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |             for(int i = 0; i < c.size(); i++) {
      |                            ~~^~~~~~~~~~
stations.cpp:90:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |             for(int i = 0; i < c.size()-1; i++) {
      |                            ~~^~~~~~~~~~~~
stations.cpp:98:1: warning: control reaches end of non-void function [-Wreturn-type]
   98 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...