답안 #100667

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
100667 2019-03-13T06:21:24 Z ainta 움직이는 개미 (IZhO12_ants) C++17
0 / 100
2 ms 384 KB
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int W, H, K, T;
struct AA {
	int x, y, dir;
}Res[110];
struct point {
	int loc, ck, num;
	bool operator<(const point &p)const {
		return loc != p.loc ? loc < p.loc : ck < p.ck;
	}
}Z[110];
vector<point>X[110], Y[110];
void Go(vector<point>&U, int M, int TT) {
	int i;
	sort(U.begin(), U.end());
	int sz = U.size();
	for (i = 0; i < sz;i++) {
		auto t = U[i];
		int x = (t.loc + t.ck * T + 2 * M) % (2 * M);
		int ck = t.ck;
		if (x > M)x = 2 * M - x, ck = -ck;
		if (x == M)ck = -1;
		if (x == 0)ck = 1;
		Z[i] = { x,ck,i };
	}
	sort(Z, Z + sz);
	for (i = 0; i < sz; i++) {
		U[i].loc = Z[i].loc;
		U[i].ck = Z[i].ck;
	}
}
int main() {
	int i, j, x, y, d;
	scanf("%d%d%d%d", &W, &H, &K, &T);
	for (i = 1; i <= K; i++) {
		scanf("%d%d%d", &x, &y, &d);
		if (d & 1) {
			Y[y].push_back({ x,2-d,i });
		}
		else {
			X[x].push_back({ y,3-d,i });
		}
	}
	for (i = 0; i <= W; i++) {
		if (X[i].empty())continue;
		Go(X[i], H, T % (2 * H));
		for (auto &t : X[i]) {
			Res[t.num] = { i, t.loc, 3 - t.ck };
		}
	}
	for (i = 0; i <= H; i++) {
		if (Y[i].empty())continue;
		Go(Y[i], W, T % (2 * W));
		for (auto &t : Y[i]) {
			Res[t.num] = { t.loc, i, 2 - t.ck };
		}
	}
	for (i = 1; i <= K; i++)printf("%d %d %d\n", Res[i].x, Res[i].y, Res[i].dir);
}

Compilation message

ants.cpp: In function 'int main()':
ants.cpp:36:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j, x, y, d;
         ^
ants.cpp:37:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d%d", &W, &H, &K, &T);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
ants.cpp:39:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &x, &y, &d);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -