답안 #413244

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
413244 2021-05-28T11:41:57 Z losmi247 기지국 (IOI20_stations) C++14
0 / 100
1278 ms 528 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1005;

int deg[N];
vector <int> g[N];



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

    for(int i = 0; i < n-1; i++){
        deg[u[i]]++;
        deg[v[i]]++;
        g[u[i]].push_back(v[i]);
        g[v[i]].push_back(u[i]);
    }


    bool prvi = 1;
    for(int i = 0; i < n; i++) if(deg[i] > 2) prvi = 0;
    if(prvi){
        int cnt = 0;
        vector <int> l(n,0);
        queue <pair<int,int>> q;
        for(int i = 0; i < n; i++){
            if(deg[i] == 1){
                q.push({i,-1});
                break;
            }
        }
        while(!q.empty()){
            int u = q.front().first,par = q.front().second;
            l[u] = cnt++;
            q.pop();
            for(auto v : g[u]){
                if(v == par) continue;
                q.push({v,u});
            }
        }
        return l;
    }


    bool drugi = 1;
    for(int i = 0; i < n-1; i++){
        if(u[i] != i+1 || v[i] != i/2) drugi = 0;
    }
    if(drugi){
        vector <int> l(n,0);
        for(int i = 0; i < n; i++) l[i] = i;
        return l;
    }
}

int find_next_station(int s,int t,vector <int> c){
    if((s == 0 && c.size() == 1 && c[0] == 1) || (c.size() == 1 && c[0] == s-2) || (c.size() == 2 && c[0] == s-1 && c[1] == s+1)){
        if(s < t){
            return s+1;
        }
        else{
            return s-1;
        }
    }

    bool drugi = 1;
    for(auto f : c){
        if(f != (s&1 ? s/2 : (s-1)/2) && f != 2*s+1 && f != 2*s+2) drugi = 0;
    }
    if(drugi){
        int nd1 = s,nd2 = t;
        vector <int> putt = {t};
        vector <int> puts = {s};
        while(nd1 != nd2){
            if(nd1 > nd2){ nd1 = (nd1&1 ? nd1/2 : (nd1-1)/2); puts.push_back(nd1); }
            else{ nd2 = (nd2&1 ? nd2/2 : (nd2-1)/2); putt.push_back(nd2); }
        }
        if(nd1 == s){
            return putt[putt.size()-2];
        }
        if(nd1 == t){
            return puts[1];
        }
        return puts[1];
    }
}

Compilation message

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:59:1: warning: control reaches end of non-void function [-Wreturn-type]
   59 | }
      | ^
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:91:1: warning: control reaches end of non-void function [-Wreturn-type]
   91 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 598 ms 504 KB Wrong query response.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 682 ms 520 KB Output is correct
2 Incorrect 672 ms 528 KB Wrong query response.
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 828 ms 528 KB Wrong query response.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1278 ms 400 KB Output is correct
2 Incorrect 942 ms 524 KB Wrong query response.
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 758 ms 528 KB Wrong query response.
2 Halted 0 ms 0 KB -