Submission #395584

#TimeUsernameProblemLanguageResultExecution timeMemory
395584idk321Toy Train (IOI17_train)C++11
Compilation error
0 ms0 KiB
#include "train.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 5000; set<int> adj[N]; vector<int> a; vector<int> r; vector<int> u; vector<int> v; bool ignore[N]; int in[N]; int up[N]; int ctime = 0; bool goodA[N]; bool goodB[N]; vector<int> comps; vector<int> st; bool onSt[N]; void dfs(int node) { ctime++; in[node] = ctime; st.push_back(node); onSt[node] = true; for (int next : adj[node]) { if (ignore[next]) continue; if (next == node && r[node]) { goodA[node] = true; } if (next == node) goodB[node] = true; if (in[next] == 0) { dfs(next); up[node] = min(up[node], up[next]); } else if (onSt[next]) { up[node] = min(up[node], in[next]); } } if (in[node] == up[node]) { vector<int> comp; while (st.back() != node) { onSt[st.back()] = false; if (r[st.back()]) goodA[st.back()] = true; goodB[st.back()] = true; comp.push_back(st.back()); st.pop_back(); } comp.push_back(node); st.pop_back(); onSt[node] = false; if (comp.size() > 1 && r[node]) { goodA[node] = true; } if (comp.size() > 1) goodB[node] = true; } } bool vis[N]; bool reachGoodA(int node) { if (goodA[node]) return true; vis[node] = true; bool ok = false; for (int next : adj[node]) { if (vis[next]) continue; ok = ok || reachGoodA(next); } return ok; } bool reachGoodB(int node) { if (goodB[node]) return true; vis[node] = true; bool ok = false; for (int next : adj[node]) { if (vis[next]) continue; ok = ok || reachGoodB(next); } return ok; } std::vector<int> who_wins(std::vector<int> A, std::vector<int> R, std::vector<int> U, std::vector<int> V) { a = A; r = R; u = U; v = V; int n = a.size(); int m = u.size(); bool simple = true; for (int i = 0; i < m; i++) { if (!(v[i] == u[i] || v[i] == u[i] + 1)) simple = false; adj[u[i]].insert(v[i]); } std::vector<int> res(a.size()); bool allA = true; bool allB = true; for (int i = 0; i < n; i++) { if (a[i] == 1) allB = false; if (a[i] == 0) allA = false; } //cout << simple << endl; if (simple) { for (int i = 0; i < n; i++) { int cur = i; bool good = false; int travelled = 0; while (travelled < n) { if (a[cur] == 1) { if (r[cur] == 1) { if (adj[cur].find(cur) != adj[cur].end()) { good = true; break; } } for (int next : adj[cur]) { if (next != cur) { cur = next; break; } } } else { if (r[cur] != 1) { if (adj[cur].find(cur) != adj[cur].end()) { break; } } for (int next : adj[cur]) { if (next != cur) { cur = next; break; } } } travelled++; } if (r[cur]) good = true; res[i] = good; } return res; } else if (allA) { for (int i = 0; i < n; i++) { if (!in[i]) dfs(i); } for (int i = 0; i < n; i++) res[i] = reachGoodA(i); return res; } else if (allB) { for (int i = 0; i < n; i++) if (r[i]) ignore[i] = true; for (int i = 0; i < n; i++) { if (!ignore[i] && !in[i]) dfs(i); } for (int i = 0; i < n; i++) res[i] = reachGoodB(i); return res; } return res; }

Compilation message (stderr)

train.cpp:18:5: error: 'int ctime' redeclared as different kind of entity
   18 | int ctime = 0;
      |     ^~~~~
In file included from /usr/include/c++/9/ctime:42,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:49,
                 from train.cpp:2:
/usr/include/time.h:142:14: note: previous declaration 'char* ctime(const time_t*)'
  142 | extern char *ctime (const time_t *__timer) __THROW;
      |              ^~~~~
train.cpp: In function 'void dfs(int)':
train.cpp:30:10: warning: ISO C++ forbids incrementing a pointer of type 'char* (*)(const time_t*) throw ()' {aka 'char* (*)(const long int*)'} [-Wpointer-arith]
   30 |     ctime++;
      |          ^~
train.cpp:30:10: error: lvalue required as increment operand
train.cpp:31:16: error: invalid conversion from 'char* (*)(const time_t*) throw ()' {aka 'char* (*)(const long int*)'} to 'int' [-fpermissive]
   31 |     in[node] = ctime;
      |                ^~~~~
      |                |
      |                char* (*)(const time_t*) throw () {aka char* (*)(const long int*)}
train.cpp:36:13: error: reference to 'ignore' is ambiguous
   36 |         if (ignore[next]) continue;
      |             ^~~~~~
In file included from /usr/include/c++/9/functional:54,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:71,
                 from train.cpp:2:
/usr/include/c++/9/tuple:1648:47: note: candidates are: 'constexpr const std::_Swallow_assign std::ignore'
 1648 |   _GLIBCXX17_INLINE constexpr _Swallow_assign ignore{};
      |                                               ^~~~~~
train.cpp:14:6: note:                 'bool ignore [5000]'
   14 | bool ignore[N];
      |      ^~~~~~
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:201:47: error: reference to 'ignore' is ambiguous
  201 |         for (int i = 0; i < n; i++) if (r[i]) ignore[i] = true;
      |                                               ^~~~~~
In file included from /usr/include/c++/9/functional:54,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:71,
                 from train.cpp:2:
/usr/include/c++/9/tuple:1648:47: note: candidates are: 'constexpr const std::_Swallow_assign std::ignore'
 1648 |   _GLIBCXX17_INLINE constexpr _Swallow_assign ignore{};
      |                                               ^~~~~~
train.cpp:14:6: note:                 'bool ignore [5000]'
   14 | bool ignore[N];
      |      ^~~~~~
train.cpp:205:18: error: reference to 'ignore' is ambiguous
  205 |             if (!ignore[i] && !in[i]) dfs(i);
      |                  ^~~~~~
In file included from /usr/include/c++/9/functional:54,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:71,
                 from train.cpp:2:
/usr/include/c++/9/tuple:1648:47: note: candidates are: 'constexpr const std::_Swallow_assign std::ignore'
 1648 |   _GLIBCXX17_INLINE constexpr _Swallow_assign ignore{};
      |                                               ^~~~~~
train.cpp:14:6: note:                 'bool ignore [5000]'
   14 | bool ignore[N];
      |      ^~~~~~