답안 #561696

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
561696 2022-05-13T11:33:33 Z raid 장난감 기차 (IOI17_train) C++17
28 / 100
271 ms 1512 KB
#include <bits/stdc++.h>
#include "train.h"

using namespace std;

const int MAXN = 5005;

vector<int> G[MAXN], Gt[MAXN], owner, fuel;
vector<int> res, viz, S;
vector<int> inset;
int N;

vector<int> who_wins( vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
  owner = a, fuel = r;
  
  for ( int i = 0; i < (int)u.size(); ++i ) {
	G[u[i]].push_back(v[i]);
	Gt[v[i]].push_back(u[i]);
  }
  N = a.size();
  res.resize(N), S.resize(N);
  queue<int> q;
  viz.assign(N, 0);
  inset.resize(N);
  for ( int i = 0; i < N; ++i ) inset[i] = 1;
  bool emp = false;
  while ( !emp ) {
    for ( int i = 0; i < N; ++i ) {
      if ( fuel[i] && inset[i] ) {
	    q.push(i);
	    S[i] = 1;
      }
    }
    while ( !q.empty() ) {
	  int u = q.front();
	  q.pop();
	  for ( auto v : Gt[u] ) {
	    ++viz[v];
	    if ( inset[v] && !S[v] && owner[v] == 1 ) {
          q.push(v);
	  	  S[v] = 1;
	    } else if ( inset[v] && !S[v] && owner[v] == 0 && viz[v] == (int)G[v].size() ) {
		  q.push(v);
		  S[v] = 1;
	    }
	  }
    }
    for ( int i = 0; i < N; ++i ) {
	  if ( inset[i] ) {
	    S[i] = 1 - S[i];
	    if ( S[i] ) q.push(i);
        viz[i] = 0;
	  }
    } 
	if ( q.empty() ) {
	  for ( int i = 0; i < N; ++i ) {
		res[i] = 1 - S[i];
	  }
	  break;
	}
    while ( !q.empty() ) {
 	  int u = q.front();
	  q.pop();
	  for ( auto v : Gt[u] ) {
	    ++viz[v];
	    if ( inset[v] && !S[v] && owner[v] == 0 ) {
          q.push(v);
		  S[v] = 1;
	    } else if ( inset[v] && !S[v] && owner[v] == 1 && viz[v] == (int)G[v].size() ) {
		  q.push(v);
		  S[v] = 1;
	    }
	  }
    }
	for ( int i = 0; i < N; ++i ) {
      if ( S[i] ) inset[i] = 0;
	}
  } 
  return res;
}
/*
int main() {
	int n, m;
	assert(2 == scanf("%d %d", &n, &m));

	vector<int> a(n), r(n), u(m), v(m);

	for(int i = 0; i < n; i++)
		assert(1 == scanf("%d", &a[i]));

	for(int i = 0; i < n; i++)
		assert(1 == scanf("%d", &r[i]));

	for(int i = 0; i < m; i++)
		scanf("%d", &u[i]);
	for ( int i = 0; i < m; ++i ) {
	  scanf("%d", &v[i]);
	}

	vector<int> res = who_wins(a, r, u, v);

	for(int i = 0; i < (int)res.size(); i++)
		printf(i ? " %d" : "%d", res[i]);
	printf("\n");

	return 0;
}*/
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1108 KB Output is correct
2 Correct 5 ms 1108 KB Output is correct
3 Correct 5 ms 1108 KB Output is correct
4 Correct 5 ms 1108 KB Output is correct
5 Correct 5 ms 1108 KB Output is correct
6 Correct 4 ms 1108 KB Output is correct
7 Correct 4 ms 1108 KB Output is correct
8 Correct 5 ms 1108 KB Output is correct
9 Correct 5 ms 1108 KB Output is correct
10 Correct 4 ms 1108 KB Output is correct
11 Correct 3 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Incorrect 1 ms 468 KB 3rd lines differ - on the 2nd token, expected: '0', found: '1'
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 104 ms 1500 KB Output is correct
2 Correct 192 ms 1504 KB Output is correct
3 Correct 271 ms 1492 KB Output is correct
4 Correct 7 ms 1492 KB Output is correct
5 Incorrect 9 ms 1492 KB 3rd lines differ - on the 11th token, expected: '0', found: '1'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1236 KB Output is correct
2 Correct 7 ms 1364 KB Output is correct
3 Correct 8 ms 1492 KB Output is correct
4 Correct 7 ms 1372 KB Output is correct
5 Correct 7 ms 1492 KB Output is correct
6 Correct 8 ms 1368 KB Output is correct
7 Correct 7 ms 1364 KB Output is correct
8 Correct 7 ms 1364 KB Output is correct
9 Correct 7 ms 1364 KB Output is correct
10 Correct 8 ms 1492 KB Output is correct
11 Correct 7 ms 1512 KB Output is correct
12 Correct 7 ms 1492 KB Output is correct
13 Correct 8 ms 1492 KB Output is correct
14 Correct 7 ms 1364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 1492 KB Output is correct
2 Correct 9 ms 1492 KB Output is correct
3 Correct 8 ms 1492 KB Output is correct
4 Correct 8 ms 1356 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 4 ms 1108 KB Output is correct
7 Correct 6 ms 1108 KB Output is correct
8 Correct 5 ms 1108 KB Output is correct
9 Correct 4 ms 1108 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 5 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1108 KB Output is correct
2 Correct 5 ms 1108 KB Output is correct
3 Correct 5 ms 1108 KB Output is correct
4 Correct 5 ms 1108 KB Output is correct
5 Correct 5 ms 1108 KB Output is correct
6 Correct 4 ms 1108 KB Output is correct
7 Correct 4 ms 1108 KB Output is correct
8 Correct 5 ms 1108 KB Output is correct
9 Correct 5 ms 1108 KB Output is correct
10 Correct 4 ms 1108 KB Output is correct
11 Correct 3 ms 1108 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Incorrect 1 ms 468 KB 3rd lines differ - on the 2nd token, expected: '0', found: '1'
20 Halted 0 ms 0 KB -