# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1067324 |
2024-08-20T14:49:48 Z |
Lalic |
Stations (IOI20_stations) |
C++17 |
|
1748 ms |
2097152 KB |
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(). x.rend()
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef complex<double> cd;
vector<int> adj[1005];
int submin[1005], submax[1005];
const int INF = 0x3f3f3f3f;
void build(int ver, int prev, vector<int>& labels, bool isMax, int& cnt){
if(prev!=-1 && (int)adj[ver].size()==1){
labels[ver]=cnt;
submin[ver]=submax[ver]=cnt;
cnt++;
return;
}
int mx=-INF, mn=INF;
for(auto u : adj[ver]){
if(u==prev) continue;
build(u, ver, labels, !isMax, cnt);
mx=max(mx, submax[u]);
mn=min(mn, submin[u]);
}
if(isMax){
labels[ver]=submax[ver]=mx+1;
if(mx+1>=cnt) cnt=mx+2;
}
else
labels[ver]=submin[ver]=mn-1;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
vector<int> labels(n);
for(int i=0;i<n-1;i++){
adj[u[i]].pb(v[i]);
adj[v[i]].pb(u[i]);
}
int aux=0;
build(1, -1, labels, 0, aux);
vector<pii> proc;
for(int i=0;i<n;i++) proc.pb({labels[i], i});
sort(all(proc));
for(int i=0;i<n;i++) labels[proc[i].se]=i;
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
sort(all(c));
if(c[0]<s){
if(t>s || t<c[1]) return c[0];
for(int i=(int)c.size()-1;i>=0;i--)
if(t>=c[i]) return c[i];
}
else{
reverse(all(c));
if(t<s || t>c[1]) return c[0];
for(int i=(int)c.size()-1;i>=0;i--)
if(t<=c[i]) return c[i];
}
return -1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1352 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
600 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1237 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
634 ms |
684 KB |
Output is correct |
2 |
Runtime error |
1108 ms |
2097152 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1748 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |