Submission #612292

# Submission time Handle Problem Language Result Execution time Memory
612292 2022-07-29T12:43:06 Z daria Stations (IOI20_stations) C++17
100 / 100
994 ms 908 KB
#include"bits/stdc++.h"
#include "stations.h"
#include <vector>
using namespace std;

const int N = 1000;

int T;
vector<int> adj[N], lb(N);
vector<bool> vis(N);

void dfs(int s, bool b){ //b = 0 apertura, b = 1 chiusura
 if(vis[s]) return;
 vis[s] = 1;
 if(!b) lb[s] = T; T++;
 for(int u : adj[s]) dfs(u, 1-b);
 if(b) lb[s] = T; T++;
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
 for(int i=0; i<n; ++i) adj[i].clear();
 lb.resize(n);
 fill(lb.begin(), lb.end(), -1);
 fill(vis.begin(), vis.end(), 0);
 T = 0;

 for(int i=0; i<n-1; ++i){
  adj[u[i]].push_back(v[i]);
  adj[v[i]].push_back(u[i]);
 }
 dfs(0, 0);
 //for(int i=0; i<n; ++i) cout << i << " " << lb[i] << endl;
 map<int, int> mp;
 for(int i=0; i<n; ++i) mp[lb[i]] = i;
 sort(lb.begin(), lb.end());

 vector<int> lb2(n);
 for(int i=0; i<n; ++i){
  int j = mp[lb[i]];
  lb2[j] = i;
 }

 return lb2;
}

int find_next_station(int s, int t, vector<int> c) {
 int m=0;
 for(int u : c) if(u>s) m++;
 int par=-1;
 if(m == c.size()){ //s apertura, le altre sono tutte chiusure
  par = 0;
  for(int u : c) par = max(par, u);
  if(t <= s) return par;
  for(int i=0; i<c.size(); ++i) if(c[i] >= t) return c[i];
 } else{ // s chiusura, le altre sono tutte aperture
  par = 400001;
  for(int u : c) par = min(par, u);
  if(t >= s) return par;
  for(int i=c.size()-1; i>=0; --i) if(c[i] <= t) return c[i];
 }
 return par;
}

Compilation message

stations.cpp: In function 'void dfs(int, bool)':
stations.cpp:15:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   15 |  if(!b) lb[s] = T; T++;
      |  ^~
stations.cpp:15:20: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   15 |  if(!b) lb[s] = T; T++;
      |                    ^
stations.cpp:17:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   17 |  if(b) lb[s] = T; T++;
      |  ^~
stations.cpp:17:19: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   17 |  if(b) lb[s] = T; T++;
      |                   ^
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:50:7: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |  if(m == c.size()){ //s apertura, le altre sono tutte chiusure
      |     ~~^~~~~~~~~~~
stations.cpp:54:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |   for(int i=0; i<c.size(); ++i) if(c[i] >= t) return c[i];
      |                ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 537 ms 676 KB Output is correct
2 Correct 420 ms 660 KB Output is correct
3 Correct 881 ms 492 KB Output is correct
4 Correct 597 ms 528 KB Output is correct
5 Correct 535 ms 536 KB Output is correct
6 Correct 444 ms 668 KB Output is correct
7 Correct 408 ms 544 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 5 ms 492 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 458 ms 532 KB Output is correct
2 Correct 629 ms 528 KB Output is correct
3 Correct 941 ms 516 KB Output is correct
4 Correct 663 ms 536 KB Output is correct
5 Correct 569 ms 420 KB Output is correct
6 Correct 488 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 543 ms 660 KB Output is correct
2 Correct 387 ms 672 KB Output is correct
3 Correct 745 ms 540 KB Output is correct
4 Correct 669 ms 528 KB Output is correct
5 Correct 508 ms 524 KB Output is correct
6 Correct 446 ms 656 KB Output is correct
7 Correct 434 ms 660 KB Output is correct
8 Correct 3 ms 496 KB Output is correct
9 Correct 3 ms 492 KB Output is correct
10 Correct 0 ms 624 KB Output is correct
11 Correct 543 ms 416 KB Output is correct
12 Correct 426 ms 644 KB Output is correct
13 Correct 429 ms 736 KB Output is correct
14 Correct 390 ms 548 KB Output is correct
15 Correct 41 ms 600 KB Output is correct
16 Correct 56 ms 572 KB Output is correct
17 Correct 93 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 871 ms 420 KB Output is correct
2 Correct 532 ms 540 KB Output is correct
3 Correct 586 ms 528 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 4 ms 492 KB Output is correct
6 Correct 1 ms 500 KB Output is correct
7 Correct 593 ms 416 KB Output is correct
8 Correct 848 ms 416 KB Output is correct
9 Correct 634 ms 424 KB Output is correct
10 Correct 534 ms 728 KB Output is correct
11 Correct 6 ms 552 KB Output is correct
12 Correct 6 ms 488 KB Output is correct
13 Correct 3 ms 492 KB Output is correct
14 Correct 4 ms 488 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 477 ms 420 KB Output is correct
17 Correct 432 ms 532 KB Output is correct
18 Correct 514 ms 544 KB Output is correct
19 Correct 482 ms 536 KB Output is correct
20 Correct 435 ms 536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 494 ms 676 KB Output is correct
2 Correct 441 ms 660 KB Output is correct
3 Correct 737 ms 416 KB Output is correct
4 Correct 660 ms 528 KB Output is correct
5 Correct 595 ms 416 KB Output is correct
6 Correct 425 ms 660 KB Output is correct
7 Correct 430 ms 536 KB Output is correct
8 Correct 5 ms 492 KB Output is correct
9 Correct 3 ms 496 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
11 Correct 440 ms 532 KB Output is correct
12 Correct 549 ms 532 KB Output is correct
13 Correct 994 ms 536 KB Output is correct
14 Correct 587 ms 532 KB Output is correct
15 Correct 655 ms 424 KB Output is correct
16 Correct 495 ms 520 KB Output is correct
17 Correct 590 ms 416 KB Output is correct
18 Correct 432 ms 660 KB Output is correct
19 Correct 539 ms 776 KB Output is correct
20 Correct 473 ms 536 KB Output is correct
21 Correct 64 ms 612 KB Output is correct
22 Correct 60 ms 548 KB Output is correct
23 Correct 112 ms 700 KB Output is correct
24 Correct 5 ms 492 KB Output is correct
25 Correct 5 ms 500 KB Output is correct
26 Correct 5 ms 488 KB Output is correct
27 Correct 4 ms 492 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 490 ms 536 KB Output is correct
30 Correct 564 ms 416 KB Output is correct
31 Correct 544 ms 532 KB Output is correct
32 Correct 530 ms 536 KB Output is correct
33 Correct 473 ms 420 KB Output is correct
34 Correct 344 ms 544 KB Output is correct
35 Correct 372 ms 908 KB Output is correct
36 Correct 511 ms 764 KB Output is correct
37 Correct 498 ms 652 KB Output is correct
38 Correct 488 ms 760 KB Output is correct
39 Correct 450 ms 792 KB Output is correct
40 Correct 400 ms 648 KB Output is correct
41 Correct 490 ms 768 KB Output is correct
42 Correct 68 ms 744 KB Output is correct
43 Correct 103 ms 532 KB Output is correct
44 Correct 199 ms 544 KB Output is correct
45 Correct 173 ms 784 KB Output is correct
46 Correct 283 ms 544 KB Output is correct
47 Correct 390 ms 612 KB Output is correct
48 Correct 62 ms 804 KB Output is correct
49 Correct 62 ms 808 KB Output is correct