# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1114955 | lucascgar | Alternating Current (BOI18_alternating) | C++17 | 92 ms | 9660 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;
/*
*/
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long double, long double> pdd;
const int MAXN = 1e5+10;
vector<int> w[MAXN];
bool ty[MAXN];
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
// cout << fixed << setprecision(7);
int n, m;
cin >> n >> m;
int a, b;
for (int i=0;i<m;i++){
cin >> a >> b;
if(b<a) return 0;
w[a].push_back(i);
w[b].push_back(i);
}
set<int> cr;
int ps=-1, ng=-1;
bool valid = 1;
for (int i=1;i<=n;i++){
vector<int> rm;
while (!w[i].empty()){
int u = w[i].back();
w[i].pop_back();
if (!cr.count(u) && ps != u && ng != u){
cr.insert(u);
}
else{
rm.push_back(u);
}
}
if (cr.size() < (int)(ps==-1)+(ng==-1)){
valid = 0;
break;
}
if (ps==-1){
ps = *cr.begin();
cr.erase(cr.begin());
ty[ps]=0;
}
if (ng==-1){
ng = *cr.begin();
cr.erase(cr.begin());
ty[ng]=1;
}
for (auto &u:rm){
cr.erase(u);
if (ps==u) ps=-1;
if (ng==u) ng=-1;
}
}
if (!valid){
cout << "impossible\n";
return 0;
}
for (int i=0;i<m;i++) cout << (int)ty[i];
cout << '\n';
return 0;
}
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... |