Submission #772648

# Submission time Handle Problem Language Result Execution time Memory
772648 2023-07-04T09:54:35 Z cadmiumsky Stations (IOI20_stations) C++17
100 / 100
811 ms 876 KB
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;

using ll = long long;
using ld = long double;

//#define int ll
#define sz(x) ((int)(x).size())

using pii = pair<int,int>;
using tii = tuple<int,int,int>;

const int nmax = 1e3 + 5;

vector<int> g[nmax];
int pin[nmax], pout[nmax], d[nmax];

int p = 0;
void dfs(int node, int f) {
  pin[node] = p++;
  d[node] = d[f] ^ 1;
  //cerr << node << ' ' << f << '\n';
  for(auto x : g[node])
    if(x != f) dfs(x, node);
  pout[node] = p++;
}

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
  for(int i = 0; i < n; i++) g[i].clear();
  p = 0;
  for(int i = 0; i < sz(u); i++)
    g[u[i]].emplace_back(v[i]),
    g[v[i]].emplace_back(u[i]);
  dfs(0, 0);
  vector<int> rez(n);
  for(int i = 0; i < n; i++)
    rez[i] = (d[i]? pin[i] : pout[i]);
  map<int, int> freq;
  int cnt = 0;
  for(auto x : rez) freq[x];
  for(auto &[a, b] : freq) b = cnt++;
  for(auto &x : rez) x = freq[x];
  //for(int i = 0; i < n; i++) cerr << i << " --> " << rez[i] << '\n';
    
  return rez;
}
int find_next_station(int s, int t, std::vector<int> c) {
  if(sz(c) == 1) return c[0];
  if(s < c[0]) {
    //cerr << s << " --> " << t << '\n';
    //for(auto x : c) cerr << x << ' ';
    //cerr << '\n';
    if(t < s || rbegin(c)[1] < t) return c.back();
    for(int i = 0; i < sz(c); i++)
      if(t <= c[i]) return c[i];
    //assert(true == false);
  }
  else {
    if(t > s || t < c[1]) return c[0];
    int n = sz(c);
    c.emplace_back(s);
    for(int i = 1; i < n; i++) {
      if(c[i] <= t && t < c[i + 1]) return c[i];
    }
    //cerr << s << ' ' << t << '\n';
    //c.pop_back();
    //for(auto x : c) cerr << x << ' ';
    //cerr << '\n';
    //assert(true == false);
  }
  assert(false);
}

/**
      Anul asta se da centroid.
-- Surse oficiale
*/

