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>
#define ll long long
#define name "Arranging Tickets"
#define fi(i, a, b) for(int i = a; i <= b; ++i)
#define fid(i, a, b) for(int i = a; i >= b; --i)
#define maxn (int) (2e5 + 7)
using namespace std;
int n, m;
int d[maxn];
struct dl { int l, r, c; } a[maxn];
void solve() {
cin >> n >> m;
fi(i, 1, m) {
cin >> a[i].l >> a[i].r >> a[i].c;
if(a[i].l > a[i].r) swap(a[i].l, a[i].r);
assert(a[i].c == 1);
}
assert(n <= 20 && m <= 20);
auto go = [&](int l, int r) {
fi(i, l, r) d[i] ++;
};
int ans = 1e9;
fi(x, 0, (1 << m) - 1) {
fi(i, 1, n) d[i] = 0;
fi(i, 1, m) {
if((x >> (i - 1))&1) go(a[i].l, a[i].r - 1);
else go(1, a[i].l - 1), go(a[i].r, n);
}
ans = min(ans, *max_element(d + 1, d + 1 + n));
}
cout << ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
if(fopen(name".inp", "r")) {
freopen(name".inp", "r", stdin);
freopen(name".out", "w", stdout);
}
solve();
}
Compilation message (stderr)
arranging_tickets.cpp: In function 'int main()':
arranging_tickets.cpp:53:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
53 | freopen(name".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
arranging_tickets.cpp:54:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
54 | freopen(name".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |