CSES - HIIT Open 2018 - Results
Submission details
Task:Euclidean Geometry
Sender:Karhukopla
Submission time:2018-05-26 15:40:53 +0300
Language:C++
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.09 sdetails
#20.13 sdetails
#30.10 sdetails
#40.14 sdetails
#50.13 sdetails
#6ACCEPTED0.09 sdetails
#70.13 sdetails
#80.14 sdetails

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:3:11: warning: narrowing conversion of 'p.std::pair<int, int>::first' from 'int' to 'double' inside { } [-Wnarrowing]
 #define F first
           ^
input/code.cpp:22:24: note: in expansion of macro 'F'
     stack.push_back({p.F, p.S});
                        ^
input/code.cpp:4:11: warning: narrowing conversion of 'p.std::pair<int, int>::second' from 'int' to 'double' inside { } [-Wnarrowing]
 #define S second
           ^
input/code.cpp:22:29: note: in expansion of macro 'S'
     stack.push_back({p.F, p.S});
                             ^

Code

#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
int main() {
	int t;
	cin >> t;
	for (int ti = 0; ti < t; ++ti) {
		vector<pair<int, int>> ones;
		for (int i = 0; i < 100; ++i) {
			cin >> ws;
			for (int j = 0; j < 100; ++j) {
				char c;
				cin >> c;
				if (c == '1') ones.push_back({i, j});
			}
		}
		vector<complex<double>> stacks[2];
		for (int dir = 0; dir < 2; ++dir) {
			auto &stack = stacks[dir];
			for (auto p : ones) {
				stack.push_back({p.F, p.S});
				while (stack.size() >= 3) {
					bool drop = false;
					auto a = stack[stack.size()-3], b = stack[stack.size()-2], c = stack[stack.size()-1];
					double ang = arg((c-b)/(b-a));
					if (abs(ang) < M_PI/5) drop = true;
					else 
					if (dir ? (ang < 0) : (ang > 0)) {
						drop = true;
					}
					if (drop) {
						stack.pop_back();
						stack.pop_back();
						stack.push_back(c);
					} else {
						double d = abs(b-c);
						if (d <= 15) {
							stack.pop_back();
						}
						break;
					}
				}
			}
		}
		reverse(stacks[1].begin(), stacks[1].end());
		vector<complex<double>> fin;
		for (int dir = 0; dir < 2; ++dir) {
			for (auto c : stacks[dir]) {
				fin.push_back(c);
				while (fin.size() >= 2) {
					auto a = fin[fin.size()-2], b = fin[fin.size()-1];
					if (abs(a-b) <= 15) {
						fin.pop_back();
						fin.pop_back();
						fin.push_back(b);
					} else break;
				}
			}
		}
		if (abs(fin.front()-fin.back()) <= 15) {
			fin.pop_back();
		}
		int res = fin.size();
		if (res > 4) res = 4;
		if (res < 3) res = 3;
		cout << res << endl;
	}
}

Test details

Test 1

Verdict: ACCEPTED

input
100
000000000000000000000000000000...

correct output
3
3
3
3
4
...

user output
3
3
3
3
4
...
Truncated

Test 2

Verdict:

input
100
000000000000000000000000000000...

correct output
3
4
4
4
3
...

user output
3
4
4
4
3
...
Truncated

Test 3

Verdict:

input
100
000000000000000000000000000000...

correct output
3
3
3
3
4
...

user output
3
3
3
4
4
...
Truncated

Test 4

Verdict:

input
100
000000000000000000000000000000...

correct output
3
3
3
4
3
...

user output
3
3
3
4
3
...
Truncated

Test 5

Verdict:

input
100
000000000000000000000000000000...

correct output
3
4
3
3
4
...

user output
4
4
3
3
4
...
Truncated

Test 6

Verdict: ACCEPTED

input
100
000000000000000000000000000000...

correct output
4
3
4
4
4
...

user output
4
3
4
4
4
...
Truncated

Test 7

Verdict:

input
100
000000000000000000000000000000...

correct output
4
4
3
3
3
...

user output
4
4
3
3
3
...
Truncated

Test 8

Verdict:

input
100
000000000000000000000000000000...

correct output
3
3
3
3
3
...

user output
3
3
3
4
3
...
Truncated