답안 #297192

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
297192 2020-09-11T10:47:23 Z Autoratch 장난감 기차 (IOI17_train) C++14
0 / 100
36 ms 1792 KB
#include "train.h"
#include <bits/stdc++.h>
using namespace std;

const int N = 5000;

int n,m;
vector<int> adj[N],rev[N];
bool sm[N],nxt[N],lop[N];
bool visited[N],loop[N];
stack<int> st;
int id[N],idx;
vector<int> tmp;
set<int> add[N];

void dfs(int u)
{
    if(visited[u]) return;
    visited[u] = true;
    for(int v : adj[u]) dfs(v);
    st.push(u);
}

void dfs2(int u)
{
    if(visited[u]) return;
    visited[u] = true;
    id[u] = idx;
    tmp.push_back(u);
    for(int v : rev[u]) dfs2(v);
}

void dfs3(int u)
{
    if(visited[u]) return;
    visited[u] = true;
    for(int v : add[u]) 
    {
        dfs3(v);
        lop[u]|=lop[v];
    }
}

std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) 
{
    n = a.size(),m = u.size();
    for(int i = 0;i < m;i++)
    {
        adj[u[i]].push_back(v[i]);
        rev[v[i]].push_back(u[i]);
        if(u[i]==v[i]) sm[u[i]] = true;
        else nxt[u[i]] = true;
    }
    for(int i = 0;i < n;i++) if(!visited[i]) dfs(i);
    for(int i = 0;i < n;i++) visited[i] = 0;
    for(int i = 0;i < n;i++)
    {
        for(int j : adj[i]) add[id[i]].insert(id[j]);
    }
    while(!st.empty())
    {
        int u = st.top();
        st.pop();
        if(visited[u]) continue;
        tmp.clear();
        dfs2(u);
        if(tmp.size()==1)
        {
            if(r[tmp[0]] and sm[tmp[0]]) lop[idx] = 1;
        }
        else
        {
            for(int x : tmp) if(r[x]) lop[idx] = 1;
        }
        idx++;
    }
    for(int i = 0;i < n;i++) visited[i] = false;
    for(int i = 0;i < n;i++) for(int x = 0;x < idx;x++) for(int y : add[x]) lop[x]|=lop[y];
//    for(int i = 0;i < n;i++) if(!visited[id[i]]) dfs3(id[i]);
    vector<int> ans(n);
    for(int i = 0;i < n;i++) ans[i] = lop[id[i]];
    /*
    for(int i = n-1;i >= 0;i--)
    {
        if(!nxt[i] and !sm[i]){ ans[i] = 0; continue; }
        if(a[i] and r[i] and sm[i]) ans[i] = 1;
        else if(a[i]) 
        {
            if(nxt[i]) ans[i] = ans[i+1];
            else ans[i] = 0;
        }
        else 
        {
            if(!r[i] and sm[i]) ans[i] = 0;
            else if(sm[i] and !nxt[i]) ans[i] = 1;
            else if(!nxt[i]) ans[i] = 0;
            else ans[i] = ans[i+1];
        }
    }*/
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 36 ms 1536 KB 3rd lines differ - on the 14th token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 768 KB 3rd lines differ - on the 8th token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 1792 KB Output is correct
2 Correct 34 ms 1792 KB Output is correct
3 Correct 30 ms 1792 KB Output is correct
4 Incorrect 12 ms 1792 KB 3rd lines differ - on the 13th token, expected: '1', found: '0'
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 1792 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 1792 KB 3rd lines differ - on the 2nd token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 36 ms 1536 KB 3rd lines differ - on the 14th token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -