QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#784881#9802. Light Up the GridlnkkerstTL 0ms0kbC++171.9kb2024-11-26 16:13:502024-11-29 22:55:26

Judging History

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

  • [2024-11-29 22:55:26]
  • 管理员手动重测本题所有提交记录
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-11-26 16:13:51]
  • 评测
  • 测评结果:0
  • 用时:1485ms
  • 内存:14584kb
  • [2024-11-26 16:13:50]
  • 提交

answer

#pragma GCC optimize(2)
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

#define int long long

void solve() {
  int t;
  vector<int> a(4);
  cin >> t;
  for (int i = 0; i < 4; ++i) {
    cin >> a[i];
  }
  vector<int> ans((1 << 16) + 1, 1e9);
  vector<vector<int>> ansa((1 << 16) + 1, vector<int>((1 << 4) + 1, 1e9));
  function<void(int, int, int)> dfs = [&](int state, int table, int val) {
    if (ansa[table][state] <= val) {
      return;
    }
    ansa[table][state] = val;
    ans[table] = min(ans[table], val);
    dfs(state ^ 0b1111, table | (1 << (state ^ 0b1111)), val + a[3]);
    for (int i = 0; i < 4; ++i) {
      int ns = state ^ (1 << i);
      int nt = table | (1 << ns);
      dfs(ns, nt, val + a[0]);
    }
    dfs(state ^ 0b1100, table | (1 << (state ^ 0b1100)), val + a[1]);
    dfs(state ^ 0b0011, table | (1 << (state ^ 0b0011)), val + a[1]);
    dfs(state ^ 0b1010, table | (1 << (state ^ 0b1010)), val + a[2]);
    dfs(state ^ 0b0101, table | (1 << (state ^ 0b0101)), val + a[2]);
  };
  dfs(0b1111, 0, 0);
  for (int i = 0; i < (1 << 16); ++i) {
    for (int j = i; j; j = (j - 1) & i) {
      ans[j] = min(ans[j], ans[i]);
    }
  }
  while (t--) {
    int n;
    cin >> n;
    int table = 0;
    for (int i = 1; i <= n; ++i) {
      string s0, s1;
      cin >> s0 >> s1;
      table |= 1 << stoi(s0 + s1, 0, 2);
    }
    cout << ans[table] << endl;
  }
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
}

详细

Test #1:

score: 0
Time Limit Exceeded

input:

2 1000 100 10 1
4
10
00

01
00

00
10

00
01
1
11
11

output:


result: