Submission #38306

#TimeUsernameProblemLanguageResultExecution timeMemory
38306romanasaAnts (IZhO12_ants)C++14
0 / 100
0 ms2024 KiB
#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 < (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 < (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; }
#Verdict Execution timeMemoryGrader output
Fetching results...