CODE FESTIVAL 2016 Grand Final(Parallel)

Submission #1678169

Source codeソースコード

//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))

using lint = long long;
using pii = pair< int, int >;

template< typename T > using Vec = vector< T >;

template< typename T > bool in_range(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool in_range(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }

template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }

int bitCount(int x) { return __builtin_popcount(x); }
int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double EPS = 1e-9;
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//

int N, a[100005], b[100005];
const lint MOD = (lint)1e9 + 7;
lint fact[100005];

int main() {
	cin >> N;
	for_(i,0,N) cin >> a[i];
	for_(i,0,N) cin >> b[i];
	sort(a, a+N);
	sort(b, b+N);
	
	fact[1] = 1;
	for_(i,2,N+1) fact[i] = (fact[i-1] * i) % MOD;
	
	Vec< int > vL;
	int len = 0;
	bool dir = false;
	for_(i,0,N) {
		if (len == 0) {
			dir = (a[i] < b[i]);
			len = 1;
		} else {
			if (dir) {
				if (a[i] < b[i]) {
					++len;
				} else {
					vL.push_back(len);
					len = 0;
					--i;
				}
			} else {
				if (a[i] > b[i]) {
					++len;
				} else {
					vL.push_back(len);
					len = 0;
					--i;
				}				
			}
		}
	}
	vL.push_back(len);
		
	lint ans = 1;
	for (int x : vL) ans = (ans * fact[x]) % MOD;
	cout << ans << endl;
}
//--------------8---------------->> coding space <<-----------------8-------------//

Submission

Task問題 A - 1D Matching
User nameユーザ名 026_tsukasa_diary
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 WA
Score得点 0
Source lengthソースコード長 2187 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 WA
001.txt WA
002.txt WA
003.txt WA
004.txt WA
005.txt WA
006.txt WA
007.txt WA
008.txt WA
009.txt WA
010.txt AC 92 ms 1792 KB
011.txt WA
example0.txt AC 1 ms 256 KB
example1.txt AC 1 ms 256 KB