QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#422310#7303. City UniteddayuxTL 0ms0kbC++141.6kb2024-05-27 11:21:292024-05-27 11:21:29

Judging History

你现在查看的是最新测评结果

  • [2024-05-27 11:21:29]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-05-27 11:21:29]
  • 提交

answer

#include <bits/stdc++.h>

const int maxn = 50, maxd = 13, mod = 4;

std::array<int, maxn + 1> e;
std::array<std::array<std::array<int, 1 << maxd>, 1 << maxd>, 2> f;

void inc(int &x, int y) {
  if ((x += y) >= mod) {
    x -= mod;
  }
}

int main() {
  std::cin.tie(nullptr)->sync_with_stdio(false);

  int n, m;
  std::cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int u, v;
    std::cin >> u >> v;
    e[std::max(u, v)] |= 1 << (std::abs(u - v) - 1);
  }

  f[0 & 1][0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int S = 0; S < (1 << maxd); ++S) {
      for (int T = S; ; T = (T - 1) & S) {
        int R = S ^ T;
        f[i & 1][T][R] = 0;
        if (T == 0) {
          break;
        }
      }
    }
    for (int S = 0; S < (1 << maxd); ++S) {
      for (int T = S; ; T = (T - 1) & S) {
        int R = S ^ T;
	    if (f[(i - 1) & 1][T][R] == 0) {
		  continue;
	    }
        inc(f[i & 1][(T << 1) & ((1 << maxd) - 1)][(R << 1) & ((1 << maxd) - 1)], f[(i - 1) & 1][T][R]);
        if ((e[i] & R) == 0) {
          inc(f[i & 1][(T << 1 | 1) & ((1 << maxd) - 1)][(R << 1) & ((1 << maxd) - 1)], f[(i - 1) & 1][T][R]);
        }
        if ((e[i] & T) == 0) {
          inc(f[i & 1][(T << 1) & ((1 << maxd) - 1)][(R << 1 | 1) & ((1 << maxd) - 1)], f[(i - 1) & 1][T][R]);
        }
        if (T == 0) {
          break;
        }
      }
    }
  }

  int ans = 0;
  for (int S = 0; S < (1 << maxd); ++S) {
    for (int T = S; ; T = (T - 1) & S) {
      inc(ans, f[n & 1][T][S ^ T]);
      if (T == 0) {
        break;
      }
    }
  }
  std::cout << ans / 2 << "\n";
  return 0;
}

詳細信息

Test #1:

score: 0
Time Limit Exceeded

input:

3 2
1 2
2 3

output:


result: