#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
#define ld long double
// 217
// 44
using namespace std;
const int MAXN = 100;
pair <int, int> mat[MAXN + 1][MAXN + 1];
struct Data {
int l, c;
int dir;
};
Data sol[MAXN + 1];
int main() {
//ifstream cin("A.in");
//ofstream cout("A.out");
int i, j, w, h, k, t;
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> w >> h >> k >> t;
//w++;
//h++;
for(i = 1; i <= k; i++) {
int x, y, d;
cin >> x >> y >> d;
mat[x][y] = {d, i};
}
for(j = 1; j <= h; j++) {
vector < pair <int, int> > cur;
for(i = 1; i <= w; i++) {
if(mat[i][j].first == 1) {
if(i + t <= w) {
cur.push_back({i + t, 1});
}
else {
int aux = (t - (w - i)) / w;
if(aux % 2 == 0) {
cur.push_back({w - (t - (w - i)) % w, 3});
}
else {
cur.push_back({0 + (t - (w - i)) % w, 1});
}
}
}
else if(mat[i][j].first == 3) {
if(i - t >= 0) {
cur.push_back({i - t, 3});
}
else {
int aux = (t - i) / w;
if(aux % 2 == 0) {
cur.push_back({0 + (t - i) % w, 1});
}
else {
cur.push_back({w - (t - i) % w, 3});
}
}
}
}
sort(cur.begin(), cur.end());
int sz = 0;
for(i = 1; i <= w; i++) {
if(mat[i][j].first % 2 == 1) {
sol[mat[i][j].second] = {cur[sz].first, j, cur[sz].second};
sz++;
}
}
}
for(i = 1; i <= w; i++) {
vector < pair <int, int> > cur;
for(j = 1; j <= h; j++) {
if(mat[i][j].first == 2) {
if(j + t <= h) {
cur.push_back({j + t, 2});
}
else {
int aux = (t - (h - j)) / h;
if(aux % 2 == 0) {
cur.push_back({h - (t - (h - j)) % h, 4});
}
else {
cur.push_back({0 + (t - (h - j)) % h, 2});
}
}
}
else if(mat[i][j].first == 4) {
if(j - t >= 0) {
cur.push_back({j - t, 4});
}
else {
int aux = (t - j) / h;
if(aux % 2 == 0) {
cur.push_back({0 + (t - j) % h, 2});
}
else {
cur.push_back({h - (t - j) % h, 4});
}
}
}
}
sort(cur.begin(), cur.end());
int sz = 0;
for(j = 1; j <= h; j++) {
if(mat[i][j].first > 0 && mat[i][j].first % 2 == 0) {
//cerr << cur.size() << "\n";
sol[mat[i][j].second] = {i, cur[sz].first, cur[sz].second};
sz++;
}
}
}
for(i = 1; i <= k; i++) {
if(sol[i].dir % 2 == 1) {
if(sol[i].l == 0) {
sol[i].dir = 1;
}
else if(sol[i].l == w) {
sol[i].dir = 3;
}
}
else {
if(sol[i].c == 0) {
sol[i].dir = 2;
}
else if(sol[i].c == h) {
sol[i].dir = 4;
}
}
cout << sol[i].l << " " << sol[i].c << " " << sol[i].dir << "\n";
}
//cin.close();
//cout.close();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
544 KB |
Output is correct |
4 |
Correct |
2 ms |
544 KB |
Output is correct |
5 |
Correct |
2 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
608 KB |
Output is correct |
8 |
Incorrect |
2 ms |
652 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |