QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#394942 | #1364. Condorcet | rania__ | WA | 1ms | 3932kb | C++20 | 3.2kb | 2024-04-20 22:52:38 | 2024-04-20 22:52: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;
if (mat[i][j] >= mat[j][i]) {
// cout << i << " " << j << " " << mat[i][j] - mat[j][i] + 1 << endl;
}
}
}
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});
// cout << B << " " << A << " " << w << endl;
}
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;
}
cyc.push_back(ww);
return;
}
}
vis[node] = 2;
};
bool valid = 1;
for (int i = 0; i < n; i++) {
if ( vis[i])
continue;
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: 1ms
memory: 3664kb
input:
3 3 ABC 1 BCA 1 CAB 1
output:
0
result:
ok single line: '0'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3564kb
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: 0
Accepted
time: 1ms
memory: 3460kb
input:
3 6 BCA 41 ABC 103 ACB 49 BAC 79 CAB 52 CBA 57
output:
66
result:
ok single line: '66'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
3 6 CBA 49 BAC 50 ABC 64 ACB 98 BCA 35 CAB 70
output:
69
result:
ok single line: '69'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
3 5 BCA 102 BAC 89 ACB 77 CAB 43 ABC 69
output:
91
result:
ok single line: '91'
Test #6:
score: 0
Accepted
time: 1ms
memory: 3696kb
input:
5 120 DEABC 125 DACBE 207 DABCE 167 BCDEA 186 BCEDA 118 AEBDC 175 CDBEA 252 CDEBA 208 ABCED 131 ADEBC 114 ABECD 132 CDAEB 365 BEADC 162 BEDAC 169 ECDBA 242 ECDAB 137 CEADB 215 EBDAC 179 EBADC 222 DABEC 248 EDBAC 177 DBEAC 207 EDACB 157 ECABD 67 DCBEA 143 BDECA 174 DACEB 195 AECDB 242 ABCDE 156 CABDE...
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 1ms
memory: 3576kb
input:
4 22 CDAB 27 DABC 114 CADB 126 BCDA 51 CABD 58 BACD 16 DACB 87 DCAB 25 BADC 88 CBDA 31 ACBD 82 BCAD 45 CBAD 58 ADCB 26 DBCA 20 DBAC 85 ABCD 27 ADBC 28 BDAC 17 DCBA 44 ABDC 60 ACDB 11
output:
125
result:
ok single line: '125'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
4 22 ADCB 36 CADB 42 ABDC 82 DACB 52 BCAD 112 CBAD 69 ADBC 89 DBCA 15 CABD 64 CDBA 31 CBDA 53 BDCA 51 BDAC 56 ACDB 54 CDAB 15 DCAB 29 ACBD 36 ABCD 29 DABC 69 BCDA 62 DCBA 48 DBAC 33
output:
0
result:
ok single line: '0'
Test #9:
score: 0
Accepted
time: 1ms
memory: 3832kb
input:
4 22 CDBA 32 BCAD 94 ADBC 39 ACBD 71 ABCD 55 CBAD 65 DBCA 39 DBAC 81 DABC 38 ACDB 13 BDAC 58 BADC 94 CBDA 55 DCAB 90 BDCA 31 ADCB 63 BCDA 23 DCBA 45 ABDC 35 CDAB 52 CADB 14 CABD 32
output:
56
result:
ok single line: '56'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3676kb
input:
4 22 CBAD 55 BADC 87 DACB 64 CDAB 57 DBAC 88 CADB 71 ABDC 54 DCAB 72 CABD 32 ADBC 25 ACBD 33 BDAC 58 DCBA 67 CBDA 34 ABCD 12 BCAD 110 ADCB 42 BACD 39 BDCA 41 DABC 39 DBCA 56 BCDA 42
output:
59
result:
ok single line: '59'
Test #11:
score: -100
Wrong Answer
time: 0ms
memory: 3932kb
input:
5 105 BCDAE 47 ACEDB 42 BDEAC 48 EBDAC 69 DBCEA 177 BECDA 86 BCEAD 42 EBADC 95 ACBDE 85 CABED 70 BCEDA 66 ECDAB 82 CEADB 91 BECAD 78 BDECA 67 ABECD 38 BEDAC 51 BAEDC 76 EABCD 56 ABEDC 50 ADBEC 110 ECBAD 49 ECBDA 15 DBCAE 132 ECDBA 13 BEACD 15 CADBE 37 EBDCA 75 ADCBE 70 BEDCA 79 DCAEB 140 BAECD 61 DB...
output:
307
result:
wrong answer 1st lines differ - expected: '291', found: '307'