Submission #684597

# Submission time Handle Problem Language Result Execution time Memory
684597 2023-01-22T00:22:55 Z GusterGoose27 Paralelogrami (COCI17_paralelogrami) C++11
28 / 140
1 ms 468 KB
#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;

const int MAXN = 400;
pii points[MAXN];
int n;

pii operator+(pii a, pii b) {
	return pii(a.first+b.first, a.second+b.second);
}

pii operator-(pii a, pii b) {
	return pii(a.first-b.first, a.second-b.second);
}

int operator*(pii a, pii b) {
	return a.first*b.second-a.second*b.first;
}

pii operator*(int a, pii b) {
	return pii(a*b.first, a*b.second);
}

class action {
public:
	int a, b, c;
	action(int a, int b, int c) : a(a), b(b), c(c) {}
};

vector<action> actions;

void make_action(int a, int b, int c) {
	actions.push_back(action(a, b, c));
	points[c] = points[a]+points[b]-points[c];
}

void reflect(int a, int b, int c) { // reflect triangle about c
	make_action(c, b, a);
	make_action(c, a, b);
	make_action(c, b, a);
}

bool good(int x, int y, int z) {
	pii a = 2*points[z]-points[x]-points[y];
	return (a.first > 0 && a.second > 0) || (a.first < 0 && a.second < 0);
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> points[i].first >> points[i].second;
	}
	int a = 0, b = 1, c = -1;
	for (int i = 2; i < n; i++) {
		if ((points[i]-points[a])*(points[i]-points[b]) != 0) {
			c = i;
			break;
		}
	}
	if (c == -1) {
		cout << "-1\n";
		return 0;
	}
	if (good(c, b, a)) {
		swap(a, c);
	}
	else if (good(c, a, b)) {
		swap(b, c);
	}
	assert(good(a, b, c)); // c is good
	if ((2*points[c]-points[a]-points[b]).first < 0) make_action(a, b, c);
	for (int i = 0; i < 100; i++) {
		reflect(a, b, c);
		make_action(a, b, c);
	}
	for (int i = 0; i < n; i++) {
		if (i == a || i == b || i == c) continue;
		make_action(a, b, i);
	}
	cout << actions.size() << "\n";
	for (int i = 0; i < actions.size(); i++) {
		action m = actions[i];
		cout << (1+m.a) << " " << (1+m.b) << " " << (1+m.c) << "\n";
	}
}

Compilation message

paralelogrami.cpp: In function 'int main()':
paralelogrami.cpp:85:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<action>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |  for (int i = 0; i < actions.size(); i++) {
      |                  ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Runtime error 1 ms 468 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Runtime error 1 ms 456 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Runtime error 1 ms 468 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Runtime error 1 ms 452 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -