Submission #106428

# Submission time Handle Problem Language Result Execution time Memory
106428 2019-04-18T11:48:49 Z eriksuenderhauf Alternating Current (BOI18_alternating) C++11
100 / 100
169 ms 17172 KB
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vil vector<pil>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 2e5 + 5;
const double eps = 1e-9;
int a[MAXN], vis[MAXN], cnt = 5;
char ans[MAXN];
vii adj[MAXN];
vi comp;
int n, m;

bool dfs(int u, int p) {
	if (u == p) 
		return 1;
	if (vis[u % n] == cnt)
		return 0;
	vis[u % n] = cnt;
	for (pii nx: adj[u]) {
		comp.pb(nx.se);
		if (dfs(nx.fi, p))
			return 1;
		comp.pop_back();
	}
	return 0;
}

bool ok(int cur) {
	vis[cur] = ++cnt;
	for (pii nx: adj[cur]) {
		if (nx.fi == cur-1) continue;
		comp.pb(nx.se);
		if (dfs(nx.fi, cur + n))
			return 1;
		comp.pop_back();
	}
	return 0;
}

int main() {
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++) {
		int l, r;
		scanf("%d %d", &l, &r);
		if (l > r) {
			a[l]++, a[n + 1]--;
			a[1]++, a[r + 1]--;
			l--, r += n;
			adj[l].pb({r, i});
			adj[l+n].pb({2*n, i});
		} else {
			a[l]++, a[r + 1]--;
			l--;
			adj[l].pb({r, i});
			adj[l+n].pb({r+n, i});
		}
		ans[i] = '1';
	}
	for (int i = 1; i <= n; i++) {
		a[i] += a[i - 1];
		if (a[i] == 1)
			return !printf("impossible\n");
	}
	for (int i = 1; i <= n; i++) {
		a[i] = max(0, min(1, a[i] - 2));
		if (!a[i]) continue;
		adj[i].pb({i - 1, -1});
		adj[i + n].pb({i - 1 + n, -1});
	}
	for (int i = 0; i < n; i++) {
		if (!ok(i)) continue;
		for (int j: comp)
			if (j != -1)
				ans[j] = '0';
		return !printf("%s\n", ans);
	}
	printf("impossible\n");
	return 0;
}

Compilation message

alternating.cpp: In function 'int main()':
alternating.cpp:69:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~~
alternating.cpp:72:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &l, &r);
   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4992 KB Output is correct
