Submission #314427

# Submission time Handle Problem Language Result Execution time Memory
314427 2020-10-19T20:39:52 Z hhh07 Toy Train (IOI17_train) C++14
100 / 100
1044 ms 1656 KB
#include <iostream>
#include <set>
#include <vector>
#include <queue>
#include <algorithm>
#include "train.h"

using namespace std;

typedef long long ll;
typedef vector<int> vi;

vector<vi> adjList(5005, vi());
vector<bool> gotov(5005, false), t(5005, false);
int n;

vi operator-(vi a, vi b){
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    
    vi res; int j = 0;
    for (int i = 0; i < a.size(); i++){
        while(j < b.size() && b[j] < a[i])
            j++;
        
        if (j == b.size() || b[j] > a[i])
            res.push_back(a[i]);
    }
    
    return res;
}

int deg[5005];
bool vis[5005];

vi f(bool type, vi x){
    for (int i = 0; i < n; i++)
        vis[i] = deg[i] = 0;
    
    for (int i = 0; i < n; i++){
        if (gotov[i])
            continue;
        for (int j = 0; j < adjList[i].size(); j++){
            int curr = adjList[i][j];
            if (!gotov[curr])
                deg[curr]++;
        }
    }
    
    queue<int> q;
    for (int i = 0; i < x.size(); i++)
        vis[x[i]] = true, q.push(x[i]);
    
    while(!q.empty()){
        int curr = q.front();
        q.pop();
        for (int i = 0; i < adjList[curr].size(); i++){
            int k = adjList[curr][i];
            if (gotov[k] || vis[k])
                continue;
            if (t[k] == type)
                vis[k] = 1, q.push(k);
            else{
                deg[k]--;
                if (!deg[k])
                    vis[k] = 1, q.push(k);
            }
        }
    }
    
    vi res;
    for (int i = 0; i < n; i++){
        if (!gotov[i] && vis[i])
            res.push_back(i);
    }
    return res;
}

vi who_wins(vi a, vi r, vi u, vi v){
    n = a.size(); int m = u.size();
    for (int i = 0; i < m; i++)
        adjList[v[i]].push_back(u[i]);
    
    vi graph;
    for (int i = 0; i < n; i++)
        graph.push_back(i), t[i] = a[i];
    
    while(!graph.empty()){
        vi f_a, f_b;
        
        for (int i = 0; i < graph.size(); i++)
            if (r[graph[i]])
                f_a.push_back(graph[i]);
            
        f_a = f(1, f_a); f_b = f(0, graph - f_a);
        
        if (f_b.size() == 0)
            break;
        
        for (int i = 0; i < f_b.size(); i++)
            gotov[f_b[i]] = true;
        
        graph = graph - f_b;
    }
    
    vi res(n, 0);
    for (int i = 0; i < graph.size(); i++)
        res[graph[i]] = true;
    return res;
}

Compilation message

