Submission #38305

# Submission time Handle Problem Language Result Execution time Memory
38305 2018-01-03T15:11:20 Z romanasa Ants (IZhO12_ants) C++14
0 / 100
0 ms 2024 KB
#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() {
#ifndef HOME
	freopen(TASK".in", "r", stdin), freopen(TASK".out", "w", stdout);
#endif
	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;
}

Compilation message

ants.cpp: In function 'int main()':
ants.cpp:14:66: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  freopen(TASK".in", "r", stdin), freopen(TASK".out", "w", stdout);
                                                                  ^
ants.cpp:14:66: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 2024 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
2 Halted 0 ms 0 KB -