Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <cctype>
- #include <cstdio>
- #include <cstring>
- #include <iostream>
- #include <sstream>
- #include <string>
- #include <vector>
- using namespace std;
- typedef long long i64;
- const int MAX_N = 200005;
- const int MAX_L = 1000005;
- int tmp[MAX_L];
- string s;
- string t;
- vector<int> pos[MAX_N];
- vector<int> pl;
- int early[MAX_N];
- int late[MAX_N];
- int ans[2][MAX_L];
- int ToNum(const string &s) {
- stringstream ss;
- ss.str(s);
- int res;
- ss >> res;
- return res;
- }
- int main() {
- #ifdef NOVACO
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #else
- freopen("math.in", "r", stdin);
- freopen("math.out", "w", stdout);
- #endif
- getline(cin, s);
- int n = s.size();
- for (int i = 0, j; i < n; i = j) {
- if (s[i] == '^') {
- tmp[i] = pl.size();
- pl.push_back(i);
- t = "";
- j = i + 1;
- while (j < n && isdigit(s[j])) {
- t += s[j];
- j++;
- }
- if (t.size() > 5) {
- continue;
- }
- int num = ToNum(t);
- if (num >= MAX_N) {
- continue;
- }
- pos[num].push_back(i);
- } else {
- j = i + 1;
- }
- }
- int last_pos = -1;
- int max_n = 1;
- while (true) {
- int p = upper_bound(pos[max_n].begin(), pos[max_n].end(), last_pos) - pos[max_n].begin();
- if (p == pos[max_n].size()) {
- break;
- }
- early[max_n] = p;
- last_pos = pos[max_n][p];
- max_n++;
- }
- last_pos = n;
- for (int j = max_n - 1; j >= 1; j--) {
- int p = lower_bound(pos[j].begin(), pos[j].end(), last_pos) - pos[j].begin() - 1;
- late[j] = p;
- last_pos = pos[j][p];
- }
- memset(ans, -1, sizeof(ans));
- for (int i = 1; i < max_n; i++) {
- for (int j = 0; j < pos[i].size(); j++) {
- if (j >= early[i] && j <= late[i]) {
- ans[0][tmp[pos[i][j]]] = 1;
- if (late[i] - early[i] > 0) {
- ans[1][tmp[pos[i][j]]] = 1;
- } else {
- ans[1][tmp[pos[i][j]]] = 0;
- }
- } else {
- ans[0][tmp[pos[i][j]]] = 0;
- ans[1][tmp[pos[i][j]]] = 1;
- }
- }
- }
- for (int i = 0; i < pl.size(); i++) {
- if (ans[0][tmp[pl[i]]] == -1) {
- ans[0][tmp[pl[i]]] = 0;
- ans[1][tmp[pl[i]]] = 1;
- }
- }
- cout << pl.size() << "\n";
- for (int i = 0; i < pl.size(); i++) {
- cout << (ans[1][i] ? "Y" : "N");
- }
- cout << "\n";
- for (int i = 0; i < pl.size(); i++) {
- cout << (ans[0][i] ? "Y" : "N");
- }
- cout << "\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment