답안 #277630

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
277630 2020-08-21T06:24:02 Z 송준혁(#5117) Travelling Salesperson (CCO20_day2problem1) C++17
25 / 25
3858 ms 34732 KB
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

int N;
int A[2020][2020];
vector<int> ans;

int main(){
	char ch;
	scanf("%d", &N);
	for (int i=2; i<=N; i++) for (int j=1; j<i; j++) scanf(" %c", &ch), A[j][i] = A[i][j] = (ch == 'R');
	for (int i=1; i<=N; i++){
		printf("%d\n", N);
		int a, t=-1;
		ans.clear();
		ans.pb(i);
		for (int j=1; j<=N; j++){
			if (i==j) continue;
			if (ans.size()==1){
				a = A[i][j], ans.pb(j);
				continue;
			}
			if (t<0){
				if (A[ans.back()][j] != a) t = ans.size()-1;
				ans.pb(j);
			}
			else{
				ans.pb(j);
				for (int k=ans.size()-1; k>t+1; k--) swap(ans[k], ans[k-1]);
				if (A[ans[t]][j] == a){
					t++;
					if (A[ans[t+1]][j] == a) t++;
					if (t == ans.size()-1) t=-1;
				}
				else{
					swap(ans[t], ans[t+1]);
					if (A[ans[t-1]][j] != a) t--;
					if (!t) t=-1, a = !a;
				}
			}
		}
		for (int x : ans) printf("%d ", x);
		printf("\n");
	}
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:36:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |      if (t == ans.size()-1) t=-1;
      |          ~~^~~~~~~~~~~~~~~
Main.cpp:13:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   13 |  scanf("%d", &N);
      |  ~~~~~^~~~~~~~~~
Main.cpp:14:56: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   14 |  for (int i=2; i<=N; i++) for (int j=1; j<i; j++) scanf(" %c", &ch), A[j][i] = A[i][j] = (ch == 'R');
      |                                                   ~~~~~^~~~~~~~~~~~
Main.cpp:27:5: warning: 'a' may be used uninitialized in this function [-Wmaybe-uninitialized]
   27 |     if (A[ans.back()][j] != a) t = ans.size()-1;
      |     ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 664 ms 34680 KB Output is correct
17 Correct 600 ms 34424 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 620 ms 34296 KB Output is correct
20 Correct 2808 ms 34420 KB Output is correct
21 Correct 1 ms 512 KB Output is correct
22 Correct 618 ms 34400 KB Output is correct
23 Correct 627 ms 34196 KB Output is correct
24 Correct 2 ms 768 KB Output is correct
25 Correct 610 ms 34180 KB Output is correct
26 Correct 634 ms 34360 KB Output is correct
27 Correct 47 ms 4344 KB Output is correct
28 Correct 699 ms 34296 KB Output is correct
29 Correct 645 ms 34168 KB Output is correct
30 Correct 623 ms 34296 KB Output is correct
31 Correct 685 ms 34248 KB Output is correct
32 Correct 637 ms 34296 KB Output is correct
33 Correct 695 ms 34400 KB Output is correct
34 Correct 625 ms 34256 KB Output is correct
35 Correct 649 ms 34404 KB Output is correct
36 Correct 641 ms 34448 KB Output is correct
37 Correct 668 ms 34296 KB Output is correct
38 Correct 639 ms 34552 KB Output is correct
39 Correct 638 ms 34296 KB Output is correct
40 Correct 608 ms 34504 KB Output is correct
41 Correct 594 ms 34296 KB Output is correct
42 Correct 593 ms 34296 KB Output is correct
43 Correct 598 ms 34300 KB Output is correct
44 Correct 656 ms 34244 KB Output is correct
45 Correct 596 ms 34296 KB Output is correct
46 Correct 619 ms 34168 KB Output is correct
47 Correct 666 ms 34416 KB Output is correct
48 Correct 602 ms 34244 KB Output is correct
49 Correct 596 ms 34424 KB Output is correct
50 Correct 596 ms 34324 KB Output is correct
51 Correct 1571 ms 34092 KB Output is correct
52 Correct 986 ms 34592 KB Output is correct
53 Correct 597 ms 34340 KB Output is correct
54 Correct 602 ms 34424 KB Output is correct
55 Correct 706 ms 34416 KB Output is correct
56 Correct 757 ms 34556 KB Output is correct
57 Correct 1874 ms 34532 KB Output is correct
58 Correct 1935 ms 34552 KB Output is correct
59 Correct 1866 ms 34312 KB Output is correct
60 Correct 1886 ms 34372 KB Output is correct
61 Correct 1900 ms 34408 KB Output is correct
62 Correct 1818 ms 34536 KB Output is correct
63 Correct 1876 ms 34560 KB Output is correct
64 Correct 2672 ms 34504 KB Output is correct
65 Correct 1931 ms 34372 KB Output is correct
66 Correct 2182 ms 34440 KB Output is correct
67 Correct 2033 ms 34444 KB Output is correct
68 Correct 1788 ms 34460 KB Output is correct
69 Correct 2107 ms 34420 KB Output is correct
70 Correct 3623 ms 34496 KB Output is correct
71 Correct 1930 ms 34552 KB Output is correct
72 Correct 1811 ms 34732 KB Output is correct
73 Correct 2032 ms 34504 KB Output is correct
74 Correct 2223 ms 34364 KB Output is correct
75 Correct 3515 ms 34460 KB Output is correct
76 Correct 2522 ms 34484 KB Output is correct
77 Correct 1842 ms 34344 KB Output is correct
78 Correct 2238 ms 34424 KB Output is correct
79 Correct 3587 ms 34440 KB Output is correct
80 Correct 2266 ms 34580 KB Output is correct
81 Correct 1983 ms 34544 KB Output is correct
82 Correct 3858 ms 34388 KB Output is correct
83 Correct 3563 ms 34380 KB Output is correct
84 Correct 1838 ms 34424 KB Output is correct
85 Correct 2228 ms 34384 KB Output is correct
86 Correct 1924 ms 34444 KB Output is correct
87 Correct 72 ms 4348 KB Output is correct
88 Correct 83 ms 4344 KB Output is correct
89 Correct 2790 ms 34372 KB Output is correct
90 Correct 2723 ms 34460 KB Output is correct
91 Correct 63 ms 4344 KB Output is correct
92 Correct 54 ms 4344 KB Output is correct
93 Correct 1517 ms 34576 KB Output is correct
94 Correct 1324 ms 34584 KB Output is correct
95 Correct 70 ms 4344 KB Output is correct
96 Correct 66 ms 4344 KB Output is correct
97 Correct 2494 ms 34632 KB Output is correct
98 Correct 2723 ms 34500 KB Output is correct