Submission #1176671
Source Code Expand
#include <bits/stdc++.h>
struct Point {
long r, c;
Point() : r(-1), c(-1) {}
Point(long r_, long c_) : r(r_), c(c_) {}
bool inrange() {
return 1 <= r and r <= 30 and 1 <= c and c <= 30;
}
};
Point operator + (Point x, Point y) {
return Point(x.r + y.r, x.c + y.c);
}
Point d4[] = {
Point(1, 0),
Point(0, 1),
Point(-1, 0),
Point(0, -1)
};
char c4[] = "DRUL-";
struct Car {
Point s, d;
Car() {}
Car(Point s_, Point d_) : s(s_), d(d_) {}
long dist() {
return std::abs(s.r - d.r) + std::abs(s.c - d.c);
}
};
void solve(long h, long w, long k, long t, std::array<Car, 450> cs) {
std::vector<std::string> answers;
for(long i = 0; i < 10000-1; ++i) {
bool reserved[32][32] = {{}};
for(long j = 0; j < 450; ++j) {
reserved[cs[j].s.r][cs[j].s.c] = true;
}
std::string ans;
ans.resize(450);
std::vector<long> random;
for(long j = 0; j < 450; ++j) {
random.push_back(j);
}
std::random_shuffle(random.begin(), random.end());
for(long jj = 0; jj < 450; ++jj) {
long j = random[jj];
long best = (1 << 28);
long bestkk = 4;
for(long kk : {i%4, (i+1)%4, (i+2)%4, (i+3)%4}) {
Point next = cs[j].s + d4[kk];
Car nextC = Car(next, cs[j].d);
if( reserved[next.r][next.c] ) continue;
if( not next.inrange() ) continue;
if( nextC.dist() < best ) {
best = nextC.dist();
bestkk = kk;
}
}
ans[j] = c4[bestkk];
Point next = cs[j].s + d4[bestkk];
reserved[next.r][next.c] = true;
cs[j].s = next;
}
answers.push_back(ans);
long maxDiff = 0;
for(long j = 0; j < 450; ++j) {
maxDiff = std::max(maxDiff, cs[j].dist());
}
if( maxDiff <= 6 ) break;
}
{
bool reserved[32][32] = {{}};
for(long j = 0; j < 450; ++j) {
reserved[cs[j].s.r][cs[j].s.c] = true;
}
std::string ans;
ans.resize(450);
for(long j = 0; j < 450; ++j) {
long best = cs[j].dist();
long bestkk = 4;
for(long kk = 0; kk < 4; ++kk) {
Point next = cs[j].s + d4[kk];
Car nextC = Car(next, cs[j].d);
if( reserved[next.r][next.c] ) continue;
if( not next.inrange() ) continue;
if( nextC.dist() < best ) {
best = nextC.dist();
bestkk = kk;
}
}
ans[j] = c4[bestkk];
Point next = cs[j].s + d4[bestkk];
reserved[next.r][next.c] = true;
cs[j].s = next;
}
answers.push_back(ans);
}
printf("%ld\n", (long)answers.size());
for(std::string& str : answers) {
printf("%s\n", str.c_str());
}
}
int main() {
long h, w, k, t;
std::array<Car, 450> cs;
scanf("%ld %ld %ld %ld", &h, &w, &k, &t);
for(long i = 0; i < k; ++i) {
long a, b, c, d;
scanf("%ld %ld %ld %ld", &a, &b, &c, &d);
cs[i] = Car(Point(a, b), Point(c, d));
}
solve(h, w, k, t, cs);
return 0;
}
Submission Info
Submission Time |
|
Task |
B - 日本橋大渋滞 |
User |
spica314 |
Language |
C++14 (GCC 5.4.1) |
Score |
37141 |
Code Size |
3049 Byte |
Status |
AC |
Exec Time |
173 ms |
Memory |
5888 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:110:43: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%ld %ld %ld %ld", &h, &w, &k, &t);
^
./Main.cpp:113:45: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%ld %ld %ld %ld", &a, &b, &c, &d);
^
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 |
1375 / 50000 |
1229 / 50000 |
907 / 50000 |
1236 / 50000 |
1066 / 50000 |
1291 / 50000 |
1204 / 50000 |
1180 / 50000 |
1398 / 50000 |
1254 / 50000 |
1387 / 50000 |
1386 / 50000 |
1363 / 50000 |
1317 / 50000 |
1212 / 50000 |
1418 / 50000 |
1484 / 50000 |
1254 / 50000 |
310 / 50000 |
1443 / 50000 |
1131 / 50000 |
1294 / 50000 |
1428 / 50000 |
1300 / 50000 |
1151 / 50000 |
1086 / 50000 |
1228 / 50000 |
1213 / 50000 |
1452 / 50000 |
1144 / 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 |
22 ms |
1024 KB |
subtask_01_02.txt |
AC |
25 ms |
1024 KB |
subtask_01_03.txt |
AC |
46 ms |
1792 KB |
subtask_01_04.txt |
AC |
23 ms |
1024 KB |
subtask_01_05.txt |
AC |
27 ms |
1152 KB |
subtask_01_06.txt |
AC |
25 ms |
1152 KB |
subtask_01_07.txt |
AC |
30 ms |
1280 KB |
subtask_01_08.txt |
AC |
26 ms |
1152 KB |
subtask_01_09.txt |
AC |
21 ms |
1024 KB |
subtask_01_10.txt |
AC |
23 ms |
1024 KB |
subtask_01_11.txt |
AC |
28 ms |
1152 KB |
subtask_01_12.txt |
AC |
27 ms |
1152 KB |
subtask_01_13.txt |
AC |
28 ms |
1152 KB |
subtask_01_14.txt |
AC |
28 ms |
1152 KB |
subtask_01_15.txt |
AC |
27 ms |
1152 KB |
subtask_01_16.txt |
AC |
23 ms |
1024 KB |
subtask_01_17.txt |
AC |
24 ms |
1024 KB |
subtask_01_18.txt |
AC |
28 ms |
1152 KB |
subtask_01_19.txt |
AC |
173 ms |
5888 KB |
subtask_01_20.txt |
AC |
27 ms |
1152 KB |
subtask_01_21.txt |
AC |
30 ms |
1280 KB |
subtask_01_22.txt |
AC |
24 ms |
1024 KB |
subtask_01_23.txt |
AC |
25 ms |
1024 KB |
subtask_01_24.txt |
AC |
33 ms |
1408 KB |
subtask_01_25.txt |
AC |
27 ms |
1152 KB |
subtask_01_26.txt |
AC |
29 ms |
1152 KB |
subtask_01_27.txt |
AC |
27 ms |
1152 KB |
subtask_01_28.txt |
AC |
23 ms |
1024 KB |
subtask_01_29.txt |
AC |
24 ms |
1024 KB |
subtask_01_30.txt |
AC |
30 ms |
1280 KB |