Submission #1173518
Source Code Expand
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
using namespace std;
const int INF = 1145141919;
const char U = 'U';
const char D = 'D';
const char L = 'L';
const char R = 'R';
const char NONE = '-';
const char moves[5] = {U, D, L, R, NONE};
// U, D, L, R, N
const int dx[5] = {0, 0, -1, 1, 0};
const int dy[5] = {-1, 1, 0, 0, 0};
int field_height;
int field_width;
int num_car;
int max_output;
vector<string> commands;
struct Car {
int x;
int y;
int tx;
int ty;
Car (int x=0, int y=0, int tx=0, int ty=0) {
this->x = x;
this->y = y;
this->tx = tx;
this->ty = ty;
}
};
Car cars[450];
void input() {
cin >> field_height >> field_width >> num_car >> max_output; cin.ignore();
for (int i = 0; i < num_car; i++) {
cin >> cars[i].y >> cars[i].x >> cars[i].ty >> cars[i].tx; cin.ignore();
}
}
double evaluate(int num_output) {
double pd = 20;
for (int i = 0; i < num_car; i++) {
pd += abs(cars[i].x - cars[i].tx) + abs(cars[i].y - cars[i].ty);
}
double pt = 10 + num_output*0.01;
return 10000000 / (pd + pt);
}
bool in_range(int x, int y) {
return 0 <= x && x < field_width && 0 <= y && y < field_height;
}
int distance(int x1, int y1, int x2, int y2) {
return abs(x1 - x2) + abs(y1 - y2);
}
void think() {
for (int t = 0; t < max_output; t++) {
Car pre_cars[450];
memcpy(&pre_cars, &cars, sizeof(cars));
bool is_car_this_turn[30][30] = {};
bool is_car_next_turn[30][30] = {};
for (int i = 0; i < num_car; i++) {
is_car_this_turn[cars[i].y][cars[i].x] = true;
}
string movement;
for (int i = 0; i < num_car; i++) {
movement.push_back(NONE);
}
bool is_action = false;
for (int i = 0; i < num_car; i++) {
int min_dist = distance(cars[i].x, cars[i].y, cars[i].tx, cars[i].ty);
int dir = 4;
for (int d = 0; d < 5; d++) {
int nx = cars[i].x + dx[d];
int ny = cars[i].y + dy[d];
if (!in_range(nx, ny)) continue;
if (is_car_this_turn[ny][nx]) continue;
if (is_car_next_turn[ny][nx]) continue;
int dist = distance(nx, ny, cars[i].tx, cars[i].ty);
if (dist < min_dist) {
min_dist = dist;
dir = d;
}
}
if (moves[dir] != NONE) is_action = true;
int nx = cars[i].x + dx[dir];
int ny = cars[i].y + dy[dir];
cars[i].x = nx;
cars[i].y = ny;
is_car_next_turn[ny][nx] = true;
movement[i] = moves[dir];
}
if (!is_action) break;
commands.push_back(movement);
}
}
void output() {
cout << commands.size() << endl;
for (int t = 0; t < commands.size(); t++) {
cout << commands[t] << endl;
}
}
int main () {
input();
think();
output();
// cerr << evaluate(commands.size()) << endl;
}
Submission Info
Submission Time |
|
Task |
B - 日本橋大渋滞 |
User |
kasuka |
Language |
C++14 (GCC 5.4.1) |
Score |
4556 |
Code Size |
3247 Byte |
Status |
AC |
Exec Time |
3 ms |
Memory |
256 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 |
161 / 50000 |
150 / 50000 |
152 / 50000 |
158 / 50000 |
167 / 50000 |
154 / 50000 |
154 / 50000 |
160 / 50000 |
143 / 50000 |
145 / 50000 |
157 / 50000 |
152 / 50000 |
149 / 50000 |
156 / 50000 |
146 / 50000 |
160 / 50000 |
146 / 50000 |
147 / 50000 |
154 / 50000 |
151 / 50000 |
161 / 50000 |
155 / 50000 |
148 / 50000 |
141 / 50000 |
143 / 50000 |
151 / 50000 |
156 / 50000 |
138 / 50000 |
151 / 50000 |
150 / 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 |
256 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 |
256 KB |
subtask_01_06.txt |
AC |
2 ms |
256 KB |
subtask_01_07.txt |
AC |
2 ms |
256 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 |
256 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 |
3 ms |
256 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 |
256 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 |
256 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 |
256 KB |
subtask_01_25.txt |
AC |
2 ms |
256 KB |
subtask_01_26.txt |
AC |
2 ms |
256 KB |
subtask_01_27.txt |
AC |
3 ms |
256 KB |
subtask_01_28.txt |
AC |
2 ms |
256 KB |
subtask_01_29.txt |
AC |
2 ms |
256 KB |
subtask_01_30.txt |
AC |
3 ms |
256 KB |