# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
93970 |
2019-01-13T19:33:09 Z |
Noam527 |
Ants (IZhO12_ants) |
C++17 |
|
2 ms |
504 KB |
#include <bits/stdc++.h>
#define CHECK cout << "ok" << endl
#define finish(x) return cout << x << endl, 0
typedef long long ll;
typedef long double ldb;
const int md = 1e9 + 7, inf = 1e9 + 7;
using namespace std;
void debug(string names) {
cout << '\n';
}
template<typename A1, typename... A2>
void debug(string names, A1 par, A2... left) {
int pos = 0;
for (; pos < names.size() && names[pos] != ' ' && names[pos] != ','; pos++)
cout << names[pos];
cout << ": " << par << " ";
while (pos < names.size() && (names[pos] == ' ' || names[pos] == ',')) {
pos++;
}
names.erase(names.begin(), names.begin() + pos);
debug(names, left...);
}
struct ant {
int x, y, d, ind;
ant() {}
ant(int xx, int yy, int dd, int ii) {
x = xx;
y = yy;
d = dd;
ind = ii;
}
bool operator < (const ant &a) const {
if (x != a.x) return x < a.x;
return y < a.y;
}
void advance(int w, int h, int cnt) {
if (d == 1 || d == 3) {
cnt %= 2 * w;
while (cnt--) {
if (d == 1) x++;
else x--;
if (x == 0 || x == w) d ^= 2;
}
}
else {
cnt %= 2 * h;
while (cnt--) {
if (d == 2) y++;
else y--;
if (y == 0 || y == h) d ^= 6;
}
}
}
};
int w, h, k, T;
vector<ant> V[102], H[102];
vector<ant> ans;
int main() {
ios::sync_with_stdio(0), cin.tie(0);
cin >> w >> h >> k >> T;
ans.resize(k);
for (int i = 0, par[3]; i < k; i++) {
cin >> par[0] >> par[1] >> par[2];
if (par[1] & 1) H[par[1]].push_back(ant(par[0], par[1], par[2], i));
else V[par[0]].push_back(ant(par[0], par[1], par[2], i));
}
vector<int> bef;
for (int i = 0; i < 102; i++) {
sort(V[i].begin(), V[i].end());
bef.resize(V[i].size());
for (int j = 0; j < bef.size(); j++) bef[j] = V[i][j].ind;
for (auto &j : V[i]) j.advance(w, h, T);
sort(V[i].begin(), V[i].end());
for (int j = 0; j < bef.size(); j++) ans[bef[j]] = V[i][j];
sort(H[i].begin(), H[i].end());
bef.resize(H[i].size());
for (int j = 0; j < bef.size(); j++) bef[j] = H[i][j].ind;
for (auto &j : H[i]) j.advance(w, h, T);
sort(H[i].begin(), H[i].end());
for (int j = 0; j < bef.size(); j++) ans[bef[j]] = H[i][j];
}
for (const auto &i : ans) cout << i.x << " " << i.y << " " << i.d << '\n';
}
Compilation message
ants.cpp: In function 'int main()':
ants.cpp:76:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < bef.size(); j++) bef[j] = V[i][j].ind;
~~^~~~~~~~~~~~
ants.cpp:79:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < bef.size(); j++) ans[bef[j]] = V[i][j];
~~^~~~~~~~~~~~
ants.cpp:83:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < bef.size(); j++) bef[j] = H[i][j].ind;
~~^~~~~~~~~~~~
ants.cpp:86:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < bef.size(); j++) ans[bef[j]] = H[i][j];
~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
380 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |