結果
問題 | No.5007 Steiner Space Travel |
ユーザー | ebicochineal |
提出日時 | 2022-07-30 17:14:24 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 902 ms / 1,000 ms |
コード長 | 9,783 bytes |
コンパイル時間 | 1,258 ms |
実行使用メモリ | 6,952 KB |
スコア | 6,722,614 |
最終ジャッジ日時 | 2022-07-30 17:14:55 |
合計ジャッジ時間 | 30,884 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge10 |
純コード判定しない問題か言語 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 901 ms
4,904 KB |
testcase_01 | AC | 902 ms
4,904 KB |
testcase_02 | AC | 902 ms
4,900 KB |
testcase_03 | AC | 902 ms
5,156 KB |
testcase_04 | AC | 902 ms
6,948 KB |
testcase_05 | AC | 902 ms
4,900 KB |
testcase_06 | AC | 901 ms
4,904 KB |
testcase_07 | AC | 902 ms
4,904 KB |
testcase_08 | AC | 902 ms
6,952 KB |
testcase_09 | AC | 902 ms
6,948 KB |
testcase_10 | AC | 902 ms
4,904 KB |
testcase_11 | AC | 902 ms
6,948 KB |
testcase_12 | AC | 902 ms
6,952 KB |
testcase_13 | AC | 902 ms
4,904 KB |
testcase_14 | AC | 902 ms
4,900 KB |
testcase_15 | AC | 902 ms
6,948 KB |
testcase_16 | AC | 902 ms
4,900 KB |
testcase_17 | AC | 902 ms
4,904 KB |
testcase_18 | AC | 901 ms
4,900 KB |
testcase_19 | AC | 902 ms
4,904 KB |
testcase_20 | AC | 902 ms
4,900 KB |
testcase_21 | AC | 902 ms
4,904 KB |
testcase_22 | AC | 902 ms
4,904 KB |
testcase_23 | AC | 902 ms
4,904 KB |
testcase_24 | AC | 902 ms
6,952 KB |
testcase_25 | AC | 902 ms
6,948 KB |
testcase_26 | AC | 902 ms
4,904 KB |
testcase_27 | AC | 902 ms
4,904 KB |
testcase_28 | AC | 902 ms
6,948 KB |
testcase_29 | AC | 902 ms
4,900 KB |
ソースコード
#pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("inline") #include <cmath> #include <string> #include <array> #include <vector> #include <cstdlib> #include <sstream> #include <iostream> #include <algorithm> #include <limits> #include <queue> #include <set> #include <unordered_set> #include <map> #include <unordered_map> #include <bitset> #include <chrono> using namespace std; template<class F, class S> string in_v_to_str (const pair<F, S> v); template<class F, class S> string v_to_str (const pair<F, S> v); string in_v_to_str (const char v) { return "'" + string{v} + "'"; } string in_v_to_str (const char* v) { return "\"" + string(v) + "\""; } string in_v_to_str (const string v) { return "\"" + v + "\""; } template<class T> string in_v_to_str (const T v) { stringstream ss; ss << v; return ss.str(); } template<class T> string v_to_str (const T v) { stringstream ss; ss << v; return ss.str(); } template<class T, size_t N> string v_to_str (const array<T, N>& v) { stringstream ss; if (v.size() > 0) { ss << "["; for (size_t i = 0; i < v.size() - 1; ++i) { ss << in_v_to_str(v[i]) << ", "; } ss << in_v_to_str(v[v.size() - 1]) << "]"; } else { ss << "[]"; } return ss.str(); } template<class T, size_t N> string v_to_str (const array< array<T, N>, N >& v) { stringstream ss; if (v.size() > 0) { ss << "["; for (size_t i = 0; i < v.size() - 1; ++i) { ss << v_to_str(v[i]) << ", "; } ss << v_to_str(v[v.size() - 1]) << "]"; } else { ss << "[-]"; } return ss.str(); } template<class T> string v_to_str (const vector<T>& v) { stringstream ss; if (v.size() > 0) { ss << "["; for (size_t i = 0; i < v.size() - 1; ++i) { ss << in_v_to_str(v[i]) << ", "; } ss << in_v_to_str(v[v.size() - 1]) << "]"; } else { ss << "[]"; } return ss.str(); } template<class T> string v_to_str (const vector< vector<T> >& v) { stringstream ss; if (v.size() > 0) { ss << "["; for (size_t i = 0; i < v.size() - 1; ++i) { ss << v_to_str(v[i]) << ", "; } ss << v_to_str(v[v.size() - 1]) << "]"; } else { ss << "[-]"; } return ss.str(); } template<class T> string v_to_str (const set<T>& v) { stringstream ss; int len = v.size(); ss << (v.size() > 0 ? "{" : "{}"); for (auto& i : v) { ss << in_v_to_str(i) << (len-- > 1 ? ", " : "}"); } return ss.str(); } template<class K, class V> string v_to_str (const map<K, V>& v) { stringstream ss; int len = v.size(); ss << (v.size() > 0 ? "{" : "{}"); for (auto& i : v) { ss << in_v_to_str(i.first) << " : " << in_v_to_str(i.second) << (len-- > 1 ? ", " : "}"); } return ss.str(); } template<class T> string v_to_str (const unordered_set<T>& v) { stringstream ss; int len = v.size(); ss << (v.size() > 0 ? "{" : "{}"); for (auto& i : v) { ss << in_v_to_str(i) << (len-- > 1 ? ", " : "}"); } return ss.str(); } template<class K, class V> string v_to_str (const unordered_map<K, V>& v) { stringstream ss; int len = v.size(); ss << (v.size() > 0 ? "{" : "{}"); for (auto& i : v) { ss << in_v_to_str(i.first) << " : " << in_v_to_str(i.second) << (len-- > 1 ? ", " : "}"); } return ss.str(); } template<class F, class S> string in_v_to_str (const pair<F, S> v) { stringstream ss; ss << "<" << v_to_str(v.first) << ", " << v_to_str(v.second) << ">"; return ss.str(); } template<class F, class S> string v_to_str (const pair<F, S> v) { stringstream ss; ss << "<" << v_to_str(v.first) << ", " << v_to_str(v.second) << ">"; return ss.str(); } string print () { return ""; } template<typename F, typename... R> string print (const F& f, const R& ...r) { stringstream ss; ss << v_to_str(f); if (sizeof...(r) > 0) { ss << " " << print(r...); } return ss.str(); } template<typename F, typename... R> void pdebug (const F& f, const R& ...r) { stringstream ss; ss << v_to_str(f); if (sizeof...(r) > 0) { ss << " " << print(r...); } cerr << "<cerr>" << ss.str() << "</cerr>" << endl; } template<typename F, typename... R> void fdebug (const F& f, const R& ...r) { stringstream ss; ss << v_to_str(f); if (sizeof...(r) > 0) { ss << " " << print(r...); } cerr << "<cerrfile>" << ss.str() << "</cerrfile>" << endl; } template<typename F, typename... R> void tdebug (const F& f, const R& ...r) { stringstream ss; ss << v_to_str(f); if (sizeof...(r) > 0) { ss << " " << print(r...); } cerr << "<cerr>[time]" << ss.str() << "</cerr>" << endl; } struct e512pos { public: int x; int y; e512pos () { this->x = 0; this->y = 0; } e512pos (int x, int y) { this->x = x; this->y = y; } e512pos operator + (const e512pos& t) { return e512pos(this->x + t.x, this->y + t.y); } e512pos operator - (const e512pos& t) { return e512pos(this->x - t.x, this->y - t.y); } bool operator == (const e512pos& t) const { return this->x == t.x && this->y == t.y; } }; namespace std { template <> class hash<e512pos> { public: size_t operator()(const e512pos& t) const{ return t.x<<16 | t.y; } }; } ostream& operator << (ostream& os, const e512pos& p) { os << "(" << p.x << ", " << p.y << ")"; return os; }; class StopWatch { public: std::chrono::system_clock::time_point start, tstart, end; StopWatch () { this->start = std::chrono::system_clock::now(); } inline void stop () { this->tstart = std::chrono::system_clock::now(); } inline void resume () { this->start += std::chrono::system_clock::now() - this->tstart; } inline uint64_t get_milli_time () { this->end = std::chrono::system_clock::now(); return std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count(); } }; inline uint32_t xrnd() { static uint32_t y = 2463534242; y = y ^ (y << 13); y = y ^ (y >> 17); return y = y ^ (y << 5); } inline float distance (const e512pos& a, const e512pos& b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); } class MM { public: StopWatch sw; int N, M; vector<e512pos> planet; vector<int> best; bitset<256> bestm; MM () { this->sw = StopWatch(); } void input () { cin >> this->N >> this->M; for (int i = 0; i < 256; ++i) { this->planet.emplace_back(0, 0); } for (int i = 0; i < this->N; ++i) { cin >> this->planet[i].x >> this->planet[i].y; } } void output () { vector<int> mindex; for (int i = 0; i < 256; ++i) { mindex.emplace_back(-1); } int cnt = 0; for (int i = 0; i < this->N; ++i) { if (this->bestm[i]) { cout << print(this->planet[i].x, this->planet[i].y) << endl; mindex[i] = cnt; cnt += 1; } } vector< pair<int, int> > out; int p = 0; out.emplace_back(1, 0); if (mindex[0] >= 0) { out.emplace_back(2, mindex[0]); } for (auto&& i : this->best) { if (mindex[i] >= 0) { out.emplace_back(2, mindex[i]); } out.emplace_back(1, i); if (mindex[i] >= 0) { out.emplace_back(2, mindex[i]); } p = i; } if (mindex[0] >= 0) { out.emplace_back(2, mindex[0]); } out.emplace_back(1, 0); cout << out.size() << endl; for (auto&& i : out) { cout << print(i.first, i.second+1) << endl; } } void solve () { vector<int> v; e512pos p = this->planet[0]; bitset<256> use; use[0] = true; for (int z = 0; z < this->N-1; ++z) { int best = -1; float bestdist = 1000000000; for (int i = 1; i < this->N; ++i) { if (use[i]) { continue; } int x = (p.x - this->planet[i].x); int y = (p.y - this->planet[i].y); float dist = sqrt(x*x+y*y); if (dist < bestdist) { bestdist = dist; best = i; } } use[best] = true; v.emplace_back(best); p = this->planet[best]; } bitset<256> m; for (int i = 0; i < this->M; ++i) { m[(this->N/this->M) * i] = true; } float bestscore = this->mallscore(v, m); while (this->sw.get_milli_time() < 900) { int a = xrnd() % this->N; int b = xrnd() % this->N; bool t = m[a]; m[a] = m[b]; m[b] = t; float score = this->mallscore(v, m); if (score < bestscore) { bestscore = score; } else { t = m[a]; m[a] = m[b]; m[b] = t; } } this->bestm = m; this->best = v; } float mallscore (vector<int>& v, bitset<256>& m) { float r = 0; int p = 0; for (int i = 0; i < v.size(); ++i) { float d = distance(this->planet[p], this->planet[v[i]]); if (m[p] || m[v[i]]) { r += d*d*5; } else { r += d*d*25; } p = v[i]; } float d = distance(this->planet[p], this->planet[0]); if (m[p] || m[0]) { r += d*d*5; } else { r += d*d*25; } return r; } }; int main () { cin.tie(0); ios::sync_with_stdio(false); MM mm; mm.input(); mm.solve(); mm.output(); cout.flush(); return 0; }