train.cpp: In function 'vi operator-(vi, vi)':
train.cpp:22:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for (int i = 0; i < a.size(); i++){
      |                     ~~^~~~~~~~~~
train.cpp:23:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |         while(j < b.size() && b[j] < a[i])
      |               ~~^~~~~~~~~~
train.cpp:26:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |         if (j == b.size() || b[j] > a[i])
      |             ~~^~~~~~~~~~~
train.cpp: In function 'vi f(bool, vi)':
train.cpp:38:25: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   38 |         vis[i] = deg[i] = 0;
      |                  ~~~~~~~^~~
train.cpp:43:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |         for (int j = 0; j < adjList[i].size(); j++){
      |                         ~~^~~~~~~~~~~~~~~~~~~
train.cpp:51:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |     for (int i = 0; i < x.size(); i++)
      |                     ~~^~~~~~~~~~
train.cpp:57:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |         for (int i = 0; i < adjList[curr].size(); i++){
      |                         ~~^~~~~~~~~~~~~~~~~~~~~~
train.cpp: In function 'vi who_wins(vi, vi, vi, vi)':
train.cpp:91:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |         for (int i = 0; i < graph.size(); i++)
      |                         ~~^~~~~~~~~~~~~~
train.cpp:100:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  100 |         for (int i = 0; i < f_b.size(); i++)
      |                         ~~^~~~~~~~~~~~
train.cpp:107:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  107 |     for (int i = 0; i < graph.size(); i++)
      |                     ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1024 KB Output is correct
2 Correct 8 ms 1024 KB Output is correct
3 Correct 7 ms 1024 KB Output is correct
4 Correct 8 ms 1024 KB Output is correct
5 Correct 6 ms 1024 KB Output is correct
6 Correct 7 ms 1024 KB Output is correct
7 Correct 6 ms 1024 KB Output is correct
8 Correct 8 ms 1024 KB Output is correct
9 Correct 7 ms 1024 KB Output is correct
10 Correct 6 ms 1024 KB Output is correct
11 Correct 5 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 293 ms 1280 KB Output is correct
2 Correct 515 ms 1656 KB Output is correct
3 Correct 670 ms 1476 KB Output is correct
4 Correct 10 ms 1408 KB Output is correct
5 Correct 11 ms 1408 KB Output is correct
6 Correct 11 ms 1408 KB Output is correct
7 Correct 11 ms 1408 KB Output is correct
8 Correct 10 ms 1408 KB Output is correct
9 Correct 10 ms 1408 KB Output is correct
10 Correct 10 ms 1408 KB Output is correct
11 Correct 11 ms 1280 KB Output is correct
12 Correct 8 ms 1280 KB Output is correct
13 Correct 10 ms 1408 KB Output is correct
14 Correct 14 ms 1408 KB Output is correct
15 Correct 12 ms 1408 KB Output is correct
16 Correct 9 ms 1408 KB Output is correct
17 Correct 9 ms 1408 KB Output is correct
18 Correct 844 ms 1276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1140 KB Output is correct
2 Correct 9 ms 1152 KB Output is correct
3 Correct 11 ms 1520 KB Output is correct
4 Correct 10 ms 1408 KB Output is correct
5 Correct 10 ms 1408 KB Output is correct
6 Correct 10 ms 1408 KB Output is correct
7 Correct 10 ms 1408 KB Output is correct
8 Correct 10 ms 1408 KB Output is correct
9 Correct 9 ms 1280 KB Output is correct
10 Correct 9 ms 1408 KB Output is correct
11 Correct 9 ms 1408 KB Output is correct
12 Correct 9 ms 1408 KB Output is correct
13 Correct 10 ms 1408 KB Output is correct
14 Correct 10 ms 1280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 1152 KB Output is correct
2 Correct 9 ms 1408 KB Output is correct
3 Correct 10 ms 1408 KB Output is correct
4 Correct 9 ms 1280 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 5 ms 1024 KB Output is correct
7 Correct 6 ms 1024 KB Output is correct
8 Correct 7 ms 1024 KB Output is correct
9 Correct 6 ms 1024 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 6 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1024 KB Output is correct
2 Correct 8 ms 1024 KB Output is correct
3 Correct 7 ms 1024 KB Output is correct
4 Correct 8 ms 1024 KB Output is correct
5 Correct 6 ms 1024 KB Output is correct
6 Correct 7 ms 1024 KB Output is correct
7 Correct 6 ms 1024 KB Output is correct
8 Correct 8 ms 1024 KB Output is correct
9 Correct 7 ms 1024 KB Output is correct
10 Correct 6 ms 1024 KB Output is correct
11 Correct 5 ms 1024 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 592 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 293 ms 1280 KB Output is correct
33 Correct 515 ms 1656 KB Output is correct
34 Correct 670 ms 1476 KB Output is correct
35 Correct 10 ms 1408 KB Output is correct
36 Correct 11 ms 1408 KB Output is correct
37 Correct 11 ms 1408 KB Output is correct
38 Correct 11 ms 1408 KB Output is correct
39 Correct 10 ms 1408 KB Output is correct
40 Correct 10 ms 1408 KB Output is correct
41 Correct 10 ms 1408 KB Output is correct
42 Correct 11 ms 1280 KB Output is correct
43 Correct 8 ms 1280 KB Output is correct
44 Correct 10 ms 1408 KB Output is correct
45 Correct 14 ms 1408 KB Output is correct
46 Correct 12 ms 1408 KB Output is correct
47 Correct 9 ms 1408 KB Output is correct
48 Correct 9 ms 1408 KB Output is correct
49 Correct 844 ms 1276 KB Output is correct
50 Correct 8 ms 1140 KB Output is correct
51 Correct 9 ms 1152 KB Output is correct
52 Correct 11 ms 1520 KB Output is correct
53 Correct 10 ms 1408 KB Output is correct
54 Correct 10 ms 1408 KB Output is correct
55 Correct 10 ms 1408 KB Output is correct
56 Correct 10 ms 1408 KB Output is correct
57 Correct 10 ms 1408 KB Output is correct
58 Correct 9 ms 1280 KB Output is correct
59 Correct 9 ms 1408 KB Output is correct
60 Correct 9 ms 1408 KB Output is correct
61 Correct 9 ms 1408 KB Output is correct
62 Correct 10 ms 1408 KB Output is correct
63 Correct 10 ms 1280 KB Output is correct
64 Correct 11 ms 1152 KB Output is correct
65 Correct 9 ms 1408 KB Output is correct
66 Correct 10 ms 1408 KB Output is correct
67 Correct 9 ms 1280 KB Output is correct
68 Correct 1 ms 512 KB Output is correct
69 Correct 5 ms 1024 KB Output is correct
70 Correct 6 ms 1024 KB Output is correct
71 Correct 7 ms 1024 KB Output is correct
72 Correct 6 ms 1024 KB Output is correct
73 Correct 2 ms 640 KB Output is correct
74 Correct 6 ms 1024 KB Output is correct
75 Correct 470 ms 1408 KB Output is correct
76 Correct 564 ms 1532 KB Output is correct
77 Correct 739 ms 1608 KB Output is correct
78 Correct 759 ms 1608 KB Output is correct
79 Correct 739 ms 1608 KB Output is correct
80 Correct 10 ms 1408 KB Output is correct
81 Correct 12 ms 1408 KB Output is correct
82 Correct 12 ms 1408 KB Output is correct
83 Correct 11 ms 1408 KB Output is correct
84 Correct 12 ms 1408 KB Output is correct
85 Correct 11 ms 1408 KB Output is correct
86 Correct 13 ms 1408 KB Output is correct
87 Correct 10 ms 1408 KB Output is correct
88 Correct 16 ms 1408 KB Output is correct
89 Correct 11 ms 1408 KB Output is correct
90 Correct 22 ms 1408 KB Output is correct
91 Correct 20 ms 1408 KB Output is correct
92 Correct 39 ms 1408 KB Output is correct
93 Correct 42 ms 1408 KB Output is correct
94 Correct 39 ms 1408 KB Output is correct
95 Correct 43 ms 1484 KB Output is correct
96 Correct 161 ms 1400 KB Output is correct
97 Correct 623 ms 1532 KB Output is correct
98 Correct 978 ms 1532 KB Output is correct
99 Correct 1044 ms 1528 KB Output is correct
100 Correct 834 ms 1152 KB Output is correct