include iostream include vector include algorithm include cstdio inclu

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <string>
using namespace std;
int main() {
freopen("input.txt", "r", stdin);
int n;
cin >> n;
string p;
cin >> p;
vector<pair<int, int> > answer;
vector<int> t;
vector<int> nums(2 * n, -1);
int count = 0;
for (int i = 0; i < 2 * n; i++) {
if (p[i] >= 'a' && p[i] <= 'z')
nums[i] = ++count;
}
for (int i = 0 ; i < 2 * n; i++)
cout << nums[i] << endl;
bool flag = false;
int v1, v2;
v1 = v2 = -1;
for (int i = 0; i < 2 * n; i++) {
if (nums[i] != -1 && p[i] != '#'){
cout << i << endl;
for (int j = i + 1; j < 2 * n; j++) {
if (tolower(p[j]) == p[i] && p[j] >= 'A' && p[j] <= 'Z') {
v1 = j;
break;
}
}
if (p[i] != '#') {
for (int j = i - 1; j > 0; j--) {
if (tolower(p[j]) == p[i]) {
v2 = j;
break;
}
}
}
if (v1 == -1 && v2 == -1) {
cout << "Impossible" << endl;
return 0;
}
if (v1 == -1) {
pair<int, int> a = make_pair(i, v2);
if (a.first > a.second)
swap(a.first, a.second);
t.push_back(nums[i]);
answer.push_back(a);
p[i] = p[v2] = '#';
}
else if (v2 == -1 ) {
pair<int, int> a = make_pair(i, v1);
if (a.first > a.second)
swap(a.first, a.second);
t.push_back(nums[i]);
answer.push_back(a);
p[i] = p[v1] = '#';
}
else {
if (abs(i - v1) > abs(i - v2))
v1 = v2;
pair<int, int> a = make_pair(i, v1);
if (a.first > a.second)
swap(a.first, a.second);
t.push_back(nums[i]);
answer.push_back(a);
p[i] = p[v1] = '#';
}
}
}
for (int i = 0; i < answer.size(); i++)
cout << answer[i].first << " " << answer[i].second << endl;
cout << answer.size();
if (answer.size() != n) {
cout << "Impossible" << endl;
return 0;
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (answer[i].first < answer[j].first && answer[i].second > answer[j].first && answer[i].second < answer[j].second) {
cout << "Impossible" << endl;;
return 0;
}
}
}
cout << "lol" << endl;
for (int i = 0; i < n; i++)
cout << t[i] << " ";
cout << endl;
/*vector<pair<int, int> > first(n), second(n);
for (int i = 0; i < n; i++) {
cin >> fisrt[i].fisrt;
first[i].second = i + 1;
}
for (int i = 0; i < n; i++) {
cin >> second[i].fisrt;
second[i].second = i + 1;
}*/
return 0;
}