Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <vector>
- #include <algorithm>
- using namespace std;
- int n;
- vector <bool> a;
- vector <int> p(0), g(0);
- vector <pair <int, int> > res(0);
- int main()
- {
- scanf("%d", &n);
- a.assign(n, false);
- for (int i = 0; i < n; ++i)
- {
- int x;
- scanf("%d", &x);
- if (x == 2)
- {
- a[x] = true;
- g.push_back(i);
- }
- else
- p.push_back(i);
- }
- p.push_back(n);
- g.push_back(n);
- for (int t = 1; t < n; ++t)
- {
- bool success = true;
- int p_s = 0, g_s = 0, p_i = 0, g_i = 0;
- while (p[p_i] < n || g[g_i] < n)
- {
- if (p_i + t >= p.size())
- {
- if (g_i + t >= g.size())
- {
- success = false;
- break;
- }
- g_i += t;
- ++g_s;
- int x = lower_bound(p.begin(), p.end(), g[g_i]) - p.begin();
- --x;
- if (x >= 0 && x < p.size())
- {
- p_i = max(p_i, x);
- }
- break;
- }
- if (g_i + t >= g.size())
- {
- p_i += t;
- ++p_s;
- int x = lower_bound(g.begin(), g.end(), p[p_i]) - g.begin();
- --x;
- if (x >= 0 && x < g.size())
- {
- g_i = max(g_i, x);
- }
- break;
- }
- if (p[p_i + t] < g[g_i + t])
- {
- p_i += t;
- ++p_s;
- int x = lower_bound(g.begin(), g.end(), p[p_i]) - g.begin();
- --x;
- if (x >= 0 && x < g.size())
- {
- g_i = max(g_i, x);
- }
- }
- else
- {
- g_i += t;
- ++g_s;
- int x = lower_bound(p.begin(), p.end(), g[g_i]) - p.begin();
- --x;
- if (x >= 0 && x < p.size())
- {
- p_i = max(p_i, x);
- }
- }
- }
- if (success && p_s != g_s)
- res.push_back(make_pair(max(p_s, g_s), t));
- }
- sort(res.begin(), res.end());
- printf("%d\n", res.size());
- for (int i = 0; i < res.size(); ++i)
- printf("%d %d\n", res[i].first, res[i].second);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement