Submission #1267618

#TimeUsernameProblemLanguageResultExecution timeMemory
1267618d1mk이주 (IOI25_migrations)C++20
82.45 / 100
743 ms1476 KiB
/// 407!3 +/ \!<07!\*
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

using namespace std;

using ll = long long;
using db = long double; // or double, if TL is tight
using str = string; // yay python!

using pi = pair<int,int>;
using pl = pair<ll,ll>;
using pd = pair<db,db>;

using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vvpi = vector<vpi>;

template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;

// pairs
#define mp make_pair
#define f first
#define s second

// vectors
#define sz(x) int((x).size())
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define rall(x) x.rbegin(), x.rend()
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pb push_back
#define eb emplace_back
#define pf push_front
#define er erase
#define ub upper_bound
#define lb lower_bound

// loops
#define FOR(i,a,b) for (ll i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (ll i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

const int MOD = 1e9+7; // 998244353;
const int MX = 2e5+5;
const ll INF = 1e18; // not too close to LLONG_MAX
const db PI = acos((db)-1);
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1}; // for every grid problem!
const char nl = '\n';

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

template<typename T>
using indexed_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define ook order_of_key
#define fbo find_by_order

void _input() {return;}
template <typename T, typename... V>
void _input(T &t, V&... v) {cin >> (t); if (sizeof...(v))  _input(v...);}
void __input(vi &v, const int n){F0R(i, n)cin >> v[i];}
void __input(vvi &v, const int n, const int m){F0R(i, n)F0R(j, m)cin>>v[i][j];}

ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

vi dista(10001), distb(10001);
vvi g(10001);
int a = 0, b = 0, d = 0, a1 = 0, a2 = 0, a3 = 0, a4 = 0, b1 = 0, b2 = 0, b3 = 0, b4 = 0;

void dfs(int u, int p, bool f){
    trav(v, g[u]){
        if(p == v)continue;
        if(f)dista[v] = dista[u] + 1;
        else distb[v] = distb[u] + 1;
        dfs(v, u, f);
    }
}

int send_message(int N, int i, int Pi){
    g[i].pb(Pi);
    g[Pi].pb(i);
    dista[i] = dista[Pi] + 1;
    distb[i] = distb[Pi] + 1;
    //if(i == 21)_print(dista, distb);
    if(distb[i] > d){
        dista[i] = 0;
        dfs(i, -1, 1);
        d = distb[i];
        if(i < N - 21)a = i;
        else if(i < N - 9)a1 = i - (N - 21) + 1;
        else if(i < N - 5)a2 = i - (N - 9) + 1;
        else if(i < N - 2)a3 = i - (N - 5) + 1;
        else a4 = i - (N - 2) + 1;
    }
    else if(dista[i] > d){
        distb[i] = 0;
        dfs(i, -1, 0);
        d = dista[i];
        if(i < N - 21)b = i;
        else if(i < N - 9)b1 = i - (N - 21) + 1;
        else if(i < N - 5)b2 = i - (N - 9) + 1;
        else if(i < N - 1)b3 = i - (N - 5) + 1;
        else b4 = 1;
    }
    //_print(a, a1, a2, a3, a4, b, b1, b2, b3, b4, d);
    if(i < N - 21)return 0;
    if(i < N - 15){
        int x = a % 5;
        a /= 5;
        return x;
    }
    if(i < N - 9){
        int x = b % 5;
        b /= 5;
        return x;
    }
    if(i < N - 7){
        int x = a1 % 5;
        a1 /= 5;
        return x;
    }
    if(i < N - 5){
        int x = b1 % 5;
        b1 /= 5;
        return x;
    }
    if(i < N - 4)return a2;
    if(i < N - 3)return b2;
    if(i < N - 2)return a3;
    if(i < N - 1)return b3;
    if(a4 == 1 && b4 == 1)return 1;
    if(a4 == 1)return 2;
    if(a4 == 2)return 3;
    if(b4 == 1)return 4;
    return 0;
}

std::pair<int,int> longest_path(std::vector<int> S){
    int ca = 0, cb = 0, fa = 0, fb = 0;
    int N = sz(S);
    ROF(i, N - 21, N - 15){
        ca *= 5;
        ca += S[i];
    }
    ROF(i, N - 15, N - 9){
        cb *= 5;
        cb += S[i];
    }
    fa = ca;
    ca = 0;
    fb = cb;
    cb = 0;
    ROF(i, N - 9, N - 7){
        ca *= 5;
        ca += S[i];
    }
    ROF(i, N - 7, N - 5){
        cb *= 5;
        cb += S[i];
    }
    if(ca > 0)fa = ca + N - 21 - 1;
    if(cb > 0)fb = cb + N - 21 - 1;
    if(S[N - 5]){
        fa = N - 9 - 1 + S[N - 5];
    }
    if(S[N - 4]){
        fb = N - 9 - 1 + S[N - 4];
    }
    if(S[N - 3]){
        fa = N - 5 - 1 + S[N - 3];
    }
    if(S[N - 2]){
        fb = N - 5 - 1 + S[N - 2];
    }
    if(S[N - 1] == 1){
        fa = N - 2;
        fb = N - 1;
    }
    else if(S[N - 1] == 2){
        fa = N - 2;
    }
    else if(S[N - 1] == 3){
        fa = N - 1;
    }
    else if(S[N - 1] == 4){
        fb = N - 1;
    }
    return mp(fa, fb);
}


/*
30
0 1 2 3 4 5 6 1 1 1 1 1 1 1 1 1 1 1 1 1 0 21 22 1 1 1 1 1 23

*/



#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...