CODE FESTIVAL 2016 Final

Submission #1200047

Source codeソースコード

#include <set>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <algorithm>

using namespace std;

typedef long long ll;

const int maxn = 210000;

struct edge
{
	int u,v;
	ll w;
};

vector<ll> g[maxn];
edge g2[maxn << 1];
int p[maxn];

int find(int x)
{
	if (x != p[x]) p[x] = find(p[x]);
	return p[x];
}

void insert(int n,int x, int y)
{
	g[x].push_back(y);
	g[1].push_back(y + (n - x + 1) * 2);
}

int id;

void add(int u, int v, ll w)
{
	g2[++id].v = v;
	g2[id].u = u;
	g2[id].w = w;
}

bool comp(const edge & a, const edge & b)
{
	return a.w < b.w;
}

int main(int argc, char * argv[])
{
	int n, q;
	scanf("%d%d", &n, &q);
	for (int i = 1; i <= q; ++i)
	{
		int a1, b1;
		ll c1;
		scanf("%d%d%lld", &a1, &b1, &c1);
		a1++;
		b1++;
		add(a1, b1, c1);
		insert(n, a1, c1 + 1);
		insert(n, b1, c1 + 2);
	}
	static set<ll> s;
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 0; j < g[i].size(); ++j)
			s.insert(g[i][j] - 2 * i);
		add(i, i%n + 1, 2 * i + (*(s.begin())));
	}
	for (int i = 1; i <= n; ++i) p[i] = i;
	sort(g2 + 1, g2 + id + 1, comp);
	ll ans = 0;
	for (int i = 1; i <= id; ++i)
	{
		int u = find(g2[i].u);
		int v = find(g2[i].v);
		if (u != v)
		{
			p[u] = v;
			ans += g2[i].w;
		}
	}
	printf("%lld\n", ans);

	return 0;
}

Submission

Task問題 G - Zigzag MST
User nameユーザ名 wrz91win
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 1300
Source lengthソースコード長 1345 Byte
File nameファイル名
Exec time実行時間 680 ms
Memory usageメモリ使用量 60396 KB

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

./Main.cpp: In function ‘int main(int, char**)’:
./Main.cpp:53:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &q);
^
./Main.cpp:58:35: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%lld", &a1, &b1, &c1);
^

Test case

Set

Set name Score得点 / Max score Cases
sample - sample-01.txt,sample-02.txt,sample-03.txt
all 1300 / 1300 sample-01.txt,sample-02.txt,sample-03.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,sample-01.txt,sample-02.txt,sample-03.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
01-01.txt AC 3 ms 6400 KB
01-02.txt AC 468 ms 53608 KB
01-03.txt AC 680 ms 60396 KB
01-04.txt AC 33 ms 12800 KB
01-05.txt AC 21 ms 11520 KB
01-06.txt AC 27 ms 12032 KB
01-07.txt AC 22 ms 10880 KB
01-08.txt AC 23 ms 10880 KB
01-09.txt AC 41 ms 15100 KB
01-10.txt AC 263 ms 33648 KB
01-11.txt AC 511 ms 40044 KB
01-12.txt AC 563 ms 48364 KB
01-13.txt AC 565 ms 48876 KB
01-14.txt AC 574 ms 48364 KB
01-15.txt AC 571 ms 49132 KB
01-16.txt AC 573 ms 48364 KB
01-17.txt AC 573 ms 48364 KB
01-18.txt AC 98 ms 22108 KB
01-19.txt AC 22 ms 10752 KB
01-20.txt AC 26 ms 11008 KB
01-21.txt AC 126 ms 25588 KB
01-22.txt AC 403 ms 47212 KB
01-23.txt AC 430 ms 46316 KB
01-24.txt AC 26 ms 16252 KB
01-25.txt AC 150 ms 24940 KB
01-26.txt AC 33 ms 13056 KB
01-27.txt AC 39 ms 16380 KB
01-28.txt AC 213 ms 33520 KB
01-29.txt AC 313 ms 31724 KB
01-30.txt AC 348 ms 39404 KB
sample-01.txt AC 3 ms 6400 KB
sample-02.txt AC 3 ms 6400 KB
sample-03.txt AC 3 ms 6400 KB