# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
187258 | 2020-01-12T14:59:31 Z | Ruxandra985 | Alternating Current (BOI18_alternating) | C++14 | 52 ms | 5624 KB |
#include <bits/stdc++.h> #define DIMN 100010 using namespace std; pair <int,pair <int,int> > v[DIMN],w[DIMN]; int sol[DIMN] , par[DIMN] , sp1[DIMN] , sp2[DIMN]; set <pair <int,int> > s; int common (int last , int c){ if (!last) return 0; if (v[last].first <= v[last].second.first){ if (v[c].first <= v[c].second.first){ if (v[c].first <= v[last].second.first) return 1; return 0; } else { if (v[c].first <= v[last].second.first) return 1; return 0; } } else { if (v[c].first <= v[c].second.first){ if (v[c].first <= v[last].second.first) return 1; return 0; } else { if (v[c].second.first > v[last].second.first) return 1; return 0; } } } int main() { FILE *fin = stdin; FILE *fout = stdout; int n , m , i , maxi , poz, poz2 , maxi2, last; fscanf (fin,"%d%d",&n,&m); maxi = 0; poz = 0; for (i=1;i<=m;i++){ fscanf (fin,"%d%d",&v[i].first,&v[i].second.first); v[i].second.second = i; w[i] = v[i]; } maxi2 = 0; poz2 = 0; sort (v + 1 , v + m + 1); for (i=1;i<=m;i++){ if (v[i].first > v[i].second.first && maxi < v[i].second.first){ maxi = v[i].second.first; poz = i; } } for (i=1;i<=m;i++){ /// check daca i e inclus total in vreun alt interval if (v[i].first <= v[i].second.first){ /// e un interval normal if (maxi > v[i].second.first){ /// e inclus par[i] = poz; continue; } else{ maxi = v[i].second.first; poz = i; } } else { maxi = n; /// le tratezi ca pe doua intervale poz = i; if (maxi2 > v[i].second.first){ /// e inclus par[i] = poz2; continue; } else { maxi2 = v[i].second.first; poz2 = i; } } par[i] = -1; /// e tata } /// daca au ceva in comun, pui semne opuse last = 0; for (i=1;i<=m;i++){ if (par[i] == -1){ if (common(last , i)){ sol[v[i].second.second] = 1 - sol[v[last].second.second]; } else { sol[v[i].second.second] = 0; } last = i; } else { sol[v[i].second.second] = 1 - sol[v[par[i]].second.second]; } } for (i=1;i<=m;i++){ if (w[i].first <= w[i].second.first){ if (sol[i] == 1){ sp1[w[i].first]++; sp1[w[i].second.first+1]--; } else { sp2[w[i].first]++; sp2[w[i].second.first+1]--; } } else { if (sol[i] == 1){ sp1[w[i].first]++; sp1[1]++; sp1[w[i].second.first+1]--; } else { sp2[w[i].first]++; sp2[1]++; sp2[w[i].second.first+1]--; } } } for (i=1;i<=n;i++){ sp1[i] += sp1[i-1]; sp2[i] += sp2[i-1]; if (!sp1[i] || !sp2[i]){ fprintf (fout,"impossible\n"); return 0; } } for (i=1;i<=m;i++){ fprintf (fout,"%d",sol[i]); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 376 KB | Output is correct |
2 | Correct | 0 ms | 248 KB | Output is correct |
3 | Correct | 2 ms | 364 KB | Output is correct |
4 | Incorrect | 2 ms | 380 KB | 'impossible' claimed, but there is a solution |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 376 KB | Output is correct |
2 | Correct | 0 ms | 248 KB | Output is correct |
3 | Correct | 2 ms | 364 KB | Output is correct |
4 | Incorrect | 2 ms | 380 KB | 'impossible' claimed, but there is a solution |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 376 KB | Output is correct |
2 | Correct | 0 ms | 248 KB | Output is correct |
3 | Correct | 2 ms | 364 KB | Output is correct |
4 | Incorrect | 2 ms | 380 KB | 'impossible' claimed, but there is a solution |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 37 ms | 5240 KB | Output is correct |
2 | Correct | 4 ms | 1144 KB | Output is correct |
3 | Correct | 15 ms | 2936 KB | Output is correct |
4 | Correct | 18 ms | 3320 KB | Output is correct |
5 | Correct | 47 ms | 5268 KB | Output is correct |
6 | Correct | 42 ms | 5368 KB | Output is correct |
7 | Correct | 43 ms | 5084 KB | Output is correct |
8 | Correct | 4 ms | 1400 KB | Output is correct |
9 | Correct | 3 ms | 1144 KB | Output is correct |
10 | Correct | 49 ms | 5496 KB | Output is correct |
11 | Correct | 39 ms | 4344 KB | Output is correct |
12 | Correct | 42 ms | 5104 KB | Output is correct |
13 | Correct | 12 ms | 1144 KB | Output is correct |
14 | Correct | 3 ms | 1148 KB | Output is correct |
15 | Correct | 52 ms | 5508 KB | Output is correct |
16 | Correct | 17 ms | 3296 KB | Output is correct |
17 | Correct | 49 ms | 5624 KB | Output is correct |
18 | Correct | 47 ms | 4600 KB | Output is correct |
19 | Correct | 5 ms | 1400 KB | Output is correct |
20 | Correct | 45 ms | 5112 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 376 KB | Output is correct |
2 | Correct | 0 ms | 248 KB | Output is correct |
3 | Correct | 2 ms | 364 KB | Output is correct |
4 | Incorrect | 2 ms | 380 KB | 'impossible' claimed, but there is a solution |
5 | Halted | 0 ms | 0 KB | - |