結果

問題 No.824 Many Shifts Hard
ユーザー 👑 kmjpkmjp
提出日時 2019-04-28 00:16:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,343 ms / 2,000 ms
コード長 1,742 bytes
コンパイル時間 1,652 ms
コンパイル使用メモリ 169,592 KB
実行使用メモリ 5,040 KB
最終ジャッジ日時 2023-08-20 04:27:50
合計ジャッジ時間 13,419 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,836 KB
testcase_01 AC 3 ms
4,848 KB
testcase_02 AC 50 ms
4,976 KB
testcase_03 AC 309 ms
4,916 KB
testcase_04 AC 269 ms
4,780 KB
testcase_05 AC 941 ms
4,764 KB
testcase_06 AC 20 ms
4,760 KB
testcase_07 AC 215 ms
4,844 KB
testcase_08 AC 721 ms
4,788 KB
testcase_09 AC 710 ms
4,892 KB
testcase_10 AC 64 ms
4,764 KB
testcase_11 AC 174 ms
4,756 KB
testcase_12 AC 363 ms
4,884 KB
testcase_13 AC 525 ms
4,784 KB
testcase_14 AC 889 ms
4,892 KB
testcase_15 AC 777 ms
5,040 KB
testcase_16 AC 59 ms
4,904 KB
testcase_17 AC 873 ms
5,040 KB
testcase_18 AC 3 ms
4,824 KB
testcase_19 AC 875 ms
4,768 KB
testcase_20 AC 1,342 ms
4,844 KB
testcase_21 AC 6 ms
4,764 KB
testcase_22 AC 1,343 ms
4,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,K;
ll from[302][302];
ll to[302][302];
ll mo=1000000007;
ll ret;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K;
	
	for(i=1;i<=min(N,K);i++) from[i-1][i]++;
	FOR(i,K) {
		ZERO(to);
		for(x=0;x<=K;x++) for(y=x+1;y<=K;y++) {
			if(x==0) {
				// take y
				if(y-1>x) (to[x][y-1]+=from[x][y])%=mo;
				// other
				(to[x][y]+=from[x][y]*(N-1))%=mo;
			}
			else {
				// take x;
				(to[x-1][y]+=from[x][y])%=mo;
				// take y
				if(y-1>x) (to[x][y-1]+=from[x][y])%=mo;
				// other
				(to[x][y]+=from[x][y]*(N-2))%=mo;
			}
		}
		
		swap(from,to);
	}
	for(x=0;x<=K;x++) for(y=x+1;y<=K;y++) (ret+=y*from[x][y])%=mo;
	
	ZERO(from);
	from[K][K+1]=1;
	FOR(i,K) {
		ZERO(to);
		for(x=1;x<=K;x++) for(y=x+1;y<=K+1;y++) {
			// take x;
			(to[x-1][y]+=from[x][y])%=mo;
			// take y
			if(y-1>x) (to[x][y-1]+=from[x][y])%=mo;
			// other
			(to[x][y]+=from[x][y]*(N-2))%=mo;
		}
		swap(from,to);
	}
	for(y=1;y<=K+1;y++) {
		ll pat=0;
		for(x=0;x<y;x++) pat+=from[x][y];
		pat%=mo;
		for(i=K+1;i<=N;i++) (ret+=pat*(i-(K+1-y)))%=mo;
	}
	cout<<ret<<endl;
	
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0