Submission #375994

#TimeUsernameProblemLanguageResultExecution timeMemory
375994mihai145Travelling Salesperson (CCO20_day2problem1)C++14
0 / 25
1 ms384 KiB
#include <iostream> #include <string> #include <deque> #include <algorithm> using namespace std; const int NMAX = 2000; int N; string m[NMAX + 2]; ///0-> BLUE ///1-> RED bool Edge(int x, int y) { if(x < y) { swap(x, y); } if(m[x][y] == 'B') { return 0; } return 1; } deque <int> dq; void Push(int vert) { if(dq.empty()) { dq.push_back(vert); } else { if(Edge(dq.back(), vert) == 1) { dq.push_back(vert); } else if(Edge(dq.front(), vert) == 0) { dq.push_front(vert); } else if(Edge(dq.front(), dq.back()) == 1) { int frontVert = dq.front(); dq.pop_front(); dq.push_back(frontVert); dq.push_back(vert); } else { int backVert = dq.back(); dq.pop_back(); dq.push_back(backVert); dq.push_back(vert); } } } void SolveFor(int vert) { dq.clear(); for(int i = 0; i < N; i++) { if(i != vert) { Push(i); } } Push(vert); if(dq.back() == vert) { reverse(dq.begin(), dq.end()); } cout << N << '\n'; for(int v : dq) { cout << v + 1 << ' '; } cout << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> N; for(int i = 1; i < N; i++) { cin >> m[i]; } for(int i = 0; i < N; i++) { SolveFor(i); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...