제출 #1349995

#제출 시각아이디문제언어결과실행 시간메모리
1349995SmuggingSpun길고양이 (JOI20_stray)C++20
100 / 100
27 ms13932 KiB
#include "Anthony.h"
#include<bits/stdc++.h>
using namespace std;
vector<int>Mark(int n, int m, int a, int b, vector<int>u, vector<int>v){
  vector<vector<int>>g(n);
  vector<int>send(m);
  for(int i = 0; i < m; i++){
    g[u[i]].push_back(i);
    g[v[i]].push_back(i);
  }
  if(a > 2){
    vector<int>h(n, -1);
    queue<int>q;
    q.push(h[0] = 0);
    while(!q.empty()){
      int x = q.front();
      q.pop();
      for(int& i : g[x]){
        int y = u[i] ^ v[i] ^ x;
        if(h[y] == -1){
          h[y] = h[x] + 1;
          q.push(y);
        }
      }
    }
    for(int i = 0; i < m; i++){
      if(h[u[i]] < h[v[i]]){
        swap(u[i], v[i]);
      }
      send[i] = (h[u[i]] + (h[u[i]] - 1 == h[v[i]] ? 2 : 0)) % 3;
    } 
  }
  else{
    const int pat[] = {1, 0, 1, 0, 0, 1};
    function<void(int, int, int)>dfs;
    dfs = [&] (int s, int p, int h){
      for(int& i : g[s]){
        int d = u[i] ^ v[i] ^ s;
        if(d != p){
          send[i] = pat[h];
          dfs(d, s, g[d].size() < 3 ? (h + 1) % 6 : pat[h]);
        }
      }
    };
    dfs(0, 0, 0);
  }
  return send;
}
#include "Catherine.h"
#include<bits/stdc++.h>
using namespace std;
int subtask_id;
namespace sub1234{
  int Move(vector<int>y){
    vector<int>ve;
    for(int i = 0; i < 3; i++){
      if(y[i] > 0){
        ve.push_back(i);
      }
    }
    if(ve.size() == 1){
      return ve[0];
    }
    return (ve[0] + 2) % 3 == ve[1] ? ve[1] : ve[0];
  }
}
namespace sub567{
  int last = -1;
  bool have_dir = false;
  vector<int>per;
  const int pat[] = {1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1};
  int Move(vector<int>y){
    int degree = y[0] + y[1] + int(last != -1);
    if(degree > 2){
      have_dir = true;
      if(last != -1 && y[last] == 0){
        return -1;
      }
      return last != -1 ? (last ^= 1) : last = y[0] == 1 ? 0 : 1;
    }
    if(have_dir){
      return last = y[0] == 1 ? 0 : 1;
    }
    if(degree == 1){
      have_dir = true;
      if(y[0] == 0 && y[1] == 0){
        return -1;
      }
      return last = y[0] == 1 ? 0 : 1;
    }
    if(last == -1){
      if(y[0] == 1 && y[1] == 1){
        per = {0, last = 1};
      }
      else{
        last = y[0] == 2 ? 0 : 1;
        per = {last, last};
      }
      return last;
    }
    if(per.size() == 4){
      per.push_back(y[0] == 1 ? 0 : 1);
      bool go_down = false;
      for(int i = 0; i < 6; i++){
        go_down = true;        
        for(int j = 0; j < 5; j++){
          if(per[j] != pat[i + j]){
            go_down = false;
            break;
          }
        }
        if(go_down){
          break;
        }
      }
      have_dir = true;
      if(go_down){
        return -1;
      }
      return last = y[0] == 1 ? 0 : 1;
    }
    per.push_back(last = y[0] == 1 ? 0 : 1);
    return last;
  }
}
void Init(int a, int b){
  subtask_id = a > 2 ? 4 : 7;
}
int Move(vector<int>y){
  if(subtask_id == 4){
    return sub1234::Move(y);
  }
  return sub567::Move(y);
}
#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...