답안 #1016345

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1016345 2024-07-07T20:51:09 Z lacito 늑대인간 (IOI18_werewolf) C++14
0 / 100
85 ms 19536 KB
#include "werewolf.h"
using namespace std;
 
const int MAXN = 3000;
 
vector<int> g[MAXN];
vector<bool> vis1;
vector<bool> vis2;
int n, l, r;
 
void dfs(int v, bool human, vector<bool> &vis) {
  vis[v] = true;
  for (int u : g[v]) {
    if (!vis[u]) {
      if (human && u >= l || !human && u <= r) { // werewolf condition
        dfs(u, human, vis);
      }
    }
  }
}
 
 
int solve(int s, int e) {
      // check all the cities where we can transform
    vis1.assign(n, false);
    dfs(s, true, vis1);
    vis2.assign(n, false);
    dfs(e, true, vis2);
    for(int i = 0; i < vis1.size(); i++){
        if(vis1[i] && vis2[i]){
            return 1;
        }
    }
    
    return 0;
}
 
vector<int> check_validity(int N, vector<int> X, vector<int> Y,
                                  vector<int> S, vector<int> E,
                                  vector<int> L, vector<int> R) {
  for (int i = 0; i < X.size(); i++) {
    // road between X[i] and Y[i]
    g[X[i]].push_back(Y[i]);
    g[Y[i]].push_back(X[i]);
  }
  n = N;
  int Q = S.size();
  vector<int> A(Q);
  for (int i = 0; i < Q; ++i) {
    l = L[i];
    r = R[i];
    A[i] = solve(S[i], E[i]);
  }
  return A;
}

Compilation message

werewolf.cpp: In function 'void dfs(int, bool, std::vector<bool>&)':
werewolf.cpp:15:17: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   15 |       if (human && u >= l || !human && u <= r) { // werewolf condition
      |           ~~~~~~^~~~~~~~~
werewolf.cpp: In function 'int solve(int, int)':
werewolf.cpp:29:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for(int i = 0; i < vis1.size(); i++){
      |                    ~~^~~~~~~~~~~~~
werewolf.cpp: In function 'std::vector<int> check_validity(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
werewolf.cpp:41:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |   for (int i = 0; i < X.size(); i++) {
      |                   ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 85 ms 19536 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -