답안 #1077949

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1077949 2024-08-27T10:55:28 Z TB_ 장난감 기차 (IOI17_train) C++17
11 / 100
8 ms 2652 KB
#include <bits/stdc++.h>

using namespace std;
#define ll long long 
#define fo(i, n) for(ll i = 0; i<(n); i++)
#define F first 
#define S second 
#define pb push_back 
#define deb(x) cout << #x << " = " << (x) << endl
#define deb2(x, y) cout << #x << " = " << (x)  << ", " << #y << " = " << (y) << endl

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pl;
typedef vector<pl> vpl;

ll n;
vl topo;
int seen[6000];
vvl adj(6000);
vvl adjr(6000);
vvl adjR(6000);

void toposort(int u){
    if(seen[u]) return;
    seen[u] = 1;
    for(auto &v : adjr[u]){
        toposort(v);
    }
    topo.pb(u);
}

int c = 0;

int dfs(int u){
    if(seen[u]) return 0;
    seen[u] = c;
    ll ans = 1;
    for(auto &v : adj[u]){
        ans+=dfs(v);
    }
    return ans;
}

vector<int> res;

void dfs2(int u){
    if(!res[u]) return;
    res[u] = 0;
    for(auto &v : adjR[u]){
        dfs2(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();
    ll m = u.size();

    vl selfEdge(n+1, 0);
    fo(i, m){
        if(u[i] == v[i]) selfEdge[u[i]] = !r[v[i]];
        else{
            if(!r[u[i]] && !r[v[i]])adj[u[i]].pb(v[i]);
            if(!r[u[i]] && !r[v[i]])adjr[v[i]].pb(u[i]);
            adjR[v[i]].pb(u[i]);
        }
    }

    memset(seen, 0, sizeof(seen));
	fo(i, n){
        if(seen[i]) continue;
        toposort(i);
    }
    reverse(all(topo));
    memset(seen, 0, sizeof(seen));
    vl good;
    fo(i, n){
        if(seen[topo[i]]) continue;
        c++;
        ll siz = dfs(topo[i]);
        // deb2(topo[i], siz);
        if(siz>1 || selfEdge[topo[i]]) good.pb(topo[i]);
    }
    res.assign(n, 1);
    fo(i, good.size()){
        // deb(good[i]);
        dfs2(good[i]);
    }

	return res;
}

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:5:33: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 | #define fo(i, n) for(ll i = 0; i<(n); i++)
      |                                 ^
train.cpp:89:5: note: in expansion of macro 'fo'
   89 |     fo(i, good.size()){
      |     ^~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 1628 KB 3rd lines differ - on the 14th token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 860 KB 3rd lines differ - on the 2nd token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2652 KB Output is correct
2 Correct 5 ms 2396 KB Output is correct
3 Correct 6 ms 2396 KB Output is correct
4 Incorrect 6 ms 2140 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1628 KB Output is correct
2 Correct 6 ms 2140 KB Output is correct
3 Correct 8 ms 2396 KB Output is correct
4 Correct 6 ms 2136 KB Output is correct
5 Correct 7 ms 2432 KB Output is correct
6 Correct 7 ms 2248 KB Output is correct
7 Correct 6 ms 2396 KB Output is correct
8 Correct 6 ms 2140 KB Output is correct
9 Correct 4 ms 1624 KB Output is correct
10 Correct 5 ms 1796 KB Output is correct
11 Correct 5 ms 1884 KB Output is correct
12 Correct 6 ms 1884 KB Output is correct
13 Correct 8 ms 2564 KB Output is correct
14 Correct 8 ms 2232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 2648 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 1628 KB 3rd lines differ - on the 14th token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -