Submission #985543

# Submission time Handle Problem Language Result Execution time Memory
985543 2024-05-18T06:20:32 Z Alex0x0 Stations (IOI20_stations) C++17
100 / 100
585 ms 1440 KB
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
// #pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef long double ld;
typedef int lli;
typedef pair<lli,lli> ii;
typedef vector<lli> vi;
typedef vector<ii> vii;
#define deb(x) cout << #x": " << (x) << endl;

const lli INF = 1e9 + 12;
const lli N = 1e3 + 12;

vector <vi> adj;

vi tk;
lli curVis = 0;
lli titi = 0;
lli vis[N];

void dfs(lli u, lli dpth){
  // cout << u << ' ';
  vis[u] = curVis;
  if (dpth % 2 == 1) tk[u] = titi++;
  for (auto & i : adj[u]){
    if (vis[i] == curVis) continue;
    dfs(i, dpth+1);
  }
  if (dpth % 2 == 0) tk[u] = titi++;
}

vi label(lli n, lli k, vi u, vi v){
  adj.resize(n + 5);
  for (auto &i : adj) i.clear();
  tk.resize(n);
  for (auto &i : tk) i = -1ll;
  titi = 0;
  fore(i,0,n-1){
    adj[u[i]].pb(v[i]);
    adj[v[i]].pb(u[i]);
  }
  ++curVis;
  dfs(0, 0);
  // cout << ENDL;
  return tk;
}


lli find_next_station(lli s, lli t, vi c){
  // cout << "c: "; for (auto & i : c) cout << i << ' '; cout << ENDL;
  for (auto & i : c) if (i == t) return i;
  bool minor = true;
  for (auto & i : c) if (i < s) minor = false;
  if (minor){
    fore(i,0,sz(c)-1) if (s < t && t < c[i]) return c[i];
    return c[sz(c)-1];
  }
  else{
    fore(i,1,sz(c)){
      lli xx = s;
      if ((i + 1) < sz(c)) xx = c[i + 1];
      if (c[i] < t && t < xx) return c[i];
    }
    return c[0];
  }
  return c[sz(c)-1];
}

// void query(lli a, lli b){
//   lli xx = 0;
//   while (tk[xx] != a) xx++;
//   vi c;
//   for(auto & i : adj[xx]) c.pb(tk[i]);
//   for (auto & i : c) cout << i << ' '; cout << ENDL;
//   sort(all(c));
//   cout << find_next_station(a, b, c) << ENDL;
// }

