Submission #156318

# Submission time Handle Problem Language Result Execution time Memory
156318 2019-10-05T05:36:58 Z socho GTA (COI14_gta) C++14
50 / 100
1294 ms 15940 KB
#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

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++) {
                 ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 560 ms 7296 KB Output is correct
2 Correct 558 ms 7292 KB Output is correct
3 Correct 571 ms 7300 KB Output is correct
4 Correct 598 ms 7300 KB Output is correct
5 Correct 591 ms 7300 KB Output is correct
6 Incorrect 597 ms 7300 KB Output isn't correct
7 Incorrect 603 ms 7432 KB Output isn't correct
8 Incorrect 617 ms 7428 KB Output isn't correct
9 Incorrect 669 ms 8196 KB Output isn't correct
10 Incorrect 1294 ms 15940 KB Output isn't correct