QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#394936 | #1364. Condorcet | rania__ | WA | 0ms | 3816kb | C++20 | 3.0kb | 2024-04-20 22:35:37 | 2024-04-20 22:35:38 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
void doWork() {
int n, m;
cin >> n >> m;
vector<vector<int>> mat(n, vector<int>(n));
for (int i = 0; i < m; i++) {
string s;
cin >> s;
int vv;
cin >> vv;
for (int j = 0; j < n; j++) {
for (int k = j + 1; k < n; k++) {
mat[s[j] - 'A'][s[k] - 'A'] += vv;
}
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if ( i == j)
continue;
}
}
vector<vector<int>> all;
function<void(int, vector<int>)> rec = [&](int i, vector<int> cur) -> void {
if (i == n) {
all.push_back(cur);
return;
}
for (int j = 0; j < n; j++) {
if (i == j)
continue;
cur.push_back(j);
rec(i + 1, cur);
cur.pop_back();
}
};
rec(0, {});
int ans = 1e9;
for (auto &v: all) {
vector<vector<pair<int, int>>> adj(n);
int mx = 0;
for (int A = 0; A < n; A++) {
int B = v[A];
int w = mat[A][B] - mat[B][A] + 1;
mx = max(mx, w);
adj[B].push_back({A, w});
}
vector<int> vis(n);
vector<pair<int, int>> p(n);
vector<int> cyc;
function<void(int)> dfs = [&](int node) -> void {
vis[node] = 1;
for (auto[to, w]: adj[node]) {
if (!vis[to])
p[to].first = node, p[to].second = w, dfs(to);
else if (vis[to] == 1) {
int cur = node, ww = w;
while (cur != p[to].first) {
cyc.push_back(ww);
ww = p[cur].second;
cur = p[cur].first;
}
return;
}
}
vis[node] = 2;
};
bool valid = 1;
for (int i = 0; i < n; i++) {
if (!vis[i]) {
cyc.clear();
dfs(i);
std::sort(cyc.begin(), cyc.end());
int g2 = -1e9, g1 = 0;
for (int j: cyc)
if (j <= 0)
g2 = j;
else {
g1 = j;
}
if ((cyc.size() && (g2 == -1e9 || abs(g2) < g1))) {
valid = 0;
break;
}
}
}
if (valid){
ans = min(ans, mx);
}
}
cout << ans << '\n';
}
signed main() {
ios::sync_with_stdio(false);
cout.tie(nullptr);
cin.tie(nullptr);
// freopen("bisector.in","r",stdin);
// freopen("bisector.out","w",stdout);
int t = 1;
// cout << primes.size() << endl;
// cin >> t;
while (t--) {
doWork();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3816kb
input:
3 3 ABC 1 BCA 1 CAB 1
output:
0
result:
ok single line: '0'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
3 6 CAB 35 ACB 142 ABC 34 BCA 66 CBA 53 BAC 44
output:
49
result:
ok single line: '49'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3584kb
input:
3 6 BCA 41 ABC 103 ACB 49 BAC 79 CAB 52 CBA 57
output:
1000000000
result:
wrong answer 1st lines differ - expected: '66', found: '1000000000'