結果
問題 | No.5016 Worst Mayor |
ユーザー | e869120 |
提出日時 | 2023-04-28 21:41:02 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 399 ms / 2,000 ms |
コード長 | 4,886 bytes |
コンパイル時間 | 1,263 ms |
コンパイル使用メモリ | 90,188 KB |
実行使用メモリ | 25,972 KB |
スコア | 18,103,800,934 |
平均クエリ数 | 400.00 |
最終ジャッジ日時 | 2023-04-29 12:32:23 |
合計ジャッジ時間 | 24,424 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
純コード判定しない問題か言語 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 394 ms
25,368 KB |
testcase_01 | AC | 390 ms
25,880 KB |
testcase_02 | AC | 399 ms
25,920 KB |
testcase_03 | AC | 389 ms
25,924 KB |
testcase_04 | AC | 387 ms
25,524 KB |
testcase_05 | AC | 396 ms
25,360 KB |
testcase_06 | AC | 384 ms
25,368 KB |
testcase_07 | AC | 388 ms
25,716 KB |
testcase_08 | AC | 386 ms
25,404 KB |
testcase_09 | AC | 385 ms
25,836 KB |
testcase_10 | AC | 388 ms
25,672 KB |
testcase_11 | AC | 387 ms
25,344 KB |
testcase_12 | AC | 390 ms
25,852 KB |
testcase_13 | AC | 387 ms
25,428 KB |
testcase_14 | AC | 385 ms
25,512 KB |
testcase_15 | AC | 383 ms
25,600 KB |
testcase_16 | AC | 384 ms
25,884 KB |
testcase_17 | AC | 386 ms
25,972 KB |
testcase_18 | AC | 388 ms
25,388 KB |
testcase_19 | AC | 387 ms
25,780 KB |
testcase_20 | AC | 394 ms
25,800 KB |
testcase_21 | AC | 392 ms
25,344 KB |
testcase_22 | AC | 394 ms
25,744 KB |
testcase_23 | AC | 398 ms
25,840 KB |
testcase_24 | AC | 391 ms
25,840 KB |
testcase_25 | AC | 392 ms
25,344 KB |
testcase_26 | AC | 387 ms
25,608 KB |
testcase_27 | AC | 382 ms
25,676 KB |
testcase_28 | AC | 389 ms
25,916 KB |
testcase_29 | AC | 388 ms
25,636 KB |
testcase_30 | AC | 384 ms
25,284 KB |
testcase_31 | AC | 383 ms
25,780 KB |
testcase_32 | AC | 385 ms
25,572 KB |
testcase_33 | AC | 388 ms
25,252 KB |
testcase_34 | AC | 387 ms
25,352 KB |
testcase_35 | AC | 390 ms
25,756 KB |
testcase_36 | AC | 387 ms
25,296 KB |
testcase_37 | AC | 386 ms
25,504 KB |
testcase_38 | AC | 392 ms
25,572 KB |
testcase_39 | AC | 388 ms
25,176 KB |
testcase_40 | AC | 395 ms
25,672 KB |
testcase_41 | AC | 389 ms
25,628 KB |
testcase_42 | AC | 387 ms
25,652 KB |
testcase_43 | AC | 386 ms
25,668 KB |
testcase_44 | AC | 389 ms
25,584 KB |
testcase_45 | AC | 390 ms
25,588 KB |
testcase_46 | AC | 389 ms
25,540 KB |
testcase_47 | AC | 391 ms
25,660 KB |
testcase_48 | AC | 395 ms
25,800 KB |
testcase_49 | AC | 390 ms
25,400 KB |
ソースコード
#include <iostream> #include <vector> #include <tuple> #include <cmath> #include <algorithm> using namespace std; // Input Information int N, T; int A[3009], B[3009], C[3009], D[3009]; int CurrentMoney; int CurrentCorps; // Other Variables int Build[1009]; int Money[2000009]; int Cost[199][199]; int D1[15][16]; int D2[16][15]; vector<tuple<int, int, int, int>> tmp; // Initialize Money void Initialize() { for (int i = 0; i <= 1000; i++) { for (int j = 0; j < 1000; j++) { Money[1000 * i + 223 * j] = 60 * j; } } for (int i = 1; i <= 1000; i++) { Build[i] = (int)(10000000.0 / sqrt(1.0 * i)); } } // Get Total Earned Money int GetEarnedMoney() { for (int i = 0; i < 196; i++) { for (int j = 0; j < 196; j++) Cost[i][j] = 1000000; Cost[i][i] = 0; } // Initialize Cost for (int i = 0; i < 13; i++) { for (int j = 0; j < 14; j++) { int a1 = (i + 0) * 14 + (j + 0); int a2 = (i + 1) * 14 + (j + 0); if (D1[i][j] == 1) { Cost[a1][a2] = 223; Cost[a2][a1] = 223; } else { Cost[a1][a2] = 1000; Cost[a2][a1] = 1000; } } } for (int i = 0; i < 14; i++) { for (int j = 0; j < 13; j++) { int a1 = (i + 0) * 14 + (j + 0); int a2 = (i + 0) * 14 + (j + 1); if (D2[i][j] == 1) { Cost[a1][a2] = 223; Cost[a2][a1] = 223; } else { Cost[a1][a2] = 1000; Cost[a2][a1] = 1000; } } } // Warshall-Floyd for (int k = 0; k < 196; k++) { for (int i = 0; i < 196; i++) { for (int j = 0; j < 196; j++) Cost[i][j] = min(Cost[i][j], Cost[i][k] + Cost[k][j]); } } int sum = 0; for (int i = 1; i <= N; i++) { int pos1 = (A[i] - 1) * 14 + (B[i] - 1); int pos2 = (C[i] - 1) * 14 + (D[i] - 1); sum += Money[Cost[pos1][pos2]]; } return sum; } // Set Rectangle: Case 1 void SetRect1(int L, int R) { for (int i = 0; i < 13; i++) { for (int j = 0; j < 14; j++) D1[i][j] = 0; } for (int i = 0; i < 14; i++) { for (int j = 0; j < 13; j++) D2[i][j] = 0; } tmp.clear(); vector<int> ord = { 6, 5, 7, 4, 8, 3, 9, 2, 10, 1, 11, 0, 12 }; for (int i = 0; i <13; i++) { D1[ord[i]][L] = 1; tmp.push_back(make_tuple(ord[i], L, ord[i] + 1, L)); } for (int i = 0; i <13; i++) { D1[ord[i]][R] = 1; tmp.push_back(make_tuple(ord[i], R, ord[i] + 1, R)); } for (int i = L; i < R; i++) { D2[ 0][i] = 1; tmp.push_back(make_tuple( 0, i, 0, i + 1)); } for (int i = L; i < R; i++) { D2[13][i] = 1; tmp.push_back(make_tuple(13, i, 13, i + 1)); } } // Set Rectangle: Case 2 void SetRect2(int L, int R) { for (int i = 0; i < 13; i++) { for (int j = 0; j < 14; j++) D1[i][j] = 0; } for (int i = 0; i < 14; i++) { for (int j = 0; j < 13; j++) D2[i][j] = 0; } tmp.clear(); vector<int> ord = { 6, 5, 7, 4, 8, 3, 9, 2, 10, 1, 11, 0, 12 }; for (int i = 0; i <13; i++) { D2[L][ord[i]] = 1; tmp.push_back(make_tuple(L, ord[i], L, ord[i] + 1)); } for (int i = 0; i <13; i++) { D2[R][ord[i]] = 1; tmp.push_back(make_tuple(R, ord[i], R, ord[i] + 1)); } for (int i = L; i < R; i++) { D1[i][ 0] = 1; tmp.push_back(make_tuple(i, 0, i + 1, 0)); } for (int i = L; i < R; i++) { D1[i][13] = 1; tmp.push_back(make_tuple(i, 13, i + 1, 13)); } } int main() { // Input Initialize(); cin >> N >> T; for (int i = 1; i <= N; i++) cin >> A[i] >> B[i] >> C[i] >> D[i]; // Brute Force Type 1 Rectangle int Maximum = 0; tuple<int, int, int> MaxID = make_tuple(-1, -1, -1); for (int i = 0; i < 14; i++) { for (int j = i + 1; j < 14; j++) { if (rand() % 100 >= 25) continue; SetRect1(i, j); int Score = GetEarnedMoney(); if (Maximum < Score) { Maximum = Score; MaxID = make_tuple(1, i, j); } } } // Brute Force Type 2 Rectangle for (int i = 0; i < 14; i++) { for (int j = i + 1; j < 14; j++) { if (rand() % 100 >= 25) continue; SetRect2(i, j); int Score = GetEarnedMoney(); if (Maximum < Score) { Maximum = Score; MaxID = make_tuple(2, i, j); } } } // Get tmp int BuiltRoads = 0; if (get<0>(MaxID) == 1) SetRect1(get<1>(MaxID), get<2>(MaxID)); if (get<0>(MaxID) == 2) SetRect2(get<1>(MaxID), get<2>(MaxID)); GetEarnedMoney(); // Answer Query for (int i = 1; i <= T; i++) { cin >> CurrentMoney >> CurrentCorps; if (CurrentMoney == -1 && CurrentCorps == -1) break; fprintf(stderr, "Turn =% 4d, Money=% 10d, Corps =% 3d, Roads =% 3d/%d\n", i, CurrentMoney, CurrentCorps, BuiltRoads, (int)tmp.size()); // Get Acts if (i <= 50) { cout << "2" << endl; } else if (BuiltRoads == (int)tmp.size()) { cout << "3" << endl; } else if (BuiltRoads >= 3 && CurrentMoney < Build[CurrentCorps]) { cout << "2" << endl; } else if (BuiltRoads <= 2 && CurrentMoney < Build[CurrentCorps]) { cout << "3" << endl; } else { cout << "1 " << get<0>(tmp[BuiltRoads]) + 1 << " " << get<1>(tmp[BuiltRoads]) + 1 << " " << get<2>(tmp[BuiltRoads]) + 1 << " " << get<3>(tmp[BuiltRoads]) + 1 << endl; BuiltRoads += 1; } } return 0; }