2 Correct 7 ms 4992 KB Output is correct
3 Correct 6 ms 4992 KB Output is correct
4 Correct 6 ms 4992 KB Output is correct
5 Correct 7 ms 4992 KB Output is correct
6 Correct 8 ms 4992 KB Output is correct
7 Correct 8 ms 4992 KB Output is correct
8 Correct 7 ms 4992 KB Output is correct
9 Correct 6 ms 4992 KB Output is correct
10 Correct 7 ms 4992 KB Output is correct
11 Correct 8 ms 4992 KB Output is correct
12 Correct 8 ms 4992 KB Output is correct
13 Correct 7 ms 4992 KB Output is correct
14 Correct 8 ms 4992 KB Output is correct
15 Correct 7 ms 4992 KB Output is correct
16 Correct 8 ms 5028 KB Output is correct
17 Correct 7 ms 4992 KB Output is correct
18 Correct 8 ms 4992 KB Output is correct
19 Correct 7 ms 5120 KB Output is correct
20 Correct 8 ms 4992 KB Output is correct
21 Correct 6 ms 4952 KB Output is correct
22 Correct 7 ms 5120 KB Output is correct
23 Correct 6 ms 4992 KB Output is correct
24 Correct 8 ms 5076 KB Output is correct
25 Correct 8 ms 4992 KB Output is correct
26 Correct 6 ms 4992 KB Output is correct
27 Correct 7 ms 4992 KB Output is correct
28 Correct 7 ms 4992 KB Output is correct
29 Correct 6 ms 4992 KB Output is correct
30 Correct 7 ms 4992 KB Output is correct
31 Correct 6 ms 4964 KB Output is correct
32 Correct 7 ms 4992 KB Output is correct
33 Correct 6 ms 4992 KB Output is correct
34 Correct 8 ms 4992 KB Output is correct
35 Correct 6 ms 4992 KB Output is correct
36 Correct 8 ms 4992 KB Output is correct
37 Correct 7 ms 4992 KB Output is correct
38 Correct 7 ms 4992 KB Output is correct
39 Correct 7 ms 4992 KB Output is correct
40 Correct 7 ms 4992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4992 KB Output is correct
2 Correct 7 ms 4992 KB Output is correct
3 Correct 6 ms 4992 KB Output is correct
4 Correct 6 ms 4992 KB Output is correct
5 Correct 7 ms 4992 KB Output is correct
6 Correct 8 ms 4992 KB Output is correct
7 Correct 8 ms 4992 KB Output is correct
8 Correct 7 ms 4992 KB Output is correct
9 Correct 6 ms 4992 KB Output is correct
10 Correct 7 ms 4992 KB Output is correct
11 Correct 8 ms 4992 KB Output is correct
12 Correct 8 ms 4992 KB Output is correct
13 Correct 7 ms 4992 KB Output is correct
14 Correct 8 ms 4992 KB Output is correct
15 Correct 7 ms 4992 KB Output is correct
16 Correct 8 ms 5028 KB Output is correct
17 Correct 7 ms 4992 KB Output is correct
18 Correct 8 ms 4992 KB Output is correct
19 Correct 7 ms 5120 KB Output is correct
20 Correct 8 ms 4992 KB Output is correct
21 Correct 6 ms 4952 KB Output is correct
22 Correct 7 ms 5120 KB Output is correct
23 Correct 6 ms 4992 KB Output is correct
24 Correct 8 ms 5076 KB Output is correct
25 Correct 8 ms 4992 KB Output is correct
26 Correct 6 ms 4992 KB Output is correct
27 Correct 7 ms 4992 KB Output is correct
28 Correct 7 ms 4992 KB Output is correct
29 Correct 6 ms 4992 KB Output is correct
30 Correct 7 ms 4992 KB Output is correct
31 Correct 6 ms 4964 KB Output is correct
32 Correct 7 ms 4992 KB Output is correct
33 Correct 6 ms 4992 KB Output is correct
34 Correct 8 ms 4992 KB Output is correct
35 Correct 6 ms 4992 KB Output is correct
36 Correct 8 ms 4992 KB Output is correct
37 Correct 7 ms 4992 KB Output is correct
38 Correct 7 ms 4992 KB Output is correct
39 Correct 7 ms 4992 KB Output is correct
40 Correct 7 ms 4992 KB Output is correct
41 Correct 8 ms 5120 KB Output is correct
42 Correct 6 ms 4992 KB Output is correct
43 Correct 7 ms 4984 KB Output is correct
44 Correct 6 ms 4992 KB Output is correct
45 Correct 6 ms 4992 KB Output is correct
46 Correct 7 ms 4964 KB Output is correct
47 Correct 6 ms 4992 KB Output is correct
48 Correct 7 ms 5020 KB Output is correct
49 Correct 7 ms 4992 KB Output is correct
50 Correct 7 ms 4992 KB Output is correct
51 Correct 7 ms 4992 KB Output is correct
52 Correct 7 ms 4992 KB Output is correct
53 Correct 8 ms 4992 KB Output is correct
54 Correct 7 ms 4992 KB Output is correct
55 Correct 6 ms 4992 KB Output is correct
56 Correct 7 ms 4992 KB Output is correct
57 Correct 7 ms 4992 KB Output is correct
58 Correct 7 ms 4992 KB Output is correct
59 Correct 7 ms 4992 KB Output is correct
60 Correct 6 ms 4992 KB Output is correct
61 Correct 6 ms 4992 KB Output is correct
62 Correct 6 ms 4992 KB Output is correct
63 Correct 7 ms 4992 KB Output is correct
64 Correct 8 ms 5120 KB Output is correct
65 Correct 6 ms 4992 KB Output is correct
66 Correct 7 ms 5036 KB Output is correct
67 Correct 7 ms 4992 KB Output is correct
68 Correct 7 ms 4964 KB Output is correct
69 Correct 8 ms 4992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4992 KB Output is correct
2 Correct 7 ms 4992 KB Output is correct
3 Correct 6 ms 4992 KB Output is correct
4 Correct 6 ms 4992 KB Output is correct
5 Correct 7 ms 4992 KB Output is correct
6 Correct 8 ms 4992 KB Output is correct
7 Correct 8 ms 4992 KB Output is correct
8 Correct 7 ms 4992 KB Output is correct
9 Correct 6 ms 4992 KB Output is correct
10 Correct 7 ms 4992 KB Output is correct
11 Correct 8 ms 4992 KB Output is correct
12 Correct 8 ms 4992 KB Output is correct
13 Correct 7 ms 4992 KB Output is correct
14 Correct 8 ms 4992 KB Output is correct
15 Correct 7 ms 4992 KB Output is correct
16 Correct 8 ms 5028 KB Output is correct
17 Correct 7 ms 4992 KB Output is correct
18 Correct 8 ms 4992 KB Output is correct
19 Correct 7 ms 5120 KB Output is correct
20 Correct 8 ms 4992 KB Output is correct
21 Correct 6 ms 4952 KB Output is correct
22 Correct 7 ms 5120 KB Output is correct
23 Correct 6 ms 4992 KB Output is correct
24 Correct 8 ms 5076 KB Output is correct
25 Correct 8 ms 4992 KB Output is correct
26 Correct 6 ms 4992 KB Output is correct
27 Correct 7 ms 4992 KB Output is correct
28 Correct 7 ms 4992 KB Output is correct
29 Correct 6 ms 4992 KB Output is correct
30 Correct 7 ms 4992 KB Output is correct
31 Correct 6 ms 4964 KB Output is correct
32 Correct 7 ms 4992 KB Output is correct
33 Correct 6 ms 4992 KB Output is correct
34 Correct 8 ms 4992 KB Output is correct
35 Correct 6 ms 4992 KB Output is correct
36 Correct 8 ms 4992 KB Output is correct
37 Correct 7 ms 4992 KB Output is correct
38 Correct 7 ms 4992 KB Output is correct
39 Correct 7 ms 4992 KB Output is correct
40 Correct 7 ms 4992 KB Output is correct
41 Correct 8 ms 5120 KB Output is correct
42 Correct 6 ms 4992 KB Output is correct
43 Correct 7 ms 4984 KB Output is correct
44 Correct 6 ms 4992 KB Output is correct
45 Correct 6 ms 4992 KB Output is correct
46 Correct 7 ms 4964 KB Output is correct
47 Correct 6 ms 4992 KB Output is correct
48 Correct 7 ms 5020 KB Output is correct
49 Correct 7 ms 4992 KB Output is correct
50 Correct 7 ms 4992 KB Output is correct
51 Correct 7 ms 4992 KB Output is correct
52 Correct 7 ms 4992 KB Output is correct
53 Correct 8 ms 4992 KB Output is correct
54 Correct 7 ms 4992 KB Output is correct
55 Correct 6 ms 4992 KB Output is correct
56 Correct 7 ms 4992 KB Output is correct
57 Correct 7 ms 4992 KB Output is correct
58 Correct 7 ms 4992 KB Output is correct
59 Correct 7 ms 4992 KB Output is correct
60 Correct 6 ms 4992 KB Output is correct
61 Correct 6 ms 4992 KB Output is correct
62 Correct 6 ms 4992 KB Output is correct
63 Correct 7 ms 4992 KB Output is correct
64 Correct 8 ms 5120 KB Output is correct
65 Correct 6 ms 4992 KB Output is correct
66 Correct 7 ms 5036 KB Output is correct
67 Correct 7 ms 4992 KB Output is correct
68 Correct 7 ms 4964 KB Output is correct
69 Correct 8 ms 4992 KB Output is correct
70 Correct 8 ms 5120 KB Output is correct
71 Correct 7 ms 5168 KB Output is correct
72 Correct 6 ms 5120 KB Output is correct
73 Correct 7 ms 4992 KB Output is correct
74 Correct 7 ms 4992 KB Output is correct
75 Correct 7 ms 4992 KB Output is correct
76 Correct 7 ms 4988 KB Output is correct
77 Correct 8 ms 5120 KB Output is correct
78 Correct 7 ms 4992 KB Output is correct
79 Correct 7 ms 4992 KB Output is correct
80 Correct 8 ms 4992 KB Output is correct
81 Correct 7 ms 5120 KB Output is correct
82 Correct 8 ms 5120 KB Output is correct
83 Correct 7 ms 5120 KB Output is correct
84 Correct 7 ms 5120 KB Output is correct
85 Correct 7 ms 4992 KB Output is correct
86 Correct 2 ms 4992 KB Output is correct
87 Correct 7 ms 5120 KB Output is correct
88 Correct 7 ms 5120 KB Output is correct
89 Correct 8 ms 5020 KB Output is correct
90 Correct 8 ms 5120 KB Output is correct
91 Correct 6 ms 5120 KB Output is correct
92 Correct 8 ms 4992 KB Output is correct
93 Correct 8 ms 5120 KB Output is correct
94 Correct 6 ms 4992 KB Output is correct
95 Correct 7 ms 5120 KB Output is correct
96 Correct 6 ms 5120 KB Output is correct
97 Correct 8 ms 5120 KB Output is correct
98 Correct 7 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 13400 KB Output is correct
2 Correct 7 ms 5376 KB Output is correct
3 Correct 24 ms 8568 KB Output is correct
4 Correct 48 ms 11768 KB Output is correct
5 Correct 105 ms 13172 KB Output is correct
6 Correct 90 ms 9976 KB Output is correct
7 Correct 122 ms 13432 KB Output is correct
8 Correct 17 ms 8832 KB Output is correct
9 Correct 14 ms 8576 KB Output is correct
10 Correct 106 ms 13392 KB Output is correct
11 Correct 82 ms 12020 KB Output is correct
12 Correct 97 ms 11144 KB Output is correct
13 Correct 10 ms 5888 KB Output is correct
14 Correct 10 ms 5760 KB Output is correct
15 Correct 146 ms 16772 KB Output is correct
16 Correct 30 ms 9080 KB Output is correct
17 Correct 135 ms 17172 KB Output is correct
18 Correct 70 ms 8880 KB Output is correct
19 Correct 12 ms 5760 KB Output is correct
20 Correct 45 ms 12508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4992 KB Output is correct
2 Correct 7 ms 4992 KB Output is correct
3 Correct 6 ms 4992 KB Output is correct
4 Correct 6 ms 4992 KB Output is correct
5 Correct 7 ms 4992 KB Output is correct
6 Correct 8 ms 4992 KB Output is correct
7 Correct 8 ms 4992 KB Output is correct
8 Correct 7 ms 4992 KB Output is correct
9 Correct 6 ms 4992 KB Output is correct
10 Correct 7 ms 4992 KB Output is correct
11 Correct 8 ms 4992 KB Output is correct
12 Correct 8 ms 4992 KB Output is correct
13 Correct 7 ms 4992 KB Output is correct
14 Correct 8 ms 4992 KB Output is correct
15 Correct 7 ms 4992 KB Output is correct
16 Correct 8 ms 5028 KB Output is correct
17 Correct 7 ms 4992 KB Output is correct
18 Correct 8 ms 4992 KB Output is correct
19 Correct 7 ms 5120 KB Output is correct
20 Correct 8 ms 4992 KB Output is correct
21 Correct 6 ms 4952 KB Output is correct
22 Correct 7 ms 5120 KB Output is correct
23 Correct 6 ms 4992 KB Output is correct
24 Correct 8 ms 5076 KB Output is correct
25 Correct 8 ms 4992 KB Output is correct
26 Correct 6 ms 4992 KB Output is correct
27 Correct 7 ms 4992 KB Output is correct
28 Correct 7 ms 4992 KB Output is correct
29 Correct 6 ms 4992 KB Output is correct
30 Correct 7 ms 4992 KB Output is correct
31 Correct 6 ms 4964 KB Output is correct
32 Correct 7 ms 4992 KB Output is correct
33 Correct 6 ms 4992 KB Output is correct
34 Correct 8 ms 4992 KB Output is correct
35 Correct 6 ms 4992 KB Output is correct
36 Correct 8 ms 4992 KB Output is correct
37 Correct 7 ms 4992 KB Output is correct
38 Correct 7 ms 4992 KB Output is correct
39 Correct 7 ms 4992 KB Output is correct
40 Correct 7 ms 4992 KB Output is correct
41 Correct 8 ms 5120 KB Output is correct
42 Correct 6 ms 4992 KB Output is correct
43 Correct 7 ms 4984 KB Output is correct
44 Correct 6 ms 4992 KB Output is correct
45 Correct 6 ms 4992 KB Output is correct
46 Correct 7 ms 4964 KB Output is correct
47 Correct 6 ms 4992 KB Output is correct
48 Correct 7 ms 5020 KB Output is correct
49 Correct 7 ms 4992 KB Output is correct
50 Correct 7 ms 4992 KB Output is correct
51 Correct 7 ms 4992 KB Output is correct
52 Correct 7 ms 4992 KB Output is correct
53 Correct 8 ms 4992 KB Output is correct
54 Correct 7 ms 4992 KB Output is correct
55 Correct 6 ms 4992 KB Output is correct
56 Correct 7 ms 4992 KB Output is correct
57 Correct 7 ms 4992 KB Output is correct
58 Correct 7 ms 4992 KB Output is correct
59 Correct 7 ms 4992 KB Output is correct
60 Correct 6 ms 4992 KB Output is correct
61 Correct 6 ms 4992 KB Output is correct
62 Correct 6 ms 4992 KB Output is correct
63 Correct 7 ms 4992 KB Output is correct
64 Correct 8 ms 5120 KB Output is correct
65 Correct 6 ms 4992 KB Output is correct
66 Correct 7 ms 5036 KB Output is correct
67 Correct 7 ms 4992 KB Output is correct
68 Correct 7 ms 4964 KB Output is correct
69 Correct 8 ms 4992 KB Output is correct
70 Correct 8 ms 5120 KB Output is correct
71 Correct 7 ms 5168 KB Output is correct
72 Correct 6 ms 5120 KB Output is correct
73 Correct 7 ms 4992 KB Output is correct
74 Correct 7 ms 4992 KB Output is correct
75 Correct 7 ms 4992 KB Output is correct
76 Correct 7 ms 4988 KB Output is correct
77 Correct 8 ms 5120 KB Output is correct
78 Correct 7 ms 4992 KB Output is correct
79 Correct 7 ms 4992 KB Output is correct
80 Correct 8 ms 4992 KB Output is correct
81 Correct 7 ms 5120 KB Output is correct
82 Correct 8 ms 5120 KB Output is correct
83 Correct 7 ms 5120 KB Output is correct
84 Correct 7 ms 5120 KB Output is correct
85 Correct 7 ms 4992 KB Output is correct
86 Correct 2 ms 4992 KB Output is correct
87 Correct 7 ms 5120 KB Output is correct
88 Correct 7 ms 5120 KB Output is correct
89 Correct 8 ms 5020 KB Output is correct
90 Correct 8 ms 5120 KB Output is correct
91 Correct 6 ms 5120 KB Output is correct
92 Correct 8 ms 4992 KB Output is correct
93 Correct 8 ms 5120 KB Output is correct
94 Correct 6 ms 4992 KB Output is correct
95 Correct 7 ms 5120 KB Output is correct
96 Correct 6 ms 5120 KB Output is correct
97 Correct 8 ms 5120 KB Output is correct
98 Correct 7 ms 5120 KB Output is correct
99 Correct 43 ms 13400 KB Output is correct
100 Correct 7 ms 5376 KB Output is correct
101 Correct 24 ms 8568 KB Output is correct
102 Correct 48 ms 11768 KB Output is correct
103 Correct 105 ms 13172 KB Output is correct
104 Correct 90 ms 9976 KB Output is correct
105 Correct 122 ms 13432 KB Output is correct
106 Correct 17 ms 8832 KB Output is correct
107 Correct 14 ms 8576 KB Output is correct
108 Correct 106 ms 13392 KB Output is correct
109 Correct 82 ms 12020 KB Output is correct
110 Correct 97 ms 11144 KB Output is correct
111 Correct 10 ms 5888 KB Output is correct
112 Correct 10 ms 5760 KB Output is correct
113 Correct 146 ms 16772 KB Output is correct
114 Correct 30 ms 9080 KB Output is correct
115 Correct 135 ms 17172 KB Output is correct
116 Correct 70 ms 8880 KB Output is correct
117 Correct 12 ms 5760 KB Output is correct
118 Correct 45 ms 12508 KB Output is correct
119 Correct 9 ms 5888 KB Output is correct
120 Correct 91 ms 14580 KB Output is correct
121 Correct 64 ms 11000 KB Output is correct
122 Correct 6 ms 4992 KB Output is correct
123 Correct 12 ms 5760 KB Output is correct
124 Correct 50 ms 7956 KB Output is correct
125 Correct 45 ms 10096 KB Output is correct
126 Correct 14 ms 7168 KB Output is correct
127 Correct 29 ms 10020 KB Output is correct
128 Correct 91 ms 13004 KB Output is correct
129 Correct 59 ms 10744 KB Output is correct
130 Correct 74 ms 11308 KB Output is correct
131 Correct 7 ms 5632 KB Output is correct
132 Correct 9 ms 5632 KB Output is correct
133 Correct 169 ms 17116 KB Output is correct
134 Correct 69 ms 16544 KB Output is correct
135 Correct 31 ms 16124 KB Output is correct
136 Correct 64 ms 8924 KB Output is correct
137 Correct 92 ms 9972 KB Output is correct
138 Correct 29 ms 13184 KB Output is correct