This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int l[22], r[22], c[22], l1[22], r1[22];
int qs[22];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n, m;
cin >> n >> m;
for (int i = 0;i < m;i++) {
cin >> l[i] >> r[i] >> c[i];
if (l[i] > r[i]) {
swap(l[i], r[i]);
}
}
int ans = n;
for (int i = 0;i < (1 << m);i++) {
int mx = 0;
memset(qs, 0, sizeof qs);
for (int j = 0;j < m;j++) {
l1[j] = l[j], r1[j] = r[j];
if (i & (1 << j)) {
swap(l1[j], r1[j]);
}
}
for (int j = 0;j < m;j++) {
if (l1[j] > r1[j]) {
qs[l1[j]]++;
qs[1]++;
qs[r1[j]]--;
}
else {
qs[l1[j]]++;
qs[r1[j]]--;
}
}
for (int i = 1;i <= n;i++) {
qs[i] += qs[i - 1];
mx = max(mx, qs[i]);
}
ans = min(ans, mx);
}
cout << ans << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |