Submission #121310

# Submission time Handle Problem Language Result Execution time Memory
121310 2019-06-26T10:03:07 Z IOrtroiii Alternating Current (BOI18_alternating) C++14
100 / 100
118 ms 18040 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 200200;

int n, m;
int a[N];
vector<pair<int, int>> g[N];
int visit[N], tt;
int ans[N];
vector<int> path;

bool dfs(int u, int trg) {
   if (u == trg) {
      return true;
   }
   if (visit[u % n] == tt) {
      return false;
   }
   visit[u % n] = tt;
   for (auto e : g[u]) {
      int v, id;
      tie(v, id) = e;
      path.push_back(id);
      if (dfs(v, trg)) {
         return true;
      }
      path.pop_back();
   }
   return false;
}

bool go(int u) {
   visit[u] = ++tt;
   for (auto e : g[u]) {
      int v, id;
      tie(v, id) = e;
      if (v == u - 1) {
         continue;
      }
      path.push_back(id);
      if (dfs(v, u + n)) {
         return true;
      }
      path.pop_back();
   }
   return false;
}

int main() {
   ios_base::sync_with_stdio(false);
   cin >> n >> m;
   for (int i = 1; i <= m; ++i) {
      int l, r;
      cin >> l >> r;
      if (l > r) {
         ++a[l], --a[n + 1];
         ++a[1], --a[r + 1];
         --l, r += n;
         g[l].emplace_back(r, i);
         g[l + n].emplace_back(n + n, i);
      } else {
         ++a[l], --a[r + 1];
         l--;
         g[l].emplace_back(r, i);
         g[l + n].emplace_back(r + n, i);
      }
   }
   for (int i = 1; i <= n; ++i) {
      a[i] += a[i - 1];
      if (a[i] == 1) {
         cout << "impossible\n";
         return 0;
      }
   }
   for (int i = 1; i <= n; ++i) {
      if (a[i] > 2) {
         g[i].emplace_back(i - 1, 0);
         g[i + n].emplace_back(i - 1 + n, 0);
      }
   }
   for (int i = 0; i < n; ++i) {
      if (go(i)) {
         for (int v : path) {
            ans[v] = 1;
         }
         for (int j = 1; j <= m; ++j) {
            cout << ans[j];
         }
         return 0;
      }
   }
   cout << "impossible\n";
   return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5120 KB Output is correct
2 Correct 6 ms 4992 KB Output is correct
3 Correct 6 ms 4992 KB Output is correct
4 Correct 5 ms 5040 KB Output is correct
5 Correct 6 ms 5120 KB Output is correct
6 Correct 6 ms 5120 KB Output is correct
7 Correct 6 ms 5144 KB Output is correct
8 Correct 7 ms 4992 KB Output is correct
9 Correct 7 ms 5120 KB Output is correct
10 Correct 6 ms 5120 KB Output is correct
11 Correct 7 ms 5092 KB Output is correct
12 Correct 7 ms 5120 KB Output is correct
13 Correct 6 ms 4992 KB Output is correct
14 Correct 6 ms 5120 KB Output is correct
15 Correct 6 ms 4992 KB Output is correct
16 Correct 6 ms 5120 KB Output is correct
17 Correct 6 ms 5120 KB Output is correct
18 Correct 7 ms 5120 KB Output is correct
19 Correct 8 ms 5120 KB Output is correct
20 Correct 7 ms 5120 KB Output is correct
21 Correct 6 ms 5120 KB Output is correct
22 Correct 6 ms 5120 KB Output is correct
23 Correct 6 ms 5120 KB Output is correct
24 Correct 6 ms 5120 KB Output is correct
25 Correct 6 ms 5120 KB Output is correct
26 Correct 7 ms 5120 KB Output is correct
27 Correct 6 ms 5120 KB Output is correct
28 Correct 5 ms 4992 KB Output is correct
29 Correct 5 ms 4992 KB Output is correct
30 Correct 8 ms 5168 KB Output is correct
31 Correct 6 ms 4992 KB Output is correct
32 Correct 6 ms 5120 KB Output is correct
33 Correct 6 ms 4992 KB Output is correct
34 Correct 6 ms 5120 KB Output is correct
35 Correct 6 ms 5120 KB Output is correct
36 Correct 6 ms 5120 KB Output is correct
37 Correct 6 ms 4992 KB Output is correct
38 Correct 6 ms 4992 KB Output is correct
39 Correct 7 ms 5120 KB Output is correct
40 Correct 6 ms 4992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5120 KB Output is correct
2 Correct 6 ms 4992 KB Output is correct
3 Correct 6 ms 4992 KB Output is correct
4 Correct 5 ms 5040 KB Output is correct
5 Correct 6 ms 5120 KB Output is correct
6 Correct 6 ms 5120 KB Output is correct
7 Correct 6 ms 5144 KB Output is correct
8 Correct 7 ms 4992 KB Output is correct
9 Correct 7 ms 5120 KB Output is correct
10 Correct 6 ms 5120 KB Output is correct
11 Correct 7 ms 5092 KB Output is correct
12 Correct 7 ms 5120 KB Output is correct
13 Correct 6 ms 4992 KB Output is correct
14 Correct 6 ms 5120 KB Output is correct
15 Correct 6 ms 4992 KB Output is correct
16 Correct 6 ms 5120 KB Output is correct
17 Correct 6 ms 5120 KB Output is correct
18 Correct 7 ms 5120 KB Output is correct
19 Correct 8 ms 5120 KB Output is correct
20 Correct 7 ms 5120 KB Output is correct
21 Correct 6 ms 5120 KB Output is correct
22 Correct 6 ms 5120 KB Output is correct
23 Correct 6 ms 5120 KB Output is correct
24 Correct 6 ms 5120 KB Output is correct
25 Correct 6 ms 5120 KB Output is correct
26 Correct 7 ms 5120 KB Output is correct
27 Correct 6 ms 5120 KB Output is correct
28 Correct 5 ms 4992 KB Output is correct
29 Correct 5 ms 4992 KB Output is correct
30 Correct 8 ms 5168 KB Output is correct
31 Correct 6 ms 4992 KB Output is correct
32 Correct 6 ms 5120 KB Output is correct
33 Correct 6 ms 4992 KB Output is correct
34 Correct 6 ms 5120 KB Output is correct
35 Correct 6 ms 5120 KB Output is correct
36 Correct 6 ms 5120 KB Output is correct
37 Correct 6 ms 4992 KB Output is correct
38 Correct 6 ms 4992 KB Output is correct
39 Correct 7 ms 5120 KB Output is correct
40 Correct 6 ms 4992 KB Output is correct
41 Correct 7 ms 4992 KB Output is correct
42 Correct 6 ms 4992 KB Output is correct
43 Correct 7 ms 5120 KB Output is correct
44 Correct 7 ms 5120 KB Output is correct
45 Correct 7 ms 5120 KB Output is correct
46 Correct 6 ms 5136 KB Output is correct
47 Correct 6 ms 5120 KB Output is correct
48 Correct 6 ms 4992 KB Output is correct
49 Correct 6 ms 5120 KB Output is correct
50 Correct 13 ms 5120 KB Output is correct
51 Correct 6 ms 5120 KB Output is correct
52 Correct 6 ms 5120 KB Output is correct
53 Correct 9 ms 5120 KB Output is correct
54 Correct 6 ms 5120 KB Output is correct
55 Correct 7 ms 5120 KB Output is correct
56 Correct 7 ms 5120 KB Output is correct
57 Correct 6 ms 4992 KB Output is correct
58 Correct 6 ms 5120 KB Output is correct
59 Correct 6 ms 5120 KB Output is correct
60 Correct 7 ms 4992 KB Output is correct
61 Correct 6 ms 4864 KB Output is correct
62 Correct 6 ms 4992 KB Output is correct
63 Correct 6 ms 5120 KB Output is correct
64 Correct 6 ms 4992 KB Output is correct
65 Correct 6 ms 5120 KB Output is correct
66 Correct 7 ms 4992 KB Output is correct
67 Correct 6 ms 4992 KB Output is correct
68 Correct 6 ms 4992 KB Output is correct
69 Correct 6 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5120 KB Output is correct
2 Correct 6 ms 4992 KB Output is correct
3 Correct 6 ms 4992 KB Output is correct
4 Correct 5 ms 5040 KB Output is correct
5 Correct 6 ms 5120 KB Output is correct
6 Correct 6 ms 5120 KB Output is correct
7 Correct 6 ms 5144 KB Output is correct
8 Correct 7 ms 4992 KB Output is correct
9 Correct 7 ms 5120 KB Output is correct
10 Correct 6 ms 5120 KB Output is correct
11 Correct 7 ms 5092 KB Output is correct
12 Correct 7 ms 5120 KB Output is correct
13 Correct 6 ms 4992 KB Output is correct
14 Correct 6 ms 5120 KB Output is correct
15 Correct 6 ms 4992 KB Output is correct
16 Correct 6 ms 5120 KB Output is correct
17 Correct 6 ms 5120 KB Output is correct
18 Correct 7 ms 5120 KB Output is correct
19 Correct 8 ms 5120 KB Output is correct
20 Correct 7 ms 5120 KB Output is correct
21 Correct 6 ms 5120 KB Output is correct
22 Correct 6 ms 5120 KB Output is correct
23 Correct 6 ms 5120 KB Output is correct
24 Correct 6 ms 5120 KB Output is correct
25 Correct 6 ms 5120 KB Output is correct
26 Correct 7 ms 5120 KB Output is correct
27 Correct 6 ms 5120 KB Output is correct
28 Correct 5 ms 4992 KB Output is correct
29 Correct 5 ms 4992 KB Output is correct
30 Correct 8 ms 5168 KB Output is correct
31 Correct 6 ms 4992 KB Output is correct
32 Correct 6 ms 5120 KB Output is correct
33 Correct 6 ms 4992 KB Output is correct
34 Correct 6 ms 5120 KB Output is correct
35 Correct 6 ms 5120 KB Output is correct
36 Correct 6 ms 5120 KB Output is correct
37 Correct 6 ms 4992 KB Output is correct
38 Correct 6 ms 4992 KB Output is correct
39 Correct 7 ms 5120 KB Output is correct
40 Correct 6 ms 4992 KB Output is correct
41 Correct 7 ms 4992 KB Output is correct
42 Correct 6 ms 4992 KB Output is correct
43 Correct 7 ms 5120 KB Output is correct
44 Correct 7 ms 5120 KB Output is correct
45 Correct 7 ms 5120 KB Output is correct
46 Correct 6 ms 5136 KB Output is correct
47 Correct 6 ms 5120 KB Output is correct
48 Correct 6 ms 4992 KB Output is correct
49 Correct 6 ms 5120 KB Output is correct
50 Correct 13 ms 5120 KB Output is correct
51 Correct 6 ms 5120 KB Output is correct
52 Correct 6 ms 5120 KB Output is correct
53 Correct 9 ms 5120 KB Output is correct
54 Correct 6 ms 5120 KB Output is correct
55 Correct 7 ms 5120 KB Output is correct
56 Correct 7 ms 5120 KB Output is correct
57 Correct 6 ms 4992 KB Output is correct
58 Correct 6 ms 5120 KB Output is correct
59 Correct 6 ms 5120 KB Output is correct
60 Correct 7 ms 4992 KB Output is correct
61 Correct 6 ms 4864 KB Output is correct
62 Correct 6 ms 4992 KB Output is correct
63 Correct 6 ms 5120 KB Output is correct
64 Correct 6 ms 4992 KB Output is correct
65 Correct 6 ms 5120 KB Output is correct
66 Correct 7 ms 4992 KB Output is correct
67 Correct 6 ms 4992 KB Output is correct
68 Correct 6 ms 4992 KB Output is correct
69 Correct 6 ms 5120 KB Output is correct
70 Correct 6 ms 5120 KB Output is correct
71 Correct 6 ms 5248 KB Output is correct
72 Correct 6 ms 5120 KB Output is correct
73 Correct 6 ms 5120 KB Output is correct
74 Correct 6 ms 5120 KB Output is correct
75 Correct 6 ms 5120 KB Output is correct
76 Correct 6 ms 5120 KB Output is correct
77 Correct 7 ms 5120 KB Output is correct
78 Correct 6 ms 5112 KB Output is correct
79 Correct 7 ms 4992 KB Output is correct
80 Correct 7 ms 5248 KB Output is correct
81 Correct 8 ms 5120 KB Output is correct
82 Correct 7 ms 5120 KB Output is correct
83 Correct 7 ms 5092 KB Output is correct
84 Correct 7 ms 5120 KB Output is correct
85 Correct 6 ms 5120 KB Output is correct
86 Correct 6 ms 4992 KB Output is correct
87 Correct 7 ms 5120 KB Output is correct
88 Correct 7 ms 4992 KB Output is correct
89 Correct 6 ms 5120 KB Output is correct
90 Correct 6 ms 5120 KB Output is correct
91 Correct 6 ms 5112 KB Output is correct
92 Correct 7 ms 5120 KB Output is correct
93 Correct 7 ms 5120 KB Output is correct
94 Correct 6 ms 5120 KB Output is correct
95 Correct 8 ms 5120 KB Output is correct
96 Correct 9 ms 5120 KB Output is correct
97 Correct 6 ms 5120 KB Output is correct
98 Correct 8 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 13412 KB Output is correct
2 Correct 7 ms 5376 KB Output is correct
3 Correct 21 ms 8568 KB Output is correct
4 Correct 35 ms 11768 KB Output is correct
5 Correct 85 ms 14196 KB Output is correct
6 Correct 80 ms 9976 KB Output is correct
7 Correct 77 ms 14452 KB Output is correct
8 Correct 15 ms 9088 KB Output is correct
9 Correct 13 ms 8704 KB Output is correct
10 Correct 79 ms 15572 KB Output is correct
11 Correct 63 ms 13564 KB Output is correct
12 Correct 63 ms 12200 KB Output is correct
13 Correct 8 ms 5888 KB Output is correct
14 Correct 7 ms 5888 KB Output is correct
15 Correct 108 ms 17800 KB Output is correct
16 Correct 23 ms 9208 KB Output is correct
17 Correct 107 ms 18040 KB Output is correct
18 Correct 38 ms 8824 KB Output is correct
19 Correct 10 ms 5760 KB Output is correct
20 Correct 44 ms 13428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5120 KB Output is correct
2 Correct 6 ms 4992 KB Output is correct
3 Correct 6 ms 4992 KB Output is correct
4 Correct 5 ms 5040 KB Output is correct
5 Correct 6 ms 5120 KB Output is correct
6 Correct 6 ms 5120 KB Output is correct
7 Correct 6 ms 5144 KB Output is correct
8 Correct 7 ms 4992 KB Output is correct
9 Correct 7 ms 5120 KB Output is correct
10 Correct 6 ms 5120 KB Output is correct
11 Correct 7 ms 5092 KB Output is correct
12 Correct 7 ms 5120 KB Output is correct
13 Correct 6 ms 4992 KB Output is correct
14 Correct 6 ms 5120 KB Output is correct
15 Correct 6 ms 4992 KB Output is correct
16 Correct 6 ms 5120 KB Output is correct
17 Correct 6 ms 5120 KB Output is correct
18 Correct 7 ms 5120 KB Output is correct
19 Correct 8 ms 5120 KB Output is correct
20 Correct 7 ms 5120 KB Output is correct
21 Correct 6 ms 5120 KB Output is correct
22 Correct 6 ms 5120 KB Output is correct
23 Correct 6 ms 5120 KB Output is correct
24 Correct 6 ms 5120 KB Output is correct
25 Correct 6 ms 5120 KB Output is correct
26 Correct 7 ms 5120 KB Output is correct
27 Correct 6 ms 5120 KB Output is correct
28 Correct 5 ms 4992 KB Output is correct
29 Correct 5 ms 4992 KB Output is correct
30 Correct 8 ms 5168 KB Output is correct
31 Correct 6 ms 4992 KB Output is correct
32 Correct 6 ms 5120 KB Output is correct
33 Correct 6 ms 4992 KB Output is correct
34 Correct 6 ms 5120 KB Output is correct
35 Correct 6 ms 5120 KB Output is correct
36 Correct 6 ms 5120 KB Output is correct
37 Correct 6 ms 4992 KB Output is correct
38 Correct 6 ms 4992 KB Output is correct
39 Correct 7 ms 5120 KB Output is correct
40 Correct 6 ms 4992 KB Output is correct
41 Correct 7 ms 4992 KB Output is correct
42 Correct 6 ms 4992 KB Output is correct
43 Correct 7 ms 5120 KB Output is correct
44 Correct 7 ms 5120 KB Output is correct
45 Correct 7 ms 5120 KB Output is correct
46 Correct 6 ms 5136 KB Output is correct
47 Correct 6 ms 5120 KB Output is correct
48 Correct 6 ms 4992 KB Output is correct
49 Correct 6 ms 5120 KB Output is correct
50 Correct 13 ms 5120 KB Output is correct
51 Correct 6 ms 5120 KB Output is correct
52 Correct 6 ms 5120 KB Output is correct
53 Correct 9 ms 5120 KB Output is correct
54 Correct 6 ms 5120 KB Output is correct
55 Correct 7 ms 5120 KB Output is correct
56 Correct 7 ms 5120 KB Output is correct
57 Correct 6 ms 4992 KB Output is correct
58 Correct 6 ms 5120 KB Output is correct
59 Correct 6 ms 5120 KB Output is correct
60 Correct 7 ms 4992 KB Output is correct
61 Correct 6 ms 4864 KB Output is correct
62 Correct 6 ms 4992 KB Output is correct
63 Correct 6 ms 5120 KB Output is correct
64 Correct 6 ms 4992 KB Output is correct
65 Correct 6 ms 5120 KB Output is correct
66 Correct 7 ms 4992 KB Output is correct
67 Correct 6 ms 4992 KB Output is correct
68 Correct 6 ms 4992 KB Output is correct
69 Correct 6 ms 5120 KB Output is correct
70 Correct 6 ms 5120 KB Output is correct
71 Correct 6 ms 5248 KB Output is correct
72 Correct 6 ms 5120 KB Output is correct
73 Correct 6 ms 5120 KB Output is correct
74 Correct 6 ms 5120 KB Output is correct
75 Correct 6 ms 5120 KB Output is correct
76 Correct 6 ms 5120 KB Output is correct
77 Correct 7 ms 5120 KB Output is correct
78 Correct 6 ms 5112 KB Output is correct
79 Correct 7 ms 4992 KB Output is correct
80 Correct 7 ms 5248 KB Output is correct
81 Correct 8 ms 5120 KB Output is correct
82 Correct 7 ms 5120 KB Output is correct
83 Correct 7 ms 5092 KB Output is correct
84 Correct 7 ms 5120 KB Output is correct
85 Correct 6 ms 5120 KB Output is correct
86 Correct 6 ms 4992 KB Output is correct
87 Correct 7 ms 5120 KB Output is correct
88 Correct 7 ms 4992 KB Output is correct
89 Correct 6 ms 5120 KB Output is correct
90 Correct 6 ms 5120 KB Output is correct
91 Correct 6 ms 5112 KB Output is correct
92 Correct 7 ms 5120 KB Output is correct
93 Correct 7 ms 5120 KB Output is correct
94 Correct 6 ms 5120 KB Output is correct
95 Correct 8 ms 5120 KB Output is correct
96 Correct 9 ms 5120 KB Output is correct
97 Correct 6 ms 5120 KB Output is correct
98 Correct 8 ms 5120 KB Output is correct
99 Correct 42 ms 13412 KB Output is correct
100 Correct 7 ms 5376 KB Output is correct
101 Correct 21 ms 8568 KB Output is correct
102 Correct 35 ms 11768 KB Output is correct
103 Correct 85 ms 14196 KB Output is correct
104 Correct 80 ms 9976 KB Output is correct
105 Correct 77 ms 14452 KB Output is correct
106 Correct 15 ms 9088 KB Output is correct
107 Correct 13 ms 8704 KB Output is correct
108 Correct 79 ms 15572 KB Output is correct
109 Correct 63 ms 13564 KB Output is correct
110 Correct 63 ms 12200 KB Output is correct
111 Correct 8 ms 5888 KB Output is correct
112 Correct 7 ms 5888 KB Output is correct
113 Correct 108 ms 17800 KB Output is correct
114 Correct 23 ms 9208 KB Output is correct
115 Correct 107 ms 18040 KB Output is correct
116 Correct 38 ms 8824 KB Output is correct
117 Correct 10 ms 5760 KB Output is correct
118 Correct 44 ms 13428 KB Output is correct
119 Correct 7 ms 6016 KB Output is correct
120 Correct 81 ms 15852 KB Output is correct
121 Correct 39 ms 11640 KB Output is correct
122 Correct 5 ms 5120 KB Output is correct
123 Correct 9 ms 5888 KB Output is correct
124 Correct 24 ms 7928 KB Output is correct
125 Correct 33 ms 10668 KB Output is correct
126 Correct 9 ms 7296 KB Output is correct
127 Correct 19 ms 10368 KB Output is correct
128 Correct 58 ms 13812 KB Output is correct
129 Correct 43 ms 11188 KB Output is correct
130 Correct 47 ms 12024 KB Output is correct
131 Correct 8 ms 5604 KB Output is correct
132 Correct 7 ms 5632 KB Output is correct
133 Correct 118 ms 17880 KB Output is correct
134 Correct 58 ms 17656 KB Output is correct
135 Correct 29 ms 17524 KB Output is correct
136 Correct 37 ms 8952 KB Output is correct
137 Correct 44 ms 9848 KB Output is correct
138 Correct 23 ms 13560 KB Output is correct