#include "stations.h"
/*
Author of all code: Pedro BIGMAN Dias
Last edit: 15/02/2021
*/
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <list>
#include <iomanip>
#include <stdlib.h>
#include <time.h>
#include <cstring>
using namespace std;
typedef int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define REP(i,a,b) for(ll i=(ll) a; i<(ll) b; i++)
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define ff first
#define ss second
#define whole(x) x.begin(),x.end()
#define DEBUG(i) cout<<"Pedro Is The Master "<<i<<endl
#define INF 500000000LL
#define EPS 0.00000001
#define pi 3.14159
ll mod=1000000007LL;
template<class A=ll>
void Out(vector<A> a) {REP(i,0,a.size()) {cout<<a[i]<<" ";} cout<<endl;}
template<class A=ll>
void In(vector<A> &a, ll N) {A cur; REP(i,0,N) {cin>>cur; a.pb(cur);}}
class Tree
{
public:
ll N;
vector<ll> p;
vector<vector<ll> > sons;
vector<vector<ll> > adj;
ll root;
vector<bool> visited;
vector<ll> DFSarr1; //DFS Array
vector<pl> pos;
Tree(vector<vector<ll> > ad, ll r=0LL)
{
N=ad.size(); root=r; adj=ad;
REP(i,0,N) {visited.pb(false);}
vector<ll> xx; REP(i,0,N) {sons.pb(xx); p.pb(-1);pos.pb({-1,-1});}
DFS_Build(r,r);
}
void Reset()
{
REP(i,0,N) {visited[i]=false;}
}
void DFS_Build(ll s, ll par)
{
pos[s].ff=DFSarr1.size();
DFSarr1.pb(s);
p[s]=par;
visited[s]=true;
REP(i,0,adj[s].size())
{
if(adj[s][i]==par) {continue;}
sons[s].pb(adj[s][i]);
DFS_Build(adj[s][i],s);
}
pos[s].ss=DFSarr1.size()-1;
return;
}
};
inline ll f(ll x)
{
ll mil=1000;
ll a = x/mil; ll b =x%mil;
ll ans =((2001-a)*a)/2 + (b-a);
return ans;
}
inline ll invf(ll x)
{
ll a,b; a=-1;
REP(i,0,1000)
{
ll val = (i*(2001-i))/2;
if(val>x) {a=i-1; break;}
}
if(a==-1) {a=999;}
ll val = (a*(2001-a))/2; b=a+x-val;
ll mil=1000;
ll ans = mil*a+b;
return ans;
}
vector<ll> label(ll N, ll k, vector<ll> u, vector<ll> v)
{
vector<ll> xx; vector<vector<ll> > adj; REP(i,0,N) {adj.pb(xx);}
REP(i,0,N-1) {adj[u[i]].pb(v[i]); adj[v[i]].pb(u[i]);}
Tree T(adj);
vector<ll> label;
ll mil=1000;
REP(i,0,N) {label.pb(f(T.pos[i].ff*mil+T.pos[i].ss));}
return label;
}
ll find_next_station(ll s, ll t, vector<ll> c)
{
vector<pl> inter; pl self; pl target;
ll mil=1000;
vector<pl> poss;
self={invf(s)/mil,invf(s)%mil};
REP(i,0,c.size()) {inter.pb({invf(c[i])/mil,invf(c[i])%mil});}
target={invf(t)/mil,invf(t)%mil};
ll beg = min_element(whole(inter))->ff;
ll maxend =-1; ll ind;
REP(i,0,inter.size()) {if(inter[i].ff==beg && inter[i].ss>maxend) {maxend=inter[i].ss; ind=i;}}
REP(i,0,inter.size())
{
if(i==ind) {continue;}
if(target.ff>=inter[i].ff && target.ss<=inter[i].ss) {return c[i];}
}
return c[ind];
}
Compilation message
stations.cpp: In function 'll find_next_station(ll, ll, std::vector<int>)':
stations.cpp:137:14: warning: 'ind' may be used uninitialized in this function [-Wmaybe-uninitialized]
137 | return c[ind];
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
620 KB |
Invalid labels (values out of range). scenario=0, k=1000, vertex=1, label=5988 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
620 KB |
Invalid labels (values out of range). scenario=0, k=1000, vertex=1, label=1510 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
580 ms |
1076 KB |
Output is correct |
2 |
Correct |
541 ms |
1016 KB |
Output is correct |
3 |
Correct |
966 ms |
868 KB |
Output is correct |
4 |
Correct |
805 ms |
888 KB |
Output is correct |
5 |
Correct |
634 ms |
868 KB |
Output is correct |
6 |
Correct |
550 ms |
1028 KB |
Output is correct |
7 |
Correct |
562 ms |
1080 KB |
Output is correct |
8 |
Correct |
4 ms |
736 KB |
Output is correct |
9 |
Correct |
6 ms |
756 KB |
Output is correct |
10 |
Correct |
2 ms |
868 KB |
Output is correct |
11 |
Correct |
720 ms |
876 KB |
Output is correct |
12 |
Correct |
668 ms |
992 KB |
Output is correct |
13 |
Correct |
648 ms |
1120 KB |
Output is correct |
14 |
Correct |
490 ms |
1124 KB |
Output is correct |
15 |
Correct |
69 ms |
756 KB |
Output is correct |
16 |
Correct |
113 ms |
864 KB |
Output is correct |
17 |
Correct |
183 ms |
992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1027 ms |
868 KB |
Output is correct |
2 |
Correct |
803 ms |
884 KB |
Output is correct |
3 |
Correct |
652 ms |
736 KB |
Output is correct |
4 |
Correct |
4 ms |
868 KB |
Output is correct |
5 |
Correct |
6 ms |
756 KB |
Output is correct |
6 |
Correct |
2 ms |
756 KB |
Output is correct |
7 |
Correct |
659 ms |
876 KB |
Output is correct |
8 |
Correct |
942 ms |
756 KB |
Output is correct |
9 |
Correct |
715 ms |
996 KB |
Output is correct |
10 |
Correct |
737 ms |
868 KB |
Output is correct |
11 |
Correct |
5 ms |
904 KB |
Output is correct |
12 |
Correct |
7 ms |
772 KB |
Output is correct |
13 |
Correct |
6 ms |
756 KB |
Output is correct |
14 |
Correct |
4 ms |
736 KB |
Output is correct |
15 |
Correct |
2 ms |
736 KB |
Output is correct |
16 |
Correct |
589 ms |
736 KB |
Output is correct |
17 |
Correct |
623 ms |
864 KB |
Output is correct |
18 |
Correct |
708 ms |
884 KB |
Output is correct |
19 |
Correct |
582 ms |
756 KB |
Output is correct |
20 |
Correct |
560 ms |
1060 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
614 ms |
1012 KB |
Partially correct |
2 |
Partially correct |
649 ms |
1012 KB |
Partially correct |
3 |
Correct |
998 ms |
868 KB |
Output is correct |
4 |
Partially correct |
785 ms |
756 KB |
Partially correct |
5 |
Partially correct |
607 ms |
868 KB |
Partially correct |
6 |
Partially correct |
560 ms |
1052 KB |
Partially correct |
7 |
Partially correct |
554 ms |
1012 KB |
Partially correct |
8 |
Partially correct |
4 ms |
756 KB |
Partially correct |
9 |
Partially correct |
6 ms |
756 KB |
Partially correct |
10 |
Partially correct |
2 ms |
868 KB |
Partially correct |
11 |
Partially correct |
687 ms |
1012 KB |
Partially correct |
12 |
Partially correct |
579 ms |
992 KB |
Partially correct |
13 |
Correct |
954 ms |
868 KB |
Output is correct |
14 |
Partially correct |
703 ms |
868 KB |
Partially correct |
15 |
Partially correct |
756 ms |
736 KB |
Partially correct |
16 |
Partially correct |
561 ms |
884 KB |
Partially correct |
17 |
Partially correct |
676 ms |
868 KB |
Partially correct |
18 |
Partially correct |
613 ms |
1248 KB |
Partially correct |
19 |
Partially correct |
560 ms |
1196 KB |
Partially correct |
20 |
Partially correct |
616 ms |
1124 KB |
Partially correct |
21 |
Partially correct |
82 ms |
736 KB |
Partially correct |
22 |
Partially correct |
113 ms |
864 KB |
Partially correct |
23 |
Partially correct |
181 ms |
1236 KB |
Partially correct |
24 |
Partially correct |
7 ms |
872 KB |
Partially correct |
25 |
Partially correct |
6 ms |
736 KB |
Partially correct |
26 |
Partially correct |
5 ms |
740 KB |
Partially correct |
27 |
Partially correct |
4 ms |
736 KB |
Partially correct |
28 |
Partially correct |
2 ms |
868 KB |
Partially correct |
29 |
Partially correct |
593 ms |
736 KB |
Partially correct |
30 |
Partially correct |
643 ms |
992 KB |
Partially correct |
31 |
Partially correct |
587 ms |
864 KB |
Partially correct |
32 |
Partially correct |
573 ms |
1060 KB |
Partially correct |
33 |
Partially correct |
635 ms |
1060 KB |
Partially correct |
34 |
Partially correct |
391 ms |
992 KB |
Partially correct |
35 |
Partially correct |
623 ms |
1132 KB |
Partially correct |
36 |
Partially correct |
661 ms |
1064 KB |
Partially correct |
37 |
Partially correct |
655 ms |
1184 KB |
Partially correct |
38 |
Partially correct |
592 ms |
1120 KB |
Partially correct |
39 |
Partially correct |
641 ms |
1192 KB |
Partially correct |
40 |
Partially correct |
632 ms |
1192 KB |
Partially correct |
41 |
Partially correct |
644 ms |
1120 KB |
Partially correct |
42 |
Partially correct |
105 ms |
992 KB |
Partially correct |
43 |
Partially correct |
183 ms |
1364 KB |
Partially correct |
44 |
Partially correct |
235 ms |
1020 KB |
Partially correct |
45 |
Partially correct |
260 ms |
1012 KB |
Partially correct |
46 |
Partially correct |
440 ms |
920 KB |
Partially correct |
47 |
Partially correct |
446 ms |
1108 KB |
Partially correct |
48 |
Partially correct |
136 ms |
992 KB |
Partially correct |
49 |
Partially correct |
136 ms |
1120 KB |
Partially correct |