답안 #306829

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
306829 2020-09-26T10:39:06 Z Ruxandra985 기지국 (IOI20_stations) C++14
0 / 100
3000 ms 2097156 KB
#include <bits/stdc++.h>
#include "stations.h"
#define DIMN 1010

using namespace std;
int poz;
int lab[DIMN] , last[DIMN] , niv[DIMN];
vector <int> ww[DIMN];
void dfs (int nod , int tt , int lvl){
    int i , vecin;

    if (lvl % 2 == 0)
        poz++;

    lab[nod] = poz;

    niv[nod] = lvl;

    for (i = 0 ; i < ww[nod].size() ; i++){
        vecin = ww[nod][i];
        if (vecin != tt){
            dfs (vecin , nod , lvl + 1);

        }
    }

    if (lvl % 2 == 1)
        poz++;

    last[nod] = poz;

    //label[vv] = poz; /// vv e ultimul vecin valid deci el e schimbat in last poz
    ///// in loc de first poz


}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	vector<int> labels;
	for (int i = 0; i < u.size(); i++) {
		ww[u[i]].push_back(v[i]);
		ww[v[i]].push_back(u[i]);
	}
	poz = 1;
	dfs (0 , -1 , 0);

	for (int i = 0 ; i < n ; i++){
        if (niv[i] % 2 == 0)
            labels.push_back(lab[i]);
        else labels.push_back(last[i]);
	}

	return labels;
}

int find_next_station(int s, int t, vector<int> c) {
	int i;

	if (c.size() == 1)
        return c[0];

	if (s == 1){ /// incep din 0, e nivel par oricum

        for (i = 0 ; i <= c.size() - 1 ; i++){

            if (c[i] < t && t <= c[i + 1])
                return c[i + 1];

        }

        return c[0];

	}
	else { /// unul dintre vecini e clar tatal

        if (s < c[0]){ /// s e un nivel par
            if (s <= t && t <= c[0])
                return c[0];
            for (i = 0 ; i <= c.size() - 2 ; i++){

                if (c[i] < t && t <= c[i + 1])
                    return c[i + 1];

            }

            return c.back();
        }
        else { /// s e un nivel impar
            for (i = 1 ; i <= c.size() - 1 ; i++){

                if (c[i] <= t && t < c[i + 1])
                    return c[i];

            }

            if (t >= c.back() && t < s)
                return c.back();
            return c[0];
        }

	}

}

Compilation message

stations.cpp: In function 'void dfs(int, int, int)':
stations.cpp:19:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for (i = 0 ; i < ww[nod].size() ; i++){
      |                  ~~^~~~~~~~~~~~~~~~
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:40:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |  for (int i = 0; i < u.size(); i++) {
      |                  ~~^~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:64:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |         for (i = 0 ; i <= c.size() - 1 ; i++){
      |                      ~~^~~~~~~~~~~~~~~
stations.cpp:79:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |             for (i = 0 ; i <= c.size() - 2 ; i++){
      |                          ~~^~~~~~~~~~~~~~~
stations.cpp:89:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |             for (i = 1 ; i <= c.size() - 1 ; i++){
      |                          ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1430 ms 2097156 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3048 ms 628 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1447 ms 2097156 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 880 ms 876 KB Output is correct
2 Runtime error 1211 ms 2097152 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2417 ms 2097152 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -