Submission #583164

#TimeUsernameProblemLanguageResultExecution timeMemory
583164LucaIlieStations (IOI20_stations)C++17
0 / 100
933 ms852 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 * 2;
    l++;
    for ( int v: edges[u] ) {
        if ( v != p )
            dfs( v, u, 1 - d );
    }
    if ( d == 1 )
        labels[u] = l * 2 + 1;
    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;
    s /= 2;
    t /= 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() / 2 + 1;
        for ( i = 0; i < c.size(); i++ )
            rc[i] = c[i] / 2;
        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() / 2 - 1;
        rs = s;
        for ( i = 0; i < c.size(); i++ )
            lc[i] = c[i] / 2;
        //for ( i = 0; i < c.size() - 1; 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:51:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |         for ( i = 0; i < e.size() - 1; i++ )
      |                      ~~^~~~~~~~~~~~~~
stations.cpp:55:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         for ( i = 0; i < c.size(); i++ )
      |                      ~~^~~~~~~~~~
stations.cpp:58:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |         for ( i = 1; i < c.size(); i++ )
      |                      ~~^~~~~~~~~~
stations.cpp:62:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |         for ( i = 1; i < e.size(); i++ )
      |                      ~~^~~~~~~~~~
stations.cpp:66:24: 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 < c.size(); i++ )
      |                      ~~^~~~~~~~~~
stations.cpp:73:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |     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...