# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1045999 |
2024-08-06T08:53:00 Z |
becaido |
Toy Train (IOI17_train) |
C++17 |
|
7 ms |
1884 KB |
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
using namespace std;
#ifdef WAIMAI
#include "grader.cpp"
#else
#include "train.h"
#endif
#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() {cout << '\n';}
template<typename T, typename...U>
void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);}
#else
#define debug(...) 7122
#endif
#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second
const int SIZE = 5005;
int n, m;
int sz[SIZE];
vector<int> adj[SIZE];
bool alice[SIZE], is[SIZE], self[SIZE], dp[SIZE], vs[SIZE];
struct SCC {
int n, dfcnt = 0, sccnt = 0;
vector<int> dfn, low, scc, st, ist;
vector<vector<int>> scc_adj;
SCC() {}
SCC(int n) : n(n) {
dfn = low = scc = ist = vector<int>(n + 1, 0);
scc_adj = vector<vector<int>>(n + 1, vector<int>());
}
void tarjan(int pos) {
dfn[pos] = low[pos] = ++dfcnt;
st.emplace_back(pos);
ist[pos] = 1;
for (int np : adj[pos]) {
if (dfn[np] == 0) {
tarjan(np);
low[pos] = min(low[pos], low[np]);
} else if (ist[np] == 1) {
low[pos] = min(low[pos], dfn[np]);
}
}
if (dfn[pos] == low[pos]) {
sccnt++;
while (1) {
int x = st.back();
ist[x] = 0;
scc[x] = sccnt;
st.pop_back();
if (x == pos) {
break;
}
}
}
}
void work() {
for (int i = 1; i <= n; i++) {
if (dfn[i] == 0) {
tarjan(i);
}
}
}
void build_adj() {
for (int i = 1; i <= n; i++) {
for (int j : adj[i]) {
if (scc[i] != scc[j]) {
scc_adj[scc[i]].emplace_back(scc[j]);
}
}
}
}
bool dfs(int pos) {
if (vs[pos]) return dp[pos];
vs[pos] = 1;
for (int np : scc_adj[pos]) dp[pos] |= dfs(np);
return dp[pos];
}
vector<int> cal() {
FOR (i, 1, n) sz[scc[i]]++;
FOR (i, 1, n) if (is[i] && (sz[scc[i]] > 1 || self[i])) dp[scc[i]] = 1;
FOR (i, 1, n) if (vs[i] == 0) dfs(i);
vector<int> ans;
FOR (i, 1, n) ans.pb(dp[scc[i]]);
return ans;
}
} g;
vector<int> who_wins(vector<int> a_, vector<int> r_, vector<int> u_, vector<int> v_) {
n = a_.size();
m = u_.size();
FOR (i, 1, n) {
alice[i] = a_[i - 1];
is[i] = r_[i - 1];
adj[i].clear();
self[i] = dp[i] = vs[i] = sz[i] = 0;
}
FOR (i, 0, m - 1) {
u_[i]++, v_[i]++;
if (u_[i] == v_[i]) self[u_[i]] = 1;
else adj[u_[i]].pb(v_[i]);
}
g = SCC(n);
g.work();
g.build_adj();
return g.cal();
}
/*
in1
2 4
0 1
1 0
0 0
0 1
1 0
1 1
out1
1 1
*/
Compilation message
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:108:41: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
108 | self[i] = dp[i] = vs[i] = sz[i] = 0;
| ~~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
1372 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
3rd lines differ - on the 8th token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1628 KB |
Output is correct |
2 |
Correct |
3 ms |
1884 KB |
Output is correct |
3 |
Correct |
4 ms |
1884 KB |
Output is correct |
4 |
Correct |
7 ms |
1628 KB |
Output is correct |
5 |
Correct |
4 ms |
1628 KB |
Output is correct |
6 |
Correct |
4 ms |
1628 KB |
Output is correct |
7 |
Correct |
4 ms |
1624 KB |
Output is correct |
8 |
Correct |
4 ms |
1628 KB |
Output is correct |
9 |
Correct |
3 ms |
1628 KB |
Output is correct |
10 |
Correct |
4 ms |
1460 KB |
Output is correct |
11 |
Correct |
3 ms |
1628 KB |
Output is correct |
12 |
Correct |
3 ms |
1532 KB |
Output is correct |
13 |
Correct |
3 ms |
1808 KB |
Output is correct |
14 |
Correct |
4 ms |
1628 KB |
Output is correct |
15 |
Correct |
4 ms |
1624 KB |
Output is correct |
16 |
Correct |
4 ms |
1624 KB |
Output is correct |
17 |
Correct |
6 ms |
1624 KB |
Output is correct |
18 |
Correct |
2 ms |
1372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
1372 KB |
3rd lines differ - on the 696th token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
1372 KB |
3rd lines differ - on the 2nd token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
1372 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |