# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
951714 | mocha | Alternating Current (BOI18_alternating) | C++14 | 20 ms | 2652 KiB |
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;
const int mx = 1e5+5;
int n, m;
struct Edge {
int fr, to;
int id;
} e[mx];
bool ans[mx];
bool cmp( Edge a, Edge b ) {
return a.fr == b.fr ? a.to < b.to : a.fr < b.fr;
}
int main() {
cin.tie(0);ios::sync_with_stdio(0);
cin >> n >> m;
for (int i=0;i<m;i++) {
cin >> e[i].fr >> e[i].to;
e[i].id = i;
}
set<pair<int, int>> st;
st.insert({1,0});
st.insert({1,1});
sort(e, e+m, cmp);
bool fl = 1;
int now = 0;
for (int i=0;i<n;i++) {
auto [num, ty] = *st.begin();
if (e[i].fr > num) {
fl = 0;
} else {
ans[e[i].id] = ty;
st.erase(st.begin());
st.insert({e[i].to+1, ty});
}
}
for (auto [i,j]:st) fl = (fl and (i>n));
if (fl) {
for (int i=0;i<m;i++) {
cout << ans[i];
}
cout << "\n";
} else {
cout << "impossible\n";
}
}
Compilation message (stderr)
# | 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... |