You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.9 KiB
60 lines
1.9 KiB
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
|
|
int n, flag, axis;
|
|
string s, ans;
|
|
struct Node {
|
|
int x, y;
|
|
char v; // value
|
|
};
|
|
vector<Node> pt;
|
|
struct Node inf;
|
|
|
|
bool comp(const Node &a, const Node &b) {
|
|
if (a.v == b.v) {
|
|
return (a.x == b.x) ? (a.y < b.y) : (a.x < b.x);
|
|
} else {
|
|
return a.v < b.v;
|
|
}
|
|
}
|
|
int main() {
|
|
cin >> n >> s;
|
|
for (int i = 0; i < n; i++) {
|
|
for (int j = 0; j <= i; j++) {
|
|
Node newPt;
|
|
newPt.v = s[flag];
|
|
newPt.y = i;
|
|
newPt.x = axis + (j << 1);
|
|
++flag;
|
|
pt.push_back(newPt);
|
|
}
|
|
--axis;
|
|
}
|
|
inf.x = (1 << 8), inf.y = (1 << 8), inf.v = '~';
|
|
pt.push_back(inf);
|
|
sort(pt.begin(), pt.end(), comp);
|
|
for (int count = 0; count <= flag; ++count) {
|
|
if (pt[count].v == '~') {
|
|
break;
|
|
}
|
|
if (pt[count].v != pt[count + 1].v) {
|
|
if (pt[count - 2].v == pt[count].v) {
|
|
int dist[3];
|
|
dist[0] = (pt[count - 2].x - pt[count - 1].x) * (pt[count - 2].x - pt[count - 1].x)
|
|
+ 3 * (pt[count - 2].y - pt[count - 1].y) * (pt[count - 2].y - pt[count - 1].y);
|
|
dist[1] = (pt[count - 2].x - pt[count].x) * (pt[count - 2].x - pt[count].x)
|
|
+ 3 * (pt[count - 2].y - pt[count].y) * (pt[count - 2].y - pt[count].y);
|
|
dist[2] = (pt[count - 1].x - pt[count].x) * (pt[count - 1].x - pt[count].x)
|
|
+ 3 * (pt[count - 1].y - pt[count].y) * (pt[count - 1].y - pt[count].y);
|
|
if (dist[1] == dist[2] && dist[0] == dist[1]) {
|
|
ans = ans + pt[count].v;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (ans != "")
|
|
cout << ans << endl;
|
|
else
|
|
puts("No Solution");
|
|
return 0;
|
|
} |