답안 #964602

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
964602 2024-04-17T07:39:54 Z kilkuwu 육각형 영역 (APIO21_hexagon) C++17
36 / 100
51 ms 85184 KB
#include "hexagon.h"

#include <bits/stdc++.h>

template <int md>
struct Modular {
  int v;

  constexpr Modular() : v(0) {}

  template <typename T>
  static inline int normalize(const T& x) {
    int res = -md <= x && x < md ? static_cast<int>(x) : static_cast<int>(x % md);
    return res + (res < 0) * md;
  }
  
  static constexpr int mod() {
    return md;
  }

  template <typename U>
  Modular(const U& x) : v(normalize(x)) {}

  const int& operator()() const { return v; }

  template <typename U>
  explicit operator U() const {
    return static_cast<U>(v);
  }

  using M = Modular;

  constexpr static inline M _raw(int x) {
    static_assert(x >= 0 && x < md);
    M res;
    res.v = x;
    return res;
  }

  template <typename U>
  friend std::enable_if_t<std::is_integral_v<U>, M> power(M b, U e) {
    assert(e >= 0);
    M ans = 1;
    while (e) {
      if (e & 1) ans *= b;
      b *= b;
      e >>= 1;
    }
    return ans;
  }

  M inv() const {
    M res = power(*this, md - 2);
    return res;
  }

  M& operator+=(const M& y) { return v += y.v, v -= (v >= md) * md, *this; }
  M& operator-=(const M& y) { return v -= y.v, v += (v < 0) * md, *this; }
  M& operator*=(const M& y) { return v = (int64_t) v * y.v % md, *this; }
  M& operator/=(const M& y) { return *this *= y.inv(); }

  M& operator++() { return *this += _raw(1); }
  M& operator--() { return *this -= _raw(1); }

  M operator++(int) {
    M res(*this);
    return *this += _raw(1), res;
  }

  M operator--(int) {
    M res(*this);
    return *this -= _raw(1), res;
  }

  M operator-() const { return M(-v); }

  friend bool operator==(const M& x, const M& y) { return x.v == y.v; }
  friend bool operator<(const M& x, const M& y) { return x.v < y.v; }
  friend bool operator>(const M& x, const M& y) { return x.v > y.v; }
  friend bool operator<=(const M& x, const M& y) { return x.v <= y.v; }
  friend bool operator>=(const M& x, const M& y) { return x.v >= y.v; }
  friend bool operator!=(const M& x, const M& y) { return x.v != y.v; }

  template <typename Istream>
  friend Istream& operator>>(Istream& is, M& y) {
    int64_t x;
    is >> x;
    y.v = y.normalize(x);
    return is;
  }

  template <typename Ostream>
  friend Ostream& operator<<(Ostream& os, const M& y) {
    return os << y.v;
  }

  friend M operator+(const M& x, const M& y) { return M(x) += y; }
  friend M operator-(const M& x, const M& y) { return M(x) -= y; }
  friend M operator*(const M& x, const M& y) { return M(x) *= y; }
  friend M operator/(const M& x, const M& y) { return M(x) /= y; }
};

constexpr int md = 1e9 + 7;
using Mint = Modular<md>;

constexpr int A = 4200;
int grid[A][A];
std::bitset<A> is_road[A];

std::pair<int, int> q[A * A];
int sz = 0, fi = 0;
std::bitset<A> vis[A];
int dist[A][A];

const std::vector<std::pair<int, int>> dxy = {
  {-1, 0},
  {0, 1},
  {1, 1},
  {1, 0},
  {0, -1},
  {-1, -1}
};

