CODE FESTIVAL 2016 Grand Final(Parallel)

Submission #1005424

Source codeソースコード

#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

struct Point {
	int x, y;
	Point operator*(int a) const { return Point{ x * a, y * a }; }
	Point operator+(const Point &that) const { return Point{ x + that.x, y + that.y }; }
};

int main() {
	int N;
	mt19937 re;
	while(~scanf("%d", &N)) {
		vector<int> a(N);
		for(int i = 0; i < N; ++ i) {
			scanf("%d", &a[i]);
			if(a[i] == 270)
				a[i] = -90;
		}
		if(accumulate(a.begin(), a.end(), 0) != 360) {
			puts("-1");
			continue;
		}
		function<vector<Point>(vector<int>)> rec = [&rec](vector<int> a) -> vector<Point> {
			vector<Point> P;
			int N = (int)a.size();
			if(N == 4) {
				assert(count(a.begin(), a.end(), 90) == 4);
				P.push_back({ 0, 0 });
				P.push_back({ 1, 0 });
				P.push_back({ 1, 1 });
				P.push_back({ 0, 1 });
				return P;
			}
			int mid = -1;
			rep(i, N) if(a[i] == 90 && a[(i + 1) % a.size()] == -90) {
				mid = i == 0 ? N - 1 : i - 1;
				break;
			}
			assert(mid != -1);
			rotate(a.begin(), a.begin() + mid, a.end());
			assert(a[1] == 90 && a[2] == -90);
			vector<int> b = a;
			b.erase(b.begin() + 1, b.begin() + 3);
			vector<Point> Q = rec(b);
			while(!(Q[0].y == Q[1].y && Q[0].x < Q[1].x)) {
				for(auto &p : Q)
					swap(p.x, p.y), p.x *= -1;
			}
			P.push_back(Q[0] * 2);
			P.push_back(Q[0] * 2 + Point{ 1, 0 });
			P.push_back(Q[0] * 2 + Point{ 1, 1 });
			P.push_back(Q[1] * 2 + Point{ 0, 1 });
			reu(i, 2, Q.size())
				P.push_back(Q[i] * 2);
			vector<int> xs, ys;
			for(auto p : P) {
				xs.push_back(p.x);
				ys.push_back(p.y);
			}
			sort(xs.begin(), xs.end());
			xs.erase(unique(xs.begin(), xs.end()), xs.end());
			sort(ys.begin(), ys.end());
			ys.erase(unique(ys.begin(), ys.end()), ys.end());
			for(auto &p : P) {
				p.x = (int)(lower_bound(xs.begin(), xs.end(), p.x) - xs.begin());
				p.y = (int)(lower_bound(ys.begin(), ys.end(), p.y) - ys.begin());
			}
			rotate(P.rbegin(), P.rbegin() + mid, P.rend());
			return P;
		};
		vector<Point> P = rec(a);
		for(auto p : P)
			printf("%d %d\n", p.x, p.y);
	}
	return 0;
}

Submission

Task問題 I - 90 and 270
User nameユーザ名 anta
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 1500
Source lengthソースコード長 2659 Byte
File nameファイル名
Exec time実行時間 52 ms
Memory usageメモリ使用量 2432 KB

Compiler messageコンパイルメッセージ

./Main.cpp: In function ‘int main()’:
./Main.cpp:23:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &a[i]);
^

Test case

Set

Set name Score得点 / Max score Cases
Sample - example0.txt,example1.txt
All 1500 / 1500 000.txt,001.txt,002.txt,003.txt,004.txt,005.txt,006.txt,007.txt,008.txt,009.txt,010.txt,011.txt,012.txt,013.txt,014.txt,015.txt,016.txt,017.txt,018.txt,019.txt,020.txt,021.txt,022.txt,023.txt,024.txt,025.txt,026.txt,027.txt,028.txt,029.txt,030.txt,031.txt,032.txt,033.txt,034.txt,035.txt,036.txt,037.txt,038.txt,039.txt,040.txt,041.txt,042.txt,043.txt,example0.txt,example1.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
000.txt AC 3 ms 256 KB
001.txt AC 3 ms 256 KB
002.txt AC 3 ms 256 KB
003.txt AC 19 ms 1280 KB
004.txt AC 5 ms 384 KB
005.txt AC 9 ms 640 KB
006.txt AC 15 ms 896 KB
007.txt AC 6 ms 512 KB
008.txt AC 4 ms 384 KB
009.txt AC 8 ms 512 KB
010.txt AC 27 ms 1536 KB
011.txt AC 3 ms 256 KB
012.txt AC 12 ms 768 KB
013.txt AC 12 ms 896 KB
014.txt AC 4 ms 256 KB
015.txt AC 5 ms 384 KB
016.txt AC 17 ms 1024 KB
017.txt AC 3 ms 256 KB
018.txt AC 14 ms 896 KB
019.txt AC 7 ms 512 KB
020.txt AC 39 ms 2304 KB
021.txt AC 3 ms 256 KB
022.txt AC 34 ms 2048 KB
023.txt AC 40 ms 2432 KB
024.txt AC 40 ms 2432 KB
025.txt AC 52 ms 2432 KB
026.txt AC 43 ms 2304 KB
027.txt AC 43 ms 2304 KB
028.txt AC 45 ms 2432 KB
029.txt AC 44 ms 2432 KB
030.txt AC 46 ms 2304 KB
031.txt AC 46 ms 2304 KB
032.txt AC 46 ms 2432 KB
033.txt AC 46 ms 2432 KB
034.txt AC 46 ms 2432 KB
035.txt AC 46 ms 2432 KB
036.txt AC 46 ms 2432 KB
037.txt AC 46 ms 2304 KB
038.txt AC 45 ms 2432 KB
039.txt AC 44 ms 2432 KB
040.txt AC 44 ms 2432 KB
041.txt AC 44 ms 2304 KB
042.txt AC 44 ms 2432 KB
043.txt AC 3 ms 256 KB
example0.txt AC 3 ms 256 KB
example1.txt AC 3 ms 256 KB