CODE FESTIVAL 2016 Grand Final(Parallel)

Submission #1004287

Source codeソースコード

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

const int N=5010;
int n,a,b,c,ret;
ll fac[N],fnv[N];
int main() {
	scanf("%d%d%d%d",&n,&a,&b,&c);
	fac[0]=fnv[0]=1;
	rep(i,1,n+1) {
		fac[i]=fac[i-1]*i%mod;
		fnv[i]=powmod(fac[i],mod-2);
	}
	if (b%2!=0) {
		puts("0");
		return 0;
	}
	for (int p3=0;3*p3<=c;p3++) for (int p2=0;3*p3+p2<=c&&p2<=a;p2++) {
		int rc=c-3*p3-p2; int ra=a-p2;
		if (b) {
			int p1=b/2;
			ret=(ret+fac[ra+p1+p2+p3]*fnv[ra]%mod*fnv[p1]%mod*fnv[p2]%mod*fnv[p3]%mod*fac[p1+rc-1]%mod*fnv[p1-1]%mod*fnv[rc])%mod;
		} else if (rc==0) {
			ret=(ret+fac[ra+p2+p3]*fnv[ra]%mod*fnv[p2]%mod*fnv[p3])%mod;			
		}
	}
	printf("%d\n",ret);
}
/*

AA ra

BbBb p1+rc-1,rc

BCBbCb

BCBcCbcb

CAAC p2

CccCcc p3*/

Submission

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

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

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

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,044.txt,045.txt,046.txt,047.txt,048.txt,049.txt,example0.txt,example1.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
000.txt AC 12 ms 256 KB
001.txt AC 2 ms 256 KB
002.txt AC 2 ms 256 KB
003.txt AC 2 ms 256 KB
004.txt AC 2 ms 256 KB
005.txt AC 2 ms 256 KB
006.txt AC 2 ms 256 KB
007.txt AC 2 ms 256 KB
008.txt AC 2 ms 256 KB
009.txt AC 2 ms 256 KB
010.txt AC 2 ms 256 KB
011.txt AC 2 ms 256 KB
012.txt AC 2 ms 256 KB
013.txt AC 1 ms 128 KB
014.txt AC 2 ms 128 KB
015.txt AC 18 ms 256 KB
016.txt AC 3 ms 256 KB
017.txt AC 6 ms 256 KB
018.txt AC 3 ms 128 KB
019.txt AC 7 ms 256 KB
020.txt AC 4 ms 256 KB
021.txt AC 15 ms 256 KB
022.txt AC 3 ms 256 KB
023.txt AC 5 ms 256 KB
024.txt AC 16 ms 256 KB
025.txt AC 4 ms 256 KB
026.txt AC 10 ms 256 KB
027.txt AC 15 ms 256 KB
028.txt AC 7 ms 256 KB
029.txt AC 8 ms 256 KB
030.txt AC 15 ms 256 KB
031.txt AC 16 ms 256 KB
032.txt AC 3 ms 256 KB
033.txt AC 2 ms 256 KB
034.txt AC 7 ms 256 KB
035.txt AC 9 ms 256 KB
036.txt AC 3 ms 256 KB
037.txt AC 1 ms 128 KB
038.txt AC 22 ms 256 KB
039.txt AC 2 ms 256 KB
040.txt AC 2 ms 256 KB
041.txt AC 5 ms 256 KB
042.txt AC 2 ms 256 KB
043.txt AC 1 ms 128 KB
044.txt AC 1 ms 128 KB
045.txt AC 1 ms 128 KB
046.txt AC 1 ms 128 KB
047.txt AC 1 ms 128 KB
048.txt AC 1 ms 128 KB
049.txt AC 1 ms 128 KB
example0.txt AC 1 ms 128 KB
example1.txt AC 2 ms 128 KB