CODE FESTIVAL 2016 Exhibition

Submission #995736

Source codeソースコード

#include<cstdio>
#include <algorithm>
#include <cstdlib>
#include <map>
using namespace std;

int N, A[101010], B[101010];

void fail()
{
	puts("-1");
	exit(0);
}

int bas[101010];
map<pair<int, int>, int> P;

bool is_good(int y, int x)
{
	return P.count(make_pair(y - 1, x - 1)) > 0;
}

int main()
{
	scanf("%d", &N);
	for (int i = 0; i < N; ++i) scanf("%d%d", A + i, B + i);

	if (A[0] != 0) fail();
	if (B[1] != 0) fail();
	if (A[1] != B[0]) fail();
	int D = A[1];

	for (int i = 2; i < N; ++i) {
		if (A[i] == 0 || B[i] == 0 || A[i] + B[i] < D) fail();
	}

	for (int i = 0; i < N; ++i) {
		if (A[i] + B[i] == D) {
			bas[A[i]] += 1;
		}
	}

	int ret = 0;
	for (int i = 0; i < D; ++i) {
		if (bas[i] == 0) fail();
		ret += max(bas[i], bas[i + 1]);
	}

	for (int i = 0; i < N; ++i) P[make_pair(A[i], B[i])] += 1;

	/*
	for (int i = 2; i < N; ++i) if (A[i] + B[i] != D) {
		int x = A[i], y = B[i];
		if (P.count(make_pair(x - 1, y - 1))) {
			++ret;
		} else if (P.count(make_pair(x, y - 1)) && P.count(make_pair(x - 1, y))) {
			ret += 2;
		} else fail();
	}
	*/
	for (map<pair<int, int>, int>::iterator p = P.begin(); p != P.end(); ++p) {
		int y = p->first.first, x = p->first.second;
		if (y + x == D) continue;

		if (P.count(make_pair(y - 1, x + 1)) == 0) {
			vector<pair<pair<int, int>, int> > V;
			for (;;) {
				int cnt = P[make_pair(y, x)];
				if (cnt == 0) break;
				V.push_back(make_pair(make_pair(y, x), cnt));
				y += 1;
				x -= 1;
			}

			if (V.size() == 1) {
				y = V[0].first.first, x = V[0].first.second;
				if (P.count(make_pair(y - 1, x - 1))) {
					ret += V[0].second;
				} else if (P.count(make_pair(y - 1, x)) && P.count(make_pair(y, x - 1))) {
					ret += 2 * V[0].second;
				} else fail();
				continue;
			}
		//	printf("%d\n", ret);
			bool waf = false;
			{
				y = V[0].first.first, x = V[0].first.second;
				if (P.count(make_pair(y - 1, x)) || P.count(make_pair(y - 1, x - 1))) {
					if (!P.count(make_pair(y - 1, x - 1))) waf = true;
					ret += V[0].second;
				} else fail();
			}
			{
				y = V[V.size()-1].first.first, x = V[V.size()-1].first.second;
				if (P.count(make_pair(y, x - 1)) || P.count(make_pair(y - 1, x - 1))) {
					if (!P.count(make_pair(y - 1, x - 1))) waf = true;
					ret += V[V.size()-1].second;
				} else fail();
			}
		//	printf("%d\n", ret);
			if (!waf) V[0].second = V[V.size()-1].second = 0;
			for (int i = 1; i < V.size(); ++i) {
				y = V[i].first.first, x = V[i].first.second;
				if (P.count(make_pair(y - 1, x - 1))) {
					ret += V[i].second;
					V[i].second = 0;
				}
			}
			for (int i = 1; i < V.size(); ++i) {
				ret += max(V[i].second, V[i - 1].second);
			}
		}
	}
	printf("%d\n", ret);

	return 0;
}

Submission

Task問題 A - Distance Pairs
User nameユーザ名 sugim48
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 WA
Score得点 0
Source lengthソースコード長 2812 Byte
File nameファイル名
Exec time実行時間 ms
Memory usageメモリ使用量 -

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

./Main.cpp: In function ‘int main()’:
./Main.cpp:25:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &N);
^
./Main.cpp:26:57: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
for (int i = 0; i < N; ++i) scanf("%d%d", A + i, B + i);
^

Test case

Set

Set name Score得点 / Max score Cases
sample - sample-01.txt,sample-02.txt
All 0 / 1500 sample-01.txt,sample-02.txt,01-01.txt,01-02.txt,01-03.txt,01-04.txt,01-05.txt,01-06.txt,01-07.txt,01-08.txt,01-09.txt,01-10.txt,01-11.txt,01-12.txt,01-13.txt,01-14.txt,01-15.txt,01-16.txt,01-17.txt,01-18.txt,01-19.txt,01-20.txt,01-21.txt,01-22.txt,01-23.txt,01-24.txt,01-25.txt,01-26.txt,01-27.txt,01-28.txt,01-29.txt,01-30.txt,01-31.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
01-01.txt AC 19 ms 1024 KB
01-02.txt AC 16 ms 1024 KB
01-03.txt AC 2 ms 256 KB
01-04.txt AC 2 ms 256 KB
01-05.txt WA
01-06.txt AC 11 ms 640 KB
01-07.txt WA
01-08.txt WA
01-09.txt WA
01-10.txt AC 18 ms 1024 KB
01-11.txt WA
01-12.txt WA
01-13.txt AC 114 ms 13056 KB
01-14.txt AC 59 ms 7680 KB
01-15.txt AC 108 ms 13568 KB
01-16.txt AC 16 ms 1024 KB
01-17.txt AC 16 ms 1024 KB
01-18.txt AC 16 ms 1024 KB
01-19.txt AC 92 ms 10452 KB
01-20.txt WA
01-21.txt WA
01-22.txt WA
01-23.txt AC 27 ms 1408 KB
01-24.txt AC 28 ms 1408 KB
01-25.txt AC 16 ms 1024 KB
01-26.txt AC 16 ms 1024 KB
01-27.txt AC 16 ms 1024 KB
01-28.txt AC 17 ms 1024 KB
01-29.txt WA
01-30.txt AC 2 ms 256 KB
01-31.txt AC 2 ms 256 KB
sample-01.txt AC 2 ms 256 KB
sample-02.txt AC 2 ms 256 KB