답안 #277449

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
277449 2020-08-21T05:12:21 Z 임성재(#5118) Travelling Salesperson (CCO20_day2problem1) C++17
0 / 25
2 ms 512 KB
#include<bits/stdc++.h>
using namespace std;

#define fast ios::sync_with_stdio(false); cin.tie(0);
#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf = 1e9;
const ll INF = 1e18;

int n;
int g[2010][2010];
vector<int> ans, v;

void f(int r) {
	ans.clear();
	
	ans.eb(r);
	int m = r;

	for(int i=1; i<=n; i++) {
		if(i == r) continue;

		v.clear();

		bool flag = false;
		for(int j=0; j<ans.size(); j++) {
			if(!flag && ans[j] == m) {
				flag = true;
				if(g[m][i] == 1) {
					v.eb(m);
					v.eb(i);

					if(j+1 < ans.size() && g[i][ans[j+1]] == 1) m = ans[j+1];
					else m = i;
				}
				else {
					v.eb(i);
					v.eb(m);

					if(j-1 >= 0 && g[i][ans[j-1]] == 2) m = ans[j-1];
					else m = i;
				}
			}
			else v.eb(ans[j]);
		}

		ans = v;
	}	
	
	if(ans[0] != r) reverse(all(ans));

	assert(ans[0] == r);

	cout << ans.size() << "\n";
	for(auto i : ans) {
		cout << i << " ";
	}
	cout << "\n";
}

int main() {
	fast;

	cin >> n;

	for(int i=2; i<=n; i++) {
		string s;
		cin >> s;

		for(int j=1; j<i; j++) {
			g[i][j] = g[j][i] = (s[j-1] == 'R') + 1;
		}
	}

	for(int i=1; i<=n; i++) {
		f(i);
	}
}

Compilation message

Main.cpp: In function 'void f(int)':
Main.cpp:34:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |   for(int j=0; j<ans.size(); j++) {
      |                ~^~~~~~~~~~~
Main.cpp:41:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |      if(j+1 < ans.size() && g[i][ans[j+1]] == 1) m = ans[j+1];
      |         ~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Runtime error 2 ms 512 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -