Submission #367303

# Submission time Handle Problem Language Result Execution time Memory
367303 2021-02-16T20:18:15 Z PurpleCrayon Stations (IOI20_stations) C++17
5 / 100
1123 ms 1236 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;

#define sz(v) int(v.size())

int tt;
vector<int> ans;
vector<vector<int>> adj;

void dfs(int c=0, int p=-1, bool b=0){
    if (!b) ans[c] = tt++;
    for (auto nxt : adj[c]) if (nxt != p) dfs(nxt, c, b^1);
    if (b) ans[c] = tt++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
    ans.assign(n, -1), adj.assign(n, vector<int>()), tt=0;
    for (int i = 0; i < n-1; i++) 
        adj[u[i]].push_back(v[i]), adj[v[i]].push_back(u[i]);
    dfs();
    return ans;
}

int find_next_station(int s, int t, vector<int> c) {
    if (s == 0){ //ans for the root
        for (auto nxt : c) if (nxt >= t) return nxt;
        assert(false);
    }
    bool b=s>c[0];

    if (b){ //i'm postorder
        int p = c[0];
        if (sz(c) == 1 || t < c[1] || t > s)
            return p; 
        
        int ans=-1;
        for (auto nxt : c) if (nxt != p) {
            if (nxt <= t) ans = nxt;
        }
        assert(ans != -1);
        return ans;

    } else { //i'm preorder
        int p = c[sz(c)-1];
        if (sz(c) == 1 || t < s || t >= c[sz(c)-1]) 
            return p;

        int ans=-1;
        for (auto nxt : c) if (nxt != p) {
            if (nxt >= t){
                return nxt;
            }
        }
        assert(false);
    }
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:48:13: warning: unused variable 'ans' [-Wunused-variable]
   48 |         int ans=-1;
      |             ^~~
# Verdict Execution time Memory Grader output
1 Correct 602 ms 864 KB Output is correct
2 Correct 437 ms 884 KB Output is correct
3 Correct 949 ms 756 KB Output is correct
4 Correct 676 ms 884 KB Output is correct
5 Correct 640 ms 736 KB Output is correct
6 Correct 475 ms 884 KB Output is correct
7 Correct 508 ms 884 KB Output is correct
8 Correct 3 ms 736 KB Output is correct
9 Correct 5 ms 868 KB Output is correct
10 Correct 2 ms 876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 1236 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 584 ms 884 KB Output is correct
2 Correct 510 ms 1012 KB Output is correct
3 Correct 1033 ms 756 KB Output is correct
4 Correct 741 ms 756 KB Output is correct
5 Correct 632 ms 744 KB Output is correct
6 Correct 462 ms 884 KB Output is correct
7 Correct 492 ms 864 KB Output is correct
8 Correct 3 ms 756 KB Output is correct
9 Correct 4 ms 884 KB Output is correct
10 Correct 2 ms 876 KB Output is correct
11 Correct 611 ms 756 KB Output is correct
12 Correct 454 ms 1024 KB Output is correct
13 Runtime error 7 ms 1120 KB Execution killed with signal 6
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1003 ms 756 KB Output is correct
2 Correct 807 ms 756 KB Output is correct
3 Correct 696 ms 736 KB Output is correct
4 Correct 3 ms 868 KB Output is correct
5 Correct 4 ms 756 KB Output is correct
6 Correct 2 ms 736 KB Output is correct
7 Correct 680 ms 756 KB Output is correct
8 Correct 915 ms 736 KB Output is correct
9 Correct 795 ms 736 KB Output is correct
10 Correct 667 ms 996 KB Output is correct
11 Runtime error 2 ms 992 KB Execution killed with signal 6
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 649 ms 920 KB Output is correct
2 Correct 525 ms 952 KB Output is correct
3 Correct 1123 ms 864 KB Output is correct
4 Correct 763 ms 756 KB Output is correct
5 Correct 565 ms 756 KB Output is correct
6 Correct 451 ms 864 KB Output is correct
7 Correct 528 ms 1008 KB Output is correct
8 Correct 3 ms 756 KB Output is correct
9 Correct 5 ms 736 KB Output is correct
10 Correct 2 ms 736 KB Output is correct
11 Runtime error 13 ms 992 KB Execution killed with signal 6
12 Halted 0 ms 0 KB -