Submission #1084698


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DBG(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(int x,int suc=1){
	printf("%lld",x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

const int inf=LLONG_MAX/3;

const int mod=1000000007;
template<class T,class U>
void add(T& a,U b){
	a=((ll)a+b)%mod;
}

template<class T,class U>
void sub(T& a,U b){
	a=((ll)a-b%mod+mod)%mod;
}

template<class T,class U>
void mult(T& a,U b){
	a=((ll)a*b)%mod;
}

ll modPow(ll a,ll p){
	ll s=1;
	REP(i,30){
		if((p>>i)&1)
			mult(s,a);
		mult(a,a);
	}
	return s;
}

ll modInv(ll a){
	return modPow(a,mod-2);
}

signed main(){
	vi fact{1};
	FOR(i,1,114514)
		fact.PB(fact.back()*i%mod);
	vi factInv;
	for(auto v:fact)
		factInv.PB(modInv(v));
	const auto comb=[&](int a,int b){
		return fact[a]*factInv[b]%mod*factInv[a-b]%mod;
	};
	int n=read(),k=read();
	int ans=0;
	if(k==1)
		ans=1;
	else{
		add(ans,comb(n-2+k-1,k-1));
		if(k>=3)
		sub(ans,comb(n-2+k-1,k-3));
	}
	if(n-k>0)
	mult(ans,modPow(2,n-k-1));
	cout<<ans<<endl;
}

Submission Info

Submission Time
Task F - Solitaire
User maroonrk
Language C++14 (GCC 5.4.1)
Score 1200
Code Size 2347 Byte
Status AC
Exec Time 25 ms
Memory 2676 KB

Compile Error

./Main.cpp: In function ‘ll read()’:
./Main.cpp:38:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld",&i);
                  ^
./Main.cpp: In function ‘std::string readString()’:
./Main.cpp:60:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s",buf);
                 ^
./Main.cpp: In function ‘char* readCharArray()’:
./Main.cpp:68:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s",ret);
                 ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1200 / 1200
Status
AC × 3
AC × 26
Set Name Test Cases
Sample 00_example_01.txt, 00_example_02.txt, 00_example_03.txt
All 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt
Case Name Status Exec Time Memory
00_example_01.txt AC 24 ms 2676 KB
00_example_02.txt AC 24 ms 2676 KB
00_example_03.txt AC 25 ms 2676 KB
01.txt AC 24 ms 2676 KB
02.txt AC 24 ms 2676 KB
03.txt AC 24 ms 2676 KB
04.txt AC 24 ms 2676 KB
05.txt AC 24 ms 2676 KB
06.txt AC 25 ms 2676 KB
07.txt AC 24 ms 2676 KB
08.txt AC 24 ms 2676 KB
09.txt AC 24 ms 2676 KB
10.txt AC 24 ms 2676 KB
11.txt AC 24 ms 2676 KB
12.txt AC 24 ms 2676 KB
13.txt AC 24 ms 2676 KB
14.txt AC 24 ms 2676 KB
15.txt AC 24 ms 2676 KB
16.txt AC 24 ms 2676 KB
17.txt AC 24 ms 2676 KB
18.txt AC 24 ms 2676 KB
19.txt AC 24 ms 2676 KB
20.txt AC 24 ms 2676 KB
21.txt AC 24 ms 2676 KB
22.txt AC 24 ms 2676 KB
23.txt AC 24 ms 2676 KB