Submission #583218

#TimeUsernameProblemLanguageResultExecution timeMemory
583218LucaIlieStations (IOI20_stations)C++17
0 / 100
837 ms788 KiB
#include "stations.h"
#include <bits/stdc++.h>

#define MAX_N 1000

using namespace std;

int l;
int lc[MAX_N], rc[MAX_N];
vector<int> edges[MAX_N];
vector<int> labels, c;

void dfs( int u, int p, int d ) {
    if ( d == 0 )
        labels[u] = l;
    l++;
    for ( int v: edges[u] ) {
        if ( v != p )
            dfs( v, u, 1 - d );
    }
    if ( d == 1 )
        labels[u] = l;
    l++;
}

vector<int> label( int n, int k, vector<int> u, vector<int> v ) {
    for ( int i = 0; i < n; i++ )
        edges[i].clear();
    for ( int i = 0; i < n - 1; i++ ) {
        edges[u[i]].push_back( v[i] );
        edges[v[i]].push_back( u[i] );
    }

    labels.resize( n );
    l = 0;
    dfs( 0, -1, 0 );

    return labels;
}

int find_next_station( int s, int t, vector<int> e ) {
    int ls, rs, ds, p, i;

    ds = s % 2;
    p = 0;
    c.clear();
    if ( ds == 0 ) {
        p = e.back();
        for ( i = 0; i < e.size() - 1; i++ )
            c.push_back( e[i] );
        ls = s;
        rs = c.back() + 1;
        for ( i = 0; i < c.size(); i++ )
            rc[i] = c[i];
        lc[0] = ls + 1;
        for ( i = 1; i < c.size(); i++ )
            lc[i] = rc[i - 1] + 1;
    } else {
        p = e.front();
        for ( i = 1; i < e.size(); i++ )
            c.push_back( e[i] );
        ls = c.front() - 1;
        rs = s;
        for ( i = 0; i < c.size(); i++ )
            lc[i] = c[i];
        for ( i = 0; i + 1 < c.size(); i++ )
            rc[i] = lc[i + 1] - 1;
        rc[c.size() - 1] = rs - 1;
    }

    for ( i = 0; i < c.size(); i++ ) {
        if ( lc[i] <= t && t <= rc[i] )
            return c[i];
    }
    return p;
}

Compilation message (stderr)

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:49:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |         for ( i = 0; i < e.size() - 1; i++ )
      |                      ~~^~~~~~~~~~~~~~
stations.cpp:53:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         for ( i = 0; i < c.size(); i++ )
      |                      ~~^~~~~~~~~~
stations.cpp:56:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |         for ( i = 1; i < c.size(); i++ )
      |                      ~~^~~~~~~~~~
stations.cpp:60:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |         for ( i = 1; i < e.size(); i++ )
      |                      ~~^~~~~~~~~~
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(); i++ )
      |                      ~~^~~~~~~~~~
stations.cpp:66:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |         for ( i = 0; i + 1 < c.size(); i++ )
      |                      ~~~~~~^~~~~~~~~~
stations.cpp:71:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |     for ( i = 0; i < c.size(); i++ ) {
      |                  ~~^~~~~~~~~~
#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...