답안 #307638

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
307638 2020-09-28T22:03:31 Z giorgikob 기지국 (IOI20_stations) C++14
0 / 100
919 ms 1040 KB
#include "stations.h"
#include <vector>
#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
using namespace std;

const int N = 1e3+5;

vector<int>gr[N];

int cnt = 0;
int fix[N];
int mn[N];
int in[N], out[N];

void dfs(int x, int h, vector<int>&v){
    fix[x] = 1;
    cnt++;
    in[x] = cnt;
    for(auto to : gr[x]){
        if(fix[to]) continue;
        dfs(to,h+1,v);
    }
    cnt++;
    out[x] = cnt;
    if(h%2){
        v[x] = out[x];
    } else {
        v[x] = in[x];
    }
}

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {

	std::vector<int> labels(n,0);
	for(int i = 0; i < u.size(); i++){
        int x = u[i];
        int y = v[i];
        gr[x].pb(y);
        gr[y].pb(x);
	}

	cnt = 0;
    dfs(0,0,labels);

	for(int i = 0; i < n; i++) gr[i].clear(), fix[i] = 0;

	return labels;
}

int find_next_station(int s, int t, std::vector<int> c) {
    /*cout << "test case" << endl;
    cout << s << " " << t << endl;
    for(auto x : c) cout << x << " "; cout << endl;
    cout << "end of test case" << endl;
    */
    if(c.size() == 1) return c[0];

    if(c[0] < s){
        for(int i = 1; i < c.size(); i++){
            int in = c[i];
            int out = (c[i] == c.back()) ? (s-1) : (c[i+1] - 1);
            if(in <= t && t <= out) return c[i];
        }
        return c.back();
    } else {
        int in = s;
        int out = c.back() - 1;
        if(in > t || t < out) return c.back();
        for(int i = 0; i < c.size() - 1; i++){
            int in = (i == 0) ? (s + 1) : (c[i-1] + 1);
            int out = c[i];
            if(in <= t && t <= out) return c[i];
        }
    }
}

Compilation message

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:39:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |  for(int i = 0; i < u.size(); i++){
      |                 ~~^~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:63:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |         for(int i = 1; i < c.size(); i++){
      |                        ~~^~~~~~~~~~
stations.cpp:73:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |         for(int i = 0; i < c.size() - 1; i++){
      |                        ~~^~~~~~~~~~~~~~
stations.cpp:79:1: warning: control reaches end of non-void function [-Wreturn-type]
   79 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 512 KB Invalid labels (values out of range). scenario=2, k=1000, vertex=1, label=1991
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 384 KB Invalid labels (values out of range). scenario=0, k=1000, vertex=1, label=1023
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 545 ms 1024 KB Wrong query response.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 919 ms 1040 KB Output is correct
2 Incorrect 713 ms 868 KB Wrong query response.
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 599 ms 1024 KB Wrong query response.
2 Halted 0 ms 0 KB -