結果

問題 No.824 Many Shifts Hard
ユーザー 👑 kmjpkmjp
提出日時 2019-04-28 00:15:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,735 bytes
コンパイル時間 1,484 ms
コンパイル使用メモリ 169,524 KB
実行使用メモリ 5,112 KB
最終ジャッジ日時 2023-08-20 04:25:56
合計ジャッジ時間 13,242 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,792 KB
testcase_01 AC 3 ms
4,844 KB
testcase_02 AC 51 ms
4,884 KB
testcase_03 AC 309 ms
5,040 KB
testcase_04 AC 269 ms
4,780 KB
testcase_05 AC 947 ms
4,780 KB
testcase_06 AC 20 ms
4,796 KB
testcase_07 AC 215 ms
4,792 KB
testcase_08 AC 717 ms
4,900 KB
testcase_09 AC 687 ms
4,784 KB
testcase_10 AC 62 ms
4,972 KB
testcase_11 AC 167 ms
4,784 KB
testcase_12 AC 356 ms
4,780 KB
testcase_13 WA -
testcase_14 AC 875 ms
4,844 KB
testcase_15 WA -
testcase_16 AC 59 ms
4,908 KB
testcase_17 AC 867 ms
4,844 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 1,318 ms
4,784 KB
testcase_21 AC 6 ms
4,900 KB
testcase_22 AC 1,326 ms
4,792 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<=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