답안 #319709

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
319709 2020-11-06T08:46:39 Z alextodoran 기지국 (IOI20_stations) C++17
0 / 100
3000 ms 2097156 KB
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>
#include "stations.h"

using namespace std;

const int N_MAX = 1002;

vector <int> edges[N_MAX];

int sub[N_MAX];

void dfs (int u, int parent = -1)
{
    sub[u] = 1;
    for(int v : edges[u])
        if(v != parent)
        {
            dfs(v, u);
            sub[u] += sub[v];
        }
}

int lb[N_MAX];

void solve (int u, int l, int r, bool type, int parent = -1)
{
    if(type == 0)
        lb[u] = l++;
    else
        lb[u] = r--;
    for(int v : edges[u])
        if(v != parent)
        {
            solve(v, l, l + sub[v] - 1, !type, u);
            l += sub[v];
        }
}

vector <int> label (int n, int k, vector <int> u, vector <int> v)
{
    for(int i = 1; i < n; i++)
    {
        int a = u[i - 1] + 1;
        int b = v[i - 1] + 1;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    dfs(1);
    solve(1, 1, n, 0);
	vector <int> labels(n);
    for(int i = 1; i <= n; i++)
        labels[i - 1] = lb[i] - 1;
	return labels;
}

int find_next_station (int s, int t, vector <int> c)
{
    bool type = 1;
    for(int u : c)
        type &= (u < s);
    if(type == 0)
    {
        sort(c.begin(), c.end());
        int root = c.back();
        c.pop_back();
        int l = s + 1;
        for(int u : c)
        {
            if(l <= t && t <= u)
                return u;
            l = u + 1;
        }
        return root;
    }
    else
    {
        sort(c.begin(), c.end());
        reverse(c.begin(), c.end());
        int root = c.back();
        c.pop_back();
        int r = s - 1;
        for(int u : c)
        {
            if(u <= t && t <= r)
                return u;
            r = u - 1;
        }
        return root;
    }
}

Compilation message

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:59:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   59 |     for(int i = 1; i <= n; i++)
      |     ^~~
stations.cpp:61:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   61 |  return labels;
      |  ^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1291 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 3060 ms 484 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1377 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 889 ms 864 KB Output is correct
2 Runtime error 1132 ms 2097156 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2177 ms 2097156 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -