# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
186614 | Ruxandra985 | Alternating Current (BOI18_alternating) | C++14 | 3020 ms | 1108 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>
#define DIMN 100010
using namespace std;
pair <int,int> v[DIMN];
int d[DIMN] , cer[DIMN] , f[DIMN] , sol[DIMN];
int main()
{
FILE *fin = stdin;
FILE *fout = stdout;
int n , m , i , j , ok , poz , what;
fscanf (fin,"%d%d",&n,&m);
for (i=1;i<=m;i++){
fscanf (fin,"%d%d",&v[i].first,&v[i].second);
if (v[i].first <= v[i].second){
for (j = v[i].first ; j <= v[i].second ; j++){
d[j]++;
}
}
else {
for (j = v[i].first ; j <= n ; j++){
d[j]++;
}
for (j = 1 ; j <= v[i].second ; j++){
d[j]++;
}
}
}
for (j=1;j<=m;j++){
ok = 0;
for (i=1;i<=n;i++){
if (d[i] == 1 && cer[i] < 3 && cer[i] > 0)
ok = i;
}
if (ok){
for (i=1;i<=m;i++){
if (!f[i]){ /// inca e relevant
if (v[i].first <= v[i].second && v[i].first <= ok && ok <= v[i].second){
poz = i;
f[i] = 1;
}
else if (v[i].first > v[i].second && (ok >= v[i].first || ok <= v[i].second)){
poz = i;
f[i] = 1;
}
}
}
what = cer[ok];
}
else {
what = 1;
for (i=1;i<=m;i++){
if (!f[i]){
poz = i;
f[i] = 1;
break;
}
}
}
sol[poz] = what - 1;
/// update
for (i=1;i<=n;i++){
if ((v[poz].first <= v[poz].second && v[poz].first <= i && i <= v[poz].second) ||
(v[poz].first > v[poz].second && (i >= v[poz].first || i <= v[poz].second))){
/// i e afectat de interval
d[i]--;
if (cer[i] == 0){
if (what == 1)
cer[i] = 2;
else cer[i] = 1;
}
else if (cer[i] == 3){}
else { /// e 1 sau 2 , cere ceva si i se da
if (cer[i] == what){
cer[i] = 3;
}
}
}
}
}
for (i=1;i<=n;i++){
if (cer[i] != 3){
fprintf (fout,"impossible");
return 0;
}
}
for (i=1;i<=m;i++){
fprintf (fout,"%d",sol[i]);
}
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... |