# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
156317 |
2019-10-05T05:35:31 Z |
socho |
GTA (COI14_gta) |
C++14 |
|
768 ms |
15116 KB |
#include "bits/stdc++.h"
using namespace std;
string g = "ACGT";
int TRUNCATE = 6;
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
gta.cpp: In function 'std::__cxx11::string sh(std::__cxx11::string)':
gta.cpp:18:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0; i<s.size(); i++) {
~^~~~~~~~~
gta.cpp: In function 'std::vector<std::__cxx11::basic_string<char> > gwi(int)':
gta.cpp:75:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j=0; j<las.size(); j++) {
~^~~~~~~~~~~
gta.cpp: In function 'void proc(std::__cxx11::string)':
gta.cpp:91:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (s.size() >= TRUNCATE) return;
~~~~~~~~~^~~~~~~~~~~
gta.cpp:92:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0; i<s.size(); i++) {
~^~~~~~~~~
gta.cpp:96:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j=i+1; j<s.size(); j++) c += s[j];
~^~~~~~~~~
gta.cpp: In function 'int main()':
gta.cpp:124:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0; i<all.size(); i++) {
~^~~~~~~~~~~
gta.cpp:128:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0; i<grid.size(); i++) {
~^~~~~~~~~~~~
gta.cpp:129:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j=0; j<grid.size(); j++) {
~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
1648 KB |
Output is correct |
2 |
Correct |
85 ms |
1520 KB |
Output is correct |
3 |
Correct |
87 ms |
1520 KB |
Output is correct |
4 |
Incorrect |
97 ms |
1520 KB |
Output isn't correct |
5 |
Incorrect |
99 ms |
1548 KB |
Output isn't correct |
6 |
Incorrect |
99 ms |
1520 KB |
Output isn't correct |
7 |
Incorrect |
96 ms |
1520 KB |
Output isn't correct |
8 |
Incorrect |
103 ms |
1648 KB |
Output isn't correct |
9 |
Incorrect |
159 ms |
2848 KB |
Output isn't correct |
10 |
Incorrect |
768 ms |
15116 KB |
Output isn't correct |