Submission #309707

# Submission time Handle Problem Language Result Execution time Memory
309707 2020-10-04T10:57:42 Z rrrr10000 Stations (IOI20_stations) C++14
100 / 100
1047 ms 1280 KB
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) {sort(all(a));a.erase(unique(all(a)),a.end());}
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}

#include "stations.h"

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	std::vector<int> ans(n);
	vvi g(n);
    rep(i,n-1){
        g[u[i]].pb(v[i]);
        g[v[i]].pb(u[i]);
    }
    ll cnt=0;
    vp r(n,P(inf,-inf));
    function<void(ll,ll,ll)> dfs=[&](ll i,ll p,ll dep){
        for(ll x:g[i])if(x!=p){
            dfs(x,i,dep+1);
            chmin(r[i].fi,r[x].fi);
            chmax(r[i].se,r[x].se);
        }
        if(g[i].size()==1&&p!=-1){
            ans[i]=cnt;cnt+=n*2;
            r[i]=P(ans[i],ans[i]);
        }
        else if(dep%2)ans[i]=(++r[i].se);
        else ans[i]=(--r[i].fi);
    };
    dfs(0,-1,0);
    vector<int> s=ans;
    sort(all(s));
    rep(i,n)ans[i]=lb(s,ans[i]);
	return ans;
}

int find_next_station(int s, int t, std::vector<int> c) {
    if(c.size()==1)return c[0];
	bool mi=true;
    for(ll x:c)if(s>x)mi=false;
    if(mi){
        if(t<s||t>c[c.size()-2])return c.back();
        return *lower_bound(all(c),t);
    }
    if(t>s||t<c[1])return c[0];
    return c[ub(c,t)-1];
}



# Verdict Execution time Memory Grader output
1 Correct 538 ms 1024 KB Output is correct
2 Correct 464 ms 1008 KB Output is correct
3 Correct 918 ms 644 KB Output is correct
4 Correct 810 ms 776 KB Output is correct
5 Correct 718 ms 648 KB Output is correct
6 Correct 478 ms 1024 KB Output is correct
7 Correct 499 ms 1024 KB Output is correct
8 Correct 3 ms 648 KB Output is correct
9 Correct 5 ms 652 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 487 ms 768 KB Output is correct
2 Correct 569 ms 804 KB Output is correct
3 Correct 942 ms 648 KB Output is correct
4 Correct 752 ms 640 KB Output is correct
5 Correct 705 ms 652 KB Output is correct
6 Correct 469 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 549 ms 1168 KB Output is correct
2 Correct 456 ms 1280 KB Output is correct
3 Correct 846 ms 648 KB Output is correct
4 Correct 666 ms 652 KB Output is correct
5 Correct 636 ms 640 KB Output is correct
6 Correct 455 ms 1024 KB Output is correct
7 Correct 471 ms 1024 KB Output is correct
8 Correct 3 ms 1160 KB Output is correct
9 Correct 5 ms 648 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
11 Correct 659 ms 652 KB Output is correct
12 Correct 503 ms 1068 KB Output is correct
13 Correct 556 ms 1024 KB Output is correct
14 Correct 487 ms 800 KB Output is correct
15 Correct 55 ms 768 KB Output is correct
16 Correct 81 ms 912 KB Output is correct
17 Correct 107 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1016 ms 640 KB Output is correct
2 Correct 731 ms 644 KB Output is correct
3 Correct 582 ms 648 KB Output is correct
4 Correct 3 ms 656 KB Output is correct
5 Correct 4 ms 780 KB Output is correct
6 Correct 1 ms 652 KB Output is correct
7 Correct 767 ms 640 KB Output is correct
8 Correct 1047 ms 648 KB Output is correct
9 Correct 656 ms 648 KB Output is correct
10 Correct 681 ms 640 KB Output is correct
11 Correct 6 ms 808 KB Output is correct
12 Correct 7 ms 652 KB Output is correct
13 Correct 6 ms 640 KB Output is correct
14 Correct 5 ms 648 KB Output is correct
15 Correct 2 ms 640 KB Output is correct
16 Correct 606 ms 656 KB Output is correct
17 Correct 491 ms 648 KB Output is correct
18 Correct 499 ms 656 KB Output is correct
19 Correct 514 ms 648 KB Output is correct
20 Correct 507 ms 784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 581 ms 1024 KB Output is correct
2 Correct 474 ms 1008 KB Output is correct
3 Correct 914 ms 648 KB Output is correct
4 Correct 653 ms 652 KB Output is correct
5 Correct 590 ms 640 KB Output is correct
6 Correct 460 ms 1024 KB Output is correct
7 Correct 433 ms 1024 KB Output is correct
8 Correct 3 ms 640 KB Output is correct
9 Correct 4 ms 660 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
11 Correct 469 ms 768 KB Output is correct
12 Correct 555 ms 888 KB Output is correct
13 Correct 860 ms 640 KB Output is correct
14 Correct 669 ms 640 KB Output is correct
15 Correct 586 ms 768 KB Output is correct
16 Correct 557 ms 1024 KB Output is correct
17 Correct 608 ms 648 KB Output is correct
18 Correct 455 ms 1104 KB Output is correct
19 Correct 492 ms 1024 KB Output is correct
20 Correct 454 ms 808 KB Output is correct
21 Correct 62 ms 768 KB Output is correct
22 Correct 71 ms 768 KB Output is correct
23 Correct 110 ms 768 KB Output is correct
24 Correct 6 ms 640 KB Output is correct
25 Correct 6 ms 648 KB Output is correct
26 Correct 5 ms 660 KB Output is correct
27 Correct 3 ms 640 KB Output is correct
28 Correct 2 ms 648 KB Output is correct
29 Correct 515 ms 660 KB Output is correct
30 Correct 514 ms 652 KB Output is correct
31 Correct 598 ms 656 KB Output is correct
32 Correct 526 ms 656 KB Output is correct
33 Correct 524 ms 656 KB Output is correct
34 Correct 357 ms 1104 KB Output is correct
35 Correct 539 ms 1024 KB Output is correct
36 Correct 548 ms 1072 KB Output is correct
37 Correct 513 ms 772 KB Output is correct
38 Correct 490 ms 784 KB Output is correct
39 Correct 459 ms 1024 KB Output is correct
40 Correct 496 ms 768 KB Output is correct
41 Correct 442 ms 888 KB Output is correct
42 Correct 62 ms 836 KB Output is correct
43 Correct 107 ms 932 KB Output is correct
44 Correct 137 ms 768 KB Output is correct
45 Correct 172 ms 788 KB Output is correct
46 Correct 293 ms 784 KB Output is correct
47 Correct 309 ms 1024 KB Output is correct
48 Correct 74 ms 816 KB Output is correct
49 Correct 63 ms 804 KB Output is correct