# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
156318 | socho | GTA (COI14_gta) | C++14 | 1294 ms | 15940 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
using namespace std;
string g = "ACGT";
int TRUNCATE = 7;
int gp(char a, char b) {
if (a == 'T' && b == 'C') return 0;
if (a == 'A' && b == 'G') return 1;
if (a == 'C' && b == 'T') return 2;
if (a == 'G' && b == 'A') return 3;
return 4;
}
string sh(string s) {
stack<char> c;
for (int i=0; i<s.size(); i++) {
c.push(s[i]);
bool can = true;
while (c.size() > 1 && can) {
char t = c.top(); c.pop(); char nx = c.top(); c.push(t);
int res = gp(nx, t);
if (res == 4) can = false;
else {
c.pop();
c.pop();
c.push(g[res]);
}
}
}
string ge;
stack<char> f;
while (!c.empty()) {
f.push(c.top());
c.pop();
}
while (!f.empty()) {
ge += f.top();
f.pop();
}
return ge;
}
vector<string> r;
map<string, string> par;
string parent(string s) {
if (par[s] == s) return s;
return par[s] = parent(par[s]);
}
bool arc(string a, string b) {
// cout << parent(a) << ' ' << parent(b) << endl;
return parent(a) == parent(b);
}
void connect(string a, string b) {
if (arc(a, b)) return;
string ax = parent(a);
string bx = parent(b);
par[ax] = bx;
}
vector<string> gwi(int n) {
if (n == 0) {
return r;
}
vector<string> rs;
vector<string> las = gwi(n-1);
for (int j=0; j<las.size(); j++) {
for (int i=0; i<4; i++) {
string cons = las[j] + g[i];
par[cons] = cons;
// cout << cons << endl;
rs.push_back(cons);
}
rs.push_back(las[j]);
}
return rs;
}
map<char, string> inv;
void proc(string s) {
if (s.size() >= TRUNCATE) return;
for (int i=0; i<s.size(); i++) {
string c = "";
for (int j=0; j<i; j++) c += s[j];
c += inv[s[i]];
for (int j=i+1; j<s.size(); j++) c += s[j];
// cout << "! " << s << ' ' << c << endl;
connect(s, c);
}
}
int main() {
inv['A'] = "TC";
inv['C'] = "AG";
inv['G'] = "CT";
inv['T'] = "GA";
int n;
cin >> n;
vector<string> grid;
for (int i=0; i<n; i++) {
string s;
cin >> s;
string result = sh(s);
par[result] = result;
grid.push_back(result);
}
r.push_back("");
vector<string> all = gwi(TRUNCATE);
// cout << all.size() << endl;
for (int i=0; i<all.size(); i++) {
proc(all[i]);
}
for (int i=0; i<grid.size(); i++) {
for (int j=0; j<grid.size(); j++) {
cout << arc(grid[i], grid[j]);
}
cout << endl;
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |