Submission #1173495
Source Code Expand
// Template {{{
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;
#ifdef LOCAL
#include "contest.h"
#else
#define error(args...)
#endif
inline bool valid(int x, int w) { return 0 <= x && x < w; }
void iostream_init() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.setf(ios::fixed);
cout.precision(12);
}
//}}}
const int WIDTH = 30;
const int HEIGHT = 30;
const int C = 450;
const int TURN = 10000;
int H, W, K, T;
int SX[C], SY[C];
int GX[C], GY[C];
void input() {
cin >> H >> W >> K >> T;
REP(i, K) cin >> SY[i] >> SX[i] >> GY[i] >> GX[i];
REP(i, K) SX[i]--;
REP(i, K) SY[i]--;
REP(i, K) GX[i]--;
REP(i, K) GY[i]--;
}
const int dxs[4] = {1, 0, -1, 0};
const int dys[4] = {0, 1, 0, -1};
int get_move(int dx, int dy) {
if(dx == 1) {
return 0;
} else if(dx == -1) {
return 2;
} else if(dy == 1) {
return 1;
} else if(dy == -1) {
return 3;
} else {
return 4;
}
}
string moves_to_str(vector<int> moves) {
string D = "RDLU-";
string res;
REP(i, moves.size()) res += D[moves[i]];
return res;
}
double calc_score(int X[C], int Y[C], int turn) {
int diff = 0;
REP(i, C) diff += abs(X[i] - GX[i]);
REP(i, C) diff += abs(Y[i] - GY[i]);
double score = (20.0 + diff) * (10 + 0.01 * turn);
return score;
}
vector<string> greedy() {
vector<string> answer;
int X[C], Y[C];
REP(i, C) X[i] = SX[i];
REP(i, C) Y[i] = SY[i];
vector<double> scores;
scores.push_back(calc_score(X, Y, 0));
while(answer.size() < TURN) {
int NX[C], NY[C];
bool grid[HEIGHT][WIDTH] = {};
REP(i, C) grid[Y[i]][X[i]] = true;
bool updated = false;
vector<int> moves;
REP(i, C) {
const int dx = (X[i] < GX[i] ? 1 : X[i] > GX[i] ? -1 : 0);
const int dy = (Y[i] < GY[i] ? 1 : Y[i] > GY[i] ? -1 : 0);
NX[i] = X[i];
NY[i] = Y[i];
if(dx != 0 && !grid[Y[i]][X[i] + dx]) {
NX[i] += dx;
moves.push_back(get_move(dx, 0));
grid[NY[i]][NX[i]] = true;
updated = true;
} else if(dy != 0 && !grid[Y[i] + dy][X[i]]) {
NY[i] += dy;
moves.push_back(get_move(0, dy));
grid[NY[i]][NX[i]] = true;
updated = true;
} else {
moves.push_back(4);
}
}
if(!updated) break;
REP(i, C) X[i] = NX[i];
REP(i, C) Y[i] = NY[i];
answer.push_back(moves_to_str(moves));
const int turn = (int)answer.size();
scores.push_back(calc_score(X, Y, turn));
}
int min_score_length = 0;
for(int i = 0; i < scores.size(); i++) {
if(scores[min_score_length] > scores[i]) {
min_score_length = i;
}
}
vector<string> final_answer;
REP(i, min_score_length) final_answer.push_back(answer[i]);
cerr << 1e7 / scores[min_score_length] << endl;
return final_answer;
}
void output(vector<string> answer) {
cout << answer.size() << endl;
for(int i = 0; i < answer.size(); i++) {
cout << answer[i] << endl;
}
}
int main(){
iostream_init();
input();
auto answer = greedy();
output(answer);
return 0;
}
Submission Info
Submission Time |
|
Task |
B - 日本橋大渋滞 |
User |
ichyo |
Language |
C++14 (GCC 5.4.1) |
Score |
4619 |
Code Size |
3538 Byte |
Status |
AC |
Exec Time |
2 ms |
Memory |
384 KB |
Judge Result
Set Name |
test_01 |
test_02 |
test_03 |
test_04 |
test_05 |
test_06 |
test_07 |
test_08 |
test_09 |
test_10 |
test_11 |
test_12 |
test_13 |
test_14 |
test_15 |
test_16 |
test_17 |
test_18 |
test_19 |
test_20 |
test_21 |
test_22 |
test_23 |
test_24 |
test_25 |
test_26 |
test_27 |
test_28 |
test_29 |
test_30 |
Score / Max Score |
159 / 50000 |
160 / 50000 |
157 / 50000 |
159 / 50000 |
172 / 50000 |
159 / 50000 |
153 / 50000 |
160 / 50000 |
147 / 50000 |
151 / 50000 |
156 / 50000 |
156 / 50000 |
149 / 50000 |
161 / 50000 |
148 / 50000 |
161 / 50000 |
154 / 50000 |
149 / 50000 |
149 / 50000 |
152 / 50000 |
163 / 50000 |
153 / 50000 |
154 / 50000 |
145 / 50000 |
143 / 50000 |
154 / 50000 |
155 / 50000 |
142 / 50000 |
149 / 50000 |
149 / 50000 |
Status |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Set Name |
Test Cases |
test_01 |
subtask_01_01.txt |
test_02 |
subtask_01_02.txt |
test_03 |
subtask_01_03.txt |
test_04 |
subtask_01_04.txt |
test_05 |
subtask_01_05.txt |
test_06 |
subtask_01_06.txt |
test_07 |
subtask_01_07.txt |
test_08 |
subtask_01_08.txt |
test_09 |
subtask_01_09.txt |
test_10 |
subtask_01_10.txt |
test_11 |
subtask_01_11.txt |
test_12 |
subtask_01_12.txt |
test_13 |
subtask_01_13.txt |
test_14 |
subtask_01_14.txt |
test_15 |
subtask_01_15.txt |
test_16 |
subtask_01_16.txt |
test_17 |
subtask_01_17.txt |
test_18 |
subtask_01_18.txt |
test_19 |
subtask_01_19.txt |
test_20 |
subtask_01_20.txt |
test_21 |
subtask_01_21.txt |
test_22 |
subtask_01_22.txt |
test_23 |
subtask_01_23.txt |
test_24 |
subtask_01_24.txt |
test_25 |
subtask_01_25.txt |
test_26 |
subtask_01_26.txt |
test_27 |
subtask_01_27.txt |
test_28 |
subtask_01_28.txt |
test_29 |
subtask_01_29.txt |
test_30 |
subtask_01_30.txt |
Case Name |
Status |
Exec Time |
Memory |
subtask_01_01.txt |
AC |
2 ms |
384 KB |
subtask_01_02.txt |
AC |
2 ms |
256 KB |
subtask_01_03.txt |
AC |
2 ms |
256 KB |
subtask_01_04.txt |
AC |
2 ms |
256 KB |
subtask_01_05.txt |
AC |
2 ms |
384 KB |
subtask_01_06.txt |
AC |
2 ms |
384 KB |
subtask_01_07.txt |
AC |
2 ms |
384 KB |
subtask_01_08.txt |
AC |
2 ms |
256 KB |
subtask_01_09.txt |
AC |
2 ms |
256 KB |
subtask_01_10.txt |
AC |
2 ms |
384 KB |
subtask_01_11.txt |
AC |
2 ms |
256 KB |
subtask_01_12.txt |
AC |
2 ms |
256 KB |
subtask_01_13.txt |
AC |
2 ms |
256 KB |
subtask_01_14.txt |
AC |
2 ms |
256 KB |
subtask_01_15.txt |
AC |
2 ms |
384 KB |
subtask_01_16.txt |
AC |
2 ms |
256 KB |
subtask_01_17.txt |
AC |
2 ms |
256 KB |
subtask_01_18.txt |
AC |
2 ms |
384 KB |
subtask_01_19.txt |
AC |
2 ms |
256 KB |
subtask_01_20.txt |
AC |
2 ms |
256 KB |
subtask_01_21.txt |
AC |
2 ms |
384 KB |
subtask_01_22.txt |
AC |
2 ms |
256 KB |
subtask_01_23.txt |
AC |
2 ms |
256 KB |
subtask_01_24.txt |
AC |
2 ms |
384 KB |
subtask_01_25.txt |
AC |
2 ms |
256 KB |
subtask_01_26.txt |
AC |
2 ms |
384 KB |
subtask_01_27.txt |
AC |
2 ms |
384 KB |
subtask_01_28.txt |
AC |
2 ms |
384 KB |
subtask_01_29.txt |
AC |
2 ms |
384 KB |
subtask_01_30.txt |
AC |
2 ms |
256 KB |