CODE FESTIVAL 2016 Grand Final(Parallel)

Submission #1291432

Source codeソースコード

#define _USE_MATH_DEFINES

#include <bits/stdc++.h>
using namespace std;
using i32 = int; using i64 = long long int; using f64 = double; using str = string;
template <typename T> using vec = vector<T>;
template <typename T> using heap = priority_queue<T, vec<T>, greater<T>>;
#define times(n, i) for (i32 i = 0; i < (n); ++i)
#define range(a, b, i) for (i32 i = (a); i < (b); ++i)
#define upto(a, b, i) for (i32 i = (a); i <= (b); ++i)
#define downto(a, b, i) for (i32 i = (a); i >= (b); --i)
#define all(xs) (xs).begin(), (xs).end()
#define sortall(xs) sort(all(xs))
#define reverseall(xs) reverse(all(xs))
#define uniqueall(xs) (xs).erase(unique(all(xs)), (xs).end())
#define even(x) (((x) & 1) == 0)
#define odd(x) (((x) & 1) == 1)
#define append emplace_back
#define findge lower_bound
#define findgt upper_bound
const i64 MOD = 1000000007;
const f64 EPS = 1e-10;

i32 n;
vec<i64> a, b;
i64 c[100001];

bool bb[100000];
i64 bf(i32 i, i64 acc, i64 minl) {
	if (i == n) {
		return acc == minl ? 1 : 0;
	}
	i64 ret = 0;
	times(n, j) {
		if (!bb[j]) {
			bb[j] = true;
			ret += bf(i + 1, acc + abs(a[i] - b[j]), minl);
			bb[j] = false;
		}
	}
	return ret;
}

i32 main()
{
	cin >> n;
	a.resize(n); b.resize(n);
	times(n, i) { cin >> a[i]; }
	times(n, i) { cin >> b[i]; }
	sortall(a);
	sortall(b);
	i64 ans = 1;
	times(n, i) {
		if (a[i] < b[i]) {
			i32 cnt = 0;
			i64 j = i;
			while (j < a.size() && a[j] < b[i]) {
				cnt++;
				j++;
			}
			ans *= cnt;
		} else {
			i32 cnt = 0;
			i64 j = i;
			while (j < b.size() && b[j] < a[i]) {
				cnt++;
				j++;
			}
			ans *= cnt;
		}
	}
	i64 minl = 0;
	times(n, i) {
		minl += abs(a[i] - b[i]);
	}
	i64 ans2 = bf(0, 0, minl);
	cout << ans << endl;
    return 0;
}

Submission

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

Test case

Set

Set name Score得点 / Max score Cases
Sample - example0.txt,example1.txt
All 0 / 500 000.txt,001.txt,002.txt,003.txt,004.txt,005.txt,006.txt,007.txt,008.txt,009.txt,010.txt,011.txt,example0.txt,example1.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
000.txt TLE
001.txt TLE
002.txt TLE
003.txt TLE
004.txt TLE
005.txt TLE
006.txt TLE
007.txt TLE
008.txt TLE
009.txt TLE
010.txt TLE
011.txt TLE
example0.txt AC 1 ms 256 KB
example1.txt AC 1 ms 256 KB