답안 #468368

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
468368 2021-08-27T21:18:46 Z kessido 기지국 (IOI20_stations) C++17
0 / 100
1049 ms 612 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define vll vector<ll>
#define vi vector<int>
#define vvi vector<vi>
#define pi pair<int, int>
#define pll pair<ll, ll>
#define all(x) (x).begin(), (x).end()
#define fori(i,n) for(int i = 0; i < int(n); ++i)

vi label(int n, int k, vi u, vi v) {
    vvi e(n);
    fori(i,n-1){
        e[u[i]].push_back(v[i]);
        e[v[i]].push_back(u[i]);
    }
    int cur_label = 0;
    vi res(n, -1);
    auto dfs = [&](auto& self, int i, int parent, int depth) -> void {
        if(depth) res[i] = cur_label++;
        for(int j : e[i]) {
            if(j==parent) continue;
            self(self, j, i, depth^1);
        }
        if(!depth) res[i] = cur_label++;
    };
    dfs(dfs, 0, -1, 1);
    assert(res[0] == 0);
    assert(cur_label==n);
    return res;
}

int find_next_station(int s, int t, vi c) {
    if(c.size() == 1) return c[0];
    if(s==t) return s;

    sort(all(c));

    if(s == 0) {
        // root
        int i = 0;
        while(i + 1 < c.size() && c[i + 1] >= t) i++;
        return c[i];
    }

    if(c.back() < s) {
        // case 1, s "end"
        if(t > s || t < *c.begin()) return *c.begin();
        int i = 1;
        while(i < c.size() && c[i] >= t) i++;
        return c[i-1];
    }else{
        // case 2, s is "start"
        if(t < s || c[c.size()-2] < t) return c.back();
        int i = 0;
        while(i + 2 < c.size() && c[i + 1] >= t) i++;
        return c[i];
    }
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:45:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |         while(i + 1 < c.size() && c[i + 1] >= t) i++;
      |               ~~~~~~^~~~~~~~~~
stations.cpp:53:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         while(i < c.size() && c[i] >= t) i++;
      |               ~~^~~~~~~~~~
stations.cpp:59:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |         while(i + 2 < c.size() && c[i + 1] >= t) i++;
      |               ~~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 703 ms 528 KB Wrong query response.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 474 ms 528 KB Wrong query response.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 532 ms 520 KB Wrong query response.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1049 ms 464 KB Output is correct
2 Incorrect 736 ms 612 KB Wrong query response.
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 600 ms 528 KB Wrong query response.
2 Halted 0 ms 0 KB -