// int main(){ _
//   // freopen("file.in","r",stdin);
//   // freopen("file.out","w",stdout);
//   // vector<vi> vv;
//   lli t; cin >> t;
//   while (t--){
//     lli n, k; cin >> n >> k;
//     vi a(n-1); vi b(n-1);
//     fore(i,0,n-1) cin >> a[i] >> b[i];
//     vi v = label(n, k, a, b);
//     for (auto & i : v) cout << i << ' '; cout << ENDL;
//     // vv.pb(v);
//     // if (t == 1) continue;
//     query(3, 15);
//     query(2, 15);
//     query(16, 15);
//     query(11, 15);
//     cout << ENDL << "FIN DE CASO" << ENDL << ENDL << ENDL;
//   }
//   return 0;
// }
# Verdict Execution time Memory Grader output
1 Correct 342 ms 932 KB Output is correct
2 Correct 280 ms 924 KB Output is correct
3 Correct 563 ms 684 KB Output is correct
4 Correct 442 ms 684 KB Output is correct
5 Correct 355 ms 684 KB Output is correct
6 Correct 272 ms 912 KB Output is correct
7 Correct 284 ms 684 KB Output is correct
8 Correct 2 ms 768 KB Output is correct
9 Correct 3 ms 768 KB Output is correct
10 Correct 0 ms 764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 290 ms 860 KB Output is correct
2 Correct 364 ms 796 KB Output is correct
3 Correct 553 ms 684 KB Output is correct
4 Correct 455 ms 684 KB Output is correct
5 Correct 392 ms 684 KB Output is correct
6 Correct 276 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 326 ms 944 KB Output is correct
2 Correct 286 ms 920 KB Output is correct
3 Correct 585 ms 684 KB Output is correct
4 Correct 493 ms 684 KB Output is correct
5 Correct 400 ms 684 KB Output is correct
6 Correct 284 ms 896 KB Output is correct
7 Correct 275 ms 892 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 3 ms 772 KB Output is correct
10 Correct 0 ms 768 KB Output is correct
11 Correct 397 ms 684 KB Output is correct
12 Correct 290 ms 1208 KB Output is correct
13 Correct 288 ms 1248 KB Output is correct
14 Correct 296 ms 860 KB Output is correct
15 Correct 35 ms 768 KB Output is correct
16 Correct 43 ms 832 KB Output is correct
17 Correct 62 ms 1176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 549 ms 684 KB Output is correct
2 Correct 437 ms 684 KB Output is correct
3 Correct 386 ms 684 KB Output is correct
4 Correct 2 ms 768 KB Output is correct
5 Correct 3 ms 768 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 366 ms 684 KB Output is correct
8 Correct 576 ms 684 KB Output is correct
9 Correct 383 ms 684 KB Output is correct
10 Correct 380 ms 684 KB Output is correct
11 Correct 3 ms 768 KB Output is correct
12 Correct 3 ms 768 KB Output is correct
13 Correct 3 ms 768 KB Output is correct
14 Correct 2 ms 768 KB Output is correct
15 Correct 0 ms 768 KB Output is correct
16 Correct 318 ms 684 KB Output is correct
17 Correct 333 ms 684 KB Output is correct
18 Correct 380 ms 684 KB Output is correct
19 Correct 323 ms 684 KB Output is correct
20 Correct 324 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 365 ms 936 KB Output is correct
2 Correct 258 ms 936 KB Output is correct
3 Correct 570 ms 684 KB Output is correct
4 Correct 428 ms 684 KB Output is correct
5 Correct 372 ms 684 KB Output is correct
6 Correct 272 ms 1184 KB Output is correct
7 Correct 296 ms 936 KB Output is correct
8 Correct 1 ms 772 KB Output is correct
9 Correct 2 ms 768 KB Output is correct
10 Correct 1 ms 768 KB Output is correct
11 Correct 291 ms 1112 KB Output is correct
12 Correct 344 ms 832 KB Output is correct
13 Correct 557 ms 684 KB Output is correct
14 Correct 446 ms 684 KB Output is correct
15 Correct 430 ms 688 KB Output is correct
16 Correct 277 ms 936 KB Output is correct
17 Correct 360 ms 684 KB Output is correct
18 Correct 298 ms 980 KB Output is correct
19 Correct 284 ms 1164 KB Output is correct
20 Correct 301 ms 684 KB Output is correct
21 Correct 32 ms 760 KB Output is correct
22 Correct 39 ms 932 KB Output is correct
23 Correct 70 ms 860 KB Output is correct
24 Correct 3 ms 764 KB Output is correct
25 Correct 3 ms 768 KB Output is correct
26 Correct 3 ms 768 KB Output is correct
27 Correct 2 ms 768 KB Output is correct
28 Correct 0 ms 1020 KB Output is correct
29 Correct 348 ms 684 KB Output is correct
30 Correct 330 ms 684 KB Output is correct
31 Correct 388 ms 944 KB Output is correct
32 Correct 340 ms 680 KB Output is correct
33 Correct 336 ms 684 KB Output is correct
34 Correct 214 ms 920 KB Output is correct
35 Correct 256 ms 1440 KB Output is correct
36 Correct 282 ms 1152 KB Output is correct
37 Correct 311 ms 1160 KB Output is correct
38 Correct 302 ms 1156 KB Output is correct
39 Correct 279 ms 1160 KB Output is correct
40 Correct 316 ms 1168 KB Output is correct
41 Correct 237 ms 1152 KB Output is correct
42 Correct 35 ms 936 KB Output is correct
43 Correct 56 ms 948 KB Output is correct
44 Correct 96 ms 916 KB Output is correct
45 Correct 122 ms 892 KB Output is correct
46 Correct 205 ms 848 KB Output is correct
47 Correct 192 ms 888 KB Output is correct
48 Correct 40 ms 908 KB Output is correct
49 Correct 38 ms 1260 KB Output is correct