# Verdict Execution time Memory Grader output
1 Correct 433 ms 660 KB Output is correct
2 Correct 307 ms 820 KB Output is correct
3 Correct 713 ms 536 KB Output is correct
4 Correct 498 ms 416 KB Output is correct
5 Correct 500 ms 416 KB Output is correct
6 Correct 362 ms 676 KB Output is correct
7 Correct 430 ms 548 KB Output is correct
8 Correct 1 ms 620 KB Output is correct
9 Correct 4 ms 628 KB Output is correct
10 Correct 0 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 318 ms 600 KB Output is correct
2 Correct 415 ms 532 KB Output is correct
3 Correct 707 ms 416 KB Output is correct
4 Correct 588 ms 532 KB Output is correct
5 Correct 498 ms 548 KB Output is correct
6 Correct 312 ms 544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 487 ms 672 KB Output is correct
2 Correct 331 ms 680 KB Output is correct
3 Correct 753 ms 416 KB Output is correct
4 Correct 515 ms 544 KB Output is correct
5 Correct 530 ms 536 KB Output is correct
6 Correct 294 ms 692 KB Output is correct
7 Correct 376 ms 544 KB Output is correct
8 Correct 1 ms 620 KB Output is correct
9 Correct 2 ms 620 KB Output is correct
10 Correct 0 ms 624 KB Output is correct
11 Correct 520 ms 544 KB Output is correct
12 Correct 316 ms 760 KB Output is correct
13 Correct 431 ms 776 KB Output is correct
14 Correct 376 ms 544 KB Output is correct
15 Correct 39 ms 596 KB Output is correct
16 Correct 56 ms 676 KB Output is correct
17 Correct 80 ms 676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 811 ms 524 KB Output is correct
2 Correct 610 ms 548 KB Output is correct
3 Correct 438 ms 544 KB Output is correct
4 Correct 1 ms 620 KB Output is correct
5 Correct 3 ms 492 KB Output is correct
6 Correct 0 ms 492 KB Output is correct
7 Correct 459 ms 532 KB Output is correct
8 Correct 659 ms 528 KB Output is correct
9 Correct 532 ms 536 KB Output is correct
10 Correct 419 ms 532 KB Output is correct
11 Correct 3 ms 640 KB Output is correct
12 Correct 4 ms 628 KB Output is correct
13 Correct 3 ms 512 KB Output is correct
14 Correct 2 ms 620 KB Output is correct
15 Correct 1 ms 620 KB Output is correct
16 Correct 392 ms 536 KB Output is correct
17 Correct 350 ms 532 KB Output is correct
18 Correct 376 ms 528 KB Output is correct
19 Correct 404 ms 536 KB Output is correct
20 Correct 458 ms 568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 495 ms 648 KB Output is correct
2 Correct 400 ms 672 KB Output is correct
3 Correct 640 ms 668 KB Output is correct
4 Correct 485 ms 528 KB Output is correct
5 Correct 418 ms 536 KB Output is correct
6 Correct 410 ms 664 KB Output is correct
7 Correct 347 ms 532 KB Output is correct
8 Correct 2 ms 620 KB Output is correct
9 Correct 3 ms 628 KB Output is correct
10 Correct 1 ms 620 KB Output is correct
11 Correct 373 ms 532 KB Output is correct
12 Correct 435 ms 544 KB Output is correct
13 Correct 692 ms 544 KB Output is correct
14 Correct 528 ms 544 KB Output is correct
15 Correct 537 ms 416 KB Output is correct
16 Correct 266 ms 540 KB Output is correct
17 Correct 557 ms 532 KB Output is correct
18 Correct 331 ms 780 KB Output is correct
19 Correct 410 ms 800 KB Output is correct
20 Correct 327 ms 544 KB Output is correct
21 Correct 58 ms 544 KB Output is correct
22 Correct 64 ms 600 KB Output is correct
23 Correct 85 ms 700 KB Output is correct
24 Correct 4 ms 628 KB Output is correct
25 Correct 4 ms 620 KB Output is correct
26 Correct 4 ms 492 KB Output is correct
27 Correct 3 ms 628 KB Output is correct
28 Correct 1 ms 620 KB Output is correct
29 Correct 454 ms 532 KB Output is correct
30 Correct 449 ms 544 KB Output is correct
31 Correct 403 ms 532 KB Output is correct
32 Correct 457 ms 416 KB Output is correct
33 Correct 385 ms 548 KB Output is correct
34 Correct 282 ms 672 KB Output is correct
35 Correct 376 ms 776 KB Output is correct
36 Correct 416 ms 780 KB Output is correct
37 Correct 340 ms 788 KB Output is correct
38 Correct 410 ms 668 KB Output is correct
39 Correct 308 ms 768 KB Output is correct
40 Correct 292 ms 776 KB Output is correct
41 Correct 371 ms 764 KB Output is correct
42 Correct 54 ms 748 KB Output is correct
43 Correct 91 ms 672 KB Output is correct
44 Correct 121 ms 712 KB Output is correct
45 Correct 123 ms 668 KB Output is correct
46 Correct 226 ms 544 KB Output is correct
47 Correct 230 ms 544 KB Output is correct
48 Correct 44 ms 876 KB Output is correct
49 Correct 53 ms 832 KB Output is correct