# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
38317 |
2018-01-03T16:08:20 Z |
romanasa |
Ants (IZhO12_ants) |
C++14 |
|
2000 ms |
2024 KB |
#include <bits/stdc++.h>
#define err(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
using namespace std;
typedef long long ll;
map<int, vector<int> > X, Y;
#define TASK "e"
int main() {
int w, h, k, t;
cin >> w >> h >> k >> t;
vector<int> x(k), y(k), d(k);
for (int i = 0; i < k; i++) {
cin >> x[i] >> y[i] >> d[i];
if (d[i] == 2 || d[i] == 4) X[x[i]].push_back(i);
else Y[y[i]].push_back(i);
}
for (auto c : X) {
auto &cur = c.second;
sort(cur.begin(), cur.end(), [&](int a, int b) { return y[a] < y[b]; });
for (int it = 0; it < t; it++) {
vector<int> used((int)cur.size());
for (int i = 0; i + 1 < (int)cur.size(); i++) if (!used[i]) {
if (y[cur[i]] + 1 == y[cur[i + 1]] && d[cur[i]] == 2 && d[cur[i + 1]] == 4) {
swap(d[cur[i]], d[cur[i + 1]]);
used[i] = 1, used[i + 1] = 1;
continue;
}
if (y[cur[i]] + 2 == y[cur[i + 1]] && d[cur[i]] == 2 && d[cur[i + 1]] == 4) {
swap(d[cur[i]], d[cur[i + 1]]);
y[cur[i]]++;
y[cur[i + 1]]--;
used[i] = 1, used[i + 1] = 1;
continue;
}
}
for (int i = 0; i < (int)cur.size(); i++) if (!used[i])
if (d[cur[i]] == 2) y[cur[i]]++;
else y[cur[i]]--;
for (int i = 0; i + 1 < (int)cur.size(); i++)
if (y[cur[i]] == y[cur[i + 1]] && d[cur[i]] == 2 && d[cur[i + 1]] == 4) swap(d[cur[i]], d[cur[i + 1]]);
for (int i = 0; i < (int)cur.size(); i++) {
if (y[cur[i]] == h && d[cur[i]] == 2) d[cur[i]] = 4;
if (y[cur[i]] == 0 && d[cur[i]] == 4) d[cur[i]] = 2;
}
}
}
for (auto c : Y) {
auto &cur = c.second;
sort(cur.begin(), cur.end(), [&](int a, int b) { return x[a] < x[b]; });
for (int it = 0; it < t; it++) {
vector<int> used((int)cur.size());
for (int i = 0; i + 1 < (int)cur.size(); i++) if (!used[i]) {
if (x[cur[i]] + 1 == x[cur[i + 1]] && d[cur[i]] == 1 && d[cur[i + 1]] == 3) {
swap(d[cur[i]], d[cur[i + 1]]);
used[i] = 1, used[i + 1] = 1;
continue;
}
if (x[cur[i]] + 2 == x[cur[i + 1]] && d[cur[i]] == 1 && d[cur[i + 1]] == 3) {
swap(d[cur[i]], d[cur[i + 1]]);
x[cur[i]]++;
x[cur[i + 1]]--;
used[i] = 1, used[i + 1] = 1;
continue;
}
}
for (int i = 0; i < (int)cur.size(); i++) if (!used[i])
if (d[cur[i]] == 1) x[cur[i]]++;
else x[cur[i]]--;
for (int i = 0; i + 1 < (int)cur.size(); i++)
if (x[cur[i]] == x[cur[i + 1]] && d[cur[i]] == 1 && d[cur[i + 1]] == 3) swap(d[cur[i]], d[cur[i + 1]]);
for (int i = 0; i < (int)cur.size(); i++) {
if (x[cur[i]] == w && d[cur[i]] == 1) d[cur[i]] = 3;
if (x[cur[i]] == 0 && d[cur[i]] == 3) d[cur[i]] = 1;
}
}
}
for (int i = 0; i < k; i++) cout << x[i] << " " << y[i] << " " << d[i] << "\n";
return 0;
}
Compilation message
ants.cpp: In function 'int main()':
ants.cpp:43:49: warning: suggest explicit braces to avoid ambiguous 'else' [-Wparentheses]
for (int i = 0; i < (int)cur.size(); i++) if (!used[i])
^
ants.cpp:74:49: warning: suggest explicit braces to avoid ambiguous 'else' [-Wparentheses]
for (int i = 0; i < (int)cur.size(); i++) if (!used[i])
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2024 KB |
Output is correct |
2 |
Correct |
0 ms |
2024 KB |
Output is correct |
3 |
Correct |
0 ms |
2024 KB |
Output is correct |
4 |
Correct |
0 ms |
2024 KB |
Output is correct |
5 |
Correct |
0 ms |
2024 KB |
Output is correct |
6 |
Correct |
0 ms |
2024 KB |
Output is correct |
7 |
Correct |
0 ms |
2024 KB |
Output is correct |
8 |
Correct |
0 ms |
2024 KB |
Output is correct |
9 |
Correct |
0 ms |
2024 KB |
Output is correct |
10 |
Correct |
0 ms |
2024 KB |
Output is correct |
11 |
Correct |
0 ms |
2024 KB |
Output is correct |
12 |
Correct |
0 ms |
2024 KB |
Output is correct |
13 |
Correct |
13 ms |
2024 KB |
Output is correct |
14 |
Correct |
33 ms |
2024 KB |
Output is correct |
15 |
Execution timed out |
2000 ms |
2024 KB |
Execution timed out |
16 |
Halted |
0 ms |
0 KB |
- |