# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
38317 | romanasa | Ants (IZhO12_ants) | C++14 | 2000 ms | 2024 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |