Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
34004 23级逯一鸣 【S】T1 C++ 运行超时 80 1000 MS 284 KB 1427 2024-11-01 15:12:48

Tests(16/20):


#include <iostream> #include <vector> using namespace std; using i64 = long long; constexpr int INF = 0x3f3f3f3f; int n, mn = INF; vector<int> curr, ans; vector<bool> vis; vector<vector<int>> round, magic; void solve(int idx, int mana, int lst = -1, int rnd = 0) { if (mana < 0 || rnd > mn) return; else if (idx >= n) { if (mn > rnd) { mn = rnd; ans = curr; } return; } for (int i = 0; i < n; ++i) { if (vis[i]) continue; vis[i] = true; curr.emplace_back(i); solve(idx + 1, mana - (lst != -1 ? magic[lst][i] : 0), i, rnd + (lst != -1 ? round[lst][i] : 0)); curr.pop_back(); vis[i] = false; } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int m; cin >> n >> m; round.resize(n); magic.resize(n); vis.resize(n); curr.reserve(n); for (auto& row : round) { row.resize(n); for (int& x : row) cin >> x; } for (auto& row : magic) { row.resize(n); for (int& x : row) cin >> x; } solve(0, m); if (ans.empty()) cout << "-1\n"; else { cout << mn << '\n'; for (int x : ans) cout << x + 1 << ' '; } return 0; }


测评信息: