Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- /*
- █▒▒▒▒▒▒▒▒▒
- 10%
- ███▒▒▒▒▒▒▒
- 30%
- █████▒▒▒▒▒
- 50%
- ███████▒▒▒
- 70%
- ██████████
- 100%
- .
- ☁☁☁☁☁☁☁⚡
- ☁☁☁☁☁☁⚡☁
- ☁☁☁☁☁⚡⚡☁
- ☁☁☁☁⚡⚡☁☁
- ☁☁☁⚡⚡☁☁☁
- ☁☁⚡⚡⚡☁☁☁
- ☁⚡⚡⚡☁☁☁☁
- ⚡⚡⚡⚡⚡⚡⚡⚡
- ⚡⚡⚡⚡⚡⚡⚡⚡
- ☁☁☁☁⚡⚡⚡☁
- ☁☁☁⚡⚡⚡☁☁
- ☁☁☁⚡⚡☁☁☁
- ☁☁⚡⚡☁☁☁☁
- ☁⚡⚡☁☁☁☁☁
- ☁⚡☁☁☁☁☁☁
- ⚡☁☁☁☁☁☁☁
- ▀█▀ █░░ █▀▀ █▀ █░░ ▄▀▄ ▄▀▀ █░░ █▄░█ █▀▀ █░░░█ ▒█▀▀ ▒▄█░
- ░█░ █▀▄ █▀▀ █▀ █░▄ █▀█ ░▀▄ █▀▄ █░▀█ █▀▀ █░█░█ ▒▀▀▄ ░▒█░
- ░▀░ ▀░▀ ▀▀▀ ▀░ ▀▀▀ ▀░▀ ▀▀░ ▀░▀ ▀░░▀ ▀▀▀ ░▀░▀░ ▒▄▄▀ ▒▄█▄
- */
- const int N = 1e6;
- #define int long long
- map <int, int> newpos, mp;
- vector <int > g[N];
- main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- string s, s1;
- cin >> s;
- set <char> kol;
- for (int i = 0; i < s.size(); i++) {
- kol.insert(s[i]);
- newpos[i] = i;
- mp[i] = i;
- }
- if (kol.size() == 1) {
- cout << 0 << "\n";
- cout.flush();
- cout << s;
- cout.flush();
- return 0;
- }
- vector <pair <int, int> > ask;
- for (int i = 0; i < s.size(); i++) {
- for (int j = i + 1; j < s.size(); j++) {
- if (s[i] != s[j]) {
- g[i].push_back(j);
- ask.push_back({i + 1, j + 1});
- }
- }
- }
- cout << ask.size() << "\n";
- cout.flush();
- for (auto to : ask) {
- cout << to.first << ' ' << to.second << "\n";
- cout.flush();
- }
- string bin;
- cin >> bin;
- int i = 0, j = 0;
- while (i < ask.size()) {
- int i1 = 0;
- while (i < ask.size() && i1 < g[j].size()) {
- if (bin[i] == '1') {
- if (mp[j] > mp[ask[i].second - 1]) {
- //cout << "kek";
- int po = mp[ask[i].second - 1], x = mp[j];
- char c2 = s[po];
- for (int z = mp[ask[i].second - 1]; z < mp[j]; z++) {
- int po1 = newpos[z + 1];
- newpos[z] = po1;
- s[z] = s[z + 1];
- mp[po1] = z;
- }
- s[x] = c2;
- newpos[x] = po;
- mp[po] = x;
- }
- }
- else {
- if (mp[j] < mp[ask[i].second - 1]) {
- int po = mp[ask[i].second - 1], x = mp[j];
- char c2 = s[po];
- for (int z = mp[ask[i].second - 1]; z > mp[j]; z--) {
- int po1 = newpos[z - 1];
- newpos[z] = po1;
- s[z] = s[z - 1];
- mp[po1] = z;
- }
- s[x] = c2;
- newpos[x] = po;
- mp[po] = x;
- }
- }
- i++;
- i1++;
- }
- j++;
- }
- string ans = s;
- cout << ans;
- cout.flush();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement