#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];
bool cmp(pair <int, int> a, pair <int, int> b) {
if(a.first == b.first) {
return a.second > b.second;
}
return a.first < b.first;
}
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;
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(), cmp);
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(), cmp);
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
584 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
624 KB |
Output is correct |
7 |
Correct |
2 ms |
624 KB |
Output is correct |
8 |
Correct |
2 ms |
640 KB |
Output is correct |
9 |
Correct |
2 ms |
640 KB |
Output is correct |
10 |
Correct |
2 ms |
640 KB |
Output is correct |
11 |
Correct |
2 ms |
640 KB |
Output is correct |
12 |
Correct |
2 ms |
640 KB |
Output is correct |
13 |
Correct |
2 ms |
656 KB |
Output is correct |
14 |
Correct |
2 ms |
700 KB |
Output is correct |
15 |
Correct |
2 ms |
700 KB |
Output is correct |
16 |
Correct |
2 ms |
700 KB |
Output is correct |
17 |
Correct |
2 ms |
704 KB |
Output is correct |
18 |
Correct |
2 ms |
708 KB |
Output is correct |
19 |
Correct |
2 ms |
712 KB |
Output is correct |
20 |
Correct |
2 ms |
716 KB |
Output is correct |