Submission #468375

# Submission time Handle Problem Language Result Execution time Memory
468375 2021-08-27T21:38:32 Z kessido Stations (IOI20_stations) C++17
0 / 100
1091 ms 596 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));

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

}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:45:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |         while(i < c.size() && c[i] < t) i++;
      |               ~~^~~~~~~~~~
stations.cpp:49:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |         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:55:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   55 |     if(c.size() <= i) return c.front();
      |        ~~~~~~~~~^~~~
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from stations.cpp:2:
stations.cpp:56:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |     assert(i < c.size());
      |            ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 668 ms 480 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 529 ms 520 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 575 ms 500 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1091 ms 400 KB Output is correct
2 Correct 659 ms 560 KB Output is correct
3 Correct 640 ms 400 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Incorrect 5 ms 468 KB Wrong query response.
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 537 ms 596 KB Wrong query response.
2 Halted 0 ms 0 KB -