int draw_territory(int N, int a, int b, std::vector<int> D, std::vector<int> L) {
#define int int64_t
  memset(grid, -1, sizeof(grid));
  if (N == 3) {
    Mint answer = 0;
    Mint size = L[0] + 1;
    Mint number = size * (size + 1) / 2;
    answer = size * (size + 1) * (size * 2 + 1) / 6; 
    answer -= number;
    answer = number * a + b * answer;
    return (int) answer;
  }

  
  int points_on_edges = 0;
  std::vector<std::pair<int, int>> instruction;

  for (int i = 0; i < N; i++) {
    points_on_edges += L[i];
    if (instruction.empty() || instruction.back().first != D[i]) {
      instruction.emplace_back(D[i], L[i]);
    } else {
      instruction.back().second += L[i];
    }
  }

  if (instruction.back().first == instruction.front().first) {
    instruction.front().second += instruction.back().second;
    instruction.pop_back();
  }

  std::vector<std::pair<int, int>> points;

  points.emplace_back(0, 0);

  for (int i = 0; i < N; i++) {
    auto [dx, dy] = dxy[instruction[i].first - 1];
    int mul = instruction[i].second;
    auto [x, y] = points.back();
    points.emplace_back(x + dx * mul, y + dy * mul);
  }

  int S2 = 0;
  points.emplace_back(points.front());

  for (int i = 0; i + 1 < (int) points.size(); i++) {
    S2 += points[i].first * points[i + 1].second - points[i + 1].first * points[i].second;
  }

  S2 = std::abs(S2);

  // S2 = 2a + b - 1
  // 2a = S2 - b + 1
  int a2 = S2 - points_on_edges + 2;
  a2 /= 2;

  a2 += points_on_edges;
  Mint ans = a2;
  ans *= a;
  return (int) ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 71256 KB Output is correct
2 Correct 15 ms 71256 KB Output is correct
3 Correct 13 ms 71324 KB Output is correct
4 Correct 12 ms 71260 KB Output is correct
5 Correct 11 ms 71256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 71428 KB Output is correct
2 Correct 12 ms 71260 KB Output is correct
3 Correct 11 ms 71256 KB Output is correct
4 Correct 9 ms 71356 KB Output is correct
5 Correct 12 ms 71260 KB Output is correct
6 Correct 13 ms 71356 KB Output is correct
7 Correct 12 ms 71264 KB Output is correct
8 Correct 12 ms 71256 KB Output is correct
9 Correct 12 ms 71512 KB Output is correct
10 Correct 12 ms 71256 KB Output is correct
11 Correct 12 ms 71260 KB Output is correct
12 Correct 13 ms 71452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 71352 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 71256 KB Output is correct
2 Correct 16 ms 71936 KB Output is correct
3 Correct 13 ms 71516 KB Output is correct
4 Correct 12 ms 71488 KB Output is correct
5 Correct 13 ms 71772 KB Output is correct
6 Correct 13 ms 72076 KB Output is correct
7 Correct 17 ms 73172 KB Output is correct
8 Correct 13 ms 71512 KB Output is correct
9 Correct 13 ms 71448 KB Output is correct
10 Correct 13 ms 71516 KB Output is correct
11 Correct 20 ms 74704 KB Output is correct
12 Correct 22 ms 74704 KB Output is correct
13 Correct 20 ms 74436 KB Output is correct
14 Correct 24 ms 74696 KB Output is correct
15 Correct 14 ms 71516 KB Output is correct
16 Correct 13 ms 71480 KB Output is correct
17 Correct 16 ms 71260 KB Output is correct
18 Correct 14 ms 71356 KB Output is correct
19 Correct 13 ms 71260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 71420 KB Output is correct
2 Correct 13 ms 71260 KB Output is correct
3 Correct 16 ms 71328 KB Output is correct
4 Correct 14 ms 72148 KB Output is correct
5 Correct 13 ms 71516 KB Output is correct
6 Correct 14 ms 71384 KB Output is correct
7 Correct 14 ms 71780 KB Output is correct
8 Correct 15 ms 71928 KB Output is correct
9 Correct 17 ms 73372 KB Output is correct
10 Correct 13 ms 71528 KB Output is correct
11 Correct 18 ms 71516 KB Output is correct
12 Correct 13 ms 71480 KB Output is correct
13 Correct 20 ms 74704 KB Output is correct
14 Correct 20 ms 74692 KB Output is correct
15 Correct 20 ms 74444 KB Output is correct
16 Correct 22 ms 74708 KB Output is correct
17 Correct 13 ms 71516 KB Output is correct
18 Correct 14 ms 71372 KB Output is correct
19 Correct 13 ms 71256 KB Output is correct
20 Correct 27 ms 77428 KB Output is correct
21 Correct 15 ms 72124 KB Output is correct
22 Correct 14 ms 71488 KB Output is correct
23 Correct 31 ms 78720 KB Output is correct
24 Correct 40 ms 84156 KB Output is correct
25 Correct 46 ms 84412 KB Output is correct
26 Correct 30 ms 78028 KB Output is correct
27 Correct 23 ms 75372 KB Output is correct
28 Correct 20 ms 74488 KB Output is correct
29 Correct 46 ms 85184 KB Output is correct
30 Correct 51 ms 85156 KB Output is correct
31 Correct 46 ms 84984 KB Output is correct
32 Correct 46 ms 84668 KB Output is correct
33 Correct 30 ms 78028 KB Output is correct
34 Correct 21 ms 74704 KB Output is correct
35 Correct 15 ms 71372 KB Output is correct
36 Correct 12 ms 71388 KB Output is correct
37 Correct 13 ms 71260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 71256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 71432 KB Output is correct
2 Correct 13 ms 71448 KB Output is correct
3 Correct 13 ms 71256 KB Output is correct
4 Correct 13 ms 71260 KB Output is correct
5 Incorrect 13 ms 71260 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 71360 KB Output isn't correct
2 Halted 0 ms 0 KB -