제출 #1194981

#제출 시각아이디문제언어결과실행 시간메모리
1194981yellowtoad길고양이 (JOI20_stray)C++20
89 / 100
44 ms13896 KiB
#include "Anthony.h"
#include <iostream>
#include <vector>
#include <queue>
#define f first
#define s second
using namespace std;

namespace {

int FunctionExample(int i, int A) {
  return i % A;
}

vector<pair<int,int>> edge[20010];
vector<int> ans, a = {0,0,1,0,1,1};
int st[2] = {1,3}, dist[20010], vis[20010];
queue<int> q;

}  // namespace

void dfs(int u, int v, int cnt, int lst) {
  for (int i = 0; i < edge[u].size(); i++) {
    if (edge[u][i].f != v) {
      if ((u == 0) || (edge[u].size() > 2)) {
        ans[edge[u][i].s] = 1-lst;
        dfs(edge[u][i].f,u,st[1-lst],1-lst);
      } else {
        ans[edge[u][i].s] = a[cnt];
        dfs(edge[u][i].f,u,(cnt+1)%6,a[cnt]);
      }
    }
  }
}

std::vector<int> Mark(int n, int m, int A, int B,
                      std::vector<int> U, std::vector<int> V) {
  ans.resize(m);
  for (int i = 0; i < m; i++) edge[U[i]].push_back({V[i],i}), edge[V[i]].push_back({U[i],i});
  if (A == 2) {
    dfs(0,-1,0,0);
    return ans;
  } else {
    q.push(0);
    for (int i = 1; i < n; i++) dist[i] = 1e9;
    while (q.size()) {
      int u = q.front();
      q.pop();
      if (vis[u]) continue;
      vis[u] = 1;
      for (int i = 0; i < edge[u].size(); i++) {
        if (dist[edge[u][i].f] > dist[u]+1) {
          dist[edge[u][i].f] = dist[u]+1;
          q.push(edge[u][i].f);
        }
      }
    }
    for (int i = 0; i < m; i++) {
      if (dist[U[i]] == dist[V[i]]) ans[i] = (dist[U[i]]+1)%3;
      else ans[i] = min(dist[U[i]],dist[V[i]])%3;
    }
  }
  return ans;
}
#include "Catherine.h"
#include <iostream>
#include <vector>
using namespace std;

namespace {

bool first, found;
int freq[2], lst, MODE;
vector<int> a;
vector<vector<int>> ok = {
  {0, 1, 1, 0, 1},
  {0, 0, 1, 1, 0},
  {1, 0, 0, 1, 1},
  {0, 1, 0, 0, 1},
  {1, 0, 1, 0, 0},
  {1, 1, 0, 1, 0}
};

}  // namespace

void Init(int A, int B) {
  MODE = A;
  first = 1; found = 0;
  freq[0] = freq[1] = 0;
}

int Move(std::vector<int> Y) {
  if (MODE == 2) {
    vector<int> y;
    for (int i = 0; i < Y.size(); i++) for (int j = 1; j <= Y[i]; j++) y.push_back(i);
    if (first) {
      first = 0;
      if (y.size() == 2) {
        a = y;
        lst = y[1];
        return lst;
      } else {
        found = 1;
        freq[0] = freq[1] = 0;
        for (int i = 0; i < y.size(); i++) freq[y[i]]++;
        if (freq[0] == 1) {
          lst = 0;
          return lst;
        } else {
          lst = 1;
          return lst;
        }
      }
    } else {
      if (found) {
        if (y.size() == 1) {
          lst = y[0];
          return y[0];
        } else {
          lst = 1-lst;
          return lst;
        }
      } else {
        if (y.size() == 0) {
          found = 1;
          return -1;
        } else if (y.size() == 1) {
          a.push_back(y[0]);
          if (a.size() == 5) {
            found = 1;
            for (int i = 0; i < 6; i++) {
              if (a == ok[i]) {
                goto skip;
              }
            }
            return -1;
            skip:;
            lst = y[0];
            return lst;
          } else {
            lst = y[0];
            return lst;
          }
        } else {
          y.push_back(lst);
          freq[0] = freq[1] = 0;
          for (int i = 0; i < y.size(); i++) freq[y[i]]++;
          found = 1;
          if (freq[lst] == 1) return -1;
          else {
            lst = 1-lst;
            return lst;
          }
        }
      }
    }
  } else {
    if ((Y[0] == 0) && (Y[1] == 0)) return 2;
    else if ((Y[0] == 0) && (Y[2] == 0)) return 1;
    else if ((Y[1] == 0) && (Y[2] == 0)) return 0;
    else if (Y[0] == 0) return 1;
    else if (Y[1] == 0) return 2;
    else return 0;
  }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...